24 RedlichKisterVPSSTP::RedlichKisterVPSSTP() :
25 numBinaryInteractions_(0),
26 formRedlichKister_(0),
32 const std::string& id_) :
33 numBinaryInteractions_(0),
34 formRedlichKister_(0),
41 const std::string& id_) :
42 numBinaryInteractions_(0),
43 formRedlichKister_(0),
50 numBinaryInteractions_(0),
51 formRedlichKister_(0),
54 warn_deprecated(
"RedlichKisterVPSSTP::RedlichKisterVPSSTP(int testProb)",
55 "To be removed after Cantera 2.2");
78 throw CanteraError(
"RedlichKisterVPSSTP test1 constructor",
79 "Unable to find LiLi");
86 throw CanteraError(
"RedlichKisterVPSSTP test1 constructor",
87 "Unable to find VLi");
93 numBinaryInteractions_(0),
94 formRedlichKister_(0),
140 for (
size_t k = 0; k <
m_kk; k++) {
153 for (
size_t k = 0; k <
m_kk; k++) {
173 for (
size_t k = 0; k <
m_kk; k++) {
184 for (
size_t i = 0; i <
m_kk; i++) {
195 for (
size_t i = 0; i <
m_kk; i++) {
206 for (
size_t i = 0; i <
m_kk; i++) {
227 for (
size_t k = 0; k <
m_kk; k++) {
236 for (
size_t k = 0; k <
m_kk; k++) {
255 for (
size_t k = 0; k <
m_kk; k++) {
261 for (
size_t k = 0; k <
m_kk; k++) {
280 for (
size_t k = 0; k <
m_kk; k++) {
287 for (
size_t k = 0; k <
m_kk; k++) {
298 for (
size_t iK = 0; iK <
m_kk; iK++) {
317 if ((
int) id_.size() > 0 && phaseNode.
id() != id_) {
318 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
319 "phasenode and Id are incompatible");
326 if (!phaseNode.
hasChild(
"thermo")) {
327 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
328 "no thermo XML node");
331 std::string mString = thermoNode.
attrib(
"model");
332 if (
lowercase(mString) !=
"redlich-kister") {
333 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
334 "Unknown thermo model: " + mString +
" - This object only knows \"Redlich-Kister\" ");
341 if (thermoNode.
hasChild(
"activityCoefficients")) {
343 mString = acNode.
attrib(
"model");
344 if (
lowercase(mString) !=
"redlich-kister") {
345 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
346 "Unknown activity coefficient model: " + mString);
348 for (
size_t i = 0; i < acNode.
nChildren(); i++) {
355 if (
lowercase(xmlACChild.
name()) ==
"binaryneutralspeciesparameters") {
382 doublereal deltaX = XA - XB;
386 doublereal poly = 1.0;
387 doublereal polyMm1 = 1.0;
388 doublereal sum = 0.0;
389 doublereal sumMm1 = 0.0;
390 doublereal sum2 = 0.0;
391 for (
size_t m = 0; m < N; m++) {
392 doublereal A_ge = (he_vec[m] - T * se_vec[m]) / (
GasConstant * T);
394 sum2 += A_ge * (m + 1) * poly;
397 sumMm1 += (A_ge * polyMm1 * m);
401 doublereal oneMXA = 1.0 - XA;
402 doublereal oneMXB = 1.0 - XB;
403 for (
size_t k = 0; k <
m_kk; k++) {
406 }
else if (iB == k) {
413 #ifdef DEBUG_MODE_NOT
417 double fac = 2.0 * XA - 1.0;
418 for (
int m = 0; m < N; m++) {
419 doublereal A_ge = (he_vec[m] - T * se_vec[m]) / (
GasConstant * T);
420 lnA += A_ge * oneMXA * oneMXA * polyk * (1.0 + 2.0 * XA * m / fac);
421 lnB += A_ge * XA * XA * polyk * (1.0 - 2.0 * oneMXA * m / fac);
441 doublereal deltaX = XA - XB;
443 doublereal poly = 1.0;
444 doublereal sum = 0.0;
447 doublereal sumMm1 = 0.0;
448 doublereal polyMm1 = 1.0;
449 doublereal sum2 = 0.0;
450 for (
size_t m = 0; m < N; m++) {
451 doublereal A_ge = - se_vec[m];
453 sum2 += A_ge * (m + 1) * poly;
456 sumMm1 += (A_ge * polyMm1 * m);
460 doublereal oneMXA = 1.0 - XA;
461 doublereal oneMXB = 1.0 - XB;
462 for (
size_t k = 0; k <
m_kk; k++) {
465 }
else if (iB == k) {
477 for (
size_t k = 0; k <
m_kk; k++) {
485 for (
size_t k = 0; k <
m_kk; k++) {
501 doublereal deltaX = XA - XB;
503 doublereal poly = 1.0;
504 doublereal sum = 0.0;
507 doublereal sumMm1 = 0.0;
508 doublereal polyMm1 = 1.0;
509 doublereal polyMm2 = 1.0;
510 doublereal sum2 = 0.0;
511 doublereal sum2Mm1 = 0.0;
512 doublereal sumMm2 = 0.0;
513 for (
size_t m = 0; m < N; m++) {
514 doublereal A_ge = he_vec[m] - T * se_vec[m];
516 sum2 += A_ge * (m + 1) * poly;
519 sumMm1 += (A_ge * polyMm1 * m);
520 sum2Mm1 += (A_ge * polyMm1 * m * (1.0 + m));
524 sumMm2 += (A_ge * polyMm2 * m * (m - 1.0));
529 for (
size_t k = 0; k <
m_kk; k++) {
533 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
534 + XA * XB * sumMm2 * (1.0 - XA + XB));
537 + XA * sumMm1 * (1.0 + 2.0 * XB - XA)
538 - XA * XB * sumMm2 * (1.0 - XA + XB));
540 }
else if (iB == k) {
543 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
544 + XA * XB * sumMm2 * (1.0 - XA + XB));
547 + XA * sumMm1 * (XB - XA - (1.0 - XB))
548 - XA * XB * sumMm2 * (-XA - (1.0 - XB)));
561 doublereal* dlnActCoeffds)
const
565 for (
size_t k = 0; k <
m_kk; k++) {
567 for (
size_t l = 0; l <
m_kk; l++) {
576 for (
size_t l = 0; l <
m_kk; l++) {
578 for (
size_t k = 0; k <
m_kk; k++) {
587 for (
size_t k = 0; k <
m_kk; k++) {
596 for (
size_t k = 0; k <
m_kk; k++) {
597 for (
size_t m = 0; m <
m_kk; m++) {
598 dlnActCoeffdlnN[ld * k + m] = data[m_kk * k + m];
616 std::string xname = xmLBinarySpecies.
name();
617 if (xname !=
"binaryNeutralSpeciesParameters") {
618 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
619 "Incorrect name for processing this routine: " + xname);
623 std::string iName = xmLBinarySpecies.
attrib(
"speciesA");
625 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"no speciesA attrib");
627 std::string jName = xmLBinarySpecies.
attrib(
"speciesB");
629 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"no speciesB attrib");
637 if (iSpecies ==
npos) {
641 if (
charge(iSpecies) != 0) {
642 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"speciesA charge problem");
645 if (jSpecies ==
npos) {
649 if (
charge(jSpecies) != 0) {
650 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"speciesB charge problem");
662 for (
size_t iChild = 0; iChild < xmLBinarySpecies.
nChildren(); iChild++) {
668 if (nodeName ==
"excessenthalpy") {
672 getFloatArray(xmlChild, hParams,
true,
"toSI",
"excessEnthalpy");
673 Npoly = std::max(hParams.size(), Npoly);
676 if (nodeName ==
"excessentropy") {
680 getFloatArray(xmlChild, sParams,
true,
"toSI",
"excessEntropy");
681 Npoly = std::max(sParams.size(), Npoly);
684 hParams.resize(Npoly, 0.0);
685 sParams.resize(Npoly, 0.0);
706 if (XA >= (1.0 - 1.0E-14)) {
713 double fac = 2.0 * XA - 1.0;
714 if (fabs(fac) < 1.0E-13) {
717 double polykp1 = fac;
718 double poly1mk = fac;
720 for (
size_t m = 0; m < N; m++) {
721 doublereal A_ge = he_vec[m] - T * se_vec[m];
722 Volts += A_ge * (polykp1 - (2.0 * XA * m * (1.0-XA)) / poly1mk);
729 double termp =
GasConstant * T * log((1.0 - XA)/XA) / Faraday;
732 voltsOut = Volts + termp;
virtual void getdlnActCoeffds(const doublereal dTds, const doublereal *const dXds, doublereal *dlnActCoeffds) const
Get the change in activity coefficients w.r.t.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
virtual void getdlnActCoeffdT(doublereal *dlnActCoeffdT) const
Get the array of temperature derivatives of the log activity coefficients.
doublereal electricPotential() const
Returns the electric potential of this phase (V).
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
XML_Node * findXMLPhase(XML_Node *root, const std::string &idtarget)
Search an XML_Node tree for a named phase XML_Node.
virtual void initThermo()
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
GibbsExcessVPSSTP & operator=(const GibbsExcessVPSSTP &b)
Assignment operator.
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the array, and fill the new entries with 'v'.
RedlichKisterVPSSTP is a derived class of GibbsExcessVPSSTP that employs the Redlich-Kister approxima...
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of each species in their standard states at the current T and P of the solution...
RedlichKisterVPSSTP & operator=(const RedlichKisterVPSSTP &b)
Assignment operator.
const size_t npos
index returned by functions to indicate "no position"
size_t numBinaryInteractions_
number of binary interaction expressions
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the standard state of the species at ...
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
std::vector< vector_fp > m_HE_m_ij
Enthalpy term for the binary mole fraction interaction of the excess Gibbs free energy expression...
int formRedlichKister_
form of the RedlichKister interaction expression
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies for the species in the mixture.
Class XML_Node is a tree-based representation of the contents of an XML file.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
std::string lowercase(const std::string &s)
Cast a copy of a string to lower case.
int formTempModel_
form of the temperature dependence of the Redlich-Kister interaction expression
std::vector< doublereal > d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
Array2D dlnActCoeff_dX_
Two dimensional array of derivatives of activity coefficients wrt mole fractions. ...
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
std::vector< size_t > m_pSpecies_A_ij
vector of species indices representing species A in the interaction
Base class for a phase with thermodynamic properties.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
bool importPhase(XML_Node &phase, ThermoPhase *th, SpeciesThermoFactory *spfactory)
Import a phase information into an empty ThermoPhase object.
void s_update_lnActCoeff() const
Update the activity coefficients.
virtual void getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar entropies for the species in the mixture.
std::string name() const
Returns the name of the XML node.
virtual void getdlnActCoeffdlnX_diag(doublereal *dlnActCoeffdlnX_diag) const
Get the array of log concentration-like derivatives of the log activity coefficients - diagonal compo...
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
std::vector< size_t > m_pSpecies_B_ij
vector of species indices representing species B in the interaction
Base class for exceptions thrown by Cantera classes.
virtual void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of derivatives of the log activity coefficients wrt mole numbers - diagonal only...
void readXMLBinarySpecies(XML_Node &xmlBinarySpecies)
Process an XML node called "binaryNeutralSpeciesParameters".
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
void s_update_dlnActCoeff_dT() const
Update the derivative of the log of the activity coefficients wrt T.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
std::vector< doublereal > dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
RedlichKisterVPSSTP()
Constructor.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Enthalpy functions for the standard state species at the current T an...
doublereal temperature() const
Temperature (K).
std::string id() const
Return the id attribute, if present.
const doublereal SmallNumber
smallest number to compare to zero.
void initLengths()
Initialize lengths of local variables after all species have been identified.
std::vector< doublereal > lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the species.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
virtual void getLnActivityCoefficients(doublereal *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
void s_update_dlnActCoeff_dX_() const
Internal routine that calculates the derivative of the activity coefficients wrt the mole fractions...
size_t getFloatArray(const XML_Node &node, std::vector< doublereal > &v, const bool convert, const std::string &unitsString, const std::string &nodeName)
This function reads the current node or a child node of the current node with the default name...
std::vector< doublereal > moleFractions_
Storage for the current values of the mole fractions of the species.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Initialize a ThermoPhase object, potentially reading activity coefficient information from an XML dat...
Contains declarations for string manipulation functions within Cantera.
void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object.
virtual void initThermo()
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
virtual void getdlnActCoeffdlnN(const size_t ld, doublereal *const dlnActCoeffdlnN)
Get the array of derivatives of the ln activity coefficients with respect to the ln species mole numb...
size_t m_kk
Number of species in the phase.
Array2D dlnActCoeffdlnN_
Storage for the current derivative values of the gradients with respect to logarithm of the species m...
void Vint(double &VintOut, double &voltsOut)
Utility routine that calculates a literature expression.
void zero()
Set all of the entries to zero.
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
Header for intermediate ThermoPhase object for phases which employ Gibbs excess free energy based for...
virtual void getd2lnActCoeffdT2(doublereal *d2lnActCoeffdT2) const
Get the array of temperature second derivatives of the log activity coefficients. ...
std::string speciesName(size_t k) const
Name of the species with index k.
void resizeNumInteractions(const size_t num)
Resize internal arrays within the object that depend upon the number of binary Redlich-Kister interac...
size_t nChildren(bool discardComments=false) const
Return the number of children.
std::vector< doublereal > dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol.
std::vector< size_t > m_N_ij
Vector of the length of the polynomial for the interaction.
std::vector< vector_fp > m_SE_m_ij
Entropy term for the binary mole fraction interaction of the excess Gibbs free energy expression...
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...