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),
53 for (
size_t k = 0; k <
m_kk; k++) {
68 for (
size_t k = 0; k <
m_kk; k++) {
79 for (
size_t i = 0; i <
m_kk; i++) {
90 for (
size_t i = 0; i <
m_kk; i++) {
101 for (
size_t i = 0; i <
m_kk; i++) {
118 for (
size_t k = 0; k <
m_kk; k++) {
126 for (
size_t k = 0; k <
m_kk; k++) {
141 for (
size_t k = 0; k <
m_kk; k++) {
145 for (
size_t k = 0; k <
m_kk; k++) {
161 for (
size_t k = 0; k <
m_kk; k++) {
166 for (
size_t k = 0; k <
m_kk; k++) {
175 for (
size_t iK = 0; iK <
m_kk; iK++) {
193 if ((
int) id_.size() > 0 && phaseNode.
id() != id_) {
194 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
195 "phasenode and Id are incompatible");
200 if (!phaseNode.
hasChild(
"thermo")) {
201 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
202 "no thermo XML node");
206 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
207 "Unknown thermo model: " + thermoNode[
"model"]
208 +
" - This object only knows \"Redlich-Kister\" ");
213 if (thermoNode.
hasChild(
"activityCoefficients")) {
216 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
217 "Unknown activity coefficient model: " + acNode[
"model"]);
219 for (
size_t i = 0; i < acNode.
nChildren(); i++) {
248 doublereal deltaX = XA - XB;
252 doublereal poly = 1.0;
253 doublereal polyMm1 = 1.0;
254 doublereal sum = 0.0;
255 doublereal sumMm1 = 0.0;
256 doublereal sum2 = 0.0;
257 for (
size_t m = 0; m < N; m++) {
258 doublereal A_ge = (he_vec[m] - T * se_vec[m]) / (
GasConstant * T);
260 sum2 += A_ge * (m + 1) * poly;
263 sumMm1 += (A_ge * polyMm1 * m);
267 doublereal oneMXA = 1.0 - XA;
268 doublereal oneMXB = 1.0 - XB;
269 for (
size_t k = 0; k <
m_kk; k++) {
272 }
else if (iB == k) {
292 doublereal deltaX = XA - XB;
294 doublereal poly = 1.0;
295 doublereal sum = 0.0;
297 doublereal sumMm1 = 0.0;
298 doublereal polyMm1 = 1.0;
299 doublereal sum2 = 0.0;
300 for (
size_t m = 0; m < N; m++) {
301 doublereal A_ge = - se_vec[m];
303 sum2 += A_ge * (m + 1) * poly;
306 sumMm1 += (A_ge * polyMm1 * m);
310 doublereal oneMXA = 1.0 - XA;
311 doublereal oneMXB = 1.0 - XB;
312 for (
size_t k = 0; k <
m_kk; k++) {
315 }
else if (iB == k) {
327 for (
size_t k = 0; k <
m_kk; k++) {
335 for (
size_t k = 0; k <
m_kk; k++) {
350 double deltaX = XA - XB;
357 double polyMm1 = 1.0;
358 double polyMm2 = 1.0;
360 for (
size_t m = 0; m < N; m++) {
361 double A_ge = (he_vec[m] - T * se_vec[m]) / (
GasConstant * T);;
365 sumMm1 += (A_ge * polyMm1 * m);
369 sumMm2 += (A_ge * polyMm2 * m * (m - 1.0));
374 for (
size_t k = 0; k <
m_kk; k++) {
377 XA * (- (1-XA+XB) * sum + 2*(1.0 - XA) * XB * sumMm1
378 + sumMm1 * (XB * (1 - 2*XA + XB) - XA * (1 - XA + 2*XB))
379 + 2 * XA * XB * sumMm2 * (1.0 - XA + XB));
380 }
else if (iB == k) {
382 XB * (- (1-XB+XA) * sum - 2*(1.0 - XB) * XA * sumMm1
383 + sumMm1 * (XA * (2*XB - XA - 1) - XB * (-2*XA + XB - 1))
384 - 2 * XA * XB * sumMm2 * (-XA - 1 + XB));
400 doublereal deltaX = XA - XB;
402 doublereal poly = 1.0;
403 doublereal sum = 0.0;
406 doublereal sumMm1 = 0.0;
407 doublereal polyMm1 = 1.0;
408 doublereal polyMm2 = 1.0;
409 doublereal sum2 = 0.0;
410 doublereal sum2Mm1 = 0.0;
411 doublereal sumMm2 = 0.0;
412 for (
size_t m = 0; m < N; m++) {
413 doublereal A_ge = he_vec[m] - T * se_vec[m];
415 sum2 += A_ge * (m + 1) * poly;
418 sumMm1 += (A_ge * polyMm1 * m);
419 sum2Mm1 += (A_ge * polyMm1 * m * (1.0 + m));
423 sumMm2 += (A_ge * polyMm2 * m * (m - 1.0));
428 for (
size_t k = 0; k <
m_kk; k++) {
431 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
432 + XA * XB * sumMm2 * (1.0 - XA + XB));
435 + XA * sumMm1 * (1.0 + 2.0 * XB - XA)
436 - XA * XB * sumMm2 * (1.0 - XA + XB));
437 }
else if (iB == k) {
439 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
440 + XA * XB * sumMm2 * (1.0 - XA + XB));
443 + XA * sumMm1 * (XB - XA - (1.0 - XB))
444 - XA * XB * sumMm2 * (-XA - (1.0 - XB)));
454 doublereal* dlnActCoeffds)
const 458 for (
size_t k = 0; k <
m_kk; k++) {
460 for (
size_t j = 0; j <
m_kk; j++) {
469 for (
size_t j = 0; j <
m_kk; j++) {
471 for (
size_t k = 0; k <
m_kk; k++) {
480 for (
size_t k = 0; k <
m_kk; k++) {
489 for (
size_t k = 0; k <
m_kk; k++) {
490 for (
size_t m = 0; m <
m_kk; m++) {
491 dlnActCoeffdlnN[ld * k + m] = data[
m_kk * k + m];
498 std::string xname = xmLBinarySpecies.
name();
499 if (xname !=
"binaryNeutralSpeciesParameters") {
500 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
501 "Incorrect name for processing this routine: " + xname);
504 std::string iName = xmLBinarySpecies.
attrib(
"speciesA");
506 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"no speciesA attrib");
508 std::string jName = xmLBinarySpecies.
attrib(
"speciesB");
510 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"no speciesB attrib");
517 if (iSpecies ==
npos) {
521 if (jSpecies ==
npos) {
526 for (
size_t iChild = 0; iChild < xmLBinarySpecies.
nChildren(); iChild++) {
531 if (nodeName ==
"excessenthalpy") {
532 getFloatArray(xmlChild, hParams,
true,
"toSI",
"excessEnthalpy");
533 }
else if (nodeName ==
"excessentropy") {
534 getFloatArray(xmlChild, sParams,
true,
"toSI",
"excessEntropy");
538 sParams.data(), sParams.size());
542 const std::string& speciesA,
const std::string& speciesB,
543 const double* excess_enthalpy,
size_t n_enthalpy,
544 const double* excess_entropy,
size_t n_entropy)
549 throw CanteraError(
"RedlichKisterVPSSTP::addBinaryInteraction",
550 "Species '{}' not present in phase", speciesA);
551 }
else if (kB ==
npos) {
552 throw CanteraError(
"RedlichKisterVPSSTP::addBinaryInteraction",
553 "Species '{}' not present in phase", speciesB);
556 throw CanteraError(
"RedlichKisterVPSSTP::addBinaryInteraction",
557 "Species '{}' should be neutral", speciesA);
558 }
else if (
charge(kB) != 0) {
559 throw CanteraError(
"RedlichKisterVPSSTP::addBinaryInteraction",
560 "Species '{}' should be neutral", speciesB);
565 m_HE_m_ij.emplace_back(excess_enthalpy, excess_enthalpy + n_enthalpy);
566 m_SE_m_ij.emplace_back(excess_entropy, excess_entropy + n_entropy);
567 size_t N = max(n_enthalpy, n_entropy);
void addBinaryInteraction(const std::string &speciesA, const std::string &speciesB, const double *excess_enthalpy, size_t n_enthalpy, const double *excess_entropy, size_t n_entropy)
Add a binary species interaction with the specified parameters.
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'.
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...
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.
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...
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...
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
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 ...
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.
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
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.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
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.
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...
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)
std::string toLowerCopy(const std::string &input)
Convert to lower case.
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.
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.