Cantera  2.3.0
VPSSMgrFactory.cpp
Go to the documentation of this file.
1 /**
2  * @file VPSSMgrFactory.cpp
3  * Definitions for factory to build instances of classes that manage the
4  * calculation of standard state properties for all the species in a phase
5  * (see \ref spthermo and class
6  * \link Cantera::VPSSMgrFactory VPSSMgrFactory\endlink);
7  */
8 
9 // This file is part of Cantera. See License.txt in the top-level directory or
10 // at http://www.cantera.org/license.txt for license and copyright information.
11 
12 #include "VPSSMgrFactory.h"
19 
23 #include "cantera/base/ctml.h"
24 
25 using namespace std;
26 
27 namespace Cantera
28 {
29 
30 VPSSMgrFactory* VPSSMgrFactory::s_factory = 0;
31 
32 // Defn of the static mutex variable that locks the VPSSMgr factory singleton
33 std::mutex VPSSMgrFactory::vpss_species_thermo_mutex;
34 
35 //! Examine the types of species thermo parameterizations, and return a flag
36 //! indicating the type of parameterization needed by the species.
37 /*!
38  * @param spDataNodeList Species Data XML node. This node contains a list
39  * of species XML nodes underneath it.
40  * @param has_nasa_idealGas Boolean indicating that one species has a
41  * NASA ideal gas standard state
42  * @param has_nasa_constVol Boolean indicating that one species has a
43  * NASA ideal solution standard state
44  * @param has_shomate_idealGas Boolean indicating that one species has a
45  * Shomate ideal gas standard state
46  * @param has_shomate_constVol Boolean indicating that one species has a
47  * Shomate ideal solution standard state
48  * @param has_simple_idealGas Boolean indicating that one species has a
49  * simple ideal gas standard state
50  * @param has_simple_constVol Boolean indicating that one species has a
51  * simple ideal solution standard state
52  * @param has_water Boolean indicating that one species has a
53  * water standard state
54  * @param has_tpx Boolean indicating that one species has a
55  * tpx standard state
56  * @param has_hptx Boolean indicating that one species has a
57  * htpx standard state
58  * @param has_other Boolean indicating that one species has
59  * different standard state than the ones listed above
60  *
61  * @todo Make sure that spDadta_node is species Data XML node by checking
62  * its name is speciesData
63  */
64 static void getVPSSMgrTypes(std::vector<XML_Node*> & spDataNodeList,
65  int& has_nasa_idealGas,
66  int& has_nasa_constVol,
67  int& has_shomate_idealGas,
68  int& has_shomate_constVol,
69  int& has_simple_idealGas,
70  int& has_simple_constVol,
71  int& has_water,
72  int& has_tpx,
73  int& has_hptx,
74  int& has_other)
75 {
76  string ssModel = "idealGas";
77  for (size_t n = 0; n < spDataNodeList.size(); n++) {
78  bool ifound = false;
79  XML_Node* spNode = spDataNodeList[n];
80  if (spNode->hasChild("standardState")) {
81  string mm = spNode->child("standardState")["model"];
82  if (mm == "waterIAPWS" || mm == "waterPDSS") {
83  has_water++;
84  ifound = true;
85  }
86  if (mm == "HKFT") {
87  has_hptx++;
88  ifound = true;
89  }
90  }
91  if (!ifound) {
92  if (spNode->hasChild("thermo")) {
93  const XML_Node& th = spNode->child("thermo");
94  if (spNode->hasChild("standardState")) {
95  ssModel = spNode->child("standardState")["model"];
96  }
97  if (th.hasChild("NASA")) {
98  if (ssModel == "idealGas") {
99  has_nasa_idealGas++;
100  } else if (ssModel == "constant_incompressible" ||
101  ssModel == "constantVolume") {
102  has_nasa_constVol++;
103  } else if (ssModel == "temperature_polynomial" ||
104  ssModel == "density_temperature_polynomial" ||
105  ssModel == "constant") {
106  has_other++;
107  } else {
108  throw CanteraError("getVPSSMgrTypes",
109  "Specified VPSSMgr model {} does not match any known type.",
110  spNode->attrib("name"));
111  }
112  ifound = true;
113  }
114  if (th.hasChild("Shomate")) {
115  if (ssModel == "idealGas") {
116  has_shomate_idealGas++;
117  } else if (ssModel == "constant_incompressible" ||
118  ssModel == "constantVolume") {
119  has_shomate_constVol++;
120  } else if (ssModel == "temperature_polynomial" ||
121  ssModel == "density_temperature_polynomial" ||
122  ssModel == "constant") {
123  has_other++;
124  } else {
125  throw CanteraError("getVPSSMgrTypes",
126  "Specified VPSSMgr model {} does not match any known type.",
127  spNode->attrib("name"));
128  }
129  ifound = true;
130  }
131  if (th.hasChild("const_cp")) {
132  if (ssModel == "idealGas") {
133  has_simple_idealGas++;
134  } else if (ssModel == "constant_incompressible" ||
135  ssModel == "constantVolume") {
136  has_simple_constVol++;
137  } else if (ssModel == "temperature_polynomial" ||
138  ssModel == "density_temperature_polynomial" ||
139  ssModel == "constant") {
140  has_other++;
141  } else {
142  throw CanteraError("getVPSSMgrTypes",
143  "Specified VPSSMgr model {} does not match any known type.",
144  spNode->attrib("name"));
145  }
146  ifound = true;
147  }
148  if (th.hasChild("poly")) {
149  if (th.child("poly")["order"] == "1") {
150  has_simple_constVol = 1;
151  ifound = true;
152  } else throw CanteraError("newSpeciesThermo",
153  "poly with order > 1 not yet supported");
154  }
155  if (th.hasChild("Mu0")) {
156  has_other++;
157  ifound = true;
158  }
159  if (th.hasChild("NASA9")) {
160  has_other++;
161  ifound = true;
162  }
163  if (th.hasChild("NASA9MULTITEMP")) {
164  has_other++;
165  ifound = true;
166  }
167  if (th.hasChild("adsorbate")) {
168  has_other++;
169  ifound = true;
170  }
171  if (th.hasChild("HKFT")) {
172  has_hptx++;
173  ifound = true;
174  }
175  } else {
176  throw CanteraError("getVPSSMgrTypes",
177  "Specified VPSSMgr model {} does not match any known type.",
178  spNode->attrib("name"));
179  }
180  }
181  }
182 }
183 
184 VPSSMgrFactory::VPSSMgrFactory()
185 {
186  reg("idealgas",
187  [] (VPStandardStateTP* tp, MultiSpeciesThermo* st) {
188  return new VPSSMgr_IdealGas(tp, st); });
189  reg("constvol",
190  [] (VPStandardStateTP* tp, MultiSpeciesThermo* st) {
191  return new VPSSMgr_ConstVol(tp, st); });
192  reg("water_constvol",
193  [] (VPStandardStateTP* tp, MultiSpeciesThermo* st) {
194  return new VPSSMgr_Water_ConstVol(tp, st); });
195  reg("water_hkft",
196  [] (VPStandardStateTP* tp, MultiSpeciesThermo* st) {
197  return new VPSSMgr_Water_HKFT(tp, st); });
198  reg("general",
199  [] (VPStandardStateTP* tp, MultiSpeciesThermo* st) {
200  return new VPSSMgr_General(tp, st); });
201 }
202 
203 void VPSSMgrFactory::deleteFactory()
204 {
205  std::unique_lock<std::mutex> lock(vpss_species_thermo_mutex);
206  delete s_factory;
207  s_factory = 0;
208 }
209 
211 VPSSMgrFactory::VPSSMgr_StringConversion(const std::string& ssModel) const
212 {
213  warn_deprecated("VPSSMgrFactory::VPSSMgr_StringConversion",
214  "To be removed after Cantera 2.3.");
215  std::string lssModel = ba::to_lower_copy(ssModel);
216  VPSSMgr_enumType type;
217  if (lssModel == "idealgas") {
218  type = cVPSSMGR_IDEALGAS;
219  } else if (lssModel == "constvol") {
220  type = cVPSSMGR_CONSTVOL;
221  } else if (lssModel == "purefuild") {
222  type = cVPSSMGR_PUREFLUID;
223  } else if (lssModel == "water_constvol") {
225  } else if (lssModel == "water_hkft") {
226  type = cVPSSMGR_WATER_HKFT;
227  } else if (lssModel == "general") {
228  type = cVPSSMGR_GENERAL;
229  } else {
230  type = cVPSSMGR_UNDEF;
231  }
232  return type;
233 }
234 
236  XML_Node* phaseNode_ptr,
237  std::vector<XML_Node*> & spDataNodeList)
238 {
239  std::string ssManager;
240  std::string vpssManager;
241 
242  // First look for any explicit instructions within the XML Database for the
243  // standard state manager and the variable pressure standard state manager
244  if (phaseNode_ptr && phaseNode_ptr->hasChild("thermo")) {
245  const XML_Node& thermoNode = phaseNode_ptr->child("thermo");
246  if (thermoNode.hasChild("standardStateManager")) {
247  const XML_Node& ssNode = thermoNode.child("standardStateManager");
248  ssManager = ssNode["model"];
249  }
250  if (thermoNode.hasChild("variablePressureStandardStateManager")) {
251  const XML_Node& vpssNode = thermoNode.child("variablePressureStandardStateManager");
252  vpssManager = ba::to_lower_copy(vpssNode["model"]);
253  }
254  }
255 
256  // first get the reference state handler.
257  MultiSpeciesThermo* spth = &vp_ptr->speciesThermo();
258 
259  // Next, if we have specific directions, use them to get the VPSSSMgr object
260  // and return immediately
261  if (vpssManager != "") {
262  return create(vpssManager, vp_ptr, spth);
263  }
264 
265  int inasaIG = 0, inasaCV = 0, ishomateIG = 0, ishomateCV = 0,
266  isimpleIG = 0, isimpleCV = 0, iwater = 0, itpx = 0, iother = 0;
267  int ihptx = 0;
268 
269  try {
270  getVPSSMgrTypes(spDataNodeList, inasaIG, inasaCV, ishomateIG, ishomateCV,
271  isimpleIG, isimpleCV, iwater, itpx, ihptx, iother);
272  } catch (CanteraError) {
273  iother = 1;
274  }
275 
276  if (iwater == 1) {
277  if (ihptx == 0) {
278  if (inasaIG || ishomateIG || isimpleIG) {
279  throw CanteraError("newVPSSMgr", "Ideal gas with liquid water");
280  } else {
281  return new VPSSMgr_Water_ConstVol(vp_ptr, spth);
282  }
283  } else {
284  if (inasaIG || ishomateIG || isimpleIG) {
285  throw CanteraError("newVPSSMgr", "Ideal gas with liquid water");
286  } else if (inasaCV || ishomateCV || isimpleCV) {
287  return new VPSSMgr_General(vp_ptr, spth);
288  } else {
289  return new VPSSMgr_Water_HKFT(vp_ptr, spth);
290  }
291  }
292  }
293  if ((inasaCV || ishomateCV || isimpleCV) &&
294  !inasaIG && !ishomateIG && !isimpleIG && !itpx && !ihptx && !iother) {
295  return new VPSSMgr_ConstVol(vp_ptr, spth);
296  }
297  return new VPSSMgr_General(vp_ptr, spth);
298 }
299 
300 // I don't think this is currently used. However, this is a virtual
301 // function where additional capabilities may be added.
303  VPStandardStateTP* vp_ptr)
304 {
305  warn_deprecated("VPSSMgrFactory::newVPSSMgr(VPSSMgr_enumType, VPStandardStateTP*)",
306  "To be removed after Cantera 2.3.");
307  static unordered_map<int, std::string> types {
308  {cVPSSMGR_IDEALGAS, "idealgas"},
309  {cVPSSMGR_CONSTVOL, "constvol"},
310  {cVPSSMGR_WATER_CONSTVOL, "water_constvol"},
311  {cVPSSMGR_WATER_HKFT, "water_hkft"},
312  {cVPSSMGR_GENERAL, "general"}
313  };
314  MultiSpeciesThermo& spthermoRef = vp_ptr->speciesThermo();
315  return create(types.at(type), vp_ptr, &spthermoRef);
316 }
317 
318 // I don't think this is currently used
321 {
322  warn_deprecated("newVPSSMgr(VPSSMgr_enumType, VPStandardStateTP*, VPSSMgrFactory*)",
323  "To be removed after Cantera 2.3.");
324  if (f == 0) {
325  f = VPSSMgrFactory::factory();
326  }
327  return f->newVPSSMgr(type, vp_ptr);
328 }
329 
331  XML_Node* phaseNode_ptr,
332  std::vector<XML_Node*> & spDataNodeList,
333  VPSSMgrFactory* f)
334 {
335  if (f == 0) {
336  f = VPSSMgrFactory::factory();
337  } else {
338  warn_deprecated("newVPSSMgr(VPStandardStateTP*, XML_Node*, vector<XML_Node*>, VPSSMgrFactory*)",
339  "The `VPSSMgrFactory*` argument to this function is deprecated and"
340  " will be removed after Cantera 2.3.");
341  }
342  return f->newVPSSMgr(tp_ptr, phaseNode_ptr, spDataNodeList);
343 }
344 
345 }
Header for a general species thermodynamic property manager for a phase (see MultiSpeciesThermo).
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:228
Variable pressure SS calculate for phases consisting of real water as the first species and species o...
Definition: mix_defs.h:132
Declaration file for a derived class that handles the calculation of standard state thermo properties...
Variable pressure SS calculate for phases consisting of completing general representations.
Definition: mix_defs.h:135
Declaration file for a derived class that handles the calculation of standard state thermo properties...
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
VPSSMgr * newVPSSMgr(VPStandardStateTP *tp_ptr, XML_Node *phaseNode_ptr, std::vector< XML_Node *> &spDataNodeList, VPSSMgrFactory *f)
Function to return VPSSMgr manager.
Handles the calculation of standard state thermo properties for real water and a set of species which...
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
STL namespace.
Variable pressure SS calculate for phases consisting of real water as the first species and species h...
Definition: mix_defs.h:129
Constant Molar Volume e VPSS species thermo manager class.
virtual MultiSpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
VPSSMgr_enumType
enum for VPSSMgr types that are responsible for calculating the species standard state and reference-...
Definition: mix_defs.h:119
Declaration file for a derived class that handles the calculation of standard state thermo properties...
Variable pressure SS calculate for phases consisting all species having a constant molar volume prope...
Definition: mix_defs.h:125
Factory to build instances of classes that manage the standard-state thermodynamic properties of a se...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
static void getVPSSMgrTypes(std::vector< XML_Node *> &spDataNodeList, int &has_nasa_idealGas, int &has_nasa_constVol, int &has_shomate_idealGas, int &has_shomate_constVol, int &has_simple_idealGas, int &has_simple_constVol, int &has_water, int &has_tpx, int &has_hptx, int &has_other)
Examine the types of species thermo parameterizations, and return a flag indicating the type of param...
Manages standard state thermo properties for real water and a set of species which have the HKFT equa...
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
Variable pressures SS calculator for ideal gas phases.
Definition: mix_defs.h:122
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:536
XML_Node & child(const size_t n) const
Return a changeable reference to the n&#39;th child of the current node.
Definition: xml.cpp:546
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:500
Declarations for a derived class for the calculation of multiple-species thermodynamic property manag...
Contains declarations for string manipulation functions within Cantera.
A VPSSMgr where all species in the phase obey an ideal gas equation of state.
Header for factory to build instances of classes that manage the standard-state thermodynamic propert...
A species thermodynamic property manager for a phase.
Class that handles the calculation of standard state thermo properties for a set of species belonging...
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual VPSSMgr * newVPSSMgr(VPSSMgr_enumType type, VPStandardStateTP *vp_ptr)
Create a new species variable pressure standard state calculator.
Declaration file for a derived class that handles the calculation of standard state thermo properties...