31 MolalityVPSSTP::MolalityVPSSTP() :
36 m_weightSolvent(18.01528),
37 m_xmolSolventMIN(0.01),
38 m_Mnaught(18.01528E-3)
50 m_indexSolvent(b.m_indexSolvent),
51 m_pHScalingType(b.m_pHScalingType),
52 m_indexCLM(b.m_indexCLM),
53 m_xmolSolventMIN(b.m_xmolSolventMIN),
54 m_Mnaught(b.m_Mnaught),
55 m_molalities(b.m_molalities)
96 "Unknown scale type: " +
int2str(pHscaleType));
113 "Molality-based methods limit solvent id to being 0");
126 if (xmolSolventMIN <= 0.0) {
127 throw CanteraError(
"MolalityVPSSTP::setSolute ",
"trouble");
128 }
else if (xmolSolventMIN > 0.9) {
129 throw CanteraError(
"MolalityVPSSTP::setSolute ",
"trouble");
146 double denomInv = 1.0/ (
m_Mnaught * xmolSolvent);
147 for (
size_t k = 0; k <
m_kk; k++) {
155 for (
size_t k = 0; k <
m_kk; k++) {
163 for (
size_t k = 1; k <
m_kk; k++) {
167 double tmp = 1.0 / Lsum;
170 for (
size_t k = 1; k <
m_kk; k++) {
176 for (
size_t k = 0; k <
m_kk; k++) {
205 compositionMap::iterator p;
206 for (
size_t k = 0; k < kk; k++) {
208 if (p != mMap.end()) {
218 size_t largePos =
npos;
220 size_t largeNeg =
npos;
223 for (
size_t k = 0; k < kk; k++) {
227 if (ch * mf[k] > cPos) {
233 if (fabs(ch) * mf[k] > cNeg) {
235 cNeg = fabs(ch) * mf[k];
244 mf[largePos] -= sum /
charge(largePos);
246 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
247 "unbalanced charges");
251 mf[largeNeg] -= (-sum) / fabs(
charge(largeNeg));
253 throw CanteraError(
"MolalityVPSSTP:setMolalitiesbyName",
254 "unbalanced charges");
260 for (
size_t k = 0; k < kk; k++) {
264 for (
size_t k = 0; k < kk; k++) {
293 err(
"getActivityConcentrations");
298 err(
"standardConcentration");
304 err(
"logStandardConc");
310 err(
"getActivities");
321 for (
size_t k = 1; k <
m_kk; k++) {
322 ac[k] /= xmolSolvent;
343 for (
size_t k = 1; k <
m_kk; k++) {
348 if (sum > 1.0E-200) {
358 for (
size_t k = 0; k <
m_kk; k++) {
365 throw CanteraError(
"MolalityVPSSTP",
"Base class method "
372 for (
int i = 0; i < sizeUA; i++) {
377 uA[1] = -int(
nDim());
397 err(
"setToEquilState");
414 const doublereal*
const molalities)
450 err(
"getUnscaledMolalityActivityCoefficients");
460 size_t indexCLM =
npos;
465 for (
size_t e = 0; e < ne; e++) {
467 if (sn ==
"Cl" || sn ==
"CL") {
476 for (
size_t e = 0; e < ne; e++) {
478 if (sn ==
"E" || sn ==
"e") {
487 for (
size_t k = 1; k <
m_kk; k++) {
488 doublereal nCl =
nAtoms(k, eCl);
492 doublereal nE =
nAtoms(k, eE);
496 for (
size_t e = 0; e < ne; e++) {
497 if (e != eE && e != eCl) {
498 doublereal nA =
nAtoms(k, e);
505 if (sn !=
"Cl-" && sn !=
"CL-") {
544 sprintf(p,
" \n %s:\n",
name().c_str());
547 sprintf(p,
" \n temperature %12.6g K\n",
temperature());
549 sprintf(p,
" pressure %12.6g Pa\n",
pressure());
551 sprintf(p,
" density %12.6g kg/m^3\n",
density());
557 sprintf(p,
" potential %12.6g V\n", phi);
576 double pH = -log(actMolal[iHp]) / log(10.0);
577 sprintf(p,
" pH %12.4g \n", pH);
584 sprintf(p,
" 1 kg 1 kmol\n");
586 sprintf(p,
" ----------- ------------\n");
588 sprintf(p,
" enthalpy %12.6g %12.4g J\n",
591 sprintf(p,
" internal energy %12.6g %12.4g J\n",
594 sprintf(p,
" entropy %12.6g %12.4g J/K\n",
597 sprintf(p,
" Gibbs function %12.6g %12.4g J\n",
600 sprintf(p,
" heat capacity c_p %12.6g %12.4g J/K\n",
604 sprintf(p,
" heat capacity c_v %12.6g %12.4g J/K\n",
609 sprintf(p,
" heat capacity c_v <not implemented> \n");
618 " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n");
621 " (J/kmol) (J/kmol) \n");
623 sprintf(p,
" ------------- "
624 " ------------ ------------ ------------ ------------\n");
626 for (
size_t k = 0; k < kk; k++) {
628 sprintf(p,
"%18s %12.6g %12.6g %12.6g %12.6g %12.6g\n",
629 speciesName(k).c_str(), x[k], molal[k], mu[k], muss[k], acMolal[k]);
631 sprintf(p,
"%18s %12.6g %12.6g N/A %12.6g %12.6g \n",
632 speciesName(k).c_str(), x[k], molal[k], muss[k], acMolal[k]);
640 sprintf(p,
" -------------"
643 for (
size_t k = 0; k < kk; k++) {
644 sprintf(p,
"%18s %12.6g %12.6g\n",
656 std::vector<vector_fp>& data)
const
661 names.push_back(
"X");
664 names.push_back(
"Molal");
667 names.push_back(
"Chem. Pot. (J/kmol)");
670 names.push_back(
"Chem. Pot. SS (J/kmol)");
673 names.push_back(
"Molal Act. Coeff.");
676 names.push_back(
"Molal Activity");
679 names.push_back(
"Part. Mol Enthalpy (J/kmol)");
682 names.push_back(
"Part. Mol. Entropy (J/K/kmol)");
685 names.push_back(
"Part. Mol. Energy (J/kmol)");
688 names.push_back(
"Part. Mol. Cp (J/K/kmol");
691 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.
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
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 doublereal logStandardConc(size_t k=0) const
Returns the natural logarithm of the standard concentration of the kth species.
virtual void applyphScale(doublereal *acMolality) const
Apply the current phScale to a set of activity Coefficients or activities.
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.
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
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 int eosType() const
Equation of state type flag.
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.
doublereal err(const std::string &msg) const
Error function.
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()
Initialize the ThermoPhase object after all species have been set up.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
doublereal gibbs_mass() const
Specific Gibbs function.
doublereal entropy_mass() const
Specific entropy.
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.
void setMolalitiesByName(compositionMap &xMap)
Set the molalities of a phase.
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...
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...
const int cAC_CONVENTION_MOLALITY
Standard state uses the molality convention.
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
doublereal cv_mass() const
Specific heat at constant volume.
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.
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()
Initialize the ThermoPhase object after all species have been set up.
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.
#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.
std::string getChildValue(const Cantera::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 std::string report(bool show_thermo=true) const
returns a summary of the state of the phase as a string
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.