Cantera  2.4.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 
20 PDSS_IonsFromNeutral::PDSS_IonsFromNeutral()
21  : neutralMoleculePhase_(0)
22  , numMult_(0)
23  , add2RTln2_(true)
24 {
25 }
26 
28 {
29  neutralMoleculePhase_ = dynamic_cast<IonsFromNeutralVPSSTP&>(*phase).getNeutralMoleculePhase();
30 }
31 
32 void PDSS_IonsFromNeutral::setNeutralSpeciesMultiplier(const std::string& species, double mult)
33 {
34  neutralSpeciesMultipliers_[species] = mult;
35  numMult_++;
36 }
37 
38 void PDSS_IonsFromNeutral::setSpecialSpecies(bool special) {
39  add2RTln2_ = !special;
40 }
41 
43 {
44  PDSS::setParametersFromXML(speciesNode);
45  const XML_Node* tn = speciesNode.findByName("thermo");
46  if (!tn) {
47  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
48  "no thermo Node for species " + speciesNode.name());
49  }
50  if (!caseInsensitiveEquals(tn->attrib("model"), "ionfromneutral")) {
51  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
52  "thermo model for species isn't IonsFromNeutral: "
53  + speciesNode.name());
54  }
55  const XML_Node* nsm = tn->findByName("neutralSpeciesMultipliers");
56  if (!nsm) {
57  throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
58  "no Thermo::neutralSpeciesMultipliers Node for species " + speciesNode.name());
59  }
60 
61  for (auto& species_mult : parseCompString(nsm->value())) {
62  setNeutralSpeciesMultiplier(species_mult.first, species_mult.second);
63  }
64 
65  if (tn->findByName("specialSpecies")) {
66  setSpecialSpecies();
67  }
68 }
69 
71 {
73  m_p0 = neutralMoleculePhase_->refPressure();
74  m_minTemp = neutralMoleculePhase_->minTemp();
75  m_maxTemp = neutralMoleculePhase_->maxTemp();
76  tmpNM.resize(neutralMoleculePhase_->nSpecies());
77  for (auto multiplier : neutralSpeciesMultipliers_) {
78  idNeutralMoleculeVec.push_back( neutralMoleculePhase_->speciesIndex(multiplier.first));
79  factorVec.push_back(multiplier.second);
80  }
81 }
82 
84 {
85  neutralMoleculePhase_->getEnthalpy_RT(tmpNM.data());
86  doublereal val = 0.0;
87  for (size_t i = 0; i < numMult_; i++) {
88  size_t jNeut = idNeutralMoleculeVec[i];
89  val += factorVec[i] * tmpNM[jNeut];
90  }
91  return val;
92 }
93 
95 {
96  return (m_h0_RT - 1.0) * GasConstant * m_temp;
97 }
98 
100 {
101  neutralMoleculePhase_->getEntropy_R(tmpNM.data());
102  doublereal val = 0.0;
103  for (size_t i = 0; i < numMult_; i++) {
104  size_t jNeut = idNeutralMoleculeVec[i];
105  val += factorVec[i] * tmpNM[jNeut];
106  }
107  if (add2RTln2_) {
108  val -= 2.0 * log(2.0);
109  }
110  return val;
111 }
112 
114 {
115  neutralMoleculePhase_->getGibbs_RT(tmpNM.data());
116  doublereal val = 0.0;
117  for (size_t i = 0; i < numMult_; i++) {
118  size_t jNeut = idNeutralMoleculeVec[i];
119  val += factorVec[i] * tmpNM[jNeut];
120  }
121  if (add2RTln2_) {
122  val += 2.0 * log(2.0);
123  }
124  return val;
125 }
126 
127 doublereal PDSS_IonsFromNeutral::cp_R() const
128 {
129  neutralMoleculePhase_->getCp_R(tmpNM.data());
130  doublereal val = 0.0;
131  for (size_t i = 0; i < numMult_; i++) {
132  size_t jNeut = idNeutralMoleculeVec[i];
133  val += factorVec[i] * tmpNM[jNeut];
134  }
135  return val;
136 }
137 
139 {
140  neutralMoleculePhase_->getStandardVolumes(tmpNM.data());
141  doublereal val = 0.0;
142  for (size_t i = 0; i < numMult_; i++) {
143  size_t jNeut = idNeutralMoleculeVec[i];
144  val += factorVec[i] * tmpNM[jNeut];
145  }
146  return val;
147 }
148 
150 {
151  return (m_pres * m_mw / (GasConstant * m_temp));
152 }
153 
155 {
156  neutralMoleculePhase_->getGibbs_RT_ref(tmpNM.data());
157  doublereal val = 0.0;
158  for (size_t i = 0; i < numMult_; i++) {
159  size_t jNeut = idNeutralMoleculeVec[i];
160  val += factorVec[i] * tmpNM[jNeut];
161  }
162  if (add2RTln2_) {
163  val += 2.0 * log(2.0);
164  }
165  return val;
166 }
167 
169 {
170  neutralMoleculePhase_->getEnthalpy_RT_ref(tmpNM.data());
171  doublereal val = 0.0;
172  for (size_t i = 0; i < numMult_; i++) {
173  size_t jNeut = idNeutralMoleculeVec[i];
174  val += factorVec[i] * tmpNM[jNeut];
175  }
176  return val;
177 }
178 
180 {
181  neutralMoleculePhase_->getEntropy_R_ref(tmpNM.data());
182  doublereal val = 0.0;
183  for (size_t i = 0; i < numMult_; i++) {
184  size_t jNeut = idNeutralMoleculeVec[i];
185  val += factorVec[i] * tmpNM[jNeut];
186  }
187  if (add2RTln2_) {
188  val -= 2.0 * log(2.0);
189  }
190  return val;
191 }
192 
194 {
195  neutralMoleculePhase_->getCp_R_ref(tmpNM.data());
196  doublereal val = 0.0;
197  for (size_t i = 0; i < numMult_; i++) {
198  size_t jNeut = idNeutralMoleculeVec[i];
199  val += factorVec[i] * tmpNM[jNeut];
200  }
201  return val;
202 }
203 
205 {
206  neutralMoleculePhase_->getStandardVolumes_ref(tmpNM.data());
207  doublereal val = 0.0;
208  for (size_t i = 0; i < numMult_; i++) {
209  size_t jNeut = idNeutralMoleculeVec[i];
210  val += factorVec[i] * tmpNM[jNeut];
211  }
212  return val;
213 }
214 
215 void PDSS_IonsFromNeutral::setState_TP(doublereal temp, doublereal pres)
216 {
217  m_pres = pres;
218  m_temp = temp;
219 }
220 
221 void PDSS_IonsFromNeutral::setState_TR(doublereal temp, doublereal rho)
222 {
223 }
224 
225 }
std::vector< size_t > idNeutralMoleculeVec
Vector of species indices in the neutral molecule ThermoPhase.
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...
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
virtual void initThermo()
Initialization routine.
Definition: PDSS.h:452
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.
Header for intermediate ThermoPhase object for phases which consist of ions whose thermodynamics is c...
virtual void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS.h:459
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:483
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 setState_TR(doublereal temp, doublereal rho)
Set the internal temperature and density.
void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
STL namespace.
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
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.
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
shared_ptr< ThermoPhase > neutralMoleculePhase_
Pointer to the Neutral Molecule ThermoPhase object.
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
std::string value() const
Return the value of an XML node as a string.
Definition: xml.cpp:449
void setParent(VPStandardStateTP *phase, size_t k)
Set the parent VPStandardStateTP object of this PDSS object.
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:492
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:489
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
Definition: stringUtils.cpp:60
virtual void initThermo()
Initialization routine.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:500
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
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:480
Contains declarations for string manipulation functions within Cantera.
virtual doublereal molarVolume() const
Return the molar volume at standard state.
double m_h0_RT
Reference state enthalpy divided by RT.
Definition: PDSS.h:536
bool add2RTln2_
Add 2RTln2 to the entropy and Gibbs free energies for this species.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
Declarations for the class PDSS_IonsFromNeutral ( which handles calculations for a single ion in a fl...
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:486
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:495