33 for (
size_t k = 0; k <
m_kk; k++) {
48 for (
size_t k = 0; k <
m_kk; k++) {
65 for (
size_t k = 0; k <
m_kk; k++) {
72 for (
size_t k = 0; k <
m_kk; k++) {
82 for (
size_t k = 0; k <
m_kk; k++) {
97 for (
size_t k = 0; k <
m_kk; k++) {
102 for (
size_t k = 0; k <
m_kk; k++) {
111 for (
size_t iK = 0; iK <
m_kk; iK++) {
119 for (
const auto& item :
m_input[
"interactions"].asVector<
AnyMap>()) {
120 auto&
species = item[
"species"].asVector<
string>(2);
121 vector<double> h_excess = item.convertVector(
"excess-enthalpy",
"J/kmol");
122 vector<double> s_excess = item.convertVector(
"excess-entropy",
"J/kmol/K");
133 vector<AnyMap> interactions;
136 interaction[
"species"] = vector<string>{
140 while (h.size() > 1 && h.back() == 0) {
143 while (s.size() > 1 && s.back() == 0) {
146 interaction[
"excess-enthalpy"].setQuantity(std::move(h),
"J/kmol");
147 interaction[
"excess-entropy"].setQuantity(std::move(s),
"J/kmol/K");
148 interactions.push_back(std::move(interaction));
150 phaseNode[
"interactions"] = std::move(interactions);
167 for (
size_t i = 0; i <
m_HE_m_ij.size(); i++) {
172 double deltaX = XA - XB;
173 const vector<double>& he_vec =
m_HE_m_ij[i];
174 const vector<double>& se_vec =
m_SE_m_ij[i];
176 double polyMm1 = 1.0;
180 for (
size_t m = 0; m < he_vec.size(); m++) {
181 double A_ge = (he_vec[m] - T * se_vec[m]) / (
GasConstant * T);
183 sum2 += A_ge * (m + 1) * poly;
186 sumMm1 += (A_ge * polyMm1 * m);
190 double oneMXA = 1.0 - XA;
191 double oneMXB = 1.0 - XB;
192 for (
size_t k = 0; k <
m_kk; k++) {
195 }
else if (iB == k) {
210 for (
size_t i = 0; i <
m_HE_m_ij.size(); i++) {
215 double deltaX = XA - XB;
218 const vector<double>& he_vec =
m_HE_m_ij[i];
220 double polyMm1 = 1.0;
222 for (
size_t m = 0; m < he_vec.size(); m++) {
225 sum2 += h_e * (m + 1) * poly;
228 sumMm1 += (h_e * polyMm1 * m);
232 double oneMXA = 1.0 - XA;
233 double oneMXB = 1.0 - XB;
234 for (
size_t k = 0; k <
m_kk; k++) {
237 }
else if (iB == k) {
250 for (
size_t k = 0; k <
m_kk; k++) {
260 for (
size_t i = 0; i <
m_HE_m_ij.size(); i++) {
265 double deltaX = XA - XB;
268 const vector<double>& he_vec =
m_HE_m_ij[i];
269 const vector<double>& se_vec =
m_SE_m_ij[i];
271 double polyMm1 = 1.0;
272 double polyMm2 = 1.0;
274 for (
size_t m = 0; m < he_vec.size(); m++) {
275 double A_ge = (he_vec[m] - T * se_vec[m]) / (
GasConstant * T);;
279 sumMm1 += (A_ge * polyMm1 * m);
283 sumMm2 += (A_ge * polyMm2 * m * (m - 1.0));
288 for (
size_t k = 0; k <
m_kk; k++) {
291 XA * (- (1-XA+XB) * sum + 2*(1.0 - XA) * XB * sumMm1
292 + sumMm1 * (XB * (1 - 2*XA + XB) - XA * (1 - XA + 2*XB))
293 + 2 * XA * XB * sumMm2 * (1.0 - XA + XB));
294 }
else if (iB == k) {
296 XB * (- (1-XB+XA) * sum - 2*(1.0 - XB) * XA * sumMm1
297 + sumMm1 * (XA * (2*XB - XA - 1) - XB * (-2*XA + XB - 1))
298 - 2 * XA * XB * sumMm2 * (-XA - 1 + XB));
309 for (
size_t i = 0; i <
m_HE_m_ij.size(); i++) {
314 double deltaX = XA - XB;
317 const vector<double>& he_vec =
m_HE_m_ij[i];
318 const vector<double>& se_vec =
m_SE_m_ij[i];
320 double polyMm1 = 1.0;
321 double polyMm2 = 1.0;
323 double sum2Mm1 = 0.0;
325 for (
size_t m = 0; m < he_vec.size(); m++) {
326 double A_ge = he_vec[m] - T * se_vec[m];
328 sum2 += A_ge * (m + 1) * poly;
331 sumMm1 += (A_ge * polyMm1 * m);
332 sum2Mm1 += (A_ge * polyMm1 * m * (1.0 + m));
336 sumMm2 += (A_ge * polyMm2 * m * (m - 1.0));
341 for (
size_t k = 0; k <
m_kk; k++) {
344 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
345 + XA * XB * sumMm2 * (1.0 - XA + XB));
348 + XA * sumMm1 * (1.0 + 2.0 * XB - XA)
349 - XA * XB * sumMm2 * (1.0 - XA + XB));
350 }
else if (iB == k) {
352 + XB * sumMm1 * (1.0 - 2.0 * XA + XB)
353 + XA * XB * sumMm2 * (1.0 - XA + XB));
356 + XA * sumMm1 * (XB - XA - (1.0 - XB))
357 - XA * XB * sumMm2 * (-XA - (1.0 - XB)));
367 span<double> dlnActCoeffds)
const
373 for (
size_t k = 0; k <
m_kk; k++) {
375 for (
size_t j = 0; j <
m_kk; j++) {
384 dlnActCoeffdlnN_diag.size(),
m_kk);
386 for (
size_t j = 0; j <
m_kk; j++) {
388 for (
size_t k = 0; k <
m_kk; k++) {
397 dlnActCoeffdlnX_diag.size(),
m_kk);
399 for (
size_t k = 0; k <
m_kk; k++) {
407 dlnActCoeffdlnN.size(), ld *
m_kk);
410 for (
size_t k = 0; k <
m_kk; k++) {
411 for (
size_t m = 0; m <
m_kk; m++) {
412 dlnActCoeffdlnN[ld * k + m] = data[
m_kk * k + m];
418 const string& speciesA,
const string& speciesB,
419 span<const double> excess_enthalpy, span<const double> excess_entropy)
424 throw CanteraError(
"RedlichKisterVPSSTP::addBinaryInteraction",
425 "Species '{}' should be neutral", speciesA);
426 }
else if (
charge(kB) != 0) {
427 throw CanteraError(
"RedlichKisterVPSSTP::addBinaryInteraction",
428 "Species '{}' should be neutral", speciesB);
433 m_HE_m_ij.emplace_back(excess_enthalpy.begin(), excess_enthalpy.end());
434 m_SE_m_ij.emplace_back(excess_entropy.begin(), excess_entropy.end());
435 size_t N = max(excess_enthalpy.size(), excess_entropy.size());
(see Thermodynamic Properties and class RedlichKisterVPSSTP).
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 string &key) const
Returns true if the map contains an item named key.
void zero()
Set all of the entries to zero.
virtual 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< double > lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the species.
vector< double > dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
vector< double > moleFractions_
Storage for the current values of the mole fractions of the species.
vector< double > dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
size_t m_kk
Number of species in the phase.
size_t speciesIndex(const string &name, bool raise=true) const
Returns the index of a species named 'name' within the Phase object.
double temperature() const
Temperature (K).
string speciesName(size_t k) const
Name of the species with index k.
shared_ptr< Species > species(const string &name) const
Return the Species object for the named species.
double charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
void getLnActivityCoefficients(span< double > lnac) const override
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
void s_update_dlnActCoeff_dX_() const
Internal routine that calculates the derivative of the activity coefficients wrt the mole fractions.
Array2D dlnActCoeff_dX_
Two dimensional array of derivatives of activity coefficients wrt mole fractions.
vector< vector< double > > m_SE_m_ij
Entropy term for the binary mole fraction interaction of the excess Gibbs free energy expression.
void getPartialMolarEnthalpies(span< double > hbar) const override
Returns an array of partial molar enthalpies for the species in the mixture.
void getdlnActCoeffdlnN_diag(span< double > dlnActCoeffdlnN_diag) const override
Get the array of log species mole number derivatives of the log activity coefficients.
void getPartialMolarCp(span< double > cpbar) const override
Returns an array of partial molar heat capacities for the species in the mixture.
void getParameters(AnyMap &phaseNode) const override
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void getdlnActCoeffdlnX_diag(span< double > dlnActCoeffdlnX_diag) const override
Get the array of ln mole fraction derivatives of the log activity coefficients - diagonal component o...
void getdlnActCoeffdlnN(const size_t ld, span< double > const dlnActCoeffdlnN) override
Get the array of derivatives of the log activity coefficients with respect to the log of the species ...
vector< size_t > m_pSpecies_A_ij
vector of species indices representing species A in the interaction
double cv_mole() const override
Molar heat capacity at constant volume and composition [J/kmol/K].
void s_update_dlnActCoeff_dT() const
Update the derivative of the log of the activity coefficients wrt T.
vector< size_t > m_pSpecies_B_ij
vector of species indices representing species B in the interaction
vector< vector< double > > m_HE_m_ij
Enthalpy term for the binary mole fraction interaction of the excess Gibbs free energy expression.
void addBinaryInteraction(const string &speciesA, const string &speciesB, span< const double > excess_enthalpy, span< const double > excess_entropy)
Add a binary species interaction with the specified parameters.
void getdlnActCoeffds(const double dTds, span< const double > dXds, span< double > dlnActCoeffds) const override
Get the change in activity coefficients wrt changes in state (temp, mole fraction,...
void getPartialMolarVolumes(span< double > vbar) const override
Return an array of partial molar volumes for the species in the mixture.
void initLengths()
Initialize lengths of local variables after all species have been identified.
void getPartialMolarEntropies(span< double > sbar) const override
Returns an array of partial molar entropies for the species in the mixture.
void s_update_dlnActCoeff_dlnX_diag() const
Internal routine that calculates the total derivative of the activity coefficients with respect to th...
void s_update_lnActCoeff() const
Update the activity coefficients.
void getdlnActCoeffdT(span< double > dlnActCoeffdT) const override
Get the array of temperature derivatives of the log activity coefficients.
RedlichKisterVPSSTP(const string &inputFile="", const string &id="")
Construct a RedlichKisterVPSSTP object from an input file.
void getChemPotentials(span< double > mu) const override
Get the species chemical potentials. Units: J/kmol.
virtual double cp_mole() const
Molar heat capacity at constant pressure and composition [J/kmol/K].
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
double RT() const
Return the Gas Constant multiplied by the current temperature.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
void initThermoFile(const string &inputFile, const string &id)
Initialize a ThermoPhase object using an input file.
AnyMap m_input
Data supplied via setParameters.
void getCp_R(span< double > cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
void getStandardChemPotentials(span< double > mu) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void getEnthalpy_RT(span< double > hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
void getEntropy_R(span< double > sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
void getStandardVolumes(span< double > vol) const override
Get the molar volumes of the species standard states at the current T and P of the solution.
const double GasConstant
Universal Gas Constant [J/kmol/K].
Namespace for the Cantera kernel.
const double SmallNumber
smallest number to compare to zero.
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.
Contains declarations for string manipulation functions within Cantera.