24 MargulesVPSSTP::MargulesVPSSTP() :
26 numBinaryInteractions_(0),
34 numBinaryInteractions_(0),
43 numBinaryInteractions_(0),
94 numBinaryInteractions_(0),
137 "Unable to find LiCl(L)");
145 "Unable to find KCl(L)");
173 for (
size_t k = 0; k <
m_kk; k++) {
186 for (
size_t k = 0; k <
m_kk; k++) {
206 for (
size_t k = 0; k <
m_kk; k++) {
218 for (
size_t i = 0; i < kk; i++) {
230 for (
size_t i = 0; i < kk; i++) {
242 for (
size_t i = 0; i < kk; i++) {
264 for (
size_t k = 0; k <
m_kk; k++) {
274 for (
size_t k = 0; k <
m_kk; k++) {
293 for (
size_t k = 0; k <
m_kk; k++) {
299 for (
size_t k = 0; k <
m_kk; k++) {
319 for (
size_t k = 0; k <
m_kk; k++) {
326 for (
size_t k = 0; k <
m_kk; k++) {
331 void MargulesVPSSTP::getPartialMolarVolumes(doublereal* vbar)
const
334 size_t iA, iB, delAK, delBK;
335 double XA, XB, g0 , g1;
343 for (
size_t iK = 0; iK <
m_kk; iK++) {
354 const doublereal temp1 = g0 + g1 * XB;
355 const doublereal all = -1.0*XA*XB*temp1 - XA*XB*XB*g1;
357 for (
size_t iK = 0; iK <
m_kk; iK++) {
361 vbar[iA] += XB * temp1;
362 vbar[iB] += XA * temp1 + XA*XB*g1;
368 throw CanteraError(
"MargulesVPSSTP",
"Base class method "
388 string subname =
"MargulesVPSSTP::initThermoXML";
389 if ((
int) id_.size() > 0) {
390 string idp = phaseNode.
id();
392 throw CanteraError(subname,
"phasenode and Id are incompatible");
399 if (!phaseNode.
hasChild(
"thermo")) {
401 "no thermo XML node");
408 stemp = thermoNode.
attrib(
"model");
410 if (formString !=
"margules") {
412 "model name isn't Margules: " + formString);
421 if (thermoNode.
hasChild(
"activityCoefficients")) {
424 string mStringa = acNode.
attrib(
"model");
426 if (mString !=
"margules") {
428 "Unknown activity coefficient model: " + mStringa);
430 for (
size_t i = 0; i < acNodePtr->
nChildren(); i++) {
432 stemp = xmlACChild.
name();
439 if (nodeName ==
"binaryneutralspeciesparameters") {
457 double XA, XB, g0 , g1;
461 for (iK = 0; iK <
m_kk; iK++) {
471 const doublereal XAXB = XA * XB;
472 const doublereal g0g1XB = (g0 + g1 * XB);
473 const doublereal all = -1.0 * XAXB * g0g1XB - XAXB * XB * g1;
474 for (iK = 0; iK <
m_kk; iK++) {
485 doublereal XA, XB, g0, g1;
490 for (iK = 0; iK <
m_kk; iK++) {
501 const doublereal XAXB = XA * XB;
502 const doublereal g0g1XB = (g0 + g1 * XB);
503 const doublereal all = -1.0 * XAXB * g0g1XB - XAXB * XB * g1;
504 const doublereal mult = 2.0 * invT;
505 const doublereal dT2all = mult * all;
506 for (iK = 0; iK <
m_kk; iK++) {
521 for (
size_t k = 0; k <
m_kk; k++) {
529 for (
size_t k = 0; k <
m_kk; k++) {
535 doublereal* dlnActCoeffds)
const
538 double XA, XB, g0 , g1, dXA, dXB;
545 for (iK = 0; iK <
m_kk; iK++) {
546 dlnActCoeffds[iK] = 0.0;
558 const doublereal g02g1XB = g0 + 2*g1*XB;
559 const doublereal g2XAdXB = 2*g1*XA*dXB;
560 const doublereal all = (-XB * dXA - XA *dXB) * g02g1XB - XB *g2XAdXB;
561 for (iK = 0; iK <
m_kk; iK++) {
566 dlnActCoeffds[iA] += dXB * g02g1XB;
567 dlnActCoeffds[iB] += dXA * g02g1XB + g2XAdXB;
573 size_t iA, iB, iK, delAK, delBK;
574 double XA, XB, XK, g0 , g1;
580 for (iK = 0; iK <
m_kk; iK++) {
629 doublereal delAK, delBK;
630 double XA, XB, g0, g1,XM;
634 doublereal delAM, delBM;
641 for (
size_t iK = 0; iK <
m_kk; iK++) {
642 for (
size_t iM = 0; iM <
m_kk; iM++) {
670 dlnActCoeffdlnN_(iK,iM) += g0*((delAM-XA)*(delBK-XB)+(delAK-XA)*(delBM-XB));
671 dlnActCoeffdlnN_(iK,iM) += 2*g1*((delAM-XA)*(delBK-XB)*XB+(delAK-XA)*(delBM-XB)*XB+(delBM-XB)*(delBK-XB)*XA);
718 for (
size_t k = 0; k <
m_kk; k++) {
726 for (
size_t k = 0; k <
m_kk; k++) {
735 for (
size_t k = 0; k <
m_kk; k++) {
736 for (
size_t m = 0; m <
m_kk; m++) {
737 dlnActCoeffdlnN[ld * k + m] = data[m_kk * k + m];
764 string xname = xmLBinarySpecies.
name();
765 if (xname !=
"binaryNeutralSpeciesParameters") {
766 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
767 "Incorrect name for processing this routine: " + xname);
772 string iName = xmLBinarySpecies.
attrib(
"speciesA");
774 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
"no speciesA attrib");
776 string jName = xmLBinarySpecies.
attrib(
"speciesB");
778 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
"no speciesB attrib");
785 if (iSpecies ==
npos) {
789 if (
charge(iSpecies) != 0) {
790 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
"speciesA charge problem");
793 if (jSpecies ==
npos) {
797 if (
charge(jSpecies) != 0) {
798 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
"speciesB charge problem");
806 for (
size_t iChild = 0; iChild < xmLBinarySpecies.
nChildren(); iChild++) {
808 stemp = xmlChild.
name();
813 if (nodeName ==
"excessenthalpy") {
818 nParamsFound = vParams.size();
820 if (nParamsFound != 2) {
821 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies::excessEnthalpy for " + ispName
823 "wrong number of params found. Need 2");
829 if (nodeName ==
"excessentropy") {
834 nParamsFound = vParams.size();
836 if (nParamsFound != 2) {
837 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies::excessEntropy for " + ispName
839 "wrong number of params found. Need 2");
845 if (nodeName ==
"excessvolume_enthalpy") {
850 nParamsFound = vParams.size();
852 if (nParamsFound != 2) {
853 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies::excessVolume_Enthalpy for " + ispName
855 "wrong number of params found. Need 2");
861 if (nodeName ==
"excessvolume_entropy") {
866 nParamsFound = vParams.size();
868 if (nParamsFound != 2) {
869 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies::excessVolume_Entropy for " + ispName
871 "wrong number of params found. Need 2");
int formMargules_
form of the Margules interaction expression
vector_fp m_VSE_c_ij
Entropy term for the ternary mole fraction interaction of the excess gibbs free energy expression...
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
void readXMLBinarySpecies(XML_Node &xmlBinarySpecies)
Process an XML node called "binaryNeutralSpeciesParameters".
doublereal electricPotential() const
Returns the electric potential of this phase (V).
vector_fp m_VSE_d_ij
Entropy term for the quaternary mole fraction interaction of the excess gibbs free energy expression...
vector_fp m_HE_b_ij
Enthalpy term for the binary mole fraction interaction of the excess gibbs free energy expression...
XML_Node * findXMLPhase(XML_Node *root, const std::string &idtarget)
Search an XML_Node tree for a named phase XML_Node.
vector_fp m_VHE_d_ij
Enthalpy term for the quaternary mole fraction interaction of the excess gibbs free energy expression...
Header for intermediate ThermoPhase object for phases which employ gibbs excess free energy based for...
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'.
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol.
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...
void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object.
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
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...
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 getd2lnActCoeffdT2(doublereal *d2lnActCoeffdT2) const
Get the array of temperature second derivatives of the log activity coefficients. ...
virtual void initThermo()
size_t numBinaryInteractions_
number of binary interaction expressions
std::string lowercase(const std::string &s)
Cast a copy of a string to lower case.
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...
std::vector< doublereal > d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
virtual void getdlnActCoeffdT(doublereal *dlnActCoeffdT) const
Get the array of temperature derivatives of the log activity coefficients.
std::vector< doublereal > dlnActCoeffdlnN_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
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.
virtual void getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar entropies for the species in the mixture.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
virtual void getdlnActCoeffds(const doublereal dTds, const doublereal *const dXds, doublereal *dlnActCoeffds) const
Get the change in activity coefficients w.r.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...
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.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
vector_fp m_SE_b_ij
Entropy term for the binary mole fraction interaction of the excess gibbs free energy expression...
void s_update_dlnActCoeff_dlnN() const
Update the derivative of the log of the activity coefficients wrt log(moles_m)
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
std::string name() const
Returns the name of the XML node.
Base class for exceptions thrown by Cantera classes.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies for the species in the mixture.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
vector_fp m_VHE_b_ij
Enthalpy term for the binary mole fraction interaction of the excess gibbs free energy expression...
void s_update_dlnActCoeff_dlnN_diag() const
Update the derivative of the log of the activity coefficients wrt log(moles) - diagonal only...
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
virtual void getLnActivityCoefficients(doublereal *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
vector_fp m_VSE_b_ij
Entropy term for the binary mole fraction interaction of the excess gibbs free energy expression...
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...
std::vector< size_t > m_pSpecies_B_ij
vector of species indices representing species B in the interaction
virtual void getdlnActCoeffdlnX_diag(doublereal *dlnActCoeffdlnX_diag) const
Get the array of log concentration-like derivatives of the log activity coefficients - diagonal compo...
MargulesVPSSTP & operator=(const MargulesVPSSTP &b)
Assignment operator.
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).
vector_fp m_VHE_c_ij
Enthalpy term for the ternary mole fraction interaction of the excess gibbs free energy expression...
std::string id() const
Return the id attribute, if present.
const doublereal SmallNumber
smallest number to compare to zero.
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.
MargulesVPSSTP()
Constructor.
std::vector< doublereal > moleFractions_
Storage for the current values of the mole fractions of the species.
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].
doublereal err(const std::string &msg) const
Error function.
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 s_update_lnActCoeff() const
Update the activity coefficients.
virtual void initThermo()
vector_fp m_SE_c_ij
Entropy term for the ternary mole fraction interaction of the excess gibbs free energy expression...
virtual int eosType() const
Equation of state type flag.
MargulesVPSSTP is a derived class of GibbsExcessVPSSTP that employs the Margules approximation for th...
vector_fp m_HE_c_ij
Enthalpy term for the ternary mole fraction interaction of the excess gibbs free energy expression...
int formTempModel_
form of the temperature dependence of the Margules interaction expression
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
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 zero()
Set all of the entries to zero.
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
void s_update_dlnActCoeff_dT() const
Update the derivative of the log of the activity coefficients wrt T.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
void s_update_dlnActCoeff_dlnX_diag() const
Update the derivative of the log of the activity coefficients wrt log(mole fraction) ...
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
std::string speciesName(size_t k) const
Name of the species with index k.
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 void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of derivatives of the log activity coefficients wrt mole numbers - diagonal only...
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...