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;