Use std::min and std::max instead of preprocessor macros

This commit is contained in:
Ray Speth 2012-02-21 16:03:09 +00:00
parent 9eb0f440a5
commit 30d233474a
33 changed files with 132 additions and 257 deletions

View file

@ -19,14 +19,6 @@ namespace VCSnonideal
*/
//@{
#ifndef MAX
# define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
#ifndef MIN
# define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
#ifndef SWAP
# define SWAP(x1, x2, temp) ((temp) = (x1), (x1) = (x2), (x2) = (temp))
#endif

View file

@ -34,8 +34,6 @@
#endif
using namespace std;
#if defined(__CYGWIN__)
#include <getopt.h>
#endif
@ -43,13 +41,6 @@ using namespace std;
#include "cantera/base/mdp_allo.h"
#include "tok_input_util.h"
#ifndef MAX
# define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
#ifndef MIN
# define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
int Debug_Flag = true;
double grtol = 1.0E-3;
double gatol = 1.0E-9;
@ -799,8 +790,8 @@ int main(int argc, char* argv[])
* Right now, if the number of data rows differ, we will punt.
* Maybe later we can do something more significant
*/
int nDataRowsMIN = MIN(nDataRows1, nDataRows2);
int nDataRowsMAX = MAX(nDataRows1, nDataRows2);
int nDataRowsMIN = std::min(nDataRows1, nDataRows2);
int nDataRowsMAX = std::max(nDataRows1, nDataRows2);
if (nDataRows1 != nDataRows2) {
printf("Number of Data rows in file1, %d, is different than file2, %d\n",
nDataRows1, nDataRows2);
@ -814,7 +805,7 @@ int main(int argc, char* argv[])
read_title(fp2, &title2, nTitleLines2);
if (nTitleLines1 > 0 || nTitleLines2 > 0) {
int n = MIN(nTitleLines1, nTitleLines2);
int n = std::min(nTitleLines1, nTitleLines2);
for (i = 0; i < n; i++) {
if (strcmp(title1[i], title2[i]) != 0) {
printf("Title Line %d differ:\n\t\"%s\"\n\t\"%s\"\n", i, title1[i], title2[i]);
@ -867,7 +858,7 @@ int main(int argc, char* argv[])
* Do a Comparison of the names to find the maximum number
* of matches.
*/
nColMAX = MAX(nCol1, nCol2);
nColMAX = std::max(nCol1, nCol2);
compColList = mdp_alloc_int_2(nColMAX, 2, -1);
nColcomparisons = 0;
@ -952,7 +943,7 @@ int main(int argc, char* argv[])
curVarValues1 = NVValues1[i1];
curVarValues2 = NVValues2[i2];
atol_j = get_atol(curVarValues1, nDataRows1, gatol);
atol_j = MIN(atol_j, get_atol(curVarValues2, nDataRows2, gatol));
atol_j = std::min(atol_j, get_atol(curVarValues2, nDataRows2, gatol));
for (j = 0; j < nDataRowsMIN; j++) {
slope1 = 0.0;

View file

@ -31,13 +31,6 @@ int MDP_MP_myproc = 0;
*/
int MDP_ALLO_errorOption = 3;
#ifndef MIN
# define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
#ifndef MAX
# define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
#define MDP_ALLOC_INTERFACE_ERROR 230346
/****************************************************************************/
@ -989,8 +982,8 @@ void mdp_realloc_dbl_2(double** *array_hdl, int ndim1, int ndim2,
if (ndim2 <= 0) {
ndim2 = 1;
}
ndim1Old = MAX(ndim1Old, 0);
ndim2Old = MAX(ndim2Old, 0);
ndim1Old = std::max(ndim1Old, 0);
ndim2Old = std::max(ndim2Old, 0);
/*
* One way to do it, if old information isn't needed. In this algorithm
* the arrays are never malloced at the same time.
@ -1014,8 +1007,8 @@ void mdp_realloc_dbl_2(double** *array_hdl, int ndim1, int ndim2,
/*
* Now, let's initialize the arrays
*/
int ndim1Min = MIN(ndim1, ndim1Old);
int ndim2Min = MIN(ndim2, ndim2Old);
int ndim1Min = std::min(ndim1, ndim1Old);
int ndim2Min = std::min(ndim2, ndim2Old);
double** array_new = *array_hdl;
/*
* When the second dimensions are equal, we can copy blocks
@ -1150,7 +1143,7 @@ void mdp_realloc_VecFixedStrings(char** *array_hdl, int numStrings,
}
array = (char**) mdp_array_alloc(2, numStrings, lenString, sizeof(char));
if (array != NULL) {
int len = MIN(numStrings, numOldStrings);
int len = std::min(numStrings, numOldStrings);
ao = *array_hdl;
if (ao) {
for (i = 0; i < len; i++) {
@ -1414,7 +1407,7 @@ void mdp_realloc_ptr_1(void** *array_hdl, int numLen, int numOldLen)
size_t bytenum = sizeof(void*) * numLen;
void** array = (void**) smalloc(bytenum);
if (array != NULL) {
int len = MIN(numLen, numOldLen);
int len = std::min(numLen, numOldLen);
if (*array_hdl) {
void** ao = *array_hdl;
for (int i = 0; i < len; i++) {

View file

@ -82,12 +82,6 @@ static void switch_pos(std::vector<size_t> &orderVector, size_t jr, size_t kspec
*/
static int mlequ(double* c, size_t idem, size_t n, double* b, size_t m);
//@{
#ifndef MIN
#define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
//@}
/*
* Choose the optimum basis for the calculations. This is done by
* choosing the species with the largest mole fraction
@ -221,7 +215,7 @@ size_t Cantera::BasisOptimize(int* usedZeroedSpecies, bool doFormRxn,
* It's equal to the minimum of the number of elements and the
* number of total species.
*/
size_t nComponents = MIN(ne, nspecies);
size_t nComponents = std::min(ne, nspecies);
size_t nNonComponents = nspecies - nComponents;
/*
* Set this return variable to false

View file

@ -29,10 +29,7 @@ using namespace std;
#include <cstdlib>
int Cantera::ChemEquil_print_lvl = 0;
//static char sbuf[1024];
#ifndef MIN
#define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
namespace Cantera
{
@ -1112,17 +1109,17 @@ int ChemEquil::dampStep(thermo_t& mix, vector_fp& oldx,
for (size_t m = 0; m < m_mm; m++) {
if (m == m_eloc) {
if (step[m] > 1.25) {
damp = MIN(damp, 1.25 /step[m]);
damp = std::min(damp, 1.25 /step[m]);
}
if (step[m] < -1.25) {
damp = MIN(damp, -1.25 / step[m]);
damp = std::min(damp, -1.25 / step[m]);
}
} else {
if (step[m] > 0.75) {
damp = MIN(damp, 0.75 /step[m]);
damp = std::min(damp, 0.75 /step[m]);
}
if (step[m] < -0.75) {
damp = MIN(damp, -0.75 / step[m]);
damp = std::min(damp, -0.75 / step[m]);
}
}
}

View file

@ -115,7 +115,7 @@ int vcs_MultiPhaseEquil::equilibrate_TV(int XY, doublereal xtarget,
doublereal Tlow = 0.5 * m_mix->minTemp();;
doublereal Thigh = 2.0 * m_mix->maxTemp();
doublereal Vnow, Verr;
int printLvlSub = MAX(0, printLvl - 1);
int printLvlSub = std::max(0, printLvl - 1);
for (int n = 0; n < maxiter; n++) {
Pnow = m_mix->pressure();
@ -238,7 +238,7 @@ int vcs_MultiPhaseEquil::equilibrate_HP(doublereal Htarget,
doublereal Hhigh = Undef;
doublereal Herr, HConvErr;
doublereal Tnow = m_mix->temperature();
int printLvlSub = MAX(printLvl - 1, 0);
int printLvlSub = std::max(printLvl - 1, 0);
for (int n = 0; n < maxiter; n++) {
@ -303,8 +303,8 @@ int vcs_MultiPhaseEquil::equilibrate_HP(doublereal Htarget,
dT = 200.;
}
}
double acpb = MAX(fabs(cpb), 1.0E-6);
double denom = MAX(fabs(Htarget), acpb);
double acpb = std::max(fabs(cpb), 1.0E-6);
double denom = std::max(fabs(Htarget), acpb);
Herr = Htarget - Hnow;
HConvErr = fabs((Herr)/denom);
addLogEntry("T",fp2str(m_mix->temperature()));
@ -399,7 +399,7 @@ int vcs_MultiPhaseEquil::equilibrate_SP(doublereal Starget,
if (Tnow > Thigh) {
Thigh = Tnow;
}
int printLvlSub = MAX(printLvl - 1, 0);
int printLvlSub = std::max(printLvl - 1, 0);
for (int n = 0; n < maxiter; n++) {
@ -456,7 +456,7 @@ int vcs_MultiPhaseEquil::equilibrate_SP(doublereal Starget,
if (Tnew > Thigh || Tnew < Tlow) {
dTmax = 1.5*fabs(Thigh - Tlow);
}
dTmax = MIN(dTmax, 300.);
dTmax = std::min(dTmax, 300.);
if (dTa > dTmax) {
dT *= dTmax/dTa;
}
@ -465,8 +465,8 @@ int vcs_MultiPhaseEquil::equilibrate_SP(doublereal Starget,
dT = Tnew - Tnow;
}
double acpb = MAX(fabs(cpb), 1.0E-6);
double denom = MAX(fabs(Starget), acpb);
double acpb = std::max(fabs(cpb), 1.0E-6);
double denom = std::max(fabs(Starget), acpb);
Serr = Starget - Snow;
SConvErr = fabs((Serr)/denom);
addLogEntry("T",fp2str(m_mix->temperature()));
@ -649,7 +649,7 @@ int vcs_MultiPhaseEquil::equilibrate_TP(int estimateEquil,
* Call the thermo Program
*/
int ip1 = m_printLvl;
int ipr = MAX(0, m_printLvl-1);
int ipr = std::max(0, m_printLvl-1);
if (m_printLvl >= 3) {
ip1 = m_printLvl - 2;
} else {

View file

@ -638,14 +638,14 @@ void vcs_VolPhase::setMolesFromVCS(const int stateCalc,
for (size_t k = 0; k < m_numSpecies; k++) {
if (m_speciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
kglob = IndSpecies[k];
v_totalMoles += MAX(0.0, molesSpeciesVCS[kglob]);
v_totalMoles += std::max(0.0, molesSpeciesVCS[kglob]);
}
}
if (v_totalMoles > 0.0) {
for (size_t k = 0; k < m_numSpecies; k++) {
if (m_speciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
kglob = IndSpecies[k];
tmp = MAX(0.0, molesSpeciesVCS[kglob]);
tmp = std::max(0.0, molesSpeciesVCS[kglob]);
Xmol_[k] = tmp / v_totalMoles;
}
}

View file

@ -96,7 +96,7 @@ bool VCS_SOLVE::vcs_elabcheck(int ibound)
multisign = true;
}
if (eval != 0.0) {
scale = MAX(scale, fabs(eval * m_molNumSpecies_old[kspec]));
scale = std::max(scale, fabs(eval * m_molNumSpecies_old[kspec]));
numNonZero++;
}
}
@ -280,7 +280,7 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
double eval = m_formulaMatrix[i][kspec];
diff -= eval * m_molNumSpecies_old[kspec];
}
m_molNumSpecies_old[compID] = MAX(0.0,diff/m_formulaMatrix[i][compID]);
m_molNumSpecies_old[compID] = std::max(0.0,diff/m_formulaMatrix[i][compID]);
changed = true;
}
}
@ -471,7 +471,7 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
xx /= its;
}
m_molNumSpecies_old[kspec] += xx;
m_molNumSpecies_old[kspec] = MAX(m_molNumSpecies_old[kspec], 1.0E-10);
m_molNumSpecies_old[kspec] = std::max(m_molNumSpecies_old[kspec], 1.0E-10);
/*
* If we are dealing with a deleted species, then
* we need to reinsert it into the active list.

View file

@ -318,7 +318,7 @@ int vcs_equilibrate_1(MultiPhase& s, int ixy,
addLogEntry("loglevel",loglevel);
endLogGroup("arguments");
int printLvlSub = MAX(0, printLvl-1);
int printLvlSub = std::max(0, printLvl-1);
s.init();
@ -413,7 +413,7 @@ int vcs_determine_PhaseStability(MultiPhase& s, int iphase,
addLogEntry("loglevel",loglevel);
endLogGroup("arguments");
int printLvlSub = MAX(0, printLvl-1);
int printLvlSub = std::max(0, printLvl-1);
s.init();
try {

View file

@ -595,7 +595,7 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
if ((jph != iphasePop) && (!m_SSPhase[j])) {
double fdeltaJ = fabs(deltaJ);
if (m_molNumSpecies_old[j] > 0.0) {
ratioComp = MAX(ratioComp, fdeltaJ/ m_molNumSpecies_old[j]);
ratioComp = std::max(ratioComp, fdeltaJ/ m_molNumSpecies_old[j]);
}
}
}
@ -895,7 +895,7 @@ double VCS_SOLVE::vcs_phaseStabilityTest(const size_t iph)
for (k = 0; k < Vphase->nSpecies(); k++) {
if (fabs(damp * delFrac[k]) > 0.3*fabs(fracDelta_old[k])) {
damp = MAX(0.3*fabs(fracDelta_old[k]) / fabs(delFrac[k]),
damp = std::max(0.3*fabs(fracDelta_old[k]) / fabs(delFrac[k]),
1.0E-8/fabs(delFrac[k]));
}
if (delFrac[k] < 0.0) {

View file

@ -344,7 +344,7 @@ int VCS_SOLVE::vcs_report(int iconv)
lx = 0.0;
} else {
if (tpmoles > 0.0 && m_molNumSpecies_old[l] > 0.0) {
double tmp = MAX(VCS_DELETE_MINORSPECIES_CUTOFF, m_molNumSpecies_old[l]);
double tmp = std::max(VCS_DELETE_MINORSPECIES_CUTOFF, m_molNumSpecies_old[l]);
lx = log(tmp) - log(tpmoles);
} else {
lx = m_feSpecies_old[l] - m_SSfeSpecies[l]

View file

@ -140,7 +140,7 @@ int vcsUtil_root1d(double xmin, double xmax, size_t itmax,
double xPosF = 0.0;
double xNegF = 0.0;
double fnorm; /* A valid norm for the making the function value
* dimensionless */
* dimensionless */
double c[9], f[3], xn1, xn2, x0 = 0.0, f0 = 0.0, root, theta, xquad;
callNum++;
@ -273,7 +273,7 @@ int vcsUtil_root1d(double xmin, double xmax, size_t itmax,
xquad = xn1;
}
theta = fabs(xquad - xnew) / fabs(xnew - x2);
theta = MIN(1.0, theta);
theta = std::min(1.0, theta);
xnew = theta * xnew + (1.0 - theta) * xquad;
#ifdef DEBUG_MODE
if (printLvl >= 3) {

View file

@ -317,7 +317,7 @@ int VCS_SOLVE::vcs(VCS_PROB* vprob, int ifunc, int ipr, int ip1, int maxit)
size_t nspecies0, nelements0, nphase0;
Cantera::clockWC tickTock;
int iprintTime = MAX(ipr, ip1);
int iprintTime = std::max(ipr, ip1);
if (m_timing_print_lvl < iprintTime) {
iprintTime = m_timing_print_lvl ;
}
@ -495,7 +495,7 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
* m_numRxnTot = number of noncomponents, also equal to the
* number of reactions
*/
m_numRxnTot = MAX(nspecies - nelements, 0);
m_numRxnTot = std::max<size_t>(nspecies - nelements, 0);
m_numRxnRdc = m_numRxnTot;
/*
* number of minor species rxn -> all species rxn are major at the start.
@ -509,7 +509,7 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
#ifdef DEBUG_MODE
m_debug_print_lvl = pub->vcs_debug_print_lvl;
#else
m_debug_print_lvl = MIN(2, pub->vcs_debug_print_lvl);
m_debug_print_lvl = std::min(2, pub->vcs_debug_print_lvl);
#endif
/*

View file

@ -867,7 +867,7 @@ L_MAINLOOP_ALL_SPECIES:
if (sc_irxn[j] != 0.0) {
wx[j] = m_molNumSpecies_old[j] + sc_irxn[j] * dx;
if (wx[j] <= m_molNumSpecies_old[j] * 0.01 - 1.0E-150) {
dx = MAX(dx, m_molNumSpecies_old[j] * -0.99 / sc_irxn[j]);
dx = std::max(dx, m_molNumSpecies_old[j] * -0.99 / sc_irxn[j]);
}
} else {
wx[j] = m_molNumSpecies_old[j];
@ -2224,7 +2224,7 @@ int VCS_SOLVE::delta_species(const size_t kspec, double* const delta_ptr)
tmp = sc_irxn[j] * dx;
if (-tmp > m_molNumSpecies_old[j]) {
retn = 0;
dx = MIN(dx, - m_molNumSpecies_old[j] / sc_irxn[j]);
dx = std::min(dx, - m_molNumSpecies_old[j] / sc_irxn[j]);
}
}
/*
@ -2886,7 +2886,7 @@ size_t VCS_SOLVE::vcs_add_all_deleted()
kspec = m_indexRxnToSpecies[irxn];
iph = m_phaseID[kspec];
if (m_tPhaseMoles_old[iph] > 0.0) {
double maxDG = MIN(m_deltaGRxn_new[irxn], 690.0);
double maxDG = std::min(m_deltaGRxn_new[irxn], 690.0);
double dx = m_tPhaseMoles_old[iph] * exp(- maxDG);
m_molNumSpecies_new[kspec] = dx;
if (m_molNumSpecies_new[kspec] > 2 *VCS_DELETE_MINORSPECIES_CUTOFF) {
@ -3256,7 +3256,7 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[],
* It's equal to the minimum of the number of elements and the
* number of total species.
*/
ncTrial = MIN(m_numElemConstraints, m_numSpeciesTot);
ncTrial = std::min(m_numElemConstraints, m_numSpeciesTot);
m_numComponents = ncTrial;
*usedZeroedSpecies = false;
@ -3349,7 +3349,7 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[],
double nu = m_formulaMatrix[j][kspec];
if (nu != 0.0) {
nonZeroesKspec++;
maxConcPossKspec = MIN(m_elemAbundancesGoal[j] / nu, maxConcPossKspec);
maxConcPossKspec = std::min(m_elemAbundancesGoal[j] / nu, maxConcPossKspec);
}
}
}
@ -5098,7 +5098,7 @@ void VCS_SOLVE::vcs_deltag(const int l, const bool doDeleted,
}
}
if (icase) {
deltaGRxn[irxn] = MAX(0.0, deltaGRxn[irxn]);
deltaGRxn[irxn] = std::max(0.0, deltaGRxn[irxn]);
}
}
}
@ -5118,7 +5118,7 @@ void VCS_SOLVE::vcs_deltag(const int l, const bool doDeleted,
}
}
if (icase) {
deltaGRxn[irxn] = MAX(0.0, deltaGRxn[irxn]);
deltaGRxn[irxn] = std::max(0.0, deltaGRxn[irxn]);
}
}
} else {
@ -5139,7 +5139,7 @@ void VCS_SOLVE::vcs_deltag(const int l, const bool doDeleted,
}
}
if (icase) {
deltaGRxn[irxn] = MAX(0.0, deltaGRxn[irxn]);
deltaGRxn[irxn] = std::max(0.0, deltaGRxn[irxn]);
}
}
}
@ -5750,7 +5750,7 @@ double VCS_SOLVE::vcs_birthGuess(const int kspec)
if (m_molNumSpecies_old[j] > 0.0) {
double tmp = sc_irxn[j] * dx;
if (3.0*(-tmp) > m_molNumSpecies_old[j]) {
dx = MIN(dx, - 0.3333* m_molNumSpecies_old[j] / sc_irxn[j]);
dx = std::min(dx, - 0.3333* m_molNumSpecies_old[j] / sc_irxn[j]);
}
}
if (m_molNumSpecies_old[j] <= 0.0) {

View file

@ -243,7 +243,7 @@ int vcs_max_int(const int* vector, int length)
}
retn = vector[0];
for (i = 1; i < length; i++) {
retn = MAX(retn, vector[i]);
retn = std::max(retn, vector[i]);
}
return retn;
}

View file

@ -44,10 +44,6 @@ static doublereal calcWeightedNorm(const doublereal [], const doublereal dx[], s
* PROTOTYPES and PREPROC DIRECTIVES FOR MISC. ROUTINES
*****************************************************************************/
#ifndef MAX
# define MAX(x,y) (( (x) > (y) ) ? (x) : (y)) /* max function */
#endif
#ifndef DAMPING
# define DAMPING true
#endif
@ -132,9 +128,9 @@ solveSP::solveSP(ImplicitSurfChem* surfChemPtr, int bulkFunc) :
m_maxTotSpecies = 0;
for (size_t n = 0; n < m_numSurfPhases; n++) {
size_t tsp = m_objects[n]->nTotalSpecies();
m_maxTotSpecies = MAX(m_maxTotSpecies, tsp);
m_maxTotSpecies = std::max(m_maxTotSpecies, tsp);
}
m_maxTotSpecies = MAX(m_maxTotSpecies, m_neq);
m_maxTotSpecies = std::max(m_maxTotSpecies, m_neq);
m_netProductionRatesSave.resize(m_maxTotSpecies, 0.0);
@ -179,7 +175,7 @@ solveSP::solveSP(ImplicitSurfChem* surfChemPtr, int bulkFunc) :
}
// Dimension solution vector
size_t dim1 = MAX(1, m_neq);
size_t dim1 = std::max<size_t>(1, m_neq);
m_CSolnSP.resize(dim1, 0.0);
m_CSolnSPInit.resize(dim1, 0.0);
m_CSolnSPOld.resize(dim1, 0.0);
@ -469,7 +465,7 @@ int solveSP::solveSurfProb(int ifunc, doublereal time_scale, doublereal TKelvin,
m_CSolnSP[irow] -= damp * m_resid[irow];
}
for (size_t irow = 0; irow < m_neq; irow++) {
m_CSolnSP[irow] = MAX(0.0, m_CSolnSP[irow]);
m_CSolnSP[irow] = std::max(0.0, m_CSolnSP[irow]);
}
updateState(DATA_PTR(m_CSolnSP));
@ -855,8 +851,8 @@ static doublereal calc_damping(doublereal x[], doublereal dxneg[], size_t dim, i
} else if (xnew < xbot) {
damp = APPROACH * x[i] / dxneg[i];
*label = int(i);
} else if (xnew > 3.0*MAX(x[i], 1.0E-10)) {
damp = - 2.0 * MAX(x[i], 1.0E-10) / dxneg[i];
} else if (xnew > 3.0*std::max(x[i], 1.0E-10)) {
damp = - 2.0 * std::max(x[i], 1.0E-10) / dxneg[i];
*label = int(i);
}
}

View file

@ -441,7 +441,7 @@ void BEulerInt::computeResidWts(GeneralMatrix& jac)
m_residWts[i] = fabs(data[i] * m_ewt[0]);
for (j = 1; j < m_neq; j++) {
value = fabs(data[j*m_neq + i] * m_ewt[j]);
m_residWts[i] = MAX(m_residWts[i], value);
m_residWts[i] = std::max(m_residWts[i], value);
}
}
}
@ -645,7 +645,7 @@ static void print_lvl1_summary(
double subtractRD(double a, double b)
{
double diff = a - b;
double d = MIN(fabs(a), fabs(b));
double d = std::min(fabs(a), fabs(b));
d *= 1.0E-14;
double ad = fabs(diff);
if (ad < 1.0E-300) {
@ -1027,7 +1027,7 @@ double BEulerInt::time_step_control(int order, double time_error_factor)
/*
* Special case time_error_factor so that zeroes don't cause a problem.
*/
time_error_factor = MAX(1.0E-50, time_error_factor);
time_error_factor = std::max(1.0E-50, time_error_factor);
/*
* Calculate the factor for the change in magnitude of time step.
@ -1050,7 +1050,7 @@ double BEulerInt::time_step_control(int order, double time_error_factor)
}
delta_t = - 0.5 * delta_t_n;
} else {
factor = MIN(factor, 1.5);
factor = std::min(factor, 1.5);
delta_t = factor * delta_t_n;
}
return delta_t;
@ -1312,8 +1312,8 @@ double BEulerInt::step(double t_max)
m_order = 1; /* Forward/Backward Euler */
} else if (m_time_step_num > 2) {
m_order = 1; /* Specified
Predictor/Corrector
- not implemented */
Predictor/Corrector
- not implemented */
}
/*
@ -1497,7 +1497,7 @@ double BEulerInt::step(double t_max)
* if the recent "History" of the time step behavior is still bad
*/
else if (m_failure_counter > 0) {
delta_t_np1 = MIN(delta_t_np1, delta_t_n);
delta_t_np1 = std::min(delta_t_np1, delta_t_n);
}
} else {
delta_t_np1 = delta_t_n;
@ -1523,7 +1523,7 @@ double BEulerInt::step(double t_max)
double target_time_step = delta_t_n
*(1.0 - iter_diff*fabs(iter_diff)/
((2.0*iter_adjust_zone*iter_adjust_zone)));
target_time_step = MAX(0.5*delta_t_n, target_time_step);
target_time_step = std::max(0.5*delta_t_n, target_time_step);
if (target_time_step < delta_t_np1) {
printf("\tNext time step will be decreased from %g to %g"
" because of new its restraint\n",
@ -1589,7 +1589,7 @@ double BEulerInt::step(double t_max)
/*
* Decrement the number of consequative failure counter.
*/
m_failure_counter = MAX(0, m_failure_counter-1);
m_failure_counter = std::max(0, m_failure_counter-1);
/*
* Print out final results of a successfull time step.
@ -1933,23 +1933,23 @@ double BEulerInt::boundStep(const double* const y,
(fabs(y_new-y[i]) > m_ewt[i])) {
ff = fabs(y[i]/(y_new - y[i]));
ff_alt = fabs(m_ewt[i] / (y_new - y[i]));
ff = MAX(ff, ff_alt);
ff = std::max(ff, ff_alt);
ifbd = 1;
}
if ((fabs(5.0 * y_new) < fabs(y[i])) &&
(fabs(y_new - y[i]) > m_ewt[i])) {
ff = y[i]/(y_new-y[i]) * (1.0 - 5.0)/5.0;
ff_alt = fabs(m_ewt[i] / (y_new - y[i]));
ff = MAX(ff, ff_alt);
ff = std::max(ff, ff_alt);
ifbd = 0;
}
if (ff < f_delta_bounds) {
f_delta_bounds = ff;
i_fbd = ifbd;
}
f_delta_bounds = MIN(f_delta_bounds, ff);
f_delta_bounds = std::min(f_delta_bounds, ff);
}
fbound = MIN(f_lowbounds, f_delta_bounds);
fbound = std::min(f_lowbounds, f_delta_bounds);
/*
* Report on any corrections
*/

View file

@ -29,12 +29,6 @@
#include "cantera/base/mdp_allo.h"
#ifndef MAX
# define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
#ifndef MIN
# define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
#define OPT_SIZE 10
#define SUCCESS 0

View file

@ -35,10 +35,6 @@
//@{
#ifndef MAX
#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
#ifndef CONSTD_DATA_PTR
#define CONSTD_DATA_PTR(x) (( const doublereal *) (&x[0]))
#endif
@ -915,7 +911,7 @@ void NonlinearSolver::calcSolnToResNormVector()
}
if (checkUserResidualTols_ == 2) {
for (size_t irow = 0; irow < neq_; irow++) {
m_residWts[irow] = MIN(m_residWts[irow], userResidAtol_[irow] + userResidRtol_ * m_rowWtScales[irow] / neq_);
m_residWts[irow] = std::min(m_residWts[irow], userResidAtol_[irow] + userResidRtol_ * m_rowWtScales[irow] / neq_);
}
}
} else {
@ -1995,7 +1991,7 @@ void NonlinearSolver::setDefaultDeltaBoundsMagnitudes()
{
for (size_t i = 0; i < neq_; i++) {
m_deltaStepMinimum[i] = 1000. * atolk_[i];
m_deltaStepMinimum[i] = MAX(m_deltaStepMinimum[i], 0.1 * fabs(m_y_n_curr[i]));
m_deltaStepMinimum[i] = std::max(m_deltaStepMinimum[i], 0.1 * fabs(m_y_n_curr[i]));
}
}
//====================================================================================================================
@ -2065,14 +2061,14 @@ NonlinearSolver::deltaBoundStep(const doublereal* const y_n_curr, const doublere
(fabs(y_new - y_n_curr[i]) > m_deltaStepMinimum[i])) {
ff = (UPFAC - 1.0) * fabs(y_n_curr[i]/(y_new - y_n_curr[i]));
ff_alt = fabs(m_deltaStepMinimum[i] / (y_new - y_n_curr[i]));
ff = MAX(ff, ff_alt);
ff = std::max(ff, ff_alt);
ifbd = 1;
}
if ((fabs(2.0 * y_new) < fabs(y_n_curr[i])) &&
(fabs(y_new - y_n_curr[i]) > m_deltaStepMinimum[i])) {
ff = y_n_curr[i]/(y_new - y_n_curr[i]) * (1.0 - 2.0)/2.0;
ff_alt = fabs(m_deltaStepMinimum[i] / (y_new - y_n_curr[i]));
ff = MAX(ff, ff_alt);
ff = std::max(ff, ff_alt);
ifbd = 0;
}
} else {
@ -2083,7 +2079,7 @@ NonlinearSolver::deltaBoundStep(const doublereal* const y_n_curr, const doublere
if (fabs(y_n_curr[i]) > m_deltaStepMinimum[i]) {
ff = y_n_curr[i]/(y_new - y_n_curr[i]) * (1.0 - 2.0)/2.0;
ff_alt = fabs(m_deltaStepMinimum[i] / (y_new - y_n_curr[i]));
ff = MAX(ff, ff_alt);
ff = std::max(ff, ff_alt);
if (y_n_curr[i] >= 0.0) {
ifbd = 0;
} else {
@ -2096,7 +2092,7 @@ NonlinearSolver::deltaBoundStep(const doublereal* const y_n_curr, const doublere
else if (fabs(y_new) > 0.5 * fabs(y_n_curr[i])) {
ff = y_n_curr[i]/(y_new - y_n_curr[i]) * (-1.5);
ff_alt = fabs(m_deltaStepMinimum[i] / (y_new - y_n_curr[i]));
ff = MAX(ff, ff_alt);
ff = std::max(ff, ff_alt);
ifbd = 0;
}
}
@ -2419,7 +2415,7 @@ doublereal NonlinearSolver::boundStep(const doublereal* const y, const doublerea
}
doublereal f_delta_bounds = deltaBoundStep(y, step0);
fbound = MIN(f_bounds, f_delta_bounds);
fbound = std::min(f_bounds, f_delta_bounds);
return fbound;
}
@ -3669,7 +3665,7 @@ print_solnDelta_norm_contrib(const doublereal* const step_1,
static inline doublereal subtractRD(doublereal a, doublereal b)
{
doublereal diff = a - b;
doublereal d = MIN(fabs(a), fabs(b));
doublereal d = std::min(fabs(a), fabs(b));
d *= 1.0E-14;
doublereal ad = fabs(diff);
if (ad < 1.0E-300) {
@ -4045,7 +4041,7 @@ NonlinearSolver::computeResidWts()
if (checkUserResidualTols_ == 2) {
for (size_t i = 0; i < neq_; i++) {
double uR = userResidAtol_[i] + userResidRtol_ * m_rowWtScales[i] / neq_;
m_residWts[i] = MIN(m_residWts[i], uR);
m_residWts[i] = std::min(m_residWts[i], uR);
}
}
}

View file

@ -36,16 +36,6 @@ using namespace std;
namespace Cantera
{
#ifndef MAX
# define MAX(x,y) (( (x) > (y) ) ? (x) : (y)) /* max function */
#endif
#ifndef MIN
# define MIN(x,y) (( (x) < (y) ) ? (x) : (y)) /* min function */
#endif
#ifndef SQUARE
# define SQUARE(x) ( (x) * (x) )
#endif
@ -315,7 +305,7 @@ bool RootFind::theSame(doublereal x2, doublereal x1, doublereal factor) const
doublereal x = fabs(x2) + fabs(x1);
doublereal deltaX = delXMeaningful(x);
doublereal deltaXSmall = factor * deltaX;
deltaXSmall = MAX(deltaXSmall , x * 1.0E-15);
deltaXSmall = std::max(deltaXSmall , x * 1.0E-15);
if (fabs(x2 - x1) < deltaXSmall) {
return true;
}
@ -623,13 +613,13 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
if (f2 < 0.0) {
if (FuncIsGenerallyIncreasing_) {
if (slopePointingToHigher) {
xnew = MIN(x2 + 3.0*DeltaXnorm_, xnew);
xnew = std::min(x2 + 3.0*DeltaXnorm_, xnew);
} else {
xnew = x2 + DeltaXnorm_;
}
} else if (FuncIsGenerallyDecreasing_) {
if (!slopePointingToHigher) {
xnew = MAX(x2 - 3.0*DeltaXnorm_, xnew);
xnew = std::max(x2 - 3.0*DeltaXnorm_, xnew);
} else {
xnew = x2 - DeltaXnorm_;
}
@ -643,13 +633,13 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
} else {
if (FuncIsGenerallyDecreasing_) {
if (!slopePointingToHigher) {
xnew = MAX(x2 + 3.0*DeltaXnorm_, xnew);
xnew = std::max(x2 + 3.0*DeltaXnorm_, xnew);
} else {
xnew = x2 + DeltaXnorm_;
}
} else if (FuncIsGenerallyIncreasing_) {
if (! slopePointingToHigher) {
xnew = MIN(x2 - 3.0*DeltaXnorm_, xnew);
xnew = std::min(x2 - 3.0*DeltaXnorm_, xnew);
} else {
xnew = x2 - DeltaXnorm_;
}
@ -1041,13 +1031,13 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
rfT.deltaXConverged = deltaXConverged_;
rfT.deltaFConverged = fnorm * m_rtolf;
if (foundStraddle) {
rfT.delX = MAX(fabs(deltaX2), fabs(deltaXnew));
rfT.delX = std::max(fabs(deltaX2), fabs(deltaXnew));
} else {
rfT.delX = MAX(fabs(deltaX2), fabs(deltaXnew));
rfT.delX = std::max(fabs(deltaX2), fabs(deltaXnew));
if (x2 < x1) {
rfT.delX = MAX(rfT.delX, x2 - xmin);
rfT.delX = std::max(rfT.delX, x2 - xmin);
} else {
rfT.delX = MAX(rfT.delX, xmax - x2);
rfT.delX = std::max(rfT.delX, xmax - x2);
}
}
/*

View file

@ -37,18 +37,6 @@ static doublereal calcWeightedNorm(const doublereal [], const doublereal dx[], s
* LAPACK PROTOTYPES
***************************************************************************/
/*****************************************************************************
* PROTOTYPES and PREPROC DIRECTIVES FOR MISC. ROUTINES
*****************************************************************************/
#ifndef MAX
# define MAX(x,y) (( (x) > (y) ) ? (x) : (y)) /* max function */
#endif
#ifndef MIN
# define MIN(x,y) (( (x) < (y) ) ? (x) : (y)) /* min function */
#endif
/***************************************************************************
* solveSP Class Definitinos
@ -66,7 +54,7 @@ solveProb::solveProb(ResidEval* resid) :
m_neq = m_residFunc->nEquations();
// Dimension solution vector
size_t dim1 = MAX(1, m_neq);
size_t dim1 = std::max<size_t>(1, m_neq);
m_atol.resize(dim1, 1.0E-9);
m_netProductionRatesSave.resize(dim1, 0.0);
@ -554,7 +542,7 @@ doublereal solveProb::calc_damping(doublereal x[], doublereal dxneg[], size_t di
}
}
}
damp = MIN(damp, newdamp);
damp = std::min(damp, newdamp);
}
}

View file

@ -12,10 +12,6 @@
* Contract DE-AC04-94AL85000 with Sandia Corporation, the
* U.S. Government retains certain rights in this software.
*/
//! Max function
#ifndef MAX
#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
#include "cantera/thermo/DebyeHuckel.h"
#include "cantera/thermo/ThermoFactory.h"
@ -676,11 +672,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 = MAX(m_molalities[k], xxSmall);
xx = std::max(m_molalities[k], xxSmall);
mu[k] += RT * (log(xx) + m_lnActCoeffMolal[k]);
}
}
xx = MAX(xmolSolvent, xxSmall);
xx = std::max(xmolSolvent, xxSmall);
mu[m_indexSolvent] +=
RT * (log(xx) + m_lnActCoeffMolal[m_indexSolvent]);
}
@ -1944,7 +1940,7 @@ _lnactivityWaterHelgesonFixedForm() const
double sum = 0.0;
for (size_t k = 0; k < m_kk; k++) {
if (k != m_indexSolvent) {
sum += MAX(m_molalities[k], 0.0);
sum += std::max(m_molalities[k], 0.0);
}
}
if (sum > 2.0 * m_maxIionicStrength) {
@ -2029,7 +2025,7 @@ void DebyeHuckel::s_update_lnMolalityActCoeff() const
* of the solvent
*/
double xmolSolvent = moleFraction(m_indexSolvent);
xmolSolvent = MAX(8.689E-3, xmolSolvent);
xmolSolvent = std::max(8.689E-3, xmolSolvent);
int est;
double ac_nonPolar = 1.0;
@ -2253,7 +2249,7 @@ void DebyeHuckel::s_update_dlnMolalityActCoeff_dT() const
* of the solvent
*/
double xmolSolvent = moleFraction(m_indexSolvent);
xmolSolvent = MAX(8.689E-3, xmolSolvent);
xmolSolvent = std::max(8.689E-3, xmolSolvent);
double sqrtI = sqrt(m_IionicMolality);
@ -2394,7 +2390,7 @@ void DebyeHuckel::s_update_d2lnMolalityActCoeff_dT2() const
* of the solvent
*/
double xmolSolvent = moleFraction(m_indexSolvent);
xmolSolvent = MAX(8.689E-3, xmolSolvent);
xmolSolvent = std::max(8.689E-3, xmolSolvent);
double sqrtI = sqrt(m_IionicMolality);
@ -2528,7 +2524,7 @@ void DebyeHuckel::s_update_dlnMolalityActCoeff_dP() const
* of the solvent
*/
double xmolSolvent = moleFraction(m_indexSolvent);
xmolSolvent = MAX(8.689E-3, xmolSolvent);
xmolSolvent = std::max(8.689E-3, xmolSolvent);
double sqrtI = sqrt(m_IionicMolality);

View file

@ -17,11 +17,7 @@
* Contract DE-AC04-94AL85000 with Sandia Corporation, the
* U.S. Government retains certain rights in this software.
*/
//@{
#ifndef MAX
#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
//@}
#include "cantera/thermo/HMWSoln.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/thermo/WaterProps.h"
@ -1132,11 +1128,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 = MAX(m_molalities[k], xxSmall);
xx = std::max(m_molalities[k], xxSmall);
mu[k] += RT * (log(xx) + m_lnActCoeffMolal_Scaled[k]);
}
}
xx = MAX(xmolSolvent, xxSmall);
xx = std::max(xmolSolvent, xxSmall);
mu[m_indexSolvent] +=
RT * (log(xx) + m_lnActCoeffMolal_Scaled[m_indexSolvent]);
}
@ -1894,7 +1890,7 @@ void HMWSoln::s_update_lnMolalityActCoeff() const
s_updatePitzer_lnMolalityActCoeff();
double xmolSolvent = moleFraction(m_indexSolvent);
double xx = MAX(m_xmolSolventMIN, xmolSolvent);
double xx = std::max(m_xmolSolventMIN, xmolSolvent);
double lnActCoeffMolal0 = - log(xx) + (xx - 1.0)/xx;
double lnxs = log(xx);
@ -3447,7 +3443,7 @@ s_updatePitzer_lnMolalityActCoeff() const
* ln(actcoeff[]). Therefore, we must calculate ln(actcoeff_0).
*/
double xmolSolvent = moleFraction(m_indexSolvent);
double xx = MAX(m_xmolSolventMIN, xmolSolvent);
double xx = std::max(m_xmolSolventMIN, xmolSolvent);
m_lnActCoeffMolal_Unscaled[0] = lnwateract - log(xx);
#ifdef DEBUG_MODE
if (m_debugCalc) {
@ -6238,7 +6234,7 @@ void HMWSoln::s_updateIMS_lnMolalityActCoeff() const
calcMolalities();
double xmolSolvent = moleFraction(m_indexSolvent);
double xx = MAX(m_xmolSolventMIN, xmolSolvent);
double xx = std::max(m_xmolSolventMIN, xmolSolvent);
if (IMS_typeCutoff_ == 0) {
for (size_t k = 1; k < m_kk; k++) {
IMS_lnActCoeffMolal_[k]= 0.0;

View file

@ -21,12 +21,6 @@
#include "cantera/thermo/ThermoFactory.h"
#include <cmath>
//@{
#ifndef MAX
#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
//@}
using namespace ctml;
namespace Cantera
@ -667,10 +661,10 @@ void IdealMolalSoln::getChemPotentials(doublereal* mu) const
for (size_t k = 1; k < m_kk; k++) {
xx = MAX(m_molalities[k], xxSmall);
xx = std::max(m_molalities[k], xxSmall);
mu[k] += RT * (log(xx) + IMS_lnActCoeffMolal_[k]);
}
xx = MAX(xmolSolvent, xxSmall);
xx = std::max(xmolSolvent, xxSmall);
mu[m_indexSolvent] +=
RT * (log(xx) + IMS_lnActCoeffMolal_[m_indexSolvent]);
}
@ -1190,7 +1184,7 @@ void IdealMolalSoln::s_updateIMS_lnMolalityActCoeff() const
calcMolalities();
double xmolSolvent = moleFraction(m_indexSolvent);
double xx = MAX(m_xmolSolventMIN, xmolSolvent);
double xx = std::max(m_xmolSolventMIN, xmolSolvent);
if (IMS_typeCutoff_ == 0) {
for (size_t k = 1; k < m_kk; k++) {

View file

@ -27,11 +27,6 @@
using namespace std;
#ifndef MIN
//! standard MIN function
# define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
namespace Cantera
{
@ -1176,7 +1171,7 @@ static double factorOverlap(const std::vector<std::string>& elnamesVN ,
if (elemVectorN[mn] <= 1.0E-13) {
return 0.0;
}
fMax = MIN(fMax, elemVectorN[mn]/eiNum);
fMax = std::min(fMax, elemVectorN[mn]/eiNum);
}
}
}

View file

@ -18,12 +18,6 @@
#include "cantera/thermo/GeneralSpeciesThermo.h"
#include <string>
#ifndef MIN
# define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
#ifndef MAX
# define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
using namespace std;
//======================================================================================================================
@ -135,7 +129,7 @@ doublereal LatticeSolidPhase::minTemp(size_t k) const
doublereal mm = 1.0E300;
for (size_t n = 0; n < m_nlattice; n++) {
double ml = (m_lattice[n])->minTemp(-1);
mm = MIN(mm, ml);
mm = std::min(mm, ml);
}
return mm;
}
@ -165,7 +159,7 @@ doublereal LatticeSolidPhase::maxTemp(size_t k) const
doublereal mm = -1.0E300;
for (size_t n = 0; n < m_nlattice; n++) {
double ml = (m_lattice[n])->maxTemp(-1);
mm = MAX(mm, ml);
mm = std::max(mm, ml);
}
return mm;
}

View file

@ -26,10 +26,6 @@
#include "cantera/thermo/VPSSMgr.h"
#include "cantera/thermo/PDSS.h"
#ifndef MIN
# define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
using namespace std;
namespace Cantera
@ -956,7 +952,7 @@ doublereal MixtureFugacityTP::densityCalc(doublereal TKelvin, doublereal presPa,
* Check for negative molar volumes
*/
if (molarVolBase <= 0.0) {
molarVolBase = MIN(1.0E-30, fabs(delMV*1.0E-4));
molarVolBase = std::min(1.0E-30, fabs(delMV*1.0E-4));
}
}

View file

@ -11,12 +11,6 @@
#include "cantera/base/mdp_allo.h"
#include <iomanip>
//@{
#ifndef MAX
#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
//@}
using namespace std;
using namespace ctml;
@ -503,8 +497,8 @@ void ThermoPhase::setState_HPorUV(doublereal Htarget, doublereal p,
}
// Convergence in H
double Herr = Htarget - Hnew;
double acpd = MAX(fabs(cpd), 1.0E-5);
double denom = MAX(fabs(Htarget), acpd * dTtol);
double acpd = std::max(fabs(cpd), 1.0E-5);
double denom = std::max(fabs(Htarget), acpd * dTtol);
double HConvErr = fabs((Herr)/denom);
if (HConvErr < 0.00001 *dTtol) {
return;
@ -772,8 +766,8 @@ void ThermoPhase::setState_SPorSV(doublereal Starget, doublereal p,
}
// Convergence in S
double Serr = Starget - Snew;
double acpd = MAX(fabs(cpd), 1.0E-5);
double denom = MAX(fabs(Starget), acpd * dTtol);
double acpd = std::max(fabs(cpd), 1.0E-5);
double denom = std::max(fabs(Starget), acpd * dTtol);
double SConvErr = fabs((Serr * Tnew)/denom);
if (SConvErr < 0.00001 *dTtol) {
return;

View file

@ -6,11 +6,6 @@
* Contract DE-AC04-94AL85000 with Sandia Corporation, the
* U.S. Government retains certain rights in this software.
*/
//@{
#ifndef MAX
#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
//@}
#include "cantera/thermo/WaterProps.h"
#include "cantera/base/ctml.h"

View file

@ -38,15 +38,6 @@ static const doublereal M_water = 18.015268;
* The Ratio of R/M = 0.46151805 kJ kg-1 K-1 , which is Eqn. (6.3) in the paper.
*/
static const doublereal Rgas = 8.314371E3; // Joules kmol-1 K-1
//@{
#ifndef MAX
# define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
#endif
#ifndef MIN
# define MIN(x,y) (( (x) < (y) ) ? (x) : (y))
#endif
//@}
// Base constructor
WaterPropsIAPWS:: WaterPropsIAPWS() :
@ -660,25 +651,25 @@ doublereal WaterPropsIAPWS::densSpinodalWater() const
m_phi->tdpolycalc(tau, delta);
doublereal dpdrho_old = dpdrho();
if (dpdrho_old > 0.0) {
rho_high = MIN(dens_old, rho_high);
rho_high = std::min(dens_old, rho_high);
} else {
rho_low = MAX(rho_low, dens_old);
rho_low = std::max(rho_low, dens_old);
}
doublereal dens_new = densSatLiq* (1.0001);
delta = dens_new / Rho_c;
m_phi->tdpolycalc(tau, delta);
doublereal dpdrho_new = dpdrho();
if (dpdrho_new > 0.0) {
rho_high = MIN(dens_new, rho_high);
rho_high = std::min(dens_new, rho_high);
} else {
rho_low = MAX(rho_low, dens_new);
rho_low = std::max(rho_low, dens_new);
}
bool conv = false;
for (int it = 0; it < 50; it++) {
doublereal slope = (dpdrho_new - dpdrho_old)/(dens_new - dens_old);
if (slope >= 0.0) {
slope = MAX(slope, dpdrho_new *5.0/ dens_new);
slope = std::max(slope, dpdrho_new *5.0/ dens_new);
} else {
slope = -dpdrho_new;
//slope = MIN(slope, dpdrho_new *5.0 / dens_new);
@ -686,9 +677,9 @@ doublereal WaterPropsIAPWS::densSpinodalWater() const
}
doublereal delta_rho = - dpdrho_new / slope;
if (delta_rho > 0.0) {
delta_rho = MIN(delta_rho, dens_new * 0.1);
delta_rho = std::min(delta_rho, dens_new * 0.1);
} else {
delta_rho = MAX(delta_rho, - dens_new * 0.1);
delta_rho = std::max(delta_rho, - dens_new * 0.1);
}
doublereal dens_est = dens_new + delta_rho;
if (dens_est < rho_low) {
@ -707,9 +698,9 @@ doublereal WaterPropsIAPWS::densSpinodalWater() const
m_phi->tdpolycalc(tau, delta);
dpdrho_new = dpdrho();
if (dpdrho_new > 0.0) {
rho_high = MIN(dens_new, rho_high);
rho_high = std::min(dens_new, rho_high);
} else if (dpdrho_new < 0.0) {
rho_low = MAX(rho_low, dens_new);
rho_low = std::max(rho_low, dens_new);
} else {
conv = true;
break;
@ -757,18 +748,18 @@ doublereal WaterPropsIAPWS::densSpinodalSteam() const
m_phi->tdpolycalc(tau, delta);
doublereal dpdrho_old = dpdrho();
if (dpdrho_old < 0.0) {
rho_high = MIN(dens_old, rho_high);
rho_high = std::min(dens_old, rho_high);
} else {
rho_low = MAX(rho_low, dens_old);
rho_low = std::max(rho_low, dens_old);
}
doublereal dens_new = densSatGas * (0.99);
delta = dens_new / Rho_c;
m_phi->tdpolycalc(tau, delta);
doublereal dpdrho_new = dpdrho();
if (dpdrho_new < 0.0) {
rho_high = MIN(dens_new, rho_high);
rho_high = std::min(dens_new, rho_high);
} else {
rho_low = MAX(rho_low, dens_new);
rho_low = std::max(rho_low, dens_new);
}
bool conv = false;
@ -780,14 +771,14 @@ doublereal WaterPropsIAPWS::densSpinodalSteam() const
// shouldn't be here for gas spinodal
} else {
//slope = -dpdrho_new;
slope = MIN(slope, dpdrho_new *5.0 / dens_new);
slope = std::min(slope, dpdrho_new *5.0 / dens_new);
}
doublereal delta_rho = - dpdrho_new / slope;
if (delta_rho > 0.0) {
delta_rho = MIN(delta_rho, dens_new * 0.1);
delta_rho = std::min(delta_rho, dens_new * 0.1);
} else {
delta_rho = MAX(delta_rho, - dens_new * 0.1);
delta_rho = std::max(delta_rho, - dens_new * 0.1);
}
doublereal dens_est = dens_new + delta_rho;
if (dens_est < rho_low) {
@ -806,9 +797,9 @@ doublereal WaterPropsIAPWS::densSpinodalSteam() const
m_phi->tdpolycalc(tau, delta);
dpdrho_new = dpdrho();
if (dpdrho_new < 0.0) {
rho_high = MIN(dens_new, rho_high);
rho_high = std::min(dens_new, rho_high);
} else if (dpdrho_new > 0.0) {
rho_low = MAX(rho_low, dens_new);
rho_low = std::max(rho_low, dens_new);
} else {
conv = true;
break;

View file

@ -11,9 +11,6 @@
using namespace std;
#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
/*****************************************************************/
/*****************************************************************/

View file

@ -30,8 +30,6 @@
using namespace std;
using namespace Cantera;
#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
void printDbl(double val)
{
if (fabs(val) < 5.0E-17) {

View file

@ -30,8 +30,6 @@
using namespace std;
using namespace Cantera;
#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))
void printDbl(double val)
{
if (fabs(val) < 1.0E-17) {