Cantera  2.5.1
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 https://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::setParametersFromXML",
48  "no 'thermo' Node for species '{}'", speciesNode.name());
49  }
50  if (!caseInsensitiveEquals(tn->attrib("model"), "ionfromneutral")) {
51  throw CanteraError("PDSS_IonsFromNeutral::setParametersFromXML",
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::setParametersFromXML",
58  "no 'Thermo::neutralSpeciesMultipliers' Node for species '{}'",
59  speciesNode.name());
60  }
61 
62  for (auto& species_mult : parseCompString(nsm->value())) {
63  setNeutralSpeciesMultiplier(species_mult.first, species_mult.second);
64  }
65 
66  if (tn->findByName("specialSpecies")) {
67  setSpecialSpecies();
68  }
69 }
70 
72 {
74  if (m_input.getBool("special-species", false)) {
75  setSpecialSpecies();
76  }
77  if (m_input.hasKey("multipliers")) {
78  for (const auto& item : m_input["multipliers"].asMap<double>()) {
79  setNeutralSpeciesMultiplier(item.first, item.second);
80  }
81  }
82 
83  m_p0 = neutralMoleculePhase_->refPressure();
84  m_minTemp = neutralMoleculePhase_->minTemp();
85  m_maxTemp = neutralMoleculePhase_->maxTemp();
86  tmpNM.resize(neutralMoleculePhase_->nSpecies());
87  for (auto multiplier : neutralSpeciesMultipliers_) {
88  idNeutralMoleculeVec.push_back( neutralMoleculePhase_->speciesIndex(multiplier.first));
89  factorVec.push_back(multiplier.second);
90  }
91 }
92 
94 {
95  neutralMoleculePhase_->getEnthalpy_RT(tmpNM.data());
96  doublereal val = 0.0;
97  for (size_t i = 0; i < numMult_; i++) {
98  size_t jNeut = idNeutralMoleculeVec[i];
99  val += factorVec[i] * tmpNM[jNeut];
100  }
101  return val;
102 }
103 
105 {
106  return (m_h0_RT - 1.0) * GasConstant * m_temp;
107 }
108 
110 {
111  neutralMoleculePhase_->getEntropy_R(tmpNM.data());
112  doublereal val = 0.0;
113  for (size_t i = 0; i < numMult_; i++) {
114  size_t jNeut = idNeutralMoleculeVec[i];
115  val += factorVec[i] * tmpNM[jNeut];
116  }
117  if (add2RTln2_) {
118  val -= 2.0 * log(2.0);
119  }
120  return val;
121 }
122 
124 {
125  neutralMoleculePhase_->getGibbs_RT(tmpNM.data());
126  doublereal val = 0.0;
127  for (size_t i = 0; i < numMult_; i++) {
128  size_t jNeut = idNeutralMoleculeVec[i];
129  val += factorVec[i] * tmpNM[jNeut];
130  }
131  if (add2RTln2_) {
132  val += 2.0 * log(2.0);
133  }
134  return val;
135 }
136 
137 doublereal PDSS_IonsFromNeutral::cp_R() const
138 {
139  neutralMoleculePhase_->getCp_R(tmpNM.data());
140  doublereal val = 0.0;
141  for (size_t i = 0; i < numMult_; i++) {
142  size_t jNeut = idNeutralMoleculeVec[i];
143  val += factorVec[i] * tmpNM[jNeut];
144  }
145  return val;
146 }
147 
149 {
150  neutralMoleculePhase_->getStandardVolumes(tmpNM.data());
151  doublereal val = 0.0;
152  for (size_t i = 0; i < numMult_; i++) {
153  size_t jNeut = idNeutralMoleculeVec[i];
154  val += factorVec[i] * tmpNM[jNeut];
155  }
156  return val;
157 }
158 
160 {
161  return (m_pres * m_mw / (GasConstant * m_temp));
162 }
163 
165 {
166  neutralMoleculePhase_->getGibbs_RT_ref(tmpNM.data());
167  doublereal val = 0.0;
168  for (size_t i = 0; i < numMult_; i++) {
169  size_t jNeut = idNeutralMoleculeVec[i];
170  val += factorVec[i] * tmpNM[jNeut];
171  }
172  if (add2RTln2_) {
173  val += 2.0 * log(2.0);
174  }
175  return val;
176 }
177 
179 {
180  neutralMoleculePhase_->getEnthalpy_RT_ref(tmpNM.data());
181  doublereal val = 0.0;
182  for (size_t i = 0; i < numMult_; i++) {
183  size_t jNeut = idNeutralMoleculeVec[i];
184  val += factorVec[i] * tmpNM[jNeut];
185  }
186  return val;
187 }
188 
190 {
191  neutralMoleculePhase_->getEntropy_R_ref(tmpNM.data());
192  doublereal val = 0.0;
193  for (size_t i = 0; i < numMult_; i++) {
194  size_t jNeut = idNeutralMoleculeVec[i];
195  val += factorVec[i] * tmpNM[jNeut];
196  }
197  if (add2RTln2_) {
198  val -= 2.0 * log(2.0);
199  }
200  return val;
201 }
202 
204 {
205  neutralMoleculePhase_->getCp_R_ref(tmpNM.data());
206  doublereal val = 0.0;
207  for (size_t i = 0; i < numMult_; i++) {
208  size_t jNeut = idNeutralMoleculeVec[i];
209  val += factorVec[i] * tmpNM[jNeut];
210  }
211  return val;
212 }
213 
215 {
216  neutralMoleculePhase_->getStandardVolumes_ref(tmpNM.data());
217  doublereal val = 0.0;
218  for (size_t i = 0; i < numMult_; i++) {
219  size_t jNeut = idNeutralMoleculeVec[i];
220  val += factorVec[i] * tmpNM[jNeut];
221  }
222  return val;
223 }
224 
225 void PDSS_IonsFromNeutral::setState_TP(doublereal temp, doublereal pres)
226 {
227  neutralMoleculePhase_->setState_TP(temp, pres);
228  m_pres = pres;
229  m_temp = temp;
230 }
231 
232 }
Header for intermediate ThermoPhase object for phases which consist of ions whose thermodynamics is c...
Declarations for the class PDSS_IonsFromNeutral ( which handles calculations for a single ion in a fl...
bool getBool(const std::string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
Definition: AnyMap.cpp:1034
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:984
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
std::vector< size_t > idNeutralMoleculeVec
Vector of species indices in the neutral molecule ThermoPhase.
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
vector_fp factorVec
Stoichiometric coefficient for this species using the Neutral Molecule Species in the vector idNeutra...
size_t numMult_
Number of neutral molecule species that make up the stoichiometric vector for this species,...
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
virtual void initThermo()
Initialization routine.
shared_ptr< ThermoPhase > neutralMoleculePhase_
Pointer to the Neutral Molecule ThermoPhase object.
virtual doublereal molarVolume() const
Return the molar volume at standard state.
void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
void setParent(VPStandardStateTP *phase, size_t k)
Set the parent VPStandardStateTP object of this PDSS object.
virtual doublereal density() const
Return the standard state density at standard state.
vector_fp tmpNM
Vector of length equal to the number of species in the neutral molecule phase.
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
bool add2RTln2_
Add 2RTln2 to the entropy and Gibbs free energies for this species.
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
double m_h0_RT
Reference state enthalpy divided by RT.
Definition: PDSS.h:524
virtual void initThermo()
Initialization routine.
Definition: PDSS.h:427
virtual void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS.h:443
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:467
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:464
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:476
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:470
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:479
AnyMap m_input
Input data supplied via setParameters.
Definition: PDSS.h:483
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:473
This is a filter class for ThermoPhase that implements some preparatory steps for efficiently handlin...
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:104
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:492
std::string name() const
Returns the name of the XML node.
Definition: xml.h:372
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:679
std::string value() const
Return the value of an XML node as a string.
Definition: xml.cpp:441
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:109
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
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
Contains declarations for string manipulation functions within Cantera.