Cantera  2.1.2
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  * Copyright (2006) Sandia Corporation. Under the terms of
8  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
9  * U.S. Government retains certain rights in this software.
10  */
11 
17 #include "cantera/base/ct_defs.h"
18 #include "cantera/base/xml.h"
19 #include "cantera/base/ctml.h"
20 
21 #include <fstream>
22 
23 using namespace std;
24 
25 namespace Cantera
26 {
27 PDSS_IonsFromNeutral::PDSS_IonsFromNeutral(VPStandardStateTP* tp, size_t spindex) :
28  PDSS(tp, spindex),
29  neutralMoleculePhase_(0),
30  numMult_(0),
31  add2RTln2_(true),
32  specialSpecies_(0)
33 {
34  m_pdssType = cPDSS_IONSFROMNEUTRAL;
35 }
36 
38  const std::string& inputFile, const std::string& id) :
39  PDSS(tp, spindex),
40  neutralMoleculePhase_(0),
41  numMult_(0),
42  add2RTln2_(true),
43  specialSpecies_(0)
44 {
45  m_pdssType = cPDSS_IONSFROMNEUTRAL;
46  constructPDSSFile(tp, spindex, inputFile, id);
47 }
48 
50  const XML_Node& phaseRoot, bool spInstalled) :
51  PDSS(tp, spindex),
52  neutralMoleculePhase_(0),
53  numMult_(0),
54  add2RTln2_(true),
55  specialSpecies_(0)
56 {
57  if (!spInstalled) {
58  throw CanteraError("PDSS_IonsFromNeutral", "sp installing not done yet");
59  }
60  m_pdssType = cPDSS_IONSFROMNEUTRAL;
61  std::string id = "";
62  constructPDSSXML(tp, spindex, speciesNode, phaseRoot, id);
63 }
64 
66  PDSS(b)
67 {
68  /*
69  * Use the assignment operator to do the brunt
70  * of the work for the copy constructor.
71  */
72  *this = b;
73 }
74 
76 {
77  if (&b == this) {
78  return *this;
79  }
80 
81  PDSS::operator=(b);
82 
83  /*
84  * The shallow pointer copy in the next step will be insufficient in most cases. However, its
85  * functionally the best we can do for this assignment operator. We fix up the pointer in the
86  * initAllPtrs() function.
87  */
89 
90  numMult_ = b.numMult_;
92  factorVec = b.factorVec;
94  tmpNM = b.tmpNM;
96 
97  return *this;
98 }
99 
101 {
102  return new PDSS_IonsFromNeutral(*this);
103 }
104 
106  SpeciesThermo* spthermo)
107 {
108  PDSS::initAllPtrs(tp, vpssmgr_ptr, spthermo);
109 
110  IonsFromNeutralVPSSTP* ionPhase = dynamic_cast<IonsFromNeutralVPSSTP*>(tp);
111  if (!ionPhase) {
112  throw CanteraError("PDSS_IonsFromNeutral::initAllPts", "Dynamic cast failed");
113  }
115 }
116 
118  const XML_Node& speciesNode,
119  const XML_Node& phaseNode, const std::string& id)
120 {
121  const XML_Node* tn = speciesNode.findByName("thermo");
122  if (!tn) {
123  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
124  "no thermo Node for species " + speciesNode.name());
125  }
126  std::string model = lowercase((*tn)["model"]);
127  if (model != "ionfromneutral") {
128  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
129  "thermo model for species isn't IonsFromNeutral: "
130  + speciesNode.name());
131  }
132  const XML_Node* nsm = tn->findByName("neutralSpeciesMultipliers");
133  if (!nsm) {
134  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
135  "no Thermo::neutralSpeciesMultipliers Node for species " + speciesNode.name());
136  }
137 
138  IonsFromNeutralVPSSTP* ionPhase = dynamic_cast<IonsFromNeutralVPSSTP*>(tp);
139  if (!ionPhase) {
140  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML", "Dynamic cast failed");
141  }
143 
144  std::vector<std::string> key;
145  std::vector<std::string> val;
146 
147  numMult_ = ctml::getPairs(*nsm, key, val);
149  factorVec.resize(numMult_);
151 
152  for (size_t i = 0; i < numMult_; i++) {
154  factorVec[i] = fpValueCheck(val[i]);
155  }
156  specialSpecies_ = 0;
157  const XML_Node* ss = tn->findByName("specialSpecies");
158  if (ss) {
159  specialSpecies_ = 1;
160  }
161  const XML_Node* sss = tn->findByName("secondSpecialSpecies");
162  if (sss) {
163  specialSpecies_ = 2;
164  }
165  add2RTln2_ = true;
166  if (specialSpecies_ == 1) {
167  add2RTln2_ = false;
168  }
169 }
170 
172  const std::string& inputFile, const std::string& id)
173 {
174  if (inputFile.size() == 0) {
175  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile",
176  "input file is null");
177  }
178  std::string path = findInputFile(inputFile);
179  ifstream fin(path.c_str());
180  if (!fin) {
181  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile","could not open "
182  +path+" for reading.");
183  }
184  /*
185  * The phase object automatically constructs an XML object.
186  * Use this object to store information.
187  */
188 
189  XML_Node* fxml = new XML_Node();
190  fxml->build(fin);
191  XML_Node* fxml_phase = findXMLPhase(fxml, id);
192  if (!fxml_phase) {
193  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile",
194  "ERROR: Can not find phase named " +
195  id + " in file named " + inputFile);
196  }
197 
198  XML_Node& speciesList = fxml_phase->child("speciesArray");
199  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
200  &(fxml_phase->root()));
201  const vector<string>&sss = tp->speciesNames();
202 
203  const XML_Node* s = speciesDB->findByAttr("name", sss[spindex]);
204 
205  constructPDSSXML(tp, spindex, *s, *fxml_phase, id);
206  delete fxml;
207 }
208 
209 void PDSS_IonsFromNeutral::initThermoXML(const XML_Node& phaseNode, const std::string& id)
210 {
211  PDSS::initThermoXML(phaseNode, id);
212 }
213 
215 {
218  m_p0 = sp.refPressure(m_spindex);
221 }
222 
223 doublereal
225 {
226  doublereal val = enthalpy_RT();
227  doublereal RT = GasConstant * m_temp;
228  return val * RT;
229 }
230 
231 doublereal
233 {
235  doublereal val = 0.0;
236  for (size_t i = 0; i < numMult_; i++) {
237  size_t jNeut = idNeutralMoleculeVec[i];
238  val += factorVec[i] * tmpNM[jNeut];
239  }
240  return val;
241 }
242 
243 doublereal
245 {
246  doublereal val = m_h0_RT_ptr[m_spindex] - 1.0;
247  doublereal RT = GasConstant * m_temp;
248  return val * RT;
249 }
250 
251 doublereal
253 {
254  doublereal val = entropy_R();
255  return val * GasConstant;
256 }
257 
258 doublereal
260 {
262  doublereal val = 0.0;
263  for (size_t i = 0; i < numMult_; i++) {
264  size_t jNeut = idNeutralMoleculeVec[i];
265  val += factorVec[i] * tmpNM[jNeut];
266  }
267  if (add2RTln2_) {
268  val -= 2.0 * log(2.0);
269  }
270  return val;
271 }
272 
273 doublereal
275 {
276  doublereal val = gibbs_RT();
277  doublereal RT = GasConstant * m_temp;
278  return val * RT;
279 }
280 
281 doublereal
283 {
285  doublereal val = 0.0;
286  for (size_t i = 0; i < numMult_; i++) {
287  size_t jNeut = idNeutralMoleculeVec[i];
288  val += factorVec[i] * tmpNM[jNeut];
289  }
290  if (add2RTln2_) {
291  val += 2.0 * log(2.0);
292  }
293  return val;
294 }
295 
296 doublereal
298 {
299  doublereal val = cp_R();
300  return val * GasConstant;
301 }
302 
303 doublereal
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 
315 doublereal
317 {
319  doublereal val = 0.0;
320  for (size_t i = 0; i < numMult_; i++) {
321  size_t jNeut = idNeutralMoleculeVec[i];
322  val += factorVec[i] * tmpNM[jNeut];
323  }
324  return val;
325 }
326 
327 doublereal
329 {
330  return (m_pres * m_mw / (GasConstant * m_temp));
331 }
332 
333 doublereal
335 {
336  throw CanteraError("PDSS_IonsFromNeutral::cv_mole()", "unimplemented");
337  return 0.0;
338 }
339 
340 doublereal
342 {
344  doublereal val = 0.0;
345  for (size_t i = 0; i < numMult_; i++) {
346  size_t jNeut = idNeutralMoleculeVec[i];
347  val += factorVec[i] * tmpNM[jNeut];
348  }
349  if (add2RTln2_) {
350  val += 2.0 * log(2.0);
351  }
352  return val;
353 }
354 
356 {
358  doublereal val = 0.0;
359  for (size_t i = 0; i < numMult_; i++) {
360  size_t jNeut = idNeutralMoleculeVec[i];
361  val += factorVec[i] * tmpNM[jNeut];
362  }
363  return val;
364 }
365 
367 {
369  doublereal val = 0.0;
370  for (size_t i = 0; i < numMult_; i++) {
371  size_t jNeut = idNeutralMoleculeVec[i];
372  val += factorVec[i] * tmpNM[jNeut];
373  }
374  if (add2RTln2_) {
375  val -= 2.0 * log(2.0);
376  }
377  return val;
378 }
379 
381 {
383  doublereal val = 0.0;
384  for (size_t i = 0; i < numMult_; i++) {
385  size_t jNeut = idNeutralMoleculeVec[i];
386  val += factorVec[i] * tmpNM[jNeut];
387  }
388  return val;
389 }
390 
392 {
394  doublereal val = 0.0;
395  for (size_t i = 0; i < numMult_; i++) {
396  size_t jNeut = idNeutralMoleculeVec[i];
397  val += factorVec[i] * tmpNM[jNeut];
398  }
399  return val;
400 }
401 
403 {
404  return m_pres;
405 }
406 
408 {
409  m_pres = p;
410 }
411 
413 {
414  throw CanteraError("PDSS_IonsFromNeutral::critTemperature()", "unimplemented");
415  return 0.0;
416 }
417 
419 {
420  throw CanteraError("PDSS_IonsFromNeutral::critPressure()", "unimplemented");
421  return 0.0;
422 }
423 
425 {
426  throw CanteraError("PDSS_IonsFromNeutral::critDensity()", "unimplemented");
427  return 0.0;
428 }
429 
430 doublereal PDSS_IonsFromNeutral::temperature() const
431 {
432  /*
433  * Obtain the temperature from the owning VPStandardStateTP object if you can.
434  */
436  return m_temp;
437 }
438 
440 {
441  m_temp = temp;
442 }
443 
444 void PDSS_IonsFromNeutral::setState_TP(doublereal temp, doublereal pres)
445 {
446  m_pres = pres;
447  m_temp = temp;
448 }
449 
450 void PDSS_IonsFromNeutral::setState_TR(doublereal temp, doublereal rho)
451 {
452 }
453 
454 doublereal PDSS_IonsFromNeutral::satPressure(doublereal t)
455 {
456  throw CanteraError("PDSS_IonsFromNeutral::satPressure()", "unimplemented");
457  /*NOTREACHED*/
458  return 0.0;
459 }
460 
461 }
doublereal temperature() const
Return the temperature stored in the object.
Definition: VPSSMgr.h:499
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:716
virtual doublereal gibbs_mole() const
Return the molar Gibbs free energy in units of J kmol-1.
std::vector< size_t > idNeutralMoleculeVec
Vector of species indices in the neutral molecule ThermoPhase.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
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:1104
Derived class for pressure dependent standard states of an ideal gas species.
SpeciesThermo * m_spthermo
Pointer to the species thermodynamic property manager.
Definition: PDSS.h:615
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:721
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:238
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:191
Header for intermediate ThermoPhase object for phases which consist of ions whose thermodynamics is c...
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
Definition: PDSS.cpp:175
doublereal * m_h0_RT_ptr
Reference state enthalpy divided by RT.
Definition: PDSS.h:622
virtual doublereal maxTemp(size_t k=npos) const =0
Maximum temperature.
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:576
virtual doublereal critPressure() const
critical pressure
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
virtual void setTemperature(doublereal temp)
Set the internal temperature.
virtual void setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
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:865
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
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:785
virtual doublereal molarVolume() const
Return the molar volume at standard state.
VPSSMgr * m_vpssmgr_ptr
Pointer to the VPSS manager for this object.
Definition: PDSS.h:596
virtual void initAllPtrs(VPStandardStateTP *vptp_ptr, VPSSMgr *vpssmgr_ptr, SpeciesThermo *spthermo_ptr)
Initialize or Reinitialize all shallow pointers in the object.
Definition: PDSS.cpp:192
virtual void initThermoXML(const XML_Node &phaseNode, const std::string &id)
Initialization routine for the PDSS object based on the phaseNode.
virtual doublereal satPressure(doublereal t)
saturation pressure
size_t m_spindex
Species index in the ThermoPhase corresponding to this species.
Definition: PDSS.h:606
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
std::string lowercase(const std::string &s)
Cast a copy of a string to lower case.
Definition: stringUtils.cpp:58
virtual doublereal density() const
Return the standard state density at standard state.
PDSS_enumType m_pdssType
Enumerated type describing the type of the PDSS object.
Definition: PDSS.h:570
virtual void initAllPtrs(VPStandardStateTP *vptp_ptr, VPSSMgr *vpssmgr_ptr, SpeciesThermo *spthermo_ptr)
Initialize or Reinitialize all shallow pointers in the object.
Pure Virtual base class for the species thermo manager classes.
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:830
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:584
std::vector< double > factorVec
Stoichiometric coefficient for this species using the Neutral Molecule Species in the vector idNeutra...
virtual void setPressure(doublereal pres)
Sets the pressure in the object.
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
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition: Phase.cpp:229
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:183
virtual doublereal entropy_mole() const
Return the molar entropy in units of J kmol-1 K-1.
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.
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 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:841
std::string name() const
Returns the name of the XML node.
Definition: xml.h:390
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
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:773
Classes providing support for XML data files.
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
virtual doublereal cv_mole() const
Return the molar const volume heat capacity in units of J kmol-1 K-1.
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
virtual doublereal refPressure(size_t k=npos) const =0
The reference-state pressure for species k.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
virtual doublereal enthalpy_mole() const
Return the molar enthalpy in units of J kmol-1.
int getPairs(const Cantera::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:527
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual doublereal critDensity() const
critical density
PDSS_IonsFromNeutral(VPStandardStateTP *tp, size_t spindex)
Constructor.
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
const ThermoPhase * neutralMoleculePhase_
Pointer to the Neutral Molecule ThermoPhase object.
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:585
virtual doublereal gibbs_RT_ref() const
Return the molar gibbs free energy divided by RT at reference pressure.
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:582
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:902
virtual doublereal cp_mole() const
Return the molar const pressure heat capacity in units of J kmol-1 K-1.
PDSS_IonsFromNeutral & operator=(const PDSS_IonsFromNeutral &b)
Assignment operator.
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
virtual doublereal minTemp(size_t k=npos) const =0
Minimum temperature.
virtual void initThermo()
Initialization routine for all of the shallow pointers.
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Definition: Phase.cpp:252
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:731
virtual doublereal critTemperature() const
critical temperature
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:195
std::vector< double > tmpNM
Vector of length equal to the number of species in the neutral molecule phase.
VPStandardStateTP * m_tp
ThermoPhase which this species belongs to.
Definition: PDSS.h:593
virtual PDSS * duplMyselfAsPDSS() const
Duplication routine for objects which inherit from PDSS.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:573
PDSS & operator=(const PDSS &b)
Assignment operator.
Definition: PDSS.cpp:110
Contains declarations for string manipulation functions within Cantera.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
Definition: ct_defs.h:36
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:890
virtual SpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
bool add2RTln2_
Add 2RTln2 to the entropy and Gibbs free energies for this species.
virtual doublereal pressure() const
Returns the pressure (Pa)
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1091
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.
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
void build(std::istream &f)
Main routine to create an tree-like representation of an XML file.
Definition: xml.cpp:776
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:271
int specialSpecies_
True if this species is the special species.
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:741
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:579
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:601