diff --git a/Cantera/python/ctml_writer.py b/Cantera/python/ctml_writer.py index f5ea4c614..af6c2fa1f 100644 --- a/Cantera/python/ctml_writer.py +++ b/Cantera/python/ctml_writer.py @@ -1084,13 +1084,15 @@ class state: mole_fractions = None, mass_fractions = None, density = None, - coverages = None): + coverages = None, + solute_molalities = None): self._t = temperature self._p = pressure self._rho = density self._x = mole_fractions self._y = mass_fractions self._c = coverages + self._m = solute_molalities def build(self, ph): st = ph.addChild('state') @@ -1100,6 +1102,7 @@ class state: if self._x: st.addChild('moleFractions', self._x) if self._y: st.addChild('massFractions', self._y) if self._c: st.addChild('coverages', self._c) + if self._m: st.addChild('soluteMolalities', self._m) class phase: @@ -1650,6 +1653,141 @@ class edge(phase): def conc_dim(self): return (1, -1) + +class binary_salt_parameters: + def __init__(self, + cation = "", + anion = "", + beta0 = None, + beta1 = None, + beta2 = None, + Cphi = None, + Alpha1 = -1.0): + self._cation = cation + self._anion = anion + self._beta0 = beta0 + self._beta1 = beta1 + self._Cphi = Cphi + self._Alpha1 = Alpha1 + + def build(self, a): + s = a.addChild("binarySaltParameters") + s["cation"] = self._cation + s["anion"] = self._anion + s.addChild("beta0", self._beta0) + s.addChild("beta1", self._beta1) + s.addChild("beta2", self._beta2) + s.addChild("Cphi", self._Cphi) + s.addChild("Alpha1", self._Alpha1) + +class theta_anion: + def __init__(self, + anions = None, + theta = 0.0): + self._anions = anions + self._theta = theta + + def build(self, a): + s = a.addChild("thetaAnion") + s["anion1"] = self._anions[0] + s["anion2"] = self._anions[1] + s.addChild("Theta", self._theta) + +class psi_common_cation: + def __init__(self, + anions = None, + cation = '', + theta = 0.0, + psi = 0.0): + self._anions = anions + self._cation = cation + self._theta = theta + self._psi = psi + + def build(self, a): + s = a.addChild("psiCommonCation") + s["anion1"] = self._anions[0] + s["anion2"] = self._anions[1] + s["cation"] = self._cation + s.addChild("Theta", self._theta) + s.addChild("Psi", self._psi) + +class psi_common_anion: + def __init__(self, + anion = '', + cations = None, + theta = 0.0, + psi = 0.0): + self._anion = anion + self._cations = cations + self._theta = theta + self._psi = psi + + def build(self, a): + s = a.addChild("psiCommonAnion") + s["anion1"] = self._cations[0] + s["anion2"] = self._cations[1] + s["cation"] = self._anion + s.addChild("Theta", self._theta) + s.addChild("Psi", self._psi) + + +class theta_cation: + def __init__(self, + cations = None, + theta = 0.0): + self._cations = cations + self._theta = theta + + def build(self, a): + s = a.addChild("thetaCation") + s["cation1"] = self._anions[0] + s["cation2"] = self._anions[1] + s.addChild("Theta", self._theta) + +class pitzer: + def __init__(self, + temp_model = "", + A_Debye = "", + default_ionic_radius = -1.0, + +class electrolyte(phase): + """An electrolye solution obeying the HMW model.""" + def __init__(self, + name = '', + elements = '', + species = '', + transport = 'None', + initial_state = None, + solvent = '', + standard_concentration = '', + activity_coefficients = None, + options = []): + + phase.__init__(self, name, 3, elements, species, 'none', + initial_state, options) + self._pure = 0 + self._solvent = solvent + self._stdconc = standard_concentration + + def conc_dim(self): + return (1,-3) + + def build(self, p): + ph = phase.build(self, p) + e = ph.addChild("thermo") + sc = e.addChild("standardConc") + sc['model'] = self._stdconc + e['model'] = 'HMW' + e.addChild("activity_coefficients") + + addFloat(e, 'density', self._dens, defunits = _umass+'/'+_ulen+'3') + if self._tr: + t = ph.addChild('transport') + t['model'] = self._tr + k = ph.addChild("kinetics") + k['model'] = 'none' + #------------------------------------------------------------------- diff --git a/Cantera/src/thermo/ThermoFactory.cpp b/Cantera/src/thermo/ThermoFactory.cpp index ef3f4fe91..705b4e763 100644 --- a/Cantera/src/thermo/ThermoFactory.cpp +++ b/Cantera/src/thermo/ThermoFactory.cpp @@ -53,20 +53,28 @@ #include "LatticePhase.h" #endif +#ifdef WITH_ELECTROLYTES +#include "HMWSoln.h" +#endif + using namespace std; namespace Cantera { ThermoFactory* ThermoFactory::s_factory = 0; - static int ntypes = 9; + static int ntypes = 10; static string _types[] = {"IdealGas", "Incompressible", "Surface", "Edge", "Metal", "StoichSubstance", - "PureFluid", "LatticeSolid", "Lattice"}; + "PureFluid", "LatticeSolid", "Lattice", + "HMW" + }; static int _itypes[] = {cIdealGas, cIncompressible, cSurf, cEdge, cMetal, cStoichSubstance, - cPureFluid, cLatticeSolid, cLattice}; + cPureFluid, cLatticeSolid, cLattice, + cHMW + }; /* * This method returns a new instance of a subclass of ThermoPhase @@ -130,6 +138,11 @@ namespace Cantera { th = new PureFluidPhase; break; #endif +#ifdef WITH_ELECTROLYTES + case cHMW: + th = new HMWSoln; + break; +#endif default: throw UnknownThermoPhaseModel("ThermoFactory::newThermoPhase", @@ -155,7 +168,12 @@ namespace Cantera { const XML_Node& th = xmlphase.child("thermo"); string model = th["model"]; ThermoPhase* t = newThermoPhase(model); - importPhase(xmlphase, t); + if (model == "HMW") { + HMWSoln* p = (HMWSoln*)t; + p->constructPhaseXML(xmlphase,""); + } + else + importPhase(xmlphase, t); return t; } diff --git a/Cantera/src/thermo/mix_defs.h b/Cantera/src/thermo/mix_defs.h index cbcb42718..55c3164a1 100755 --- a/Cantera/src/thermo/mix_defs.h +++ b/Cantera/src/thermo/mix_defs.h @@ -50,6 +50,9 @@ namespace Cantera { /// An edge between two 2D surfaces const int cEdge = 6; + // HMW + const int cHMW = 40; + // kinetic manager types const int cGasKinetics = 2; const int cGRI30 = 3; diff --git a/Cantera/src/thermo/phasereport.cpp b/Cantera/src/thermo/phasereport.cpp index 147aad76b..8d746d0f7 100644 --- a/Cantera/src/thermo/phasereport.cpp +++ b/Cantera/src/thermo/phasereport.cpp @@ -18,7 +18,8 @@ namespace Cantera { * Format a summary of the mixture state for output. */ string report(const ThermoPhase& th, bool show_thermo) { - + cout << "in report... " << th.name() << endl; + cout << "nSpecies = " << th.nSpecies() << endl; char p[200]; string s = ""; try { @@ -71,9 +72,15 @@ namespace Cantera { sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n", th.cp_mass(), th.cp_mole()); s += p; - sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n", - th.cv_mass(), th.cv_mole()); - s += p; + try { + sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n", + th.cv_mass(), th.cv_mole()); + s += p; + } + catch(CanteraError) { + sprintf(p, " heat capacity c_v \n"); + s += p; + } } int kk = th.nSpecies(); @@ -85,7 +92,7 @@ namespace Cantera { th.getChemPotentials(&mu[0]); doublereal rt = GasConstant * th.temperature(); int k; - if (th.nSpecies() > 1) { + //if (th.nSpecies() > 1) { if (show_thermo) { sprintf(p, " \n X " @@ -120,7 +127,7 @@ namespace Cantera { } } } - } + //} catch (CanteraError) { ; }