diff --git a/Cantera/src/equil/ChemEquil.cpp b/Cantera/src/equil/ChemEquil.cpp index 9685927b1..4a2a4613e 100755 --- a/Cantera/src/equil/ChemEquil.cpp +++ b/Cantera/src/equil/ChemEquil.cpp @@ -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); } } diff --git a/Cantera/src/equil/vcs_prob.cpp b/Cantera/src/equil/vcs_prob.cpp index 2178e91ef..3090319cf 100644 --- a/Cantera/src/equil/vcs_prob.cpp +++ b/Cantera/src/equil/vcs_prob.cpp @@ -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 diff --git a/Cantera/src/equil/vcs_solve.cpp b/Cantera/src/equil/vcs_solve.cpp index ae8f282c9..f9eb0892e 100644 --- a/Cantera/src/equil/vcs_solve.cpp +++ b/Cantera/src/equil/vcs_solve.cpp @@ -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 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); diff --git a/Cantera/src/equil/vcs_solve_TP.cpp b/Cantera/src/equil/vcs_solve_TP.cpp index 91af5823a..b134b81a6 100644 --- a/Cantera/src/equil/vcs_solve_TP.cpp +++ b/Cantera/src/equil/vcs_solve_TP.cpp @@ -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); } diff --git a/Cantera/src/kinetics/ImplicitSurfChem.cpp b/Cantera/src/kinetics/ImplicitSurfChem.cpp index c090dcedc..eee9233f1 100644 --- a/Cantera/src/kinetics/ImplicitSurfChem.cpp +++ b/Cantera/src/kinetics/ImplicitSurfChem.cpp @@ -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); diff --git a/Cantera/src/kinetics/InterfaceKinetics.cpp b/Cantera/src/kinetics/InterfaceKinetics.cpp index f51c66fc7..74cfef02c 100644 --- a/Cantera/src/kinetics/InterfaceKinetics.cpp +++ b/Cantera/src/kinetics/InterfaceKinetics.cpp @@ -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) { diff --git a/Cantera/src/kinetics/Kinetics.cpp b/Cantera/src/kinetics/Kinetics.cpp index bb6c512f1..3ba4825a1 100644 --- a/Cantera/src/kinetics/Kinetics.cpp +++ b/Cantera/src/kinetics/Kinetics.cpp @@ -153,7 +153,7 @@ namespace Cantera { * "" 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]); } diff --git a/Cantera/src/kinetics/ReactionPath.cpp b/Cantera/src/kinetics/ReactionPath.cpp index cc8450a67..406c78c2a 100644 --- a/Cantera/src/kinetics/ReactionPath.cpp +++ b/Cantera/src/kinetics/ReactionPath.cpp @@ -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)); diff --git a/Cantera/src/kinetics/solveSP.cpp b/Cantera/src/kinetics/solveSP.cpp index 8f72719b7..eda3b8599 100644 --- a/Cantera/src/kinetics/solveSP.cpp +++ b/Cantera/src/kinetics/solveSP.cpp @@ -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); diff --git a/Cantera/src/numerics/BandMatrix.cpp b/Cantera/src/numerics/BandMatrix.cpp index bf19c99b3..091bbbbc2 100755 --- a/Cantera/src/numerics/BandMatrix.cpp +++ b/Cantera/src/numerics/BandMatrix.cpp @@ -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; diff --git a/Cantera/src/oneD/StFlow.cpp b/Cantera/src/oneD/StFlow.cpp index 791aca5bc..bbf1ac138 100644 --- a/Cantera/src/oneD/StFlow.cpp +++ b/Cantera/src/oneD/StFlow.cpp @@ -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); diff --git a/Cantera/src/oneD/boundaries1D.cpp b/Cantera/src/oneD/boundaries1D.cpp index b18b85c51..849c55ad6 100644 --- a/Cantera/src/oneD/boundaries1D.cpp +++ b/Cantera/src/oneD/boundaries1D.cpp @@ -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."); } diff --git a/Cantera/src/thermo/Constituents.cpp b/Cantera/src/thermo/Constituents.cpp index c906cd44c..e9436a189 100644 --- a/Cantera/src/thermo/Constituents.cpp +++ b/Cantera/src/thermo/Constituents.cpp @@ -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]; diff --git a/Cantera/src/thermo/Elements.cpp b/Cantera/src/thermo/Elements.cpp index ac3795198..a381cfb10 100644 --- a/Cantera/src/thermo/Elements.cpp +++ b/Cantera/src/thermo/Elements.cpp @@ -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]); } diff --git a/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp b/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp index 2bf665842..0e51cbba3 100644 --- a/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp +++ b/Cantera/src/thermo/IonsFromNeutralVPSSTP.cpp @@ -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; diff --git a/Cantera/src/thermo/SpeciesThermoInterpType.cpp b/Cantera/src/thermo/SpeciesThermoInterpType.cpp index 0e98a949d..b14feec21 100644 --- a/Cantera/src/thermo/SpeciesThermoInterpType.cpp +++ b/Cantera/src/thermo/SpeciesThermoInterpType.cpp @@ -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(); diff --git a/Cantera/src/thermo/ThermoFactory.cpp b/Cantera/src/thermo/ThermoFactory.cpp index 41972855a..0f6516482 100644 --- a/Cantera/src/thermo/ThermoFactory.cpp +++ b/Cantera/src/thermo/ThermoFactory.cpp @@ -680,7 +680,7 @@ namespace Cantera { // otherwise, throw an exception map::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"] + diff --git a/Cantera/src/zeroD/FlowDevice.cpp b/Cantera/src/zeroD/FlowDevice.cpp index 084b05f59..a9ee93009 100644 --- a/Cantera/src/zeroD/FlowDevice.cpp +++ b/Cantera/src/zeroD/FlowDevice.cpp @@ -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); } diff --git a/Cantera/src/zeroD/Reactor.cpp b/Cantera/src/zeroD/Reactor.cpp index 10961e0a3..ae032a97f 100644 --- a/Cantera/src/zeroD/Reactor.cpp +++ b/Cantera/src/zeroD/Reactor.cpp @@ -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 { diff --git a/apps/bvp/stagnation.cpp b/apps/bvp/stagnation.cpp index 003d9d624..1db11065a 100644 --- a/apps/bvp/stagnation.cpp +++ b/apps/bvp/stagnation.cpp @@ -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); diff --git a/tools/testtools/mdp_allo.cpp b/tools/testtools/mdp_allo.cpp index 45bdd3b40..f855cb662 100644 --- a/tools/testtools/mdp_allo.cpp +++ b/tools/testtools/mdp_allo.cpp @@ -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;