diff --git a/include/cantera/thermo/PengRobinsonMFTP.h b/include/cantera/thermo/PengRobinsonMFTP.h index 58110fd0c5c..ec383aed293 100644 --- a/include/cantera/thermo/PengRobinsonMFTP.h +++ b/include/cantera/thermo/PengRobinsonMFTP.h @@ -1,7 +1,7 @@ //! @file PengRobinsonMFTP.h // This file is part of Cantera. See License.txt in the top-level directory or -// at http://www.cantera.org/license.txt for license and copyright information. +// at https://cantera.org/license.txt for license and copyright information. #ifndef CT_PENGROBINSONMFTP_H #define CT_PENGROBINSONMFTP_H @@ -73,9 +73,33 @@ class PengRobinsonMFTP : public MixtureFugacityTP * where: * * \f[ - * \alpha = \left[ 1 + \left(0.37464 + 1.54226\omega - 0.26992\omega^2\right)\left(1-T_r^{0.5}\right)\right]^2 + * \alpha = \left[ 1 + \kappa \left(1-T_r^{0.5}\right)\right]^2 * \f] + * + * and + * + * \f[ + * \kappa = \left(0.37464 + 1.54226\omega - 0.26992\omega^2\right) for omega <= 0.491 + * \kappa = \left(0.379642 + 1.487503\omega - 0.164423\omega^2 + 0.016667\omega^3 \right) for omega > 0.491 + * \f] + * + *Coefficients a_mix, b_mix and (a \alpha)_{mix} are caclulated as + * + *\f[ + *a_{mix} = \sum_i \sum_j X_i X_j a_{i, j} = \sum_i \sum_j X_i X_j sqrt{a_i a_j} + *\f] + * + *\f[ + * b_{mix} = \sum_i X_i b_i + *\f] + * + *\f[ + * {a \alpha}_{mix} = \sum_i \sum_j X_i X_j {a \alpha}_{i, j} = \sum_i \sum_j X_i X_j sqrt{a_i a_j} sqrt{\alpha_i \alpha_j} + *\f] + * + * */ + virtual double pressure() const; // @} @@ -112,8 +136,9 @@ class PengRobinsonMFTP : public MixtureFugacityTP /*! * This is defined as the concentration by which the generalized * concentration is normalized to produce the activity. In many cases, this - * quantity will be the same for all species in a phase. Since the activity - * for an ideal gas mixture is simply the mole fraction, for an ideal gas + * quantity will be the same for all species in a phase. + * The ideal gas mixture is considered as the standard or reference state here. + * Since the activity for an ideal gas mixture is simply the mole fraction, for an ideal gas * \f$ C^0_k = P/\hat R T \f$. * * @param k Optional parameter indicating the species. The default is to @@ -143,7 +168,7 @@ class PengRobinsonMFTP : public MixtureFugacityTP * \f$ \mu_k / \hat R T \f$. * Units: unitless * - * We close the loop on this function, here, calling getChemPotentials() and + * We close the loop on this function here calling getChemPotentials() and * then dividing by RT. No need for child classes to handle. * * @param mu Output vector of non-dimensional species chemical potentials @@ -158,7 +183,13 @@ class PengRobinsonMFTP : public MixtureFugacityTP virtual void getPartialMolarCp(double* cpbar) const; virtual void getPartialMolarVolumes(double* vbar) const; - + //! Calculate the temperature dependent interaction parameter alpha needed for P-R EoS + /* + * The temperature dependent parameter in P-R EoS is calculated as + * \alpha = [1 + \kappa(1 - sqrt{T/T_crit}]^2 + * kappa is a function calulated based on the accentric factor. + * Units: unitless + */ virtual void calculateAlpha(const std::string& species, double a, double b, double w); //@} /// @name Critical State Properties. @@ -190,7 +221,7 @@ class PengRobinsonMFTP : public MixtureFugacityTP //! Retrieve a and b coefficients by looking up tabulated critical parameters /*! * If pureFluidParameters are not provided for any species in the phase, - * consult the critical properties tabulated in /thermo/critProperties.xml. + * consult the critical properties tabulated in /build/data/thermo/critProperties.xml. * If the species is found there, calculate pure fluid parameters a_k and b_k as: * \f[ a_k = 0.4278*R**2*T_c^2/P_c \f] * @@ -223,10 +254,10 @@ class PengRobinsonMFTP : public MixtureFugacityTP /*! * The "a" parameter for interactions between species *i* and *j* is * assumed by default to be computed as: - * \f[ a_{ij} = \sqrt(a_{i,0} a_{j,0}) + \sqrt(a_{i,1} a_{j,1}) T \f] + * \f[ a_{ij} = \sqrt(a_{i, 0} a_{j, 0}) + \sqrt(a_{i, 1} a_{j, 1}) T \f] * * This function overrides the defaults with the specified parameters: - * \f[ a_{ij} = a_{ij,0} + a_{ij,1} T \f] + * \f[ a_{ij} = a_{ij, 0} + a_{ij, 1} T \f] * * @param species_i Name of one species * @param species_j Name of the other species @@ -316,20 +347,20 @@ class PengRobinsonMFTP : public MixtureFugacityTP protected: //! Form of the temperature parameterization /*! - * - 0 = There is no temperature parameterization of a or b - * - 1 = The a_ij parameter is a linear function of the temperature + * 0 = There is no temperature parameterization of a or b + * 1 = The a_ij parameter is a linear function of the temperature */ int m_formTempParam; //! Value of b in the equation of state /*! - * m_b is a function of the temperature and the mole fraction. + * m_b_current is a function of the temperature and the mole fractions. */ double m_b_current; - //! Value of a in the equation of state + //! Value of a and alpha in the equation of state /*! - * a_b is a function of the temperature and the mole fraction. + * m_aAlpha_current is a function of the temperature and the mole fractions. m_a_current depends only on the mole fractions. */ double m_a_current; double m_aAlpha_current; @@ -358,21 +389,21 @@ class PengRobinsonMFTP : public MixtureFugacityTP // Partial molar volumes of the species mutable vector_fp m_partialMolarVolumes; - //! The derivative of the pressure wrt the volume + //! The derivative of the pressure with respect to the volume /*! * Calculated at the current conditions. temperature and mole number kept * constant */ mutable double dpdV_; - //! The derivative of the pressure wrt the temperature + //! The derivative of the pressure with respect to the temperature /*! * Calculated at the current conditions. Total volume and mole number kept * constant */ mutable double dpdT_; - //! Vector of derivatives of pressure wrt mole number + //! Vector of derivatives of pressure with respect to mole number /*! * Calculated at the current conditions. Total volume, temperature and * other mole number kept constant @@ -380,9 +411,9 @@ class PengRobinsonMFTP : public MixtureFugacityTP mutable vector_fp dpdni_; public: - //! Omega constant for a -> value of a in terms of critical properties + //! Omega constants: a0 (= omega_a) and b0 (= omega_b) values used in Peng-Robinson equation of state /*! - * this was calculated from a small nonlinear solve + * These values are calculated by solving P-R cubic equation at the critical point. */ static const double omega_a; diff --git a/src/thermo/PengRobinsonMFTP.cpp b/src/thermo/PengRobinsonMFTP.cpp index 8d4c6c0a60e..d4962a25011 100644 --- a/src/thermo/PengRobinsonMFTP.cpp +++ b/src/thermo/PengRobinsonMFTP.cpp @@ -71,8 +71,7 @@ void PengRobinsonMFTP::calculateAlpha(const std::string& species, double a, doub if (w <= 0.491) { kappa_vec_[k] = 0.37464 + 1.54226*w - 0.26992*w*w; - } - else { + } else { kappa_vec_[k] = 0.374642 + 1.487503*w - 0.164423*w*w + 0.016666*w*w*w; } @@ -177,10 +176,7 @@ double PengRobinsonMFTP::cv_mole() const { _updateReferenceStateThermo(); double TKelvin = temperature(); - double mv = molarVolume(); - double pp = pressure(); pressureDerivatives(); - double cp = cp_mole(); return (cp_mole() + TKelvin* dpdT_* dpdT_ / dpdV_); } @@ -188,10 +184,10 @@ double PengRobinsonMFTP::pressure() const { _updateReferenceStateThermo(); // Get a copy of the private variables stored in the State object - double T = temperature(); + double TKelvin = temperature(); double mv = meanMolecularWeight() / density(); - double den = mv * mv + 2 * mv * m_b_current - m_b_current * m_b_current; - double pp = GasConstant * T / (mv - m_b_current) - m_aAlpha_current / den; + double denom = mv * mv + 2 * mv * m_b_current - m_b_current * m_b_current; + double pp = GasConstant * TKelvin / (mv - m_b_current) - m_aAlpha_current / denom; return pp; } @@ -223,8 +219,9 @@ void PengRobinsonMFTP::compositionChanged() void PengRobinsonMFTP::getActivityConcentrations(double* c) const { getActivityCoefficients(c); + double p_RT = pressure() / RT(); for (size_t k = 0; k < m_kk; k++) { - c[k] *= moleFraction(k)*pressure()/RT(); + c[k] *= moleFraction(k)* p_RT; } } @@ -239,8 +236,8 @@ void PengRobinsonMFTP::getActivityCoefficients(double* ac) const double mv = molarVolume(); double T = temperature(); double sqt2 = sqrt(2); - double vpb_2 = mv + (1 + sqt2)*m_b_current; - double vmb_2 = mv + (1 - sqt2)*m_b_current; + double vpb2 = mv + (1 + sqt2)*m_b_current; + double vmb2 = mv + (1 - sqt2)*m_b_current; double vmb = mv - m_b_current; double pres = pressure(); @@ -254,16 +251,17 @@ void PengRobinsonMFTP::getActivityCoefficients(double* ac) const double num = 0; double den = 2 * sqt2 * m_b_current * m_b_current; double den2 = m_b_current*(mv * mv + 2 * mv * m_b_current - m_b_current * m_b_current); + double RTkelvin = RT(); for (size_t k = 0; k < m_kk; k++) { num = 2 * m_b_current * m_pp[k] - m_aAlpha_current* b_vec_Curr_[k]; - ac[k] = (-RT()*log(pres*mv/RT()) + RT() * log(mv / vmb) - + RT() * b_vec_Curr_[k] / vmb - - (num /den) * log(vpb_2/vmb_2) + ac[k] = (-RTkelvin *log(pres*mv/ RTkelvin) + RTkelvin * log(mv / vmb) + + RTkelvin * b_vec_Curr_[k] / vmb + - (num /den) * log(vpb2/vmb2) - m_aAlpha_current* b_vec_Curr_[k] * mv/den2 ); } for (size_t k = 0; k < m_kk; k++) { - ac[k] = exp(ac[k]/RT()); + ac[k] = exp(ac[k]/ RTkelvin); } } @@ -272,24 +270,26 @@ void PengRobinsonMFTP::getActivityCoefficients(double* ac) const void PengRobinsonMFTP::getChemPotentials_RT(double* muRT) const { getChemPotentials(muRT); + double RTkelvin = RT(); for (size_t k = 0; k < m_kk; k++) { - muRT[k] *= 1.0 / RT(); + muRT[k] *= 1.0 / RTkelvin; } } void PengRobinsonMFTP::getChemPotentials(double* mu) const { getGibbs_ref(mu); + double RTkelvin = RT(); for (size_t k = 0; k < m_kk; k++) { double xx = std::max(SmallNumber, moleFraction(k)); - mu[k] += RT()*(log(xx)); + mu[k] += RTkelvin *(log(xx)); } double mv = molarVolume(); double vmb = mv - m_b_current; double sqt2 = sqrt(2); - double vpb_2 = mv + (1 + sqt2)*m_b_current; - double vmb_2 = mv + (1 - sqt2)*m_b_current; + double vpb2 = mv + (1 + sqt2)*m_b_current; + double vmb2 = mv + (1 - sqt2)*m_b_current; for (size_t k = 0; k < m_kk; k++) { m_pp[k] = 0.0; @@ -307,10 +307,10 @@ void PengRobinsonMFTP::getChemPotentials(double* mu) const for (size_t k = 0; k < m_kk; k++) { num = 2 * m_b_current * m_pp[k] - m_aAlpha_current* b_vec_Curr_[k]; - mu[k] += (RT() * log(pres/refP) - RT() * log(pres * mv / RT()) - + RT() * log(mv / vmb) - + RT() * b_vec_Curr_[k] / vmb - - (num /den) * log(vpb_2/vmb_2) + mu[k] += (RTkelvin * log(pres/refP) - RTkelvin * log(pres * mv / RTkelvin) + + RTkelvin * log(mv / vmb) + + RTkelvin * b_vec_Curr_[k] / vmb + - (num /den) * log(vpb2/vmb2) - m_aAlpha_current* b_vec_Curr_[k] * mv/den2 ); } @@ -328,8 +328,8 @@ void PengRobinsonMFTP::getPartialMolarEnthalpies(double* hbar) const double sqt = sqrt(2); double vmb = mv - m_b_current; double sqt2 = sqrt(2); - double vpb_2 = mv + (1 + sqt2)*m_b_current; - double vmb_2 = mv + (1 - sqt2)*m_b_current; + double vpb2 = mv + (1 + sqt2)*m_b_current; + double vmb2 = mv + (1 - sqt2)*m_b_current; for (size_t k = 0; k < m_kk; k++) { m_pp[k] = 0.0; @@ -341,8 +341,9 @@ void PengRobinsonMFTP::getPartialMolarEnthalpies(double* hbar) const double den = mv * mv + 2 * mv * m_b_current - m_b_current * m_b_current; double den2 = den*den; + double RTkelvin = RT(); for (size_t k = 0; k < m_kk; k++) { - dpdni_[k] = RT()/vmb + RT() * b_vec_Curr_[k] / (vmb * vmb) - 2.0 * m_pp[k] / den + dpdni_[k] = RTkelvin /vmb + RTkelvin * b_vec_Curr_[k] / (vmb * vmb) - 2.0 * m_pp[k] / den + 2 * vmb * m_aAlpha_current * b_vec_Curr_[k] / den2; } @@ -353,7 +354,7 @@ void PengRobinsonMFTP::getPartialMolarEnthalpies(double* hbar) const double fac2 = mv + TKelvin * dpdT_ / dpdV_; double fac3 = 2 * sqt * m_b_current *m_b_current; for (size_t k = 0; k < m_kk; k++) { - double hE_v = mv * dpdni_[k] - RT() + (2 * m_b_current - b_vec_Curr_[k]) / fac3 * log(vpb_2 / vmb_2)*fac + double hE_v = mv * dpdni_[k] - RTkelvin + (2 * m_b_current - b_vec_Curr_[k]) / fac3 * log(vpb2 / vmb2)*fac + (mv * b_vec_Curr_[k]) /(m_b_current*den) * fac; hbar[k] = hbar[k] + hE_v; hbar[k] -= fac2 * dpdni_[k]; @@ -368,16 +369,16 @@ void PengRobinsonMFTP::getPartialMolarEntropies(double* sbar) const double mv = molarVolume(); double sqt2 = sqrt(2); double vmb = mv - m_b_current; - double vpb_2 = mv + (1 + sqt2)*m_b_current; - double vmb_2 = mv + (1 - sqt2)*m_b_current; + double vpb2 = mv + (1 + sqt2)*m_b_current; + double vmb2 = mv + (1 - sqt2)*m_b_current; double refP = refPressure(); double daAlphadT = daAlpha_dT(); double coeff1 = 0; double den1 = 2 * sqt2 * m_b_current * m_b_current; double den2 = mv * mv + 2 * mv * m_b_current - m_b_current * m_b_current; - // Calculate sum(n_j (a alpha)_i,k * (1/alpha_k d/dT(alpha_k))) -> m_pp - // Calculate sum(n_j (a alpha)_i,k * (1/alpha_i d/dT(alpha_i))) -> m_tmpV + // Calculate sum(n_j (a alpha)_i, k * (1/alpha_k d/dT(alpha_k))) -> m_pp + // Calculate sum(n_j (a alpha)_i, k * (1/alpha_i d/dT(alpha_i))) -> m_tmpV for (size_t k = 0; k < m_kk; k++) { m_pp[k] = 0.0; m_tmpV[k] = 0; @@ -393,10 +394,10 @@ void PengRobinsonMFTP::getPartialMolarEntropies(double* sbar) const for (size_t k = 0; k < m_kk; k++) { coeff1 = m_b_current * (m_pp[k] + m_tmpV[k]) - daAlphadT * b_vec_Curr_[k]; sbar[k] += GasConstant * log(GasConstant * TKelvin / (refP * mv)) - + GasConstant; + + GasConstant + GasConstant * log(mv / vmb) + GasConstant * b_vec_Curr_[k] / vmb - - coeff1* log(vpb_2 / vmb_2) / den1 + - coeff1* log(vpb2 / vmb2) / den1 - b_vec_Curr_[k] * mv * daAlphadT / den2 / m_b_current; } pressureDerivatives(); @@ -433,14 +434,15 @@ void PengRobinsonMFTP::getPartialMolarVolumes(double* vbar) const double vpb = mv + m_b_current; double fac = mv * mv + 2 * mv * m_b_current - m_b_current * m_b_current; double fac2 = fac * fac; + double RTkelvin = RT(); for (size_t k = 0; k < m_kk; k++) { - double num = (RT() + RT() * m_b_current/ vmb + RT() * b_vec_Curr_[k] / vmb - + RT() * m_b_current * b_vec_Curr_[k] /(vmb * vmb) + double num = (RTkelvin + RTkelvin * m_b_current/ vmb + RTkelvin * b_vec_Curr_[k] / vmb + + RTkelvin * m_b_current * b_vec_Curr_[k] /(vmb * vmb) - 2 * mv * m_pp[k] / fac + 2 * mv * vmb * m_aAlpha_current * b_vec_Curr_[k] / fac2 ); - double denom = (pressure() + RT() * m_b_current / (vmb * vmb) + double denom = (pressure() + RTkelvin * m_b_current / (vmb * vmb) + m_aAlpha_current/fac - 2 * mv* vpb *m_aAlpha_current / fac2 ); @@ -563,7 +565,7 @@ vector PengRobinsonMFTP::getCoeff(const std::string& iName) std::string iNameLower = toLowerCopy(iName); std::string dbName = toLowerCopy(acNodeDoc.attrib("name")); - // Attempt to match provided specie iName to current database species + // Attempt to match provided species iName to current database species // dbName: if (iNameLower == dbName) { // Read from database and calculate a and b coefficients @@ -577,9 +579,8 @@ vector PengRobinsonMFTP::getCoeff(const std::string& iName) std::string critTemp = xmlChildCoeff.attrib("value"); vParams = strSItoDbl(critTemp); } - if (vParams <= 0.0) //Assuming that Pc and Tc are non zero. - { - throw CanteraError("PengRobinsonMFTP::GetCoeff", + if (vParams <= 0.0) { //Assuming that Pc and Tc are non zero. + throw CanteraError("PengRobinsonMFTP::getCoeff", "Critical Temperature must be positive "); } T_crit = vParams; @@ -591,9 +592,8 @@ vector PengRobinsonMFTP::getCoeff(const std::string& iName) std::string critPressure = xmlChildCoeff.attrib("value"); vParams = strSItoDbl(critPressure); } - if (vParams <= 0.0) //Assuming that Pc and Tc are non zero. - { - throw CanteraError("PengRobinsonMFTP::GetCoeff", + if (vParams <= 0.0) { //Assuming that Pc and Tc are non zero. + throw CanteraError("PengRobinsonMFTP::getCoeff", "Critical Pressure must be positive "); } P_crit = vParams; @@ -709,20 +709,16 @@ void PengRobinsonMFTP::readXMLPureFluid(XML_Node& pureFluidParam) if (vParams.size() == 1) { a0 = vParams[0]; - } - else if (vParams.size() == 2) { + } else if (vParams.size() == 2) { a0 = vParams[0]; a1 = vParams[1]; - } - else { + } else { throw CanteraError("PengRobinsonMFTP::readXMLPureFluid", "unknown model or incorrect number of parameters"); } - } - else if (nodeName == "b_coeff") { + } else if (nodeName == "b_coeff") { b = getFloatCurrent(xmlChild, "toSI"); - } - else if (nodeName == "acentric_factor") { + } else if (nodeName == "acentric_factor") { w = getFloatCurrent(xmlChild); } } @@ -752,11 +748,9 @@ void PengRobinsonMFTP::readXMLCrossFluid(XML_Node& CrossFluidParam) string iModel = toLowerCopy(xmlChild.attrib("model")); if (iModel == "constant" && vParams.size() == 1) { setBinaryCoeffs(iName, jName, vParams[0], 0.0); - } - else if (iModel == "linear_a") { + } else if (iModel == "linear_a") { setBinaryCoeffs(iName, jName, vParams[0], vParams[1]); - } - else { + } else { throw CanteraError("PengRobinsonMFTP::readXMLCrossFluid", "unknown model ({}) or wrong number of parameters ({})", iModel, vParams.size()); @@ -991,7 +985,7 @@ void PengRobinsonMFTP::updateAB() alpha_vec_Curr_[j] = sqt_alpha*sqt_alpha; } - //Update aAlpha_i,j + //Update aAlpha_i, j for (size_t i = 0; i < m_kk; i++) { for (size_t j = 0; j < m_kk; j++) { size_t counter = i * m_kk + j; @@ -1032,12 +1026,10 @@ void PengRobinsonMFTP::calculateAB(double temp, double& aCalc, double& bCalc, do double PengRobinsonMFTP::daAlpha_dT() const { double daAlphadT = 0.0, temp, k, Tc = 0.0, sqtTr = 0.0; - //we need species critical temperature - double coeff1 = 1 / (critTemperature()*sqtTr); - double coeff2 = sqtTr - 1; + double coeff1, coeff2; for (size_t i = 0; i < m_kk; i++) { size_t counter = i + m_kk * i; - // Calculate first and double derivatives of alpha for individual species + // Calculate first derivative of alpha for individual species Tc = speciesCritTemperature(a_vec_Curr_[counter], b_vec_Curr_[i]); sqtTr = sqrt(temperature() / Tc); //we need species critical temperature coeff1 = 1 / (Tc*sqtTr); @@ -1066,14 +1058,14 @@ double PengRobinsonMFTP::d2aAlpha_dT2() const double coeff1 = 1 / (critTemperature()*critTemperature()*sqt_Tr); double coeff2 = sqt_Tr - 1; for (size_t i = 0; i < m_kk; i++) { - // Calculate individual dAlpha_dTi + // Calculate first and second derivatives of alpha for individual species size_t counter = i + m_kk * i; k = kappa_vec_[i]; dalphadT_vec_Curr_[i] = coeff1 *(k* k*coeff2 - k); d2alphadT2_[i] = (k*k + k) * coeff1 / (2 * sqt_Tr*sqt_Tr); } - //Calculate mixture derivative + //Calculate mixture derivative for (size_t i = 0; i < m_kk; i++) { size_t counter1 = i + m_kk * i; alphai = alpha_vec_Curr_[i]; @@ -1117,7 +1109,7 @@ int PengRobinsonMFTP::NicholsSolve(double TKelvin, double pres, double a, double double tmp; fill_n(Vroot, 3, 0.0); if (TKelvin <= 0.0) { - throw CanteraError("PengRobinsonMFTP::NicholsSolve()", "neg temperature"); + throw CanteraError("PengRobinsonMFTP::NicholsSolve()", "neg temperature T = {}", TKelvin); } // Derive the coefficients of the cubic polynomial (in terms of molar volume v) to solve. @@ -1136,13 +1128,12 @@ int PengRobinsonMFTP::NicholsSolve(double TKelvin, double pres, double a, double // Derive the center of the cubic, x_N double xN = - bn /(3 * an); - // Derive the value of delta**2. This is a key quantity that determines the - // number of turning points - double delta2 = (bn * bn - 3 * an * cn) / (9 * an * an); //This is delta^2 term in Nichols method + // Derive the value of delta**2. This is a key quantity that determines the number of turning points + double delta2 = (bn * bn - 3 * an * cn) / (9 * an * an); double delta = 0.0; // Calculate a couple of ratios - // Cubic equation in z : z^2 - (1-B) z^2 + (A-2B -3B^2)z - (AB-B^2-B^3) = 0 + // Cubic equation in z : z^3 - (1-B) z^2 + (A -2B -3B^2)z - (AB- B^2- B^3) = 0 double ratio1 = 3.0 * an * cn / (bn * bn); double ratio2 = pres * b / (GasConstant * TKelvin); // B if (fabs(ratio1) < 1.0E-7) { @@ -1172,7 +1163,7 @@ int PengRobinsonMFTP::NicholsSolve(double TKelvin, double pres, double a, double double h = 2.0 * an * delta * delta2; double yN = 2.0 * bn * bn * bn / (27.0 * an * an) - bn * cn / (3.0 * an) + dn; // y_N term - double desc = yN * yN - h2; // descriminant + double desc = yN * yN - h2; // discriminant //check if y = h if (fabs(fabs(h) - fabs(yN)) < 1.0E-10) { @@ -1218,13 +1209,12 @@ int PengRobinsonMFTP::NicholsSolve(double TKelvin, double pres, double a, double Vroot[2] = 0.0; tmp = an * Vroot[0] * Vroot[0] * Vroot[0] + bn * Vroot[0] * Vroot[0] + cn * Vroot[0] + dn; } else if (desc < 0.0) { - double tmp = - yN/h; - double val = acos(tmp); + double val = acos(-yN / h); double theta = val / 3.0; - double oo = 2. * Pi / 3.; + double twoThirdPi = 2. * Pi / 3.; double alpha = xN + 2. * delta * cos(theta); - double beta = xN + 2. * delta * cos(theta + oo); - double gamma = xN + 2. * delta * cos(theta + 2.0 * oo); + double beta = xN + 2. * delta * cos(theta + twoThirdPi); + double gamma = xN + 2. * delta * cos(theta + 2.0 * twoThirdPi); Vroot[0] = beta; Vroot[1] = gamma; Vroot[2] = alpha; @@ -1270,8 +1260,7 @@ int PengRobinsonMFTP::NicholsSolve(double TKelvin, double pres, double a, double } } - // Unfortunately, there is a heavy amount of roundoff error due to bad - // conditioning in this + // Unfortunately, there is a heavy amount of roundoff error due to bad conditioning in this double res, dresdV = 0.0; for (int i = 0; i < nSolnValues; i++) { for (int n = 0; n < 20; n++) {