Consolidated definitions of repeatedly-used constants

"MIN_X" and "TINY" are replaced by "Tiny". "xxSmall" is replaced with
"SmallNumber".
This commit is contained in:
Ray Speth 2013-01-11 22:55:46 +00:00
parent db4a1dfe46
commit 83097b3860
20 changed files with 44 additions and 112 deletions

View file

@ -133,7 +133,7 @@ protected:
virtual void updateDiff_T();
//! Vector of species mole fractions. These are processed so that all mole
//! fractions are >= MIN_X. Length = m_kk.
//! fractions are >= *Tiny*. Length = m_kk.
vector_fp m_molefracs;
//! Internal storage for the viscosity of the mixture (kg /m /s)

View file

@ -1200,7 +1200,7 @@ private:
//! Local copy of the mass fractions of the species in the phase
/**
* This version of the mass fraction vector is adjusted to a
* minimum lower bound of MIN_X for use in transport calculations.
* minimum lower bound of *Tiny* for use in transport calculations.
*/
vector_fp m_massfracs_tran;
@ -1218,7 +1218,7 @@ private:
//! Non-zero mole fraction vector used in transport property calculations
/*!
* The mole fractions here are assumed to be bounded by MIN_X and 1.0
* The mole fractions here are assumed to be bounded by *Tiny* and 1.0
* and they may not be assumed to add up to one. This
* mole fraction vector is created from the ThermoPhase object.
* Derivative quantities of this use the _tran suffix.

View file

@ -16,8 +16,6 @@ using namespace std;
namespace Cantera
{
const doublereal TINY = 1.0e-20;
#if defined(WITH_HTML_LOGS)
/// Used to print reaction equations. Given a stoichiometric
/// coefficient 'nu' and a chemical symbol 'sym', return a string
@ -428,7 +426,7 @@ void MultiPhaseEquil::getComponents(const std::vector<size_t>& order)
// Check for rows that are zero
bool isZeroRow = true;
for (k = m; k < nColumns; k++) {
if (fabs(m_A(m,k)) > sqrt(TINY)) {
if (fabs(m_A(m,k)) > sqrt(Tiny)) {
isZeroRow = false;
break;
}
@ -439,7 +437,7 @@ void MultiPhaseEquil::getComponents(const std::vector<size_t>& order)
bool foundSwapCandidate = false;
for (; n > m; n--) {
for (k = m; k < nColumns; k++) {
if (fabs(m_A(n,k)) > sqrt(TINY)) {
if (fabs(m_A(n,k)) > sqrt(Tiny)) {
foundSwapCandidate = true;
break;
}
@ -713,7 +711,7 @@ stepComposition(int loglevel)
if (m_moles[k] < MAJOR_THRESHOLD) {
m_force = true;
}
omax = m_moles[k]*FCTR/(fabs(m_work[k]) + TINY);
omax = m_moles[k]*FCTR/(fabs(m_work[k]) + Tiny);
if (m_work[k] < 0.0 && omax < omegamax) {
omegamax = omax;
if (omegamax < 1.0e-5) {
@ -785,7 +783,6 @@ doublereal MultiPhaseEquil::computeReactionSteps(vector_fp& dxi)
index_t j, k, ik, kc, ip;
doublereal stoich, nmoles, csum, term1, fctr, rfctr;
vector_fp nu;
const doublereal TINY = 1.0e-20;
doublereal grad = 0.0;
dxi.resize(nFree());
@ -827,13 +824,13 @@ doublereal MultiPhaseEquil::computeReactionSteps(vector_fp& dxi)
for (k = 0; k < m_nel; k++) {
kc = m_order[k];
stoich = nu[kc];
nmoles = fabs(m_mix->speciesMoles(m_species[kc])) + TINY;
nmoles = fabs(m_mix->speciesMoles(m_species[kc])) + Tiny;
csum += stoich*stoich*m_dsoln[kc]/nmoles;
}
// noncomponent term
kc = m_order[j + m_nel];
nmoles = fabs(m_mix->speciesMoles(m_species[kc])) + TINY;
nmoles = fabs(m_mix->speciesMoles(m_species[kc])) + Tiny;
term1 = m_dsoln[kc]/nmoles;
// sum over solution phases
@ -850,11 +847,11 @@ doublereal MultiPhaseEquil::computeReactionSteps(vector_fp& dxi)
psum += stoich * stoich;
}
}
sum -= psum / (fabs(m_mix->phaseMoles(ip)) + TINY);
sum -= psum / (fabs(m_mix->phaseMoles(ip)) + Tiny);
}
}
rfctr = term1 + csum + sum;
if (fabs(rfctr) < TINY) {
if (fabs(rfctr) < Tiny) {
fctr = 1.0;
} else {
fctr = 1.0/(term1 + csum + sum);

View file

@ -657,7 +657,6 @@ getMolalityActivityCoefficients(doublereal* acMolality) const
void DebyeHuckel::getChemPotentials(doublereal* mu) const
{
double xx;
const double xxSmall = 1.0E-150;
/*
* First get the standard chemical potentials in
* molar form.
@ -674,11 +673,11 @@ void DebyeHuckel::getChemPotentials(doublereal* mu) const
double xmolSolvent = moleFraction(m_indexSolvent);
for (size_t k = 0; k < m_kk; k++) {
if (m_indexSolvent != k) {
xx = std::max(m_molalities[k], xxSmall);
xx = std::max(m_molalities[k], SmallNumber);
mu[k] += RT * (log(xx) + m_lnActCoeffMolal[k]);
}
}
xx = std::max(xmolSolvent, xxSmall);
xx = std::max(xmolSolvent, SmallNumber);
mu[m_indexSolvent] +=
RT * (log(xx) + m_lnActCoeffMolal[m_indexSolvent]);
}

View file

@ -1122,7 +1122,6 @@ getUnscaledMolalityActivityCoefficients(doublereal* acMolality) const
void HMWSoln::getChemPotentials(doublereal* mu) const
{
double xx;
const double xxSmall = 1.0E-150;
/*
* First get the standard chemical potentials in
* molar form.
@ -1139,11 +1138,11 @@ void HMWSoln::getChemPotentials(doublereal* mu) const
double xmolSolvent = moleFraction(m_indexSolvent);
for (size_t k = 0; k < m_kk; k++) {
if (m_indexSolvent != k) {
xx = std::max(m_molalities[k], xxSmall);
xx = std::max(m_molalities[k], SmallNumber);
mu[k] += RT * (log(xx) + m_lnActCoeffMolal_Scaled[k]);
}
}
xx = std::max(xmolSolvent, xxSmall);
xx = std::max(xmolSolvent, SmallNumber);
mu[m_indexSolvent] +=
RT * (log(xx) + m_lnActCoeffMolal_Scaled[m_indexSolvent]);
}

View file

@ -28,9 +28,6 @@ using namespace ctml;
namespace Cantera
{
//! Small value to be used in cutoff expressions with logs
static double xxSmall = 1.0E-150;
/*
* Default constructor
*/
@ -615,7 +612,6 @@ getMolalityActivityCoefficients(doublereal* acMolality) const
void IdealMolalSoln::getChemPotentials(doublereal* mu) const
{
double xx;
//const double xxSmall = 1.0E-150;
// Assertion is made for speed
AssertThrow(m_indexSolvent == 0, "solvent not the first species");
@ -641,7 +637,7 @@ void IdealMolalSoln::getChemPotentials(doublereal* mu) const
if (IMS_typeCutoff_ == 0 || xmolSolvent > 3.* IMS_X_o_cutoff_/2.0) {
for (size_t k = 1; k < m_kk; k++) {
xx = std::max(m_molalities[k], xxSmall);
xx = std::max(m_molalities[k], SmallNumber);
mu[k] += RT * log(xx);
}
/*
@ -649,7 +645,7 @@ void IdealMolalSoln::getChemPotentials(doublereal* mu) const
* -> see my notes
*/
xx = std::max(xmolSolvent, xxSmall);
xx = std::max(xmolSolvent, SmallNumber);
mu[m_indexSolvent] +=
(RT * (xmolSolvent - 1.0) / xx);
} else {
@ -661,10 +657,10 @@ void IdealMolalSoln::getChemPotentials(doublereal* mu) const
for (size_t k = 1; k < m_kk; k++) {
xx = std::max(m_molalities[k], xxSmall);
xx = std::max(m_molalities[k], SmallNumber);
mu[k] += RT * (log(xx) + IMS_lnActCoeffMolal_[k]);
}
xx = std::max(xmolSolvent, xxSmall);
xx = std::max(xmolSolvent, SmallNumber);
mu[m_indexSolvent] +=
RT * (log(xx) + IMS_lnActCoeffMolal_[m_indexSolvent]);
}

View file

@ -31,7 +31,6 @@ using namespace std;
namespace Cantera
{
static const double xxSmall = 1.0E-150;
//====================================================================================================================
/*
* Default constructor.
@ -672,7 +671,7 @@ void IonsFromNeutralVPSSTP::getPartialMolarEntropies(doublereal* sbar) const
s_update_dlnActCoeffdT();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
sbar[k] += - lnActCoeff_Scaled_[k] -log(xx) - T * dlnActCoeffdT_Scaled_[k];
}
/*

View file

@ -23,7 +23,6 @@ using namespace std;
namespace Cantera
{
static const double xxSmall = 1.0E-150;
/*
* Default constructor.
*
@ -280,7 +279,7 @@ void MargulesVPSSTP::getChemPotentials(doublereal* mu) const
s_update_lnActCoeff();
doublereal RT = GasConstant * temperature();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
mu[k] += RT * (log(xx) + lnActCoeff_Scaled_[k]);
}
}
@ -439,7 +438,7 @@ void MargulesVPSSTP::getPartialMolarEntropies(doublereal* sbar) const
s_update_dlnActCoeff_dT();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
sbar[k] += - lnActCoeff_Scaled_[k] -log(xx) - T * dlnActCoeffdT_Scaled_[k];
}
/*

View file

@ -24,7 +24,6 @@ using namespace std;
namespace Cantera
{
static const double xxSmall = 1.0E-150;
/*
* Default constructor.
*
@ -285,7 +284,7 @@ void MixedSolventElectrolyte::getChemPotentials(doublereal* mu) const
*/
doublereal RT = GasConstant * temperature();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
mu[k] += RT * (log(xx) + lnActCoeff_Scaled_[k]);
}
}
@ -444,7 +443,7 @@ void MixedSolventElectrolyte::getPartialMolarEntropies(doublereal* sbar) const
s_update_dlnActCoeff_dT();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
sbar[k] += - lnActCoeff_Scaled_[k] -log(xx) - T * dlnActCoeffdT_Scaled_[k];
}
/*

View file

@ -27,7 +27,6 @@ using namespace std;
namespace Cantera
{
static const double xxSmall = 1.0E-150;
//====================================================================================================================
/*
* Default constructor.
@ -212,7 +211,7 @@ void MolarityIonicVPSSTP::getChemPotentials(doublereal* mu) const
*/
doublereal RT = GasConstant * temperature();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
mu[k] += RT * (log(xx) + lnActCoeff_Scaled_[k]);
}
}
@ -337,7 +336,7 @@ void MolarityIonicVPSSTP::getPartialMolarEntropies(doublereal* sbar) const
s_update_dlnActCoeff_dT();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
sbar[k] += - lnActCoeff_Scaled_[k] -log(xx) - T * dlnActCoeffdT_Scaled_[k];
}
/*

View file

@ -20,7 +20,6 @@ using namespace std;
namespace Cantera
{
static const double xxSmall = 1.0E-150;
//====================================================================================================================
/*
* Default constructor.
@ -296,7 +295,7 @@ void PhaseCombo_Interaction::getChemPotentials(doublereal* mu) const
*/
doublereal RT = GasConstant * temperature();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
mu[k] += RT * (log(xx) + lnActCoeff_Scaled_[k]);
}
}
@ -454,7 +453,7 @@ void PhaseCombo_Interaction::getPartialMolarEntropies(doublereal* sbar) const
s_update_dlnActCoeff_dT();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
sbar[k] += - lnActCoeff_Scaled_[k] - log(xx) - T * dlnActCoeffdT_Scaled_[k];
}
/*
@ -654,7 +653,7 @@ void PhaseCombo_Interaction::s_update_lnActCoeff() const
/*
* We never sample the end of the mole fraction domains
*/
xx = std::max(moleFractions_[iK], xxSmall);
xx = std::max(moleFractions_[iK], SmallNumber);
/*
* First wipe out the ideal solution mixing term
*/
@ -775,11 +774,11 @@ void PhaseCombo_Interaction::getdlnActCoeffds(const doublereal dTds, const doub
/*
* We never sample the end of the mole fraction domains
*/
xx = std::max(moleFractions_[iK], xxSmall);
xx = std::max(moleFractions_[iK], SmallNumber);
/*
* First wipe out the ideal solution mixing term
*/
if (xx > xxSmall) {
if (xx > SmallNumber) {
dlnActCoeffds[iK] += - 1.0 / xx;
}
@ -839,12 +838,12 @@ void PhaseCombo_Interaction::s_update_dlnActCoeff_dlnN_diag() const
/*
* We never sample the end of the mole fraction domains
*/
xx = std::max(moleFractions_[iK], xxSmall);
xx = std::max(moleFractions_[iK], SmallNumber);
/*
* First wipe out the ideal solution mixing term
*/
// lnActCoeff_Scaled_[iK] = - log(xx);
if (xx > xxSmall) {
if (xx > SmallNumber) {
dlnActCoeffdlnN_diag_[iK] = - 1.0 + xx;
}
@ -901,12 +900,12 @@ void PhaseCombo_Interaction::s_update_dlnActCoeff_dlnN() const
/*
* We never sample the end of the mole fraction domains
*/
xx = std::max(moleFractions_[iK], xxSmall);
xx = std::max(moleFractions_[iK], SmallNumber);
for (size_t iM = 0; iM < m_kk; iM++) {
XM = moleFractions_[iM];
if (xx > xxSmall) {
if (xx > SmallNumber) {
delKM = 0.0;
if (iK == iM) {
delKM = 1.0;

View file

@ -24,7 +24,6 @@ using namespace std;
namespace Cantera
{
static const double xxSmall = 1.0E-150;
//====================================================================================================================
/*
* Default constructor.
@ -282,7 +281,7 @@ void RedlichKisterVPSSTP::getChemPotentials(doublereal* mu) const
*/
doublereal RT = GasConstant * temperature();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
mu[k] += RT * (log(xx) + lnActCoeff_Scaled_[k]);
}
}
@ -441,7 +440,7 @@ void RedlichKisterVPSSTP::getPartialMolarEntropies(doublereal* sbar) const
s_update_dlnActCoeff_dT();
for (size_t k = 0; k < m_kk; k++) {
xx = std::max(moleFractions_[k], xxSmall);
xx = std::max(moleFractions_[k], SmallNumber);
sbar[k] += - lnActCoeff_Scaled_[k] -log(xx) - T * dlnActCoeffdT_Scaled_[k];
}
/*

View file

@ -20,12 +20,6 @@
using namespace std;
/**
* Mole fractions below MIN_X will be set to MIN_X when computing
* transport properties.
*/
#define MIN_X 1.e-20
namespace Cantera
{
@ -512,10 +506,10 @@ void AqueousTransport::update_C()
m_thermo->getMoleFractions(DATA_PTR(m_molefracs));
// add an offset to avoid a pure species condition or
// negative mole fractions. MIN_X is 1.0E-20, a value
// negative mole fractions. *Tiny* is 1.0E-20, a value
// which is below the additive machine precision of mole fractions.
for (size_t k = 0; k < m_nsp; k++) {
m_molefracs[k] = std::max(MIN_X, m_molefracs[k]);
m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
}
}
//====================================================================================================================

View file

@ -16,12 +16,6 @@
using namespace std;
/**
* Mole fractions below MIN_X will be set to MIN_X when computing
* transport properties.
*/
#define MIN_X 1.e-20
namespace Cantera
{
@ -441,7 +435,7 @@ void DustyGasTransport::updateTransport_C()
// add an offset to avoid a pure species condition
// (check - this may be unnecessary)
for (size_t k = 0; k < m_nsp; k++) {
m_x[k] = std::max(MIN_X, m_x[k]);
m_x[k] = std::max(Tiny, m_x[k]);
}
// diffusion coeffs depend on Pressure
m_bulk_ok = false;

View file

@ -16,13 +16,6 @@
using namespace std;
/**
* Mole fractions below MIN_X will be set to MIN_X when computing
* transport properties.
*/
#define MIN_X 1.e-14
namespace Cantera
{
@ -1342,8 +1335,8 @@ bool LiquidTransport::update_C()
concTot_tran_ = 0.0;
for (size_t k = 0; k < m_nsp; k++) {
m_molefracs[k] = std::max(0.0, m_molefracs[k]);
m_molefracs_tran[k] = std::max(MIN_X, m_molefracs[k]);
m_massfracs_tran[k] = std::max(MIN_X, m_massfracs[k]);
m_molefracs_tran[k] = std::max(Tiny, m_molefracs[k]);
m_massfracs_tran[k] = std::max(Tiny, m_massfracs[k]);
concTot_tran_ += m_molefracs_tran[k];
concTot_ += m_concentrations[k];
}

View file

@ -15,14 +15,6 @@
#include <iostream>
using namespace std;
/**
* Mole fractions below MIN_X will be set to MIN_X when computing
* transport properties.
*/
#ifndef MIN_X
#define MIN_X 1.e-20
#endif
namespace Cantera
{
@ -270,7 +262,7 @@ void MixTransport::update_C()
// add an offset to avoid a pure species condition
for (size_t k = 0; k < m_nsp; k++) {
m_molefracs[k] = std::max(MIN_X, m_molefracs[k]);
m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
}
}
//====================================================================================================================

View file

@ -25,12 +25,6 @@
#include <iostream>
using namespace std;
/**
* Mole fractions below MIN_X will be set to MIN_X when computing
* transport properties.
*/
#define MIN_X 1.e-20
namespace Cantera
{
@ -578,7 +572,7 @@ void MultiTransport::update_C()
// add an offset to avoid a pure species condition
// (check - this may be unnecessary)
for (size_t k = 0; k < m_nsp; k++) {
m_molefracs[k] = std::max(MIN_X, m_molefracs[k]);
m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
}
}

View file

@ -17,12 +17,6 @@
#include <iostream>
using namespace std;
/**
* Mole fractions below MIN_X will be set to MIN_X when computing
* transport properties.
*/
#define MIN_X 1.e-20
namespace Cantera
{
@ -481,7 +475,7 @@ void PecosTransport::update_C()
// add an offset to avoid a pure species condition
int k;
for (k = 0; k < m_nsp; k++) {
m_molefracs[k] = std::max(MIN_X, m_molefracs[k]);
m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
}
}

View file

@ -14,13 +14,6 @@
#include <iostream>
using namespace std;
/**
* Mole fractions below MIN_X will be set to MIN_X when computing
* transport properties.
*/
#define MIN_X 1.e-14
#ifndef SAFE_DELETE
//! \cond
#define SAFE_DELETE(x) if (x) { delete (x); x = 0; }

View file

@ -16,13 +16,6 @@
#include <iostream>
using namespace std;
/**
* Mole fractions below MIN_X will be set to MIN_X when computing
* transport properties.
*/
#define MIN_X 1.e-20
namespace Cantera
{