Cantera  2.1.2
ConstDensityThermo.cpp
Go to the documentation of this file.
1 /**
2  * @file ConstDensityThermo.cpp
3  * Declarations for a Thermo manager for incompressible ThermoPhases
4  * (see \ref thermoprops and \link Cantera::ConstDensityThermo ConstDensityThermo
5 \endlink).
6  */
7 
8 // Copyright 2002 California Institute of Technology
9 #include "cantera/base/ct_defs.h"
13 
14 using namespace ctml;
15 
16 namespace Cantera
17 {
18 
19 ConstDensityThermo::ConstDensityThermo() : m_tlast(0.0)
20 {
21 }
22 
23 
25  : m_tlast(0.0)
26 {
27  *this = operator=(right);
28 }
29 
31 {
32  if (&right == this) {
33  return *this;
34  }
35 
36  m_tlast = right.m_tlast;
37  m_h0_RT = right.m_h0_RT;
38  m_cp0_R = right.m_cp0_R;
39  m_g0_RT = right.m_g0_RT;
40  m_s0_R = right.m_s0_R;
41  m_pp = right.m_pp;
42 
43  return *this;
44 
45 }
46 
48 {
49  return new ConstDensityThermo(*this);
50 }
51 
53 eosType() const
54 {
55  return cIncompressible;
56 }
57 
59 {
60  doublereal p0 = m_spthermo->refPressure();
61  return GasConstant * temperature() *
62  mean_X(&enthalpy_RT()[0])
63  + (pressure() - p0)/molarDensity();
64 }
65 
67 {
68  doublereal p0 = m_spthermo->refPressure();
69  return GasConstant * temperature() *
70  mean_X(&enthalpy_RT()[0])
71  - p0/molarDensity();
72 }
73 
75 {
76  return GasConstant * (mean_X(&entropy_R()[0]) -
77  sum_xlogx());
78 }
79 
81 {
82  return enthalpy_mole() - temperature() * entropy_mole();
83 }
84 
85 doublereal ConstDensityThermo::cp_mole() const
86 {
87  return GasConstant * mean_X(&cp_R()[0]);
88 }
89 
90 doublereal ConstDensityThermo::cv_mole() const
91 {
92  return cp_mole();
93 }
94 
95 doublereal ConstDensityThermo::pressure() const
96 {
97  return m_press;
98 }
99 
101 {
102  m_press = p;
103 }
104 
106 {
108 }
109 
111 {
112  for (size_t k = 0; k < m_kk; k++) {
113  ac[k] = 1.0;
114  }
115 }
116 
118 {
119  return molarDensity();
120 }
121 
122 doublereal ConstDensityThermo::logStandardConc(size_t k) const
123 {
124  return log(molarDensity());
125 }
126 
127 void ConstDensityThermo::getChemPotentials(doublereal* mu) const
128 {
129  doublereal vdp = (pressure() - m_spthermo->refPressure())/
130  molarDensity();
131  doublereal xx;
132  doublereal rt = temperature() * GasConstant;
133  const vector_fp& g_RT = gibbs_RT();
134  for (size_t k = 0; k < m_kk; k++) {
135  xx = std::max(SmallNumber, moleFraction(k));
136  mu[k] = rt*(g_RT[k] + log(xx)) + vdp;
137  }
138 }
139 
140 
142 {
143  getPureGibbs(mu0);
144 }
145 
147 {
148  m_kk = nSpecies();
149  m_h0_RT.resize(m_kk);
150  m_g0_RT.resize(m_kk);
151  m_cp0_R.resize(m_kk);
152  m_s0_R.resize(m_kk);
153  m_pp.resize(m_kk);
154 }
155 
156 
157 void ConstDensityThermo::setToEquilState(const doublereal* lambda_RT)
158 {
159  throw CanteraError("setToEquilState","not yet impl.");
160 }
161 
163 {
164  doublereal tnow = temperature();
165  if (m_tlast != tnow) {
166  m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0],
167  &m_s0_R[0]);
168  m_tlast = tnow;
169  for (size_t k = 0; k < m_kk; k++) {
170  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
171  }
172  m_tlast = tnow;
173  }
174 }
175 
177 {
178  eosdata._require("model","Incompressible");
179  doublereal rho = getFloat(eosdata, "density", "toSI");
180  setDensity(rho);
181 }
182 
183 }
184 
185 
186 
187 
void _require(const std::string &a, const std::string &v) const
Require that the current xml node have an attribute named by the first argument, a, and that this attribute have the the string value listed in the second argument, v.
Definition: xml.cpp:614
vector_fp m_s0_R
Temporary storage for dimensionless reference state entropies.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
virtual void setToEquilState(const doublereal *lambda_RT)
This method is used by the ChemEquil equilibrium solver.
virtual void getPureGibbs(doublereal *gpure) const
Get the Gibbs functions for the standard state of the species at the current T and P of the solution...
const vector_fp & cp_R() const
Returns a reference to the vector of nondimensional constant pressure heat capacities of the referenc...
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
vector_fp m_h0_RT
Temporary storage for dimensionless reference state enthalpies.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Virtual base class for the calculation of multiple-species thermodynamic reference-state property man...
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:267
doublereal molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:597
Header for a Thermo manager for incompressible ThermoPhases (see Thermodynamic Properties and ConstDe...
void getConcentrations(doublereal *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:572
doublereal m_press
Current pressure (Pa)
vector_fp m_pp
Temporary array containing internally calculated partial pressures.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:623
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
doublereal sum_xlogx() const
Evaluate .
Definition: Phase.cpp:633
void _updateThermo() const
Function to update the reference state thermo functions.
virtual doublereal refPressure(size_t k=npos) const =0
The reference-state pressure for species k.
Overloads the virtual methods of class ThermoPhase to implement the incompressible equation of state...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
const vector_fp & enthalpy_RT() const
Returns a reference to the vector of nondimensional enthalpies of the reference state at the current ...
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
doublereal moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:524
const vector_fp & gibbs_RT() const
Returns a reference to the vector of nondimensional Gibbs Free Energies of the reference state at the...
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
doublereal m_tlast
last value of the temperature processed by reference state
const doublereal SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:139
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:165
virtual int eosType() const
Returns a constant corresponding to this class's equation of state.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
ConstDensityThermo & operator=(const ConstDensityThermo &right)
Assignment Operator.
const vector_fp & entropy_R() const
Returns a reference to the vector of nondimensional entropies of the reference state at the current t...
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
size_t m_kk
Number of species in the phase.
Definition: Phase.h:716
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const =0
Compute the reference-state properties for all species.
vector_fp m_g0_RT
Temporary storage for dimensionless reference state gibbs energies.
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
vector_fp m_cp0_R
Temporary storage for dimensionless reference state heat capacities.
SpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1625
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase Note the density of a phase is an independent...
Definition: Phase.h:549
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.