Cantera  2.1.2
MolalityVPSSTP.cpp
Go to the documentation of this file.
1 /**
2  * @file MolalityVPSSTP.cpp
3  * Definitions for intermediate ThermoPhase object for phases which
4  * employ molality based activity coefficient formulations
5  * (see \ref thermoprops
6  * and class \link Cantera::MolalityVPSSTP MolalityVPSSTP\endlink).
7  *
8  * Header file for a derived class of ThermoPhase that handles
9  * variable pressure standard state methods for calculating
10  * thermodynamic properties that are further based upon activities
11  * based on the molality scale. These include most of the methods for
12  * calculating liquid electrolyte thermodynamics.
13  */
14 /*
15  * Copyright (2005) Sandia Corporation. Under the terms of
16  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
17  * U.S. Government retains certain rights in this software.
18  */
21 
22 #include <iomanip>
23 #include <cstdio>
24 #include <fstream>
25 
26 using namespace std;
27 
28 namespace Cantera
29 {
30 
31 MolalityVPSSTP::MolalityVPSSTP() :
33  m_indexSolvent(0),
34  m_pHScalingType(PHSCALE_PITZER),
35  m_indexCLM(npos),
36  m_weightSolvent(18.01528),
37  m_xmolSolventMIN(0.01),
38  m_Mnaught(18.01528E-3)
39 {
40  /*
41  * Change the default to be that charge neutrality in the
42  * phase is necessary condition for the proper specification
43  * of thermodynamic functions within the phase
44  */
46 }
47 
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)
56 {
57  *this = operator=(b);
58 }
59 
62 {
63  if (&b != this) {
70  m_Mnaught = b.m_Mnaught;
72  }
73  return *this;
74 }
75 
78 {
79  return new MolalityVPSSTP(*this);
80 }
81 
82 /*
83  * -------------- Utilities -------------------------------
84  */
85 
87 {
88  return 0;
89 }
90 
91 void MolalityVPSSTP::setpHScale(const int pHscaleType)
92 {
93  m_pHScalingType = pHscaleType;
94  if (pHscaleType != PHSCALE_PITZER && pHscaleType != PHSCALE_NBS) {
95  throw CanteraError("MolalityVPSSTP::setpHScale",
96  "Unknown scale type: " + int2str(pHscaleType));
97  }
98 }
99 
101 {
102  return m_pHScalingType;
103 }
104 
106 {
107  if (k >= m_kk) {
108  throw CanteraError("MolalityVPSSTP::setSolute ",
109  "bad value");
110  }
111  m_indexSolvent = k;
112  AssertThrowMsg(m_indexSolvent==0, "MolalityVPSSTP::setSolvent",
113  "Molality-based methods limit solvent id to being 0");
115  m_Mnaught = m_weightSolvent / 1000.;
116 }
117 
119 {
120  return m_indexSolvent;
121 }
122 
123 void MolalityVPSSTP::
124 setMoleFSolventMin(doublereal xmolSolventMIN)
125 {
126  if (xmolSolventMIN <= 0.0) {
127  throw CanteraError("MolalityVPSSTP::setSolute ", "trouble");
128  } else if (xmolSolventMIN > 0.9) {
129  throw CanteraError("MolalityVPSSTP::setSolute ", "trouble");
130  }
131  m_xmolSolventMIN = xmolSolventMIN;
132 }
133 
135 {
136  return m_xmolSolventMIN;
137 }
138 
140 {
142  double xmolSolvent = m_molalities[m_indexSolvent];
143  if (xmolSolvent < m_xmolSolventMIN) {
144  xmolSolvent = m_xmolSolventMIN;
145  }
146  double denomInv = 1.0/ (m_Mnaught * xmolSolvent);
147  for (size_t k = 0; k < m_kk; k++) {
148  m_molalities[k] *= denomInv;
149  }
150 }
151 
152 void MolalityVPSSTP::getMolalities(doublereal* const molal) const
153 {
154  calcMolalities();
155  for (size_t k = 0; k < m_kk; k++) {
156  molal[k] = m_molalities[k];
157  }
158 }
159 
160 void MolalityVPSSTP::setMolalities(const doublereal* const molal)
161 {
162  double Lsum = 1.0 / m_Mnaught;
163  for (size_t k = 1; k < m_kk; k++) {
164  m_molalities[k] = molal[k];
165  Lsum += molal[k];
166  }
167  double tmp = 1.0 / Lsum;
169  double sum = m_molalities[m_indexSolvent];
170  for (size_t k = 1; k < m_kk; k++) {
171  m_molalities[k] = tmp * molal[k];
172  sum += m_molalities[k];
173  }
174  if (sum != 1.0) {
175  tmp = 1.0 / sum;
176  for (size_t k = 0; k < m_kk; k++) {
177  m_molalities[k] *= tmp;
178  }
179  }
181  /*
182  * Essentially we don't trust the input: We calculate
183  * the molalities from the mole fractions that we
184  * just obtained.
185  */
186  calcMolalities();
187 }
188 
190 {
191  /*
192  * HKM -> Might need to be more complicated here, setting
193  * neutrals so that the existing mole fractions are
194  * preserved.
195  */
196  size_t kk = nSpecies();
197  doublereal x;
198  /*
199  * Get a vector of mole fractions
200  */
201  vector_fp mf(kk, 0.0);
203  double xmolS = mf[m_indexSolvent];
204  double xmolSmin = std::max(xmolS, m_xmolSolventMIN);
205  compositionMap::iterator p;
206  for (size_t k = 0; k < kk; k++) {
207  p = mMap.find(speciesName(k));
208  if (p != mMap.end()) {
209  x = mMap[speciesName(k)];
210  if (x > 0.0) {
211  mf[k] = x * m_Mnaught * xmolSmin;
212  }
213  }
214  }
215  /*
216  * check charge neutrality
217  */
218  size_t largePos = npos;
219  double cPos = 0.0;
220  size_t largeNeg = npos;
221  double cNeg = 0.0;
222  double sum = 0.0;
223  for (size_t k = 0; k < kk; k++) {
224  double ch = charge(k);
225  if (mf[k] > 0.0) {
226  if (ch > 0.0) {
227  if (ch * mf[k] > cPos) {
228  largePos = k;
229  cPos = ch * mf[k];
230  }
231  }
232  if (ch < 0.0) {
233  if (fabs(ch) * mf[k] > cNeg) {
234  largeNeg = k;
235  cNeg = fabs(ch) * mf[k];
236  }
237  }
238  }
239  sum += mf[k] * ch;
240  }
241  if (sum != 0.0) {
242  if (sum > 0.0) {
243  if (cPos > sum) {
244  mf[largePos] -= sum / charge(largePos);
245  } else {
246  throw CanteraError("MolalityVPSSTP:setMolalitiesbyName",
247  "unbalanced charges");
248  }
249  } else {
250  if (cNeg > (-sum)) {
251  mf[largeNeg] -= (-sum) / fabs(charge(largeNeg));
252  } else {
253  throw CanteraError("MolalityVPSSTP:setMolalitiesbyName",
254  "unbalanced charges");
255  }
256  }
257 
258  }
259  sum = 0.0;
260  for (size_t k = 0; k < kk; k++) {
261  sum += mf[k];
262  }
263  sum = 1.0/sum;
264  for (size_t k = 0; k < kk; k++) {
265  mf[k] *= sum;
266  }
268  /*
269  * After we formally set the mole fractions, we
270  * calculate the molalities again and store it in
271  * this object.
272  */
273  calcMolalities();
274 }
275 
276 void MolalityVPSSTP::setMolalitiesByName(const std::string& x)
277 {
280 }
281 
282 /*
283  * - Activities, Standard States, Activity Concentrations -----------
284  */
285 
287 {
289 }
290 
292 {
293  err("getActivityConcentrations");
294 }
295 
296 doublereal MolalityVPSSTP::standardConcentration(size_t k) const
297 {
298  err("standardConcentration");
299  return -1.0;
300 }
301 
302 doublereal MolalityVPSSTP::logStandardConc(size_t k) const
303 {
304  err("logStandardConc");
305  return -1.0;
306 }
307 
308 void MolalityVPSSTP::getActivities(doublereal* ac) const
309 {
310  err("getActivities");
311 }
312 
313 void MolalityVPSSTP::getActivityCoefficients(doublereal* ac) const
314 {
316  AssertThrow(m_indexSolvent==0, "MolalityVPSSTP::getActivityCoefficients");
317  double xmolSolvent = moleFraction(m_indexSolvent);
318  if (xmolSolvent < m_xmolSolventMIN) {
319  xmolSolvent = m_xmolSolventMIN;
320  }
321  for (size_t k = 1; k < m_kk; k++) {
322  ac[k] /= xmolSolvent;
323  }
324 }
325 
326 void MolalityVPSSTP::getMolalityActivityCoefficients(doublereal* acMolality) const
327 {
329  applyphScale(acMolality);
330 }
331 
333 {
334  /*
335  * First, we calculate the activities all over again
336  */
337  vector_fp act(m_kk);
338  getActivities(DATA_PTR(act));
339  /*
340  * Then, we calculate the sum of the solvent molalities
341  */
342  double sum = 0;
343  for (size_t k = 1; k < m_kk; k++) {
344  sum += std::max(m_molalities[k], 0.0);
345  }
346  double oc = 1.0;
347  double lac = log(act[m_indexSolvent]);
348  if (sum > 1.0E-200) {
349  oc = - lac / (m_Mnaught * sum);
350  }
351  return oc;
352 }
353 
355 {
356  getChemPotentials(mu);
357  double ve = Faraday * electricPotential();
358  for (size_t k = 0; k < m_kk; k++) {
359  mu[k] += ve*charge(k);
360  }
361 }
362 
363 doublereal MolalityVPSSTP::err(const std::string& msg) const
364 {
365  throw CanteraError("MolalityVPSSTP","Base class method "
366  +msg+" called. Equation of state type: "+int2str(eosType()));
367  return 0;
368 }
369 
370 void MolalityVPSSTP::getUnitsStandardConc(double* uA, int k, int sizeUA) const
371 {
372  for (int i = 0; i < sizeUA; i++) {
373  if (i == 0) {
374  uA[0] = 1.0;
375  }
376  if (i == 1) {
377  uA[1] = -int(nDim());
378  }
379  if (i == 2) {
380  uA[2] = 0.0;
381  }
382  if (i == 3) {
383  uA[3] = 0.0;
384  }
385  if (i == 4) {
386  uA[4] = 0.0;
387  }
388  if (i == 5) {
389  uA[5] = 0.0;
390  }
391  }
392 }
393 
394 void MolalityVPSSTP::setToEquilState(const doublereal* lambda_RT)
395 {
397  err("setToEquilState");
398 }
399 
401 {
403  string comp = ctml::getChildValue(state,"soluteMolalities");
404  if (comp != "") {
405  setMolalitiesByName(comp);
406  }
407  if (state.hasChild("pressure")) {
408  double p = ctml::getFloat(state, "pressure", "pressure");
409  setPressure(p);
410  }
411 }
412 
413 void MolalityVPSSTP::setState_TPM(doublereal t, doublereal p,
414  const doublereal* const molalities)
415 {
416  setMolalities(molalities);
417  setState_TP(t, p);
418 }
419 
420 void MolalityVPSSTP::setState_TPM(doublereal t, doublereal p, compositionMap& m)
421 {
423  setState_TP(t, p);
424 }
425 
426 void MolalityVPSSTP::setState_TPM(doublereal t, doublereal p, const std::string& m)
427 {
429  setState_TP(t, p);
430 }
431 
432 
434 {
435  initLengths();
437 
438  /*
439  * The solvent defaults to species 0
440  */
441  setSolvent(0);
442  /*
443  * Find the Cl- species
444  */
446 }
447 
449 {
450  err("getUnscaledMolalityActivityCoefficients");
451 }
452 
453 void MolalityVPSSTP::applyphScale(doublereal* acMolality) const
454 {
455  err("applyphScale");
456 }
457 
459 {
460  size_t indexCLM = npos;
461  size_t eCl = npos;
462  size_t eE = npos;
463  size_t ne = nElements();
464  string sn;
465  for (size_t e = 0; e < ne; e++) {
466  sn = elementName(e);
467  if (sn == "Cl" || sn == "CL") {
468  eCl = e;
469  break;
470  }
471  }
472  // We have failed if we can't find the Cl element index
473  if (eCl == npos) {
474  return npos;
475  }
476  for (size_t e = 0; e < ne; e++) {
477  sn = elementName(e);
478  if (sn == "E" || sn == "e") {
479  eE = e;
480  break;
481  }
482  }
483  // We have failed if we can't find the E element index
484  if (eE == npos) {
485  return npos;
486  }
487  for (size_t k = 1; k < m_kk; k++) {
488  doublereal nCl = nAtoms(k, eCl);
489  if (nCl != 1.0) {
490  continue;
491  }
492  doublereal nE = nAtoms(k, eE);
493  if (nE != 1.0) {
494  continue;
495  }
496  for (size_t e = 0; e < ne; e++) {
497  if (e != eE && e != eCl) {
498  doublereal nA = nAtoms(k, e);
499  if (nA != 0.0) {
500  continue;
501  }
502  }
503  }
504  sn = speciesName(k);
505  if (sn != "Cl-" && sn != "CL-") {
506  continue;
507  }
508 
509  indexCLM = k;
510  break;
511  }
512  return indexCLM;
513 }
514 
515 // Initialize lengths of local variables after all species have
516 // been identified.
518 {
519  m_kk = nSpecies();
520  m_molalities.resize(m_kk);
521 }
522 
523 void MolalityVPSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)
524 {
525 
526  initLengths();
527  /*
528  * The solvent defaults to species 0
529  */
530  setSolvent(0);
531 
532  VPStandardStateTP::initThermoXML(phaseNode, id_);
533 }
534 
535 /**
536  * Format a summary of the mixture state for output.
537  */
538 std::string MolalityVPSSTP::report(bool show_thermo) const
539 {
540  char p[800];
541  string s = "";
542  try {
543  if (name() != "") {
544  sprintf(p, " \n %s:\n", name().c_str());
545  s += p;
546  }
547  sprintf(p, " \n temperature %12.6g K\n", temperature());
548  s += p;
549  sprintf(p, " pressure %12.6g Pa\n", pressure());
550  s += p;
551  sprintf(p, " density %12.6g kg/m^3\n", density());
552  s += p;
553  sprintf(p, " mean mol. weight %12.6g amu\n", meanMolecularWeight());
554  s += p;
555 
556  doublereal phi = electricPotential();
557  sprintf(p, " potential %12.6g V\n", phi);
558  s += p;
559 
560  size_t kk = nSpecies();
561  vector_fp x(kk);
562  vector_fp molal(kk);
563  vector_fp mu(kk);
564  vector_fp muss(kk);
565  vector_fp acMolal(kk);
566  vector_fp actMolal(kk);
567  getMoleFractions(&x[0]);
568  getMolalities(&molal[0]);
569  getChemPotentials(&mu[0]);
570  getStandardChemPotentials(&muss[0]);
571  getMolalityActivityCoefficients(&acMolal[0]);
572  getActivities(&actMolal[0]);
573 
574  size_t iHp = speciesIndex("H+");
575  if (iHp != npos) {
576  double pH = -log(actMolal[iHp]) / log(10.0);
577  sprintf(p, " pH %12.4g \n", pH);
578  s += p;
579  }
580 
581  if (show_thermo) {
582  sprintf(p, " \n");
583  s += p;
584  sprintf(p, " 1 kg 1 kmol\n");
585  s += p;
586  sprintf(p, " ----------- ------------\n");
587  s += p;
588  sprintf(p, " enthalpy %12.6g %12.4g J\n",
590  s += p;
591  sprintf(p, " internal energy %12.6g %12.4g J\n",
593  s += p;
594  sprintf(p, " entropy %12.6g %12.4g J/K\n",
596  s += p;
597  sprintf(p, " Gibbs function %12.6g %12.4g J\n",
598  gibbs_mass(), gibbs_mole());
599  s += p;
600  sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n",
601  cp_mass(), cp_mole());
602  s += p;
603  try {
604  sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n",
605  cv_mass(), cv_mole());
606  s += p;
607  } catch (CanteraError& e) {
608  e.save();
609  sprintf(p, " heat capacity c_v <not implemented> \n");
610  s += p;
611  }
612  }
613 
614  sprintf(p, " \n");
615  s += p;
616  if (show_thermo) {
617  sprintf(p, " X "
618  " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n");
619  s += p;
620  sprintf(p, " "
621  " (J/kmol) (J/kmol) \n");
622  s += p;
623  sprintf(p, " ------------- "
624  " ------------ ------------ ------------ ------------\n");
625  s += p;
626  for (size_t k = 0; k < kk; k++) {
627  if (x[k] > SmallNumber) {
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]);
630  } else {
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]);
633  }
634  s += p;
635  }
636  } else {
637  sprintf(p, " X"
638  "Molalities\n");
639  s += p;
640  sprintf(p, " -------------"
641  " ------------\n");
642  s += p;
643  for (size_t k = 0; k < kk; k++) {
644  sprintf(p, "%18s %12.6g %12.6g\n",
645  speciesName(k).c_str(), x[k], molal[k]);
646  s += p;
647  }
648  }
649  } catch (CanteraError& err) {
650  err.save();
651  }
652  return s;
653 }
654 
655 void MolalityVPSSTP::getCsvReportData(std::vector<std::string>& names,
656  std::vector<vector_fp>& data) const
657 {
658  names.clear();
659  data.assign(10, vector_fp(nSpecies()));
660 
661  names.push_back("X");
662  getMoleFractions(&data[0][0]);
663 
664  names.push_back("Molal");
665  getMolalities(&data[1][0]);
666 
667  names.push_back("Chem. Pot. (J/kmol)");
668  getChemPotentials(&data[2][0]);
669 
670  names.push_back("Chem. Pot. SS (J/kmol)");
671  getStandardChemPotentials(&data[3][0]);
672 
673  names.push_back("Molal Act. Coeff.");
674  getMolalityActivityCoefficients(&data[4][0]);
675 
676  names.push_back("Molal Activity");
677  getActivities(&data[5][0]);
678 
679  names.push_back("Part. Mol Enthalpy (J/kmol)");
680  getPartialMolarEnthalpies(&data[5][0]);
681 
682  names.push_back("Part. Mol. Entropy (J/K/kmol)");
683  getPartialMolarEntropies(&data[6][0]);
684 
685  names.push_back("Part. Mol. Energy (J/kmol)");
686  getPartialMolarIntEnergies(&data[7][0]);
687 
688  names.push_back("Part. Mol. Cp (J/K/kmol");
689  getPartialMolarCp(&data[8][0]);
690 
691  names.push_back("Part. Mol. Cv (J/K/kmol)");
692  getPartialMolarVolumes(&data[9][0]);
693 }
694 
695 }
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
Definition: ct_defs.h:162
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
Definition: Phase.cpp:215
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Definition: Phase.cpp:484
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:534
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:40
virtual double osmoticCoefficient() const
Calculate the osmotic coefficient.
doublereal electricPotential() const
Returns the electric potential of this phase (V).
Definition: ThermoPhase.h:391
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.
Definition: ThermoPhase.h:279
size_t nElements() const
Number of elements.
Definition: Phase.cpp:139
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"
Definition: ct_defs.h:173
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.
Definition: xml.h:100
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.
Definition: ctml.cpp:267
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: ThermoPhase.h:669
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.
Definition: Phase.cpp:519
std::string name() const
Return the name of the phase.
Definition: Phase.cpp:129
virtual int eosType() const
Equation of state type flag.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
Definition: ThermoPhase.h:274
#define AssertThrowMsg(expr, procedure, message)
Assertion must be true or an error is thrown.
Definition: ctexceptions.h:247
Header for intermediate ThermoPhase object for phases which employ molality based activity coefficien...
doublereal intEnergy_mass() const
Specific internal energy.
Definition: ThermoPhase.h:940
VPStandardStateTP & operator=(const VPStandardStateTP &b)
Assignment operator.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
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.
Definition: ThermoPhase.h:1659
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.
Definition: Phase.cpp:229
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.
Definition: ThermoPhase.h:269
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
Definition: ThermoPhase.h:264
doublereal gibbs_mass() const
Specific Gibbs function.
Definition: ThermoPhase.h:954
doublereal entropy_mass() const
Specific entropy.
Definition: ThermoPhase.h:947
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.
Definition: ThermoPhase.h:595
doublereal cp_mass() const
Specific heat at constant pressure.
Definition: ThermoPhase.h:961
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.
Definition: ctexceptions.h:229
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.
Definition: ThermoPhase.h:638
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
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.
Definition: ThermoPhase.h:26
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
doublereal cv_mass() const
Specific heat at constant volume.
Definition: ThermoPhase.h:968
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...
Definition: Phase.cpp:306
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.
Definition: xml.cpp:574
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.
Definition: ThermoPhase.h:648
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.
Definition: ThermoPhase.h:289
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.
Definition: Phase.h:252
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Definition: Phase.cpp:252
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.
Definition: Phase.cpp:524
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
size_t nDim() const
Returns the number of spatial dimensions (1, 2, or 3)
Definition: Phase.h:512
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.
Definition: ct_defs.h:139
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:165
doublereal enthalpy_mass() const
Specific enthalpy.
Definition: ThermoPhase.h:933
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)
Definition: Phase.h:588
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.
Definition: ct_defs.h:36
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.
Definition: Phase.cpp:158
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: ThermoPhase.h:628
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: ThermoPhase.h:284
size_t m_kk
Number of species in the phase.
Definition: Phase.h:716
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
Definition: ThermoPhase.h:659
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...
Definition: ctml.cpp:164
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.
Definition: Phase.cpp:246
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...
Definition: Phase.h:504
void save()
Function to put this error onto Cantera's error stack.