Go to the documentation of this file.
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++) {
183 for (
const auto& item :
m_input[
"interactions"].asVector<AnyMap>()) {
184 auto&
species = item[
"species"].asVector<
string>(2);
185 vector_fp h_excess = item.convertVector(
"excess-enthalpy",
"J/kmol");
186 vector_fp s_excess = item.convertVector(
"excess-entropy",
"J/kmol/K");
188 h_excess.data(), h_excess.size(),
189 s_excess.data(), s_excess.size());
203 if ((
int) id_.size() > 0 && phaseNode.
id() != id_) {
204 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
205 "phasenode and Id are incompatible");
210 if (!phaseNode.
hasChild(
"thermo")) {
211 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
212 "no thermo XML node");
216 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
217 "Unknown thermo model: " + thermoNode[
"model"]
218 +
" - This object only knows \"Redlich-Kister\" ");
223 if (thermoNode.
hasChild(
"activityCoefficients")) {
226 throw CanteraError(
"RedlichKisterVPSSTP::initThermoXML",
227 "Unknown activity coefficient model: " + acNode[
"model"]);
229 for (
size_t i = 0; i < acNode.
nChildren(); i++) {
258 doublereal deltaX = XA - XB;
262 doublereal poly = 1.0;
263 doublereal polyMm1 = 1.0;
264 doublereal sum = 0.0;
265 doublereal sumMm1 = 0.0;
266 doublereal sum2 = 0.0;
267 for (
size_t m = 0; m < N; m++) {
268 doublereal A_ge = (he_vec[m] - T * se_vec[m]) / (
GasConstant * T);
270 sum2 += A_ge * (m + 1) * poly;
273 sumMm1 += (A_ge * polyMm1 * m);
277 doublereal oneMXA = 1.0 - XA;
278 doublereal oneMXB = 1.0 - XB;
279 for (
size_t k = 0; k <
m_kk; k++) {
282 }
else if (iB == k) {
302 doublereal deltaX = XA - XB;
304 doublereal poly = 1.0;
305 doublereal sum = 0.0;
307 doublereal sumMm1 = 0.0;
308 doublereal polyMm1 = 1.0;
309 doublereal sum2 = 0.0;
310 for (
size_t m = 0; m < N; m++) {
311 doublereal A_ge = - se_vec[m];
313 sum2 += A_ge * (m + 1) * poly;
316 sumMm1 += (A_ge * polyMm1 * m);
320 doublereal oneMXA = 1.0 - XA;
321 doublereal oneMXB = 1.0 - XB;
322 for (
size_t k = 0; k <
m_kk; k++) {
325 }
else if (iB == k) {
337 for (
size_t k = 0; k <
m_kk; k++) {
345 for (
size_t k = 0; k <
m_kk; k++) {
360 double deltaX = XA - XB;
367 double polyMm1 = 1.0;
368 double polyMm2 = 1.0;
370 for (
size_t m = 0; m < N; m++) {
371 double A_ge = (he_vec[m] - T * se_vec[m]) / (
GasConstant * T);;
375 sumMm1 += (A_ge * polyMm1 * m);
379 sumMm2 += (A_ge * polyMm2 * m * (m - 1.0));
384 for (
size_t k = 0; k <
m_kk; k++) {
387 XA * (- (1-XA+XB) * sum + 2*(1.0 - XA) * XB * sumMm1
388 + sumMm1 * (XB * (1 - 2*XA + XB) - XA * (1 - XA + 2*XB))
389 + 2 * XA * XB * sumMm2 * (1.0 - XA + XB));
390 }
else if (iB == k) {
392 XB * (- (1-XB+XA) * sum - 2*(1.0 - XB) * XA * sumMm1
393 + sumMm1 * (XA * (2*XB - XA - 1) - XB * (-2*XA + XB - 1))
394 - 2 * XA * XB * sumMm2 * (-XA - 1 + XB));
410 doublereal deltaX = XA - XB;
412 doublereal poly = 1.0;
413 doublereal sum = 0.0;
416 doublereal sumMm1 = 0.0;
417 doublereal polyMm1 = 1.0;
418 doublereal polyMm2 = 1.0;
419 doublereal sum2 = 0.0;
420 doublereal sum2Mm1 = 0.0;
421 doublereal sumMm2 = 0.0;
422 for (
size_t m = 0; m < N; m++) {
423 doublereal A_ge = he_vec[m] - T * se_vec[m];
425 sum2 += A_ge * (m + 1) * poly;
428 sumMm1 += (A_ge * polyMm1 * m);
429 sum2Mm1 += (A_ge * polyMm1 * m * (1.0 + m));
433 sumMm2 += (A_ge * polyMm2 * m * (m - 1.0));
438 for (
size_t k = 0; k <
m_kk; k++) {
441 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
442 + XA * XB * sumMm2 * (1.0 - XA + XB));
445 + XA * sumMm1 * (1.0 + 2.0 * XB - XA)
446 - XA * XB * sumMm2 * (1.0 - XA + XB));
447 }
else if (iB == k) {
449 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
450 + XA * XB * sumMm2 * (1.0 - XA + XB));
453 + XA * sumMm1 * (XB - XA - (1.0 - XB))
454 - XA * XB * sumMm2 * (-XA - (1.0 - XB)));
464 doublereal* dlnActCoeffds)
const
468 for (
size_t k = 0; k <
m_kk; k++) {
470 for (
size_t j = 0; j <
m_kk; j++) {
479 for (
size_t j = 0; j <
m_kk; j++) {
481 for (
size_t k = 0; k <
m_kk; k++) {
490 for (
size_t k = 0; k <
m_kk; k++) {
499 for (
size_t k = 0; k <
m_kk; k++) {
500 for (
size_t m = 0; m <
m_kk; m++) {
501 dlnActCoeffdlnN[ld * k + m] = data[
m_kk * k + m];
508 std::string xname = xmLBinarySpecies.
name();
509 if (xname !=
"binaryNeutralSpeciesParameters") {
510 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
511 "Incorrect name for processing this routine: " + xname);
514 std::string iName = xmLBinarySpecies.
attrib(
"speciesA");
516 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"no speciesA attrib");
518 std::string jName = xmLBinarySpecies.
attrib(
"speciesB");
520 throw CanteraError(
"RedlichKisterVPSSTP::readXMLBinarySpecies",
"no speciesB attrib");
527 if (iSpecies ==
npos) {
531 if (jSpecies ==
npos) {
536 for (
size_t iChild = 0; iChild < xmLBinarySpecies.
nChildren(); iChild++) {
541 if (nodeName ==
"excessenthalpy") {
542 getFloatArray(xmlChild, hParams,
true,
"toSI",
"excessEnthalpy");
543 }
else if (nodeName ==
"excessentropy") {
544 getFloatArray(xmlChild, sParams,
true,
"toSI",
"excessEntropy");
548 sParams.data(), sParams.size());
552 const std::string& speciesA,
const std::string& speciesB,
553 const double* excess_enthalpy,
size_t n_enthalpy,
554 const double* excess_entropy,
size_t n_entropy)
559 throw CanteraError(
"RedlichKisterVPSSTP::addBinaryInteraction",
560 "Species '{}' not present in phase", speciesA);
561 }
else if (kB ==
npos) {
562 throw CanteraError(
"RedlichKisterVPSSTP::addBinaryInteraction",
563 "Species '{}' not present in phase", speciesB);
566 throw CanteraError(
"RedlichKisterVPSSTP::addBinaryInteraction",
567 "Species '{}' should be neutral", speciesA);
568 }
else if (
charge(kB) != 0) {
569 throw CanteraError(
"RedlichKisterVPSSTP::addBinaryInteraction",
570 "Species '{}' should be neutral", speciesB);
575 m_HE_m_ij.emplace_back(excess_enthalpy, excess_enthalpy + n_enthalpy);
576 m_SE_m_ij.emplace_back(excess_entropy, excess_entropy + n_entropy);
577 size_t N = max(n_enthalpy, n_entropy);
vector_fp d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
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.
std::vector< size_t > m_N_ij
Vector of the length of the polynomial for the interaction.
Array2D dlnActCoeff_dX_
Two dimensional array of derivatives of activity coefficients wrt mole fractions.
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 ...
const double SmallNumber
smallest number to compare to zero.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
virtual void getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar entropies for the species in the mixture.
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_lnActCoeff() const
Update the activity coefficients.
vector_fp lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the species.
std::string id() const
Return the id attribute, if present.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
std::vector< vector_fp > m_HE_m_ij
Enthalpy term for the binary mole fraction interaction of the excess Gibbs free energy expression.
vector_fp moleFractions_
Storage for the current values of the mole fractions of the species.
Array2D dlnActCoeffdlnN_
Storage for the current derivative values of the gradients with respect to logarithm of the species m...
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
void readXMLBinarySpecies(XML_Node &xmlBinarySpecies)
Process an XML node called "binaryNeutralSpeciesParameters".
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.
virtual void initThermo()
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the array, and fill the new entries with 'v'.
size_t m_kk
Number of species in the phase.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
void s_update_dlnActCoeff_dX_() const
Internal routine that calculates the derivative of the activity coefficients wrt the mole fractions.
AnyMap m_input
Data supplied via setParameters.
void s_update_dlnActCoeff_dT() const
Update the derivative of the log of the activity coefficients wrt T.
void initLengths()
Initialize lengths of local variables after all species have been identified.
std::vector< size_t > m_pSpecies_A_ij
vector of species indices representing species A in the interaction
std::string name() const
Returns the name of the XML node.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
virtual void getd2lnActCoeffdT2(doublereal *d2lnActCoeffdT2) const
Get the array of temperature second derivatives of the log activity coefficients.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
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,...
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies for the species in the mixture.
vector_fp dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
size_t nChildren(bool discardComments=false) const
Return the number of children.
virtual void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of log species mole number 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.
Class XML_Node is a tree-based representation of the contents of an XML file.
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
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).
virtual void initThermo()
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
void zero()
Set all of the entries to zero.
void s_update_dlnActCoeff_dlnX_diag() const
Internal routine that calculates the total derivative of the activity coefficients with respect to th...
RedlichKisterVPSSTP()
Constructor.
std::vector< size_t > m_pSpecies_B_ij
vector of species indices representing species B in the interaction
const double GasConstant
Universal Gas Constant [J/kmol/K].
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::string toLowerCopy(const std::string &input)
Convert to lower case.
std::vector< vector_fp > m_SE_m_ij
Entropy term for the binary mole fraction interaction of the excess Gibbs free energy expression.
Base class for exceptions thrown by Cantera classes.
virtual void getdlnActCoeffdT(doublereal *dlnActCoeffdT) const
Get the array of temperature derivatives of the log activity coefficients.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
const size_t npos
index returned by functions to indicate "no position"
size_t numBinaryInteractions_
number of binary interaction expressions
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Namespace for the Cantera kernel.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
virtual void getdlnActCoeffdlnX_diag(doublereal *dlnActCoeffdlnX_diag) const
Get the array of ln mole fraction derivatives of the log activity coefficients - diagonal component o...
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,...
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.