Cantera  2.5.1
ConstDensityThermo.cpp
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 // This file is part of Cantera. See License.txt in the top-level directory or
9 // at https://cantera.org/license.txt for license and copyright information.
10 
12 #include "cantera/base/ctml.h"
13 
14 namespace Cantera
15 {
16 
18 {
19  doublereal p0 = refPressure();
20  return RT() * mean_X(enthalpy_RT()) + (pressure() - p0)/molarDensity();
21 }
22 
24 {
25  return GasConstant * (mean_X(entropy_R()) - sum_xlogx());
26 }
27 
28 doublereal ConstDensityThermo::cp_mole() const
29 {
30  return GasConstant * mean_X(cp_R());
31 }
32 
33 doublereal ConstDensityThermo::cv_mole() const
34 {
35  return cp_mole();
36 }
37 
38 doublereal ConstDensityThermo::pressure() const
39 {
40  return m_press;
41 }
42 
44 {
45  m_press = p;
46 }
47 
49 {
51 }
52 
54 {
55  for (size_t k = 0; k < m_kk; k++) {
56  ac[k] = 1.0;
57  }
58 }
59 
61 {
62  return density()/molecularWeight(k);
63 }
64 
65 void ConstDensityThermo::getChemPotentials(doublereal* mu) const
66 {
67  doublereal vdp = (pressure() - refPressure())/
68  molarDensity();
69  const vector_fp& g_RT = gibbs_RT();
70  for (size_t k = 0; k < m_kk; k++) {
71  double xx = std::max(SmallNumber, moleFraction(k));
72  mu[k] = RT()*(g_RT[k] + log(xx)) + vdp;
73  }
74 }
75 
76 
78 {
79  getPureGibbs(mu0);
80 }
81 
82 bool ConstDensityThermo::addSpecies(shared_ptr<Species> spec)
83 {
84  bool added = ThermoPhase::addSpecies(spec);
85  if (added) {
86  m_h0_RT.push_back(0.0);
87  m_g0_RT.push_back(0.0);
88  m_cp0_R.push_back(0.0);
89  m_s0_R.push_back(0.0);
90  }
91  return added;
92 }
93 
95 {
96  doublereal tnow = temperature();
97  if (m_tlast != tnow) {
98  m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0],
99  &m_s0_R[0]);
100  m_tlast = tnow;
101  for (size_t k = 0; k < m_kk; k++) {
102  m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
103  }
104  m_tlast = tnow;
105  }
106 }
107 
109 {
110  if (m_input.hasKey("density")) {
111  assignDensity(m_input.convert("density", "kg/m^3"));
112  }
114 }
115 
117 {
118  eosdata._require("model","Incompressible");
119  doublereal rho = getFloat(eosdata, "density", "toSI");
120  assignDensity(rho);
121 }
122 
123 }
Cantera::ConstDensityThermo::gibbs_RT
const vector_fp & gibbs_RT() const
Returns a reference to the vector of nondimensional Gibbs Free Energies of the reference state at the...
Definition: ConstDensityThermo.h:110
Cantera::SmallNumber
const double SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:149
Cantera::AnyMap::convert
double convert(const std::string &key, const std::string &units) const
Convert the item stored by the given key to the units specified in units.
Definition: AnyMap.cpp:1055
Cantera::ThermoPhase::refPressure
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:145
Cantera::ConstDensityThermo::setPressure
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition: ConstDensityThermo.cpp:43
Cantera::ConstDensityThermo::standardConcentration
virtual doublereal standardConcentration(size_t k=0) const
Returns the standard Concentration in units of m3 kmol-1.
Definition: ConstDensityThermo.cpp:60
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:984
Cantera::ConstDensityThermo::m_g0_RT
vector_fp m_g0_RT
Temporary storage for dimensionless reference state Gibbs energies.
Definition: ConstDensityThermo.h:154
Cantera::Phase::assignDensity
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition: Phase.cpp:727
Cantera::ConstDensityThermo::enthalpy_RT
const vector_fp & enthalpy_RT() const
Returns a reference to the vector of nondimensional enthalpies of the reference state at the current ...
Definition: ConstDensityThermo.h:102
Cantera::ConstDensityThermo::m_h0_RT
vector_fp m_h0_RT
Temporary storage for dimensionless reference state enthalpies.
Definition: ConstDensityThermo.h:148
Cantera::MultiSpeciesThermo::update
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
Definition: MultiSpeciesThermo.cpp:90
Cantera::vector_fp
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:180
Cantera::Phase::getConcentrations
void getConcentrations(double *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:625
Cantera::Phase::moleFraction
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:577
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition: Phase.h:942
Cantera::ThermoPhase::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: ThermoPhase.cpp:1134
Cantera::ThermoPhase::m_input
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1874
Cantera::Phase::molecularWeight
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:521
Cantera::Phase::density
virtual double density() const
Density (kg/m^3).
Definition: Phase.h:685
Cantera::ConstDensityThermo::getChemPotentials
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ConstDensityThermo.cpp:65
Cantera::ConstDensityThermo::m_s0_R
vector_fp m_s0_R
Temporary storage for dimensionless reference state entropies.
Definition: ConstDensityThermo.h:157
Cantera::ConstDensityThermo::getActivityCoefficients
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
Definition: ConstDensityThermo.cpp:53
Cantera::ConstDensityThermo::entropy_mole
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
Definition: ConstDensityThermo.cpp:23
Cantera::ConstDensityThermo::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: ConstDensityThermo.cpp:82
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::ThermoPhase::m_tlast
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1904
Cantera::ThermoPhase::RT
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:776
Cantera::ConstDensityThermo::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: ConstDensityThermo.cpp:116
Cantera::ConstDensityThermo::pressure
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
Definition: ConstDensityThermo.cpp:38
Cantera::ConstDensityThermo::cp_mole
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: ConstDensityThermo.cpp:28
Cantera::Phase::sum_xlogx
doublereal sum_xlogx() const
Evaluate .
Definition: Phase.cpp:756
ctml.h
Cantera::Phase::temperature
doublereal temperature() const
Temperature (K).
Definition: Phase.h:667
Cantera::ConstDensityThermo::entropy_R
const vector_fp & entropy_R() const
Returns a reference to the vector of nondimensional entropies of the reference state at the current t...
Definition: ConstDensityThermo.h:118
Cantera::ConstDensityThermo::m_press
doublereal m_press
Current pressure (Pa)
Definition: ConstDensityThermo.h:160
Cantera::ConstDensityThermo::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: ConstDensityThermo.cpp:108
Cantera::ConstDensityThermo::getPureGibbs
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.
Definition: ConstDensityThermo.h:74
Cantera::ThermoPhase::m_spthermo
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1870
Cantera::ConstDensityThermo::getStandardChemPotentials
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: ConstDensityThermo.cpp:77
ConstDensityThermo.h
Cantera::getFloat
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:164
Cantera::ConstDensityThermo::m_cp0_R
vector_fp m_cp0_R
Temporary storage for dimensionless reference state heat capacities.
Definition: ConstDensityThermo.h:151
Cantera::Phase::mean_X
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:746
Cantera::ConstDensityThermo::_updateThermo
void _updateThermo() const
Function to update the reference state thermo functions.
Definition: ConstDensityThermo.cpp:94
Cantera::Phase::molarDensity
double molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:700
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:109
Cantera::XML_Node::_require
void _require(const std::string &a, const std::string &v) const
Require that the current XML node has an attribute named by the first argument, a,...
Definition: xml.cpp:576
Cantera::ConstDensityThermo::enthalpy_mole
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
Definition: ConstDensityThermo.cpp:17
Cantera::ThermoPhase::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: ThermoPhase.cpp:1096
Cantera::ConstDensityThermo::getActivityConcentrations
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: ConstDensityThermo.cpp:48
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:263
Cantera::ConstDensityThermo::cv_mole
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: ConstDensityThermo.cpp:33
Cantera::ConstDensityThermo::cp_R
const vector_fp & cp_R() const
Returns a reference to the vector of nondimensional constant pressure heat capacities of the referenc...
Definition: ConstDensityThermo.h:126