17 #ifndef CT_UTILITIES_H
18 #define CT_UTILITIES_H
35 template<
class T>
struct timesConstant :
public std::unary_function<T, double> {
43 "To be removed after Cantera 2.5. Replaceable with C++11 lambda.");
70 inline doublereal
dot4(
const V& x,
const V& y)
72 return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3];
85 inline doublereal
dot5(
const V& x,
const V& y)
87 return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] +
111 template<
class InputIter,
class InputIter2>
112 inline doublereal
dot(InputIter x_begin, InputIter x_end,
115 return std::inner_product(x_begin, x_end, y_begin, 0.0);
134 template<
class InputIter,
class OutputIter,
class S>
135 inline void scale(InputIter begin, InputIter end,
136 OutputIter out, S scale_factor)
138 std::transform(begin, end, out,
139 [scale_factor](
double x) {
return x * scale_factor; });
168 template<
class InputIter,
class OutputIter>
173 for (; x_begin != x_end; ++x_begin, ++y_begin) {
174 *x_begin *= *y_begin;
203 template<
class InputIter>
204 inline doublereal
absmax(InputIter begin, InputIter end)
207 doublereal amax = 0.0;
208 for (; begin != end; ++begin) {
209 amax = std::max(fabs(*begin), amax);
244 template<
class InputIter,
class OutputIter>
249 doublereal sum = std::accumulate(begin, end, 0.0);
250 for (; begin != end; ++begin, ++out) {
281 template<
class InputIter,
class OutputIter>
286 for (; x_begin != x_end; ++x_begin, ++y_begin) {
287 *x_begin /= *y_begin;
304 template<
class InputIter,
class OutputIter>
305 inline void sum_each(OutputIter x_begin, OutputIter x_end,
309 for (; x_begin != x_end; ++x_begin, ++y_begin) {
310 *x_begin += *y_begin;
346 template<
class InputIter,
class OutputIter,
class IndexIter>
348 OutputIter result, IndexIter index)
351 for (; begin != end; ++begin, ++index) {
352 *(result + *index) = *begin;
385 template<
class InputIter,
class RandAccessIter,
class IndexIter>
387 RandAccessIter data, IndexIter index)
390 for (; mult_begin != mult_end; ++mult_begin, ++index) {
391 *(data + *index) *= *mult_begin;
409 template<
class InputIter>
410 inline doublereal
sum_xlogx(InputIter begin, InputIter end)
413 doublereal sum = 0.0;
414 for (; begin != end; ++begin) {
415 sum += (*begin) * std::log(*begin +
Tiny);
437 template<
class InputIter1,
class InputIter2>
438 inline doublereal
sum_xlogQ(InputIter1 begin, InputIter1 end,
442 doublereal sum = 0.0;
443 for (; begin != end; ++begin, ++Q_begin) {
444 sum += (*begin) * std::log(*Q_begin +
Tiny);
454 template<
class D,
class R>
457 return ((((((c[6]*x + 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[8]*x + c[7])*x + c[6])*x + c[5])*x + c[4])*x + c[3])*x +
470 c[2])*x + c[1])*x + c[0]);
478 template<
class D,
class R>
481 return (((((c[5]*x + c[4])*x + c[3])*x +
482 c[2])*x + c[1])*x + c[0]);
490 template<
class D,
class R>
493 return ((((c[4]*x + c[3])*x +
494 c[2])*x + c[1])*x + c[0]);
502 template<
class D,
class R>
505 return (((c[3]*x + c[2])*x + c[1])*x + c[0]);
520 void checkFinite(
const std::string& name,
double* values,
size_t N);
527 template <
class T,
class U>
528 const U&
getValue(
const std::map<T, U>& m,
const T& key,
const U& default_val) {
529 typename std::map<T,U>::const_iterator iter = m.find(key);
530 return (iter == m.end()) ? default_val : iter->second;
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
This file contains definitions for utility functions and text for modules, inputfiles,...
const double Tiny
Small number to compare differences of mole fractions against.
Namespace for the Cantera kernel.
const U & getValue(const std::map< T, U > &m, const T &key, const U &default_val)
Const accessor for a value in a std::map.
void checkFinite(const double tmp)
Check to see that a number is finite (not NaN, +Inf or -Inf)
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.
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
doublereal sum_xlogQ(InputIter1 begin, InputIter1 end, InputIter2 Q_begin)
Compute.
doublereal absmax(InputIter begin, InputIter end)
The maximum absolute value (templated version)
void multiply_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Multiply each entry in x by the corresponding entry in y.
doublereal sum_xlogx(InputIter begin, InputIter end)
Compute.
doublereal dot4(const V &x, const V &y)
Templated Inner product of two vectors of length 4.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
R poly5(D x, R *c)
Templated evaluation of a polynomial of order 5.
doublereal dot5(const V &x, const V &y)
Templated Inner product of two vectors of length 5.
void scatter_copy(InputIter begin, InputIter end, OutputIter result, IndexIter index)
Copies a contiguous range in a sequence to indexed positions in another sequence.
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 sum_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Increment each entry in x by the corresponding entry in y.
void normalize(InputIter begin, InputIter end, OutputIter out)
Normalize the values in a sequence, such that they sum to 1.0 (templated version)
R poly8(D x, R *c)
Templated evaluation of a polynomial of order 8.
R poly3(D x, R *c)
Templated evaluation of a polynomial of order 3.
R poly4(D x, R *c)
Evaluates a polynomial of order 4.
R poly6(D x, R *c)
Templated evaluation of a polynomial of order 6.
Unary operator to multiply the argument by a constant.
timesConstant(T c)
Constructor.
T m_c
Stored constant value of time T.
double operator()(T x)
Parenthesis operator returning a double.