36 "Unknown scale type: {}", pHscaleType);
47 if (xmolSolventMIN <= 0.0) {
48 throw CanteraError(
"MolalityVPSSTP::setMoleFSolventMin ",
"trouble");
49 }
else if (xmolSolventMIN > 0.9) {
50 throw CanteraError(
"MolalityVPSSTP::setMoleFSolventMin ",
"trouble");
64 double denomInv = 1.0/ (
m_Mnaught * xmolSolvent);
65 for (
size_t k = 0; k <
m_kk; k++) {
73 for (
size_t k = 0; k <
m_kk; k++) {
81 for (
size_t k = 1; k <
m_kk; k++) {
85 double tmp = 1.0 / Lsum;
88 for (
size_t k = 1; k <
m_kk; k++) {
94 for (
size_t k = 0; k <
m_kk; k++) {
111 vector<double> mf(
m_kk, 0.0);
114 for (
size_t k = 0; k <
m_kk; k++) {
122 size_t largePos =
npos;
124 size_t largeNeg =
npos;
127 for (
size_t k = 0; k <
m_kk; k++) {
130 if (ch > 0.0 && ch * mf[k] > cPos) {
134 if (ch < 0.0 && fabs(ch) * mf[k] > cNeg) {
136 cNeg = fabs(ch) * mf[k];
144 mf[largePos] -= sum /
charge(largePos);
146 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
147 "unbalanced charges");
151 mf[largeNeg] -= (-sum) / fabs(
charge(largeNeg));
153 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
154 "unbalanced charges");
159 for (
size_t k = 0; k <
m_kk; k++) {
163 for (
size_t k = 0; k <
m_kk; k++) {
205 for (
size_t k = 1; k <
m_kk; k++) {
206 ac[k] /= xmolSolvent;
219 vector<double> act(
m_kk);
224 for (
size_t k = 1; k <
m_kk; k++) {
228 if (sum > 1.0E-200) {
254 if (state.
hasKey(
"molalities")) {
255 molalities = state[
"molalities"];
256 }
else if (state.
hasKey(
"M")) {
257 molalities = state[
"M"];
260 if (molalities.
is<
string>()) {
262 }
else if (molalities.
is<
AnyMap>()) {
289 size_t indexCLM =
npos;
293 for (
size_t e = 0; e < ne; e++) {
295 if (sn ==
"Cl" || sn ==
"CL") {
304 for (
size_t e = 0; e < ne; e++) {
306 if (sn ==
"E" || sn ==
"e") {
315 for (
size_t k = 1; k <
m_kk; k++) {
316 double nCl =
nAtoms(k, eCl);
320 double nE =
nAtoms(k, eE);
324 for (
size_t e = 0; e < ne; e++) {
325 if (e != eE && e != eCl) {
333 if (sn !=
"Cl-" && sn !=
"CL-") {
359 fmt::memory_buffer b;
371 fmt_append(b,
" potential {:12.6g} V\n", phi);
373 vector<double> x(
m_kk);
374 vector<double> molal(
m_kk);
375 vector<double> mu(
m_kk);
376 vector<double> muss(
m_kk);
377 vector<double> acMolal(
m_kk);
378 vector<double> actMolal(
m_kk);
388 double pH = -log(actMolal[iHp]) / log(10.0);
390 " pH {:12.4g}\n", pH);
397 fmt_append(b,
" enthalpy {:12.6g} {:12.4g} J\n",
399 fmt_append(b,
" internal energy {:12.6g} {:12.4g} J\n",
401 fmt_append(b,
" entropy {:12.6g} {:12.4g} J/K\n",
403 fmt_append(b,
" Gibbs function {:12.6g} {:12.4g} J\n",
405 fmt_append(b,
" heat capacity c_p {:12.6g} {:12.4g} J/K\n",
408 fmt_append(b,
" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
411 fmt_append(b,
" heat capacity c_v <not implemented>\n");
420 " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n");
422 " (J/kmol) (J/kmol)\n");
424 " ------------ ------------ ------------ ------------\n");
425 for (
size_t k = 0; k <
m_kk; k++) {
426 if (x[k] > threshold) {
429 "{:>18s} {:12.6g} {:12.6g} {:12.6g} "
431 x[k], molal[k], mu[k], muss[k], acMolal[k]);
434 "{:>18s} {:12.6g} {:12.6g} N/A "
436 x[k], molal[k], muss[k], acMolal[k]);
445 fmt_append(b,
" ------------- ------------\n");
446 for (
size_t k = 0; k <
m_kk; k++) {
447 if (x[k] > threshold) {
457 fmt_append(b,
" [{:+5d} minor] {:12.6g}\n", nMinor, xMinor);
460 return to_string(b) + err.
what();
Header for intermediate ThermoPhase object for phases which employ molality based activity coefficien...
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.
A wrapper for a variable whose type is determined at runtime.
const string & asString() const
Return the held value, if it is a string.
map< string, T > asMap() const
Return the held AnyMap as a map where all of the values have the specified type.
bool is() const
Returns true if the held value is of the specified type.
Base class for exceptions thrown by Cantera classes.
const char * what() const override
Get a description of the error.
int activityConvention() const override
We set the convention to molality here.
void setState(const AnyMap &state) override
Set the state using an AnyMap containing any combination of properties supported by the thermodynamic...
void setMolalitiesByName(const Composition &xMap)
Set the molalities of a phase.
double m_Mnaught
This is the multiplication factor that goes inside log expressions involving the molalities of specie...
size_t m_indexCLM
Index of the phScale species.
size_t findCLMIndex() const
Returns the index of the Cl- species.
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
int pHScale() const
Reports the pH scale, which determines the scale for single-ion activity coefficients.
virtual void getMolalityActivityCoefficients(double *acMolality) const
Get the array of non-dimensional molality based activity coefficients at the current solution tempera...
void setpHScale(const int pHscaleType)
Set the pH scale, which determines the scale for single-ion activity coefficients.
double m_xmolSolventMIN
In any molality implementation, it makes sense to have a minimum solvent mole fraction requirement,...
vector< double > m_molalities
Current value of the molalities of the species in the phase.
virtual void applyphScale(double *acMolality) const
Apply the current phScale to a set of activity Coefficients or activities.
int m_pHScalingType
Scaling to be used for output of single-ion species activity coefficients.
void setMolalities(const double *const molal)
Set the molalities of the solutes in a phase.
void getMolalities(double *const molal) const
This function will return the molalities of the species.
void setMoleFSolventMin(double xmolSolventMIN)
Sets the minimum mole fraction in the molality formulation.
virtual double osmoticCoefficient() const
Calculate the osmotic coefficient.
MolalityVPSSTP()
Default Constructor.
double moleFSolventMin() const
Returns the minimum mole fraction in the molality formulation.
void setState_TPM(double t, double p, const double *const molalities)
Set the temperature (K), pressure (Pa), and molalities (gmol kg-1) of the solutes.
void getActivities(double *ac) const override
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
virtual void getUnscaledMolalityActivityCoefficients(double *acMolality) const
Get the array of unscaled non-dimensional molality based activity coefficients at the current solutio...
void calcMolalities() const
Calculates the molality of all species and stores the result internally.
double standardConcentration(size_t k=0) const override
Return the standard concentration for the kth species.
double m_weightSolvent
Molecular weight of the Solvent.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
void getActivityCoefficients(double *ac) const override
Get the array of non-dimensional activity coefficients at the current solution temperature,...
string report(bool show_thermo=true, double threshold=1e-14) const override
returns a summary of the state of the phase as a string
An error indicating that an unimplemented function has been called.
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
size_t m_kk
Number of species in the phase.
double temperature() const
Temperature (K).
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
string speciesName(size_t k) const
Name of the species with index k.
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
double moleFraction(size_t k) const
Return the mole fraction of a single species.
virtual double density() const
Density (kg/m^3).
double nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
size_t nElements() const
Number of elements.
const vector< string > & speciesNames() const
Return a const reference to the vector of species names.
double molecularWeight(size_t k) const
Molecular weight of species k.
string elementName(size_t m) const
Name of the element with index m.
double charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
string name() const
Return the name of the phase.
double electricPotential() const
Returns the electric potential of this phase (V).
virtual double cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual double enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual void setState(const AnyMap &state)
Set the state using an AnyMap containing any combination of properties supported by the thermodynamic...
double gibbs_mass() const
Specific Gibbs function. Units: J/kg.
bool m_chargeNeutralityNecessary
Boolean indicating whether a charge neutrality condition is a necessity.
virtual double entropy_mole() const
Molar entropy. Units: J/kmol/K.
double cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
double entropy_mass() const
Specific entropy. Units: J/kg/K.
virtual void getChemPotentials(double *mu) const
Get the species chemical potentials. Units: J/kmol.
double cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
double intEnergy_mass() const
Specific internal energy. Units: J/kg.
virtual double cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual double intEnergy_mole() const
Molar internal energy. Units: J/kmol.
virtual double gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
double enthalpy_mass() const
Specific enthalpy. Units: J/kg.
double pressure() const override
Returns the current pressure of the phase.
void getStandardChemPotentials(double *mu) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void setState_TP(double T, double pres) override
Set the temperature and pressure at the same time.
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
void fmt_append(fmt::memory_buffer &b, Args... args)
Versions 6.2.0 and 6.2.1 of fmtlib do not include this define before they include windows....
Composition parseCompString(const string &ss, const vector< string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
const int PHSCALE_PITZER
Scale to be used for the output of single-ion activity coefficients is that used by Pitzer.
const double SmallNumber
smallest number to compare to zero.
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 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.
const int cAC_CONVENTION_MOLALITY
Standard state uses the molality convention.
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...