diff --git a/include/cantera/base/utilities.h b/include/cantera/base/utilities.h index 32329315b..1150f36db 100644 --- a/include/cantera/base/utilities.h +++ b/include/cantera/base/utilities.h @@ -163,11 +163,13 @@ inline void scale(InputIter begin, InputIter end, * begin determines the loop length * @param y_begin Iterator pointing to the beginning of the vector y, * belonging to the iterator class outputIter. + * @deprecated Unused. To be removed after Cantera 2.5. */ template inline void multiply_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin) { + warn_deprecated("multiply_each", "To be removed after Cantera 2.5."); for (; x_begin != x_end; ++x_begin, ++y_begin) { *x_begin *= *y_begin; } @@ -196,10 +198,12 @@ inline void multiply_each(OutputIter x_begin, OutputIter x_end, * @param end Iterator pointing to the end of the x vector, belonging to * the iterator class InputIter. The difference between end and * begin determines the loop length + * @deprecated Unused. To be removed after Cantera 2.5. */ template inline doublereal absmax(InputIter begin, InputIter end) { + warn_deprecated("absmax", "To be removed after Cantera 2.5."); doublereal amax = 0.0; for (; begin != end; ++begin) { amax = std::max(fabs(*begin), amax); @@ -235,11 +239,13 @@ inline doublereal absmax(InputIter begin, InputIter end) * begin determines the loop length * @param out Iterator pointing to the beginning of the output vector, * belonging to the iterator class OutputIter. + * @deprecated Unused. To be removed after Cantera 2.5. */ template inline void normalize(InputIter begin, InputIter end, OutputIter out) { + warn_deprecated("normalize", "To be removed after Cantera 2.5."); doublereal sum = std::accumulate(begin, end, 0.0); for (; begin != end; ++begin, ++out) { *out = *begin/sum; @@ -270,11 +276,13 @@ inline void normalize(InputIter begin, InputIter end, * and begin determines the number of inner iterations. * @param y_begin Iterator pointing to the beginning of the yvector, belonging * to the iterator class InputIter. + * @deprecated Unused. To be removed after Cantera 2.5. */ template inline void divide_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin) { + warn_deprecated("divide_each", "To be removed after Cantera 2.5."); for (; x_begin != x_end; ++x_begin, ++y_begin) { *x_begin /= *y_begin; } @@ -291,11 +299,13 @@ inline void divide_each(OutputIter x_begin, OutputIter x_end, * and begin determines the number of inner iterations. * @param y_begin Iterator pointing to the beginning of the yvector, belonging * to the iterator class InputIter. + * @deprecated Unused. To be removed after Cantera 2.5. */ template inline void sum_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin) { + warn_deprecated("sum_each", "To be removed after Cantera 2.5."); for (; x_begin != x_end; ++x_begin, ++y_begin) { *x_begin += *y_begin; } @@ -331,11 +341,13 @@ inline void sum_each(OutputIter x_begin, OutputIter x_end, * belonging to the iterator class outputIter. * @param index Iterator pointing to the beginning of the index vector, belonging to the * iterator class IndexIter. + * @deprecated Unused. To be removed after Cantera 2.5. */ template inline void scatter_copy(InputIter begin, InputIter end, OutputIter result, IndexIter index) { + warn_deprecated("scatter_copy", "To be removed after Cantera 2.5."); for (; begin != end; ++begin, ++index) { *(result + *index) = *begin; } @@ -368,11 +380,13 @@ inline void scatter_copy(InputIter begin, InputIter end, * be selectively multiplied. * @param index Iterator pointing to the beginning of the index vector, * belonging to the iterator class IndexIter. + * @deprecated Unused. To be removed after Cantera 2.5. */ template inline void scatter_mult(InputIter mult_begin, InputIter mult_end, RandAccessIter data, IndexIter index) { + warn_deprecated("scatter_mult", "To be removed after Cantera 2.5."); for (; mult_begin != mult_end; ++mult_begin, ++index) { *(data + *index) *= *mult_begin; } @@ -390,10 +404,12 @@ inline void scatter_mult(InputIter mult_begin, InputIter mult_end, * @param end Iterator pointing to the end, belonging to the * iterator class InputIter. * @return The return from this class is a double. + * @deprecated Unused. To be removed after Cantera 2.5. */ template inline doublereal sum_xlogx(InputIter begin, InputIter end) { + warn_deprecated("sum_xlogx", "To be removed after Cantera 2.5."); doublereal sum = 0.0; for (; begin != end; ++begin) { sum += (*begin) * std::log(*begin + Tiny); @@ -416,11 +432,13 @@ inline doublereal sum_xlogx(InputIter begin, InputIter end) * @param Q_begin Iterator pointing to the beginning of Q_k, belonging to the * iterator class InputIter2. * @return The return from this class is hard coded to a doublereal. + * @deprecated Unused. To be removed after Cantera 2.5. */ template inline doublereal sum_xlogQ(InputIter1 begin, InputIter1 end, InputIter2 Q_begin) { + warn_deprecated("sum_xlogQ", "To be removed after Cantera 2.5."); doublereal sum = 0.0; for (; begin != end; ++begin, ++Q_begin) { sum += (*begin) * std::log(*Q_begin + Tiny); diff --git a/include/cantera/kinetics/InterfaceKinetics.h b/include/cantera/kinetics/InterfaceKinetics.h index dc729b84f..faec6c625 100644 --- a/include/cantera/kinetics/InterfaceKinetics.h +++ b/include/cantera/kinetics/InterfaceKinetics.h @@ -11,7 +11,6 @@ #include "Kinetics.h" #include "Reaction.h" -#include "cantera/base/utilities.h" #include "RateCoeffMgr.h" namespace Cantera diff --git a/include/cantera/kinetics/ThirdBodyCalc.h b/include/cantera/kinetics/ThirdBodyCalc.h index 578f6fe14..3f63074f9 100644 --- a/include/cantera/kinetics/ThirdBodyCalc.h +++ b/include/cantera/kinetics/ThirdBodyCalc.h @@ -8,7 +8,7 @@ #ifndef CT_THIRDBODYCALC_H #define CT_THIRDBODYCALC_H -#include "cantera/base/utilities.h" +#include "cantera/base/ct_defs.h" #include namespace Cantera @@ -44,8 +44,9 @@ public: } void multiply(double* output, const double* work) { - scatter_mult(work, work + m_reaction_index.size(), - output, m_reaction_index.begin()); + for (size_t i = 0; i < m_reaction_index.size(); i++) { + output[m_reaction_index[i]] *= work[i]; + } } size_t workSize() { diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index ff952833c..713b44238 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -1147,8 +1147,10 @@ extern "C" { k.checkSpeciesArraySize(len); k.checkSpeciesArraySize(nsp); k.getNetProductionRates(ydot); - multiply_each(ydot, ydot + nsp, p.molecularWeights().begin()); - scale(ydot, ydot + nsp, ydot, 1.0/p.density()); + double rho_inv = 1.0 / p.density(); + for (size_t k = 0; k < nsp; k++) { + ydot[k] *= p.molecularWeight(k) * rho_inv; + } return 0; } catch (...) { return handleAllExceptions(-1, ERR); diff --git a/src/kinetics/GasKinetics.cpp b/src/kinetics/GasKinetics.cpp index a72bec917..6f83047a4 100644 --- a/src/kinetics/GasKinetics.cpp +++ b/src/kinetics/GasKinetics.cpp @@ -146,10 +146,8 @@ void GasKinetics::processFalloffReactions() } else { // CHEMACT_RXN pr[i] *= m_rfn_low[i]; } + m_ropf[m_fallindx[i]] = pr[i]; } - - scatter_copy(pr.begin(), pr.begin() + m_falloff_low_rates.nReactions(), - m_ropf.begin(), m_fallindx.begin()); } void GasKinetics::updateROP() @@ -172,15 +170,13 @@ void GasKinetics::updateROP() processFalloffReactions(); } - // multiply by perturbation factor - multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin()); - - // copy the forward rates to the reverse rates - m_ropr = m_ropf; - - // for reverse rates computed from thermochemistry, multiply the forward - // rates copied into m_ropr by the reciprocals of the equilibrium constants - multiply_each(m_ropr.begin(), m_ropr.end(), m_rkcn.begin()); + for (size_t i = 0; i < nReactions(); i++) { + // Scale the forward rate coefficient by the perturbation factor + m_ropf[i] *= m_perturb[i]; + // For reverse rates computed from thermochemistry, multiply the forward + // rate coefficients by the reciprocals of the equilibrium constants + m_ropr[i] = m_ropf[i] * m_rkcn[i]; + } // multiply ropf by concentration products m_reactantStoich.multiply(m_conc.data(), m_ropf.data()); @@ -220,11 +216,9 @@ void GasKinetics::getFwdRateConstants(doublereal* kfwd) processFalloffReactions(); } - // multiply by perturbation factor - multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin()); - for (size_t i = 0; i < nReactions(); i++) { - kfwd[i] = m_ropf[i]; + // multiply by perturbation factor + kfwd[i] = m_ropf[i] * m_perturb[i]; } } diff --git a/src/kinetics/InterfaceKinetics.cpp b/src/kinetics/InterfaceKinetics.cpp index 19e99a6ea..ba5de002b 100644 --- a/src/kinetics/InterfaceKinetics.cpp +++ b/src/kinetics/InterfaceKinetics.cpp @@ -291,12 +291,10 @@ void InterfaceKinetics::convertExchangeCurrentDensityFormulation(doublereal* con void InterfaceKinetics::getFwdRateConstants(doublereal* kfwd) { updateROP(); - - // copy rate coefficients into kfwd - copy(m_rfn.begin(), m_rfn.end(), kfwd); - - // multiply by perturbation factor - multiply_each(kfwd, kfwd + nReactions(), m_perturb.begin()); + for (size_t i = 0; i < nReactions(); i++) { + // base rate coefficient multiplied by perturbation factor + kfwd[i] = m_rfn[i] * m_perturb[i]; + } } void InterfaceKinetics::getRevRateConstants(doublereal* krev, bool doIrreversible) @@ -308,7 +306,9 @@ void InterfaceKinetics::getRevRateConstants(doublereal* krev, bool doIrreversibl krev[i] /= m_ropnet[i]; } } else { - multiply_each(krev, krev + nReactions(), m_rkcn.begin()); + for (size_t i = 0; i < nReactions(); i++) { + krev[i] *= m_rkcn[i]; + } } } @@ -324,19 +324,13 @@ void InterfaceKinetics::updateROP() return; } - // Copy the reaction rate coefficients, m_rfn, into m_ropf - m_ropf = m_rfn; - - // Multiply by the perturbation factor - multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin()); - - // Copy the forward rate constants to the reverse rate constants - m_ropr = m_ropf; - - // For reverse rates computed from thermochemistry, multiply - // the forward rates copied into m_ropr by the reciprocals of - // the equilibrium constants - multiply_each(m_ropr.begin(), m_ropr.end(), m_rkcn.begin()); + for (size_t i = 0; i < nReactions(); i++) { + // Scale the base forward rate coefficient by the perturbation factor + m_ropf[i] = m_rfn[i] * m_perturb[i]; + // Multiply the scaled forward rate coefficient by the reciprocal of the + // equilibrium constant + m_ropr[i] = m_ropf[i] * m_rkcn[i]; + } // multiply ropf by the activity concentration reaction orders to obtain // the forward rates of progress. diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index 73cbe9818..880bdfae9 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -623,7 +623,11 @@ doublereal Phase::mean_X(const vector_fp& Q) const doublereal Phase::sum_xlogx() const { - return m_mmw* Cantera::sum_xlogx(m_ym.begin(), m_ym.end()) + log(m_mmw); + double sumxlogx = 0; + for (size_t k = 0; k < m_kk; k++) { + sumxlogx += m_ym[k] * std::log(m_ym[k] + Tiny); + } + return m_mmw * sumxlogx + std::log(m_mmw); } size_t Phase::addElement(const std::string& symbol, doublereal weight, diff --git a/src/transport/DustyGasTransport.cpp b/src/transport/DustyGasTransport.cpp index f2d8004b0..73eb387ff 100644 --- a/src/transport/DustyGasTransport.cpp +++ b/src/transport/DustyGasTransport.cpp @@ -147,7 +147,9 @@ void DustyGasTransport::getMolarFluxes(const doublereal* const state1, // Multiply m_multidiff and gradc together and store the result in fluxes[] multiply(m_multidiff, gradc, fluxes); - divide_each(cbar, cbar + m_nsp, m_dk.begin()); + for (size_t k = 0; k < m_nsp; k++) { + cbar[k] /= m_dk[k]; + } // if no permeability has been specified, use result for // close-packed spheres