| Cantera 3.0.0

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
17#include "cantera/base/ctexceptions.h"
18#include "cantera/thermo/Nasa9PolyMultiTempRegion.h"
19#include "cantera/thermo/speciesThermoTypes.h"
20#include "cantera/base/AnyMap.h"
21
22 namespace 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
82 void 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;
89 poly->setRefPressure(refPressure());
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
100 int Nasa9PolyMultiTempRegion::reportType() const
101{
102 return NASA9MULTITEMP;
103}
104
105 void 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
116 void Nasa9PolyMultiTempRegion::updateProperties(const double* tt,
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
130 void Nasa9PolyMultiTempRegion::updatePropertiesTemp(const double temp,
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
145 size_t Nasa9PolyMultiTempRegion::nCoeffs() const
146{
147 return 11*m_regionPts.size() + 1;
148}
149
150 void Nasa9PolyMultiTempRegion::reportParameters(size_t& n, int& type,
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
175 void Nasa9PolyMultiTempRegion::getParameters(AnyMap& thermo) const
176{
177 thermo["model"] = "NASA9";
178 SpeciesThermoInterpType::getParameters(thermo);
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}
AnyMap.h
Nasa9PolyMultiTempRegion.h
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::Nasa9Poly1
The NASA 9 polynomial parameterization for one temperature range.
Definition Nasa9Poly1.h:60
Cantera::Nasa9Poly1::setParameters
void setParameters(const vector< double > &coeffs)
Set the array of 9 polynomial coefficients.
Definition Nasa9Poly1.cpp:33
Cantera::Nasa9PolyMultiTempRegion::reportType
int reportType() const override
Returns an integer representing the type of parameterization.
Definition Nasa9PolyMultiTempRegion.cpp:100
Cantera::Nasa9PolyMultiTempRegion::setParameters
void setParameters(const map< double, vector< double > > &regions)
Set the array of polynomial coefficients for each temperature region.
Definition Nasa9PolyMultiTempRegion.cpp:82
Cantera::Nasa9PolyMultiTempRegion::getParameters
void getParameters(AnyMap &thermo) const override
Store the parameters of the species thermo object such that an identical species thermo object could ...
Definition Nasa9PolyMultiTempRegion.cpp:175
Cantera::Nasa9PolyMultiTempRegion::nCoeffs
size_t nCoeffs() const override
This utility function returns the number of coefficients for a given type of species parameterization...
Definition Nasa9PolyMultiTempRegion.cpp:145
Cantera::Nasa9PolyMultiTempRegion::updateTemperaturePoly
void updateTemperaturePoly(double T, double *T_poly) const override
Given the temperature T, compute the terms of the temperature polynomial T_poly.
Definition Nasa9PolyMultiTempRegion.cpp:105
Cantera::Nasa9PolyMultiTempRegion::reportParameters
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...
Definition Nasa9PolyMultiTempRegion.cpp:150
Cantera::Nasa9PolyMultiTempRegion::m_lowerTempBounds
vector< double > m_lowerTempBounds
Lower boundaries of each temperature regions.
Definition Nasa9PolyMultiTempRegion.h:119
Cantera::Nasa9PolyMultiTempRegion::m_regionPts
vector< unique_ptr< Nasa9Poly1 > > m_regionPts
Individual temperature region objects.
Definition Nasa9PolyMultiTempRegion.h:122
Cantera::Nasa9PolyMultiTempRegion::updateProperties
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.
Definition Nasa9PolyMultiTempRegion.cpp:116
Cantera::Nasa9PolyMultiTempRegion::m_currRegion
int m_currRegion
current region
Definition Nasa9PolyMultiTempRegion.h:125
Cantera::Nasa9PolyMultiTempRegion::updatePropertiesTemp
void updatePropertiesTemp(const double temp, double *cp_R, double *h_RT, double *s_R) const override
Compute the reference-state property of one species.
Definition Nasa9PolyMultiTempRegion.cpp:130
Cantera::SpeciesThermoInterpType
Abstract Base class for the thermodynamic manager for an individual species' reference state.
Definition SpeciesThermoInterpType.h:113
Cantera::SpeciesThermoInterpType::maxTemp
virtual double maxTemp() const
Returns the maximum temperature that the thermo parameterization is valid.
Definition SpeciesThermoInterpType.h:138
Cantera::SpeciesThermoInterpType::m_Pref
double m_Pref
Reference state pressure.
Definition SpeciesThermoInterpType.h:288
Cantera::SpeciesThermoInterpType::setRefPressure
virtual void setRefPressure(double Pref)
Set the reference pressure [Pa].
Definition SpeciesThermoInterpType.h:153
Cantera::SpeciesThermoInterpType::getParameters
virtual void getParameters(AnyMap &thermo) const
Store the parameters of the species thermo object such that an identical species thermo object could ...
Definition SpeciesThermoInterpType.cpp:58
Cantera::SpeciesThermoInterpType::m_lowT
double m_lowT
lowest valid temperature
Definition SpeciesThermoInterpType.h:284
Cantera::SpeciesThermoInterpType::setMinTemp
virtual void setMinTemp(double Tmin)
Set the minimum temperature at which the thermo parameterization is valid.
Definition SpeciesThermoInterpType.h:132
Cantera::SpeciesThermoInterpType::refPressure
virtual double refPressure() const
Returns the reference pressure (Pa)
Definition SpeciesThermoInterpType.h:148
Cantera::SpeciesThermoInterpType::m_highT
double m_highT
Highest valid temperature.
Definition SpeciesThermoInterpType.h:286
ctexceptions.h
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
speciesThermoTypes.h
Contains const definitions for types of species reference-state thermodynamics managers (see Species ...
NASA9MULTITEMP
#define NASA9MULTITEMP
9 coefficient NASA Polynomials in multiple temperature regions This is implemented in the class Nasa9...
Definition speciesThermoTypes.h:58