17 #ifndef CT_UTILITIES_H 18 #define CT_UTILITIES_H 33 template<
class T>
struct timesConstant :
public std::unary_function<T, double> {
65 inline doublereal
dot4(
const V& x,
const V& y)
67 return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3];
80 inline doublereal
dot5(
const V& x,
const V& y)
82 return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] +
106 template<
class InputIter,
class InputIter2>
107 inline doublereal
dot(InputIter x_begin, InputIter x_end,
110 return inner_product(x_begin, x_end, y_begin, 0.0);
129 template<
class InputIter,
class OutputIter,
class S>
130 inline void scale(InputIter begin, InputIter end,
131 OutputIter out, S scale_factor)
161 template<
class InputIter,
class OutputIter>
165 for (; x_begin != x_end; ++x_begin, ++y_begin) {
166 *x_begin *= *y_begin;
194 template<
class InputIter>
195 inline doublereal
absmax(InputIter begin, InputIter end)
197 doublereal amax = 0.0;
198 for (; begin != end; ++begin) {
199 amax = std::max(fabs(*begin), amax);
233 template<
class InputIter,
class OutputIter>
237 doublereal sum = accumulate(begin, end, 0.0);
238 for (; begin != end; ++begin, ++out) {
268 template<
class InputIter,
class OutputIter>
272 for (; x_begin != x_end; ++x_begin, ++y_begin) {
273 *x_begin /= *y_begin;
289 template<
class InputIter,
class OutputIter>
290 inline void sum_each(OutputIter x_begin, OutputIter x_end,
293 for (; x_begin != x_end; ++x_begin, ++y_begin) {
294 *x_begin += *y_begin;
329 template<
class InputIter,
class OutputIter,
class IndexIter>
331 OutputIter result, IndexIter index)
333 for (; begin != end; ++begin, ++index) {
334 *(result + *index) = *begin;
366 template<
class InputIter,
class RandAccessIter,
class IndexIter>
368 RandAccessIter data, IndexIter index)
370 for (; mult_begin != mult_end; ++mult_begin, ++index) {
371 *(data + *index) *= *mult_begin;
388 template<
class InputIter>
389 inline doublereal
sum_xlogx(InputIter begin, InputIter end)
391 doublereal sum = 0.0;
392 for (; begin != end; ++begin) {
393 sum += (*begin) * std::log(*begin +
Tiny);
414 template<
class InputIter1,
class InputIter2>
415 inline doublereal
sum_xlogQ(InputIter1 begin, InputIter1 end,
418 doublereal sum = 0.0;
419 for (; begin != end; ++begin, ++Q_begin) {
420 sum += (*begin) * std::log(*Q_begin +
Tiny);
430 template<
class D,
class R>
433 return ((((((c[6]*x + c[5])*x + c[4])*x + c[3])*x +
434 c[2])*x + c[1])*x + c[0]);
442 template<
class D,
class R>
445 return ((((((((c[8]*x + c[7])*x + c[6])*x + c[5])*x + c[4])*x + c[3])*x +
446 c[2])*x + c[1])*x + c[0]);
454 template<
class D,
class R>
457 return (((((c[5]*x + c[4])*x + c[3])*x +
458 c[2])*x + c[1])*x + c[0]);
466 template<
class D,
class R>
469 return ((((c[4]*x + c[3])*x +
470 c[2])*x + c[1])*x + c[0]);
478 template<
class D,
class R>
481 return (((c[3]*x + c[2])*x + c[1])*x + c[0]);
498 warn_deprecated(
"deepStdVectorPointerCopy",
"Used only in deprecated code." 499 " To be removed after Cantera 2.3.");
500 size_t is = toVec.size();
501 for (
size_t i = 0; i < is; i++) {
506 for (
size_t i = 0; i < is; i++) {
508 toVec[i] =
new D(*fromVec[i]);
527 void checkFinite(
const std::string& name,
double* values,
size_t N);
536 template <
class T,
class U>
537 const U&
getValue(
const std::map<T, U>& m,
const T& key) {
539 "Use map.at(key) instead. To be removed after Cantera 2.3.");
540 typename std::map<T,U>::const_iterator iter = m.find(key);
541 if (iter == m.end()) {
542 throw std::out_of_range(
"std::map: key not found");
553 template <
class T,
class U>
554 const U&
getValue(
const std::map<T, U>& m,
const T& key,
const U& default_val) {
555 typename std::map<T,U>::const_iterator iter = m.find(key);
556 return (iter == m.end()) ? default_val : iter->second;
R poly3(D x, R *c)
Templated evaluation of a polynomial of order 3.
void divide_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Templated divide of each element of x by the corresponding element of y.
timesConstant(T c)
Constructor.
void checkFinite(const double tmp)
Check to see that a number is finite (not NaN, +Inf or -Inf)
doublereal dot4(const V &x, const V &y)
Templated Inner product of two vectors of length 4.
R poly5(D x, R *c)
Templated evaluation of a polynomial of order 5.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, (see Input File Handling, Diagnostic Output, and Writing messages to the screen).
Unary operator to multiply the argument by a constant.
double operator()(T x)
Parenthesis operator returning a double.
void multiply_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Multiply each entry in x by the corresponding entry in y.
R poly4(D x, R *c)
Evaluates a polynomial of order 4.
R poly8(D x, R *c)
Templated evaluation of a polynomial of order 8.
void normalize(InputIter begin, InputIter end, OutputIter out)
Normalize the values in a sequence, such that they sum to 1.0 (templated version) ...
R poly6(D x, R *c)
Templated evaluation of a polynomial of order 6.
void scatter_mult(InputIter mult_begin, InputIter mult_end, RandAccessIter data, IndexIter index)
Multiply selected elements in an array by a contiguous sequence of multipliers.
void deepStdVectorPointerCopy(const std::vector< D *> &fromVec, std::vector< D *> &toVec)
Templated deep copy of a std vector of pointers.
doublereal absmax(InputIter begin, InputIter end)
The maximum absolute value (templated version)
doublereal sum_xlogQ(InputIter1 begin, InputIter1 end, InputIter2 Q_begin)
Compute .
const U & getValue(const std::map< T, U > &m, const T &key)
Const accessor for a value in a std::map.
doublereal sum_xlogx(InputIter begin, InputIter end)
Compute .
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
void sum_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Increment each entry in x by the corresponding entry in y.
doublereal dot5(const V &x, const V &y)
Templated Inner product of two vectors of length 5.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
const doublereal Tiny
Small number to compare differences of mole fractions against.
void scatter_copy(InputIter begin, InputIter end, OutputIter result, IndexIter index)
Copies a contiguous range in a sequence to indexed positions in another sequence. ...
Namespace for the Cantera kernel.
T m_c
Stored constant value of time T.