Cantera  2.1.2
VPSSMgr_General.cpp
Go to the documentation of this file.
1 /**
2  * @file VPSSMgr_General.cpp
3  * Definition file for a derived class that handles the calculation
4  * of standard state thermo properties for
5  * a set of species belonging to a single phase in a completely general
6  * but slow way (see \ref thermoprops and
7  * class \link Cantera::VPSSMgr_General VPSSMgr_General\endlink).
8  */
9 /*
10  * Copyright (2005) Sandia Corporation. Under the terms of
11  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
12  * U.S. Government retains certain rights in this software.
13  */
14 
16 #include "cantera/thermo/PDSS.h"
17 #include "cantera/base/xml.h"
18 #include "cantera/base/ctml.h"
26 
27 using namespace std;
28 
29 namespace Cantera
30 {
31 
32 VPSSMgr_General::VPSSMgr_General(VPStandardStateTP* vp_ptr,
33  SpeciesThermo* spth) :
34  VPSSMgr(vp_ptr, spth)
35 {
36  // Might want to do something other than holding this true.
37  // However, for the sake of getting this all up and running,
38  // will not go there for now.
41 }
42 
44  VPSSMgr(right.m_vptp_ptr, right.m_spthermo)
45 {
48  *this = right;
49 }
50 
52 {
53  if (&b == this) {
54  return *this;
55  }
57  /*
58  * Must fill in the shallow pointers. These must have already been transfered
59  * and stored in the owning VPStandardStateTP class. Note we are aware that at this point
60  * m_vptr_ptr may refer back to the wrong ThermoPhase object. However, the shallow copy
61  * performed here is consistent with the assignment operator's general functionality.
62  */
63  m_PDSS_ptrs.resize(m_kk);
64  for (size_t k = 0; k < m_kk; k++) {
65  m_PDSS_ptrs[k] = m_vptp_ptr->providePDSS(k);
66  }
67  return *this;
68 }
69 
71 {
72  return new VPSSMgr_General(*this);
73 }
74 
76 {
77  VPSSMgr::initAllPtrs(vp_ptr, sp_ptr);
78  /*
79  * Must fill in the shallow pointers. These must have already been transfered
80  * and stored in the owning VPStandardStateTP class.
81  */
82  m_PDSS_ptrs.resize(m_kk);
83  for (size_t k = 0; k < m_kk; k++) {
84  m_PDSS_ptrs[k] = m_vptp_ptr->providePDSS(k);
85  }
86 }
87 
89 {
91  for (size_t k = 0; k < m_kk; k++) {
92  PDSS* kPDSS = m_PDSS_ptrs[k];
93  kPDSS->setState_TP(m_tlast, m_plast);
94  m_h0_RT[k] = kPDSS->enthalpy_RT_ref();
95  m_s0_R[k] = kPDSS->entropy_R_ref();
96  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
97  m_cp0_R[k] = kPDSS->cp_R_ref();
98  m_V0[k] = kPDSS->molarVolume_ref();
99  }
100  }
101 }
102 
104 {
105  for (size_t k = 0; k < m_kk; k++) {
106  PDSS* kPDSS = m_PDSS_ptrs[k];
107  kPDSS->setState_TP(m_tlast, m_plast);
108  m_hss_RT[k] = kPDSS->enthalpy_RT();
109  m_sss_R[k] = kPDSS->entropy_R();
110  m_gss_RT[k] = m_hss_RT[k] - m_sss_R[k];
111  m_cpss_R[k] = kPDSS->cp_R();
112  m_Vss[k] = kPDSS->molarVolume();
113  }
114 }
115 
117 {
118  initLengths();
119 }
120 
121 void VPSSMgr_General::getGibbs_ref(doublereal* g) const
122 {
123  doublereal _rt = GasConstant * m_tlast;
125  std::copy(m_g0_RT.begin(), m_g0_RT.end(), g);
126  scale(g, g+m_kk, g, _rt);
127  } else {
128  for (size_t k = 0; k < m_kk; k++) {
129  PDSS* kPDSS = m_PDSS_ptrs[k];
130  kPDSS->setState_TP(m_tlast, m_plast);
131  double h0_RT = kPDSS->enthalpy_RT_ref();
132  double s0_R = kPDSS->entropy_R_ref();
133  g[k] = _rt * (h0_RT - s0_R);
134  }
135  }
136 }
137 
138 void
139 VPSSMgr_General::initThermoXML(XML_Node& phaseNode, const std::string& id)
140 {
141  VPSSMgr::initThermoXML(phaseNode, id);
142 }
143 
144 PDSS*
145 VPSSMgr_General::returnPDSS_ptr(size_t k, const XML_Node& speciesNode,
146  const XML_Node* const phaseNode_ptr, bool& doST)
147 {
148  PDSS* kPDSS = 0;
149  doST = true;
150  GeneralSpeciesThermo* genSpthermo = dynamic_cast<GeneralSpeciesThermo*>(m_spthermo);
151 
152 
153  const XML_Node* const ss = speciesNode.findByName("standardState");
154  if (!ss) {
155  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
156  kPDSS = new PDSS_IdealGas(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
157  return kPDSS;
158  }
159  std::string model = (*ss)["model"];
160  if (model == "constant_incompressible") {
161  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
162  kPDSS = new PDSS_ConstVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
163  if (!kPDSS) {
164  throw CanteraError("VPSSMgr_General::returnPDSS_ptr", "new PDSS_ConstVol failed");
165  }
166  } else if (model == "waterIAPWS" || model == "waterPDSS") {
167  // VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
168  kPDSS = new PDSS_Water(m_vptp_ptr, 0);
169  if (!genSpthermo) {
170  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
171  "failed dynamic cast");
172  }
173  genSpthermo->installPDSShandler(k, kPDSS, this);
174  m_useTmpRefStateStorage = false;
175  } else if (model == "HKFT") {
176  doST = false;
177  kPDSS = new PDSS_HKFT(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
178  if (!genSpthermo) {
179  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
180  "failed dynamic cast");
181  }
182  genSpthermo->installPDSShandler(k, kPDSS, this);
183 
184  } else if (model == "IonFromNeutral") {
185  if (!genSpthermo) {
186  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
187  "failed dynamic cast");
188  }
189  doST = false;
190  kPDSS = new PDSS_IonsFromNeutral(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
191  if (!kPDSS) {
192  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
193  "new PDSS_IonsFromNeutral failed");
194  }
195  genSpthermo->installPDSShandler(k, kPDSS, this);
196 
197  } else if (model == "constant" || model == "temperature_polynomial" || model == "density_temperature_polynomial") {
198  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
199  kPDSS = new PDSS_SSVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
200  if (!kPDSS) {
201  throw CanteraError("VPSSMgr_General::returnPDSS_ptr", "new PDSS_SSVol failed");
202  }
203  } else {
204  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
205  "unknown standard state formulation: " + model);
206  }
207  return kPDSS;
208 }
209 
210 PDSS*
211 VPSSMgr_General::createInstallPDSS(size_t k, const XML_Node& speciesNode,
212  const XML_Node* const phaseNode_ptr)
213 {
214  bool doST;
215  PDSS* kPDSS = returnPDSS_ptr(k, speciesNode, phaseNode_ptr, doST);
216  // VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
217  if (m_PDSS_ptrs.size() < k+1) {
218  m_PDSS_ptrs.resize(k+1, 0);
219  }
220  m_PDSS_ptrs[k] = kPDSS;
221  if ((k+1) >= m_kk) {
222  m_kk = k+1;
223  }
224 
225  doublereal minTemp = kPDSS->minTemp();
226  if (minTemp > m_minTemp) {
227  m_minTemp = minTemp;
228  }
229 
230  doublereal maxTemp = kPDSS->maxTemp();
231  if (maxTemp < m_maxTemp) {
232  m_maxTemp = maxTemp;
233  }
234 
235  doublereal p0 = kPDSS->refPressure();
236  if (k == 0) {
237  m_p0 = p0;
238  }
239  return kPDSS;
240 }
241 
243 {
244  PDSS* kPDSS = m_PDSS_ptrs[k];
245  return kPDSS->reportPDSSType();
246 }
247 
249 {
250  return cVPSSMGR_GENERAL;
251 }
252 }
vector_fp m_V0
Vector containing the species reference molar volumes.
Definition: VPSSMgr.h:778
PDSS * returnPDSS_ptr(size_t k, const XML_Node &speciesNode, const XML_Node *const phaseNode_ptr, bool &doST)
Local factory routine for the creation of PDSS objects.
doublereal m_minTemp
minimum temperature for the standard state calculations
Definition: VPSSMgr.h:742
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
virtual VPSSMgr_enumType reportVPSSMgrType() const
This utility function reports the type of manager for the calculation of ss properties.
bool m_useTmpRefStateStorage
Definition: VPSSMgr.h:751
void initLengths()
Initialize the lengths within the object.
Definition: VPSSMgr.cpp:366
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
VPSSMgr_General & operator=(const VPSSMgr_General &right)
Assignment operator.
Derived class for pressure dependent standard states of an ideal gas species.
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS.cpp:305
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:808
doublereal m_maxTemp
maximum temperature for the standard state calculations
Definition: VPSSMgr.h:745
doublereal maxTemp() const
return the minimum temperature
Definition: PDSS.h:375
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, SpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:238
VPSSMgr & operator=(const VPSSMgr &right)
Assignment operator.
Definition: VPSSMgr.cpp:67
VPSSMgr_General(VPStandardStateTP *vp_ptr, SpeciesThermo *spth)
Constructor.
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
Definition: VPSSMgr.cpp:468
bool m_useTmpStandardStateStorage
Definition: VPSSMgr.h:784
virtual void _updateStandardStateThermo()
Updates the standard state thermodynamic functions at the current T and P of the solution.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Finalize the thermo after all species have been entered.
Definition: VPSSMgr.cpp:393
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS.cpp:223
Variable pressure SS calculate for phases consisting of completing general representations.
Definition: mix_defs.h:149
size_t m_kk
Number of species in the phase.
Definition: VPSSMgr.h:716
std::vector< PDSS * > m_PDSS_ptrs
Shallow pointers containing the PDSS objects for the species in this phase.
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
Implementation of a pressure dependent standard state virtual function for a Pure Water Phase (see Sp...
doublereal refPressure() const
Return the reference pressure for this phase.
Definition: PDSS.h:365
doublereal minTemp() const
return the minimum temperature
Definition: PDSS.h:370
virtual void _updateRefStateThermo() const
Updates the reference state thermodynamic functions at the current T of the solution and the referenc...
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
const XML_Node * findByName(const std::string &nm, int depth=100000) const
This routine carries out a recursive search for an XML node based on the name of the node...
Definition: xml.cpp:754
Declarations for the class PDSS_IdealGas (pressure dependent standard state) which handles calculatio...
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS.cpp:241
vector_fp m_cp0_R
Vector containing the species reference constant pressure heat capacities at T = m_tlast and P = p_re...
Definition: VPSSMgr.h:763
Declarations for the virtual base class PDSS (pressure dependent standard state) which handles calcul...
A species thermodynamic property manager for a phase.
VPStandardStateTP * m_vptp_ptr
Variable pressure ThermoPhase object.
Definition: VPSSMgr.h:719
Class for pressure dependent standard states that use a constant volume model.
Definition: PDSS_ConstVol.h:26
virtual void getGibbs_ref(doublereal *g) const
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, SpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
Definition: VPSSMgr.cpp:125
Class for the liquid water pressure dependent standard state.
Definition: PDSS_Water.h:54
doublereal m_plast
The last pressure at which the Standard State thermodynamic properties were calculated at...
Definition: VPSSMgr.h:733
PDSS_enumType
Types of PDSS's.
Definition: mix_defs.h:119
Declarations for the class PDSS_SSVol (pressure dependent standard state) which handles calculations ...
Classes providing support for XML data files.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
virtual VPSSMgr * duplMyselfAsVPSSMgr() const
Duplication routine for objects which derive from VPSSMgr.
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual PDSS_enumType reportPDSSType(int index=-1) const
This utility function reports the type of parameterization used for the species with index number ind...
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
Definition: VPSSMgr.cpp:459
Class for pressure dependent standard states that uses a standard state volume model of some sort...
Definition: PDSS_SSVol.h:159
vector_fp m_Vss
Vector containing the species standard state volumes at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:814
vector_fp m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:790
vector_fp m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
Definition: VPSSMgr.h:796
vector_fp m_h0_RT
Definition: VPSSMgr.h:757
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS.cpp:264
Headers for a completely general species thermodynamic property manager for a phase (see Managers for...
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS.cpp:269
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:195
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:154
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:769
doublereal m_p0
Definition: VPSSMgr.h:739
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS.cpp:299
Declarations for the class PDSS_ConstVol (pressure dependent standard state) which handles calculatio...
Class for pressure dependent standard states corresponding to ionic solutes in electrolyte water...
Definition: PDSS_HKFT.h:32
SpeciesThermo * m_spthermo
Pointer to reference state thermo calculator.
Definition: VPSSMgr.h:725
Derived class for pressure dependent standard states of an ideal gas species.
Definition: PDSS_IdealGas.h:28
void installSTSpecies(size_t k, const XML_Node &speciesNode, const XML_Node *phaseNode_ptr)
Install specific content for species k in the reference-state thermodynamic SpeciesManager object...
Definition: VPSSMgr.cpp:440
doublereal m_tlast
The last temperature at which the standard state thermodynamic properties were calculated at...
Definition: VPSSMgr.h:729
Class that handles the calculation of standard state thermo properties for a set of species belonging...
vector_fp m_gss_RT
Vector containing the species Standard State Gibbs functions at T = m_tlast and P = m_plast...
Definition: VPSSMgr.h:802
Declarations for the class PDSS_IonsFromNeutral ( which handles calculations for a single ion in a fl...
virtual PDSS * createInstallPDSS(size_t k, const XML_Node &speciesNode, const XML_Node *const phaseNode_ptr)
Factory routine for the creation of PDSS objects that are then internally registered with this VPSSMg...
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS.cpp:398
PDSS_enumType reportPDSSType() const
Returns the type of the standard state parameterization.
Definition: PDSS.cpp:170
Declarations for the class PDSS_HKFT (pressure dependent standard state) which handles calculations f...
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS.cpp:311
vector_fp m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:775
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS.cpp:293
void installPDSShandler(size_t k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr)
Install a PDSS object to handle the reference state thermodynamics calculation.