diff --git a/Cantera/src/Group.h b/Cantera/src/Group.h index 4bdb94ff2..82e13b74f 100755 --- a/Cantera/src/Group.h +++ b/Cantera/src/Group.h @@ -25,11 +25,11 @@ namespace Cantera { public: Group() : m_sign(-999) { } Group(int n) : m_sign(0) { m_comp.resize(n,0);} - Group(const vector_int& elnumbers) : - m_comp(elnumbers), m_sign(0) { + Group(const vector_int& elnumbers) : + m_comp(elnumbers), m_sign(0) { validate(); } - Group(const Group& g) : + Group(const Group& g) : m_comp(g.m_comp), m_sign(g.m_sign) { } Group& operator=(const Group& g) { if (&g != this) { @@ -41,7 +41,7 @@ namespace Cantera { virtual ~Group(){} /** - * Decrement the atom numbers by those in group 'other'. + * Decrement the atom numbers by those in group 'other'. */ void operator-=(const Group& other) { verifyInputs(*this, other); @@ -66,7 +66,7 @@ namespace Cantera { bool operator==(const Group& other) const { verifyInputs(*this, other); int n = m_comp.size(); - for (int m = 0; m < n; m++) { + for (int m = 0; m < n; m++) { if (m_comp[m] != other.m_comp[m]) return false; } return true; @@ -97,17 +97,17 @@ namespace Cantera { /** * True if all non-zero atom numbers have the same sign. - */ + */ bool valid() const { return (m_sign != -999); } bool operator!() const { return (m_sign == -999); } int sign() const { return m_sign; } int size() const { return m_comp.size(); } - + /// Number of atoms in the group (>= 0) int nAtoms() const { int n = m_comp.size(); int sum = 0; - for (int m = 0; m < n; m++) sum += abs(m_comp[m]); + for (int m = 0; m < n; m++) sum += std::abs(m_comp[m]); return sum; } /// Number of atoms of element m (positive or negative) @@ -129,4 +129,3 @@ namespace Cantera { } #endif - diff --git a/Cantera/src/IdealGasPhase.h b/Cantera/src/IdealGasPhase.h index 9ba2f52c2..e59486214 100644 --- a/Cantera/src/IdealGasPhase.h +++ b/Cantera/src/IdealGasPhase.h @@ -100,7 +100,7 @@ namespace Cantera { */ virtual doublereal entropy_mole() const { return GasConstant * (mean_X(&entropy_R_ref()[0]) - - sum_xlogx() - log(pressure()/m_spthermo->refPressure())); + sum_xlogx() - std::log(pressure()/m_spthermo->refPressure())); } /** @@ -236,7 +236,7 @@ namespace Cantera { virtual doublereal logStandardConc(int k=0) const { _updateThermo(); double p = pressure(); - double lc = log (p / (GasConstant * temperature())); + double lc = std::log (p / (GasConstant * temperature())); return lc; } @@ -397,7 +397,7 @@ namespace Cantera { const array_fp& expGibbs_RT_ref() const { _updateThermo(); int k; - for (k = 0; k != m_kk; k++) m_expg0_RT[k] = exp(m_g0_RT[k]); + for (k = 0; k != m_kk; k++) m_expg0_RT[k] = std::exp(m_g0_RT[k]); return m_expg0_RT; } diff --git a/Cantera/src/StoichManager.h b/Cantera/src/StoichManager.h index f59c9d0e1..c1a2dc7d0 100755 --- a/Cantera/src/StoichManager.h +++ b/Cantera/src/StoichManager.h @@ -16,12 +16,12 @@ namespace Cantera { - /** + /** * @defgroup Stoichiometry Stoichiometry * * Note: these classes are designed for internal use in class * ReactionStoichManager. - * + * * The classes defined here implement simple operations that are * used by class ReactionStoichManager to compute things like * rates of progress, species production rates, etc. In general, a @@ -45,7 +45,7 @@ namespace Cantera { * \f] * where \f$ \nu^{(p)_{k,i}} \f$ is the product-side stoichiometric * coefficient of species \a k in reaction \a i. - * This could be done be straightforward matrix multiplication, but would be inefficient, since most of the matrix elements of \f$ \nu^{(p)}_{k,i} \f$ are zero. We could do better by using sparse-matrix algorithms to compute this product. + * This could be done be straightforward matrix multiplication, but would be inefficient, since most of the matrix elements of \f$ \nu^{(p)}_{k,i} \f$ are zero. We could do better by using sparse-matrix algorithms to compute this product. If the reactions are general ones, with non-integral stoichiometric coefficients, this is about as good as we can do. But we are @@ -57,7 +57,7 @@ than 3 product or reactant molecules. This means that instead of But we can do even better if we take account of the special structure -of this matrix for elementary reactions. +of this matrix for elementary reactions. involve three or fewer product molecules (or reactant molecules). @@ -69,14 +69,14 @@ These classes are They are designed to explicitly unroll loops over species or reactions for * Operations on reactions that require knowing the reaction - * stoichiometry. + * stoichiometry. * This module consists of class StoichManager, and * classes C1, C2, and C3. Classes C1, C2, and C3 handle operations * involving one, two, or three species, respectively, in a * reaction. Instances are instantiated with a reaction number, and n * species numbers (n = 1 for C1, etc.). All three classes have the * same interface. - * + * * These classes are designed for use by StoichManager, and the * operations implemented are those needed to efficiently compute * quantities such as rates of progress, species production rates, @@ -89,16 +89,16 @@ They are designed to explicitly unroll loops over species or reactions for * is created with reaction number irxn and species numbers k0, k1, * and k2. * - * - multiply(in, out) : out[irxn] is multiplied by + * - multiply(in, out) : out[irxn] is multiplied by * in[k0] * in[k1] * in[k2] * - * - power(in, out) : out[irxn] is multiplied by + * - power(in, out) : out[irxn] is multiplied by * (in[k0]^order0) * (in[k1]^order1) * (in[k2]^order2) - * - * - incrementReaction(in, out) : out[irxn] is incremented by + * + * - incrementReaction(in, out) : out[irxn] is incremented by * in[k0] + in[k1] + in[k2] * - * - decrementReaction(in, out) : out[irxn] is decremented by + * - decrementReaction(in, out) : out[irxn] is decremented by * in[k0] + in[k1] + in[k2] * * - incrementSpecies(in, out) : out[k0], out[k1], and out[k2] @@ -109,16 +109,16 @@ They are designed to explicitly unroll loops over species or reactions for * * The function multiply() is usually used when evaluating the * forward and reverse rates of progress of reactions. - * The rate constants are usually loaded into out[]. Then - * multply() is called to add in the dependence of the + * The rate constants are usually loaded into out[]. Then + * multply() is called to add in the dependence of the * species concentrations to yield a forward and reverse rop. * * The function incrementSpecies() and its cousin decrementSpecies() - * is used to translate from rates of progress to species production - * rates. The vector in[] is preloaed with the rates of progess of - * all reactions. Then incrementSpecies() is called to + * is used to translate from rates of progress to species production + * rates. The vector in[] is preloaed with the rates of progess of + * all reactions. Then incrementSpecies() is called to * increment the species production vector, out[], with the rates - * of progress. + * of progress. * * The functions incrementReaction() and decrementReaction() are * used to find the standard state equilibrium constant for @@ -127,24 +127,24 @@ They are designed to explicitly unroll loops over species or reactions for * of reaction, while input, usually the standard state * gibbs free energies of species, is a vector of length number of * species. - * + * * Note the stoichiometric coefficient for a species in a reaction - * is handled by always assuming it is equal to one and then + * is handled by always assuming it is equal to one and then * treating reactants and products for a reaction separately. - * Bimolecular reactions involving the identical species are + * Bimolecular reactions involving the identical species are * treated as involving separate species. * * @internal This class should be upgraded to include cases where * real stoichiometric coefficients are used. Shouldn't be that * hard to do, and they occur in engineering simulations with some * regularity. - * + * */ static doublereal ppow(doublereal x, doublereal order) { - if (x > 0.0) - return pow(x, order); - else + if (x > 0.0) + return std::pow(x, order); + else return 0.0; } @@ -162,37 +162,37 @@ They are designed to explicitly unroll loops over species or reactions for C1( int rxn = 0, int ic0 = 0) : m_rxn (rxn), m_ic0 (ic0) {} - + int data(std::vector& ic) { ic.resize(1); ic[0] = m_ic0; return m_rxn; } - - void incrementSpecies(const doublereal* R, doublereal* S) const { + + void incrementSpecies(const doublereal* R, doublereal* S) const { S[m_ic0] += R[m_rxn]; } - void decrementSpecies(const doublereal* R, doublereal* S) const { + void decrementSpecies(const doublereal* R, doublereal* S) const { S[m_ic0] -= R[m_rxn]; } - void multiply(const doublereal* S, doublereal* R) const { + void multiply(const doublereal* S, doublereal* R) const { R[m_rxn] *= S[m_ic0]; } - void incrementReaction(const doublereal* S, doublereal* R) const { + void incrementReaction(const doublereal* S, doublereal* R) const { R[m_rxn] += S[m_ic0]; } - void decrementReaction(const doublereal* S, doublereal* R) const { + void decrementReaction(const doublereal* S, doublereal* R) const { R[m_rxn] -= S[m_ic0]; } int rxnNumber() const { return m_rxn; } int speciesIndex(int n) const { return m_ic0; } int nSpecies() { return 1;} - + void writeMultiply(std::string r, std::map& out) { out[m_rxn] = fmt(r, m_ic0); } @@ -210,11 +210,11 @@ They are designed to explicitly unroll loops over species or reactions for void writeDecrementSpecies(std::string r, std::map& out) { out[m_ic0] += " - "+fmt(r, m_rxn); } - + private: int m_rxn, m_ic0; }; - + /** @@ -223,7 +223,7 @@ They are designed to explicitly unroll loops over species or reactions for */ class C2 { public: - C2( int rxn = 0, int ic0 = 0, int ic1 = 0) + C2( int rxn = 0, int ic0 = 0, int ic1 = 0) : m_rxn (rxn), m_ic0 (ic0), m_ic1 (ic1) {} int data(std::vector& ic) { @@ -233,25 +233,25 @@ They are designed to explicitly unroll loops over species or reactions for return m_rxn; } - void incrementSpecies(const doublereal* R, doublereal* S) const { + void incrementSpecies(const doublereal* R, doublereal* S) const { S[m_ic0] += R[m_rxn]; S[m_ic1] += R[m_rxn]; } - void decrementSpecies(const doublereal* R, doublereal* S) const { + void decrementSpecies(const doublereal* R, doublereal* S) const { S[m_ic0] -= R[m_rxn]; S[m_ic1] -= R[m_rxn]; } - void multiply(const doublereal* S, doublereal* R) const { + void multiply(const doublereal* S, doublereal* R) const { R[m_rxn] *= S[m_ic0] * S[m_ic1]; } - void incrementReaction(const doublereal* S, doublereal* R) const { + void incrementReaction(const doublereal* S, doublereal* R) const { R[m_rxn] += S[m_ic0] + S[m_ic1]; } - void decrementReaction(const doublereal* S, doublereal* R) const { + void decrementReaction(const doublereal* S, doublereal* R) const { R[m_rxn] -= (S[m_ic0] + S[m_ic1]); } @@ -271,13 +271,13 @@ They are designed to explicitly unroll loops over species or reactions for void writeIncrementSpecies(std::string r, std::map& out) { std::string s = " + "+fmt(r, m_rxn); - out[m_ic0] += s; - out[m_ic1] += s; + out[m_ic0] += s; + out[m_ic1] += s; } void writeDecrementSpecies(std::string r, std::map& out) { std::string s = " - "+fmt(r, m_rxn); - out[m_ic0] += s; - out[m_ic1] += s; + out[m_ic0] += s; + out[m_ic1] += s; } private: @@ -293,12 +293,12 @@ They are designed to explicitly unroll loops over species or reactions for */ int m_ic0, m_ic1; }; - + /** * Handles three species in a reaction. * @ingroup Stoichiometry - */ + */ class C3 { public: C3( int rxn = 0, int ic0 = 0, int ic1 = 0, int ic2 = 0) @@ -312,27 +312,27 @@ They are designed to explicitly unroll loops over species or reactions for return m_rxn; } - void incrementSpecies(const doublereal* R, doublereal* S) const { + void incrementSpecies(const doublereal* R, doublereal* S) const { S[m_ic0] += R[m_rxn]; S[m_ic1] += R[m_rxn]; S[m_ic2] += R[m_rxn]; } - void decrementSpecies(const doublereal* R, doublereal* S) const { + void decrementSpecies(const doublereal* R, doublereal* S) const { S[m_ic0] -= R[m_rxn]; S[m_ic1] -= R[m_rxn]; S[m_ic2] -= R[m_rxn]; } - void multiply(const doublereal* S, doublereal* R) const { + void multiply(const doublereal* S, doublereal* R) const { R[m_rxn] *= S[m_ic0] * S[m_ic1] * S[m_ic2]; } - void incrementReaction(const doublereal* S, doublereal* R) const { + void incrementReaction(const doublereal* S, doublereal* R) const { R[m_rxn] += S[m_ic0] + S[m_ic1] + S[m_ic2]; } - void decrementReaction(const doublereal* S, doublereal* R) const { + void decrementReaction(const doublereal* S, doublereal* R) const { R[m_rxn] -= (S[m_ic0] + S[m_ic1] + S[m_ic2]); } @@ -351,23 +351,23 @@ They are designed to explicitly unroll loops over species or reactions for } void writeIncrementSpecies(std::string r, std::map& out) { std::string s = " + "+fmt(r, m_rxn); - out[m_ic0] += s; - out[m_ic1] += s; - out[m_ic2] += s; + out[m_ic0] += s; + out[m_ic1] += s; + out[m_ic2] += s; } void writeDecrementSpecies(std::string r, std::map& out) { std::string s = " - "+fmt(r, m_rxn); - out[m_ic0] += s; + out[m_ic0] += s; out[m_ic1] += s; - out[m_ic2] += s; + out[m_ic2] += s; } private: - int m_rxn, m_ic0, m_ic1, m_ic2; + int m_rxn, m_ic0, m_ic1, m_ic2; }; /** - * Handles any number of species in a reaction, including fractional + * Handles any number of species in a reaction, including fractional * stoichiometric coefficients, and arbitrary reaction orders. * @ingroup Stoichiometry */ @@ -375,8 +375,8 @@ They are designed to explicitly unroll loops over species or reactions for public: C_AnyN() : m_rxn (-1) {} - C_AnyN( int rxn, const vector_int& ic, const vector_fp& order, - const vector_fp& stoich) + C_AnyN( int rxn, const vector_int& ic, const vector_fp& order, + const vector_fp& stoich) : m_rxn (rxn) { m_n = ic.size(); m_ic.resize(m_n); @@ -395,39 +395,39 @@ They are designed to explicitly unroll loops over species or reactions for for (n = 0; n < m_n; n++) ic[n] = m_ic[n]; return m_rxn; } - + doublereal order(int n) const {return m_order[n];} doublereal stoich(int n) const {return m_stoich[n];} int speciesIndex(int n) const {return m_ic[n];} void multiply(const doublereal* input, doublereal* output) const { for (int n = 0; n < m_n; n++) { - output[m_rxn] *= - ppow(input[m_ic[n]],m_order[n]); - } + output[m_rxn] *= + ppow(input[m_ic[n]],m_order[n]); + } } - void incrementSpecies(const doublereal* input, + void incrementSpecies(const doublereal* input, doublereal* output) const { doublereal x = input[m_rxn]; for (int n = 0; n < m_n; n++) output[m_ic[n]] += m_stoich[n]*x; } - void decrementSpecies(const doublereal* input, + void decrementSpecies(const doublereal* input, doublereal* output) const { doublereal x = input[m_rxn]; for (int n = 0; n < m_n; n++) output[m_ic[n]] -= m_stoich[n]*x; } - void incrementReaction(const doublereal* input, - doublereal* output) const { - for (int n = 0; n < m_n; n++) output[m_rxn] + void incrementReaction(const doublereal* input, + doublereal* output) const { + for (int 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 (int n = 0; n < m_n; n++) output[m_rxn] + void decrementReaction(const doublereal* input, + doublereal* output) const { + for (int n = 0; n < m_n; n++) output[m_rxn] -= m_stoich[n]*input[m_ic[n]]; } @@ -477,70 +477,70 @@ They are designed to explicitly unroll loops over species or reactions for vector_fp m_order; vector_fp m_stoich; }; - + template - inline static void _multiply(InputIter begin, InputIter end, + inline static void _multiply(InputIter begin, InputIter end, const Vec1& input, Vec2& output) { - for (; begin != end; ++begin) + for (; begin != end; ++begin) begin->multiply(input, output); } template - inline static void _incrementSpecies(InputIter begin, + inline static void _incrementSpecies(InputIter begin, InputIter end, const Vec1& input, Vec2& output) { - for (; begin != end; ++begin) + for (; begin != end; ++begin) begin->incrementSpecies(input, output); } template - inline static void _decrementSpecies(InputIter begin, + inline static void _decrementSpecies(InputIter begin, InputIter end, const Vec1& input, Vec2& output) { - for (; begin != end; ++begin) + for (; begin != end; ++begin) begin->decrementSpecies(input, output); } template - inline static void _incrementReactions(InputIter begin, + inline static void _incrementReactions(InputIter begin, InputIter end, const Vec1& input, Vec2& output) { - for (; begin != end; ++begin) + for (; begin != end; ++begin) begin->incrementReaction(input, output); } template - inline static void _decrementReactions(InputIter begin, + inline static void _decrementReactions(InputIter begin, InputIter end, const Vec1& input, Vec2& output) { - for (; begin != end; ++begin) + for (; begin != end; ++begin) begin->decrementReaction(input, output); } template - inline static void _writeIncrementSpecies(InputIter begin, InputIter end, std::string r, + inline static void _writeIncrementSpecies(InputIter begin, InputIter end, std::string r, std::map& out) { for (; begin != end; ++begin) begin->writeIncrementSpecies(r, out); } template - inline static void _writeDecrementSpecies(InputIter begin, InputIter end, std::string r, + inline static void _writeDecrementSpecies(InputIter begin, InputIter end, std::string r, std::map& out) { for (; begin != end; ++begin) begin->writeDecrementSpecies(r, out); } template - inline static void _writeIncrementReaction(InputIter begin, InputIter end, std::string r, + inline static void _writeIncrementReaction(InputIter begin, InputIter end, std::string r, std::map& out) { for (; begin != end; ++begin) begin->writeIncrementReaction(r, out); } template - inline static void _writeDecrementReaction(InputIter begin, InputIter end, std::string r, + inline static void _writeDecrementReaction(InputIter begin, InputIter end, std::string r, std::map& out) { for (; begin != end; ++begin) begin->writeDecrementReaction(r, out); } template - inline static void _writeMultiply(InputIter begin, InputIter end, std::string r, + inline static void _writeMultiply(InputIter begin, InputIter end, std::string r, std::map& out) { for (; begin != end; ++begin) begin->writeMultiply(r, out); } @@ -560,15 +560,15 @@ They are designed to explicitly unroll loops over species or reactions for * reaction number i. * \f[ * r_i = \sum_m^{M_i} s_{k_{m,i}} - * \f] + * \f] * To understand the operations performed by this class, let * \f$ N_{k,i}\f$ denote the stoichiometric coefficient of species k on * one side (reactant or product) in reaction i. Then \b N is a sparse * K by I matrix of stoichiometric coefficients. - * + * * The following matrix operations may be carried out with a vector * S of length K, and a vector R of length I: - * + * * - \f$ S = S + N R\f$ (incrementSpecies) * - \f$ S = S - N R\f$ (decrementSpecies) * - \f$ R = R + N^T S \f$ (incrementReaction) @@ -581,7 +581,7 @@ They are designed to explicitly unroll loops over species or reactions for * \f[ * S_k = R_{i1} + \dots + R_{iM} * \f] - * where M is the number of molecules, and $\f i(m) \f$ is the + * where M is the number of molecules, and $\f i(m) \f$ is the * @ingroup Stoichiometry */ class StoichManagerN { @@ -639,7 +639,7 @@ They are designed to explicitly unroll loops over species or reactions for * @param stoich This is used to handle fractional stoichiometric coefficients * on the product side of irreversible reactions. */ - void add(int rxn, const vector_int& k, const vector_fp& order, + void add(int rxn, const vector_int& k, const vector_fp& order, const vector_fp& stoich) { m_n[rxn] = static_cast(k.size()); int ns = stoich.size(); @@ -649,30 +649,30 @@ They are designed to explicitly unroll loops over species or reactions for if (stoich[n] != 1.0) frac = true; } if (frac) { - m_loc[rxn] = static_cast(m_cn_list.size()); + m_loc[rxn] = static_cast(m_cn_list.size()); m_cn_list.push_back(C_AnyN(rxn, k, order, stoich)); } else { switch (k.size()) { case 1: m_loc[rxn] = static_cast(m_c1_list.size()); - m_c1_list.push_back(C1(rxn, k[0])); - break; + m_c1_list.push_back(C1(rxn, k[0])); + break; case 2: - m_loc[rxn] = static_cast(m_c2_list.size()); - m_c2_list.push_back(C2(rxn, k[0], k[1])); - break; + m_loc[rxn] = static_cast(m_c2_list.size()); + m_c2_list.push_back(C2(rxn, k[0], k[1])); + break; case 3: - m_loc[rxn] = static_cast(m_c3_list.size()); - m_c3_list.push_back(C3(rxn, k[0], k[1], k[2])); - break; + m_loc[rxn] = static_cast(m_c3_list.size()); + m_c3_list.push_back(C3(rxn, k[0], k[1], k[2])); + break; default: - m_loc[rxn] = static_cast(m_cn_list.size()); + m_loc[rxn] = static_cast(m_cn_list.size()); m_cn_list.push_back(C_AnyN(rxn, k, order, stoich)); } } } - + void multiply(const doublereal* input, doublereal* output) const { _multiply(m_c1_list.begin(), m_c1_list.end(), input, output); _multiply(m_c2_list.begin(), m_c2_list.end(), input, output); @@ -707,7 +707,7 @@ They are designed to explicitly unroll loops over species or reactions for _decrementReactions(m_c3_list.begin(), m_c3_list.end(), input, output); _decrementReactions(m_cn_list.begin(), m_cn_list.end(), input, output); } - + void writeIncrementSpecies(std::string r, std::map& out) { _writeIncrementSpecies(m_c1_list.begin(), m_c1_list.end(), r, out); _writeIncrementSpecies(m_c2_list.begin(), m_c2_list.end(), r, out); @@ -782,14 +782,14 @@ They are designed to explicitly unroll loops over species or reactions for } } - void add(int rxn, const vector_int& k, const vector_fp& order, + void add(int rxn, const vector_int& k, const vector_fp& order, const vector_fp& stoich) { int n, nn = k.size(); std::string s; for (n = 0; n < nn; n++) { - if (order[n] == 1.0) + if (order[n] == 1.0) m_mult[rxn] += "*c[" + int2str(k[n]) + "]"; - else + else m_mult[rxn] += "*pow(c[" _ int2str(k[n]) + "],"+fp2str(order[n])+")"; if (stoich[n] == 1.0) { m_is[k[n]] += " + r[" + int2str(rxn) + "]"; @@ -810,7 +810,7 @@ They are designed to explicitly unroll loops over species or reactions for std::string mult(int rxn) { return m_mult[rxn]; } std::string incrSpec(int k, std::string) { return m_is[k]; } std::string decrSpec(int k) { return m_ds[k]; } - std::string incrRxn(int rxn) { return m_ir[rxn]; } + std::string incrRxn(int rxn) { return m_ir[rxn]; } std::string decrRxn(int rxn) { return m_dr[rxn]; } private: @@ -822,4 +822,3 @@ They are designed to explicitly unroll loops over species or reactions for } #endif - diff --git a/Cantera/src/ThermoPhase.h b/Cantera/src/ThermoPhase.h index 2e432341a..9e7e6e199 100755 --- a/Cantera/src/ThermoPhase.h +++ b/Cantera/src/ThermoPhase.h @@ -761,7 +761,7 @@ namespace Cantera { bool getElementPotentials(doublereal* lambda) { if (m_hasElementPotentials) - copy(m_lambda.begin(), m_lambda.end(), lambda); + std::copy(m_lambda.begin(), m_lambda.end(), lambda); return (m_hasElementPotentials); }