Cantera  3.2.0
Loading...
Searching...
No Matches
IdealSolidSolnPhase.cpp
Go to the documentation of this file.
1/**
2 * @file IdealSolidSolnPhase.cpp Implementation file for an ideal solid
3 * solution model with incompressible thermodynamics (see @ref
4 * thermoprops and @link Cantera::IdealSolidSolnPhase
5 * IdealSolidSolnPhase@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
16
17namespace Cantera
18{
19
20IdealSolidSolnPhase::IdealSolidSolnPhase(const string& inputFile, const string& id_)
21{
22 initThermoFile(inputFile, id_);
23}
24
25// Molar Thermodynamic Properties of the Solution
26
28{
29 return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx());
30}
31
33{
34 double Pv = (pressure() - m_Pref)/molarDensity();
35 return RT() * (mean_X(gibbs_RT_ref()) + sum_xlogx()) + Pv;
36}
37
39{
40 return GasConstant * mean_X(cp_R_ref());
41}
42
43// Mechanical Equation of State
44
46{
47 // Calculate the molarVolume of the solution (m**3 kmol-1)
48 double v_mol = mean_X(m_speciesMolarVolume);
49
50 // Set the density in the parent object directly, by calling the
51 // Phase::assignDensity() function.
53}
54
56{
57 m_Pcurrent = p;
59}
60
62{
65}
66
67// Chemical Potentials and Activities
68
70{
71 if (m_formGC == 0) {
72 return Units(1.0); // dimensionless
73 } else {
74 // kmol/m^3 for bulk phases
75 return Units(1.0, 0, -static_cast<double>(nDim()), 0, 0, 0, 1);
76 }
77}
78
80{
82 switch (m_formGC) {
83 case 0:
84 break;
85 case 1:
86 for (size_t k = 0; k < m_kk; k++) {
87 c[k] /= m_speciesMolarVolume[k];
88 }
89 break;
90 case 2:
91 for (size_t k = 0; k < m_kk; k++) {
92 c[k] /= m_speciesMolarVolume[m_kk-1];
93 }
94 break;
95 }
96}
97
99{
100 switch (m_formGC) {
101 case 0:
102 return 1.0;
103 case 1:
104 return 1.0 / m_speciesMolarVolume[k];
105 case 2:
106 return 1.0/m_speciesMolarVolume[m_kk-1];
107 }
108 return 0.0;
109}
110
112{
113 for (size_t k = 0; k < m_kk; k++) {
114 ac[k] = 1.0;
115 }
116}
117
119{
120 double delta_p = m_Pcurrent - m_Pref;
121 const vector<double>& g_RT = gibbs_RT_ref();
122 for (size_t k = 0; k < m_kk; k++) {
123 double xx = std::max(SmallNumber, moleFraction(k));
124 mu[k] = RT() * (g_RT[k] + log(xx))
125 + delta_p * m_speciesMolarVolume[k];
126 }
127}
128
129// Partial Molar Properties
130
132{
133 const vector<double>& _h = enthalpy_RT_ref();
134 double delta_p = m_Pcurrent - m_Pref;
135 for (size_t k = 0; k < m_kk; k++) {
136 hbar[k] = _h[k]*RT() + delta_p * m_speciesMolarVolume[k];
137 }
138 // scale(_h.begin(), _h.end(), hbar, RT());
139}
140
142{
143 const vector<double>& _s = entropy_R_ref();
144 for (size_t k = 0; k < m_kk; k++) {
145 double xx = std::max(SmallNumber, moleFraction(k));
146 sbar[k] = GasConstant * (_s[k] - log(xx));
147 }
148}
149
151{
152 getCp_R(cpbar);
153 for (size_t k = 0; k < m_kk; k++) {
154 cpbar[k] *= GasConstant;
155 }
156}
157
159{
160 getStandardVolumes(vbar);
161}
162
163// Properties of the Standard State of the Species in the Solution
164
165void IdealSolidSolnPhase::getPureGibbs(double* gpure) const
166{
167 warn_deprecated("IdealSolidSolnPhase::getPureGibbs",
168 "To be removed after Cantera 3.2. Use getStandardChemPotentials instead.");
170}
171
173{
174 const vector<double>& gibbsrt = gibbs_RT_ref();
175 double delta_p = (m_Pcurrent - m_Pref);
176 for (size_t k = 0; k < m_kk; k++) {
177 g0[k] = RT() * gibbsrt[k] + delta_p * m_speciesMolarVolume[k];
178 }
179}
180
181void IdealSolidSolnPhase::getGibbs_RT(double* grt) const
182{
183 const vector<double>& gibbsrt = gibbs_RT_ref();
184 double delta_prt = (m_Pcurrent - m_Pref)/ RT();
185 for (size_t k = 0; k < m_kk; k++) {
186 grt[k] = gibbsrt[k] + delta_prt * m_speciesMolarVolume[k];
187 }
188}
189
191{
192 const vector<double>& _h = enthalpy_RT_ref();
193 double delta_prt = (m_Pcurrent - m_Pref) / RT();
194 for (size_t k = 0; k < m_kk; k++) {
195 hrt[k] = _h[k] + delta_prt * m_speciesMolarVolume[k];
196 }
197}
198
200{
201 const vector<double>& _s = entropy_R_ref();
202 copy(_s.begin(), _s.end(), sr);
203}
204
206{
207 const vector<double>& _h = enthalpy_RT_ref();
208 double prefrt = m_Pref / RT();
209 for (size_t k = 0; k < m_kk; k++) {
210 urt[k] = _h[k] - prefrt * m_speciesMolarVolume[k];
211 }
212}
213
214void IdealSolidSolnPhase::getCp_R(double* cpr) const
215{
216 const vector<double>& _cpr = cp_R_ref();
217 copy(_cpr.begin(), _cpr.end(), cpr);
218}
219
221{
222 copy(m_speciesMolarVolume.begin(), m_speciesMolarVolume.end(), vol);
223}
224
225// Thermodynamic Values for the Species Reference States
226
228{
230 for (size_t k = 0; k != m_kk; k++) {
231 hrt[k] = m_h0_RT[k];
232 }
233}
234
236{
238 for (size_t k = 0; k != m_kk; k++) {
239 grt[k] = m_g0_RT[k];
240 }
241}
242
244{
246 double tmp = RT();
247 for (size_t k = 0; k != m_kk; k++) {
248 g[k] = tmp * m_g0_RT[k];
249 }
250}
251
253{
254 const vector<double>& _h = enthalpy_RT_ref();
255 double prefrt = m_Pref / RT();
256 for (size_t k = 0; k < m_kk; k++) {
257 urt[k] = _h[k] - prefrt * m_speciesMolarVolume[k];
258 }
259}
260
262{
264 for (size_t k = 0; k != m_kk; k++) {
265 er[k] = m_s0_R[k];
266 }
267}
268
269void IdealSolidSolnPhase::getCp_R_ref(double* cpr) const
270{
272 for (size_t k = 0; k != m_kk; k++) {
273 cpr[k] = m_cp0_R[k];
274 }
275}
276
277const vector<double>& IdealSolidSolnPhase::enthalpy_RT_ref() const
278{
280 return m_h0_RT;
281}
282
283const vector<double>& IdealSolidSolnPhase::entropy_R_ref() const
284{
286 return m_s0_R;
287}
288
289// Utility Functions
290
291bool IdealSolidSolnPhase::addSpecies(shared_ptr<Species> spec)
292{
293 bool added = ThermoPhase::addSpecies(spec);
294 if (added) {
295 if (m_kk == 1) {
296 // Obtain the reference pressure by calling the ThermoPhase function
297 // refPressure, which in turn calls the species thermo reference
298 // pressure function of the same name.
300 }
301
302 m_h0_RT.push_back(0.0);
303 m_g0_RT.push_back(0.0);
304 m_expg0_RT.push_back(0.0);
305 m_cp0_R.push_back(0.0);
306 m_s0_R.push_back(0.0);
307 m_pp.push_back(0.0);
308 if (spec->input.hasKey("equation-of-state")) {
309 auto& eos = spec->input["equation-of-state"].getMapWhere("model", "constant-volume");
310 double mv;
311 if (eos.hasKey("density")) {
312 mv = molecularWeight(m_kk-1) / eos.convert("density", "kg/m^3");
313 } else if (eos.hasKey("molar-density")) {
314 mv = 1.0 / eos.convert("molar-density", "kmol/m^3");
315 } else if (eos.hasKey("molar-volume")) {
316 mv = eos.convert("molar-volume", "m^3/kmol");
317 } else {
318 throw CanteraError("IdealSolidSolnPhase::addSpecies",
319 "equation-of-state entry for species '{}' is missing "
320 "'density', 'molar-volume', or 'molar-density' "
321 "specification", spec->name);
322 }
323 m_speciesMolarVolume.push_back(mv);
324 } else {
325 throw CanteraError("IdealSolidSolnPhase::addSpecies",
326 "Molar volume not specified for species '{}'", spec->name);
327 }
328 if (ready()) {
329 calcDensity();
330 }
331 }
332 return added;
333}
334
336{
337 if (m_input.hasKey("standard-concentration-basis")) {
338 setStandardConcentrationModel(m_input["standard-concentration-basis"].asString());
339 }
341}
342
344{
346 if (m_formGC == 1) {
347 phaseNode["standard-concentration-basis"] = "species-molar-volume";
348 } else if (m_formGC == 2) {
349 phaseNode["standard-concentration-basis"] = "solvent-molar-volume";
350 }
351}
352
354 AnyMap& speciesNode) const
355{
357 size_t k = speciesIndex(name, true);
358 const auto S = species(k);
359 auto& eosNode = speciesNode["equation-of-state"].getMapWhere(
360 "model", "constant-volume", true);
361 // Output volume information in a form consistent with the input
362 if (S->input.hasKey("equation-of-state")) {
363 auto& eosIn = S->input["equation-of-state"];
364 if (eosIn.hasKey("density")) {
365 eosNode["density"].setQuantity(
366 molecularWeight(k) / m_speciesMolarVolume[k], "kg/m^3");
367 } else if (eosIn.hasKey("molar-density")) {
368 eosNode["molar-density"].setQuantity(1.0 / m_speciesMolarVolume[k],
369 "kmol/m^3");
370 } else {
371 eosNode["molar-volume"].setQuantity(m_speciesMolarVolume[k],
372 "m^3/kmol");
373 }
374 } else {
375 eosNode["molar-volume"].setQuantity(m_speciesMolarVolume[k],
376 "m^3/kmol");
377 }
378}
379
381{
382 const vector<double>& grt = gibbs_RT_ref();
383
384 // Within the method, we protect against inf results if the exponent is too
385 // high.
386 //
387 // If it is too low, we set the partial pressure to zero. This capability is
388 // needed by the elemental potential method.
389 double pres = 0.0;
390 double m_p0 = refPressure();
391 for (size_t k = 0; k < m_kk; k++) {
392 double tmp = -grt[k] + mu_RT[k];
393 if (tmp < -600.) {
394 m_pp[k] = 0.0;
395 } else if (tmp > 500.0) {
396 // Protect against inf results if the exponent is too high
397 double tmp2 = tmp / 500.;
398 tmp2 *= tmp2;
399 m_pp[k] = m_p0 * exp(500.) * tmp2;
400 } else {
401 m_pp[k] = m_p0 * exp(tmp);
402 }
403 pres += m_pp[k];
404 }
405 // set state
406 setMoleFractions(m_pp.data());
407 setPressure(pres);
408}
409
411{
412 if (caseInsensitiveEquals(model, "unity")) {
413 m_formGC = 0;
414 } else if (caseInsensitiveEquals(model, "species-molar-volume")
415 || caseInsensitiveEquals(model, "molar_volume")) {
416 m_formGC = 1;
417 } else if (caseInsensitiveEquals(model, "solvent-molar-volume")
418 || caseInsensitiveEquals(model, "solvent_volume")) {
419 m_formGC = 2;
420 } else {
421 throw CanteraError("IdealSolidSolnPhase::setStandardConcentrationModel",
422 "Unknown standard concentration model '{}'", model);
423 }
424}
425
427{
428 return m_speciesMolarVolume[k];
429}
430
432{
433 copy(m_speciesMolarVolume.begin(), m_speciesMolarVolume.end(), smv);
434}
435
437{
438 double tnow = temperature();
439 if (m_tlast != tnow) {
440
441 // Update the thermodynamic functions of the reference state.
442 m_spthermo.update(tnow, m_cp0_R.data(), m_h0_RT.data(), m_s0_R.data());
443 m_tlast = tnow;
444 for (size_t k = 0; k < m_kk; k++) {
445 m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
446 }
447 m_tlast = tnow;
448 }
449}
450
451} // end namespace Cantera
Header file for an ideal solid solution model with incompressible thermodynamics (see Thermodynamic P...
Declaration for class Cantera::Species.
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1477
Base class for exceptions thrown by Cantera classes.
const vector< double > & entropy_R_ref() const
Returns a reference to the vector of nondimensional enthalpies of the reference state at the current ...
void getStandardChemPotentials(double *mu0) const override
Get the standard state chemical potentials of the species.
void getPartialMolarEnthalpies(double *hbar) const override
Returns an array of partial molar enthalpies for the species in the mixture.
void getChemPotentials(double *mu) const override
Get the species chemical potentials.
double pressure() const override
Pressure.
vector< double > m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast.
void getSpeciesParameters(const string &name, AnyMap &speciesNode) const override
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
void getEntropy_R(double *sr) const override
Get the nondimensional Entropies for the species standard states at the current T and P of the soluti...
vector< double > m_h0_RT
Vector containing the species reference enthalpies at T = m_tlast.
void getGibbs_ref(double *g) const override
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
double speciesMolarVolume(int k) const
Report the molar volume of species k.
vector< double > m_pp
Temporary array used in equilibrium calculations.
double m_Pref
Value of the reference pressure for all species in this phase.
void getCp_R(double *cpr) const override
Get the nondimensional heat capacity at constant pressure function for the species standard states at...
void getParameters(AnyMap &phaseNode) const override
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void getActivityConcentrations(double *c) const override
This method returns the array of generalized concentrations.
void getSpeciesMolarVolumes(double *smv) const
Fill in a return vector containing the species molar volumes.
void setPressure(double p) override
Set the pressure at constant temperature.
const vector< double > & gibbs_RT_ref() const
Returns a reference to the vector of nondimensional enthalpies of the reference state at the current ...
void getPartialMolarVolumes(double *vbar) const override
returns an array of partial molar volumes of the species in the solution.
void getPureGibbs(double *gpure) const override
Get the Gibbs functions for the pure species at the current T and P of the solution.
double standardConcentration(size_t k) const override
The standard concentration used to normalize the generalized concentration.
void setStandardConcentrationModel(const string &model)
Set the form for the standard and generalized concentrations.
void getIntEnergy_RT_ref(double *urt) const override
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
void getEnthalpy_RT(double *hrt) const override
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
void getEntropy_R_ref(double *er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
vector< double > m_s0_R
Vector containing the species reference entropies at T = m_tlast.
void getGibbs_RT(double *grt) const override
Get the nondimensional Gibbs function for the species standard states at the current T and P of the s...
double entropy_mole() const override
Molar entropy of the solution.
int m_formGC
The standard concentrations can have one of three different forms: 0 = 'unity', 1 = 'species-molar-vo...
vector< double > m_speciesMolarVolume
Vector of molar volumes for each species in the solution.
void getCp_R_ref(double *cprt) const override
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
void getStandardVolumes(double *vol) const override
Get the molar volumes of the species standard states at the current T and P of the solution.
double cp_mole() const override
Molar heat capacity of the solution at at constant pressure and composition [J/kmol/K].
void getIntEnergy_RT(double *urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Units standardConcentrationUnits() const override
Returns the units of the "standard concentration" for this phase.
IdealSolidSolnPhase(const string &infile="", const string &id="")
Construct and initialize an IdealSolidSolnPhase ThermoPhase object directly from an input file.
void getPartialMolarCp(double *cpbar) const override
Returns an array of partial molar Heat Capacities at constant pressure of the species in the solution...
void compositionChanged() override
Apply changes to the state which are needed after the composition changes.
double gibbs_mole() const override
Molar Gibbs free energy of the solution.
vector< double > m_cp0_R
Vector containing the species reference constant pressure heat capacities at T = m_tlast.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
virtual void _updateThermo() const
This function gets called for every call to functions in this class.
void setToEquilState(const double *mu_RT) override
This method is used by the ChemEquil equilibrium solver.
void getGibbs_RT_ref(double *grt) const override
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
void getActivityCoefficients(double *ac) const override
Get the array of species activity coefficients.
vector< double > m_expg0_RT
Vector containing the species reference exp(-G/RT) functions at T = m_tlast.
void getPartialMolarEntropies(double *sbar) const override
Returns an array of partial molar entropies of the species in the solution.
const vector< double > & cp_R_ref() const
Returns a reference to the vector of nondimensional enthalpies of the reference state at the current ...
double m_Pcurrent
m_Pcurrent = The current pressure Since the density isn't a function of pressure, but only of the mol...
void getEnthalpy_RT_ref(double *hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
virtual void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
const vector< double > & enthalpy_RT_ref() const
Returns a reference to the vector of nondimensional enthalpies of the reference state at the current ...
virtual void update(double T, double *cp_R, double *h_RT, double *s_R) const
Compute the reference-state properties for all species.
virtual double molarDensity() const
Molar density (kmol/m^3).
Definition Phase.cpp:639
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:660
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
Definition Phase.cpp:347
size_t m_kk
Number of species in the phase.
Definition Phase.h:921
size_t nDim() const
Returns the number of spatial dimensions (1, 2, or 3)
Definition Phase.h:613
double temperature() const
Temperature (K).
Definition Phase.h:629
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:722
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition Phase.cpp:499
double sum_xlogx() const
Evaluate .
Definition Phase.cpp:689
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:147
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition Phase.cpp:504
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
Definition Phase.cpp:981
double mean_X(const double *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition Phase.cpp:679
virtual bool ready() const
Returns a bool indicating whether the object is ready for use.
Definition Phase.cpp:961
double molecularWeight(size_t k) const
Molecular weight of species k.
Definition Phase.cpp:448
shared_ptr< Species > species(const string &name) const
Return the Species object for the named species.
Definition Phase.cpp:937
string name() const
Return the name of the phase.
Definition Phase.cpp:20
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
double RT() const
Return the Gas Constant multiplied by the current temperature.
double m_tlast
last value of the temperature processed by reference state
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
void initThermoFile(const string &inputFile, const string &id)
Initialize a ThermoPhase object using an input file.
virtual void getSpeciesParameters(const string &name, AnyMap &speciesNode) const
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
virtual double refPressure() const
Returns the reference pressure in Pa.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
AnyMap m_input
Data supplied via setParameters.
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
bool caseInsensitiveEquals(const string &input, const string &test)
Case insensitive equality predicate.
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const double SmallNumber
smallest number to compare to zero.
Definition ct_defs.h:158
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...