31 MolalityVPSSTP::MolalityVPSSTP() :
35 m_weightSolvent(18.01528),
36 m_xmolSolventMIN(0.01),
37 m_Mnaught(18.01528E-3)
48 m_indexSolvent(b.m_indexSolvent),
49 m_pHScalingType(b.m_pHScalingType),
50 m_indexCLM(b.m_indexCLM),
51 m_xmolSolventMIN(b.m_xmolSolventMIN),
52 m_Mnaught(b.m_Mnaught),
53 m_molalities(b.m_molalities)
87 "Unknown scale type: " +
int2str(pHscaleType));
104 "Molality-based methods limit solvent id to being 0");
116 if (xmolSolventMIN <= 0.0) {
117 throw CanteraError(
"MolalityVPSSTP::setSolute ",
"trouble");
118 }
else if (xmolSolventMIN > 0.9) {
119 throw CanteraError(
"MolalityVPSSTP::setSolute ",
"trouble");
133 double denomInv = 1.0/ (
m_Mnaught * xmolSolvent);
134 for (
size_t k = 0; k <
m_kk; k++) {
142 for (
size_t k = 0; k <
m_kk; k++) {
150 for (
size_t k = 1; k <
m_kk; k++) {
154 double tmp = 1.0 / Lsum;
157 for (
size_t k = 1; k <
m_kk; k++) {
163 for (
size_t k = 0; k <
m_kk; k++) {
189 for (
size_t k = 0; k <
m_kk; k++) {
198 size_t largePos =
npos;
200 size_t largeNeg =
npos;
203 for (
size_t k = 0; k <
m_kk; k++) {
207 if (ch * mf[k] > cPos) {
213 if (fabs(ch) * mf[k] > cNeg) {
215 cNeg = fabs(ch) * mf[k];
224 mf[largePos] -= sum /
charge(largePos);
226 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
227 "unbalanced charges");
231 mf[largeNeg] -= (-sum) / fabs(
charge(largeNeg));
233 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
234 "unbalanced charges");
240 for (
size_t k = 0; k <
m_kk; k++) {
244 for (
size_t k = 0; k <
m_kk; k++) {
291 for (
size_t k = 1; k <
m_kk; k++) {
292 ac[k] /= xmolSolvent;
313 for (
size_t k = 1; k <
m_kk; k++) {
317 if (sum > 1.0E-200) {
327 for (
size_t k = 0; k <
m_kk; k++) {
335 "To be removed after Cantera 2.2.");
337 for (
int i = 0; i < sizeUA; i++) {
342 uA[1] = -int(
nDim());
373 double p =
getFloat(state,
"pressure",
"pressure");
379 const doublereal*
const molalities)
425 size_t indexCLM =
npos;
429 for (
size_t e = 0; e < ne; e++) {
431 if (sn ==
"Cl" || sn ==
"CL") {
440 for (
size_t e = 0; e < ne; e++) {
442 if (sn ==
"E" || sn ==
"e") {
451 for (
size_t k = 1; k <
m_kk; k++) {
452 doublereal nCl =
nAtoms(k, eCl);
456 doublereal nE =
nAtoms(k, eE);
460 for (
size_t e = 0; e < ne; e++) {
461 if (e != eE && e != eCl) {
462 doublereal nA =
nAtoms(k, e);
469 if (sn !=
"Cl-" && sn !=
"CL-") {
507 sprintf(p,
" \n %s:\n",
name().c_str());
510 sprintf(p,
" \n temperature %12.6g K\n",
temperature());
512 sprintf(p,
" pressure %12.6g Pa\n",
pressure());
514 sprintf(p,
" density %12.6g kg/m^3\n",
density());
520 sprintf(p,
" potential %12.6g V\n", phi);
538 double pH = -log(actMolal[iHp]) / log(10.0);
539 sprintf(p,
" pH %12.4g \n", pH);
546 sprintf(p,
" 1 kg 1 kmol\n");
548 sprintf(p,
" ----------- ------------\n");
550 sprintf(p,
" enthalpy %12.6g %12.4g J\n",
553 sprintf(p,
" internal energy %12.6g %12.4g J\n",
556 sprintf(p,
" entropy %12.6g %12.4g J/K\n",
559 sprintf(p,
" Gibbs function %12.6g %12.4g J\n",
562 sprintf(p,
" heat capacity c_p %12.6g %12.4g J/K\n",
566 sprintf(p,
" heat capacity c_v %12.6g %12.4g J/K\n",
571 sprintf(p,
" heat capacity c_v <not implemented> \n");
579 doublereal xMinor = 0.0;
582 " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n");
585 " (J/kmol) (J/kmol) \n");
587 sprintf(p,
" ------------- "
588 " ------------ ------------ ------------ ------------\n");
590 for (
size_t k = 0; k <
m_kk; k++) {
591 if (x[k] > threshold) {
593 sprintf(p,
"%18s %12.6g %12.6g %12.6g %12.6g %12.6g\n",
594 speciesName(k).c_str(), x[k], molal[k], mu[k], muss[k], acMolal[k]);
596 sprintf(p,
"%18s %12.6g %12.6g N/A %12.6g %12.6g \n",
597 speciesName(k).c_str(), x[k], molal[k], muss[k], acMolal[k]);
609 sprintf(p,
" -------------"
612 for (
size_t k = 0; k <
m_kk; k++) {
613 if (x[k] > threshold) {
614 sprintf(p,
"%18s %12.6g %12.6g\n",
624 sprintf(p,
" [%+5i minor] %12.6g\n", nMinor, xMinor);
634 std::vector<vector_fp>& data)
const
639 names.push_back(
"X");
642 names.push_back(
"Molal");
645 names.push_back(
"Chem. Pot. (J/kmol)");
648 names.push_back(
"Chem. Pot. SS (J/kmol)");
651 names.push_back(
"Molal Act. Coeff.");
654 names.push_back(
"Molal Activity");
657 names.push_back(
"Part. Mol Enthalpy (J/kmol)");
660 names.push_back(
"Part. Mol. Entropy (J/K/kmol)");
663 names.push_back(
"Part. Mol. Energy (J/kmol)");
666 names.push_back(
"Part. Mol. Cp (J/K/kmol");
669 names.push_back(
"Part. Mol. Cv (J/K/kmol)");
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
virtual doublereal density() const
Density (kg/m^3).
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
virtual double osmoticCoefficient() const
Calculate the osmotic coefficient.
doublereal electricPotential() const
Returns the electric potential of this phase (V).
void initLengths()
Initialize lengths of local variables after all species have been identified.
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
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...
size_t nElements() const
Number of elements.
void setSolvent(size_t k)
This routine sets the index number of the solvent for the phase.
virtual void applyphScale(doublereal *acMolality) const
Apply the current phScale to a set of activity Coefficients or activities.
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
An error indicating that an unimplemented function has been called.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
doublereal m_Mnaught
This is the multiplication factor that goes inside log expressions involving the molalities of specie...
const size_t npos
index returned by functions to indicate "no position"
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.
Class XML_Node is a tree-based representation of the contents of an XML file.
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
doublereal m_xmolSolventMIN
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
virtual void getUnscaledMolalityActivityCoefficients(doublereal *acMolality) const
Get the array of unscaled non-dimensional molality based activity coefficients at the current solutio...
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
std::string name() const
Return the name of the phase.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
#define AssertThrowMsg(expr, procedure, message)
Assertion must be true or an error is thrown.
Header for intermediate ThermoPhase object for phases which employ molality based activity coefficien...
doublereal intEnergy_mass() const
Specific internal energy.
VPStandardStateTP & operator=(const VPStandardStateTP &b)
Assignment operator.
Base class for a phase with thermodynamic properties.
size_t solventIndex() const
Returns the solvent index.
bool m_chargeNeutralityNecessary
Boolean indicating whether a charge neutrality condition is a necessity.
virtual void getActivities(doublereal *ac) const
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
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 enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
doublereal gibbs_mass() const
Specific Gibbs function.
doublereal entropy_mass() const
Specific entropy.
void setMolalitiesByName(const compositionMap &xMap)
Set the molalities of a phase.
doublereal pressure() const
Returns the current pressure of the phase.
MolalityVPSSTP & operator=(const MolalityVPSSTP &b)
Assignment operator.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
doublereal cp_mass() const
Specific heat at constant pressure.
virtual void getMolalityActivityCoefficients(doublereal *acMolality) const
Get the array of non-dimensional molality based activity coefficients at the current solution tempera...
virtual void setToEquilState(const doublereal *lambda_RT)
This method is used by the ChemEquil element-potential based equilibrium solver.
const int PHSCALE_NBS
Scale to be used for evaluation of single-ion activity coefficients is that used by the NBS standard ...
#define AssertThrow(expr, procedure)
Assertion must be true or an error is thrown.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Base class for exceptions thrown by Cantera classes.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations that are defined such that where is a s...
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.
doublereal cv_mass() const
Specific heat at constant volume.
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 There is no restriction on the sum of the mole fractio...
int m_pHScalingType
Scaling to be used for output of single-ion species activity coefficients.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
virtual void setStateFromXML(const XML_Node &state)
Set equation of state parameter values from XML entries.
virtual void getPartialMolarIntEnergies(doublereal *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
virtual size_t findCLMIndex() const
Returns the index of the Cl- species.
void setMolalities(const doublereal *const molal)
Set the molalities of the solutes in a phase.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
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.
size_t nSpecies() const
Returns the number of species in the phase.
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 std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
doublereal moleFSolventMin() const
Returns the minimum mole fraction in the molality formulation.
doublereal moleFraction(size_t k) const
Return the mole fraction of a single species.
doublereal temperature() const
Temperature (K).
size_t nDim() const
Returns the number of spatial dimensions (1, 2, or 3)
void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional activity coefficients at the current solution temperature, pressure, and solution concentration.
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 enthalpy_mass() const
Specific enthalpy.
virtual void initThermo()
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 meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Initialize a ThermoPhase object, potentially reading activity coefficient information from an XML dat...
void getMolalities(doublereal *const molal) const
This function will return the molalities of the species.
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.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
doublereal m_weightSolvent
Molecular weight of the Solvent.
void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object.
std::string elementName(size_t m) const
Name of the element with index m.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
size_t m_kk
Number of species in the phase.
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
int activityConvention() const
This method returns the activity convention.
int pHScale() const
Reports the pH scale, which determines the scale for single-ion activity coefficients.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
size_t m_indexSolvent
Index of the solvent.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
MolalityVPSSTP()
Default Constructor.
void calcMolalities() const
Calculates the molality of all species and stores the result internally.
std::string speciesName(size_t k) const
Name of the species with index k.
virtual void getUnitsStandardConc(double *uA, int k=0, int sizeUA=6) const
Returns the units of the standard and generalized concentrations Note they have the same units...
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.
virtual doublereal standardConcentration(size_t k=0) const
The standard concentration used to normalize the generalized concentration.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
void save()
Function to put this error onto Cantera's error stack.