Cantera  2.0
PDSS_ConstVol.cpp
Go to the documentation of this file.
1 /**
2  * @file PDSS_ConstVol.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 #include "cantera/base/ct_defs.h"
12 #include "cantera/base/xml.h"
13 #include "cantera/base/ctml.h"
16 
18 
19 #include <fstream>
20 
21 using namespace std;
22 
23 namespace Cantera
24 {
25 /**
26  * Basic list of constructors and duplicators
27  */
28 
29 PDSS_ConstVol::PDSS_ConstVol(VPStandardStateTP* tp, size_t spindex) :
30  PDSS(tp, spindex)
31 {
32  m_pdssType = cPDSS_CONSTVOL;
33 }
34 
35 
36 PDSS_ConstVol::PDSS_ConstVol(VPStandardStateTP* tp, size_t spindex, std::string inputFile, std::string id) :
37  PDSS(tp, spindex)
38 {
39  m_pdssType = cPDSS_CONSTVOL;
40  constructPDSSFile(tp, spindex, inputFile, id);
41 }
42 
44  const XML_Node& speciesNode,
45  const XML_Node& phaseRoot,
46  bool spInstalled) :
47  PDSS(tp, spindex)
48 {
49  m_pdssType = cPDSS_CONSTVOL;
50  constructPDSSXML(tp, spindex, speciesNode, phaseRoot, spInstalled) ;
51 }
52 
53 
55  PDSS(b)
56 {
57  /*
58  * Use the assignment operator to do the brunt
59  * of the work for the copy constructor.
60  */
61  *this = b;
62 }
63 
64 /*
65  * Assignment operator
66  */
68 {
69  if (&b == this) {
70  return *this;
71  }
72  PDSS::operator=(b);
74  return *this;
75 }
76 
78 {
79 }
80 
81 // Duplicator
83 {
84  PDSS_ConstVol* idg = new PDSS_ConstVol(*this);
85  return (PDSS*) idg;
86 }
87 
88 /*
89  * constructPDSSXML:
90  *
91  * Initialization of a PDSS_ConstVol object using an
92  * xml file.
93  *
94  * This routine is a precursor to initThermo(XML_Node*)
95  * routine, which does most of the work.
96  *
97  * @param infile XML file containing the description of the
98  * phase
99  *
100  * @param id Optional parameter identifying the name of the
101  * phase. If none is given, the first XML
102  * phase element will be used.
103  */
105  const XML_Node& speciesNode,
106  const XML_Node& phaseNode, bool spInstalled)
107 {
110  m_p0 = sp.refPressure(m_spindex);
111 
112  if (!spInstalled) {
113  throw CanteraError("PDSS_ConstVol::constructPDSSXML", "spInstalled false not handled");
114  }
115 
116  const XML_Node* ss = speciesNode.findByName("standardState");
117  if (!ss) {
118  throw CanteraError("PDSS_ConstVol::constructPDSSXML",
119  "no standardState Node for species " + speciesNode.name());
120  }
121  std::string model = (*ss)["model"];
122  if (model != "constant_incompressible") {
123  throw CanteraError("PDSS_ConstVol::initThermoXML",
124  "standardState model for species isn't constant_incompressible: " + speciesNode.name());
125  }
126 
127  m_constMolarVolume = ctml::getFloat(*ss, "molarVolume", "toSI");
128 
129  std::string id = "";
130  // initThermoXML(phaseNode, id);
131 }
132 
133 
134 /*
135  * constructPDSSFile():
136  *
137  * Initialization of a PDSS_ConstVol object using an
138  * xml file.
139  *
140  * This routine is a precursor to initThermo(XML_Node*)
141  * routine, which does most of the work.
142  *
143  * @param infile XML file containing the description of the
144  * phase
145  *
146  * @param id Optional parameter identifying the name of the
147  * phase. If none is given, the first XML
148  * phase element will be used.
149  */
151  std::string inputFile, std::string id)
152 {
153 
154  if (inputFile.size() == 0) {
155  throw CanteraError("PDSS_ConstVol::initThermo",
156  "input file is null");
157  }
158  std::string path = findInputFile(inputFile);
159  ifstream fin(path.c_str());
160  if (!fin) {
161  throw CanteraError("PDSS_ConstVol::initThermo","could not open "
162  +path+" for reading.");
163  }
164  /*
165  * The phase object automatically constructs an XML object.
166  * Use this object to store information.
167  */
168 
169  XML_Node* fxml = new XML_Node();
170  fxml->build(fin);
171  XML_Node* fxml_phase = findXMLPhase(fxml, id);
172  if (!fxml_phase) {
173  throw CanteraError("PDSS_ConstVol::initThermo",
174  "ERROR: Can not find phase named " +
175  id + " in file named " + inputFile);
176  }
177 
178  XML_Node& speciesList = fxml_phase->child("speciesArray");
179  XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
180  &(fxml_phase->root()));
181  const vector<string>&sss = tp->speciesNames();
182  const XML_Node* s = speciesDB->findByAttr("name", sss[spindex]);
183 
184  constructPDSSXML(tp, spindex, *s, *fxml_phase, true);
185  delete fxml;
186 }
187 
188 void PDSS_ConstVol::initThermoXML(const XML_Node& phaseNode, std::string& id)
189 {
190  PDSS::initThermoXML(phaseNode, id);
195 }
196 
198 {
201  m_p0 = sp.refPressure(m_spindex);
204 }
205 
206 doublereal
208 {
209  doublereal val = enthalpy_RT();
210  doublereal RT = GasConstant * m_temp;
211  return (val * RT);
212 }
213 
214 doublereal
216 {
217  doublereal val = m_hss_RT_ptr[m_spindex];
218  return (val);
219 }
220 
221 
222 doublereal
224 {
225  doublereal pVRT = (m_pres * m_Vss_ptr[m_spindex]) / (GasConstant * m_temp);
226  doublereal val = m_h0_RT_ptr[m_spindex] - pVRT;
227  doublereal RT = GasConstant * m_temp;
228  return (val * RT);
229 }
230 
231 
232 doublereal
234 {
235  doublereal val = entropy_R();
236  return (val * GasConstant);
237 }
238 
239 doublereal
241 {
242  doublereal val = m_sss_R_ptr[m_spindex];
243  return (val);
244 }
245 
246 /*
247  * Calculate the Gibbs free energy in mks units of
248  * J kmol-1 K-1.
249  */
250 doublereal
252 {
253  doublereal val = gibbs_RT();
254  doublereal RT = GasConstant * m_temp;
255  return (val * RT);
256 }
257 
258 doublereal
260 {
261  doublereal val = m_gss_RT_ptr[m_spindex];
262  return (val);
263 }
264 
265 doublereal
267 {
268  doublereal val = m_cpss_R_ptr[m_spindex];
269  return (val * GasConstant);
270 }
271 
272 doublereal
274 {
275  doublereal val = m_cpss_R_ptr[m_spindex];
276  return (val);
277 }
278 
279 doublereal
281 {
282  doublereal val = (cp_mole() - m_V0_ptr[m_spindex]);
283  return (val);
284 }
285 
286 doublereal
288 {
289  doublereal val = m_Vss_ptr[m_spindex];
290  return (val);
291 }
292 
293 doublereal
295 {
296  doublereal val = m_Vss_ptr[m_spindex];
297  return (m_mw/val);
298 }
299 
300 doublereal
302 {
303  doublereal val = m_g0_RT_ptr[m_spindex];
304  return (val);
305 }
306 
308 {
309  doublereal val = m_h0_RT_ptr[m_spindex];
310  return (val);
311 }
312 
314 {
315  doublereal val = m_s0_R_ptr[m_spindex];
316  return (val);
317 }
318 
319 doublereal PDSS_ConstVol::cp_R_ref() const
320 {
321  doublereal val = m_cp0_R_ptr[m_spindex];
322  return (val);
323 }
324 
326 {
327  doublereal val = m_V0_ptr[m_spindex];
328  return (val);
329 }
330 
331 
332 
333 // critical temperature
335 {
336  throw CanteraError("PDSS_ConstVol::critTemperature()", "unimplemented");
337  return (0.0);
338 }
339 
340 // critical pressure
341 doublereal PDSS_ConstVol::critPressure() const
342 {
343  throw CanteraError("PDSS_ConstVol::critPressure()", "unimplemented");
344  return (0.0);
345 }
346 
347 // critical density
348 doublereal PDSS_ConstVol::critDensity() const
349 {
350  throw CanteraError("PDSS_ConstVol::critDensity()", "unimplemented");
351  return (0.0);
352 }
353 
354 void PDSS_ConstVol::setPressure(doublereal p)
355 {
356  m_pres = p;
357  doublereal del_pRT = (m_pres - m_p0) / (GasConstant * m_temp);
360 }
361 
362 void PDSS_ConstVol::setTemperature(doublereal temp)
363 {
364  m_temp = temp;
368 
369  doublereal del_pRT = (m_pres - m_p0) / (GasConstant * m_temp);
370 
373  m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex];
375 
376 }
377 
378 
379 void PDSS_ConstVol::setState_TP(doublereal temp, doublereal pres)
380 {
381  setTemperature(temp);
382  setPressure(pres);
383 }
384 
385 
386 void PDSS_ConstVol::setState_TR(doublereal temp, doublereal rho)
387 {
388  doublereal rhoStored = m_mw / m_constMolarVolume;
389  if (fabs(rhoStored - rho) / (rhoStored + rho) > 1.0E-4) {
390  throw CanteraError("PDSS_ConstVol::setState_TR",
391  "Inconsistent supplied rho");
392  }
393  setTemperature(temp);
394 }
395 
396 // saturation pressure
397 doublereal PDSS_ConstVol::satPressure(doublereal t)
398 {
399  return (1.0E-200);
400 }
401 
402 }