16 #ifndef CT_UTILITIES_H
17 #define CT_UTILITIES_H
32 template<
class T>
struct timesConstant :
public std::unary_function<T, double> {
69 inline doublereal
dot4(
const V& x,
const V& y)
71 return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3];
87 inline doublereal
dot5(
const V& x,
const V& y)
89 return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] +
106 inline doublereal
dot6(
const V& x,
const V& y)
109 return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] +
110 x[4]*y[4] + x[5]*y[5];
134 template<
class InputIter,
class InputIter2>
135 inline doublereal
dot(InputIter x_begin, InputIter x_end,
138 return inner_product(x_begin, x_end, y_begin, 0.0);
157 template<
class InputIter,
class OutputIter,
class S>
158 inline void scale(InputIter begin, InputIter end,
159 OutputIter out, S scale_factor)
196 template<
class InputIter,
class OutputIter,
class S>
198 OutputIter out, S scale_factor)
201 "To be removed after Cantera 2.2.");
202 for (; begin != end; ++begin, ++out) {
203 *out += scale_factor * *begin;
233 template<
class InputIter,
class OutputIter>
237 for (; x_begin != x_end; ++x_begin, ++y_begin) {
238 *x_begin *= *y_begin;
270 template<
class InputIter>
274 "To be removed after Cantera 2.2.");
275 for (; begin != end; ++begin) {
304 template<
class InputIter>
305 inline doublereal
absmax(InputIter begin, InputIter end)
307 doublereal amax = 0.0;
308 for (; begin != end; ++begin) {
309 amax = std::max(fabs(*begin), amax);
342 template<
class InputIter,
class OutputIter>
346 doublereal sum = accumulate(begin, end, 0.0);
347 for (; begin != end; ++begin, ++out) {
377 template<
class InputIter,
class OutputIter>
381 for (; x_begin != x_end; ++x_begin, ++y_begin) {
382 *x_begin /= *y_begin;
398 template<
class InputIter,
class OutputIter>
399 inline void sum_each(OutputIter x_begin, OutputIter x_end,
402 for (; x_begin != x_end; ++x_begin, ++y_begin) {
403 *x_begin += *y_begin;
438 template<
class InputIter,
class OutputIter,
class IndexIter>
440 OutputIter result, IndexIter index)
442 for (; begin != end; ++begin, ++index) {
443 *(result + *index) = *begin;
474 template<
class InputIter,
class RandAccessIter,
class IndexIter>
476 RandAccessIter data, IndexIter index)
478 for (; mult_begin != mult_end; ++mult_begin, ++index) {
479 *(data + *index) *= *mult_begin;
510 template<
class InputIter,
class OutputIter,
class IndexIter>
512 OutputIter result, IndexIter index)
515 "To be removed after Cantera 2.2.");
516 for (; begin != end; ++begin, ++index) {
517 *(result + *index) /= *begin;
535 template<
class InputIter>
536 inline doublereal
sum_xlogx(InputIter begin, InputIter end)
538 doublereal sum = 0.0;
539 for (; begin != end; ++begin) {
540 sum += (*begin) * std::log(*begin +
Tiny);
563 template<
class InputIter1,
class InputIter2>
564 inline doublereal
sum_xlogQ(InputIter1 begin, InputIter1 end,
567 doublereal sum = 0.0;
568 for (; begin != end; ++begin, ++Q_begin) {
569 sum += (*begin) * std::log(*Q_begin +
Tiny);
589 template<
class OutputIter>
590 inline void scale(
int N,
double alpha, OutputIter x)
593 "To be removed after Cantera 2.2.");
594 scale(x, x+N, x, alpha);
603 template<
class D,
class R>
606 return ((((((c[6]*x + c[5])*x + c[4])*x + c[3])*x +
607 c[2])*x + c[1])*x + c[0]);
615 template<
class D,
class R>
618 return ((((((((c[8]*x + c[7])*x + c[6])*x + c[5])*x + c[4])*x + c[3])*x +
619 c[2])*x + c[1])*x + c[0]);
628 template<
class D,
class R>
632 "To be removed after Cantera 2.2.");
633 return ((((((((((c[10]*x + c[9])*x + c[8])*x + c[7])*x
634 + c[6])*x + c[5])*x + c[4])*x + c[3])*x
635 + c[2])*x + c[1])*x + c[0]);
643 template<
class D,
class R>
646 return (((((c[5]*x + c[4])*x + c[3])*x +
647 c[2])*x + c[1])*x + c[0]);
655 template<
class D,
class R>
658 return ((((c[4]*x + c[3])*x +
659 c[2])*x + c[1])*x + c[0]);
667 template<
class D,
class R>
670 return (((c[3]*x + c[2])*x + c[1])*x + c[0]);
687 size_t is = toVec.size();
688 for (
size_t i = 0; i < is; i++) {
693 for (
size_t i = 0; i < is; i++) {
695 toVec[i] =
new D(*(fromVec[i]));
713 template <
class T,
class U>
714 const U&
getValue(
const std::map<T, U>& m,
const T& key) {
715 typename std::map<T,U>::const_iterator iter = m.find(key);
716 if (iter == m.end()) {
717 throw std::out_of_range(
"std::map: key not found");
728 template <
class T,
class U>
729 const U&
getValue(
const std::map<T, U>& m,
const T& key,
const U& default_val) {
730 typename std::map<T,U>::const_iterator iter = m.find(key);
731 return (iter == m.end()) ? default_val : iter->second;
doublereal dot6(const V &x, const V &y)
Templated Inner product of two vectors of length 6.
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.
R poly10(D x, R *c)
Templated evaluation of a polynomial of order 10.
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.
void resize_each(int m, InputIter begin, InputIter end)
Invoke method 'resize' with argument m for a sequence of objects (templated version) ...
R poly4(D x, R *c)
Evaluates a polynomial of order 4.
void increment_scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
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.
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 deepStdVectorPointerCopy(const std::vector< D * > &fromVec, std::vector< D * > &toVec)
Templated deep copy of a std vector of pointers.
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. ...
T m_c
Stored constant value of time T.
void scatter_divide(InputIter begin, InputIter end, OutputIter result, IndexIter index)
Divide selected elements in an array by a contiguous sequence of divisors.