diff --git a/include/cantera/kinetics/StoichManager.h b/include/cantera/kinetics/StoichManager.h index f6f9c57c4..2aadad3b1 100644 --- a/include/cantera/kinetics/StoichManager.h +++ b/include/cantera/kinetics/StoichManager.h @@ -383,14 +383,16 @@ public: void incrementReaction(const doublereal* input, doublereal* output) const { - for (size_t n = 0; n < m_n; n++) output[m_rxn] - += m_stoich[n]*input[m_ic[n]]; + for (size_t n = 0; n < m_n; n++) { + output[m_rxn] += m_stoich[n]*input[m_ic[n]]; + } } void decrementReaction(const doublereal* input, doublereal* output) const { - for (size_t n = 0; n < m_n; n++) output[m_rxn] - -= m_stoich[n]*input[m_ic[n]]; + for (size_t n = 0; n < m_n; n++) { + output[m_rxn] -= m_stoich[n]*input[m_ic[n]]; + } } private: @@ -598,8 +600,9 @@ public: // instead of 'power'. std::vector kRep; for (size_t n = 0; n < k.size(); n++) { - for (size_t i = 0; i < stoich[n]; i++) + for (size_t i = 0; i < stoich[n]; i++) { kRep.push_back(k[n]); + } } switch (kRep.size()) { diff --git a/include/cantera/zeroD/Wall.h b/include/cantera/zeroD/Wall.h index 3380b41b6..33a6853e4 100644 --- a/include/cantera/zeroD/Wall.h +++ b/include/cantera/zeroD/Wall.h @@ -82,9 +82,10 @@ public: //! Set the emissivity. void setEmissivity(doublereal epsilon) { - if (epsilon > 1.0 || epsilon < 0.0) + if (epsilon > 1.0 || epsilon < 0.0) { throw CanteraError("Wall::setEmissivity", "emissivity must be between 0.0 and 1.0"); + } m_emiss = epsilon; } diff --git a/src/base/ctml.cpp b/src/base/ctml.cpp index 7b034a46c..74243611b 100644 --- a/src/base/ctml.cpp +++ b/src/base/ctml.cpp @@ -176,10 +176,11 @@ doublereal getFloat(const XML_Node& parent, const std::string& name, const std::string& type) { - if (!parent.hasChild(name)) + if (!parent.hasChild(name)) { throw CanteraError("getFloat (called from XML Node \"" + parent.name() + "\"): ", "no child XML element named \"" + name + "\" exists"); + } const XML_Node& node = parent.child(name); return getFloatCurrent(node, type); } diff --git a/src/base/stringUtils.cpp b/src/base/stringUtils.cpp index 04f5105be..0cd26b87e 100644 --- a/src/base/stringUtils.cpp +++ b/src/base/stringUtils.cpp @@ -107,10 +107,11 @@ static int lastChar(const std::string& s) { int i; int n = static_cast(s.size()); - for (i = n-1; i >= 0; i--) + for (i = n-1; i >= 0; i--) { if (s[i] != ' ' && isprint(s[i])) { break; } + } return i; } diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index 452c04dc9..9f52bdbf5 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -548,13 +548,15 @@ extern "C" { int th_set_HP(int n, double* vals) { try { - if (vals[1] < 0.0) + if (vals[1] < 0.0) { throw CanteraError("th_set_HP", "pressure cannot be negative"); + } ThermoCabinet::item(n).setState_HP(vals[0],vals[1]); - if (ThermoCabinet::item(n).temperature() < 0.0) + if (ThermoCabinet::item(n).temperature() < 0.0) { throw CanteraError("th_set_HP", "temperature cannot be negative"); + } return 0; } catch (...) { return handleAllExceptions(-1, ERR); @@ -564,13 +566,15 @@ extern "C" { int th_set_UV(int n, double* vals) { try { - if (vals[1] < 0.0) + if (vals[1] < 0.0) { throw CanteraError("th_set_UV", "specific volume cannot be negative"); + } ThermoCabinet::item(n).setState_UV(vals[0],vals[1]); - if (ThermoCabinet::item(n).temperature() < 0.0) + if (ThermoCabinet::item(n).temperature() < 0.0) { throw CanteraError("th_set_UV", "temperature cannot be negative"); + } return 0; } catch (...) { return handleAllExceptions(-1, ERR); diff --git a/src/clib/ctfunc.cpp b/src/clib/ctfunc.cpp index f85ddf8ba..6fa7678a3 100644 --- a/src/clib/ctfunc.cpp +++ b/src/clib/ctfunc.cpp @@ -34,32 +34,37 @@ extern "C" { } else if (type == ExpFuncType) { r = new Exp1(params[0]); } else if (type == PowFuncType) { - if (lenp < 1) + if (lenp < 1) { throw CanteraError("func_new", "exponent for pow must be supplied"); + } r = new Pow1(params[0]); } else if (type == ConstFuncType) { r = new Const1(params[0]); } else if (type == FourierFuncType) { - if (lenp < 2*n + 2) + if (lenp < 2*n + 2) { throw CanteraError("func_new", "not enough Fourier coefficients"); + } r = new Fourier1(n, params[n+1], params[0], params + 1, params + n + 2); } else if (type == GaussianFuncType) { - if (lenp < 3) + if (lenp < 3) { throw CanteraError("func_new", "not enough Gaussian coefficients"); + } r = new Gaussian(params[0], params[1], params[2]); } else if (type == PolyFuncType) { - if (lenp < n + 1) + if (lenp < n + 1) { throw CanteraError("func_new", "not enough polynomial coefficients"); + } r = new Poly1(n, params); } else if (type == ArrheniusFuncType) { - if (lenp < 3*n) + if (lenp < 3*n) { throw CanteraError("func_new", "not enough Arrhenius coefficients"); + } r = new Arrhenius1(n, params); } else if (type == PeriodicFuncType) { r = new Periodic1(FuncCabinet::item(n), params[0]); diff --git a/src/clib/ctxml.cpp b/src/clib/ctxml.cpp index 16a0231e6..d00e166c0 100644 --- a/src/clib/ctxml.cpp +++ b/src/clib/ctxml.cpp @@ -119,9 +119,10 @@ extern "C" { if (node.hasAttrib(key)) { string v = node[key]; strncpy(value, v.c_str(), 80); - } else + } else { throw CanteraError("xml_attrib","node " " has no attribute '"+string(key)+"'"); + } } catch (...) { return handleAllExceptions(-1, ERR); } @@ -213,9 +214,10 @@ extern "C" { XML_Node* c = XmlCabinet::item(i).findByName(nm); if (c) { return XmlCabinet::add(c); - } else + } else { throw CanteraError("xml_findByName","name "+string(nm) +" not found"); + } } catch (...) { return handleAllExceptions(-1, ERR); } diff --git a/src/equil/ChemEquil.cpp b/src/equil/ChemEquil.cpp index 30ea03698..6dcefbc07 100644 --- a/src/equil/ChemEquil.cpp +++ b/src/equil/ChemEquil.cpp @@ -108,21 +108,23 @@ void ChemEquil::initialize(thermo_t& s) // if negative atom numbers have already been specified // for some element other than this one, throw // an exception - if (mneg != npos && mneg != m) + if (mneg != npos && mneg != m) { throw CanteraError("ChemEquil::initialize", "negative atom numbers allowed for only one element"); + } mneg = m; ewt = s.atomicWeight(m); // the element should be an electron... if it isn't // print a warning. - if (ewt > 1.0e-3) + if (ewt > 1.0e-3) { writelog(string("WARNING: species " +s.speciesName(k) +" has "+fp2str(s.nAtoms(k,m)) +" atoms of element " +s.elementName(m)+ ", but this element is not an electron.\n")); + } } } } @@ -141,10 +143,11 @@ void ChemEquil::setToEquilState(thermo_t& s, { // Construct the chemical potentials by summing element potentials fill(m_mu_RT.begin(), m_mu_RT.end(), 0.0); - for (size_t k = 0; k < m_kk; k++) + for (size_t k = 0; k < m_kk; k++) { for (size_t m = 0; m < m_mm; m++) { m_mu_RT[k] += lambda_RT[m]*nAtoms(k,m); } + } // Set the temperature s.setTemperature(t); @@ -620,9 +623,8 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr, doublereal f, oldf; doublereal fctr = 1.0, newval; - for (int iter = 0; iter < options.maxIterations; iter++) - { - // check for convergence. + for (int iter = 0; iter < options.maxIterations; iter++) { + // check for convergence. equilResidual(s, x, elMolesGoal, res_trial, xval, yval); f = 0.5*dot(res_trial.begin(), res_trial.end(), res_trial.begin()); doublereal xx, yy, deltax, deltay; diff --git a/src/equil/MultiPhase.cpp b/src/equil/MultiPhase.cpp index 79333ae51..af9d82dbe 100644 --- a/src/equil/MultiPhase.cpp +++ b/src/equil/MultiPhase.cpp @@ -927,8 +927,7 @@ void MultiPhase::updatePhases() const loc += nsp; m_phase[p]->setState_TPX(m_temp, m_press, x); m_temp_OK[p] = true; - if (m_temp < m_phase[p]->minTemp() - || m_temp > m_phase[p]->maxTemp()) { + if (m_temp < m_phase[p]->minTemp() || m_temp > m_phase[p]->maxTemp()) { m_temp_OK[p] = false; } } diff --git a/src/equil/MultiPhaseEquil.cpp b/src/equil/MultiPhaseEquil.cpp index 968c51973..00c4175b0 100644 --- a/src/equil/MultiPhaseEquil.cpp +++ b/src/equil/MultiPhaseEquil.cpp @@ -409,10 +409,9 @@ void MultiPhaseEquil::getComponents(const std::vector& order) for (j = 0; j < nFree(); j++) { m_solnrxn[j] = false; for (k = 0; k < m_nsp; k++) { - if (m_N(k, j) != 0) - if (m_mix->solutionSpecies(m_species[m_order[k]])) { - m_solnrxn[j] = true; - } + if (m_N(k, j) != 0 && m_mix->solutionSpecies(m_species[m_order[k]])) { + m_solnrxn[j] = true; + } } } } diff --git a/src/equil/vcs_inest.cpp b/src/equil/vcs_inest.cpp index 583566e24..0d4167e1d 100644 --- a/src/equil/vcs_inest.cpp +++ b/src/equil/vcs_inest.cpp @@ -135,12 +135,13 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm, for (size_t kspec = 0; kspec < nspecies; ++kspec) { plogf("%s", pprefix); plogf("%-12.12s", m_speciesName[kspec].c_str()); - if (kspec < m_numComponents) + if (kspec < m_numComponents) { plogf("fe* = %15.5g ff = %15.5g\n", m_feSpecies_new[kspec], m_SSfeSpecies[kspec]); - else + } else { plogf("fe* = %15.5g ff = %15.5g dg* = %15.5g\n", m_feSpecies_new[kspec], m_SSfeSpecies[kspec], m_deltaGRxn_new[kspec-m_numComponents]); + } } } /* ********************************************************** */ diff --git a/src/fortran/fctxml.cpp b/src/fortran/fctxml.cpp index 89c9ccb10..8448d937e 100644 --- a/src/fortran/fctxml.cpp +++ b/src/fortran/fctxml.cpp @@ -106,9 +106,10 @@ extern "C" { if (node.hasAttrib(ky)) { std::string v = node[ky]; strncpy(value, v.c_str(), valuelen); - } else + } else { throw CanteraError("fxml_attrib","node " " has no attribute '"+ky+"'"); + } } catch (...) { return handleAllExceptions(-1, ERR); } @@ -212,9 +213,10 @@ extern "C" { XML_Node* c = node.findByName(f2string(nm, nmlen)); if (c) { return XmlCabinet::add(c); - } else + } else { throw CanteraError("fxml_findByName","name "+f2string(nm, nmlen) +" not found"); + } } catch (...) { return handleAllExceptions(-1, ERR); } diff --git a/src/kinetics/BulkKinetics.cpp b/src/kinetics/BulkKinetics.cpp index 7375a0ff8..3d1fd796e 100644 --- a/src/kinetics/BulkKinetics.cpp +++ b/src/kinetics/BulkKinetics.cpp @@ -22,12 +22,7 @@ Kinetics* BulkKinetics::duplMyselfAsKinetics(const std::vector & tpVe } bool BulkKinetics::isReversible(size_t i) { - if (std::find(m_revindex.begin(), m_revindex.end(), i) - < m_revindex.end()) { - return true; - } else { - return false; - } + return std::find(m_revindex.begin(), m_revindex.end(), i) < m_revindex.end(); } void BulkKinetics::getDeltaGibbs(doublereal* deltaG) diff --git a/src/kinetics/ImplicitSurfChem.cpp b/src/kinetics/ImplicitSurfChem.cpp index 19cde753f..c946bf4a0 100644 --- a/src/kinetics/ImplicitSurfChem.cpp +++ b/src/kinetics/ImplicitSurfChem.cpp @@ -41,9 +41,10 @@ ImplicitSurfChem::ImplicitSurfChem(vector k) : InterfaceKinetics* kinPtr = k[n]; m_vecKinPtrs.push_back(kinPtr); ns = k[n]->surfacePhaseIndex(); - if (ns == npos) + if (ns == npos) { throw CanteraError("ImplicitSurfChem", "kinetics manager contains no surface phase"); + } m_surfindex.push_back(ns); m_surf.push_back((SurfPhase*)&k[n]->thermo(ns)); nsp = m_surf.back()->nSpecies(); diff --git a/src/kinetics/solveSP.cpp b/src/kinetics/solveSP.cpp index c3490fc3c..9161cbaba 100644 --- a/src/kinetics/solveSP.cpp +++ b/src/kinetics/solveSP.cpp @@ -833,16 +833,18 @@ void solveSP::printIteration(int ioflag, doublereal damp, int label_d, } if (do_time) { printf("%9.4e %9.4e ", t_real, 1.0/inv_t); - } else + } else { for (i = 0; i < 22; i++) { printf(" "); } + } if (damp < 1.0) { printf("%9.4e ", damp); - } else + } else { for (i = 0; i < 11; i++) { printf(" "); } + } printf("%9.4e %9.4e", update_norm, resid_norm); if (do_time) { k = m_kinSpecIndex[label_t]; diff --git a/src/numerics/BandMatrix.cpp b/src/numerics/BandMatrix.cpp index a4039eae4..5d1fc2da4 100644 --- a/src/numerics/BandMatrix.cpp +++ b/src/numerics/BandMatrix.cpp @@ -264,10 +264,11 @@ int BandMatrix::solve(doublereal* b, size_t nrhs, size_t ldb) if (ldb == 0) { ldb = nColumns(); } - if (info == 0) + if (info == 0) { ct_dgbtrs(ctlapack::NoTranspose, nColumns(), nSubDiagonals(), nSuperDiagonals(), nrhs, DATA_PTR(ludata), ldim(), DATA_PTR(ipiv()), b, ldb, info); + } // error handling if (info != 0) { diff --git a/src/oneD/MultiNewton.cpp b/src/oneD/MultiNewton.cpp index 486e8e6ea..eef1ed9e6 100644 --- a/src/oneD/MultiNewton.cpp +++ b/src/oneD/MultiNewton.cpp @@ -193,10 +193,11 @@ void MultiNewton::step(doublereal* x, doublereal* step, iok--; size_t nd = r.nDomains(); size_t n; - for (n = nd-1; n != npos; n--) + for (n = nd-1; n != npos; n--) { if (iok >= r.start(n)) { break; } + } Domain1D& dom = r.domain(n); size_t offset = iok - r.start(n); size_t pt = offset/dom.nComponents(); @@ -207,9 +208,10 @@ void MultiNewton::step(doublereal* x, doublereal* step, +dom.componentName(comp)+" at point " +int2str(pt)+"\n(Matrix row " +int2str(iok)+") \nsee file bandmatrix.csv\n"); - } else if (int(iok) < 0) + } else if (int(iok) < 0) { throw CanteraError("MultiNewton::step", "iok = "+int2str(iok)); + } } doublereal MultiNewton::boundStep(const doublereal* x0, diff --git a/src/oneD/OneDim.cpp b/src/oneD/OneDim.cpp index e8c677b87..34f07f1f4 100644 --- a/src/oneD/OneDim.cpp +++ b/src/oneD/OneDim.cpp @@ -353,9 +353,10 @@ doublereal OneDim::timeStep(int nsteps, doublereal dt, doublereal* x, // Decrease the stepsize and try again. writelog("...failure.\n", loglevel); dt *= m_tfactor; - if (dt < m_tmin) + if (dt < m_tmin) { throw CanteraError("OneDim::timeStep", "Time integration failed."); + } } } diff --git a/src/oneD/Sim1D.cpp b/src/oneD/Sim1D.cpp index c5a994ae2..976880b97 100644 --- a/src/oneD/Sim1D.cpp +++ b/src/oneD/Sim1D.cpp @@ -107,9 +107,10 @@ void Sim1D::restore(const std::string& fname, const std::string& id, int loglevel) { ifstream s(fname.c_str()); - if (!s) + if (!s) { throw CanteraError("Sim1D::restore", "could not open input file "+fname); + } XML_Node root; root.build(s); diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index 40c8d7904..a05d9842c 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -156,10 +156,11 @@ void StFlow::setTransport(Transport& trans, bool withSoret) } else if (model == cMixtureAveraged || model == CK_MixtureAveraged) { m_transport_option = c_Mixav_Transport; m_diff.resize(m_nsp*m_points); - if (withSoret) + if (withSoret) { throw CanteraError("setTransport", "Thermal diffusion (the Soret effect) " "requires using a multicomponent transport model."); + } } else { throw CanteraError("setTransport","unknown transport model."); } diff --git a/src/oneD/boundaries1D.cpp b/src/oneD/boundaries1D.cpp index ca5d06c46..193185971 100644 --- a/src/oneD/boundaries1D.cpp +++ b/src/oneD/boundaries1D.cpp @@ -48,11 +48,12 @@ void Bdry1D::_init(size_t n) m_left_loc = container().start(m_index-1); m_left_nsp = m_left_nv - 4; m_phase_left = &m_flow_left->phase(); - } else + } else { throw CanteraError("Bdry1D::_init", "Boundary domains can only be " "connected on the left to flow domains, not type "+int2str(r.domainType()) + " domains."); + } } // if this is not the last domain, see what is connected on @@ -65,11 +66,12 @@ void Bdry1D::_init(size_t n) m_right_loc = container().start(m_index+1); m_right_nsp = m_right_nv - 4; m_phase_right = &m_flow_right->phase(); - } else + } else { throw CanteraError("Bdry1D::_init", "Boundary domains can only be " "connected on the right to flow domains, not type "+int2str(r.domainType()) + " domains."); + } } } diff --git a/src/thermo/DebyeHuckel.cpp b/src/thermo/DebyeHuckel.cpp index f72ad45a1..d755e4740 100644 --- a/src/thermo/DebyeHuckel.cpp +++ b/src/thermo/DebyeHuckel.cpp @@ -956,8 +956,7 @@ void DebyeHuckel::initThermoXML(XML_Node& phaseNode, const std::string& id_) for (size_t k = 0; k < m_kk; k++) { if (fabs(m_speciesCharge[k]) > 0.0001) { m_electrolyteSpeciesType[k] = cEST_chargedSpecies; - if (fabs(m_speciesCharge_Stoich[k] - m_speciesCharge[k]) - > 0.0001) { + if (fabs(m_speciesCharge_Stoich[k] - m_speciesCharge[k]) > 0.0001) { m_electrolyteSpeciesType[k] = cEST_weakAcidAssociated; } } else if (fabs(m_speciesCharge_Stoich[k]) > 0.0001) { diff --git a/src/thermo/HMWSoln_input.cpp b/src/thermo/HMWSoln_input.cpp index 2da4115c3..fe2bc638c 100644 --- a/src/thermo/HMWSoln_input.cpp +++ b/src/thermo/HMWSoln_input.cpp @@ -1471,8 +1471,7 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_) for (size_t k = 0; k < m_kk; k++) { if (fabs(charge(k)) > 0.0001) { m_electrolyteSpeciesType[k] = cEST_chargedSpecies; - if (fabs(m_speciesCharge_Stoich[k] - charge(k)) - > 0.0001) { + if (fabs(m_speciesCharge_Stoich[k] - charge(k)) > 0.0001) { m_electrolyteSpeciesType[k] = cEST_weakAcidAssociated; } } else if (fabs(m_speciesCharge_Stoich[k]) > 0.0001) { diff --git a/src/thermo/PureFluidPhase.cpp b/src/thermo/PureFluidPhase.cpp index 7dae85c2a..f509b3434 100644 --- a/src/thermo/PureFluidPhase.cpp +++ b/src/thermo/PureFluidPhase.cpp @@ -93,9 +93,10 @@ void PureFluidPhase::setParametersFromXML(const XML_Node& eosdata) { eosdata._require("model","PureFluid"); m_subflag = atoi(eosdata["fluid_type"].c_str()); - if (m_subflag < 0) + if (m_subflag < 0) { throw CanteraError("PureFluidPhase::setParametersFromXML", "missing or negative substance flag"); + } } doublereal PureFluidPhase::enthalpy_mole() const diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index da6279f04..d829e011a 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -331,10 +331,11 @@ void importPhase(XML_Node& phase, ThermoPhase* th) // Number of spatial dimensions. Defaults to 3 (bulk phase) if (phase.hasAttrib("dim")) { int idim = intValue(phase["dim"]); - if (idim < 1 || idim > 3) + if (idim < 1 || idim > 3) { throw CanteraError("importPhase", "phase, " + th->id() + ", has unphysical number of dimensions: " + phase["dim"]); + } th->setNDim(idim); } else { th->setNDim(3); // default diff --git a/src/transport/GasTransport.cpp b/src/transport/GasTransport.cpp index e9d47542d..e4711d7af 100644 --- a/src/transport/GasTransport.cpp +++ b/src/transport/GasTransport.cpp @@ -229,10 +229,11 @@ void GasTransport::getBinaryDiffCoeffs(const size_t ld, doublereal* const d) throw CanteraError(" MixTransport::getBinaryDiffCoeffs()", "ld is too small"); } doublereal rp = 1.0/m_thermo->pressure(); - for (size_t i = 0; i < m_nsp; i++) + for (size_t i = 0; i < m_nsp; i++) { for (size_t j = 0; j < m_nsp; j++) { d[ld*j + i] = rp * m_bdiff(i,j); } + } } void GasTransport::getMixDiffCoeffs(doublereal* const d) diff --git a/src/transport/HighPressureGasTransport.cpp b/src/transport/HighPressureGasTransport.cpp index a5ccbea60..0d3027ad5 100755 --- a/src/transport/HighPressureGasTransport.cpp +++ b/src/transport/HighPressureGasTransport.cpp @@ -151,8 +151,7 @@ void HighPressureGasTransport::getBinaryDiffCoeffs(const size_t ld, doublereal* throw CanteraError("HighPressureTransport::getBinaryDiffCoeffs()", "ld is too small"); } doublereal rp = 1.0/m_thermo->pressure(); - for (size_t i = 0; i < nsp; i++) - { + for (size_t i = 0; i < nsp; i++) { for (size_t j = 0; j < nsp; j++) { // Add an offset to avoid a condition where x_i and x_j both equal // zero (this would lead to Pr_ij = Inf): @@ -221,8 +220,7 @@ void HighPressureGasTransport::getMultiDiffCoeffs(const size_t ld, doublereal* c throw CanteraError("HighPressureTransport::getMultiDiffCoeffs()", "ld is too small"); } - for (size_t i = 0; i < m_nsp; i++) - { + for (size_t i = 0; i < m_nsp; i++) { for (size_t j = 0; j < m_nsp; j++) { // Add an offset to avoid a condition where x_i and x_j both equal // zero (this would lead to Pr_ij = Inf): diff --git a/src/transport/LiquidTranInteraction.cpp b/src/transport/LiquidTranInteraction.cpp index f3c37495f..58a976784 100644 --- a/src/transport/LiquidTranInteraction.cpp +++ b/src/transport/LiquidTranInteraction.cpp @@ -474,15 +474,17 @@ void LTI_Pairwise_Interaction::getMatrixTransProp(DenseMatrix& mat, doublereal* m_thermo->getMoleFractions(&molefracs[0]); mat.resize(nsp, nsp, 0.0); - for (size_t i = 0; i < nsp; i++) + for (size_t i = 0; i < nsp; i++) { for (size_t j = 0; j < i; j++) { mat(i,j) = mat(j,i) = exp(m_Eij(i,j) / temp) / m_Dij(i,j); } + } - for (size_t i = 0; i < nsp; i++) + for (size_t i = 0; i < nsp; i++) { if (mat(i,i) == 0.0 && m_diagonals[i]) { mat(i,i) = 1.0 / m_diagonals[i]->getSpeciesTransProp() ; } + } } void LTI_StefanMaxwell_PPN::setParameters(LiquidTransportParams& trParam) @@ -660,10 +662,11 @@ void LTI_StokesEinstein::getMatrixTransProp(DenseMatrix& mat, doublereal* specie } mat.resize(nsp,nsp, 0.0); - for (size_t i = 0; i < nsp; i++) + for (size_t i = 0; i < nsp; i++) { for (size_t j = 0; j < nsp; j++) { mat(i,j) = (6.0 * Pi * radiusSpec[i] * viscSpec[j]) / GasConstant / temp; } + } } doublereal LTI_MoleFracs_ExpT::getMixTransProp(doublereal* speciesValues, doublereal* speciesWeight) diff --git a/src/transport/LiquidTransport.cpp b/src/transport/LiquidTransport.cpp index 6f5846251..191edd955 100644 --- a/src/transport/LiquidTransport.cpp +++ b/src/transport/LiquidTransport.cpp @@ -510,9 +510,10 @@ void LiquidTransport::getThermalDiffCoeffs(doublereal* const dt) void LiquidTransport::getBinaryDiffCoeffs(size_t ld, doublereal* d) { - if (ld != m_nsp) + if (ld != m_nsp) { throw CanteraError("LiquidTransport::getBinaryDiffCoeffs", "First argument does not correspond to number of species in model.\nDiff Coeff matrix may be misdimensioned"); + } update_T(); // if necessary, evaluate the binary diffusion coefficients // from the polynomial fits @@ -902,12 +903,13 @@ void LiquidTransport::update_Grad_lnAC() grad_T = m_Grad_T[k]; size_t start = m_nsp*k; m_thermo->getdlnActCoeffds(grad_T, &m_Grad_X[start], &m_Grad_lnAC[start]); - for (size_t i = 0; i < m_nsp; i++) + for (size_t i = 0; i < m_nsp; i++) { if (m_molefracs[i] < 1.e-15) { m_Grad_lnAC[start+i] = 0; } else { m_Grad_lnAC[start+i] += m_Grad_X[start+i]/m_molefracs[i]; } + } } return; } @@ -997,16 +999,17 @@ void LiquidTransport::stefan_maxwell_solve() } else if (m_velocityBasis == VB_MASSAVG) { m_A(0,j) = m_massfracs_tran[j]; } else if ((m_velocityBasis >= 0) - && (m_velocityBasis < static_cast(m_nsp))) + && (m_velocityBasis < static_cast(m_nsp))) { // use species number m_velocityBasis as reference velocity if (m_velocityBasis == static_cast(j)) { m_A(0,j) = 1.0; } else { m_A(0,j) = 0.0; } - else + } else { throw CanteraError("LiquidTransport::stefan_maxwell_solve", "Unknown reference velocity provided."); + } } for (size_t i = 1; i < m_nsp; i++) { m_B(i,0) = m_Grad_mu[i] * invRT; @@ -1037,16 +1040,17 @@ void LiquidTransport::stefan_maxwell_solve() } else if (m_velocityBasis == VB_MASSAVG) { m_A(0,j) = m_massfracs_tran[j]; } else if ((m_velocityBasis >= 0) - && (m_velocityBasis < static_cast(m_nsp))) + && (m_velocityBasis < static_cast(m_nsp))) { // use species number m_velocityBasis as reference velocity if (m_velocityBasis == static_cast(j)) { m_A(0,j) = 1.0; } else { m_A(0,j) = 0.0; } - else + } else { throw CanteraError("LiquidTransport::stefan_maxwell_solve", "Unknown reference velocity provided."); + } } for (size_t i = 1; i < m_nsp; i++) { m_B(i,0) = m_Grad_mu[i] * invRT; @@ -1075,16 +1079,17 @@ void LiquidTransport::stefan_maxwell_solve() } else if (m_velocityBasis == VB_MASSAVG) { m_A(0,j) = m_massfracs_tran[j]; } else if ((m_velocityBasis >= 0) - && (m_velocityBasis < static_cast(m_nsp))) + && (m_velocityBasis < static_cast(m_nsp))) { // use species number m_velocityBasis as reference velocity if (m_velocityBasis == static_cast(j)) { m_A(0,j) = 1.0; } else { m_A(0,j) = 0.0; } - else + } else { throw CanteraError("LiquidTransport::stefan_maxwell_solve", "Unknown reference velocity provided."); + } } for (size_t i = 1; i < m_nsp; i++) { m_B(i,0) = m_Grad_mu[i] * invRT; diff --git a/src/transport/MultiTransport.cpp b/src/transport/MultiTransport.cpp index c5a9b41f2..228859013 100644 --- a/src/transport/MultiTransport.cpp +++ b/src/transport/MultiTransport.cpp @@ -655,19 +655,21 @@ void MultiTransport::eval_L0001() void MultiTransport::eval_L0100() { size_t n2 = 2*m_nsp; - for (size_t j = 0; j < m_nsp; j++) + for (size_t j = 0; j < m_nsp; j++) { for (size_t i = 0; i < m_nsp; i++) { m_Lmatrix(i+n2,j) = 0.0; // see Eq. (12.123) } + } } void MultiTransport::eval_L0110() { size_t n2 = 2*m_nsp; - for (size_t j = 0; j < m_nsp; j++) + for (size_t j = 0; j < m_nsp; j++) { for (size_t i = 0; i < m_nsp; i++) { m_Lmatrix(i+n2,j+m_nsp) = m_Lmatrix(j+m_nsp,i+n2); // see Eq. (12.123) } + } } void MultiTransport::eval_L0101(const doublereal* x) diff --git a/src/transport/TransportBase.cpp b/src/transport/TransportBase.cpp index cd3055a92..329027d8a 100644 --- a/src/transport/TransportBase.cpp +++ b/src/transport/TransportBase.cpp @@ -104,9 +104,10 @@ void Transport::finalize() { if (!ready()) { m_ready = true; - } else + } else { throw CanteraError("Transport::finalize", "finalize has already been called."); + } } void Transport::getSpeciesFluxes(size_t ndim, const doublereal* const grad_T, diff --git a/src/zeroD/Reactor.cpp b/src/zeroD/Reactor.cpp index 46fc09525..5e3f0a145 100644 --- a/src/zeroD/Reactor.cpp +++ b/src/zeroD/Reactor.cpp @@ -75,10 +75,11 @@ void Reactor::initialize(doublereal t0) m_sdot.resize(m_nsp, 0.0); m_wdot.resize(m_nsp, 0.0); m_nv = m_nsp + 3; - for (size_t w = 0; w < m_wall.size(); w++) + for (size_t w = 0; w < m_wall.size(); w++) { if (m_wall[w]->surface(m_lr[w])) { m_nv += m_wall[w]->surface(m_lr[w])->nSpecies(); } + } m_enthalpy = m_thermo->enthalpy_mass(); m_pressure = m_thermo->pressure(); @@ -323,9 +324,10 @@ double Reactor::evalSurfaces(double t, double* ydot) void Reactor::addSensitivityReaction(size_t rxn) { - if (rxn >= m_kin->nReactions()) + if (rxn >= m_kin->nReactions()) { throw CanteraError("Reactor::addSensitivityReaction", "Reaction number out of range ("+int2str(rxn)+")"); + } network().registerSensitivityReaction(this, rxn, name()+": "+m_kin->reactionString(rxn)); diff --git a/src/zeroD/ReactorNet.cpp b/src/zeroD/ReactorNet.cpp index 04e6bbb70..8f429dae6 100644 --- a/src/zeroD/ReactorNet.cpp +++ b/src/zeroD/ReactorNet.cpp @@ -43,9 +43,10 @@ void ReactorNet::initialize() char buf[100]; m_nv = 0; writelog("Initializing reactor network.\n", m_verbose); - if (m_reactors.empty()) + if (m_reactors.empty()) { throw CanteraError("ReactorNet::initialize", "no reactors in network!"); + } size_t sensParamNumber = 0; m_start.assign(1, 0); for (n = 0; n < m_reactors.size(); n++) { diff --git a/src/zeroD/Wall.cpp b/src/zeroD/Wall.cpp index 3d68ea933..99f8cd4cd 100644 --- a/src/zeroD/Wall.cpp +++ b/src/zeroD/Wall.cpp @@ -141,9 +141,10 @@ void Wall::syncCoverages(int leftright) void Wall::addSensitivityReaction(int leftright, size_t rxn) { - if (rxn >= m_chem[leftright]->nReactions()) + if (rxn >= m_chem[leftright]->nReactions()) { throw CanteraError("Wall::addSensitivityReaction", "Reaction number out of range ("+int2str(rxn)+")"); + } if (leftright == 0) { m_left->network().registerSensitivityReaction(this, rxn, m_chem[0]->reactionString(rxn), leftright); diff --git a/test_problems/surfkin/surfdemo.cpp b/test_problems/surfkin/surfdemo.cpp index 3f0fca029..83deb19dd 100644 --- a/test_problems/surfkin/surfdemo.cpp +++ b/test_problems/surfkin/surfdemo.cpp @@ -30,10 +30,10 @@ int main() cout << gas.speciesName(k) << " " << wdot[k] << endl; } - for (size_t k = 0; k < surf.nSpecies(); k++) + for (size_t k = 0; k < surf.nSpecies(); k++) { cout << surf.speciesName(k) << " " << wdot[k+gas.nSpecies()] << endl; - + } } catch (CanteraError& err) { std::cout << err.what() << std::endl; }