24 MolalityVPSSTP::MolalityVPSSTP() :
27 m_weightSolvent(18.01528),
28 m_xmolSolventMIN(0.01),
29 m_Mnaught(18.01528E-3)
44 "Unknown scale type: {}", pHscaleType);
55 warn_deprecated(
"MolalityVPSSTP::setSolvent",
"Solvent is always the first" 56 " species. To be removed after Cantera 2.4.");
62 " first species. To be removed after Cantera 2.4.");
68 if (xmolSolventMIN <= 0.0) {
69 throw CanteraError(
"MolalityVPSSTP::setSolute ",
"trouble");
70 }
else if (xmolSolventMIN > 0.9) {
71 throw CanteraError(
"MolalityVPSSTP::setSolute ",
"trouble");
85 double denomInv = 1.0/ (
m_Mnaught * xmolSolvent);
86 for (
size_t k = 0; k <
m_kk; k++) {
94 for (
size_t k = 0; k <
m_kk; k++) {
102 for (
size_t k = 1; k <
m_kk; k++) {
106 double tmp = 1.0 / Lsum;
109 for (
size_t k = 1; k <
m_kk; k++) {
115 for (
size_t k = 0; k <
m_kk; k++) {
135 for (
size_t k = 0; k <
m_kk; k++) {
143 size_t largePos =
npos;
145 size_t largeNeg =
npos;
148 for (
size_t k = 0; k <
m_kk; k++) {
151 if (ch > 0.0 && ch * mf[k] > cPos) {
155 if (ch < 0.0 && fabs(ch) * mf[k] > cNeg) {
157 cNeg = fabs(ch) * mf[k];
165 mf[largePos] -= sum /
charge(largePos);
167 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
168 "unbalanced charges");
172 mf[largeNeg] -= (-sum) / fabs(
charge(largeNeg));
174 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
175 "unbalanced charges");
180 for (
size_t k = 0; k <
m_kk; k++) {
184 for (
size_t k = 0; k <
m_kk; k++) {
226 for (
size_t k = 1; k <
m_kk; k++) {
227 ac[k] /= xmolSolvent;
245 for (
size_t k = 1; k <
m_kk; k++) {
249 if (sum > 1.0E-200) {
263 double p =
getFloat(state,
"pressure",
"pressure");
269 const doublereal*
const molalities)
307 size_t indexCLM =
npos;
311 for (
size_t e = 0; e < ne; e++) {
313 if (sn ==
"Cl" || sn ==
"CL") {
322 for (
size_t e = 0; e < ne; e++) {
324 if (sn ==
"E" || sn ==
"e") {
333 for (
size_t k = 1; k <
m_kk; k++) {
334 doublereal nCl =
nAtoms(k, eCl);
338 doublereal nE =
nAtoms(k, eE);
342 for (
size_t e = 0; e < ne; e++) {
343 if (e != eE && e != eCl) {
344 doublereal nA =
nAtoms(k, e);
351 if (sn !=
"Cl-" && sn !=
"CL-") {
377 fmt::memory_buffer b;
380 format_to(b,
"\n {}:\n",
name());
383 format_to(b,
" temperature {:12.6g} K\n",
temperature());
384 format_to(b,
" pressure {:12.6g} Pa\n",
pressure());
385 format_to(b,
" density {:12.6g} kg/m^3\n",
density());
389 format_to(b,
" potential {:12.6g} V\n", phi);
406 double pH = -log(actMolal[iHp]) / log(10.0);
407 format_to(b,
" pH {:12.4g}\n", pH);
412 format_to(b,
" 1 kg 1 kmol\n");
413 format_to(b,
" ----------- ------------\n");
414 format_to(b,
" enthalpy {:12.6g} {:12.4g} J\n",
416 format_to(b,
" internal energy {:12.6g} {:12.4g} J\n",
418 format_to(b,
" entropy {:12.6g} {:12.4g} J/K\n",
420 format_to(b,
" Gibbs function {:12.6g} {:12.4g} J\n",
422 format_to(b,
" heat capacity c_p {:12.6g} {:12.4g} J/K\n",
425 format_to(b,
" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
428 format_to(b,
" heat capacity c_v <not implemented>\n");
434 doublereal xMinor = 0.0;
437 " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n");
439 " (J/kmol) (J/kmol)\n");
440 format_to(b,
" ------------- " 441 " ------------ ------------ ------------ ------------\n");
442 for (
size_t k = 0; k <
m_kk; k++) {
443 if (x[k] > threshold) {
445 format_to(b,
"{:>18s} {:12.6g} {:12.6g} {:12.6g} {:12.6g} {:12.6g}\n",
446 speciesName(k), x[k], molal[k], mu[k], muss[k], acMolal[k]);
448 format_to(b,
"{:>18s} {:12.6g} {:12.6g} N/A {:12.6g} {:12.6g}\n",
449 speciesName(k), x[k], molal[k], muss[k], acMolal[k]);
459 format_to(b,
" -------------" 461 for (
size_t k = 0; k <
m_kk; k++) {
462 if (x[k] > threshold) {
463 format_to(b,
"{:>18s} {:12.6g} {:12.6g}\n",
472 format_to(b,
" [{:+5d} minor] {:12.6g}\n", nMinor, xMinor);
475 return to_string(b) + err.
what();
481 std::vector<vector_fp>& data)
const 486 names.push_back(
"X");
489 names.push_back(
"Molal");
492 names.push_back(
"Chem. Pot. (J/kmol)");
495 names.push_back(
"Chem. Pot. SS (J/kmol)");
498 names.push_back(
"Molal Act. Coeff.");
501 names.push_back(
"Molal Activity");
504 names.push_back(
"Part. Mol Enthalpy (J/kmol)");
507 names.push_back(
"Part. Mol. Entropy (J/K/kmol)");
510 names.push_back(
"Part. Mol. Energy (J/kmol)");
513 names.push_back(
"Part. Mol. Cp (J/K/kmol");
516 names.push_back(
"Part. Mol. Cv (J/K/kmol)");
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
size_t nElements() const
Number of elements.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
std::string getChildValue(const XML_Node &parent, const std::string &nameString)
This function reads a child node with the name, nameString, and returns its XML value as the return s...
void setSolvent(size_t k)
This routine sets the index number of the solvent for the phase.
doublereal temperature() const
Temperature (K).
int activityConvention() const
We set the convention to molality here.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
An error indicating that an unimplemented function has been called.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
virtual size_t findCLMIndex() const
Returns the index of the Cl- species.
doublereal m_Mnaught
This is the multiplication factor that goes inside log expressions involving the molalities of specie...
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
doublereal cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
doublereal moleFraction(size_t k) const
Return the mole fraction of a single species.
const size_t npos
index returned by functions to indicate "no position"
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
void setpHScale(const int pHscaleType)
Set the pH scale, which determines the scale for single-ion activity coefficients.
size_t m_indexCLM
Index of the phScale species.
const char * what() const
Get a description of the error.
virtual void applyphScale(doublereal *acMolality) const
Apply the current phScale to a set of activity Coefficients or activities.
Class XML_Node is a tree-based representation of the contents of an XML file.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
size_t nSpecies() const
Returns the number of species in the phase.
virtual doublereal density() const
Density (kg/m^3).
doublereal m_xmolSolventMIN
doublereal enthalpy_mass() const
Specific enthalpy. Units: J/kg.
virtual bool addSpecies(shared_ptr< Species > spec)
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
doublereal moleFSolventMin() const
Returns the minimum mole fraction in the molality formulation.
virtual std::string report(bool show_thermo=true, doublereal threshold=1e-14) const
returns a summary of the state of the phase as a string
virtual void getMolalityActivityCoefficients(doublereal *acMolality) const
Get the array of non-dimensional molality based activity coefficients at the current solution tempera...
size_t solventIndex() const
Returns the solvent index.
virtual double osmoticCoefficient() const
Calculate the osmotic coefficient.
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Header for intermediate ThermoPhase object for phases which employ molality based activity coefficien...
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature, pressure, and solution concentration.
virtual bool addSpecies(shared_ptr< Species > spec)
bool m_chargeNeutralityNecessary
Boolean indicating whether a charge neutrality condition is a necessity.
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the phase to the conditions specified in the state XML element.
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
virtual void initThermo()
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
void setMolalitiesByName(const compositionMap &xMap)
Set the molalities of a phase.
void getMolalities(doublereal *const molal) const
This function will return the molalities of the species.
std::string speciesName(size_t k) const
Name of the species with index k.
int pHScale() const
Reports the pH scale, which determines the scale for single-ion activity coefficients.
virtual void getActivities(doublereal *ac) const
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
doublereal electricPotential() const
Returns the electric potential of this phase (V).
const int PHSCALE_NBS
Scale to be used for evaluation of single-ion activity coefficients is that used by the NBS standard ...
doublereal entropy_mass() const
Specific entropy. Units: J/kg/K.
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.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Base class for exceptions thrown by Cantera classes.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
const int PHSCALE_PITZER
Scale to be used for the output of single-ion activity coefficients is that used by Pitzer...
const int cAC_CONVENTION_MOLALITY
Standard state uses the molality convention.
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values.
virtual void getUnscaledMolalityActivityCoefficients(doublereal *acMolality) const
Get the array of unscaled non-dimensional molality based activity coefficients at the current solutio...
int m_pHScalingType
Scaling to be used for output of single-ion species activity coefficients.
virtual void setStateFromXML(const XML_Node &state)
Set equation of state parameter values from XML entries.
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
virtual doublereal pressure() const
Returns the current pressure of the phase.
void setMolalities(const doublereal *const molal)
Set the molalities of the solutes in a phase.
virtual void getCsvReportData(std::vector< std::string > &names, std::vector< vector_fp > &data) const
Fills names and data with the column names and species thermo properties to be included in the output...
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
void setState_TPM(doublereal t, doublereal p, const doublereal *const molalities)
Set the temperature (K), pressure (Pa), and molalities (gmol kg-1) of the solutes.
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
doublereal cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
vector_fp m_molalities
Current value of the molalities of the species in the phase.
const doublereal SmallNumber
smallest number to compare to zero.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
doublereal gibbs_mass() const
Specific Gibbs function. Units: J/kg.
virtual void initThermo()
std::string name() const
Return the name of the phase.
Contains declarations for string manipulation functions within Cantera.
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
doublereal m_weightSolvent
Molecular weight of the Solvent.
size_t m_kk
Number of species in the phase.
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
void calcMolalities() const
Calculates the molality of all species and stores the result internally.
Namespace for the Cantera kernel.
doublereal intEnergy_mass() const
Specific internal energy. Units: J/kg.
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
std::string elementName(size_t m) const
Name of the element with index m.
virtual void setState_TP(doublereal T, doublereal pres)
Set the temperature and pressure at the same time.
void setMoleFSolventMin(doublereal xmolSolventMIN)
Sets the minimum mole fraction in the molality formulation.