Cantera  2.0
StoichSubstance.cpp
Go to the documentation of this file.
1 /**
2  * @file StoichSubstance.cpp
3  * This file contains the class definitions for the StoichSubstance
4  * ThermoPhase class.
5  */
6 
7 // Copyright 2001 California Institute of Technology
8 
9 #include "cantera/base/ct_defs.h"
10 #include "cantera/thermo/mix_defs.h"
13 
14 namespace Cantera
15 {
16 
17 // Default empty constructor
19  m_kk(0),
20  m_tmin(0.0),
21  m_tmax(0.0),
22  m_press(OneAtm),
23  m_p0(OneAtm),
24  m_tlast(-1.0)
25 {
26 }
27 
28 // Copy Constructor
29 /*
30  * Copy constructor for the object. Constructed
31  * object will be a clone of this object, but will
32  * also own all of its data.
33  * This is a wrapper around the assignment operator
34  *
35  * @param right Object to be copied.
36  */
38  m_kk(0),
39  m_tmin(0.0),
40  m_tmax(0.0),
41  m_press(OneAtm),
42  m_p0(OneAtm),
43  m_tlast(-1.0)
44 {
45  *this = operator=(right);
46 }
47 
48 // Assignment operator
49 /*
50  * Assignment operator for the object. Constructed
51  * object will be a clone of this object, but will
52  * also own all of its data.
53  *
54  * @param right Object to be copied.
55  */
58 {
59  if (&right != this) {
61  m_kk = right.m_kk;
62  m_tmin = right.m_tmin;
63  m_tmax = right.m_tmax;
64  m_press = right.m_press;
65  m_p0 = right.m_p0;
66  m_tlast = right.m_tlast;
67  m_h0_RT = right.m_h0_RT;
68  m_cp0_R = right.m_cp0_R;
69  m_s0_R = right.m_s0_R;
70  }
71  return *this;
72 }
73 
74 // Duplicator from the %ThermoPhase parent class
75 /*
76  * Given a pointer to a %ThermoPhase object, this function will
77  * duplicate the %ThermoPhase object and all underlying structures.
78  * This is basically a wrapper around the copy constructor.
79  *
80  * @return returns a pointer to a %ThermoPhase
81  */
83 {
84  ThermoPhase* igp = new StoichSubstance(*this);
85  return (ThermoPhase*) igp;
86 }
87 
88 // Destructor
90 {
91 }
92 
94 {
95  double hh = intEnergy_mole() + m_press / molarDensity();
96  return hh;
97 }
98 
100 {
101  _updateThermo();
102  return GasConstant * temperature() * m_h0_RT[0]
103  - m_p0 / molarDensity();
104 }
105 
107 {
108  _updateThermo();
109  return GasConstant * m_s0_R[0];
110 }
111 
112 doublereal StoichSubstance::gibbs_mole() const
113 {
114  return enthalpy_mole() - temperature() * entropy_mole();
115 }
116 
117 doublereal StoichSubstance::cp_mole() const
118 {
119  _updateThermo();
120  return GasConstant * m_cp0_R[0];
121 }
122 
123 doublereal StoichSubstance::cv_mole() const
124 {
125  return cp_mole();
126 }
127 
129 {
130  m_kk = nSpecies();
131  if (m_kk > 1) {
132  throw CanteraError("initThermo",
133  "stoichiometric substances may only contain one species.");
134  }
135  doublereal tmin = m_spthermo->minTemp();
136  doublereal tmax = m_spthermo->maxTemp();
137  if (tmin > 0.0) {
138  m_tmin = tmin;
139  }
140  if (tmax > 0.0) {
141  m_tmax = tmax;
142  }
143  m_p0 = refPressure();
144 
145  m_h0_RT.resize(m_kk);
146  m_cp0_R.resize(m_kk);
147  m_s0_R.resize(m_kk);
148 
149  // Put the object on a valid temperature point.
150  double tnow = 300.;
151  if (tnow > tmin && tnow < tmax) {
152 
153  } else {
154  tnow = 0.1 * (9 * tmin + tmax);
155  }
156  setState_TP(tnow, m_p0);
157 }
158 
159 void StoichSubstance::_updateThermo() const
160 {
161  doublereal tnow = temperature();
162  if (m_tlast != tnow) {
163  m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0],
164  &m_s0_R[0]);
165  m_tlast = tnow;
166  }
167 }
168 
169 doublereal StoichSubstance::pressure() const
170 {
171  return m_press;
172 }
173 
175 {
176  m_press = p;
177 }
178 
180 {
181  c[0] = 1.0;
182 }
183 
184 doublereal StoichSubstance::standardConcentration(size_t k) const
185 {
186  return 1.0;
187 }
188 
189 doublereal StoichSubstance::logStandardConc(size_t k) const
190 {
191  return 0.0;
192 }
193 
195 {
196  mu0[0] = gibbs_mole();
197 }
198 
200 getUnitsStandardConc(double* uA, int k, int sizeUA) const
201 {
202  for (int i = 0; i < sizeUA; i++) {
203  uA[i] = 0.0;
204  }
205 }
206 
207 void StoichSubstance::getChemPotentials_RT(doublereal* mu) const
208 {
209  mu[0] = gibbs_mole() / (GasConstant * temperature());
210 }
211 
212 void StoichSubstance::getChemPotentials(doublereal* mu) const
213 {
214  mu[0] = gibbs_mole();
215 }
216 
218 {
219  getChemPotentials(mu);
220 }
221 
222 void StoichSubstance::getPartialMolarEnthalpies(doublereal* hbar) const
223 {
224  hbar[0] = enthalpy_mole();
225 }
226 
227 void StoichSubstance::getPartialMolarEntropies(doublereal* sbar) const
228 {
229  sbar[0] = entropy_mole();
230 }
231 
232 void StoichSubstance::getPartialMolarVolumes(doublereal* vbar) const
233 {
234  vbar[0] = 1.0 / molarDensity();
235 }
236 
237 void StoichSubstance::getEnthalpy_RT(doublereal* hrt) const
238 {
239  hrt[0] = enthalpy_mole() / (GasConstant * temperature());
240 }
241 
242 void StoichSubstance::getEntropy_R(doublereal* sr) const
243 {
244  sr[0] = entropy_mole() / GasConstant;
245 }
246 
247 void StoichSubstance::getGibbs_RT(doublereal* grt) const
248 {
249  grt[0] = gibbs_mole() / (GasConstant * temperature());
250 }
251 
252 void StoichSubstance::getPureGibbs(doublereal* gpure) const
253 {
254  gpure[0] = gibbs_mole();
255 }
256 
257 void StoichSubstance::getCp_R(doublereal* cpr) const
258 {
259  cpr[0] = cp_mole() / GasConstant;
260 }
261 
262 void StoichSubstance::getStandardVolumes(doublereal* vol) const
263 {
264  vol[0] = 1.0 / molarDensity();
265 }
266 
267 void StoichSubstance::getEnthalpy_RT_ref(doublereal* hrt) const
268 {
269  _updateThermo();
270  hrt[0] = m_h0_RT[0];
271 }
272 
273 void StoichSubstance::getGibbs_RT_ref(doublereal* grt) const
274 {
275  _updateThermo();
276  grt[0] = m_h0_RT[0] - m_s0_R[0];
277 }
278 
279 void StoichSubstance::getGibbs_ref(doublereal* g) const
280 {
281  getGibbs_RT_ref(g);
282  g[0] *= GasConstant * temperature();
283 }
284 
285 void StoichSubstance::getEntropy_R_ref(doublereal* er) const
286 {
287  _updateThermo();
288  er[0] = m_s0_R[0];
289 }
290 
291 void StoichSubstance::getCp_R_ref(doublereal* cprt) const
292 {
293  _updateThermo();
294  cprt[0] = m_cp0_R[0];
295 }
296 
297 void StoichSubstance::setParameters(int n, double* const c)
298 {
299  double rho = c[0];
300  setDensity(rho);
301 }
302 
303 void StoichSubstance::getParameters(int& n, double* const c) const
304 {
305  double rho = density();
306  c[0] = rho;
307 }
308 
310 {
311  eosdata._require("model","StoichSubstance");
312  doublereal rho = ctml::getFloat(eosdata, "density", "toSI");
313  setDensity(rho);
314 }
315 
316 }
317 
318 
319 
320