21 RedlichKisterVPSSTP::RedlichKisterVPSSTP() :
22 numBinaryInteractions_(0),
23 formRedlichKister_(0),
29 const std::string& id_) :
30 numBinaryInteractions_(0),
31 formRedlichKister_(0),
38 const std::string& id_) :
39 numBinaryInteractions_(0),
40 formRedlichKister_(0),
47 numBinaryInteractions_(0),
48 formRedlichKister_(0),
51 RedlichKisterVPSSTP::operator=(b);
54 RedlichKisterVPSSTP& RedlichKisterVPSSTP::operator=(
const RedlichKisterVPSSTP& b)
60 GibbsExcessVPSSTP::operator=(b);
87 for (
size_t k = 0; k <
m_kk; k++) {
102 for (
size_t k = 0; k <
m_kk; k++) {
113 for (
size_t i = 0; i <
m_kk; i++) {
124 for (
size_t i = 0; i <
m_kk; i++) {
135 for (
size_t i = 0; i <
m_kk; i++) {
152 for (
size_t k = 0; k <
m_kk; k++) {
160 for (
size_t k = 0; k <
m_kk; k++) {
175 for (
size_t k = 0; k <
m_kk; k++) {
179 for (
size_t k = 0; k <
m_kk; k++) {
195 for (
size_t k = 0; k <
m_kk; k++) {
200 for (
size_t k = 0; k <
m_kk; k++) {
209 for (
size_t iK = 0; iK <
m_kk; iK++) {
227 if ((
int) id_.size() > 0 && phaseNode.
id() != id_) {
228 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
229 "phasenode and Id are incompatible");
234 if (!phaseNode.
hasChild(
"thermo")) {
235 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
236 "no thermo XML node");
239 if (!ba::iequals(thermoNode[
"model"],
"redlich-kister")) {
240 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
241 "Unknown thermo model: " + thermoNode[
"model"]
242 +
" - This object only knows \"Redlich-Kister\" ");
247 if (thermoNode.
hasChild(
"activityCoefficients")) {
249 if (!ba::iequals(acNode[
"model"],
"redlich-kister")) {
250 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
251 "Unknown activity coefficient model: " + acNode[
"model"]);
253 for (
size_t i = 0; i < acNode.
nChildren(); i++) {
259 if (ba::iequals(xmlACChild.
name(),
"binaryneutralspeciesparameters")) {
282 doublereal deltaX = XA - XB;
286 doublereal poly = 1.0;
287 doublereal polyMm1 = 1.0;
288 doublereal sum = 0.0;
289 doublereal sumMm1 = 0.0;
290 doublereal sum2 = 0.0;
291 for (
size_t m = 0; m < N; m++) {
292 doublereal A_ge = (he_vec[m] - T * se_vec[m]) / (
GasConstant * T);
294 sum2 += A_ge * (m + 1) * poly;
297 sumMm1 += (A_ge * polyMm1 * m);
301 doublereal oneMXA = 1.0 - XA;
302 doublereal oneMXB = 1.0 - XB;
303 for (
size_t k = 0; k <
m_kk; k++) {
306 }
else if (iB == k) {
326 doublereal deltaX = XA - XB;
328 doublereal poly = 1.0;
329 doublereal sum = 0.0;
331 doublereal sumMm1 = 0.0;
332 doublereal polyMm1 = 1.0;
333 doublereal sum2 = 0.0;
334 for (
size_t m = 0; m < N; m++) {
335 doublereal A_ge = - se_vec[m];
337 sum2 += A_ge * (m + 1) * poly;
340 sumMm1 += (A_ge * polyMm1 * m);
344 doublereal oneMXA = 1.0 - XA;
345 doublereal oneMXB = 1.0 - XB;
346 for (
size_t k = 0; k <
m_kk; k++) {
349 }
else if (iB == k) {
361 for (
size_t k = 0; k <
m_kk; k++) {
369 for (
size_t k = 0; k <
m_kk; k++) {
384 double deltaX = XA - XB;
391 double polyMm1 = 1.0;
392 double polyMm2 = 1.0;
394 for (
size_t m = 0; m < N; m++) {
395 double A_ge = (he_vec[m] - T * se_vec[m]) / (
GasConstant * T);;
399 sumMm1 += (A_ge * polyMm1 * m);
403 sumMm2 += (A_ge * polyMm2 * m * (m - 1.0));
408 for (
size_t k = 0; k <
m_kk; k++) {
411 XA * (- (1-XA+XB) * sum + 2*(1.0 - XA) * XB * sumMm1
412 + sumMm1 * (XB * (1 - 2*XA + XB) - XA * (1 - XA + 2*XB))
413 + 2 * XA * XB * sumMm2 * (1.0 - XA + XB));
414 }
else if (iB == k) {
416 XB * (- (1-XB+XA) * sum - 2*(1.0 - XB) * XA * sumMm1
417 + sumMm1 * (XA * (2*XB - XA - 1) - XB * (-2*XA + XB - 1))
418 - 2 * XA * XB * sumMm2 * (-XA - 1 + XB));
434 doublereal deltaX = XA - XB;
436 doublereal poly = 1.0;
437 doublereal sum = 0.0;
440 doublereal sumMm1 = 0.0;
441 doublereal polyMm1 = 1.0;
442 doublereal polyMm2 = 1.0;
443 doublereal sum2 = 0.0;
444 doublereal sum2Mm1 = 0.0;
445 doublereal sumMm2 = 0.0;
446 for (
size_t m = 0; m < N; m++) {
447 doublereal A_ge = he_vec[m] - T * se_vec[m];
449 sum2 += A_ge * (m + 1) * poly;
452 sumMm1 += (A_ge * polyMm1 * m);
453 sum2Mm1 += (A_ge * polyMm1 * m * (1.0 + m));
457 sumMm2 += (A_ge * polyMm2 * m * (m - 1.0));
462 for (
size_t k = 0; k <
m_kk; k++) {
465 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
466 + XA * XB * sumMm2 * (1.0 - XA + XB));
469 + XA * sumMm1 * (1.0 + 2.0 * XB - XA)
470 - XA * XB * sumMm2 * (1.0 - XA + XB));
471 }
else if (iB == k) {
473 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
474 + XA * XB * sumMm2 * (1.0 - XA + XB));
477 + XA * sumMm1 * (XB - XA - (1.0 - XB))
478 - XA * XB * sumMm2 * (-XA - (1.0 - XB)));
488 doublereal* dlnActCoeffds)
const 492 for (
size_t k = 0; k <
m_kk; k++) {
494 for (
size_t j = 0; j <
m_kk; j++) {
503 for (
size_t j = 0; j <
m_kk; j++) {
505 for (
size_t k = 0; k <
m_kk; k++) {
514 for (
size_t k = 0; k <
m_kk; k++) {
523 for (
size_t k = 0; k <
m_kk; k++) {
524 for (
size_t m = 0; m <
m_kk; m++) {
525 dlnActCoeffdlnN[ld * k + m] = data[
m_kk * k + m];
543 std::string xname = xmLBinarySpecies.
name();
544 if (xname !=
"binaryNeutralSpeciesParameters") {
545 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
546 "Incorrect name for processing this routine: " + xname);
550 std::string iName = xmLBinarySpecies.
attrib(
"speciesA");
552 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"no speciesA attrib");
554 std::string jName = xmLBinarySpecies.
attrib(
"speciesB");
556 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"no speciesB attrib");
563 if (iSpecies ==
npos) {
567 if (
charge(iSpecies) != 0) {
568 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"speciesA charge problem");
571 if (jSpecies ==
npos) {
575 if (
charge(jSpecies) != 0) {
576 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"speciesB charge problem");
587 for (
size_t iChild = 0; iChild < xmLBinarySpecies.
nChildren(); iChild++) {
589 string nodeName = ba::to_lower_copy(xmlChild.
name());
592 if (nodeName ==
"excessenthalpy") {
594 getFloatArray(xmlChild, hParams,
true,
"toSI",
"excessEnthalpy");
595 Npoly = std::max(hParams.size(), Npoly);
598 if (nodeName ==
"excessentropy") {
600 getFloatArray(xmlChild, sParams,
true,
"toSI",
"excessEntropy");
601 Npoly = std::max(sParams.size(), Npoly);
604 hParams.resize(Npoly, 0.0);
605 sParams.resize(Npoly, 0.0);
615 "To be removed after Cantera 2.3.");
627 if (XA >= (1.0 - 1.0E-14)) {
634 double fac = 2.0 * XA - 1.0;
635 if (fabs(fac) < 1.0E-13) {
638 double polykp1 = fac;
639 double poly1mk = fac;
641 for (
size_t m = 0; m < N; m++) {
642 doublereal A_ge = he_vec[m] - T * se_vec[m];
643 Volts += A_ge * (polykp1 - (2.0 * XA * m * (1.0-XA)) / poly1mk);
650 double termp =
GasConstant * T * log((1.0 - XA)/XA) / Faraday;
652 voltsOut = Volts + termp;
size_t getFloatArray(const XML_Node &node, vector_fp &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...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
std::string name() const
Returns the name of the XML node.
virtual void initThermo()
vector_fp dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
doublereal temperature() const
Temperature (K).
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the array, and fill the new entries with 'v'.
virtual void getdlnActCoeffdT(doublereal *dlnActCoeffdT) const
Get the array of temperature derivatives of the log activity coefficients.
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
RedlichKisterVPSSTP is a derived class of GibbsExcessVPSSTP that employs the Redlich-Kister approxima...
const size_t npos
index returned by functions to indicate "no position"
size_t numBinaryInteractions_
number of binary interaction expressions
virtual void getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar entropies for the species in the mixture.
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.
Class XML_Node is a tree-based representation of the contents of an XML file.
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
int formTempModel_
form of the temperature dependence of the Redlich-Kister interaction expression.
Array2D dlnActCoeff_dX_
Two dimensional array of derivatives of activity coefficients wrt mole fractions. ...
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
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.
virtual void getLnActivityCoefficients(doublereal *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
virtual void initThermo()
virtual void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of log species mole number derivatives of the log activity coefficients.
vector_fp d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
std::string speciesName(size_t k) const
Name of the species with index k.
void s_update_dlnActCoeff_dX_() const
Internal routine that calculates the derivative of the activity coefficients wrt the mole fractions...
virtual void getd2lnActCoeffdT2(doublereal *d2lnActCoeffdT2) const
Get the array of temperature second derivatives of the log activity coefficients. ...
void s_update_dlnActCoeff_dT() const
Update the derivative of the log of the activity coefficients wrt T.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
std::vector< size_t > m_pSpecies_B_ij
vector of species indices representing species B in the interaction
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Base class for exceptions thrown by Cantera classes.
void readXMLBinarySpecies(XML_Node &xmlBinarySpecies)
Process an XML node called "binaryNeutralSpeciesParameters".
virtual void getdlnActCoeffds(const doublereal dTds, const doublereal *const dXds, doublereal *dlnActCoeffds) const
Get the change in activity coefficients wrt changes in state (temp, mole fraction, etc) along a line in parameter space or along a line in physical space.
virtual void getdlnActCoeffdlnX_diag(doublereal *dlnActCoeffdlnX_diag) const
Get the array of ln mole fraction derivatives of the log activity coefficients - diagonal component o...
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
vector_fp lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the species.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
RedlichKisterVPSSTP()
Constructor.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
const doublereal SmallNumber
smallest number to compare to zero.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
void initLengths()
Initialize lengths of local variables after all species have been identified.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
std::string id() const
Return the id attribute, if present.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
Contains declarations for string manipulation functions within Cantera.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies for the species in the mixture.
vector_fp moleFractions_
Storage for the current values of the mole fractions of the species.
virtual void getdlnActCoeffdlnN(const size_t ld, doublereal *const dlnActCoeffdlnN)
Get the array of derivatives of the log activity coefficients with respect to the log of the species ...
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.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
void s_update_dlnActCoeff_dlnX_diag() const
Internal routine that calculates the total derivative of the activity coefficients with respect to th...
void zero()
Set all of the entries to zero.
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
void s_update_lnActCoeff() const
Update the activity coefficients.
Namespace for the Cantera kernel.
(see Thermodynamic Properties and class RedlichKisterVPSSTP).
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
size_t nChildren(bool discardComments=false) const
Return the number of children.
void resizeNumInteractions(const size_t num)
Resize internal arrays within the object that depend upon the number of binary Redlich-Kister interac...
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution...
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...
vector_fp dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.