Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
14 #include "VPSSMgrFactory.h"
21 
25 #include "cantera/base/ctml.h"
26 
27 using namespace std;
28 
29 namespace Cantera
30 {
31 
32 VPSSMgrFactory* VPSSMgrFactory::s_factory = 0;
33 
34 // Defn of the static mutex variable that locks the VPSSMgr factory singleton
35 mutex_t VPSSMgrFactory::vpss_species_thermo_mutex;
36 
37 //! Examine the types of species thermo parameterizations, and return a flag indicating the type of parameterization
38 //! needed by the species.
39 /*!
40  * @param spDataNodeList Species Data XML node. This node contains a list
41  * of species XML nodes underneath it.
42  * @param has_nasa_idealGas Boolean indicating that one species has a NASA ideal gas standard state
43  * @param has_nasa_constVol Boolean indicating that one species has a NASA ideal solution standard state
44  * @param has_shomate_idealGas Boolean indicating that one species has a Shomate ideal gas standard state
45  * @param has_shomate_constVol Boolean indicating that one species has a Shomate ideal solution standard state
46  * @param has_simple_idealGas Boolean indicating that one species has a simple ideal gas standard state
47  * @param has_simple_constVol Boolean indicating that one species has a simple ideal solution standard state
48  * @param has_water Boolean indicating that one species has a water standard state
49  * @param has_tpx Boolean indicating that one species has a tpx standard state
50  * @param has_hptx Boolean indicating that one species has a htpx standard state
51  * @param has_other Boolean indicating that one species has different standard state than the ones listed above
52  *
53  * @todo Make sure that spDadta_node is species Data XML node by checking
54  * its name is speciesData
55  */
56 static void getVPSSMgrTypes(std::vector<XML_Node*> & spDataNodeList,
57  int& has_nasa_idealGas,
58  int& has_nasa_constVol,
59  int& has_shomate_idealGas,
60  int& has_shomate_constVol,
61  int& has_simple_idealGas,
62  int& has_simple_constVol,
63  int& has_water,
64  int& has_tpx,
65  int& has_hptx,
66  int& has_other)
67 {
68 
69  string ssModel = "idealGas";
70  for (size_t n = 0; n < spDataNodeList.size(); n++) {
71  bool ifound = false;
72  XML_Node* spNode = spDataNodeList[n];
73  if (spNode->hasChild("standardState")) {
74  string mm = spNode->child("standardState")["model"];
75  if (mm == "waterIAPWS" || mm == "waterPDSS") {
76  has_water++;
77  ifound = true;
78  }
79  if (mm == "HKFT") {
80  has_hptx++;
81  ifound = true;
82  }
83  }
84  if (!ifound) {
85  if (spNode->hasChild("thermo")) {
86  const XML_Node& th = spNode->child("thermo");
87  if (spNode->hasChild("standardState")) {
88  ssModel = spNode->child("standardState")["model"];
89  }
90  if (th.hasChild("NASA")) {
91  if (ssModel == "idealGas") {
92  has_nasa_idealGas++;
93  } else if (ssModel == "constant_incompressible" ||
94  ssModel == "constantVolume") {
95  has_nasa_constVol++;
96  } else if (ssModel == "temperature_polynomial" ||
97  ssModel == "density_temperature_polynomial" ||
98  ssModel == "constant") {
99  has_other++;
100  } else {
101  throw UnknownVPSSMgrModel("getVPSSMgrTypes:",
102  spNode->attrib("name"));
103  }
104  ifound = true;
105  }
106  if (th.hasChild("Shomate")) {
107  if (ssModel == "idealGas") {
108  has_shomate_idealGas++;
109  } else if (ssModel == "constant_incompressible" ||
110  ssModel == "constantVolume") {
111  has_shomate_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("const_cp")) {
123  if (ssModel == "idealGas") {
124  has_simple_idealGas++;
125  } else if (ssModel == "constant_incompressible" ||
126  ssModel == "constantVolume") {
127  has_simple_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("poly")) {
139  if (th.child("poly")["order"] == "1") {
140  has_simple_constVol = 1;
141  ifound = true;
142  } else throw CanteraError("newSpeciesThermo",
143  "poly with order > 1 not yet supported");
144  }
145  if (th.hasChild("Mu0")) {
146  has_other++;
147  ifound = true;
148  }
149  if (th.hasChild("NASA9")) {
150  has_other++;
151  ifound = true;
152  }
153  if (th.hasChild("NASA9MULTITEMP")) {
154  has_other++;
155  ifound = true;
156  }
157  if (th.hasChild("adsorbate")) {
158  has_other++;
159  ifound = true;
160  }
161  if (th.hasChild("HKFT")) {
162  has_hptx++;
163  ifound = true;
164  }
165  } else {
166  throw UnknownVPSSMgrModel("getVPSSMgrTypes:",
167  spNode->attrib("name"));
168  }
169  }
170  }
171 }
172 
173 void VPSSMgrFactory::deleteFactory()
174 {
175  ScopedLock lock(vpss_species_thermo_mutex);
176  delete s_factory;
177  s_factory = 0;
178 }
179 
181 VPSSMgrFactory::VPSSMgr_StringConversion(const std::string& ssModel) const
182 {
183  std::string lssModel = lowercase(ssModel);
184  VPSSMgr_enumType type;
185  if (lssModel == "idealgas") {
186  type = cVPSSMGR_IDEALGAS;
187  } else if (lssModel == "constvol") {
188  type = cVPSSMGR_CONSTVOL;
189  } else if (lssModel == "purefuild") {
190  type = cVPSSMGR_PUREFLUID;
191  } else if (lssModel == "water_constvol") {
193  } else if (lssModel == "water_hkft") {
194  type = cVPSSMGR_WATER_HKFT;
195  } else if (lssModel == "general") {
196  type = cVPSSMGR_GENERAL;
197  } else {
198  type = cVPSSMGR_UNDEF;
199  }
200  return type;
201 }
202 
203 VPSSMgr*
205  XML_Node* phaseNode_ptr,
206  std::vector<XML_Node*> & spDataNodeList)
207 {
208 
209  std::string ssManager;
210  std::string vpssManager;
211 
212  // First look for any explicit instructions within the XML Database
213  // for the standard state manager and the variable pressure
214  // standard state manager
215  if (phaseNode_ptr) {
216  if (phaseNode_ptr->hasChild("thermo")) {
217  const XML_Node& thermoNode = phaseNode_ptr->child("thermo");
218  if (thermoNode.hasChild("standardStateManager")) {
219  const XML_Node& ssNode = thermoNode.child("standardStateManager");
220  ssManager = ssNode["model"];
221  }
222  if (thermoNode.hasChild("variablePressureStandardStateManager")) {
223  const XML_Node& vpssNode = thermoNode.child("variablePressureStandardStateManager");
224  vpssManager = vpssNode["model"];
225  }
226  }
227  }
228 
229  // first get the reference state handler.
230  SpeciesThermo* spth = new GeneralSpeciesThermo();
231  vp_ptr->setSpeciesThermo(spth);
232 
233  // Next, if we have specific directions, use them to get the VPSSSMgr object
234  // and return immediately
235  if (vpssManager != "") {
236  VPSSMgr_enumType type = VPSSMgr_StringConversion(vpssManager);
237  return newVPSSMgr(type, vp_ptr);
238  }
239 
240  // Handle special cases based on the VPStandardState types
241  if (vp_ptr->eosType() == cVPSS_IdealGas) {
242  return new VPSSMgr_IdealGas(vp_ptr, spth);
243  } else if (vp_ptr->eosType() == cVPSS_ConstVol) {
244  return new VPSSMgr_ConstVol(vp_ptr, spth);
245  }
246 
247 
248  int inasaIG = 0, inasaCV = 0, ishomateIG = 0, ishomateCV = 0,
249  isimpleIG = 0, isimpleCV = 0, iwater = 0, itpx = 0, iother = 0;
250  int ihptx = 0;
251 
252  try {
253  getVPSSMgrTypes(spDataNodeList, inasaIG, inasaCV, ishomateIG, ishomateCV,
254  isimpleIG, isimpleCV, iwater, itpx, ihptx, iother);
255  } catch (UnknownSpeciesThermoModel) {
256  iother = 1;
257  popError();
258  }
259 
260  if (iwater == 1) {
261  if (ihptx == 0) {
262  if (inasaIG || ishomateIG || isimpleIG) {
263  throw CanteraError("newVPSSMgr", "Ideal gas with liquid water");
264  } else {
265  return new VPSSMgr_Water_ConstVol(vp_ptr, spth);
266  }
267  } else {
268  if (inasaIG || ishomateIG || isimpleIG) {
269  throw CanteraError("newVPSSMgr", "Ideal gas with liquid water");
270  } else if (inasaCV || ishomateCV || isimpleCV) {
271  return new VPSSMgr_General(vp_ptr, spth);
272  } else {
273  return new VPSSMgr_Water_HKFT(vp_ptr, spth);
274  }
275  }
276  }
277  if (inasaCV || ishomateCV || isimpleCV) {
278  if (!inasaIG && !ishomateIG && !isimpleIG && !itpx && !ihptx && !iother) {
279  return new VPSSMgr_ConstVol(vp_ptr, spth);
280  }
281  }
282 
283  return new VPSSMgr_General(vp_ptr, spth);
284 }
285 
286 // I don't think this is currently used. However, this is a virtual
287 // function where additional capabilities may be added.
288 VPSSMgr*
290 {
291  SpeciesThermo& spthermoRef = vp_ptr->speciesThermo();
292  switch (type) {
293  case cVPSSMGR_IDEALGAS:
294  return new VPSSMgr_IdealGas(vp_ptr, &spthermoRef);
295  case cVPSSMGR_CONSTVOL:
296  return new VPSSMgr_ConstVol(vp_ptr, &spthermoRef);
297  case cVPSSMGR_PUREFLUID:
298  throw CanteraError("VPSSMgrFactory::newVPSSMgr",
299  "unimplemented");
301  return new VPSSMgr_Water_ConstVol(vp_ptr, &spthermoRef);
302  case cVPSSMGR_WATER_HKFT:
303  return new VPSSMgr_Water_HKFT(vp_ptr, &spthermoRef);
304  case cVPSSMGR_GENERAL:
305  return new VPSSMgr_General(vp_ptr, &spthermoRef);
306  case cVPSSMGR_UNDEF:
307  default:
308  throw UnknownVPSSMgrModel("VPSSMgrFactory::newVPSSMgr", int2str(type));
309  return 0;
310  }
311 }
312 
313 // I don't think this is currently used
316 {
317  if (f == 0) {
318  f = VPSSMgrFactory::factory();
319  }
320  return f->newVPSSMgr(type, vp_ptr);
321 }
322 
323 
325  XML_Node* phaseNode_ptr,
326  std::vector<XML_Node*> & spDataNodeList,
327  VPSSMgrFactory* f)
328 {
329  if (f == 0) {
330  f = VPSSMgrFactory::factory();
331  }
332  return f->newVPSSMgr(tp_ptr, phaseNode_ptr, spDataNodeList);
333 }
334 
335 }
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:39
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:126
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:527
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:235
Variable pressure SS calculate for phases consisting of real water as the first species and species o...
Definition: mix_defs.h:148
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:151
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...
Variable pressure SS calculate for phases consisting of real water as the first species and species h...
Definition: mix_defs.h:145
std::string lowercase(const std::string &s)
Cast a copy of a string to lower case.
Definition: stringUtils.cpp:73
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:135
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:573
A species thermodynamic property manager for a phase.
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:141
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:99
const int cVPSS_IdealGas
Variable Pressure Standard State ThermoPhase objects.
Definition: mix_defs.h:96
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:563
Variable pressures SS calculator for ideal gas phases.
Definition: mix_defs.h:138
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 ...
virtual int eosType() const
Equation of state type flag.
Definition: ThermoPhase.h:142
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...
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...