26 RedlichKisterVPSSTP::RedlichKisterVPSSTP() :
28 numBinaryInteractions_(0),
34 formRedlichKister_(0),
41 const std::string& id_) :
43 numBinaryInteractions_(0),
49 formRedlichKister_(0),
57 const std::string& id_) :
59 numBinaryInteractions_(0),
65 formRedlichKister_(0),
74 numBinaryInteractions_(0),
80 formRedlichKister_(0),
105 throw CanteraError(
"RedlichKisterVPSSTP test1 constructor",
106 "Unable to find LiLi");
113 throw CanteraError(
"RedlichKisterVPSSTP test1 constructor",
114 "Unable to find VLi");
121 numBinaryInteractions_(0),
127 formRedlichKister_(0),
181 for (
size_t k = 0; k <
m_kk; k++) {
194 for (
size_t k = 0; k <
m_kk; k++) {
217 for (
size_t k = 0; k <
m_kk; k++) {
229 for (
size_t i = 0; i < kk; i++) {
241 for (
size_t i = 0; i < kk; i++) {
253 for (
size_t i = 0; i < kk; i++) {
275 for (
size_t k = 0; k <
m_kk; k++) {
285 for (
size_t k = 0; k <
m_kk; k++) {
304 for (
size_t k = 0; k <
m_kk; k++) {
310 for (
size_t k = 0; k <
m_kk; k++) {
330 for (
size_t k = 0; k <
m_kk; k++) {
337 for (
size_t k = 0; k <
m_kk; k++) {
342 void RedlichKisterVPSSTP::getPartialMolarVolumes(doublereal* vbar)
const
348 for (
size_t iK = 0; iK <
m_kk; iK++) {
356 throw CanteraError(
"RedlichKisterVPSSTP",
"Base class method "
375 std::string subname =
"RedlichKisterVPSSTP::initThermoXML";
377 if ((
int) id_.size() > 0) {
378 string idp = phaseNode.
id();
381 "phasenode and Id are incompatible");
389 if (!phaseNode.
hasChild(
"thermo")) {
393 std::string mStringa = thermoNode.
attrib(
"model");
394 std::string mString =
lowercase(mStringa);
395 if (mString !=
"redlich-kister") {
397 "Unknown thermo model: " + mStringa +
" - This object only knows \"Redlich-Kister\" ");
405 if (thermoNode.
hasChild(
"activityCoefficients")) {
408 mStringa = acNode.
attrib(
"model");
410 if (mString !=
"redlich-kister") {
412 "Unknown activity coefficient model: " + mStringa);
415 for (
size_t i = 0; i < n; i++) {
417 stemp = xmlACChild.
name();
424 if (nodeName ==
"binaryneutralspeciesparameters") {
454 doublereal deltaX = XA - XB;
458 doublereal poly = 1.0;
459 doublereal polyMm1 = 1.0;
460 doublereal sum = 0.0;
461 doublereal sumMm1 = 0.0;
462 doublereal sum2 = 0.0;
463 for (
size_t m = 0; m < N; m++) {
464 doublereal A_ge = (he_vec[m] - T * se_vec[m]) / RT;
466 sum2 += A_ge * (m + 1) * poly;
469 sumMm1 += (A_ge * polyMm1 * m);
473 doublereal oneMXA = 1.0 - XA;
474 doublereal oneMXB = 1.0 - XB;
475 for (
size_t k = 0; k <
m_kk; k++) {
478 }
else if (iB == k) {
485 #ifdef DEBUG_MODE_NOT
489 double fac = 2.0 * XA - 1.0;
490 for (
int m = 0; m < N; m++) {
491 doublereal A_ge = (he_vec[m] - T * se_vec[m]) / RT;
492 lnA += A_ge * oneMXA * oneMXA * polyk * (1.0 + 2.0 * XA * m / fac);
493 lnB += A_ge * XA * XA * polyk * (1.0 - 2.0 * oneMXA * m / fac);
519 doublereal deltaX = XA - XB;
521 doublereal poly = 1.0;
522 doublereal sum = 0.0;
525 doublereal sumMm1 = 0.0;
526 doublereal polyMm1 = 1.0;
527 doublereal sum2 = 0.0;
528 for (
size_t m = 0; m < N; m++) {
529 doublereal A_ge = - se_vec[m];
531 sum2 += A_ge * (m + 1) * poly;
534 sumMm1 += (A_ge * polyMm1 * m);
538 doublereal oneMXA = 1.0 - XA;
539 doublereal oneMXB = 1.0 - XB;
540 for (
size_t k = 0; k <
m_kk; k++) {
543 }
else if (iB == k) {
555 for (
size_t k = 0; k <
m_kk; k++) {
563 for (
size_t k = 0; k <
m_kk; k++) {
580 doublereal deltaX = XA - XB;
582 doublereal poly = 1.0;
583 doublereal sum = 0.0;
586 doublereal sumMm1 = 0.0;
587 doublereal polyMm1 = 1.0;
588 doublereal polyMm2 = 1.0;
589 doublereal sum2 = 0.0;
590 doublereal sum2Mm1 = 0.0;
591 doublereal sumMm2 = 0.0;
592 for (
size_t m = 0; m < N; m++) {
593 doublereal A_ge = he_vec[m] - T * se_vec[m];
595 sum2 += A_ge * (m + 1) * poly;
598 sumMm1 += (A_ge * polyMm1 * m);
599 sum2Mm1 += (A_ge * polyMm1 * m * (1.0 + m));
603 sumMm2 += (A_ge * polyMm2 * m * (m - 1.0));
608 for (
size_t k = 0; k <
m_kk; k++) {
612 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
613 + XA * XB * sumMm2 * (1.0 - XA + XB));
616 + XA * sumMm1 * (1.0 + 2.0 * XB - XA)
617 - XA * XB * sumMm2 * (1.0 - XA + XB));
619 }
else if (iB == k) {
622 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
623 + XA * XB * sumMm2 * (1.0 - XA + XB));
626 + XA * sumMm1 * (XB - XA - (1.0 - XB))
627 - XA * XB * sumMm2 * (-XA - (1.0 - XB)));
640 doublereal* dlnActCoeffds)
const
644 for (
size_t k = 0; k <
m_kk; k++) {
646 for (
size_t l = 0; l <
m_kk; l++) {
655 for (
size_t l = 0; l <
m_kk; l++) {
657 for (
size_t k = 0; k <
m_kk; k++) {
666 for (
size_t k = 0; k <
m_kk; k++) {
675 for (
size_t k = 0; k <
m_kk; k++) {
676 for (
size_t m = 0; m <
m_kk; m++) {
677 dlnActCoeffdlnN[ld * k + m] = data[m_kk * k + m];
695 std::string xname = xmLBinarySpecies.
name();
696 if (xname !=
"binaryNeutralSpeciesParameters") {
697 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
698 "Incorrect name for processing this routine: " + xname);
703 std::string iName = xmLBinarySpecies.
attrib(
"speciesA");
705 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"no speciesA attrib");
707 std::string jName = xmLBinarySpecies.
attrib(
"speciesB");
709 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"no speciesB attrib");
717 if (iSpecies ==
npos) {
721 if (
charge(iSpecies) != 0) {
722 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"speciesA charge problem");
725 if (jSpecies ==
npos) {
729 if (
charge(jSpecies) != 0) {
730 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"speciesB charge problem");
742 size_t num = xmLBinarySpecies.
nChildren();
743 for (
size_t iChild = 0; iChild < num; iChild++) {
745 stemp = xmlChild.
name();
750 if (nodeName ==
"excessenthalpy") {
755 size_t nParamsFound = hParams.size();
756 if (nParamsFound > Npoly) {
757 Npoly = nParamsFound;
762 if (nodeName ==
"excessentropy") {
767 size_t nParamsFound = sParams.size();
768 if (nParamsFound > Npoly) {
769 Npoly = nParamsFound;
773 hParams.resize(Npoly, 0.0);
774 sParams.resize(Npoly, 0.0);
800 if (XA >= (1.0 - 1.0E-14)) {
807 double fac = 2.0 * XA - 1.0;
808 if (fabs(fac) < 1.0E-13) {
811 double polykp1 = fac;
812 double poly1mk = fac;
814 for (m = 0; m < N; m++) {
815 doublereal A_ge = he_vec[m] - T * se_vec[m];
816 Volts += A_ge * (polykp1 - (2.0 * XA * m * (1.0-XA)) / poly1mk);
823 double termp = RT * log((1.0 - XA)/XA) / Faraday;
826 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.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
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).
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 int eosType() const
Equation of state type flag.
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.
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.
doublereal err(const std::string &msg) const
Error function.
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.
size_t nSpecies() const
Returns the number of species in the phase.
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...
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 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 getFloatArray(const Cantera::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...
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...