Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
15 #include "cantera/base/ctml.h"
16 
17 #include <fstream>
18 
19 using namespace std;
20 
21 namespace Cantera
22 {
23 PDSS_IonsFromNeutral::PDSS_IonsFromNeutral(VPStandardStateTP* tp, size_t spindex) :
24  PDSS(tp, spindex),
25  neutralMoleculePhase_(0),
26  numMult_(0),
27  add2RTln2_(true),
28  specialSpecies_(0)
29 {
30  m_pdssType = cPDSS_IONSFROMNEUTRAL;
31 }
32 
34  const std::string& inputFile, const std::string& id) :
35  PDSS(tp, spindex),
36  neutralMoleculePhase_(0),
37  numMult_(0),
38  add2RTln2_(true),
39  specialSpecies_(0)
40 {
41  m_pdssType = cPDSS_IONSFROMNEUTRAL;
42  constructPDSSFile(tp, spindex, inputFile, id);
43 }
44 
46  const XML_Node& phaseRoot, bool spInstalled) :
47  PDSS(tp, spindex),
48  neutralMoleculePhase_(0),
49  numMult_(0),
50  add2RTln2_(true),
51  specialSpecies_(0)
52 {
53  if (!spInstalled) {
54  throw CanteraError("PDSS_IonsFromNeutral", "sp installing not done yet");
55  }
56  m_pdssType = cPDSS_IONSFROMNEUTRAL;
57  std::string id = "";
58  constructPDSSXML(tp, spindex, speciesNode, phaseRoot, id);
59 }
60 
62  PDSS(b)
63 {
64  /*
65  * Use the assignment operator to do the brunt
66  * of the work for the copy constructor.
67  */
68  *this = b;
69 }
70 
72 {
73  if (&b == this) {
74  return *this;
75  }
76 
77  PDSS::operator=(b);
78 
79  /*
80  * The shallow pointer copy in the next step will be insufficient in most cases. However, its
81  * functionally the best we can do for this assignment operator. We fix up the pointer in the
82  * initAllPtrs() function.
83  */
85 
86  numMult_ = b.numMult_;
88  factorVec = b.factorVec;
90  tmpNM = b.tmpNM;
92 
93  return *this;
94 }
95 
97 {
98  return new PDSS_IonsFromNeutral(*this);
99 }
100 
102  SpeciesThermo* spthermo)
103 {
104  PDSS::initAllPtrs(tp, vpssmgr_ptr, spthermo);
105 
106  IonsFromNeutralVPSSTP* ionPhase = dynamic_cast<IonsFromNeutralVPSSTP*>(tp);
107  if (!ionPhase) {
108  throw CanteraError("PDSS_IonsFromNeutral::initAllPts", "Dynamic cast failed");
109  }
111 }
112 
114  const XML_Node& speciesNode,
115  const XML_Node& phaseNode, const std::string& id)
116 {
117  const XML_Node* tn = speciesNode.findByName("thermo");
118  if (!tn) {
119  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
120  "no thermo Node for species " + speciesNode.name());
121  }
122  if (lowercase(tn->attrib("model")) != "ionfromneutral") {
123  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
124  "thermo model for species isn't IonsFromNeutral: "
125  + speciesNode.name());
126  }
127  const XML_Node* nsm = tn->findByName("neutralSpeciesMultipliers");
128  if (!nsm) {
129  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
130  "no Thermo::neutralSpeciesMultipliers Node for species " + speciesNode.name());
131  }
132 
133  IonsFromNeutralVPSSTP* ionPhase = dynamic_cast<IonsFromNeutralVPSSTP*>(tp);
134  if (!ionPhase) {
135  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML", "Dynamic cast failed");
136  }
138 
139  std::vector<std::string> key;
140  std::vector<std::string> val;
141 
142  numMult_ = getPairs(*nsm, key, val);
144  factorVec.resize(numMult_);
146 
147  for (size_t i = 0; i < numMult_; i++) {
149  factorVec[i] = fpValueCheck(val[i]);
150  }
151  specialSpecies_ = 0;
152  const XML_Node* ss = tn->findByName("specialSpecies");
153  if (ss) {
154  specialSpecies_ = 1;
155  }
156  const XML_Node* sss = tn->findByName("secondSpecialSpecies");
157  if (sss) {
158  specialSpecies_ = 2;
159  }
160  add2RTln2_ = true;
161  if (specialSpecies_ == 1) {
162  add2RTln2_ = false;
163  }
164 }
165 
167  const std::string& inputFile, const std::string& id)
168 {
169  if (inputFile.size() == 0) {
170  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile",
171  "input file is null");
172  }
173  std::string path = findInputFile(inputFile);
174  ifstream fin(path.c_str());
175  if (!fin) {
176  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile","could not open "
177  +path+" for reading.");
178  }
179  /*
180  * The phase object automatically constructs an XML object.
181  * Use this object to store information.
182  */
183 
184  XML_Node fxml;
185  fxml.build(fin);
186  XML_Node* fxml_phase = findXMLPhase(&fxml, id);
187  if (!fxml_phase) {
188  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile",
189  "ERROR: Can not find phase named " +
190  id + " in file named " + inputFile);
191  }
192 
193  XML_Node& speciesList = fxml_phase->child("speciesArray");
194  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
195  &(fxml_phase->root()));
196  const XML_Node* s = speciesDB->findByAttr("name", tp->speciesName(spindex));
197 
198  constructPDSSXML(tp, spindex, *s, *fxml_phase, id);
199 }
200 
202 {
207 }
208 
209 doublereal
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  return val;
219 }
220 
221 doublereal
223 {
224  return (m_h0_RT_ptr[m_spindex] - 1.0) * GasConstant * m_temp;
225 }
226 
227 doublereal
229 {
231  doublereal val = 0.0;
232  for (size_t i = 0; i < numMult_; i++) {
233  size_t jNeut = idNeutralMoleculeVec[i];
234  val += factorVec[i] * tmpNM[jNeut];
235  }
236  if (add2RTln2_) {
237  val -= 2.0 * log(2.0);
238  }
239  return val;
240 }
241 
242 doublereal
244 {
246  doublereal val = 0.0;
247  for (size_t i = 0; i < numMult_; i++) {
248  size_t jNeut = idNeutralMoleculeVec[i];
249  val += factorVec[i] * tmpNM[jNeut];
250  }
251  if (add2RTln2_) {
252  val += 2.0 * log(2.0);
253  }
254  return val;
255 }
256 
257 doublereal
259 {
261  doublereal val = 0.0;
262  for (size_t i = 0; i < numMult_; i++) {
263  size_t jNeut = idNeutralMoleculeVec[i];
264  val += factorVec[i] * tmpNM[jNeut];
265  }
266  return val;
267 }
268 
269 doublereal
271 {
273  doublereal val = 0.0;
274  for (size_t i = 0; i < numMult_; i++) {
275  size_t jNeut = idNeutralMoleculeVec[i];
276  val += factorVec[i] * tmpNM[jNeut];
277  }
278  return val;
279 }
280 
281 doublereal
283 {
284  return (m_pres * m_mw / (GasConstant * m_temp));
285 }
286 
287 doublereal
289 {
291  doublereal val = 0.0;
292  for (size_t i = 0; i < numMult_; i++) {
293  size_t jNeut = idNeutralMoleculeVec[i];
294  val += factorVec[i] * tmpNM[jNeut];
295  }
296  if (add2RTln2_) {
297  val += 2.0 * log(2.0);
298  }
299  return val;
300 }
301 
303 {
305  doublereal val = 0.0;
306  for (size_t i = 0; i < numMult_; i++) {
307  size_t jNeut = idNeutralMoleculeVec[i];
308  val += factorVec[i] * tmpNM[jNeut];
309  }
310  return val;
311 }
312 
314 {
316  doublereal val = 0.0;
317  for (size_t i = 0; i < numMult_; i++) {
318  size_t jNeut = idNeutralMoleculeVec[i];
319  val += factorVec[i] * tmpNM[jNeut];
320  }
321  if (add2RTln2_) {
322  val -= 2.0 * log(2.0);
323  }
324  return val;
325 }
326 
328 {
330  doublereal val = 0.0;
331  for (size_t i = 0; i < numMult_; i++) {
332  size_t jNeut = idNeutralMoleculeVec[i];
333  val += factorVec[i] * tmpNM[jNeut];
334  }
335  return val;
336 }
337 
339 {
341  doublereal val = 0.0;
342  for (size_t i = 0; i < numMult_; i++) {
343  size_t jNeut = idNeutralMoleculeVec[i];
344  val += factorVec[i] * tmpNM[jNeut];
345  }
346  return val;
347 }
348 
350 {
351  /*
352  * Obtain the temperature from the owning VPStandardStateTP object if you can.
353  */
355  return m_temp;
356 }
357 
359 {
360  m_temp = temp;
361 }
362 
363 void PDSS_IonsFromNeutral::setState_TP(doublereal temp, doublereal pres)
364 {
365  m_pres = pres;
366  m_temp = temp;
367 }
368 
369 void PDSS_IonsFromNeutral::setState_TR(doublereal temp, doublereal rho)
370 {
371 }
372 
373 }
doublereal temperature() const
Return the temperature stored in the object.
Definition: VPSSMgr.h:494
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:704
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:1108
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:604
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:527
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:680
Virtual base class for the classes that manage the calculation of standard state properties for all t...
Definition: VPSSMgr.h:235
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:156
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:611
virtual doublereal maxTemp(size_t k=npos) const =0
Maximum temperature.
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:565
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.
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:824
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:744
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:585
virtual void initAllPtrs(VPStandardStateTP *vptp_ptr, VPSSMgr *vpssmgr_ptr, SpeciesThermo *spthermo_ptr)
Initialize or Reinitialize all shallow pointers in the object.
Definition: PDSS.cpp:182
size_t m_spindex
Species index in the ThermoPhase corresponding to this species.
Definition: PDSS.h:595
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:73
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:559
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:789
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:573
std::vector< double > factorVec
Stoichiometric coefficient for this species using the Neutral Molecule Species in the vector idNeutra...
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
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:257
virtual void initThermo()
Initialization routine for all of the shallow pointers.
Definition: PDSS.cpp:173
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:800
std::string name() const
Returns the name of the XML node.
Definition: xml.h:394
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:732
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 entropy_R_ref() const
Return the molar entropy 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:417
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:99
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 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:574
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:571
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:861
PDSS_IonsFromNeutral & operator=(const PDSS_IonsFromNeutral &b)
Assignment operator.
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:265
virtual doublereal minTemp(size_t k=npos) const =0
Minimum temperature.
virtual void initThermo()
Initialization routine for all of the shallow pointers.
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:690
Virtual base class for a species with a pressure dependent standard state.
Definition: PDSS.h:193
std::vector< double > tmpNM
Vector of length equal to the number of species in the neutral molecule phase.
virtual doublereal temperature() const
Return the current stored temperature.
VPStandardStateTP * m_tp
ThermoPhase which this species belongs to.
Definition: PDSS.h:582
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:64
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:562
PDSS & operator=(const PDSS &b)
Assignment operator.
Definition: PDSS.cpp:104
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:849
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.
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1095
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:764
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:272
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.
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:700
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:568
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:590