21 MargulesVPSSTP::MargulesVPSSTP() :
22 numBinaryInteractions_(0),
28 MargulesVPSSTP::MargulesVPSSTP(
const std::string& inputFile,
const std::string& id_) :
29 numBinaryInteractions_(0),
36 MargulesVPSSTP::MargulesVPSSTP(
XML_Node& phaseRoot,
const std::string& id_) :
37 numBinaryInteractions_(0),
46 MargulesVPSSTP::operator=(b);
49 MargulesVPSSTP& MargulesVPSSTP::operator=(
const MargulesVPSSTP& b)
55 GibbsExcessVPSSTP::operator=(b);
91 for (
size_t k = 0; k <
m_kk; k++) {
106 for (
size_t k = 0; k <
m_kk; k++) {
118 for (
size_t i = 0; i < kk; i++) {
130 for (
size_t i = 0; i < kk; i++) {
142 for (
size_t i = 0; i < kk; i++) {
159 for (
size_t k = 0; k <
m_kk; k++) {
167 for (
size_t k = 0; k <
m_kk; k++) {
183 for (
size_t k = 0; k <
m_kk; k++) {
187 for (
size_t k = 0; k <
m_kk; k++) {
203 for (
size_t k = 0; k <
m_kk; k++) {
209 for (
size_t k = 0; k <
m_kk; k++) {
228 const doublereal temp1 = g0 + g1 * XB;
229 const doublereal all = -1.0*XA*XB*temp1 - XA*XB*XB*g1;
231 for (
size_t iK = 0; iK <
m_kk; iK++) {
234 vbar[iA] += XB * temp1;
235 vbar[iB] += XA * temp1 + XA*XB*g1;
252 if ((
int) id_.size() > 0) {
253 string idp = phaseNode.
id();
255 throw CanteraError(
"MargulesVPSSTP::initThermoXML",
"phasenode and Id are incompatible");
260 if (!phaseNode.
hasChild(
"thermo")) {
262 "no thermo XML node");
267 if (!ba::iequals(thermoNode[
"model"],
"margules")) {
269 "model name isn't Margules: " + thermoNode[
"model"]);
274 if (thermoNode.
hasChild(
"activityCoefficients")) {
276 if (!ba::iequals(acNode[
"model"],
"margules")) {
278 "Unknown activity coefficient model: " + acNode[
"model"]);
280 for (
size_t i = 0; i < acNode.
nChildren(); i++) {
286 if (ba::iequals(xmlACChild.
name(),
"binaryneutralspeciesparameters")) {
307 const doublereal XAXB = XA * XB;
308 const doublereal g0g1XB = (g0 + g1 * XB);
309 const doublereal all = -1.0 * XAXB * g0g1XB - XAXB * XB * g1;
310 for (
size_t iK = 0; iK <
m_kk; iK++) {
331 const doublereal XAXB = XA * XB;
332 const doublereal g0g1XB = (g0 + g1 * XB);
333 const doublereal all = -1.0 * XAXB * g0g1XB - XAXB * XB * g1;
334 const doublereal mult = 2.0 * invT;
335 const doublereal dT2all = mult * all;
336 for (
size_t iK = 0; iK <
m_kk; iK++) {
350 for (
size_t k = 0; k <
m_kk; k++) {
358 for (
size_t k = 0; k <
m_kk; k++) {
364 doublereal* dlnActCoeffds)
const 368 for (
size_t iK = 0; iK <
m_kk; iK++) {
369 dlnActCoeffds[iK] = 0.0;
377 double dXA = dXds[iA];
378 double dXB = dXds[iB];
381 const doublereal g02g1XB = g0 + 2*g1*XB;
382 const doublereal g2XAdXB = 2*g1*XA*dXB;
383 const doublereal all = (-XB * dXA - XA *dXB) * g02g1XB - XB *g2XAdXB;
384 for (
size_t iK = 0; iK <
m_kk; iK++) {
387 dlnActCoeffds[iA] += dXB * g02g1XB;
388 dlnActCoeffds[iB] += dXA * g02g1XB + g2XAdXB;
397 for (
size_t iK = 0; iK <
m_kk; iK++) {
430 for (
size_t iK = 0; iK <
m_kk; iK++) {
431 for (
size_t iM = 0; iM <
m_kk; iM++) {
455 dlnActCoeffdlnN_(iK,iM) += g0*((delAM-XA)*(delBK-XB)+(delAK-XA)*(delBM-XB));
456 dlnActCoeffdlnN_(iK,iM) += 2*g1*((delAM-XA)*(delBK-XB)*XB+(delAK-XA)*(delBM-XB)*XB+(delBM-XB)*(delBK-XB)*XA);
486 for (
size_t k = 0; k <
m_kk; k++) {
494 for (
size_t k = 0; k <
m_kk; k++) {
503 for (
size_t k = 0; k <
m_kk; k++) {
504 for (
size_t m = 0; m <
m_kk; m++) {
505 dlnActCoeffdlnN[ld * k + m] = data[
m_kk * k + m];
532 string xname = xmLBinarySpecies.
name();
533 if (xname !=
"binaryNeutralSpeciesParameters") {
534 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
535 "Incorrect name for processing this routine: " + xname);
538 string aName = xmLBinarySpecies.
attrib(
"speciesA");
540 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
"no speciesA attrib");
542 string bName = xmLBinarySpecies.
attrib(
"speciesB");
544 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
"no speciesB attrib");
551 if (aSpecies ==
npos) {
558 if (
charge(aSpecies) != 0.0) {
559 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
560 "speciesA has a charge: {}",
charge(aSpecies));
563 if (bSpecies ==
npos) {
567 if (
charge(bSpecies) != 0.0) {
568 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
569 "speciesB has a charge: {}",
charge(bSpecies));
577 for (
size_t iChild = 0; iChild < xmLBinarySpecies.
nChildren(); iChild++) {
579 string nodeName = ba::to_lower_copy(xmlChild.
name());
589 if (nodeName ==
"excessenthalpy") {
591 getFloatArray(xmlChild, vParams,
true,
"toSI",
"excessEnthalpy");
592 if (vParams.size() != 2) {
593 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies::excessEnthalpy for " + aspName
595 "wrong number of params found. Need 2");
601 if (nodeName ==
"excessentropy") {
603 getFloatArray(xmlChild, vParams,
true,
"toSI",
"excessEntropy");
604 if (vParams.size() != 2) {
605 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies::excessEntropy for " + aspName
607 "wrong number of params found. Need 2");
613 if (nodeName ==
"excessvolume_enthalpy") {
615 getFloatArray(xmlChild, vParams,
true,
"toSI",
"excessVolume_Enthalpy");
616 if (vParams.size() != 2) {
617 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies::excessVolume_Enthalpy for " + aspName
619 "wrong number of params found. Need 2");
625 if (nodeName ==
"excessvolume_entropy") {
627 getFloatArray(xmlChild, vParams,
true,
"toSI",
"excessVolume_Entropy");
628 if (vParams.size() != 2) {
629 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies::excessVolume_Entropy for " + aspName
631 "wrong number of params found. Need 2");
int formMargules_
form of the Margules interaction expression
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
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...
vector_fp m_VSE_c_ij
Entropy term for the ternary mole fraction interaction of the excess Gibbs free energy expression...
virtual void getLnActivityCoefficients(doublereal *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
void readXMLBinarySpecies(XML_Node &xmlBinarySpecies)
Process an XML node called "binaryNeutralSpeciesParameters".
vector_fp m_VSE_d_ij
Entropy term for the quaternary mole fraction interaction of the excess Gibbs free energy expression...
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.
vector_fp m_HE_b_ij
Enthalpy term for the binary mole fraction interaction of the excess Gibbs free energy expression...
vector_fp m_VHE_d_ij
Enthalpy term for the quaternary mole fraction interaction of the excess Gibbs free energy expression...
(see Thermodynamic Properties and class MargulesVPSSTP).
vector_fp dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
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 speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
const size_t npos
index returned by functions to indicate "no position"
std::vector< size_t > m_pSpecies_A_ij
vector of species indices representing species A in the interaction
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
vector_fp m_HE_d_ij
Enthalpy term for the quaternary 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...
size_t nSpecies() const
Returns the number of species in the phase.
virtual void getdlnActCoeffdlnX_diag(doublereal *dlnActCoeffdlnX_diag) const
Get the array of ln mole fraction derivatives of the log activity coefficients - diagonal component o...
virtual void initThermo()
size_t numBinaryInteractions_
number of binary interaction expressions
virtual void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of log species mole number derivatives of the log activity coefficients.
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 ...
void s_update_dlnActCoeff_dlnX_diag() const
Update the derivative of the log of the activity coefficients wrt log(mole fraction) ...
void resizeNumInteractions(const size_t num)
Resize internal arrays within the object that depend upon the number of binary Margules interaction t...
void initLengths()
Initialize lengths of local variables after all species have been identified.
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
void s_update_dlnActCoeff_dT() const
Update the derivative of the log of the activity coefficients wrt T.
Base class for a phase with thermodynamic properties.
vector_fp m_SE_d_ij
Entropy term for the quaternary mole fraction interaction of the excess Gibbs free energy expression...
virtual void getd2lnActCoeffdT2(doublereal *d2lnActCoeffdT2) const
Get the array of temperature second derivatives of the log activity coefficients. ...
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
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 initThermo()
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
vector_fp dlnActCoeffdlnN_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies for the species in the mixture.
vector_fp d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
vector_fp m_SE_b_ij
Entropy term for the binary mole fraction interaction of the excess Gibbs free energy expression...
std::string speciesName(size_t k) const
Name of the species with index k.
void s_update_dlnActCoeff_dlnN_diag() const
Update the derivative of the log of the activity coefficients wrt log(moles) - diagonal only...
void s_update_lnActCoeff() const
Update the activity coefficients.
void s_update_dlnActCoeff_dlnN() const
Update the derivative of the log of the activity coefficients wrt log(moles_m)
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.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
vector_fp m_VHE_b_ij
Enthalpy term for the binary mole fraction interaction of the excess Gibbs free energy expression...
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.
vector_fp m_VSE_b_ij
Entropy term for the binary mole fraction interaction of the excess Gibbs free energy expression...
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.
std::vector< size_t > m_pSpecies_B_ij
vector of species indices representing species B in the interaction
vector_fp m_VHE_c_ij
Enthalpy term for the ternary mole fraction interaction of the excess Gibbs free energy expression...
const doublereal SmallNumber
smallest number to compare to zero.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
virtual void getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar entropies for the species in the mixture.
virtual void getdlnActCoeffdT(doublereal *dlnActCoeffdT) const
Get the array of temperature derivatives of the log activity coefficients.
std::string id() const
Return the id attribute, if present.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
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.
vector_fp m_SE_c_ij
Entropy term for the ternary mole fraction interaction of the excess Gibbs free energy expression...
MargulesVPSSTP is a derived class of GibbsExcessVPSSTP that employs the Margules approximation for th...
vector_fp moleFractions_
Storage for the current values of the mole fractions of the species.
vector_fp m_HE_c_ij
Enthalpy term for the ternary mole fraction interaction of the excess Gibbs free energy expression...
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
int formTempModel_
form of the temperature dependence of the Margules interaction expression
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
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 zero()
Set all of the entries to zero.
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
Namespace for the Cantera kernel.
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...
vector_fp dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.