Cantera  3.1.0a1
SpeciesThermoFactory.cpp
Go to the documentation of this file.
1 /**
2  * @file SpeciesThermoFactory.cpp
3  * Definitions for factory functions to build instances of classes that
4  * manage the standard-state thermodynamic properties of a set of species
5  * (see @ref spthermo);
6  */
7 
8 // This file is part of Cantera. See License.txt in the top-level directory or
9 // at https://cantera.org/license.txt for license and copyright information.
10 
13 #include "cantera/thermo/Mu0Poly.h"
22 #include "cantera/base/Units.h"
23 
24 namespace Cantera
25 {
26 
28  double thigh, double pref, const double* coeffs)
29 {
30  switch (type) {
31  case NASA1:
32  return new NasaPoly1(tlow, thigh, pref, coeffs);
33  case SHOMATE1:
34  return new ShomatePoly(tlow, thigh, pref, coeffs);
35  case CONSTANT_CP:
36  case SIMPLE:
37  return new ConstCpPoly(tlow, thigh, pref, coeffs);
38  case MU0_INTERP:
39  return new Mu0Poly(tlow, thigh, pref, coeffs);
40  case SHOMATE2:
41  return new ShomatePoly2(tlow, thigh, pref, coeffs);
42  case NASA2:
43  return new NasaPoly2(tlow, thigh, pref, coeffs);
44  case NASA9MULTITEMP:
45  return new Nasa9PolyMultiTempRegion(tlow, thigh, pref, coeffs);
46  default:
47  throw CanteraError("newSpeciesThermoInterpType",
48  "Unknown species thermo type: {}.", type);
49  }
50 }
51 
53  double tlow, double thigh, double pref, const double* coeffs)
54 {
55  int itype = -1;
56  string type = toLowerCopy(stype);
57  if (type == "nasa2" || type == "nasa") {
58  itype = NASA2; // two-region 7-coefficient NASA polynomials
59  } else if (type == "const_cp" || type == "simple") {
60  itype = CONSTANT_CP;
61  } else if (type == "shomate" || type == "shomate1") {
62  itype = SHOMATE1; // single-region Shomate polynomial
63  } else if (type == "shomate2") {
64  itype = SHOMATE2; // two-region Shomate polynomials
65  } else if (type == "nasa1") {
66  itype = NASA1; // single-region, 7-coefficient NASA polynomial
67  } else if (type == "nasa9") {
68  itype = NASA9; // single-region, 9-coefficient NASA polynomial
69  } else if (type == "nasa9multi") {
70  itype = NASA9MULTITEMP; // multi-region, 9-coefficient NASA polynomials
71  } else if (type == "mu0") {
72  itype = MU0_INTERP;
73  } else {
74  throw CanteraError("newSpeciesThermoInterpType",
75  "Unknown species thermo type: '" + stype + "'.");
76  }
77  return newSpeciesThermoInterpType(itype, tlow, thigh, pref, coeffs);
78 }
79 
80 void setupSpeciesThermo(SpeciesThermoInterpType& thermo,
81  const AnyMap& node)
82 {
83  double Pref = node.convert("reference-pressure", "Pa", OneAtm);
84  thermo.setRefPressure(Pref);
85  thermo.input() = node;
86 }
87 
88 void setupNasaPoly(NasaPoly2& thermo, const AnyMap& node)
89 {
90  setupSpeciesThermo(thermo, node);
91  vector<double> Tranges = node.convertVector("temperature-ranges", "K", 2, 3);
92  const auto& data = node["data"].asVector<vector<double>>(Tranges.size()-1);
93  for (const auto& poly : data) {
94  if (poly.size() != 7) {
95  throw CanteraError("setupNasaPoly", "Wrong number of coefficients "
96  "for NASA polynomial. Expected 7, but got {}", poly.size());
97  }
98  }
99  thermo.setMinTemp(Tranges.front());
100  thermo.setMaxTemp(Tranges.back());
101  if (Tranges.size() == 3) { // standard 2 temperature range polynomial
102  thermo.setParameters(Tranges[1], data[0], data[1]);
103  } else { // Repeat data for single temperature range for both ranges
104  thermo.setParameters(Tranges[1], data[0], data[0]);
105  }
106 }
107 
108 void setupShomatePoly(ShomatePoly2& thermo, const AnyMap& node)
109 {
110  setupSpeciesThermo(thermo, node);
111  vector<double> Tranges = node.convertVector("temperature-ranges", "K", 2, 3);
112  const auto& data = node["data"].asVector<vector<double>>(Tranges.size()-1);
113  for (const auto& poly : data) {
114  if (poly.size() != 7) {
115  throw CanteraError("setupShomatePoly", "Wrong number of coefficients "
116  "for Shomate polynomial. Expected 7, but got {}", poly.size());
117  }
118  }
119  thermo.setMinTemp(Tranges.front());
120  thermo.setMaxTemp(Tranges.back());
121  if (Tranges.size() == 3) { // standard 2 temperature range polynomial
122  thermo.setParameters(Tranges[1], data[0], data[1]);
123  } else { // Repeat data for single temperature range for both ranges
124  thermo.setParameters(Tranges[1], data[0], data[0]);
125  }
126 }
127 
128 void setupConstCp(ConstCpPoly& thermo, const AnyMap& node)
129 {
130  setupSpeciesThermo(thermo, node);
131  if (node.hasKey("T-min")) {
132  thermo.setMinTemp(node.convert("T-min", "K"));
133  }
134  if (node.hasKey("T-max")) {
135  thermo.setMaxTemp(node.convert("T-max", "K"));
136  }
137  double T0 = node.convert("T0", "K", 298.15);
138  double h0 = node.convert("h0", "J/kmol", 0.0);
139  double s0 = node.convert("s0", "J/kmol/K", 0.0);
140  double cp0 = node.convert("cp0", "J/kmol/K", 0.0);
141  thermo.setParameters(T0, h0, s0, cp0);
142 }
143 
144 void setupNasa9Poly(Nasa9PolyMultiTempRegion& thermo, const AnyMap& node)
145 {
146  setupSpeciesThermo(thermo, node);
147  vector<double> Tranges = node.convertVector("temperature-ranges", "K", 2, 999);
148  const auto& data = node["data"].asVector<vector<double>>(Tranges.size()-1);
149  map<double, vector<double>> regions;
150  for (size_t i = 0; i < data.size(); i++) {
151  if (data[i].size() != 9) {
152  throw CanteraError("setupNasa9Poly", "Wrong number of coefficients "
153  "for NASA9 polynomial. Expected 9, but got {}", data[i].size());
154  }
155  regions[Tranges[i]] = data[i];
156  }
157  thermo.setMinTemp(Tranges.front());
158  thermo.setMaxTemp(Tranges.back());
159  thermo.setParameters(regions);
160 }
161 
162 
163 void setupMu0(Mu0Poly& thermo, const AnyMap& node)
164 {
165  setupSpeciesThermo(thermo, node);
166  if (node.hasKey("T-min")) {
167  thermo.setMinTemp(node.convert("T-min", "K"));
168  }
169  if (node.hasKey("T-max")) {
170  thermo.setMaxTemp(node.convert("T-max", "K"));
171  }
172  bool dimensionless = node.getBool("dimensionless", false);
173  double h0 = node.convert("h0", "J/kmol", 0.0);
174  map<double, double> T_mu;
175  for (const auto& [T_str, mu] : node["data"]) {
176  double T = node.units().convertTo(fpValueCheck(T_str), "K");
177  if (dimensionless) {
178  T_mu[T] = mu.asDouble() * GasConstant * T;
179  } else {
180  T_mu[T] = node.units().convert(mu, "J/kmol");
181  }
182  }
183  thermo.setParameters(h0, T_mu);
184 }
185 
186 unique_ptr<SpeciesThermoInterpType> newSpeciesThermo(const AnyMap& node)
187 {
188  string model = node["model"].asString();
189  if (model == "NASA7") {
190  auto thermo = make_unique<NasaPoly2>();
191  setupNasaPoly(*thermo, node);
192  return thermo;
193  } else if (model == "Shomate") {
194  auto thermo = make_unique<ShomatePoly2>();
195  setupShomatePoly(*thermo, node);
196  return thermo;
197  } else if (model == "NASA9") {
198  auto thermo = make_unique<Nasa9PolyMultiTempRegion>();
199  setupNasa9Poly(*thermo, node);
200  return thermo;
201  } else if (model == "constant-cp") {
202  auto thermo = make_unique<ConstCpPoly>();
203  setupConstCp(*thermo, node);
204  return thermo;
205  } else if (model == "piecewise-Gibbs") {
206  auto thermo = make_unique<Mu0Poly>();
207  setupMu0(*thermo, node);
208  return thermo;
209  } else {
210  throw CanteraError("newSpeciesThermo",
211  "Unknown thermo model '{}'", model);
212  }
213 }
214 
215 }
Headers for the SpeciesThermoInterpType object that employs a constant heat capacity assumption (see ...
Header for a single-species standard state object derived from SpeciesThermoInterpType based on a pie...
Header for a general species thermodynamic property manager for a phase (see MultiSpeciesThermo).
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the N...
Header for a single-species standard state object derived from SpeciesThermoInterpType based on the S...
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
Header for unit conversion utilities, which are used to translate user input from input files (See In...
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
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.
Definition: ctexceptions.h:66
A constant-heat capacity species thermodynamic property manager class.
Definition: ConstCpPoly.h:45
The Mu0Poly class implements an interpolation of the Gibbs free energy based on a piecewise constant ...
Definition: Mu0Poly.h:74
The NASA 9 polynomial parameterization for a single species encompassing multiple temperature regions...
The NASA polynomial parameterization for one temperature range.
Definition: NasaPoly1.h:48
The NASA polynomial parameterization for two temperature ranges.
Definition: NasaPoly2.h:49
The Shomate polynomial parameterization for two temperature ranges for one species.
Definition: ShomatePoly.h:233
The Shomate polynomial parameterization for one temperature range for one species.
Definition: ShomatePoly.h:59
Abstract Base class for the thermodynamic manager for an individual species' reference state.
double fpValueCheck(const string &val)
Translate a string into one double value, with error checking.
string toLowerCopy(const string &input)
Convert to lower case.
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:96
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:120
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564
unique_ptr< SpeciesThermoInterpType > newSpeciesThermo(const AnyMap &node)
Create a new SpeciesThermoInterpType object using the specified parameters.
SpeciesThermoInterpType * newSpeciesThermoInterpType(int type, double tlow, double thigh, double pref, const double *coeffs)
Create a new SpeciesThermoInterpType object given a corresponding constant.
Contains const definitions for types of species reference-state thermodynamics managers (see Species ...
#define NASA1
7 coefficient NASA Polynomials This is implemented in the class NasaPoly1 in NasaPoly1....
#define CONSTANT_CP
Constant Cp.
#define MU0_INTERP
piecewise interpolation of mu0.
#define SHOMATE1
one region of Shomate Polynomials used in NIST database This is implemented in the NIST database.
#define NASA9MULTITEMP
9 coefficient NASA Polynomials in multiple temperature regions This is implemented in the class Nasa9...
#define NASA9
9 coefficient NASA Polynomials This is implemented in the class Nasa9Poly1 in Nasa9Poly1....
#define SHOMATE2
Two regions of Shomate Polynomials.
#define SIMPLE
Constant Cp thermo.
#define NASA2
Two regions of 7 coefficient NASA Polynomials This is implemented in the class NasaPoly2 in NasaPoly2...
Contains declarations for string manipulation functions within Cantera.