Cantera 2.6.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 https://cantera.org/license.txt for license and copyright information.
9
10#include "cantera/thermo/PDSS_IonsFromNeutral.h"
11#include "cantera/thermo/IonsFromNeutralVPSSTP.h"
12#include "cantera/base/stringUtils.h"
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
27 void PDSS_IonsFromNeutral::setParent(VPStandardStateTP* phase, size_t k)
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
42 void PDSS_IonsFromNeutral::setParametersFromXML(const XML_Node& speciesNode)
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
71 void PDSS_IonsFromNeutral::getParameters(AnyMap& eosNode) const
72{
73 PDSS::getParameters(eosNode);
74 eosNode["model"] = "ions-from-neutral-molecule";
75 if (!add2RTln2_) {
76 eosNode["special-species"] = true;
77 }
78 if (!neutralSpeciesMultipliers_.empty()) {
79 eosNode["multipliers"] = neutralSpeciesMultipliers_;
80 }
81}
82
83 void PDSS_IonsFromNeutral::initThermo()
84{
85 PDSS::initThermo();
86 if (m_input.getBool("special-species", false)) {
87 setSpecialSpecies();
88 }
89 if (m_input.hasKey("multipliers")) {
90 for (const auto& item : m_input["multipliers"].asMap<double>()) {
91 setNeutralSpeciesMultiplier(item.first, item.second);
92 }
93 }
94
95 m_p0 = neutralMoleculePhase_->refPressure();
96 m_minTemp = neutralMoleculePhase_->minTemp();
97 m_maxTemp = neutralMoleculePhase_->maxTemp();
98 tmpNM.resize(neutralMoleculePhase_->nSpecies());
99 for (auto multiplier : neutralSpeciesMultipliers_) {
100 idNeutralMoleculeVec.push_back( neutralMoleculePhase_->speciesIndex(multiplier.first));
101 factorVec.push_back(multiplier.second);
102 }
103}
104
105doublereal PDSS_IonsFromNeutral::enthalpy_RT() const
106{
107 neutralMoleculePhase_->getEnthalpy_RT(tmpNM.data());
108 doublereal val = 0.0;
109 for (size_t i = 0; i < numMult_; i++) {
110 size_t jNeut = idNeutralMoleculeVec[i];
111 val += factorVec[i] * tmpNM[jNeut];
112 }
113 return val;
114}
115
116doublereal PDSS_IonsFromNeutral::intEnergy_mole() const
117{
118 return (m_h0_RT - 1.0) * GasConstant * m_temp;
119}
120
121doublereal PDSS_IonsFromNeutral::entropy_R() const
122{
123 neutralMoleculePhase_->getEntropy_R(tmpNM.data());
124 doublereal val = 0.0;
125 for (size_t i = 0; i < numMult_; i++) {
126 size_t jNeut = idNeutralMoleculeVec[i];
127 val += factorVec[i] * tmpNM[jNeut];
128 }
129 if (add2RTln2_) {
130 val -= 2.0 * log(2.0);
131 }
132 return val;
133}
134
135doublereal PDSS_IonsFromNeutral::gibbs_RT() const
136{
137 neutralMoleculePhase_->getGibbs_RT(tmpNM.data());
138 doublereal val = 0.0;
139 for (size_t i = 0; i < numMult_; i++) {
140 size_t jNeut = idNeutralMoleculeVec[i];
141 val += factorVec[i] * tmpNM[jNeut];
142 }
143 if (add2RTln2_) {
144 val += 2.0 * log(2.0);
145 }
146 return val;
147}
148
149doublereal PDSS_IonsFromNeutral::cp_R() const
150{
151 neutralMoleculePhase_->getCp_R(tmpNM.data());
152 doublereal val = 0.0;
153 for (size_t i = 0; i < numMult_; i++) {
154 size_t jNeut = idNeutralMoleculeVec[i];
155 val += factorVec[i] * tmpNM[jNeut];
156 }
157 return val;
158}
159
160doublereal PDSS_IonsFromNeutral::molarVolume() const
161{
162 neutralMoleculePhase_->getStandardVolumes(tmpNM.data());
163 doublereal val = 0.0;
164 for (size_t i = 0; i < numMult_; i++) {
165 size_t jNeut = idNeutralMoleculeVec[i];
166 val += factorVec[i] * tmpNM[jNeut];
167 }
168 return val;
169}
170
171doublereal PDSS_IonsFromNeutral::density() const
172{
173 return (m_pres * m_mw / (GasConstant * m_temp));
174}
175
176doublereal PDSS_IonsFromNeutral::gibbs_RT_ref() const
177{
178 neutralMoleculePhase_->getGibbs_RT_ref(tmpNM.data());
179 doublereal val = 0.0;
180 for (size_t i = 0; i < numMult_; i++) {
181 size_t jNeut = idNeutralMoleculeVec[i];
182 val += factorVec[i] * tmpNM[jNeut];
183 }
184 if (add2RTln2_) {
185 val += 2.0 * log(2.0);
186 }
187 return val;
188}
189
190doublereal PDSS_IonsFromNeutral::enthalpy_RT_ref() const
191{
192 neutralMoleculePhase_->getEnthalpy_RT_ref(tmpNM.data());
193 doublereal val = 0.0;
194 for (size_t i = 0; i < numMult_; i++) {
195 size_t jNeut = idNeutralMoleculeVec[i];
196 val += factorVec[i] * tmpNM[jNeut];
197 }
198 return val;
199}
200
201doublereal PDSS_IonsFromNeutral::entropy_R_ref() const
202{
203 neutralMoleculePhase_->getEntropy_R_ref(tmpNM.data());
204 doublereal val = 0.0;
205 for (size_t i = 0; i < numMult_; i++) {
206 size_t jNeut = idNeutralMoleculeVec[i];
207 val += factorVec[i] * tmpNM[jNeut];
208 }
209 if (add2RTln2_) {
210 val -= 2.0 * log(2.0);
211 }
212 return val;
213}
214
215doublereal PDSS_IonsFromNeutral::cp_R_ref() const
216{
217 neutralMoleculePhase_->getCp_R_ref(tmpNM.data());
218 doublereal val = 0.0;
219 for (size_t i = 0; i < numMult_; i++) {
220 size_t jNeut = idNeutralMoleculeVec[i];
221 val += factorVec[i] * tmpNM[jNeut];
222 }
223 return val;
224}
225
226doublereal PDSS_IonsFromNeutral::molarVolume_ref() const
227{
228 neutralMoleculePhase_->getStandardVolumes_ref(tmpNM.data());
229 doublereal val = 0.0;
230 for (size_t i = 0; i < numMult_; i++) {
231 size_t jNeut = idNeutralMoleculeVec[i];
232 val += factorVec[i] * tmpNM[jNeut];
233 }
234 return val;
235}
236
237 void PDSS_IonsFromNeutral::setState_TP(doublereal temp, doublereal pres)
238{
239 neutralMoleculePhase_->setState_TP(temp, pres);
240 m_pres = pres;
241 m_temp = temp;
242}
243
244}
IonsFromNeutralVPSSTP.h
Header for intermediate ThermoPhase object for phases which consist of ions whose thermodynamics is c...
PDSS_IonsFromNeutral.h
Declarations for the class PDSS_IonsFromNeutral ( which handles calculations for a single ion in a fl...
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Cantera::AnyMap::getBool
bool getBool(const std::string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
Definition: AnyMap.cpp:1487
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::IonsFromNeutralVPSSTP
Definition: IonsFromNeutralVPSSTP.h:68
Cantera::PDSS_IonsFromNeutral::idNeutralMoleculeVec
std::vector< size_t > idNeutralMoleculeVec
Vector of species indices in the neutral molecule ThermoPhase.
Definition: PDSS_IonsFromNeutral.h:108
Cantera::PDSS_IonsFromNeutral::getParameters
virtual void getParameters(AnyMap &eosNode) const
Store the parameters needed to reconstruct a copy of this PDSS object.
Definition: PDSS_IonsFromNeutral.cpp:71
Cantera::PDSS_IonsFromNeutral::cp_R_ref
virtual doublereal cp_R_ref() const
Return the molar heat capacity divided by R at reference pressure.
Definition: PDSS_IonsFromNeutral.cpp:215
Cantera::PDSS_IonsFromNeutral::entropy_R
virtual doublereal entropy_R() const
Return the standard state entropy divided by RT.
Definition: PDSS_IonsFromNeutral.cpp:121
Cantera::PDSS_IonsFromNeutral::PDSS_IonsFromNeutral
PDSS_IonsFromNeutral()
Default constructor.
Definition: PDSS_IonsFromNeutral.cpp:20
Cantera::PDSS_IonsFromNeutral::factorVec
vector_fp factorVec
Stoichiometric coefficient for this species using the Neutral Molecule Species in the vector idNeutra...
Definition: PDSS_IonsFromNeutral.h:112
Cantera::PDSS_IonsFromNeutral::numMult_
size_t numMult_
Number of neutral molecule species that make up the stoichiometric vector for this species,...
Definition: PDSS_IonsFromNeutral.h:105
Cantera::PDSS_IonsFromNeutral::setState_TP
virtual void setState_TP(doublereal temp, doublereal pres)
Set the internal temperature and pressure.
Definition: PDSS_IonsFromNeutral.cpp:237
Cantera::PDSS_IonsFromNeutral::enthalpy_RT
virtual doublereal enthalpy_RT() const
Return the standard state molar enthalpy divided by RT.
Definition: PDSS_IonsFromNeutral.cpp:105
Cantera::PDSS_IonsFromNeutral::gibbs_RT
virtual doublereal gibbs_RT() const
Return the molar Gibbs free energy divided by RT.
Definition: PDSS_IonsFromNeutral.cpp:135
Cantera::PDSS_IonsFromNeutral::cp_R
virtual doublereal cp_R() const
Return the molar const pressure heat capacity divided by RT.
Definition: PDSS_IonsFromNeutral.cpp:149
Cantera::PDSS_IonsFromNeutral::molarVolume_ref
virtual doublereal molarVolume_ref() const
Return the molar volume at reference pressure.
Definition: PDSS_IonsFromNeutral.cpp:226
Cantera::PDSS_IonsFromNeutral::initThermo
virtual void initThermo()
Initialization routine.
Definition: PDSS_IonsFromNeutral.cpp:83
Cantera::PDSS_IonsFromNeutral::neutralMoleculePhase_
shared_ptr< ThermoPhase > neutralMoleculePhase_
Pointer to the Neutral Molecule ThermoPhase object.
Definition: PDSS_IonsFromNeutral.h:99
Cantera::PDSS_IonsFromNeutral::molarVolume
virtual doublereal molarVolume() const
Return the molar volume at standard state.
Definition: PDSS_IonsFromNeutral.cpp:160
Cantera::PDSS_IonsFromNeutral::setParametersFromXML
void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS_IonsFromNeutral.cpp:42
Cantera::PDSS_IonsFromNeutral::enthalpy_RT_ref
virtual doublereal enthalpy_RT_ref() const
Return the molar enthalpy divided by RT at reference pressure.
Definition: PDSS_IonsFromNeutral.cpp:190
Cantera::PDSS_IonsFromNeutral::setParent
void setParent(VPStandardStateTP *phase, size_t k)
Set the parent VPStandardStateTP object of this PDSS object.
Definition: PDSS_IonsFromNeutral.cpp:27
Cantera::PDSS_IonsFromNeutral::density
virtual doublereal density() const
Return the standard state density at standard state.
Definition: PDSS_IonsFromNeutral.cpp:171
Cantera::PDSS_IonsFromNeutral::tmpNM
vector_fp tmpNM
Vector of length equal to the number of species in the neutral molecule phase.
Definition: PDSS_IonsFromNeutral.h:121
Cantera::PDSS_IonsFromNeutral::entropy_R_ref
virtual doublereal entropy_R_ref() const
Return the molar entropy divided by R at reference pressure.
Definition: PDSS_IonsFromNeutral.cpp:201
Cantera::PDSS_IonsFromNeutral::gibbs_RT_ref
virtual doublereal gibbs_RT_ref() const
Return the molar Gibbs free energy divided by RT at reference pressure.
Definition: PDSS_IonsFromNeutral.cpp:176
Cantera::PDSS_IonsFromNeutral::add2RTln2_
bool add2RTln2_
Add 2RTln2 to the entropy and Gibbs free energies for this species.
Definition: PDSS_IonsFromNeutral.h:118
Cantera::PDSS_IonsFromNeutral::intEnergy_mole
virtual doublereal intEnergy_mole() const
Return the molar internal Energy in units of J kmol-1.
Definition: PDSS_IonsFromNeutral.cpp:116
Cantera::PDSS_Nondimensional::m_h0_RT
double m_h0_RT
Reference state enthalpy divided by RT.
Definition: PDSS.h:515
Cantera::PDSS::initThermo
virtual void initThermo()
Initialization routine.
Definition: PDSS.h:415
Cantera::PDSS::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &speciesNode)
Initialization routine for the PDSS object based on the speciesNode.
Definition: PDSS.h:434
Cantera::PDSS::m_pres
doublereal m_pres
State of the system - pressure.
Definition: PDSS.h:458
Cantera::PDSS::m_temp
doublereal m_temp
Current temperature used by the PDSS object.
Definition: PDSS.h:455
Cantera::PDSS::m_maxTemp
doublereal m_maxTemp
Maximum temperature.
Definition: PDSS.h:467
Cantera::PDSS::m_p0
doublereal m_p0
Reference state pressure of the species.
Definition: PDSS.h:461
Cantera::PDSS::m_mw
doublereal m_mw
Molecular Weight of the species.
Definition: PDSS.h:470
Cantera::PDSS::m_input
AnyMap m_input
Input data supplied via setParameters.
Definition: PDSS.h:474
Cantera::PDSS::getParameters
virtual void getParameters(AnyMap &eosNode) const
Store the parameters needed to reconstruct a copy of this PDSS object.
Definition: PDSS.h:424
Cantera::PDSS::m_minTemp
doublereal m_minTemp
Minimum temperature.
Definition: PDSS.h:464
Cantera::VPStandardStateTP
This is a filter class for ThermoPhase that implements some preparatory steps for efficiently handlin...
Definition: VPStandardStateTP.h:44
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::XML_Node::attrib
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:493
Cantera::XML_Node::name
std::string name() const
Returns the name of the XML node.
Definition: xml.h:371
Cantera::XML_Node::findByName
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:680
Cantera::XML_Node::value
std::string value() const
Return the value of an XML node as a string.
Definition: xml.cpp:442
ctml.h
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::caseInsensitiveEquals
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
Definition: stringUtils.cpp:266
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
Cantera::parseCompString
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:59
stringUtils.h
Contains declarations for string manipulation functions within Cantera.