22 numBinaryInteractions_(0),
30 numBinaryInteractions_(0),
45 for (
size_t k = 0; k <
m_kk; k++) {
60 for (
size_t k = 0; k <
m_kk; k++) {
72 for (
size_t i = 0; i < kk; i++) {
84 for (
size_t i = 0; i < kk; i++) {
96 for (
size_t i = 0; i < kk; i++) {
113 for (
size_t k = 0; k <
m_kk; k++) {
121 for (
size_t k = 0; k <
m_kk; k++) {
137 for (
size_t k = 0; k <
m_kk; k++) {
141 for (
size_t k = 0; k <
m_kk; k++) {
157 for (
size_t k = 0; k <
m_kk; k++) {
163 for (
size_t k = 0; k <
m_kk; k++) {
182 const doublereal temp1 = g0 + g1 * XB;
183 const doublereal all = -1.0*XA*XB*temp1 - XA*XB*XB*g1;
185 for (
size_t iK = 0; iK <
m_kk; iK++) {
188 vbar[iA] += XB * temp1;
189 vbar[iB] += XA * temp1 + XA*XB*g1;
197 for (
auto& item :
m_input[
"interactions"].asVector<AnyMap>()) {
198 auto&
species = item[
"species"].asVector<
string>(2);
200 if (item.hasKey(
"excess-enthalpy")) {
201 h = item.convertVector(
"excess-enthalpy",
"J/kmol", 2);
203 if (item.hasKey(
"excess-entropy")) {
204 s = item.convertVector(
"excess-entropy",
"J/kmol/K", 2);
206 if (item.hasKey(
"excess-volume-enthalpy")) {
207 vh = item.convertVector(
"excess-volume-enthalpy",
"m^3/kmol", 2);
209 if (item.hasKey(
"excess-volume-entropy")) {
210 vs = item.convertVector(
"excess-volume-entropy",
"m^3/kmol/K", 2);
213 h[0], h[1], s[0], s[1], vh[0], vh[1], vs[0], vs[1]);
222 vector<AnyMap> interactions;
225 interaction[
"species"] = vector<std::string>{
228 interaction[
"excess-enthalpy"].setQuantity(
232 interaction[
"excess-entropy"].setQuantity(
236 interaction[
"excess-volume-enthalpy"].setQuantity(
240 interaction[
"excess-volume-entropy"].setQuantity(
243 interactions.push_back(std::move(interaction));
245 phaseNode[
"interactions"] = std::move(interactions);
255 if ((
int) id_.size() > 0) {
256 string idp = phaseNode.
id();
258 throw CanteraError(
"MargulesVPSSTP::initThermoXML",
"phasenode and Id are incompatible");
263 if (!phaseNode.
hasChild(
"thermo")) {
265 "no thermo XML node");
272 "model name isn't Margules: " + thermoNode[
"model"]);
277 if (thermoNode.
hasChild(
"activityCoefficients")) {
281 "Unknown activity coefficient model: " + acNode[
"model"]);
283 for (
size_t i = 0; i < acNode.
nChildren(); i++) {
300 const std::string& speciesB,
double h0,
double h1,
double s0,
double s1,
301 double vh0,
double vh1,
double vs0,
double vs1)
336 const doublereal XAXB = XA * XB;
337 const doublereal g0g1XB = (g0 + g1 * XB);
338 const doublereal all = -1.0 * XAXB * g0g1XB - XAXB * XB * g1;
339 for (
size_t iK = 0; iK <
m_kk; iK++) {
360 const doublereal XAXB = XA * XB;
361 const doublereal g0g1XB = (g0 + g1 * XB);
362 const doublereal all = -1.0 * XAXB * g0g1XB - XAXB * XB * g1;
363 const doublereal mult = 2.0 * invT;
364 const doublereal dT2all = mult * all;
365 for (
size_t iK = 0; iK <
m_kk; iK++) {
379 for (
size_t k = 0; k <
m_kk; k++) {
387 for (
size_t k = 0; k <
m_kk; k++) {
393 doublereal* dlnActCoeffds)
const
397 for (
size_t iK = 0; iK <
m_kk; iK++) {
398 dlnActCoeffds[iK] = 0.0;
406 double dXA = dXds[iA];
407 double dXB = dXds[iB];
410 const doublereal g02g1XB = g0 + 2*g1*XB;
411 const doublereal g2XAdXB = 2*g1*XA*dXB;
412 const doublereal all = (-XB * dXA - XA *dXB) * g02g1XB - XB *g2XAdXB;
413 for (
size_t iK = 0; iK <
m_kk; iK++) {
416 dlnActCoeffds[iA] += dXB * g02g1XB;
417 dlnActCoeffds[iB] += dXA * g02g1XB + g2XAdXB;
426 for (
size_t iK = 0; iK <
m_kk; iK++) {
459 for (
size_t iK = 0; iK <
m_kk; iK++) {
460 for (
size_t iM = 0; iM <
m_kk; iM++) {
484 dlnActCoeffdlnN_(iK,iM) += g0*((delAM-XA)*(delBK-XB)+(delAK-XA)*(delBM-XB));
485 dlnActCoeffdlnN_(iK,iM) += 2*g1*((delAM-XA)*(delBK-XB)*XB+(delAK-XA)*(delBM-XB)*XB+(delBM-XB)*(delBK-XB)*XA);
515 for (
size_t k = 0; k <
m_kk; k++) {
523 for (
size_t k = 0; k <
m_kk; k++) {
532 for (
size_t k = 0; k <
m_kk; k++) {
533 for (
size_t m = 0; m <
m_kk; m++) {
534 dlnActCoeffdlnN[ld * k + m] = data[
m_kk * k + m];
541 string xname = xmLBinarySpecies.
name();
542 if (xname !=
"binaryNeutralSpeciesParameters") {
543 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
544 "Incorrect name for processing this routine: " + xname);
546 string aName = xmLBinarySpecies.
attrib(
"speciesA");
548 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
"no speciesA attrib");
550 string bName = xmLBinarySpecies.
attrib(
"speciesB");
552 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies",
"no speciesB attrib");
565 for (
size_t iChild = 0; iChild < xmLBinarySpecies.
nChildren(); iChild++) {
577 if (nodeName ==
"excessenthalpy") {
579 getFloatArray(xmlChild, vParams,
true,
"toSI",
"excessEnthalpy");
580 if (vParams.size() != 2) {
581 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies"
582 "excessEnthalpy for {} : {}: wrong number of params found."
583 " Need 2", aName, bName);
587 }
else if (nodeName ==
"excessentropy") {
589 getFloatArray(xmlChild, vParams,
true,
"toSI",
"excessEntropy");
590 if (vParams.size() != 2) {
591 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies"
592 "excessEntropy for {} : {}: wrong number of params found."
593 " Need 2", aName, bName);
597 }
else if (nodeName ==
"excessvolume_enthalpy") {
599 getFloatArray(xmlChild, vParams,
true,
"toSI",
"excessVolume_Enthalpy");
600 if (vParams.size() != 2) {
601 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies"
602 "excessVolume_Enthalpy for {} : {}: wrong number of params"
603 " found. Need 2", aName, bName);
607 }
else if (nodeName ==
"excessvolume_entropy") {
609 getFloatArray(xmlChild, vParams,
true,
"toSI",
"excessVolume_Entropy");
610 if (vParams.size() != 2) {
611 throw CanteraError(
"MargulesVPSSTP::readXMLBinarySpecies"
612 "excessVolume_Entropy for {} : {}: wrong number of params"
613 " found. Need 2", aName, bName);
(see Thermodynamic Properties and class MargulesVPSSTP).
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
A map of string keys to values whose type can vary at runtime.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
void zero()
Set all of the entries to zero.
void resize(size_t n, size_t m, double v=0.0)
Resize the array, and fill the new entries with 'v'.
Base class for exceptions thrown by Cantera classes.
Array2D dlnActCoeffdlnN_
Storage for the current derivative values of the gradients with respect to logarithm of the species m...
vector_fp dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
vector_fp lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the species.
vector_fp d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
vector_fp moleFractions_
Storage for the current values of the mole fractions of the species.
vector_fp dlnActCoeffdlnN_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
vector_fp dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
vector_fp m_SE_c_ij
Entropy term for the ternary mole fraction interaction of the excess Gibbs free energy expression.
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
virtual void getd2lnActCoeffdT2(doublereal *d2lnActCoeffdT2) const
Get the array of temperature second derivatives of the log activity coefficients.
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...
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies 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.
virtual void getdlnActCoeffdT(doublereal *dlnActCoeffdT) const
Get the array of temperature derivatives of the log activity coefficients.
size_t numBinaryInteractions_
number of binary interaction expressions
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
void s_update_dlnActCoeff_dlnN_diag() const
Update the derivative of the log of the activity coefficients wrt log(moles) - diagonal only.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
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 readXMLBinarySpecies(XML_Node &xmlBinarySpecies)
Process an XML node called "binaryNeutralSpeciesParameters".
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
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 getPartialMolarCp(doublereal *cpbar) const
Returns an array of partial molar entropies for the species in the mixture.
vector_fp m_VHE_c_ij
Enthalpy term for the ternary mole fraction interaction of the excess Gibbs free energy expression.
std::vector< size_t > m_pSpecies_A_ij
vector of species indices representing species A in the interaction
void s_update_dlnActCoeff_dT() const
Update the derivative of the log of the activity coefficients wrt T.
vector_fp m_HE_b_ij
Enthalpy term for the binary mole fraction interaction of the excess Gibbs free energy expression.
void addBinaryInteraction(const std::string &speciesA, const std::string &speciesB, double h0, double h1, double s0, double s1, double vh0, double vh1, double vs0, double vs1)
Add a binary species interaction with the specified parameters.
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.
virtual void initThermo()
void s_update_dlnActCoeff_dlnN() const
Update the derivative of the log of the activity coefficients wrt log(moles_m)
vector_fp m_SE_b_ij
Entropy term for the binary mole fraction interaction of the excess Gibbs free energy expression.
vector_fp m_VHE_b_ij
Enthalpy term for the binary mole fraction interaction of the excess Gibbs free energy expression.
virtual void getdlnActCoeffdlnN_diag(doublereal *dlnActCoeffdlnN_diag) const
Get the array of log species mole number derivatives of the log activity coefficients.
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,...
std::vector< size_t > m_pSpecies_B_ij
vector of species indices representing species B in the interaction
void initLengths()
Initialize lengths of local variables after all species have been identified.
void s_update_dlnActCoeff_dlnX_diag() const
Update the derivative of the log of the activity coefficients wrt log(mole fraction)
void s_update_lnActCoeff() const
Update the activity coefficients.
MargulesVPSSTP(const std::string &inputFile="", const std::string &id="")
Construct a MargulesVPSSTP object from an input file.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
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.
size_t m_kk
Number of species in the phase.
std::string speciesName(size_t k) const
Name of the species with index k.
doublereal temperature() const
Temperature (K).
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
void initThermoFile(const std::string &inputFile, const std::string &id)
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
AnyMap m_input
Data supplied via setParameters.
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution.
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
virtual void initThermo()
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 getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Class XML_Node is a tree-based representation of the contents of an XML file.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
std::string name() const
Returns the name of the XML node.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
std::string id() const
Return the id attribute, if present.
size_t nChildren(bool discardComments=false) const
Return the number of children.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
const double SmallNumber
smallest number to compare to zero.
std::string toLowerCopy(const std::string &input)
Convert to lower case.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
const double GasConstant
Universal Gas Constant [J/kmol/K].
size_t getFloatArray(const XML_Node &node, vector_fp &v, const bool convert=true, const std::string &unitsString="", const std::string &nodeName="floatArray")
This function reads the current node or a child node of the current node with the default name,...
Contains declarations for string manipulation functions within Cantera.