Cantera  2.0
PDSS_IdealGas.cpp
Go to the documentation of this file.
1 /**
2  * @file PDSS_IdealGas.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_IdealGas::PDSS_IdealGas(VPStandardStateTP* tp, int spindex) :
30  PDSS(tp, spindex)
31 {
32  m_pdssType = cPDSS_IDEALGAS;
33 }
34 
35 
37  std::string inputFile, std::string id) :
38  PDSS(tp, spindex)
39 {
40  m_pdssType = cPDSS_IDEALGAS;
41  constructPDSSFile(tp, spindex, inputFile, id);
42 }
43 
44 
45 
46 PDSS_IdealGas::PDSS_IdealGas(VPStandardStateTP* tp, size_t spindex, const XML_Node& speciesNode,
47  const XML_Node& phaseRoot, bool spInstalled) :
48  PDSS(tp, spindex)
49 {
50  if (!spInstalled) {
51  throw CanteraError("PDSS_IdealGas", "sp installing not done yet");
52  }
53  m_pdssType = cPDSS_IDEALGAS;
54  std::string id = "";
55  constructPDSSXML(tp, spindex, phaseRoot, id);
56 }
57 
58 
59 
61  PDSS(b)
62 {
63  /*
64  * Use the assignment operator to do the brunt
65  * of the work for the copy constructor.
66  */
67  *this = b;
68 }
69 
70 /*
71  * Assignment operator
72  */
74 {
75  if (&b == this) {
76  return *this;
77  }
78  PDSS::operator=(b);
79 
80  m_tmin = b.m_tmin;
81  m_tmax = b.m_tmax;
82 
83  return *this;
84 }
85 
87 {
88 }
89 
90 // Duplicator
92 {
93  PDSS_IdealGas* idg = new PDSS_IdealGas(*this);
94  return (PDSS*) idg;
95 }
96 
97 
98 
99 /*
100  * constructPDSSXML:
101  *
102  * Initialization of a PDSS_IdealGas object using an
103  * xml file.
104  *
105  * This routine is a precursor to initThermo(XML_Node*)
106  * routine, which does most of the work.
107  *
108  * @param infile XML file containing the description of the
109  * phase
110  *
111  * @param id Optional parameter identifying the name of the
112  * phase. If none is given, the first XML
113  * phase element will be used.
114  */
116  const XML_Node& phaseNode, std::string id)
117 {
118  //initThermo();
119  //initThermoXML(phaseNode, id);
120 }
121 
122 
124  std::string inputFile, std::string id)
125 {
126 
127  if (inputFile.size() == 0) {
128  throw CanteraError("PDSS_IdealGas::constructPDSSFile",
129  "input file is null");
130  }
131  std::string path = findInputFile(inputFile);
132  ifstream fin(path.c_str());
133  if (!fin) {
134  throw CanteraError("PDSS_IdealGas::constructPDSSFile","could not open "
135  +path+" for reading.");
136  }
137  /*
138  * The phase object automatically constructs an XML object.
139  * Use this object to store information.
140  */
141 
142  XML_Node* fxml = new XML_Node();
143  fxml->build(fin);
144  XML_Node* fxml_phase = findXMLPhase(fxml, id);
145  if (!fxml_phase) {
146  throw CanteraError("PDSS_IdealGas::constructPDSSFile",
147  "ERROR: Can not find phase named " +
148  id + " in file named " + inputFile);
149  }
150  constructPDSSXML(tp, spindex, *fxml_phase, id);
151  delete fxml;
152 }
153 
154 void PDSS_IdealGas::initThermoXML(const XML_Node& phaseNode, std::string& id)
155 {
156  PDSS::initThermoXML(phaseNode, id);
157 }
158 
160 {
163  m_p0 = sp.refPressure(m_spindex);
166 }
167 
168 /*
169  * Return the molar enthalpy in units of J kmol-1
170  */
171 doublereal
173 {
174  doublereal val = enthalpy_RT();
175  doublereal RT = GasConstant * m_temp;
176  return (val * RT);
177 }
178 
179 doublereal
181 {
182  doublereal val = m_h0_RT_ptr[m_spindex];
183  return (val);
184 }
185 
186 
187 /*
188  * Calculate the internal energy in mks units of
189  * J kmol-1
190  */
191 doublereal
193 {
194  doublereal val = m_h0_RT_ptr[m_spindex] - 1.0;
195  doublereal RT = GasConstant * m_temp;
196  return (val * RT);
197 }
198 
199 /*
200  * Calculate the entropy in mks units of
201  * J kmol-1 K-1
202  */
203 doublereal
205 {
206  doublereal val = entropy_R();
207  return (val * GasConstant);
208 }
209 
210 doublereal
212 {
213  doublereal val = m_s0_R_ptr[m_spindex] - log(m_pres/m_p0);
214  return (val);
215 }
216 
217 /*
218  * Calculate the Gibbs free energy in mks units of
219  * J kmol-1 K-1.
220  */
221 doublereal
223 {
224  doublereal val = gibbs_RT();
225  doublereal RT = GasConstant * m_temp;
226  return (val * RT);
227 }
228 
229 doublereal
231 {
232  doublereal val = m_g0_RT_ptr[m_spindex] + log(m_pres/m_p0);
233  return (val);
234 }
235 
236 /*
237  * Calculate the constant pressure heat capacity
238  * in mks units of J kmol-1 K-1
239  */
240 doublereal
242 {
243  doublereal val = cp_R();
244  return (val * GasConstant);
245 }
246 
247 doublereal
249 {
250  doublereal val = m_cp0_R_ptr[m_spindex];
251  return (val);
252 }
253 
254 doublereal
256 {
257  return (GasConstant * m_temp / m_pres);
258 }
259 
260 
261 doublereal
263 {
264  return (m_pres * m_mw / (GasConstant * m_temp));
265 }
266 
267 /*
268  * Calculate the constant volume heat capacity
269  * in mks units of J kmol-1 K-1
270  */
271 doublereal
273 {
274  return (cp_mole() - GasConstant);
275 }
276 
277 
278 doublereal
280 {
281  doublereal val = m_g0_RT_ptr[m_spindex];
282  return (val);
283 }
284 
286 {
287  doublereal val = m_h0_RT_ptr[m_spindex];
288  return (val);
289 }
290 
292 {
293  doublereal val = m_s0_R_ptr[m_spindex];
294  return (val);
295 }
296 
297 doublereal PDSS_IdealGas::cp_R_ref() const
298 {
299  return (cp_R());
300 }
301 
303 {
304  return (GasConstant * m_temp / m_p0);
305 }
306 
307 /*
308  * Calculate the pressure (Pascals), given the temperature and density
309  * Temperature: kelvin
310  * rho: density in kg m-3
311  */
312 doublereal PDSS_IdealGas::pressure() const
313 {
314  throw CanteraError("PDSS_IdealGas::pressure()", "unimplemented");
315  return (0.0);
316 }
317 
318 void PDSS_IdealGas::setPressure(doublereal p)
319 {
323 }
324 
325 
326 // critical temperature
328 {
329  throw CanteraError("PDSS_IdealGas::critTemperature()", "unimplemented");
330  return (0.0);
331 }
332 
333 // critical pressure
334 doublereal PDSS_IdealGas::critPressure() const
335 {
336  throw CanteraError("PDSS_IdealGas::critPressure()", "unimplemented");
337  return (0.0);
338 }
339 
340 // critical density
341 doublereal PDSS_IdealGas::critDensity() const
342 {
343  throw CanteraError("PDSS_IdealGas::critDensity()", "unimplemented");
344  return (0.0);
345 }
346 
347 
348 /*
349  * Return the temperature
350  *
351  * Obtain the temperature from the owning VPStandardStateTP object
352  * if you can.
353  */
354 doublereal PDSS_IdealGas::temperature() const
355 {
357  return m_temp;
358 }
359 
360 void PDSS_IdealGas::setTemperature(doublereal temp)
361 {
362  m_temp = temp;
367 
370  m_sss_R_ptr[m_spindex] = m_s0_R_ptr[m_spindex] + log(m_pres/m_p0);
373 }
374 
375 
376 void PDSS_IdealGas::setState_TP(doublereal temp, doublereal pres)
377 {
378  m_pres = pres;
379  setTemperature(temp);
380 }
381 
382 void PDSS_IdealGas::setState_TR(doublereal temp, doublereal rho)
383 {
384  m_pres = GasConstant * temp * rho / m_mw;
385  setTemperature(temp);
386 }
387 
388 // saturation pressure
389 doublereal PDSS_IdealGas::satPressure(doublereal t)
390 {
391  throw CanteraError("PDSS_IdealGas::satPressure()", "unimplemented");
392  /*NOTREACHED*/
393  return (0.0);
394 }
395 
396 
397 }