19 #include <boost/algorithm/string.hpp>
21 namespace ba = boost::algorithm;
29 for (
size_t n = 0; n <
m_lattice.size(); n++) {
30 if (lkstart_[n+1] < k) {
31 return m_lattice[n]->minTemp(k-lkstart_[n]);
37 mm = std::max(mm, lattice->minTemp());
45 for (
size_t n = 0; n <
m_lattice.size(); n++) {
46 if (lkstart_[n+1] < k) {
47 return (
m_lattice[n])->maxTemp(k - lkstart_[n]);
53 mm = std::min(mm, lattice->maxTemp());
67 for (
size_t n = 0; n <
m_lattice.size(); n++) {
77 for (
size_t n = 0; n <
m_lattice.size(); n++) {
87 for (
size_t n = 0; n <
m_lattice.size(); n++) {
97 for (
size_t n = 0; n <
m_lattice.size(); n++) {
107 for (
size_t n = 0; n <
m_lattice.size(); n++) {
122 for (
size_t n = 0; n <
m_lattice.size(); n++) {
130 for (
size_t k = 0; k <
m_kk; k++) {
148 for (
size_t n = 0; n <
m_lattice.size(); n++) {
157 for (
size_t n = 0; n <
m_lattice.size(); n++) {
167 for (
size_t n = 0; n <
m_lattice.size(); n++) {
169 m_lattice[n]->setMoleFractions(x + strt);
172 for (
size_t k = 0; k < strt; k++) {
184 for (
size_t n = 0; n <
m_lattice.size(); n++) {
187 for (
size_t k = 0; k < nsp; k++) {
188 sum += (x + strt)[k];
190 for (
size_t k = 0; k < nsp; k++) {
191 (x + strt)[k] /= sum;
197 for (
size_t k = 0; k < nsp; k++) {
198 if (fabs((x + strt)[k] -
m_x[strt+k]) > 1.0E-14) {
199 throw CanteraError(
"LatticeSolidPhase::getMoleFractions",
211 for (
size_t n = 0; n <
m_lattice.size(); n++) {
213 m_lattice[n]->getChemPotentials(mu+strt);
222 for (
size_t n = 0; n <
m_lattice.size(); n++) {
224 m_lattice[n]->getPartialMolarEnthalpies(hbar + strt);
233 for (
size_t n = 0; n <
m_lattice.size(); n++) {
235 m_lattice[n]->getPartialMolarEntropies(sbar + strt);
244 for (
size_t n = 0; n <
m_lattice.size(); n++) {
246 m_lattice[n]->getPartialMolarCp(cpbar + strt);
255 for (
size_t n = 0; n <
m_lattice.size(); n++) {
257 m_lattice[n]->getPartialMolarVolumes(vbar + strt);
266 for (
size_t n = 0; n <
m_lattice.size(); n++) {
267 m_lattice[n]->getStandardChemPotentials(mu0+strt);
275 for (
size_t n = 0; n <
m_lattice.size(); n++) {
276 m_lattice[n]->getGibbs_RT_ref(grt + lkstart_[n]);
283 for (
size_t k = 0; k <
m_kk; k++) {
299 for (
auto& [
name, stoich] : composition) {
314 for (
size_t i = 0; i <
m_lattice.size(); i++) {
317 phaseNode[
"composition"] = std::move(composition);
320 phaseNode.
erase(
"species");
321 vector<string> elements;
322 for (
auto& el : phaseNode[
"elements"].asVector<string>()) {
323 if (!ba::starts_with(el,
"LC_")) {
324 elements.push_back(el);
327 phaseNode[
"elements"] = elements;
331 AnyMap& speciesNode)
const
336 if (phase->speciesIndex(
name) !=
npos) {
337 phase->getSpeciesParameters(
name, speciesNode);
352 if (lkstart_.empty()) {
353 lkstart_.push_back(0);
355 lkstart_.push_back(lkstart_.back() + lattice->nSpecies());
363 for (
size_t k = 0; k < lattice->nSpecies(); k++) {
365 vector<double> constArr(lattice->nElements());
366 const vector<double>& aws = lattice->atomicWeights();
367 for (
size_t es = 0; es < lattice->nElements(); es++) {
368 addElement(lattice->elementName(es), aws[es], lattice->atomicNumber(es),
369 lattice->entropyElement298(es), lattice->elementType(es));
371 m_x.push_back(lattice->moleFraction(k));
372 tmpV_.push_back(0.0);
378 for (
size_t i = 0; i <
m_lattice.size(); i++) {
382 for (
size_t i = 1; i <
m_lattice.size(); i++) {
383 string econ = fmt::format(
"LC_{}_{}", i,
name());
386 for (
size_t k = 0; k <
m_lattice[0]->nSpecies(); k++) {
389 for (
size_t k = 0; k <
m_lattice[i]->nSpecies(); k++) {
390 size_t ks = lkstart_[i] + k;
402 for (
size_t n = 0; n <
m_lattice.size(); n++) {
414 m_lattice[nn]->setMoleFractionsByName(x);
416 for (
size_t n = 0; n <
m_lattice.size(); n++) {
418 double ndens =
m_lattice[n]->molarDensity();
419 for (
size_t k = 0; k < nsp; k++) {
429 for (
size_t n = 0; n <
m_lattice.size(); n++) {
430 if (lkstart_[n+1] < k) {
431 size_t kk = k-lkstart_[n];
443 for (
size_t n = 0; n <
m_lattice.size(); n++) {
444 if (lkstart_[n+1] < k) {
445 size_t kk = k-lkstart_[n];
446 m_lattice[n]->speciesThermo().resetHf298(kk);
450 for (
size_t n = 0; n <
m_lattice.size(); n++) {
#define CT_ELEM_TYPE_LATTICERATIO
Constraint associated with maintaining a fixed lattice stoichiometry in a solid.
Header for a simple thermodynamics model of a bulk solid phase derived from ThermoPhase,...
Header for a general species thermodynamic property manager for a phase (see MultiSpeciesThermo).
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
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.
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
void erase(const string &key)
Erase the value held by key.
Base class for exceptions thrown by Cantera classes.
vector< shared_ptr< ThermoPhase > > m_lattice
Vector of sublattice ThermoPhase objects.
void setLatticeStoichiometry(const Composition &comp)
Set the lattice stoichiometric coefficients, .
void getStandardChemPotentials(double *mu0) const override
Get the array of standard state chemical potentials at unit activity for the species at their standar...
double enthalpy_mole() const override
Return the Molar Enthalpy. Units: J/kmol.
double logStandardConc(size_t k=0) const override
Natural logarithm of the standard concentration of the kth species.
AnyMap m_rootNode
Root node of the AnyMap which contains this phase definition.
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. Units: J/kmol.
vector< double > tmpV_
Temporary vector.
vector< double > m_x
Vector of mole fractions.
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 getGibbs_ref(double *g) const override
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
void modifyOneHf298SS(const size_t k, const double Hf298New) override
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1)
vector< double > theta_
Lattice stoichiometric coefficients.
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 setMoleFractions(const double *const x) override
Set the mole fractions to the specified values, and then normalize them so that they sum to 1....
void getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
void setPressure(double p) override
Set the pressure at constant temperature. Units: Pa.
void getPartialMolarVolumes(double *vbar) const override
returns an array of partial molar volumes of the species in the solution.
void setLatticeMoleFractionsByName(int n, const string &x)
Set the Lattice mole fractions using a string.
double m_press
Current value of the pressure.
double refPressure() const override
Returns the reference pressure in Pa.
double minTemp(size_t k=npos) const override
Minimum temperature for which the thermodynamic data for the species or phase are valid.
double intEnergy_mole() const override
Return the Molar Internal Energy. Units: J/kmol.
double entropy_mole() const override
Return the Molar Entropy. Units: J/kmol/K.
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
double cp_mole() const override
Return the constant pressure heat capacity. Units: J/kmol/K.
Units standardConcentrationUnits() const override
Returns the units of the "standard concentration" for this phase.
void getPartialMolarCp(double *cpbar) const override
Returns an array of partial molar Heat Capacities at constant pressure of the species in the solution...
double gibbs_mole() const override
Return the Molar Gibbs energy. Units: J/kmol.
double standardConcentration(size_t k=0) const override
Return the standard concentration for the kth species.
void addLattice(shared_ptr< ThermoPhase > lattice)
Add a lattice to this phase.
double calcDensity()
Calculate the density of the solid mixture.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
void _updateThermo() const
Update the reference thermodynamic functions.
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 non-dimensional molar-based activity coefficients at the current solution temperatur...
void setParameters(const AnyMap &phaseNode, const AnyMap &rootNode=AnyMap()) override
Set equation of state parameters from an AnyMap phase description.
void resetHf298(const size_t k=npos) override
Restore the original heat of formation of one or more species.
void getPartialMolarEntropies(double *sbar) const override
Returns an array of partial molar entropies of the species in the solution.
double maxTemp(size_t k=npos) const override
Maximum temperature for which the thermodynamic data for the species are valid.
A species thermodynamic property manager for a phase.
virtual void modifyOneHf298(const size_t k, const double Hf298New)
Modify the value of the 298 K Heat of Formation of the standard state of one species in the phase (J ...
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
vector< double > m_speciesComp
Atomic composition of the species.
size_t m_kk
Number of species in the phase.
double temperature() const
Temperature (K).
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
size_t nElements() const
Number of elements.
size_t addElement(const string &symbol, double weight=-12345.0, int atomicNumber=0, double entropy298=ENTROPY298_UNKNOWN, int elem_type=CT_ELEM_TYPE_ABSPOS)
Add an element.
string name() const
Return the name of the phase.
virtual void setParameters(const AnyMap &phaseNode, const AnyMap &rootNode=AnyMap())
Set equation of state parameters from an AnyMap phase description.
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 invalidateCache() override
Invalidate any cached values which are normally updated only when a change in state is detected.
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.
shared_ptr< ThermoPhase > newThermo(const AnyMap &phaseNode, const AnyMap &rootNode)
Create a new ThermoPhase object and initialize it.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
const U & getValue(const map< T, U > &m, const T &key, const U &default_val)
Const accessor for a value in a map.
const double BigNumber
largest number to compare to inf.
map< string, double > Composition
Map from string names to doubles.
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...