Cantera  2.3.0
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 // This file is part of Cantera. See License.txt in the top-level directory or
11 // at http://www.cantera.org/license.txt for license and copyright information.
12 
14 #include "cantera/base/ctml.h"
22 #include "cantera/base/utilities.h"
23 
24 using namespace std;
25 
26 namespace Cantera
27 {
28 
29 VPSSMgr_General::VPSSMgr_General(VPStandardStateTP* vp_ptr,
30  MultiSpeciesThermo* spth) :
31  VPSSMgr(vp_ptr, spth)
32 {
33  // Might want to do something other than holding this true.
34  // However, for the sake of getting this all up and running,
35  // will not go there for now.
38 }
39 
41  VPSSMgr(right.m_vptp_ptr, right.m_spthermo)
42 {
45  *this = right;
46 }
47 
48 VPSSMgr_General& VPSSMgr_General::operator=(const VPSSMgr_General& b)
49 {
50  if (&b == this) {
51  return *this;
52  }
54 
55  // Must fill in the shallow pointers. These must have already been
56  // transfered and stored in the owning VPStandardStateTP class. Note we are
57  // aware that at this point m_vptr_ptr may refer back to the wrong
58  // ThermoPhase object. However, the shallow copy performed here is
59  // consistent with the assignment operator's general functionality.
60  m_PDSS_ptrs.resize(m_kk);
61  for (size_t k = 0; k < m_kk; k++) {
62  m_PDSS_ptrs[k] = m_vptp_ptr->providePDSS(k);
63  }
64  return *this;
65 }
66 
68 {
69  return new VPSSMgr_General(*this);
70 }
71 
73 {
74  VPSSMgr::initAllPtrs(vp_ptr, sp_ptr);
75 
76  // Must fill in the shallow pointers. These must have already been
77  // transfered and stored in the owning VPStandardStateTP class.
78  m_PDSS_ptrs.resize(m_kk);
79  for (size_t k = 0; k < m_kk; k++) {
80  m_PDSS_ptrs[k] = m_vptp_ptr->providePDSS(k);
81  }
82 }
83 
85 {
87  for (size_t k = 0; k < m_kk; k++) {
88  PDSS* kPDSS = m_PDSS_ptrs[k];
89  kPDSS->setState_TP(m_tlast, m_plast);
90  m_h0_RT[k] = kPDSS->enthalpy_RT_ref();
91  m_s0_R[k] = kPDSS->entropy_R_ref();
92  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
93  m_cp0_R[k] = kPDSS->cp_R_ref();
94  m_V0[k] = kPDSS->molarVolume_ref();
95  }
96  }
97 }
98 
100 {
101  for (size_t k = 0; k < m_kk; k++) {
102  PDSS* kPDSS = m_PDSS_ptrs[k];
103  kPDSS->setState_TP(m_tlast, m_plast);
104  m_hss_RT[k] = kPDSS->enthalpy_RT();
105  m_sss_R[k] = kPDSS->entropy_R();
106  m_gss_RT[k] = m_hss_RT[k] - m_sss_R[k];
107  m_cpss_R[k] = kPDSS->cp_R();
108  m_Vss[k] = kPDSS->molarVolume();
109  }
110 }
111 
113 {
114  initLengths();
115 }
116 
117 void VPSSMgr_General::getGibbs_ref(doublereal* g) const
118 {
120  std::copy(m_g0_RT.begin(), m_g0_RT.end(), g);
121  scale(g, g+m_kk, g, GasConstant * m_tlast);
122  } else {
123  for (size_t k = 0; k < m_kk; k++) {
124  PDSS* kPDSS = m_PDSS_ptrs[k];
125  kPDSS->setState_TP(m_tlast, m_plast);
126  double h0_RT = kPDSS->enthalpy_RT_ref();
127  double s0_R = kPDSS->entropy_R_ref();
128  g[k] = GasConstant * m_tlast * (h0_RT - s0_R);
129  }
130  }
131 }
132 
133 PDSS* VPSSMgr_General::returnPDSS_ptr(size_t k, const XML_Node& speciesNode,
134  const XML_Node* const phaseNode_ptr, bool& doST)
135 {
136  PDSS* kPDSS = 0;
137  doST = true;
138 
139  const XML_Node* const ss = speciesNode.findByName("standardState");
140  if (!ss) {
141  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
142  kPDSS = new PDSS_IdealGas(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
143  return kPDSS;
144  }
145  std::string model = ss->attrib("model");
146  if (model == "constant_incompressible") {
147  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
148  kPDSS = new PDSS_ConstVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
149  if (!kPDSS) {
150  throw CanteraError("VPSSMgr_General::returnPDSS_ptr", "new PDSS_ConstVol failed");
151  }
152  } else if (model == "waterIAPWS" || model == "waterPDSS") {
153  kPDSS = new PDSS_Water(m_vptp_ptr, 0);
154  m_spthermo->installPDSShandler(k, kPDSS, this);
155  m_useTmpRefStateStorage = false;
156  } else if (model == "HKFT") {
157  doST = false;
158  kPDSS = new PDSS_HKFT(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
159  m_spthermo->installPDSShandler(k, kPDSS, this);
160  } else if (model == "IonFromNeutral") {
161  doST = false;
162  kPDSS = new PDSS_IonsFromNeutral(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
163  if (!kPDSS) {
164  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
165  "new PDSS_IonsFromNeutral failed");
166  }
167  m_spthermo->installPDSShandler(k, kPDSS, this);
168  } else if (model == "constant" || model == "temperature_polynomial" || model == "density_temperature_polynomial") {
169  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
170  kPDSS = new PDSS_SSVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
171  if (!kPDSS) {
172  throw CanteraError("VPSSMgr_General::returnPDSS_ptr", "new PDSS_SSVol failed");
173  }
174  } else {
175  throw CanteraError("VPSSMgr_General::returnPDSS_ptr",
176  "unknown standard state formulation: " + model);
177  }
178  return kPDSS;
179 }
180 
181 PDSS* VPSSMgr_General::createInstallPDSS(size_t k, const XML_Node& speciesNode,
182  const XML_Node* const phaseNode_ptr)
183 {
184  bool doST;
185  PDSS* kPDSS = returnPDSS_ptr(k, speciesNode, phaseNode_ptr, doST);
186  if (m_PDSS_ptrs.size() < k+1) {
187  m_PDSS_ptrs.resize(k+1, 0);
188  }
189  m_PDSS_ptrs[k] = kPDSS;
190  m_kk = std::max(m_kk, k+1);
191  m_minTemp = std::max(m_minTemp, kPDSS->minTemp());
192  m_maxTemp = std::min(m_maxTemp, kPDSS->maxTemp());
193  doublereal p0 = kPDSS->refPressure();
194  if (k == 0) {
195  m_p0 = p0;
196  }
197  return kPDSS;
198 }
199 
201 {
202  warn_deprecated("VPSSMgr_General::reportPDSSType",
203  "To be removed after Cantera 2.3.");
204  return m_PDSS_ptrs[k]->reportPDSSType();
205 }
206 
208 {
209  warn_deprecated("VPSSMgr_General::reportVPSSMgrType",
210  "To be removed after Cantera 2.3.");
211  return cVPSSMGR_GENERAL;
212 }
213 }
vector_fp m_V0
Vector containing the species reference molar volumes.
Definition: VPSSMgr.h:753
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:727
bool m_useTmpRefStateStorage
boolean indicating whether temporary reference state storage is used -> default is false ...
Definition: VPSSMgr.h:734
void initLengths()
Initialize the lengths within the object.
Definition: VPSSMgr.cpp:337
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
Derived class for pressure dependent standard states of an ideal gas species.
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:695
vector_fp m_sss_R
Vector containing the species Standard State entropies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:773
doublereal m_maxTemp
maximum temperature for the standard state calculations
Definition: VPSSMgr.h:730
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:228
VPSSMgr & operator=(const VPSSMgr &right)
Definition: VPSSMgr.cpp:60
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS.cpp:281
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS.cpp:231
bool m_useTmpStandardStateStorage
boolean indicating whether temporary standard state storage is used -> default is false ...
Definition: VPSSMgr.h:757
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, MultiSpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
Definition: VPSSMgr.cpp:121
virtual void _updateStandardStateThermo()
Updates the standard state thermodynamic functions at the current T and P of the solution.
doublereal refPressure() const
Return the reference pressure for this phase.
Definition: PDSS.h:335
Variable pressure SS calculate for phases consisting of completing general representations.
Definition: mix_defs.h:135
size_t m_kk
Number of species in the phase.
Definition: VPSSMgr.h:704
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:97
Implementation of a pressure dependent standard state virtual function for a Pure Water Phase (see Sp...
void installPDSShandler(size_t k, PDSS *PDSS_ptr, VPSSMgr *vpssmgr_ptr)
Install a PDSS object to handle the reference state thermodynamics calculation.
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.
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS.cpp:251
doublereal maxTemp() const
return the minimum temperature
Definition: PDSS.h:345
VPSSMgr_enumType
enum for VPSSMgr types that are responsible for calculating the species standard state and reference-...
Definition: mix_defs.h:119
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS.cpp:291
VPSSMgr_General(VPStandardStateTP *vp_ptr, MultiSpeciesThermo *spth)
Constructor.
virtual VPSSMgr_enumType reportVPSSMgrType() const
This utility function reports the type of manager for the calculation of ss properties.
Declarations for the class PDSS_IdealGas (pressure dependent standard state) which handles calculatio...
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS.cpp:256
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:742
virtual VPSSMgr * duplMyselfAsVPSSMgr() const
Duplication routine for objects which derive from VPSSMgr.
VPStandardStateTP * m_vptp_ptr
Variable pressure ThermoPhase object.
Definition: VPSSMgr.h:707
MultiSpeciesThermo * m_spthermo
Pointer to reference state thermo calculator.
Definition: VPSSMgr.h:713
Class for pressure dependent standard states that use a constant volume model.
Definition: PDSS_ConstVol.h:22
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS.cpp:286
virtual void getGibbs_ref(doublereal *g) const
Class for the liquid water pressure dependent standard state.
Definition: PDSS_Water.h:49
doublereal m_plast
The last pressure at which the Standard State thermodynamic properties were calculated at...
Definition: VPSSMgr.h:721
PDSS_enumType
Types of PDSS&#39;s.
Definition: mix_defs.h:105
Declarations for the class PDSS_SSVol (pressure dependent standard state) which handles calculations ...
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS.cpp:216
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual void _updateRefStateThermo() const
Updates the reference state thermodynamic functions at the current T of the solution and the referenc...
Class for pressure dependent standard states that uses a standard state volume model of some sort...
Definition: PDSS_SSVol.h:163
vector_fp m_Vss
Vector containing the species standard state volumes at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:777
vector_fp m_hss_RT
Vector containing the species Standard State enthalpies at T = m_tlast and P = m_plast.
Definition: VPSSMgr.h:761
vector_fp m_cpss_R
Vector containing the species Standard State constant pressure heat capacities at T = m_tlast and P =...
Definition: VPSSMgr.h:765
vector_fp m_h0_RT
Vector containing the species reference enthalpies at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:738
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
virtual void initAllPtrs(VPStandardStateTP *vp_ptr, MultiSpeciesThermo *sp_ptr)
Initialize the internal shallow pointers in this object.
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:176
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:130
vector_fp m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:746
doublereal m_p0
Reference pressure (Pa) must be the same for all species - defaults to 1 atm.
Definition: VPSSMgr.h:724
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
doublereal minTemp() const
return the minimum temperature
Definition: PDSS.h:340
virtual PDSS_enumType reportPDSSType(int index=-1) const
This utility function reports the type of parameterization used for the species with index number ind...
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:27
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS.cpp:276
A species thermodynamic property manager for a phase.
Derived class for pressure dependent standard states of an ideal gas species.
Definition: PDSS_IdealGas.h:24
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:375
doublereal m_tlast
The last temperature at which the standard state thermodynamic properties were calculated at...
Definition: VPSSMgr.h:717
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
vector_fp m_gss_RT
Vector containing the species Standard State Gibbs functions at T = m_tlast and P = m_plast...
Definition: VPSSMgr.h:769
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:365
Declarations for the class PDSS_HKFT (pressure dependent standard state) which handles calculations f...
vector_fp m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
Definition: VPSSMgr.h:750