Cantera  2.3.0
PDSS_IonsFromNeutral.cpp
Go to the documentation of this file.
1 /**
2  * @file PDSS_IonsFromNeutral.cpp
3  * Implementation of a pressure dependent standard state
4  * virtual function.
5  */
6 
7 // This file is part of Cantera. See License.txt in the top-level directory or
8 // at http://www.cantera.org/license.txt for license and copyright information.
9 
13 #include "cantera/base/ctml.h"
14 
15 using namespace std;
16 
17 namespace Cantera
18 {
19 PDSS_IonsFromNeutral::PDSS_IonsFromNeutral(VPStandardStateTP* tp, size_t spindex) :
20  PDSS(tp, spindex),
21  neutralMoleculePhase_(0),
22  numMult_(0),
23  add2RTln2_(true),
24  specialSpecies_(0)
25 {
26  m_pdssType = cPDSS_IONSFROMNEUTRAL;
27 }
28 
30  const std::string& inputFile, const std::string& id) :
31  PDSS(tp, spindex),
32  neutralMoleculePhase_(0),
33  numMult_(0),
34  add2RTln2_(true),
35  specialSpecies_(0)
36 {
37  warn_deprecated("PDSS_IonsFromNeutral constructor from XML input file",
38  "To be removed after Cantera 2.3.");
39  m_pdssType = cPDSS_IONSFROMNEUTRAL;
40  constructPDSSFile(tp, spindex, inputFile, id);
41 }
42 
44  const XML_Node& phaseRoot, bool spInstalled) :
45  PDSS(tp, spindex),
46  neutralMoleculePhase_(0),
47  numMult_(0),
48  add2RTln2_(true),
49  specialSpecies_(0)
50 {
51  if (!spInstalled) {
52  throw CanteraError("PDSS_IonsFromNeutral", "sp installing not done yet");
53  }
54  m_pdssType = cPDSS_IONSFROMNEUTRAL;
55  std::string id = "";
56  constructPDSSXML(tp, spindex, speciesNode, phaseRoot, id);
57 }
58 
60  PDSS(b)
61 {
62  // Use the assignment operator to do the brunt of the work for the copy
63  // constructor.
64  *this = b;
65 }
66 
67 PDSS_IonsFromNeutral& PDSS_IonsFromNeutral::operator=(const PDSS_IonsFromNeutral& b)
68 {
69  if (&b == this) {
70  return *this;
71  }
72 
73  PDSS::operator=(b);
74 
75  // The shallow pointer copy in the next step will be insufficient in most
76  // cases. However, its functionally the best we can do for this assignment
77  // operator. We fix up the pointer in the initAllPtrs() function.
78  neutralMoleculePhase_ = b.neutralMoleculePhase_;
79 
80  numMult_ = b.numMult_;
81  idNeutralMoleculeVec = b.idNeutralMoleculeVec;
82  factorVec = b.factorVec;
83  add2RTln2_ = b.add2RTln2_;
84  tmpNM = b.tmpNM;
85  specialSpecies_ = b.specialSpecies_;
86 
87  return *this;
88 }
89 
91 {
92  return new PDSS_IonsFromNeutral(*this);
93 }
94 
96  MultiSpeciesThermo* spthermo)
97 {
98  PDSS::initAllPtrs(tp, vpssmgr_ptr, spthermo);
99 
100  IonsFromNeutralVPSSTP* ionPhase = dynamic_cast<IonsFromNeutralVPSSTP*>(tp);
101  if (!ionPhase) {
102  throw CanteraError("PDSS_IonsFromNeutral::initAllPts", "Dynamic cast failed");
103  }
105 }
106 
108  const XML_Node& speciesNode,
109  const XML_Node& phaseNode, const std::string& id)
110 {
111  const XML_Node* tn = speciesNode.findByName("thermo");
112  if (!tn) {
113  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
114  "no thermo Node for species " + speciesNode.name());
115  }
116  if (!ba::iequals(tn->attrib("model"), "ionfromneutral")) {
117  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
118  "thermo model for species isn't IonsFromNeutral: "
119  + speciesNode.name());
120  }
121  const XML_Node* nsm = tn->findByName("neutralSpeciesMultipliers");
122  if (!nsm) {
123  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
124  "no Thermo::neutralSpeciesMultipliers Node for species " + speciesNode.name());
125  }
126 
127  IonsFromNeutralVPSSTP* ionPhase = dynamic_cast<IonsFromNeutralVPSSTP*>(tp);
128  if (!ionPhase) {
129  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML", "Dynamic cast failed");
130  }
132 
133  std::vector<std::string> key;
134  std::vector<std::string> val;
135  numMult_ = getPairs(*nsm, key, val);
137  factorVec.resize(numMult_);
139  for (size_t i = 0; i < numMult_; i++) {
141  factorVec[i] = fpValueCheck(val[i]);
142  }
143  specialSpecies_ = 0;
144  const XML_Node* ss = tn->findByName("specialSpecies");
145  if (ss) {
146  specialSpecies_ = 1;
147  }
148  const XML_Node* sss = tn->findByName("secondSpecialSpecies");
149  if (sss) {
150  specialSpecies_ = 2;
151  }
152  add2RTln2_ = true;
153  if (specialSpecies_ == 1) {
154  add2RTln2_ = false;
155  }
156 }
157 
159  const std::string& inputFile, const std::string& id)
160 {
161  warn_deprecated("PDSS_IonsFromNeutral::constructPDSSFile",
162  "To be removed after Cantera 2.3.");
163  if (inputFile.size() == 0) {
164  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile",
165  "input file is null");
166  }
167 
168  // The phase object automatically constructs an XML object. Use this object
169  // to store information.
170  XML_Node fxml;
171  fxml.build(findInputFile(inputFile));
172  XML_Node* fxml_phase = findXMLPhase(&fxml, id);
173  if (!fxml_phase) {
174  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile",
175  "ERROR: Can not find phase named " +
176  id + " in file named " + inputFile);
177  }
178 
179  XML_Node& speciesList = fxml_phase->child("speciesArray");
180  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
181  &fxml_phase->root());
182  const XML_Node* s = speciesDB->findByAttr("name", tp->speciesName(spindex));
183  constructPDSSXML(tp, spindex, *s, *fxml_phase, id);
184 }
185 
187 {
192 }
193 
195 {
197  doublereal val = 0.0;
198  for (size_t i = 0; i < numMult_; i++) {
199  size_t jNeut = idNeutralMoleculeVec[i];
200  val += factorVec[i] * tmpNM[jNeut];
201  }
202  return val;
203 }
204 
206 {
207  return (m_h0_RT_ptr[m_spindex] - 1.0) * GasConstant * m_temp;
208 }
209 
211 {
213  doublereal val = 0.0;
214  for (size_t i = 0; i < numMult_; i++) {
215  size_t jNeut = idNeutralMoleculeVec[i];
216  val += factorVec[i] * tmpNM[jNeut];
217  }
218  if (add2RTln2_) {
219  val -= 2.0 * log(2.0);
220  }
221  return val;
222 }
223 
225 {
227  doublereal val = 0.0;
228  for (size_t i = 0; i < numMult_; i++) {
229  size_t jNeut = idNeutralMoleculeVec[i];
230  val += factorVec[i] * tmpNM[jNeut];
231  }
232  if (add2RTln2_) {
233  val += 2.0 * log(2.0);
234  }
235  return val;
236 }
237 
238 doublereal PDSS_IonsFromNeutral::cp_R() const
239 {
241  doublereal val = 0.0;
242  for (size_t i = 0; i < numMult_; i++) {
243  size_t jNeut = idNeutralMoleculeVec[i];
244  val += factorVec[i] * tmpNM[jNeut];
245  }
246  return val;
247 }
248 
250 {
252  doublereal val = 0.0;
253  for (size_t i = 0; i < numMult_; i++) {
254  size_t jNeut = idNeutralMoleculeVec[i];
255  val += factorVec[i] * tmpNM[jNeut];
256  }
257  return val;
258 }
259 
261 {
262  return (m_pres * m_mw / (GasConstant * m_temp));
263 }
264 
266 {
268  doublereal val = 0.0;
269  for (size_t i = 0; i < numMult_; i++) {
270  size_t jNeut = idNeutralMoleculeVec[i];
271  val += factorVec[i] * tmpNM[jNeut];
272  }
273  if (add2RTln2_) {
274  val += 2.0 * log(2.0);
275  }
276  return val;
277 }
278 
280 {
282  doublereal val = 0.0;
283  for (size_t i = 0; i < numMult_; i++) {
284  size_t jNeut = idNeutralMoleculeVec[i];
285  val += factorVec[i] * tmpNM[jNeut];
286  }
287  return val;
288 }
289 
291 {
293  doublereal val = 0.0;
294  for (size_t i = 0; i < numMult_; i++) {
295  size_t jNeut = idNeutralMoleculeVec[i];
296  val += factorVec[i] * tmpNM[jNeut];
297  }
298  if (add2RTln2_) {
299  val -= 2.0 * log(2.0);
300  }
301  return val;
302 }
303 
305 {
307  doublereal val = 0.0;
308  for (size_t i = 0; i < numMult_; i++) {
309  size_t jNeut = idNeutralMoleculeVec[i];
310  val += factorVec[i] * tmpNM[jNeut];
311  }
312  return val;
313 }
314 
316 {
318  doublereal val = 0.0;
319  for (size_t i = 0; i < numMult_; i++) {
320  size_t jNeut = idNeutralMoleculeVec[i];
321  val += factorVec[i] * tmpNM[jNeut];
322  }
323  return val;
324 }
325 
327 {
328  // Obtain the temperature from the owning VPStandardStateTP object if you
329  // can.
331  return m_temp;
332 }
333 
335 {
336  m_temp = temp;
337 }
338 
339 void PDSS_IonsFromNeutral::setState_TP(doublereal temp, doublereal pres)
340 {
341  m_pres = pres;
342  m_temp = temp;
343 }
344 
345 void PDSS_IonsFromNeutral::setState_TR(doublereal temp, doublereal rho)
346 {
347 }
348 
349 }
virtual doublereal temperature() const
Return the current stored temperature.
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Definition: ThermoPhase.h:668
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature.
virtual void getStandardVolumes_ref(doublereal *vol) const
Get the molar volumes of the species reference states at the current T and P_ref of the solution...
Definition: ThermoPhase.h:736
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
std::vector< size_t > idNeutralMoleculeVec
Vector of species indices in the neutral molecule ThermoPhase.
doublereal temperature() const
Return the temperature stored in the object.
Definition: VPSSMgr.h:487
vector_fp factorVec
Stoichiometric coefficient for this species using the Neutral Molecule Species in the vector idNeutra...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
std::string name() const
Returns the name of the XML node.
Definition: xml.h:370
size_t numMult_
Number of neutral molecule species that make up the stoichiometric vector for this species...
XML_Node * findXMLPhase(XML_Node *root, const std::string &idtarget)
Search an XML_Node tree for a named phase XML_Node.
Definition: xml.cpp:1038
Derived class for pressure dependent standard states of an ideal gas species.
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
Definition: ThermoPhase.h:701
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
size_t speciesIndex(const std::string &name) const
Returns the index of a species named &#39;name&#39; within the Phase object.
Definition: Phase.cpp:251
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:228
virtual doublereal density() const
Return the standard state density at standard state.
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
std::string findInputFile(const std::string &name)
Find an input file.
Definition: global.cpp:155
Header for intermediate ThermoPhase object for phases which consist of ions whose thermodynamics is c...
doublereal * m_h0_RT_ptr
Reference state enthalpy divided by RT.
Definition: PDSS.h:586
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition: ThermoPhase.h:609
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution...
Definition: ThermoPhase.h:653
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:544
vector_fp tmpNM
Vector of length equal to the number of species in the neutral molecule phase.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
virtual void setTemperature(doublereal temp)
Set the internal temperature.
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:262
STL namespace.
VPSSMgr * m_vpssmgr_ptr
Pointer to the VPSS manager for this object.
Definition: PDSS.h:564
virtual doublereal refPressure(size_t k=npos) const
The reference-state pressure for species k.
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
size_t m_spindex
Species index in the ThermoPhase corresponding to this species.
Definition: PDSS.h:570
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
PDSS_enumType m_pdssType
Enumerated type describing the type of the PDSS object.
Definition: PDSS.h:538
virtual MultiSpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
Definition: ThermoPhase.h:724
virtual void initAllPtrs(VPStandardStateTP *vptp_ptr, VPSSMgr *vpssmgr_ptr, MultiSpeciesThermo *spthermo_ptr)
Initialize or Reinitialize all shallow pointers in the object.
Definition: PDSS.cpp:184
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:175
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition: ThermoPhase.h:589
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
void constructPDSSFile(VPStandardStateTP *vptp_ptr, size_t spindex, const std::string &inputFile, const std::string &id)
Initialization of a PDSS object using an input XML file.
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:267
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
void constructPDSSXML(VPStandardStateTP *vptp_ptr, size_t spindex, const XML_Node &speciesNode, const XML_Node &phaseNode, const std::string &id)
Initialization of a PDSS object using an XML tree.
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
int getPairs(const XML_Node &node, std::vector< std::string > &key, std::vector< std::string > &val)
This function interprets the value portion of an XML element as a series of "Pairs" separated by whit...
Definition: ctml.cpp:387
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
void build(const std::string &filename)
Populate the XML tree from an input file.
Definition: xml.cpp:716
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
PDSS_IonsFromNeutral(VPStandardStateTP *tp, size_t spindex)
Constructor.
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
const ThermoPhase * neutralMoleculePhase_
Pointer to the Neutral Molecule ThermoPhase object.
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:553
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature.
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:550
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition: ThermoPhase.h:641
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
XML_Node & child(const size_t n) const
Return a changeable reference to the n&#39;th child of the current node.
Definition: xml.cpp:546
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1025
virtual void initThermo()
Initialization routine for all of the shallow pointers.
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
Definition: ThermoPhase.h:679
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:500
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:176
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
VPStandardStateTP * m_tp
ThermoPhase which this species belongs to.
Definition: PDSS.h:561
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:541
virtual void initAllPtrs(VPStandardStateTP *vptp_ptr, VPSSMgr *vpssmgr_ptr, MultiSpeciesThermo *spthermo_ptr)
Initialize or Reinitialize all shallow pointers in the object.
PDSS & operator=(const PDSS &b)
Definition: PDSS.cpp:103
Contains declarations for string manipulation functions within Cantera.
virtual doublereal molarVolume() const
Return the molar volume at standard state.
MultiSpeciesThermo * m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:579
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition: ThermoPhase.h:599
XML_Node * findByAttr(const std::string &attr, const std::string &val, int depth=100000) const
This routine carries out a recursive search for an XML node based on an attribute of each XML node...
Definition: xml.cpp:661
A species thermodynamic property manager for a phase.
bool add2RTln2_
Add 2RTln2 to the entropy and Gibbs free energies for this species.
Namespace for the Cantera kernel.
Definition: application.cpp:29
Declarations for the class PDSS_IonsFromNeutral ( which handles calculations for a single ion in a fl...
ThermoPhase * neutralMoleculePhase_
This is a pointer to the neutral Molecule Phase.
doublereal fpValueCheck(const std::string &val)
Translate a string into one doublereal value, with error checking.
XML_Node * get_XML_NameID(const std::string &nameTarget, const std::string &file_ID, XML_Node *root)
This routine will locate an XML node in either the input XML tree or in another input file specified ...
Definition: global.cpp:252
int specialSpecies_
True if this species is the special species.
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:547
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:567