19#include <boost/algorithm/string.hpp>
21namespace ba = boost::algorithm;
28 warn_deprecated(
"class LatticeSolidPhase",
"To be removed after Cantera 3.2. No "
29 "known usage exists, and the model does not satisfy several basic thermodynamic"
30 "identities. See https://github.com/Cantera/cantera/issues/1310.");
36 for (
size_t n = 0; n <
m_lattice.size(); n++) {
37 if (lkstart_[n+1] < k) {
38 return m_lattice[n]->minTemp(k-lkstart_[n]);
44 mm = std::max(mm, lattice->minTemp());
52 for (
size_t n = 0; n <
m_lattice.size(); n++) {
53 if (lkstart_[n+1] < k) {
54 return (
m_lattice[n])->maxTemp(k - lkstart_[n]);
60 mm = std::min(mm, lattice->maxTemp());
74 for (
size_t n = 0; n <
m_lattice.size(); n++) {
84 for (
size_t n = 0; n <
m_lattice.size(); n++) {
94 for (
size_t n = 0; n <
m_lattice.size(); n++) {
104 for (
size_t n = 0; n <
m_lattice.size(); n++) {
114 for (
size_t n = 0; n <
m_lattice.size(); n++) {
129 for (
size_t n = 0; n <
m_lattice.size(); n++) {
137 for (
size_t k = 0; k <
m_kk; k++) {
155 for (
size_t n = 0; n <
m_lattice.size(); n++) {
164 for (
size_t n = 0; n <
m_lattice.size(); n++) {
174 for (
size_t n = 0; n <
m_lattice.size(); n++) {
176 m_lattice[n]->setMoleFractions(x + strt);
179 for (
size_t k = 0; k < strt; k++) {
191 for (
size_t n = 0; n <
m_lattice.size(); n++) {
194 for (
size_t k = 0; k < nsp; k++) {
195 sum += (x + strt)[k];
197 for (
size_t k = 0; k < nsp; k++) {
198 (x + strt)[k] /= sum;
204 for (
size_t k = 0; k < nsp; k++) {
205 if (fabs((x + strt)[k] -
m_x[strt+k]) > 1.0E-14) {
206 throw CanteraError(
"LatticeSolidPhase::getMoleFractions",
218 for (
size_t n = 0; n <
m_lattice.size(); n++) {
220 m_lattice[n]->getChemPotentials(mu+strt);
229 for (
size_t n = 0; n <
m_lattice.size(); n++) {
231 m_lattice[n]->getPartialMolarEnthalpies(hbar + strt);
240 for (
size_t n = 0; n <
m_lattice.size(); n++) {
242 m_lattice[n]->getPartialMolarEntropies(sbar + strt);
251 for (
size_t n = 0; n <
m_lattice.size(); n++) {
253 m_lattice[n]->getPartialMolarCp(cpbar + strt);
262 for (
size_t n = 0; n <
m_lattice.size(); n++) {
264 m_lattice[n]->getPartialMolarVolumes(vbar + strt);
273 for (
size_t n = 0; n <
m_lattice.size(); n++) {
274 m_lattice[n]->getStandardChemPotentials(mu0+strt);
282 for (
size_t n = 0; n <
m_lattice.size(); n++) {
283 m_lattice[n]->getGibbs_RT_ref(grt + lkstart_[n]);
290 for (
size_t k = 0; k <
m_kk; k++) {
306 for (
auto& [
name, stoich] : composition) {
321 for (
size_t i = 0; i <
m_lattice.size(); i++) {
324 phaseNode[
"composition"] = std::move(composition);
327 phaseNode.
erase(
"species");
328 vector<string> elements;
329 for (
auto& el : phaseNode[
"elements"].asVector<
string>()) {
330 if (!ba::starts_with(el,
"LC_")) {
331 elements.push_back(el);
334 phaseNode[
"elements"] = elements;
338 AnyMap& speciesNode)
const
343 if (phase->speciesIndex(
name) !=
npos) {
344 phase->getSpeciesParameters(
name, speciesNode);
359 if (lkstart_.empty()) {
360 lkstart_.push_back(0);
362 lkstart_.push_back(lkstart_.back() + lattice->nSpecies());
370 for (
size_t k = 0; k < lattice->nSpecies(); k++) {
372 vector<double> constArr(lattice->nElements());
373 const vector<double>& aws = lattice->atomicWeights();
374 for (
size_t es = 0; es < lattice->nElements(); es++) {
375 addElement(lattice->elementName(es), aws[es], lattice->atomicNumber(es),
376 lattice->entropyElement298(es), lattice->elementType(es));
378 m_x.push_back(lattice->moleFraction(k));
379 tmpV_.push_back(0.0);
385 for (
size_t i = 0; i <
m_lattice.size(); i++) {
389 for (
size_t i = 1; i <
m_lattice.size(); i++) {
390 string econ = fmt::format(
"LC_{}_{}", i,
name());
393 for (
size_t k = 0; k <
m_lattice[0]->nSpecies(); k++) {
396 for (
size_t k = 0; k <
m_lattice[i]->nSpecies(); k++) {
397 size_t ks = lkstart_[i] + k;
409 for (
size_t n = 0; n <
m_lattice.size(); n++) {
421 m_lattice[nn]->setMoleFractionsByName(x);
423 for (
size_t n = 0; n <
m_lattice.size(); n++) {
425 double ndens =
m_lattice[n]->molarDensity();
426 for (
size_t k = 0; k < nsp; k++) {
436 for (
size_t n = 0; n <
m_lattice.size(); n++) {
437 if (lkstart_[n+1] < k) {
438 size_t kk = k-lkstart_[n];
450 for (
size_t n = 0; n <
m_lattice.size(); n++) {
451 if (lkstart_[n+1] < k) {
452 size_t kk = k-lkstart_[n];
453 m_lattice[n]->speciesThermo().resetHf298(kk);
457 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.
LatticeSolidPhase()
Base empty constructor.
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"
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
const double BigNumber
largest number to compare to inf.
const U & getValue(const map< T, U > &m, const T &key, const U &default_val)
Const accessor for a value in a map.
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...