Fixed erroneous inequality comparisons between size_t and 0

This commit is contained in:
Ray Speth 2012-01-20 23:13:17 +00:00
parent db2b9636bb
commit 4e2a48c4e5
21 changed files with 34 additions and 38 deletions

View file

@ -999,7 +999,7 @@ namespace Cantera {
addLogEntry("element "+ s.elementName(m), fp2str(x[m]));
}
if (m_eloc >= 0) {
if (m_eloc != npos) {
adjustEloc(s, elMolesGoal);
}
/*
@ -1780,7 +1780,7 @@ namespace Cantera {
if (ChemEquil_print_lvl > 0) {
if (lumpSum[m]) {
writelogf("Lump summing row %d, due to rank deficiency analysis\n", m);
} else if (sameAsRow >= 0) {
} else if (sameAsRow != npos) {
writelogf("Identified that rows %d and %d are the same\n", m, sameAsRow);
}
}

View file

@ -440,7 +440,7 @@ namespace VCSnonideal {
for (eVP = 0; eVP < volPhase->nElemConstraints(); eVP++) {
e = volPhase->elemGlobalIndex(eVP);
#ifdef DEBUG_MODE
if (e < 0) {
if (e == npos) {
exit(EXIT_FAILURE);
}
#endif

View file

@ -318,7 +318,7 @@ namespace VCSnonideal {
iprintTime = m_timing_print_lvl ;
}
if (ifunc < 0 || ifunc > 2) {
if (ifunc > 2) {
plogf("vcs: Unrecognized value of ifunc, %d: bailing!\n",
ifunc);
return VCS_PUB_BAD;
@ -649,7 +649,7 @@ namespace VCSnonideal {
std::vector<size_t> numPhSp(nph, 0);
for (size_t kspec = 0; kspec < nspecies; kspec++) {
size_t iph = pub->PhaseID[kspec];
if (iph < 0 || iph >= nph) {
if (iph >= nph) {
plogf("%sSpecies to Phase Mapping, PhaseID, has a bad value\n",
ser);
plogf("\tPhaseID[%d] = %d\n", kspec, iph);

View file

@ -2062,7 +2062,7 @@ namespace VCSnonideal {
double tmp;
double delta = *delta_ptr;
#ifdef DEBUG_MODE
if (irxn < 0) {
if (kspec < m_numComponents) {
plogf(" --- delete_species() ERROR: called for a component %d", kspec);
plogendl();
exit(EXIT_FAILURE);
@ -3173,7 +3173,7 @@ namespace VCSnonideal {
}
if ((maxConcPossKspec >= maxConcPoss) || (maxConcPossKspec > 1.0E-5)) {
if (nonZeroesKspec <= minNonZeroes) {
if (kfound < 0 || nonZeroesKspec < minNonZeroes) {
if (kfound == npos || nonZeroesKspec < minNonZeroes) {
kfound = kspec;
} else {
// ok we are sitting pretty equal here decide on the raw ss Gibbs energy
@ -5073,8 +5073,8 @@ namespace VCSnonideal {
VCS_SPECIES_THERMO *st_tmp;
if (k1 == k2) return;
#ifdef DEBUG_MODE
if (k1 < 0 || k1 > (m_numSpeciesTot - 1) ||
k2 < 0 || k2 > (m_numSpeciesTot - 1) ) {
if (k1 > (m_numSpeciesTot - 1) ||
k2 > (m_numSpeciesTot - 1) ) {
plogf("vcs_switch_pos: ifunc = 0: inappropriate args: %d %d\n",
k1, k2);
}
@ -5143,8 +5143,8 @@ namespace VCSnonideal {
i1 = k1 - m_numComponents;
i2 = k2 - m_numComponents;
#ifdef DEBUG_MODE
if (i1 < 0 || i1 > (m_numRxnTot - 1) ||
i2 < 0 || i2 > (m_numRxnTot - 1) ) {
if (i1 > (m_numRxnTot - 1) ||
i2 > (m_numRxnTot - 1) ) {
plogf("switch_pos: ifunc = 1: inappropriate noncomp values: %d %d\n",
i1 , i2);
}

View file

@ -42,7 +42,7 @@ namespace Cantera {
InterfaceKinetics *kinPtr = k[n];
m_vecKinPtrs.push_back(kinPtr);
ns = k[n]->surfacePhaseIndex();
if (ns < 0)
if (ns == npos)
throw CanteraError("ImplicitSurfChem",
"kinetics manager contains no surface phase");
m_surfindex.push_back(ns);

View file

@ -1212,7 +1212,7 @@ namespace Cantera {
//================================================================================================
void InterfaceKinetics::setPhaseExistence(const size_t iphase, const bool exists) {
if (iphase < 0 || iphase >= m_thermo.size()) {
if (iphase >= m_thermo.size()) {
throw CanteraError("InterfaceKinetics:setPhaseExistence", "out of bounds");
}
if (exists) {

View file

@ -153,7 +153,7 @@ namespace Cantera {
* "<unknown>" is returned.
*/
string Kinetics::kineticsSpeciesName(size_t k) const {
for (size_t n = m_start.size()-1; n >= 0; n--) {
for (size_t n = m_start.size()-1; n != npos; n--) {
if (k >= m_start[n]) {
return thermo(n).speciesName(k - m_start[n]);
}

View file

@ -845,7 +845,7 @@ namespace Cantera {
size_t m = m_enamemap[element]-1; //ph.elementIndex(element);
r.element = element;
if (m < 0) return -1;
if (m == npos) return -1;
s.getFwdRatesOfProgress(DATA_PTR(m_ropf));
s.getRevRatesOfProgress(DATA_PTR(m_ropr));

View file

@ -77,7 +77,7 @@ namespace Cantera {
for (size_t n = 0; n < numPossibleSurfPhases; n++) {
InterfaceKinetics *m_kin = m_objects[n];
size_t surfPhaseIndex = m_kin->surfacePhaseIndex();
if (surfPhaseIndex >= 0) {
if (surfPhaseIndex != npos) {
m_numSurfPhases++;
m_indexKinObjSurfPhase.push_back(n);
m_kinObjPhaseIDSurfPhase.push_back(surfPhaseIndex);

View file

@ -87,7 +87,7 @@ namespace Cantera {
for (m = 0; m < nr; m++) {
sum = 0.0;
for (j = m - m_kl; j <= m + m_ku; j++) {
if (j >= 0 && j < m_n)
if (j < m_n)
sum += _value(m,j)*b[j];
}
prod[m] = sum;
@ -105,7 +105,7 @@ namespace Cantera {
for (n = 0; n < nc; n++) {
sum = 0.0;
for (i = n - m_ku; i <= n + m_kl; i++) {
if (i >= 0 && i < m_n)
if (i < m_n)
sum += _value(i,n)*b[i];
}
prod[n] = sum;

View file

@ -62,7 +62,7 @@ namespace Cantera {
knew = newmech.speciesIndex(nm);
// copy this species from the old to the new solution vectors
if (knew >= 0) {
if (knew != npos) {
for (j = 0; j < points; j++) {
newSoln[nv_new*j + 4 + knew] = oldSoln[nv_old*j + 4 + k];
}
@ -364,7 +364,7 @@ namespace Cantera {
// update thermodynamic properties only if a Jacobian is not
// being evaluated
if (jpt < 0) { //if (jpt < 0 || (m_transport_option == c_Multi_Transport)) {
if (jpt == npos) { //if (jpt < 0 || (m_transport_option == c_Multi_Transport)) {
updateThermo(x, j0, j1);
// update transport properties only if a Jacobian is not being
@ -668,7 +668,7 @@ namespace Cantera {
// update thermodynamic properties only if a Jacobian is not
// being evaluated
if (jpt < 0) {
if (jpt == npos) {
updateThermo(x, j0, j1);
updateTransport(x, j0, j1);
}
@ -1097,7 +1097,7 @@ namespace Cantera {
}
else goto error;
}
else if (m_thermo->speciesIndex(nm) >= 0) {
else if (m_thermo->speciesIndex(nm) != npos) {
writelog(nm+" ");
if (x.size() == np) {
k = m_thermo->speciesIndex(nm);

View file

@ -24,7 +24,7 @@ namespace Cantera {
void Bdry1D::
_init(size_t n) {
if (m_index < 0) {
if (m_index == npos) {
throw CanteraError("Bdry1D",
"install in container before calling init.");
}

View file

@ -417,7 +417,7 @@ namespace Cantera {
* Name of the species with index k
*/
string Constituents::speciesName(size_t k) const {
if (k < 0 || k >= nSpecies())
if (k >= nSpecies())
throw SpeciesRangeError("Constituents::speciesName",
k, nSpecies());
return m_speciesNames[k];

View file

@ -318,7 +318,7 @@ namespace Cantera {
AssertThrowMsg(m_entropy298[m] != ENTROPY298_UNKNOWN,
"Elements::entropy298",
"Entropy at 298 K of element is unknown");
AssertTrace(m >= 0 && m < m_mm);
AssertTrace(m < m_mm);
return (m_entropy298[m]);
}

View file

@ -772,7 +772,7 @@ namespace Cantera {
//! Get the id for the next cation
icat = cationList_[k];
jNeut = fm_invert_ionForNeutral[icat];
if (jNeut >= 0) {
if (jNeut != npos) {
fmij = fm_neutralMolec_ions_[icat + jNeut * m_kk];
AssertTrace(fmij != 0.0);
NeutralMolecMoleFractions_[jNeut] += moleFractions_[icat] / fmij;
@ -885,7 +885,7 @@ namespace Cantera {
//! Get the id for the next cation
icat = cationList_[k];
jNeut = fm_invert_ionForNeutral[icat];
if (jNeut >= 0) {
if (jNeut != npos) {
fmij = fm_neutralMolec_ions_[icat + jNeut * m_kk];
AssertTrace(fmij != 0.0);
dy[jNeut] += dx[icat] / fmij;

View file

@ -153,7 +153,7 @@ namespace Cantera {
doublereal* s_R) const {
//m_vpssmgr_ptr->setState_T(temp);
m_PDSS_ptr->setTemperature(temp);
AssertThrowMsg(m_speciesIndex >= 0, "STITbyPDSS::updatePropertiesTemp",
AssertThrowMsg(m_speciesIndex != npos, "STITbyPDSS::updatePropertiesTemp",
"object was probably not installed correctly");
h_RT[m_speciesIndex] = m_PDSS_ptr->enthalpy_RT_ref();
cp_R[m_speciesIndex] = m_PDSS_ptr->cp_R_ref();

View file

@ -680,7 +680,7 @@ namespace Cantera {
// otherwise, throw an exception
map<string,string>::const_iterator _b = comp.begin();
for (; _b != comp.end(); ++_b) {
if (th.elementIndex(_b->first) < 0) {
if (th.elementIndex(_b->first) == npos) {
if (rule == 0) {
throw CanteraError("installSpecies",
"Species " + s["name"] +

View file

@ -46,9 +46,9 @@ namespace CanteraZeroD {
* species is not present in the upstream mixture.
*/
doublereal FlowDevice::outletSpeciesMassFlowRate(size_t k) {
if (k < 0 || k >= m_nspout) return 0.0;
if (k >= m_nspout) return 0.0;
size_t ki = m_out2in[k];
if (ki < 0) return 0.0;
if (ki == npos) return 0.0;
return m_mdot * m_in->massFraction(ki);
}

View file

@ -357,7 +357,7 @@ namespace CanteraZeroD {
kp = m_wall[m]->kinetics(m_lr[m])->reactionPhaseIndex();
th = &m_wall[m]->kinetics(m_lr[m])->thermo(kp);
k = th->speciesIndex(nm);
if (k >= 0) {
if (k != npos) {
return k + 2 + m_nsp + walloffset;
}
else {

View file

@ -1043,7 +1043,7 @@ AxiStagnBVP::AxiStagnBVP(igthermo_t* ph, int nsp, int points) :
}
else goto error;
}
else if (m_thermo->speciesIndex(nm) >= 0) {
else if (m_thermo->speciesIndex(nm) != npos) {
writelog(nm+" ");
if ((int) x.size() == np) {
k = m_thermo->speciesIndex(nm);

View file

@ -315,11 +315,7 @@ static double *smalloc(size_t n)
FILE *file;
#endif
double *pntr;
if (n < 0) {
Fprintf(stderr, "smalloc ERROR: Non-positive argument. (%d)\n", int(n));
return NULL;
}
else if (n == 0) pntr = NULL;
if (n == 0) pntr = NULL;
else {
n = ((n - 1) / 8);
n = (n + 1) * 8;