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++) {
74 for (
size_t k = 0; k <
m_kk; k++) {
83 for (
size_t k = 1; k <
m_kk; k++) {
87 double tmp = 1.0 / Lsum;
90 for (
size_t k = 1; k <
m_kk; k++) {
96 for (
size_t k = 0; k <
m_kk; k++) {
113 vector<double> mf(
m_kk, 0.0);
116 for (
size_t k = 0; k <
m_kk; k++) {
124 size_t largePos =
npos;
126 size_t largeNeg =
npos;
129 for (
size_t k = 0; k <
m_kk; k++) {
132 if (ch > 0.0 && ch * mf[k] > cPos) {
136 if (ch < 0.0 && fabs(ch) * mf[k] > cNeg) {
138 cNeg = fabs(ch) * mf[k];
146 mf[largePos] -= sum /
charge(largePos);
148 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
149 "unbalanced charges");
153 mf[largeNeg] -= (-sum) / fabs(
charge(largeNeg));
155 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
156 "unbalanced charges");
161 for (
size_t k = 0; k <
m_kk; k++) {
165 for (
size_t k = 0; k <
m_kk; k++) {
207 for (
size_t k = 1; k <
m_kk; k++) {
208 ac[k] /= xmolSolvent;
221 vector<double> act(
m_kk);
226 for (
size_t k = 1; k <
m_kk; k++) {
230 if (sum > 1.0E-200) {
256 if (state.
hasKey(
"molalities")) {
257 molalities = state[
"molalities"];
258 }
else if (state.
hasKey(
"M")) {
259 molalities = state[
"M"];
262 if (molalities.
is<
string>()) {
264 }
else if (molalities.
is<
AnyMap>()) {
291 size_t indexCLM =
npos;
295 for (
size_t e = 0; e < ne; e++) {
297 if (sn ==
"Cl" || sn ==
"CL") {
306 for (
size_t e = 0; e < ne; e++) {
308 if (sn ==
"E" || sn ==
"e") {
317 for (
size_t k = 1; k <
m_kk; k++) {
318 double nCl =
nAtoms(k, eCl);
322 double nE =
nAtoms(k, eE);
326 for (
size_t e = 0; e < ne; e++) {
327 if (e != eE && e != eCl) {
335 if (sn !=
"Cl-" && sn !=
"CL-") {
361 fmt::memory_buffer b;
364 fmt_append(b,
"\n {}:\n",
name());
367 fmt_append(b,
" temperature {:12.6g} K\n",
temperature());
368 fmt_append(b,
" pressure {:12.6g} Pa\n",
pressure());
369 fmt_append(b,
" density {:12.6g} kg/m^3\n",
density());
373 fmt_append(b,
" potential {:12.6g} V\n", phi);
375 vector<double> x(
m_kk);
376 vector<double> molal(
m_kk);
377 vector<double> mu(
m_kk);
378 vector<double> muss(
m_kk);
379 vector<double> acMolal(
m_kk);
380 vector<double> actMolal(
m_kk);
390 double pH = -log(actMolal[iHp]) / log(10.0);
392 " pH {:12.4g}\n", pH);
397 fmt_append(b,
" 1 kg 1 kmol\n");
398 fmt_append(b,
" ----------- ------------\n");
399 fmt_append(b,
" enthalpy {:12.6g} {:12.4g} J\n",
401 fmt_append(b,
" internal energy {:12.6g} {:12.4g} J\n",
403 fmt_append(b,
" entropy {:12.6g} {:12.4g} J/K\n",
405 fmt_append(b,
" Gibbs function {:12.6g} {:12.4g} J\n",
407 fmt_append(b,
" heat capacity c_p {:12.6g} {:12.4g} J/K\n",
410 fmt_append(b,
" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
413 fmt_append(b,
" heat capacity c_v <not implemented>\n");
422 " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n");
424 " (J/kmol) (J/kmol)\n");
425 fmt_append(b,
" ------------- "
426 " ------------ ------------ ------------ ------------\n");
427 for (
size_t k = 0; k <
m_kk; k++) {
428 if (x[k] > threshold) {
431 "{:>18s} {:12.6g} {:12.6g} {:12.6g} "
433 x[k], molal[k], mu[k], muss[k], acMolal[k]);
436 "{:>18s} {:12.6g} {:12.6g} N/A "
438 x[k], molal[k], muss[k], acMolal[k]);
446 fmt_append(b,
" X Molalities\n");
447 fmt_append(b,
" ------------- ------------\n");
448 for (
size_t k = 0; k <
m_kk; k++) {
449 if (x[k] > threshold) {
450 fmt_append(b,
"{:>18s} {:12.6g} {:12.6g}\n",
459 fmt_append(b,
" [{:+5d} minor] {:12.6g}\n", nMinor, xMinor);
462 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.
void getMolalities(span< double > molal) const
This function will return the molalities of the species.
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...
virtual void applyphScale(span< double > acMolality) const
Apply the current phScale to a set of activity Coefficients or activities.
size_t m_indexCLM
Index of the phScale species.
void getActivityCoefficients(span< double > ac) const override
Get the array of non-dimensional activity coefficients at the current solution temperature,...
size_t findCLMIndex() const
Returns the index of the Cl- species.
void setState_TPM(double t, double p, span< const double > molalities)
Set the temperature (K), pressure (Pa), and molalities (gmol kg-1) of the solutes.
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
int pHScale() const
Reports the pH scale, which determines the scale for single-ion activity coefficients.
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,...
void getActivities(span< double > ac) const override
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
vector< double > m_molalities
Current value of the molalities of the species in the phase.
int m_pHScalingType
Scaling to be used for output of single-ion species activity coefficients.
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.
virtual void getMolalityActivityCoefficients(span< double > acMolality) const
Get the array of non-dimensional molality based activity coefficients at the current solution tempera...
void setMolalities(span< const double > molal)
Set the molalities of the solutes in a phase.
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 getActivityConcentrations(span< double > c) const override
This method returns an array of generalized concentrations.
virtual void getUnscaledMolalityActivityCoefficients(span< double > acMolality) const
Get the array of unscaled non-dimensional molality based activity coefficients at the current solutio...
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.
void getMoleFractions(span< double > x) const
Get the species mole fraction vector.
size_t m_kk
Number of species in the phase.
size_t speciesIndex(const string &name, bool raise=true) const
Returns the index of a species named 'name' within the Phase object.
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.
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.
virtual void setMoleFractions(span< const double > x)
Set the mole fractions to the specified values.
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 and composition [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 and composition [J/kg/K].
double entropy_mass() const
Specific entropy. Units: J/kg/K.
double cp_mass() const
Specific heat at constant pressure and composition [J/kg/K].
double intEnergy_mass() const
Specific internal energy. Units: J/kg.
virtual double cv_mole() const
Molar heat capacity at constant volume and composition [J/kmol/K].
virtual void getChemPotentials(span< double > mu) const
Get the species chemical potentials. Units: J/kmol.
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(span< 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.
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.
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...