15 #include "cantera/thermo/MixedSolventElectrolyte.h"
27 static const double xxSmall = 1.0E-150;
32 MixedSolventElectrolyte::MixedSolventElectrolyte() :
34 numBinaryInteractions_(0),
51 numBinaryInteractions_(0),
60 numBinaryInteractions_(0),
147 numBinaryInteractions_(0),
190 throw CanteraError(
"MixedSolventElectrolyte test1 constructor",
191 "Unable to find LiCl(L)");
198 throw CanteraError(
"MixedSolventElectrolyte test1 constructor",
199 "Unable to find KCl(L)");
240 if ((
int) inputFile.size() == 0) {
241 throw CanteraError(
"MixedSolventElectrolyte:constructPhaseFile",
242 "input file is null");
245 std::ifstream fin(path.c_str());
247 throw CanteraError(
"MixedSolventElectrolyte:constructPhaseFile",
"could not open "
248 +path+
" for reading.");
259 throw CanteraError(
"MixedSolventElectrolyte:constructPhaseFile",
260 "ERROR: Can not find phase named " +
261 id +
" in file named " + inputFile);
263 fxml_phase->
copy(&phaseNode_XML);
298 if ((
int)
id.
size() > 0) {
299 string idp = phaseNode.
id();
301 throw CanteraError(
"MixedSolventElectrolyte::constructPhaseXML",
302 "phasenode and Id are incompatible");
309 if (!phaseNode.
hasChild(
"thermo")) {
310 throw CanteraError(
"MixedSolventElectrolyte::constructPhaseXML",
311 "no thermo XML node");
318 stemp = thermoNode.
attrib(
"model");
320 if (formString !=
"margules") {
321 throw CanteraError(
"MixedSolventElectrolyte::constructPhaseXML",
322 "model name isn't Margules: " + formString);
333 throw CanteraError(
"MixedSolventElectrolyte::constructPhaseXML",
"importPhase failed ");
361 for (
size_t k = 0; k <
m_kk; k++) {
376 for (
size_t k = 0; k <
m_kk; k++) {
400 for (
size_t k = 0; k <
m_kk; k++) {
413 for (
size_t i = 0; i < kk; i++) {
426 for (
size_t i = 0; i < kk; i++) {
439 for (
size_t i = 0; i < kk; i++) {
476 for (
size_t k = 0; k <
m_kk; k++) {
486 for (
size_t k = 0; k <
m_kk; k++) {
519 for (
size_t k = 0; k <
m_kk; k++) {
525 for (
size_t k = 0; k <
m_kk; k++) {
559 for (
size_t k = 0; k <
m_kk; k++) {
566 for (
size_t k = 0; k <
m_kk; k++) {
588 double XA, XB, g0 , g1;
596 for (
size_t iK = 0; iK <
m_kk; iK++) {
615 vbar[iK] += XA*XB*(g0+g1*XB)+((delAK-XA)*XB+XA*(delBK-XB))*(g0+g1*XB)+XA*XB*(delBK-XB)*g1;
622 throw CanteraError(
"MixedSolventElectrolyte",
"Base class method "
673 string subname =
"MixedSolventElectrolyte::initThermoXML";
682 string mStringa = thermoNode.
attrib(
"model");
684 if (mString !=
"margules") {
686 "Unknown thermo model: " + mStringa);
699 if (thermoNode.
hasChild(
"activityCoefficients")) {
702 string mStringa = acNode.
attrib(
"model");
704 if (mString !=
"margules") {
706 "Unknown activity coefficient model: " + mStringa);
709 for (
size_t i = 0; i < n; i++) {
711 stemp = xmlACChild.
name();
718 if (nodeName ==
"binaryneutralspeciesparameters") {
744 double XA, XB, g0, g1;
748 for (
size_t iK = 0; iK <
m_kk; iK++) {
763 lnActCoeff_Scaled_[iK] += (delAK * XB + XA * delBK - XA * XB) * (g0 + g1 * XB) + XA * XB * (delBK - XB) * g1;
778 doublereal XA, XB, g0, g1;
783 for (
size_t iK = 0; iK <
m_kk; iK++) {
798 double temp = (delAK * XB + XA * delBK - XA * XB) * (g0 + g1 * XB) + XA * XB * (delBK - XB) * g1;
808 for (
size_t k = 0; k <
m_kk; k++) {
816 for (
size_t k = 0; k <
m_kk; k++) {
834 doublereal* dlnActCoeffds)
const
837 double XA, XB, g0, g1, dXA, dXB;
844 for (
size_t iK = 0; iK <
m_kk; iK++) {
845 dlnActCoeffds[iK] = 0.0;
869 dlnActCoeffds[iK] += ((delBK-XB)*dXA + (delAK-XA)*dXB)*(g0+2*g1*XB) + (delBK-XB)*2*g1*XA*dXB
886 double XA, XB, XK, g0, g1;
892 for (
size_t iK = 0; iK <
m_kk; iK++) {
948 doublereal delAK, delBK;
949 double XA, XB, g0, g1,XM;
953 doublereal delAM, delBM;
959 for (
size_t iK = 0; iK <
m_kk; iK++) {
960 for (
size_t iM = 0; iM <
m_kk; iM++) {
988 dlnActCoeffdlnN_(iK,iM) += g0*((delAM-XA)*(delBK-XB)+(delAK-XA)*(delBM-XB));
989 dlnActCoeffdlnN_(iK,iM) += 2*g1*((delAM-XA)*(delBK-XB)*XB+(delAK-XA)*(delBM-XB)*XB+(delBM-XB)*(delBK-XB)*XA);
1014 doublereal XA, XB, g0 , g1;
1040 for (
size_t k = 0; k <
m_kk; k++) {
1048 for (
size_t k = 0; k <
m_kk; k++) {
1057 for (
size_t k = 0; k <
m_kk; k++) {
1058 for (
size_t m = 0; m <
m_kk; m++) {
1059 dlnActCoeffdlnN[ld * k + m] = data[m_kk * k + m];
1095 string xname = xmLBinarySpecies.
name();
1096 if (xname !=
"binaryNeutralSpeciesParameters") {
1097 throw CanteraError(
"MixedSolventElectrolyte::readXMLBinarySpecies",
1098 "Incorrect name for processing this routine: " + xname);
1102 size_t nParamsFound;
1104 string iName = xmLBinarySpecies.
attrib(
"speciesA");
1106 throw CanteraError(
"MixedSolventElectrolyte::readXMLBinarySpecies",
"no speciesA attrib");
1108 string jName = xmLBinarySpecies.
attrib(
"speciesB");
1110 throw CanteraError(
"MixedSolventElectrolyte::readXMLBinarySpecies",
"no speciesB attrib");
1117 if (iSpecies ==
npos) {
1121 if (charge[iSpecies] != 0) {
1122 throw CanteraError(
"MixedSolventElectrolyte::readXMLBinarySpecies",
"speciesA charge problem");
1125 if (jSpecies ==
npos) {
1129 if (charge[jSpecies] != 0) {
1130 throw CanteraError(
"MixedSolventElectrolyte::readXMLBinarySpecies",
"speciesB charge problem");
1138 size_t num = xmLBinarySpecies.
nChildren();
1139 for (
size_t iChild = 0; iChild < num; iChild++) {
1141 stemp = xmlChild.
name();
1146 if (nodeName ==
"excessenthalpy") {
1151 nParamsFound = vParams.size();
1153 if (nParamsFound != 2) {
1154 throw CanteraError(
"MixedSolventElectrolyte::readXMLBinarySpecies::excessEnthalpy for " + ispName
1156 "wrong number of params found");
1162 if (nodeName ==
"excessentropy") {
1167 nParamsFound = vParams.size();
1169 if (nParamsFound != 2) {
1170 throw CanteraError(
"MixedSolventElectrolyte::readXMLBinarySpecies::excessEntropy for " + ispName
1172 "wrong number of params found");
1178 if (nodeName ==
"excessvolume_enthalpy") {
1183 nParamsFound = vParams.size();
1185 if (nParamsFound != 2) {
1186 throw CanteraError(
"MixedSolventElectrolyte::readXMLBinarySpecies::excessVolume_Enthalpy for " + ispName
1188 "wrong number of params found");
1194 if (nodeName ==
"excessvolume_entropy") {
1199 nParamsFound = vParams.size();
1201 if (nParamsFound != 2) {
1202 throw CanteraError(
"MixedSolventElectrolyte::readXMLBinarySpecies::excessVolume_Entropy for " + ispName
1204 "wrong number of params found");