20#include <boost/algorithm/string.hpp>
23namespace ba = boost::algorithm;
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]);
42 doublereal mm = 1.0E300;
43 for (
size_t n = 0; n <
m_lattice.size(); n++) {
45 mm = std::min(mm, ml);
53 for (
size_t n = 0; n <
m_lattice.size(); n++) {
54 if (lkstart_[n+1] < k) {
55 return (
m_lattice[n])->maxTemp(k - lkstart_[n]);
59 doublereal mm = -1.0E300;
60 for (
size_t n = 0; n <
m_lattice.size(); n++) {
62 mm = std::max(mm, ml);
76 for (
size_t n = 0; n <
m_lattice.size(); n++) {
86 for (
size_t n = 0; n <
m_lattice.size(); n++) {
96 for (
size_t n = 0; n <
m_lattice.size(); n++) {
105 doublereal sum = 0.0;
106 for (
size_t n = 0; n <
m_lattice.size(); n++) {
115 doublereal sum = 0.0;
116 for (
size_t n = 0; n <
m_lattice.size(); n++) {
131 for (
size_t n = 0; n <
m_lattice.size(); n++) {
139 for (
size_t k = 0; k <
m_kk; k++) {
157 for (
size_t n = 0; n <
m_lattice.size(); n++) {
166 for (
size_t n = 0; n <
m_lattice.size(); n++) {
176 for (
size_t n = 0; n <
m_lattice.size(); n++) {
178 m_lattice[n]->setMoleFractions(x + strt);
181 for (
size_t k = 0; k < strt; k++) {
193 for (
size_t n = 0; n <
m_lattice.size(); n++) {
196 for (
size_t k = 0; k < nsp; k++) {
197 sum += (x + strt)[k];
199 for (
size_t k = 0; k < nsp; k++) {
200 (x + strt)[k] /= sum;
206 for (
size_t k = 0; k < nsp; k++) {
207 if (fabs((x + strt)[k] -
m_x[strt+k]) > 1.0E-14) {
208 throw CanteraError(
"LatticeSolidPhase::getMoleFractions",
220 for (
size_t n = 0; n <
m_lattice.size(); n++) {
222 m_lattice[n]->getChemPotentials(mu+strt);
231 for (
size_t n = 0; n <
m_lattice.size(); n++) {
233 m_lattice[n]->getPartialMolarEnthalpies(hbar + strt);
242 for (
size_t n = 0; n <
m_lattice.size(); n++) {
244 m_lattice[n]->getPartialMolarEntropies(sbar + strt);
253 for (
size_t n = 0; n <
m_lattice.size(); n++) {
255 m_lattice[n]->getPartialMolarCp(cpbar + strt);
264 for (
size_t n = 0; n <
m_lattice.size(); n++) {
266 m_lattice[n]->getPartialMolarVolumes(vbar + strt);
275 for (
size_t n = 0; n <
m_lattice.size(); n++) {
276 m_lattice[n]->getStandardChemPotentials(mu0+strt);
284 for (
size_t n = 0; n <
m_lattice.size(); n++) {
285 m_lattice[n]->getGibbs_RT_ref(grt + lkstart_[n]);
292 for (
size_t k = 0; k <
m_kk; k++) {
308 for (
auto& item : composition) {
323 for (
size_t i = 0; i <
m_lattice.size(); i++) {
326 phaseNode[
"composition"] = std::move(composition);
329 phaseNode.
erase(
"species");
330 vector<std::string> elements;
331 for (
auto& el : phaseNode[
"elements"].asVector<std::string>()) {
332 if (!ba::starts_with(el,
"LC_")) {
333 elements.push_back(el);
336 phaseNode[
"elements"] = elements;
340 AnyMap& speciesNode)
const
345 if (phase->speciesIndex(
name) !=
npos) {
346 phase->getSpeciesParameters(
name, speciesNode);
361 if (lkstart_.empty()) {
362 lkstart_.push_back(0);
364 lkstart_.push_back(lkstart_.back() + lattice->nSpecies());
372 for (
size_t k = 0; k < lattice->nSpecies(); k++) {
374 vector_fp constArr(lattice->nElements());
375 const vector_fp& aws = lattice->atomicWeights();
376 for (
size_t es = 0; es < lattice->nElements(); es++) {
377 addElement(lattice->elementName(es), aws[es], lattice->atomicNumber(es),
378 lattice->entropyElement298(es), lattice->elementType(es));
380 m_x.push_back(lattice->moleFraction(k));
381 tmpV_.push_back(0.0);
387 for (
size_t i = 0; i <
m_lattice.size(); i++) {
391 for (
size_t i = 1; i <
m_lattice.size(); i++) {
392 string econ = fmt::format(
"LC_{}_{}", i,
name());
395 for (
size_t k = 0; k <
m_lattice[0]->nSpecies(); k++) {
398 for (
size_t k = 0; k <
m_lattice[i]->nSpecies(); k++) {
399 size_t ks = lkstart_[i] + k;
411 for (
size_t n = 0; n <
m_lattice.size(); n++) {
423 m_lattice[nn]->setMoleFractionsByName(x);
425 for (
size_t n = 0; n <
m_lattice.size(); n++) {
427 double ndens =
m_lattice[n]->molarDensity();
428 for (
size_t k = 0; k < nsp; k++) {
438 eosdata.
_require(
"model",
"LatticeSolid");
440 std::vector<XML_Node*> lattices = la.
getChildren(
"phase");
441 for (
auto lattice : lattices) {
449 for (
size_t n = 0; n <
m_lattice.size(); n++) {
450 if (lkstart_[n+1] < k) {
451 size_t kk = k-lkstart_[n];
463 for (
size_t n = 0; n <
m_lattice.size(); n++) {
464 if (lkstart_[n+1] < k) {
465 size_t kk = k-lkstart_[n];
466 m_lattice[n]->speciesThermo().resetHf298(kk);
470 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.
void erase(const std::string &key)
Erase the value held by key.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Base class for exceptions thrown by Cantera classes.
virtual void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
doublereal m_press
Current value of the pressure.
AnyMap m_rootNode
Root node of the AnyMap which contains this phase definition.
virtual bool addSpecies(shared_ptr< Species > spec)
LatticeSolidPhase()
Base empty constructor.
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
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 ...
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
vector_fp m_x
Vector of mole fractions.
std::vector< shared_ptr< ThermoPhase > > m_lattice
Vector of sublattic ThermoPhase objects.
virtual doublereal cp_mole() const
Return the constant pressure heat capacity. Units: J/kmol/K.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
virtual doublereal enthalpy_mole() const
Return the Molar Enthalpy. Units: J/kmol.
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
virtual void getPartialMolarVolumes(doublereal *vbar) const
returns an array of partial molar volumes of the species in the solution.
doublereal calcDensity()
Calculate the density of the solid mixture.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
void setLatticeMoleFractionsByName(int n, const std::string &x)
Set the Lattice mole fractions using a string.
virtual void getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar Heat Capacities at constant pressure of the species in the solution...
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of standard state chemical potentials at unit activity for the species at their standar...
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
virtual doublereal entropy_mole() const
Return the Molar Entropy. Units: J/kmol/K.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values, and then normalize them so that they sum to 1....
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
virtual void resetHf298(const size_t k=npos)
Restore the original heat of formation of one or more species.
vector_fp theta_
Lattice stoichiometric coefficients.
virtual doublereal gibbs_mole() const
Return the Molar Gibbs energy. Units: J/kmol.
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
virtual void getSpeciesParameters(const std::string &name, AnyMap &speciesNode) const
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
void setLatticeStoichiometry(const compositionMap &comp)
Set the lattice stoichiometric coefficients, .
virtual void modifyOneHf298SS(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1)
void addLattice(shared_ptr< ThermoPhase > lattice)
Add a lattice to this phase.
void _updateThermo() const
Update the reference thermodynamic functions.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual void getGibbs_ref(doublereal *g) const
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
vector_fp tmpV_
Temporary vector.
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
virtual doublereal intEnergy_mole() const
Return the Molar Internal Energy. Units: J/kmol.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
A species thermodynamic property manager for a phase.
virtual void modifyOneHf298(const size_t k, const doublereal 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.
size_t addElement(const std::string &symbol, doublereal weight=-12345.0, int atomicNumber=0, doublereal entropy298=ENTROPY298_UNKNOWN, int elem_type=CT_ELEM_TYPE_ABSPOS)
Add an element.
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
std::string name() const
Return the name of the phase.
size_t m_kk
Number of species in the phase.
vector_fp m_speciesComp
Atomic composition of the species.
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
doublereal temperature() const
Temperature (K).
size_t nElements() const
Number of elements.
virtual bool addSpecies(shared_ptr< Species > spec)
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
doublereal 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.
AnyMap m_input
Data supplied via setParameters.
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
A representation of the units associated with a dimensional quantity.
Class XML_Node is a tree-based representation of the contents of an XML file.
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,...
std::vector< XML_Node * > getChildren(const std::string &name) const
Get a vector of pointers to XML_Node containing all of the children of the current node which match t...
std::string value() const
Return the value of an XML node as a string.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
std::map< std::string, double > compositionMap
Map connecting a string name with a double.
const U & getValue(const std::map< T, U > &m, const T &key, const U &default_val)
Const accessor for a value in a std::map.
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names=std::vector< std::string >())
Parse a composition string into a map consisting of individual key:composition pairs.
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...