24 MolalityVPSSTP::MolalityVPSSTP() :
28 m_weightSolvent(18.01528),
29 m_xmolSolventMIN(0.01),
30 m_Mnaught(18.01528E-3)
39 m_indexSolvent(b.m_indexSolvent),
40 m_pHScalingType(b.m_pHScalingType),
41 m_indexCLM(b.m_indexCLM),
42 m_xmolSolventMIN(b.m_xmolSolventMIN),
43 m_Mnaught(b.m_Mnaught),
44 m_molalities(b.m_molalities)
49 MolalityVPSSTP& MolalityVPSSTP::operator=(
const MolalityVPSSTP& b)
52 VPStandardStateTP::operator=(b);
76 "Unknown scale type: {}", pHscaleType);
93 "Molality-based methods limit solvent id to being 0");
105 if (xmolSolventMIN <= 0.0) {
106 throw CanteraError(
"MolalityVPSSTP::setSolute ",
"trouble");
107 }
else if (xmolSolventMIN > 0.9) {
108 throw CanteraError(
"MolalityVPSSTP::setSolute ",
"trouble");
122 double denomInv = 1.0/ (
m_Mnaught * xmolSolvent);
123 for (
size_t k = 0; k <
m_kk; k++) {
131 for (
size_t k = 0; k <
m_kk; k++) {
139 for (
size_t k = 1; k <
m_kk; k++) {
143 double tmp = 1.0 / Lsum;
146 for (
size_t k = 1; k <
m_kk; k++) {
152 for (
size_t k = 0; k <
m_kk; k++) {
172 for (
size_t k = 0; k <
m_kk; k++) {
180 size_t largePos =
npos;
182 size_t largeNeg =
npos;
185 for (
size_t k = 0; k <
m_kk; k++) {
188 if (ch > 0.0 && ch * mf[k] > cPos) {
192 if (ch < 0.0 && fabs(ch) * mf[k] > cNeg) {
194 cNeg = fabs(ch) * mf[k];
202 mf[largePos] -= sum /
charge(largePos);
204 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
205 "unbalanced charges");
209 mf[largeNeg] -= (-sum) / fabs(
charge(largeNeg));
211 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
212 "unbalanced charges");
217 for (
size_t k = 0; k <
m_kk; k++) {
221 for (
size_t k = 0; k <
m_kk; k++) {
264 for (
size_t k = 1; k <
m_kk; k++) {
265 ac[k] /= xmolSolvent;
283 for (
size_t k = 1; k <
m_kk; k++) {
287 if (sum > 1.0E-200) {
301 double p =
getFloat(state,
"pressure",
"pressure");
307 const doublereal*
const molalities)
345 size_t indexCLM =
npos;
349 for (
size_t e = 0; e < ne; e++) {
351 if (sn ==
"Cl" || sn ==
"CL") {
360 for (
size_t e = 0; e < ne; e++) {
362 if (sn ==
"E" || sn ==
"e") {
371 for (
size_t k = 1; k <
m_kk; k++) {
372 doublereal nCl =
nAtoms(k, eCl);
376 doublereal nE =
nAtoms(k, eE);
380 for (
size_t e = 0; e < ne; e++) {
381 if (e != eE && e != eCl) {
382 doublereal nA =
nAtoms(k, e);
389 if (sn !=
"Cl-" && sn !=
"CL-") {
417 b.write(
"\n {}:\n",
name());
420 b.write(
" temperature {:12.6g} K\n",
temperature());
421 b.write(
" pressure {:12.6g} Pa\n",
pressure());
422 b.write(
" density {:12.6g} kg/m^3\n",
density());
426 b.write(
" potential {:12.6g} V\n", phi);
443 double pH = -log(actMolal[iHp]) / log(10.0);
444 b.write(
" pH {:12.4g}\n", pH);
449 b.write(
" 1 kg 1 kmol\n");
450 b.write(
" ----------- ------------\n");
451 b.write(
" enthalpy {:12.6g} {:12.4g} J\n",
453 b.write(
" internal energy {:12.6g} {:12.4g} J\n",
455 b.write(
" entropy {:12.6g} {:12.4g} J/K\n",
457 b.write(
" Gibbs function {:12.6g} {:12.4g} J\n",
459 b.write(
" heat capacity c_p {:12.6g} {:12.4g} J/K\n",
462 b.write(
" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
465 b.write(
" heat capacity c_v <not implemented>\n");
471 doublereal xMinor = 0.0;
474 " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n");
476 " (J/kmol) (J/kmol)\n");
477 b.write(
" ------------- " 478 " ------------ ------------ ------------ ------------\n");
479 for (
size_t k = 0; k <
m_kk; k++) {
480 if (x[k] > threshold) {
482 b.write(
"{:>18s} {:12.6g} {:12.6g} {:12.6g} {:12.6g} {:12.6g}\n",
483 speciesName(k), x[k], molal[k], mu[k], muss[k], acMolal[k]);
485 b.write(
"{:>18s} {:12.6g} {:12.6g} N/A {:12.6g} {:12.6g}\n",
486 speciesName(k), x[k], molal[k], muss[k], acMolal[k]);
496 b.write(
" -------------" 498 for (
size_t k = 0; k <
m_kk; k++) {
499 if (x[k] > threshold) {
500 b.write(
"{:>18s} {:12.6g} {:12.6g}\n",
509 b.write(
" [{:+5d} minor] {:12.6g}\n", nMinor, xMinor);
512 return b.str() + err.
what();
518 std::vector<vector_fp>& data)
const 523 names.push_back(
"X");
526 names.push_back(
"Molal");
529 names.push_back(
"Chem. Pot. (J/kmol)");
532 names.push_back(
"Chem. Pot. SS (J/kmol)");
535 names.push_back(
"Molal Act. Coeff.");
538 names.push_back(
"Molal Activity");
541 names.push_back(
"Part. Mol Enthalpy (J/kmol)");
544 names.push_back(
"Part. Mol. Entropy (J/K/kmol)");
547 names.push_back(
"Part. Mol. Energy (J/kmol)");
550 names.push_back(
"Part. Mol. Cp (J/K/kmol");
553 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.
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.
Base class for a phase with thermodynamic properties.
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.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
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.
#define AssertThrow(expr, procedure)
Assertion must be true or an error is thrown.
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.
const U & getValue(const std::map< T, U > &m, const T &key)
Const accessor for a value in a std::map.
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.
#define AssertThrowMsg(expr, procedure,...)
Assertion must be true or an error is thrown.
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.
size_t m_indexSolvent
Index of the solvent.
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.
MolalityVPSSTP()
Default Constructor.
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.