Deprecate rarely-used vector functions

This commit is contained in:
Ray Speth 2018-11-14 19:24:05 -05:00
parent 6a859215f8
commit 19577abfbe
8 changed files with 58 additions and 44 deletions

View file

@ -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<class InputIter, class OutputIter>
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<class InputIter>
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<class InputIter, class OutputIter>
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<class InputIter, class OutputIter>
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<class InputIter, class OutputIter>
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<class InputIter, class OutputIter, class IndexIter>
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<class InputIter, class RandAccessIter, class IndexIter>
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<class InputIter>
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<class InputIter1, class InputIter2>
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);

View file

@ -11,7 +11,6 @@
#include "Kinetics.h"
#include "Reaction.h"
#include "cantera/base/utilities.h"
#include "RateCoeffMgr.h"
namespace Cantera

View file

@ -8,7 +8,7 @@
#ifndef CT_THIRDBODYCALC_H
#define CT_THIRDBODYCALC_H
#include "cantera/base/utilities.h"
#include "cantera/base/ct_defs.h"
#include <cassert>
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() {

View file

@ -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);

View file

@ -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];
}
}

View file

@ -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.

View file

@ -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,

View file

@ -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