Cantera  2.1.2
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  * Copyright (2005) Sandia Corporation. Under the terms of
10  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
11  * U.S. Government retains certain rights in this software.
12  */
13 
15 
16 #include "cantera/thermo/VPSSMgr.h"
17 #include "VPSSMgrFactory.h"
18 
20 
26 
32 
34 
35 #include "cantera/base/xml.h"
36 #include "cantera/base/ctml.h"
37 
38 using namespace ctml;
39 using namespace std;
40 
41 namespace Cantera
42 {
43 
44 VPSSMgrFactory* VPSSMgrFactory::s_factory = 0;
45 
46 // Defn of the static mutex variable that locks the VPSSMgr factory singleton
47 mutex_t VPSSMgrFactory::vpss_species_thermo_mutex;
48 
49 //! Examine the types of species thermo parameterizations, and return a flag indicating the type of parameterization
50 //! needed by the species.
51 /*!
52  * @param spDataNodeList Species Data XML node. This node contains a list
53  * of species XML nodes underneath it.
54  * @param has_nasa_idealGas Boolean indicating that one species has a NASA ideal gas standard state
55  * @param has_nasa_constVol Boolean indicating that one species has a NASA ideal solution standard state
56  * @param has_shomate_idealGas Boolean indicating that one species has a shomate ideal gas standard state
57  * @param has_shomate_constVol Boolean indicating that one species has a shomate ideal solution standard state
58  * @param has_simple_idealGas Boolean indicating that one species has a simple ideal gas standard state
59  * @param has_simple_constVol Boolean indicating that one species has a simple ideal solution standard state
60  * @param has_water Boolean indicating that one species has a water standard state
61  * @param has_tpx Boolean indicating that one species has a tpx standard state
62  * @param has_hptx Boolean indicating that one species has a htpx standard state
63  * @param has_other Boolean indicating that one species has different standard state than the ones listed above
64  *
65  * @todo Make sure that spDadta_node is species Data XML node by checking
66  * its name is speciesData
67  */
68 static void getVPSSMgrTypes(std::vector<XML_Node*> & spDataNodeList,
69  int& has_nasa_idealGas,
70  int& has_nasa_constVol,
71  int& has_shomate_idealGas,
72  int& has_shomate_constVol,
73  int& has_simple_idealGas,
74  int& has_simple_constVol,
75  int& has_water,
76  int& has_tpx,
77  int& has_hptx,
78  int& has_other)
79 {
80 
81  XML_Node* ss_ptr = 0;
82  string ssModel = "idealGas";
83  size_t ns = spDataNodeList.size();
84  for (size_t n = 0; n < ns; n++) {
85  bool ifound = false;
86  XML_Node* spNode = spDataNodeList[n];
87  if (spNode->hasChild("standardState")) {
88  const XML_Node& ssN = spNode->child("standardState");
89  string mm = ssN["model"];
90  if (mm == "waterIAPWS" || mm == "waterPDSS") {
91  has_water++;
92  ifound = true;
93  }
94  if (mm == "HKFT") {
95  has_hptx++;
96  ifound = true;
97  }
98  }
99  if (!ifound) {
100  if (spNode->hasChild("thermo")) {
101  const XML_Node& th = spNode->child("thermo");
102  if (spNode->hasChild("standardState")) {
103  ss_ptr = &(spNode->child("standardState"));
104  ssModel = ss_ptr->attrib("model");
105  }
106  if (th.hasChild("NASA")) {
107  if (ssModel == "idealGas") {
108  has_nasa_idealGas++;
109  } else if (ssModel == "constant_incompressible" ||
110  ssModel == "constantVolume") {
111  has_nasa_constVol++;
112  } else if (ssModel == "temperature_polynomial" ||
113  ssModel == "density_temperature_polynomial" ||
114  ssModel == "constant") {
115  has_other++;
116  } else {
117  throw UnknownVPSSMgrModel("getVPSSMgrTypes:",
118  spNode->attrib("name"));
119  }
120  ifound = true;
121  }
122  if (th.hasChild("Shomate")) {
123  if (ssModel == "idealGas") {
124  has_shomate_idealGas++;
125  } else if (ssModel == "constant_incompressible" ||
126  ssModel == "constantVolume") {
127  has_shomate_constVol++;
128  } else if (ssModel == "temperature_polynomial" ||
129  ssModel == "density_temperature_polynomial" ||
130  ssModel == "constant") {
131  has_other++;
132  } else {
133  throw UnknownVPSSMgrModel("getVPSSMgrTypes:",
134  spNode->attrib("name"));
135  }
136  ifound = true;
137  }
138  if (th.hasChild("const_cp")) {
139  if (ssModel == "idealGas") {
140  has_simple_idealGas++;
141  } else if (ssModel == "constant_incompressible" ||
142  ssModel == "constantVolume") {
143  has_simple_constVol++;
144  } else if (ssModel == "temperature_polynomial" ||
145  ssModel == "density_temperature_polynomial" ||
146  ssModel == "constant") {
147  has_other++;
148  } else {
149  throw UnknownVPSSMgrModel("getVPSSMgrTypes:",
150  spNode->attrib("name"));
151  }
152  ifound = true;
153  }
154  if (th.hasChild("poly")) {
155  if (th.child("poly")["order"] == "1") {
156  has_simple_constVol = 1;
157  ifound = true;
158  } else throw CanteraError("newSpeciesThermo",
159  "poly with order > 1 not yet supported");
160  }
161  if (th.hasChild("Mu0")) {
162  has_other++;
163  ifound = true;
164  }
165  if (th.hasChild("NASA9")) {
166  has_other++;
167  ifound = true;
168  }
169  if (th.hasChild("NASA9MULTITEMP")) {
170  has_other++;
171  ifound = true;
172  }
173  if (th.hasChild("adsorbate")) {
174  has_other++;
175  ifound = true;
176  }
177  if (th.hasChild("HKFT")) {
178  has_hptx++;
179  ifound = true;
180  }
181  } else {
182  throw UnknownVPSSMgrModel("getVPSSMgrTypes:",
183  spNode->attrib("name"));
184  }
185  }
186  }
187 }
188 
189 void VPSSMgrFactory::deleteFactory()
190 {
191  ScopedLock lock(vpss_species_thermo_mutex);
192  if (s_factory) {
193  delete s_factory;
194  s_factory = 0;
195  }
196 }
197 
199 VPSSMgrFactory::VPSSMgr_StringConversion(const std::string& ssModel) const
200 {
201  std::string lssModel = lowercase(ssModel);
202  VPSSMgr_enumType type;
203  if (lssModel == "idealgas") {
204  type = cVPSSMGR_IDEALGAS;
205  } else if (lssModel == "constvol") {
206  type = cVPSSMGR_CONSTVOL;
207  } else if (lssModel == "purefuild") {
208  type = cVPSSMGR_PUREFLUID;
209  } else if (lssModel == "water_constvol") {
211  } else if (lssModel == "water_hkft") {
212  type = cVPSSMGR_WATER_HKFT;
213  } else if (lssModel == "general") {
214  type = cVPSSMGR_GENERAL;
215  } else {
216  type = cVPSSMGR_UNDEF;
217  }
218  return type;
219 }
220 
221 VPSSMgr*
223  XML_Node* phaseNode_ptr,
224  std::vector<XML_Node*> & spDataNodeList)
225 {
226 
227  std::string ssManager="";
228  std::string vpssManager="";
229 
230  // First look for any explicit instructions within the XML Database
231  // for the standard state manager and the variable pressure
232  // standard state manager
233  if (phaseNode_ptr) {
234  if (phaseNode_ptr->hasChild("thermo")) {
235  const XML_Node& thermoNode = phaseNode_ptr->child("thermo");
236  if (thermoNode.hasChild("standardStateManager")) {
237  const XML_Node& ssNode = thermoNode.child("standardStateManager");
238  ssManager = ssNode["model"];
239  }
240  if (thermoNode.hasChild("variablePressureStandardStateManager")) {
241  const XML_Node& vpssNode = thermoNode.child("variablePressureStandardStateManager");
242  vpssManager = vpssNode["model"];
243  }
244  }
245  }
246 
247  // first get the reference state handler. If we have explicit instructions,
248  // use them to spawn the object.
249  SpeciesThermo* spth = 0;
250  if (ssManager != "") {
251  spth = newSpeciesThermoMgr(ssManager);
252  } else {
253  spth = newSpeciesThermoMgr(spDataNodeList);
254  }
255  vp_ptr->setSpeciesThermo(spth);
256 
257  // Next, if we have specific directions, use them to get the VPSSSMgr object
258  // and return immediately
259  if (vpssManager != "") {
260  VPSSMgr_enumType type = VPSSMgr_StringConversion(vpssManager);
261  return newVPSSMgr(type, vp_ptr);
262  }
263 
264  // Handle special cases based on the VPStandardState types
265  if (vp_ptr->eosType() == cVPSS_IdealGas) {
266  return new VPSSMgr_IdealGas(vp_ptr, spth);
267  } else if (vp_ptr->eosType() == cVPSS_ConstVol) {
268  return new VPSSMgr_ConstVol(vp_ptr, spth);
269  }
270 
271 
272  int inasaIG = 0, inasaCV = 0, ishomateIG = 0, ishomateCV = 0,
273  isimpleIG = 0, isimpleCV = 0,
274  iwater = 0, itpx = 0, iother = 0;
275  int ihptx = 0;
276 
277  try {
278  getVPSSMgrTypes(spDataNodeList, inasaIG, inasaCV, ishomateIG, ishomateCV,
279  isimpleIG, isimpleCV, iwater, itpx, ihptx, iother);
280  } catch (UnknownSpeciesThermoModel) {
281  iother = 1;
282  popError();
283  }
284 
285  if (iwater == 1) {
286  if (ihptx == 0) {
287  if (inasaIG || ishomateIG || isimpleIG) {
288  throw CanteraError("newVPSSMgr", "Ideal gas with liquid water");
289  } else {
290  return new VPSSMgr_Water_ConstVol(vp_ptr, spth);
291  }
292  } else {
293  if (inasaIG || ishomateIG || isimpleIG) {
294  throw CanteraError("newVPSSMgr", "Ideal gas with liquid water");
295  } else if (inasaCV || ishomateCV || isimpleCV) {
296  return new VPSSMgr_General(vp_ptr, spth);
297  } else {
298  return new VPSSMgr_Water_HKFT(vp_ptr, spth);
299  }
300  }
301  }
302  if (inasaCV || ishomateCV || isimpleCV) {
303  if (!inasaIG && !ishomateIG && !isimpleIG && !itpx && !ihptx && !iother) {
304  return new VPSSMgr_ConstVol(vp_ptr, spth);
305  }
306  }
307 
308  return new VPSSMgr_General(vp_ptr, spth);
309 }
310 
311 // I don't think this is currently used. However, this is a virtual
312 // function where additional capabilities may be added.
313 VPSSMgr*
315 {
316  SpeciesThermo& spthermoRef = vp_ptr->speciesThermo();
317  switch (type) {
318  case cVPSSMGR_IDEALGAS:
319  return new VPSSMgr_IdealGas(vp_ptr, &spthermoRef);
320  case cVPSSMGR_CONSTVOL:
321  return new VPSSMgr_ConstVol(vp_ptr, &spthermoRef);
322  case cVPSSMGR_PUREFLUID:
323  throw CanteraError("VPSSMgrFactory::newVPSSMgr",
324  "unimplemented");
326  return new VPSSMgr_Water_ConstVol(vp_ptr, &spthermoRef);
327  case cVPSSMGR_WATER_HKFT:
328  return new VPSSMgr_Water_HKFT(vp_ptr, &spthermoRef);
329  case cVPSSMGR_GENERAL:
330  return new VPSSMgr_General(vp_ptr, &spthermoRef);
331  case cVPSSMGR_UNDEF:
332  default:
333  throw UnknownVPSSMgrModel("VPSSMgrFactory::newVPSSMgr", int2str(type));
334  return 0;
335  }
336 }
337 
338 // I don't think this is currently used
341 {
342  if (f == 0) {
343  f = VPSSMgrFactory::factory();
344  }
345  return f->newVPSSMgr(type, vp_ptr);
346 }
347 
348 
350  XML_Node* phaseNode_ptr,
351  std::vector<XML_Node*> & spDataNodeList,
352  VPSSMgrFactory* f)
353 {
354  if (f == 0) {
355  f = VPSSMgrFactory::factory();
356  }
357  return f->newVPSSMgr(tp_ptr, phaseNode_ptr, spDataNodeList);
358 }
359 
360 }
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:40
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
void popError()
Discard the last error message.
Definition: global.cpp:161
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:534
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:238
Declaration file for a virtual base class that manages the calculation of standard state properties f...
Variable pressure SS calculate for phases consisting of real water as the first species and species o...
Definition: mix_defs.h:146
Declaration file for a derived class that handles the calculation of standard state thermo properties...
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...
Variable pressure SS calculate for phases consisting of completing general representations.
Definition: mix_defs.h:149
virtual int eosType() const
Equation of state type flag.
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:100
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...
Virtual base class for the calculation of multiple-species thermodynamic reference-state property man...
Variable pressure SS calculate for phases consisting of real water as the first species and species h...
Definition: mix_defs.h:143
std::string lowercase(const std::string &s)
Cast a copy of a string to lower case.
Definition: stringUtils.cpp:58
Constant Molar Volume e VPSS species thermo manager class.
Pure Virtual base class for the species thermo manager classes.
VPSSMgr_enumType
enum for VPSSMgr types that are responsible for calculating the species standard state and reference-...
Definition: mix_defs.h:133
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:584
SpeciesThermo * newSpeciesThermoMgr(int type, SpeciesThermoFactory *f)
Create a new species thermo manager instance, by specifying the type and (optionally) a pointer to th...
Contains const definitions for types of species reference-state thermodynamics managers (see Species ...
Declaration file for a derived class that handles the calculation of standard state thermo properties...
Throw a named error for an unknown or missing vpss species thermo model.
Variable pressure SS calculate for phases consisting all species having a constant molar volume prope...
Definition: mix_defs.h:139
Classes providing support for XML data files.
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:68
const int cVPSS_IdealGas
Variable Pressure Standard State ThermoPhase objects.
Definition: mix_defs.h:94
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 ...
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:574
Variable pressures SS calculator for ideal gas phases.
Definition: mix_defs.h:136
This file contains descriptions of templated subclasses of the virtual base class, SpeciesThermo, which includes SpeciesThermoDuo (see Managers for Calculating Reference-State Thermodynamics and class SpeciesThermoDuo)
Throw a named error for an unknown or missing species thermo model.
Header for factory to build instances of classes that manage the standard-state thermodynamic propert...
Headers for a completely general species thermodynamic property manager for a phase (see Managers for...
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
Declarations for a derived class for the calculation of multiple-species thermodynamic property manag...
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...
virtual SpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
void setSpeciesThermo(SpeciesThermo *spthermo)
Install a species thermodynamic property manager.
Class that handles the calculation of standard state thermo properties for a set of species belonging...
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...