Cantera  2.0
VPSSMgr_Water_ConstVol.cpp
Go to the documentation of this file.
1 /**
2  * @file VPSSMgr_Water_ConstVol.cpp
3  * Definition file for a derived class that handles the calculation
4  * of standard state thermo properties for pure water and
5  * a set of species which have a constant molar volume pressure
6  * dependence.
7  * (see \ref thermoprops and class
8  * \link Cantera::VPSSMgr_Water_ConstVol VPSSMgr_Water_ConstVol\endlink).
9  */
10 
11 /*
12  * Copyright (2005) Sandia Corporation. Under the terms of
13  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
14  * U.S. Government retains certain rights in this software.
15  */
16 
21 
22 using namespace std;
23 
24 namespace Cantera
25 {
26 
27 VPSSMgr_Water_ConstVol::VPSSMgr_Water_ConstVol(VPStandardStateTP* vp_ptr,
28  SpeciesThermo* spth) :
29  VPSSMgr(vp_ptr, spth),
30  m_waterSS(0)
31 {
34 }
35 
36 
38 {
39 }
40 
42  VPSSMgr(right.m_vptp_ptr, right.m_spthermo)
43 {
46  *this = right;
47 }
48 
49 
52 {
53  if (&b == this) {
54  return *this;
55  }
57  return *this;
58 }
59 
60 VPSSMgr*
62 {
64  return (VPSSMgr*) vpm;
65 }
66 
67 void
69  SpeciesThermo* sp_ptr)
70 {
71  VPSSMgr::initAllPtrs(vp_ptr, sp_ptr);
72  m_waterSS = dynamic_cast<PDSS_Water*>(m_vptp_ptr->providePDSS(0));
73  if (!m_waterSS) {
74  throw CanteraError("VPSSMgr_Water_ConstVol::initAllPtrs",
75  "bad dynamic cast");
76  }
77 }
78 
79 
80 void
82 {
83  // Everything should be OK except for the water SS
85  if (m_p0 != m_plast) {
86  doublereal RT = GasConstant * m_tlast;
87  m_waterSS->setState_TP(m_tlast, m_p0);
88  m_h0_RT[0] = (m_waterSS->enthalpy_mole()) / RT;
89  m_waterSS->setState_TP(m_tlast, m_plast);
90  } else {
91  m_h0_RT[0] = m_hss_RT[0];
92  }
93  copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
94 }
95 
96 void
98 {
99  // Everything should be OK except for the water SS
101  if (m_p0 != m_plast) {
102  doublereal RT = GasConstant * m_tlast;
103  m_waterSS->setState_TP(m_tlast, m_p0);
104  m_g0_RT[0] = (m_waterSS->gibbs_mole()) / RT;
105  m_waterSS->setState_TP(m_tlast, m_plast);
106  } else {
107  m_g0_RT[0] = m_gss_RT[0];
108  }
109  copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
110 }
111 
112 void
114 {
115  doublereal RT = GasConstant * m_tlast;
116  getGibbs_RT_ref(g);
117  for (size_t k = 0; k < m_kk; k++) {
118  g[k] *= RT;
119  }
120 }
121 
122 void
124 {
125  // Everything should be OK except for the water SS
127  if (m_p0 != m_plast) {
131  } else {
132  m_s0_R[0] = m_sss_R[0];
133  }
134  copy(m_s0_R.begin(), m_s0_R.end(), sr);
135 }
136 
137 void
139 {
140  // Everything should be OK except for the water SS
142  if (m_p0 != m_plast) {
144  m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
146  } else {
147  m_cp0_R[0] = m_cpss_R[0];
148  }
149  copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
150 }
151 
152 void
154 {
155  // Everything should be OK except for the water SS
157  if (m_p0 != m_plast) {
161  } else {
162  m_V0[0] = m_Vss[0];
163  }
164  copy(m_V0.begin(), m_V0.end(), vol);
165 }
166 
168 {
170  m_spthermo->update(m_tlast, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
171  for (size_t k = 0; k < m_kk; k++) {
172  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
173  PDSS* kPDSS = m_vptp_ptr->providePDSS(k);
174  kPDSS->setTemperature(m_tlast);
175  }
176  doublereal RT = GasConstant * m_tlast;
177  m_waterSS->setState_TP(m_tlast, m_p0);
178  m_h0_RT[0] = (m_waterSS->enthalpy_mole())/ RT;
180  m_cp0_R[0] = (m_waterSS->cp_mole()) / GasConstant;
181  m_g0_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
183  m_waterSS->setState_TP(m_tlast, m_plast);
184 }
185 
186 
187 
189 {
190 
191  doublereal RT = GasConstant * m_tlast;
192  doublereal del_pRT = (m_plast - OneAtm) / (RT);
193 
194  for (size_t k = 1; k < m_kk; k++) {
195  m_hss_RT[k] = m_h0_RT[k] + del_pRT * m_Vss[k];
196  m_cpss_R[k] = m_cp0_R[k];
197  m_sss_R[k] = m_s0_R[k];
198  m_gss_RT[k] = m_hss_RT[k] - m_sss_R[k];
199  // m_Vss[k] constant
200  PDSS* kPDSS = m_vptp_ptr->providePDSS(k);
201  kPDSS->setState_TP(m_tlast, m_plast);
202  }
203  // Do the water
204  m_waterSS->setState_TP(m_tlast, m_plast);
205  m_hss_RT[0] = (m_waterSS->enthalpy_mole())/ RT;
208  m_gss_RT[0] = (m_hss_RT[0] - m_sss_R[0]);
210 }
211 
212 
214 {
216 }
217 
218 void
220 {
221  VPSSMgr::initThermoXML(phaseNode, id);
222 
223  XML_Node& speciesList = phaseNode.child("speciesArray");
224  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
225  &phaseNode.root());
226  const vector<string>&sss = m_vptp_ptr->speciesNames();
227 
228 
229  if (!m_waterSS) {
230  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
231  "bad dynamic cast");
232  }
233 
234  m_waterSS->setState_TP(300., OneAtm);
236 
237  for (size_t k = 1; k < m_kk; k++) {
238  const XML_Node* s = speciesDB->findByAttr("name", sss[k]);
239  if (!s) {
240  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
241  "no species Node for species " + sss[k]);
242  }
243  const XML_Node* ss = s->findByName("standardState");
244  if (!ss) {
245  std::string sName = s->operator[]("name");
246  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
247  "no standardState Node for species " + sName);
248  }
249  std::string model = (*ss)["model"];
250  if (model != "constant_incompressible") {
251  std::string sName = s->operator[]("name");
252  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
253  "standardState model for species isn't "
254  "constant_incompressible: " + sName);
255  }
256  m_Vss[k] = ctml::getFloat(*ss, "molarVolume", "toSI");
257  }
258 }
259 
260 PDSS*
262  const XML_Node* const phaseNode_ptr)
263 {
264 
265  PDSS* kPDSS = 0;
266  // Will have to do something for water
267  // -> make sure it's species 0
268  // -> make sure it's designated as a real water EOS
269  if (k == 0) {
270  string xn = speciesNode["name"];
271  if (xn != "H2O(L)") {
272  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
273  "h2o wrong name: " + xn);
274  }
275  const XML_Node* ss = speciesNode.findByName("standardState");
276  std::string model = (*ss)["model"];
277  if (model != "waterIAPWS" && model != "waterPDSS") {
278  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
279  "wrong SS mode: " + model);
280  }
281  if (m_waterSS) {
282  delete m_waterSS;
283  }
284  m_waterSS = new PDSS_Water(m_vptp_ptr, 0);
285  GeneralSpeciesThermo* genSpthermo = dynamic_cast<GeneralSpeciesThermo*>(m_spthermo);
286  if (!genSpthermo) {
287  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
288  "failed dynamic cast");
289  }
290  genSpthermo->installPDSShandler(k, m_waterSS, this);
291  kPDSS = m_waterSS;
292  } else {
293 
294  VPSSMgr::installSTSpecies(k, speciesNode, phaseNode_ptr);
295 
296  const XML_Node* ss = speciesNode.findByName("standardState");
297  if (!ss) {
298  throw CanteraError("VPSSMgr_Water_ConstVol::installSpecies",
299  "no standardState Node for species " + speciesNode.name());
300  }
301  std::string model = (*ss)["model"];
302  if (model != "constant_incompressible") {
303  throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML",
304  "standardState model for species isn't "
305  "constant_incompressible: " + speciesNode.name());
306  }
307  if (m_Vss.size() < k+1) {
308  m_Vss.resize(k+1, 0.0);
309  }
310  m_Vss[k] = ctml::getFloat(*ss, "molarVolume", "toSI");
311 
312  // instantiate a new kPDSS object
313  kPDSS = new PDSS_ConstVol(m_vptp_ptr, k, speciesNode, *phaseNode_ptr, true);
314  }
315  return kPDSS;
316 }
317 
319 {
320  return cPDSS_UNDEF;
321 }
322 
324 {
325  return cVPSSMGR_WATER_CONSTVOL;
326 }
327 }
328 
329