Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/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 {
124  std::copy(m_g0_RT.begin(), m_g0_RT.end(), g);
125  scale(g, g+m_kk, g, GasConstant * m_tlast);
126  } else {
127  for (size_t k = 0; k < m_kk; k++) {
128  PDSS* kPDSS = m_PDSS_ptrs[k];
129  kPDSS->setState_TP(m_tlast, m_plast);
130  double h0_RT = kPDSS->enthalpy_RT_ref();
131  double s0_R = kPDSS->entropy_R_ref();
132  g[k] = GasConstant * m_tlast * (h0_RT - s0_R);
133  }
134  }
135 }
136 
137 void
138 VPSSMgr_General::initThermoXML(XML_Node& phaseNode, const std::string& id)
139 {
140  VPSSMgr::initThermoXML(phaseNode, id);
141 }
142 
143 PDSS*
144 VPSSMgr_General::returnPDSS_ptr(size_t k, const XML_Node& speciesNode,
145  const XML_Node* const phaseNode_ptr, bool& doST)
146 {
147  PDSS* kPDSS = 0;
148  doST = true;
149  GeneralSpeciesThermo* genSpthermo = dynamic_cast<GeneralSpeciesThermo*>(m_spthermo);
150 
151 
152  const XML_Node* const ss = speciesNode.findByName("standardState");
153  if (!ss) {
154  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
155  kPDSS = new PDSS_IdealGas(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
156  return kPDSS;
157  }
158  std::string model = ss->attrib("model");
159  if (model == "constant_incompressible") {
160  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
161  kPDSS = new PDSS_ConstVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
162  if (!kPDSS) {
163  throw CanteraError("VPSSMgr_General::returnPDSS_ptr", "new PDSS_ConstVol failed");
164  }
165  } else if (model == "waterIAPWS" || model == "waterPDSS") {
166  kPDSS = new PDSS_Water(m_vptp_ptr, 0);
167  if (!genSpthermo) {
168  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
169  "failed dynamic cast");
170  }
171  genSpthermo->installPDSShandler(k, kPDSS, this);
172  m_useTmpRefStateStorage = false;
173  } else if (model == "HKFT") {
174  doST = false;
175  kPDSS = new PDSS_HKFT(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
176  if (!genSpthermo) {
177  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
178  "failed dynamic cast");
179  }
180  genSpthermo->installPDSShandler(k, kPDSS, this);
181 
182  } else if (model == "IonFromNeutral") {
183  if (!genSpthermo) {
184  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
185  "failed dynamic cast");
186  }
187  doST = false;
188  kPDSS = new PDSS_IonsFromNeutral(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
189  if (!kPDSS) {
190  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
191  "new PDSS_IonsFromNeutral failed");
192  }
193  genSpthermo->installPDSShandler(k, kPDSS, this);
194 
195  } else if (model == "constant" || model == "temperature_polynomial" || model == "density_temperature_polynomial") {
196  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
197  kPDSS = new PDSS_SSVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
198  if (!kPDSS) {
199  throw CanteraError("VPSSMgr_General::returnPDSS_ptr", "new PDSS_SSVol failed");
200  }
201  } else {
202  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
203  "unknown standard state formulation: " + model);
204  }
205  return kPDSS;
206 }
207 
208 PDSS*
209 VPSSMgr_General::createInstallPDSS(size_t k, const XML_Node& speciesNode,
210  const XML_Node* const phaseNode_ptr)
211 {
212  bool doST;
213  PDSS* kPDSS = returnPDSS_ptr(k, speciesNode, phaseNode_ptr, doST);
214  if (m_PDSS_ptrs.size() < k+1) {
215  m_PDSS_ptrs.resize(k+1, 0);
216  }
217  m_PDSS_ptrs[k] = kPDSS;
218  m_kk = std::max(m_kk, k+1);
219  m_minTemp = std::max(m_minTemp, kPDSS->minTemp());
220  m_maxTemp = std::min(m_maxTemp, kPDSS->maxTemp());
221 
222  doublereal p0 = kPDSS->refPressure();
223  if (k == 0) {
224  m_p0 = p0;
225  }
226  return kPDSS;
227 }
228 
230 {
231  return m_PDSS_ptrs[k]->reportPDSSType();
232 }
233 
235 {
236  return cVPSSMGR_GENERAL;
237 }
238 }
vector_fp m_V0
Vector containing the species reference molar volumes.
Definition: VPSSMgr.h:773
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:737
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:746
void initLengths()
Initialize the lengths within the object.
Definition: VPSSMgr.cpp:356
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:282
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:527
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:803
doublereal m_maxTemp
maximum temperature for the standard state calculations
Definition: VPSSMgr.h:740
doublereal maxTemp() const
return the minimum temperature
Definition: PDSS.h:365
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:235
VPSSMgr & operator=(const VPSSMgr &right)
Assignment operator.
Definition: VPSSMgr.cpp:61
VPSSMgr_General(VPStandardStateTP *vp_ptr, SpeciesThermo *spth)
Constructor.
bool m_useTmpStandardStateStorage
Definition: VPSSMgr.h:779
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:383
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS.cpp:212
Variable pressure SS calculate for phases consisting of completing general representations.
Definition: mix_defs.h:151
size_t m_kk
Number of species in the phase.
Definition: VPSSMgr.h:711
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:355
doublereal minTemp() const
return the minimum temperature
Definition: PDSS.h:360
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:135
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:742
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:227
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:758
A species thermodynamic property manager for a phase.
VPStandardStateTP * m_vptp_ptr
Variable pressure ThermoPhase object.
Definition: VPSSMgr.h:714
Class for pressure dependent standard states that use a constant volume model.
Definition: PDSS_ConstVol.h:23
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:119
Class for the liquid water pressure dependent standard state.
Definition: PDSS_Water.h:51
doublereal m_plast
The last pressure at which the Standard State thermodynamic properties were calculated at...
Definition: VPSSMgr.h:728
PDSS_enumType
Types of PDSS's.
Definition: mix_defs.h:121
Declarations for the class PDSS_SSVol (pressure dependent standard state) which handles calculations ...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
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...
Class for pressure dependent standard states that uses a standard state volume model of some sort...
Definition: PDSS_SSVol.h:156
vector_fp m_Vss
Vector containing the species standard state volumes at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:809
vector_fp m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:785
vector_fp m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
Definition: VPSSMgr.h:791
vector_fp m_h0_RT
Definition: VPSSMgr.h:752
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS.cpp:247
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:252
Header file for a derived class of ThermoPhase that handles variable pressure standard state methods ...
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:193
Templates for operations on vector-like objects.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:158
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:764
doublereal m_p0
Definition: VPSSMgr.h:734
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS.cpp:277
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:29
SpeciesThermo * m_spthermo
Pointer to reference state thermo calculator.
Definition: VPSSMgr.h:720
Derived class for pressure dependent standard states of an ideal gas species.
Definition: PDSS_IdealGas.h:25
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:394
doublereal m_tlast
The last temperature at which the standard state thermodynamic properties were calculated at...
Definition: VPSSMgr.h:724
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:797
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:362
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:287
vector_fp m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:770
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS.cpp:272
void installPDSShandler(size_t k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr)
Install a PDSS object to handle the reference state thermodynamics calculation.