Go to the documentation of this file.
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 if (xmolSolventMIN <= 0.0) {
56 throw CanteraError(
"MolalityVPSSTP::setMoleFSolventMin ",
"trouble");
57 }
else if (xmolSolventMIN > 0.9) {
58 throw CanteraError(
"MolalityVPSSTP::setMoleFSolventMin ",
"trouble");
72 double denomInv = 1.0/ (
m_Mnaught * xmolSolvent);
73 for (
size_t k = 0; k <
m_kk; k++) {
81 for (
size_t k = 0; k <
m_kk; k++) {
89 for (
size_t k = 1; k <
m_kk; k++) {
93 double tmp = 1.0 / Lsum;
96 for (
size_t k = 1; k <
m_kk; k++) {
102 for (
size_t k = 0; k <
m_kk; k++) {
122 for (
size_t k = 0; k <
m_kk; k++) {
130 size_t largePos =
npos;
132 size_t largeNeg =
npos;
135 for (
size_t k = 0; k <
m_kk; k++) {
138 if (ch > 0.0 && ch * mf[k] > cPos) {
142 if (ch < 0.0 && fabs(ch) * mf[k] > cNeg) {
144 cNeg = fabs(ch) * mf[k];
152 mf[largePos] -= sum /
charge(largePos);
154 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
155 "unbalanced charges");
159 mf[largeNeg] -= (-sum) / fabs(
charge(largeNeg));
161 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
162 "unbalanced charges");
167 for (
size_t k = 0; k <
m_kk; k++) {
171 for (
size_t k = 0; k <
m_kk; k++) {
213 for (
size_t k = 1; k <
m_kk; k++) {
214 ac[k] /= xmolSolvent;
232 for (
size_t k = 1; k <
m_kk; k++) {
236 if (sum > 1.0E-200) {
250 double p =
getFloat(state,
"pressure",
"pressure");
256 const doublereal*
const molalities)
276 if (state.
hasKey(
"molalities")) {
277 molalities = state[
"molalities"];
278 }
else if (state.
hasKey(
"M")) {
279 molalities = state[
"M"];
282 if (molalities.
is<
string>()) {
284 }
else if (molalities.
is<
AnyMap>()) {
311 size_t indexCLM =
npos;
315 for (
size_t e = 0; e < ne; e++) {
317 if (sn ==
"Cl" || sn ==
"CL") {
326 for (
size_t e = 0; e < ne; e++) {
328 if (sn ==
"E" || sn ==
"e") {
337 for (
size_t k = 1; k <
m_kk; k++) {
338 doublereal nCl =
nAtoms(k, eCl);
342 doublereal nE =
nAtoms(k, eE);
346 for (
size_t e = 0; e < ne; e++) {
347 if (e != eE && e != eCl) {
348 doublereal nA =
nAtoms(k, e);
355 if (sn !=
"Cl-" && sn !=
"CL-") {
381 fmt::memory_buffer b;
384 format_to(b,
"\n {}:\n",
name());
387 format_to(b,
" temperature {:12.6g} K\n",
temperature());
388 format_to(b,
" pressure {:12.6g} Pa\n",
pressure());
389 format_to(b,
" density {:12.6g} kg/m^3\n",
density());
393 format_to(b,
" potential {:12.6g} V\n", phi);
410 double pH = -log(actMolal[iHp]) / log(10.0);
411 format_to(b,
" pH {:12.4g}\n", pH);
416 format_to(b,
" 1 kg 1 kmol\n");
417 format_to(b,
" ----------- ------------\n");
418 format_to(b,
" enthalpy {:12.6g} {:12.4g} J\n",
420 format_to(b,
" internal energy {:12.6g} {:12.4g} J\n",
422 format_to(b,
" entropy {:12.6g} {:12.4g} J/K\n",
424 format_to(b,
" Gibbs function {:12.6g} {:12.4g} J\n",
426 format_to(b,
" heat capacity c_p {:12.6g} {:12.4g} J/K\n",
429 format_to(b,
" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
432 format_to(b,
" heat capacity c_v <not implemented>\n");
438 doublereal xMinor = 0.0;
441 " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n");
443 " (J/kmol) (J/kmol)\n");
444 format_to(b,
" ------------- "
445 " ------------ ------------ ------------ ------------\n");
446 for (
size_t k = 0; k <
m_kk; k++) {
447 if (x[k] > threshold) {
449 format_to(b,
"{:>18s} {:12.6g} {:12.6g} {:12.6g} {:12.6g} {:12.6g}\n",
450 speciesName(k), x[k], molal[k], mu[k], muss[k], acMolal[k]);
452 format_to(b,
"{:>18s} {:12.6g} {:12.6g} N/A {:12.6g} {:12.6g}\n",
453 speciesName(k), x[k], molal[k], muss[k], acMolal[k]);
463 format_to(b,
" -------------"
465 for (
size_t k = 0; k <
m_kk; k++) {
466 if (x[k] > threshold) {
467 format_to(b,
"{:>18s} {:12.6g} {:12.6g}\n",
476 format_to(b,
" [{:+5d} minor] {:12.6g}\n", nMinor, xMinor);
479 return to_string(b) + err.
what();
485 std::vector<vector_fp>& data)
const
490 names.push_back(
"X");
493 names.push_back(
"Molal");
496 names.push_back(
"Chem. Pot. (J/kmol)");
499 names.push_back(
"Chem. Pot. SS (J/kmol)");
502 names.push_back(
"Molal Act. Coeff.");
505 names.push_back(
"Molal Activity");
508 names.push_back(
"Part. Mol Enthalpy (J/kmol)");
511 names.push_back(
"Part. Mol. Entropy (J/K/kmol)");
514 names.push_back(
"Part. Mol. Energy (J/kmol)");
517 names.push_back(
"Part. Mol. Cp (J/K/kmol");
520 names.push_back(
"Part. Mol. Cv (J/K/kmol)");
virtual bool addSpecies(shared_ptr< Species > spec)
doublereal moleFSolventMin() const
Returns the minimum mole fraction in the molality formulation.
virtual void setState_TP(doublereal T, doublereal pres)
Set the temperature and pressure at the same time.
A wrapper for a variable whose type is determined at runtime.
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.
doublereal enthalpy_mass() const
Specific enthalpy. Units: J/kg.
virtual doublereal pressure() const
Returns the current pressure of the phase.
bool m_chargeNeutralityNecessary
Boolean indicating whether a charge neutrality condition is a necessity.
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...
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the phase to the conditions specified in the state XML element.
void setpHScale(const int pHscaleType)
Set the pH scale, which determines the scale for single-ion activity coefficients.
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
virtual bool addSpecies(shared_ptr< Species > spec)
doublereal cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
void setMolalitiesByName(const compositionMap &xMap)
Set the molalities of a phase.
std::map< std::string, double > compositionMap
Map connecting a string name with a double.
int activityConvention() const
We set the convention to molality here.
const std::string & asString() const
Return the held value, if it is a string.
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
const double SmallNumber
smallest number to compare to zero.
doublereal m_xmolSolventMIN
const char * what() const
Get a description of the error.
doublereal intEnergy_mass() const
Specific internal energy. Units: J/kg.
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
An error indicating that an unimplemented function has been called.
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
doublereal m_weightSolvent
Molecular weight of the Solvent.
int m_pHScalingType
Scaling to be used for output of single-ion species activity coefficients.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
void setMoleFSolventMin(doublereal xmolSolventMIN)
Sets the minimum mole fraction in the molality formulation.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
size_t m_indexCLM
Index of the phScale species.
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.
bool is() const
Returns true if the held value is of the specified type.
std::map< std::string, T > asMap() const
Return the held AnyMap as a std::map where all of the values have the specified type.
virtual void getUnscaledMolalityActivityCoefficients(doublereal *acMolality) const
Get the array of unscaled non-dimensional molality based activity coefficients at the current solutio...
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
std::string name() const
Return the name of the phase.
virtual void setState(const AnyMap &state)
Set the state using an AnyMap containing any combination of properties supported by the thermodynamic...
double moleFraction(size_t k) const
Return the mole fraction of a single species.
void getMolalities(doublereal *const molal) const
This function will return the molalities of the species.
int pHScale() const
Reports the pH scale, which determines the scale for single-ion activity coefficients.
virtual void initThermo()
void calcMolalities() const
Calculates the molality of all species and stores the result internally.
virtual void setStateFromXML(const XML_Node &state)
Set equation of state parameter values from XML entries.
doublereal cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
std::string elementName(size_t m) const
Name of the element with index m.
size_t m_kk
Number of species in the phase.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
virtual double density() const
Density (kg/m^3).
doublereal gibbs_mass() const
Specific Gibbs function. Units: J/kg.
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 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...
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
const int PHSCALE_NBS
Scale to be used for evaluation of single-ion activity coefficients is that used by the NBS standard ...
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 getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
virtual size_t findCLMIndex() const
Returns the index of the Cl- species.
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Class XML_Node is a tree-based representation of the contents of an XML file.
size_t nElements() const
Number of elements.
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
virtual void applyphScale(doublereal *acMolality) const
Apply the current phScale to a set of activity Coefficients or activities.
const int cAC_CONVENTION_MOLALITY
Standard state uses the molality convention.
doublereal m_Mnaught
This is the multiplication factor that goes inside log expressions involving the molalities of specie...
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
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.
const int PHSCALE_PITZER
Scale to be used for the output of single-ion activity coefficients is that used by Pitzer.
virtual void getActivities(doublereal *ac) const
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
vector_fp m_molalities
Current value of the molalities of the species in the phase.
doublereal temperature() const
Temperature (K).
virtual void initThermo()
size_t nSpecies() const
Returns the number of species in the phase.
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
doublereal electricPotential() const
Returns the electric potential of this phase (V).
void setMolalities(const doublereal *const molal)
Set the molalities of the solutes in a phase.
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
A map of string keys to values whose type can vary at runtime.
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature,...
Base class for exceptions thrown by Cantera classes.
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
const size_t npos
index returned by functions to indicate "no position"
virtual double osmoticCoefficient() const
Calculate the osmotic coefficient.
doublereal entropy_mass() const
Specific entropy. Units: J/kg/K.
virtual void getMolalityActivityCoefficients(doublereal *acMolality) const
Get the array of non-dimensional molality based activity coefficients at the current solution tempera...
Namespace for the Cantera kernel.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
std::string speciesName(size_t k) const
Name of the species with index k.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
virtual void setState(const AnyMap &state)
Set the state using an AnyMap containing any combination of properties supported by the thermodynamic...