Cantera  3.1.0a2
Loading...
Searching...
No Matches
Nasa9PolyMultiTempRegion.cpp
Go to the documentation of this file.
1/**
2 * @file Nasa9PolyMultiTempRegion.cpp
3 * Definitions for a single-species standard state object derived
4 * from @link Cantera::SpeciesThermoInterpType
5 * SpeciesThermoInterpType@endlink based
6 * on the NASA 9 coefficient temperature polynomial form
7 * applied to one temperature region
8 * (see @ref spthermo and class
9 * @link Cantera::Nasa9Poly1 Nasa9Poly1@endlink).
10 *
11 * This parameterization has one NASA temperature region.
12 */
13
14// This file is part of Cantera. See License.txt in the top-level directory or
15// at https://cantera.org/license.txt for license and copyright information.
16
20#include "cantera/base/AnyMap.h"
21
22namespace Cantera
23{
24
25Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(vector<Nasa9Poly1*>& regionPts)
26{
27 // From now on, we own these pointers
28 for (Nasa9Poly1* region : regionPts) {
29 m_regionPts.emplace_back(region);
30 }
31 m_lowerTempBounds.resize(regionPts.size());
32 m_lowT = m_regionPts[0]->minTemp();
33 m_highT = m_regionPts[m_regionPts.size()-1]->maxTemp();
34 m_Pref = m_regionPts[0]->refPressure();
35 for (size_t i = 0; i < m_regionPts.size(); i++) {
36 m_lowerTempBounds[i] = m_regionPts[i]->minTemp();
37 if (fabs(m_regionPts[i]->refPressure() - m_Pref) > 0.0001) {
38 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
39 "refPressure inconsistency");
40 }
41 if (i > 0) {
42 if (m_lowerTempBounds[i-1] >= m_lowerTempBounds[i]) {
43 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
44 "minTemp bounds inconsistency");
45 }
46 if (fabs(m_regionPts[i-1]->maxTemp() - m_lowerTempBounds[i]) > 0.0001) {
47 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
48 "Temp bounds inconsistency");
49 }
50 }
51 }
52}
53
54Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(double tlow, double thigh, double pref,
55 const double* coeffs)
56 : SpeciesThermoInterpType(tlow, thigh, pref)
57{
58 size_t regions = static_cast<size_t>(coeffs[0]);
59
60 for (size_t i=0; i<regions; i++) {
61 Nasa9Poly1* poly = new Nasa9Poly1(coeffs[11*i+1], coeffs[11*i+2],
62 pref, coeffs + 11*i + 3);
63 m_regionPts.emplace_back(poly);
64 }
65
66 m_lowerTempBounds.resize(regions);
67 for (size_t i = 0; i < m_regionPts.size(); i++) {
68 m_lowerTempBounds[i] = m_regionPts[i]->minTemp();
69 if (i > 0) {
70 if (m_lowerTempBounds[i-1] >= m_lowerTempBounds[i]) {
71 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
72 "minTemp bounds inconsistency");
73 }
74 if (fabs(m_regionPts[i-1]->maxTemp() - m_lowerTempBounds[i]) > 0.0001) {
75 throw CanteraError("Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion",
76 "Temp bounds inconsistency");
77 }
78 }
79 }
80}
81
82void Nasa9PolyMultiTempRegion::setParameters(const map<double, vector<double>>& regions)
83{
84 m_regionPts.clear();
85 m_lowerTempBounds.clear();
86 for (const auto& [Tmin, coeffs] : regions) {
87 m_lowerTempBounds.push_back(Tmin);
88 Nasa9Poly1* poly = new Nasa9Poly1;
90 poly->setMinTemp(Tmin);
91 poly->setParameters(coeffs);
92 if (!m_regionPts.empty()) {
93 m_regionPts.back()->setMaxTemp(Tmin);
94 }
95 m_regionPts.emplace_back(poly);
96 }
97 m_regionPts.back()->setMaxTemp(maxTemp());
98}
99
101{
102 return NASA9MULTITEMP;
103}
104
105void Nasa9PolyMultiTempRegion::updateTemperaturePoly(double T, double* T_poly) const
106{
107 T_poly[0] = T;
108 T_poly[1] = T * T;
109 T_poly[2] = T_poly[1] * T;
110 T_poly[3] = T_poly[2] * T;
111 T_poly[4] = 1.0 / T;
112 T_poly[5] = T_poly[4] / T;
113 T_poly[6] = std::log(T);
114}
115
117 double* cp_R, double* h_RT, double* s_R) const
118{
119 m_currRegion = 0;
120 for (size_t i = 1; i < m_regionPts.size(); i++) {
121 if (tt[0] < m_lowerTempBounds[i]) {
122 break;
123 }
124 m_currRegion++;
125 }
126
127 m_regionPts[m_currRegion]->updateProperties(tt, cp_R, h_RT, s_R);
128}
129
131 double* cp_R, double* h_RT, double* s_R) const
132{
133 // Now find the region
134 m_currRegion = 0;
135 for (size_t i = 1; i < m_regionPts.size(); i++) {
136 if (temp < m_lowerTempBounds[i]) {
137 break;
138 }
139 m_currRegion++;
140 }
141
142 m_regionPts[m_currRegion]->updatePropertiesTemp(temp, cp_R, h_RT, s_R);
143}
144
146{
147 return 11*m_regionPts.size() + 1;
148}
149
151 double& tlow, double& thigh, double& pref, double* const coeffs) const
152{
153 n = 0;
154 type = NASA9MULTITEMP;
155 tlow = m_lowT;
156 thigh = m_highT;
157 pref = m_Pref;
158 double ctmp[12];
159 coeffs[0] = double(m_regionPts.size());
160 int index = 1;
161 size_t n_tmp = 0;
162 int type_tmp = 0;
163 double pref_tmp = 0.0;
164 for (size_t iReg = 0; iReg < m_regionPts.size(); iReg++) {
165 m_regionPts[iReg]->reportParameters(n_tmp, type_tmp,
166 coeffs[index], coeffs[index+1],
167 pref_tmp, ctmp);
168 for (int i = 0; i < 9; i++) {
169 coeffs[index+2+i] = ctmp[3+i];
170 }
171 index += 11;
172 }
173}
174
176{
177 thermo["model"] = "NASA9";
179 auto T_ranges = m_lowerTempBounds;
180 T_ranges.push_back(m_highT);
181 thermo["temperature-ranges"].setQuantity(T_ranges, "K");
182 thermo["data"] = vector<vector<double>>();
183 for (const auto& region : m_regionPts) {
184 region->getParameters(thermo);
185 }
186}
187
188}
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Base class for exceptions thrown by Cantera classes.
The NASA 9 polynomial parameterization for one temperature range.
Definition Nasa9Poly1.h:60
void setParameters(const vector< double > &coeffs)
Set the array of 9 polynomial coefficients.
int reportType() const override
Returns an integer representing the type of parameterization.
void setParameters(const map< double, vector< double > > &regions)
Set the array of polynomial coefficients for each temperature region.
void getParameters(AnyMap &thermo) const override
Store the parameters of the species thermo object such that an identical species thermo object could ...
size_t nCoeffs() const override
This utility function returns the number of coefficients for a given type of species parameterization...
void updateTemperaturePoly(double T, double *T_poly) const override
Given the temperature T, compute the terms of the temperature polynomial T_poly.
void reportParameters(size_t &n, int &type, double &tlow, double &thigh, double &pref, double *const coeffs) const override
This utility function reports back the type of parameterization and all of the parameters for the spe...
vector< double > m_lowerTempBounds
Lower boundaries of each temperature regions.
vector< unique_ptr< Nasa9Poly1 > > m_regionPts
Individual temperature region objects.
void updateProperties(const double *tt, double *cp_R, double *h_RT, double *s_R) const override
Update the properties for this species, given a temperature polynomial.
void updatePropertiesTemp(const double temp, double *cp_R, double *h_RT, double *s_R) const override
Compute the reference-state property of one species.
Abstract Base class for the thermodynamic manager for an individual species' reference state.
virtual double maxTemp() const
Returns the maximum temperature that the thermo parameterization is valid.
double m_Pref
Reference state pressure.
virtual void setRefPressure(double Pref)
Set the reference pressure [Pa].
virtual void getParameters(AnyMap &thermo) const
Store the parameters of the species thermo object such that an identical species thermo object could ...
double m_lowT
lowest valid temperature
virtual void setMinTemp(double Tmin)
Set the minimum temperature at which the thermo parameterization is valid.
virtual double refPressure() const
Returns the reference pressure (Pa)
double m_highT
Highest valid temperature.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Contains const definitions for types of species reference-state thermodynamics managers (see Species ...
#define NASA9MULTITEMP
9 coefficient NASA Polynomials in multiple temperature regions This is implemented in the class Nasa9...