Cantera  2.1.2
utilities.h
Go to the documentation of this file.
1 /**
2  * @file utilities.h
3  * Various templated functions that carry out common vector
4  * operations (see \ref utils).
5  */
6 
7 // Copyright 2001 California Institute of Technology
8 /**
9  * @defgroup utils Templated Utility Functions
10  *
11  * These are templates to perform various simple operations on arrays.
12  * Note that the compiler will inline these, so using them carries no
13  * performance penalty.
14  */
15 
16 #ifndef CT_UTILITIES_H
17 #define CT_UTILITIES_H
18 
19 #include "ct_defs.h"
20 
21 #include <algorithm>
22 
23 namespace Cantera
24 {
25 //! Unary operator to multiply the argument by a constant.
26 /*!
27  * The form of this operator is designed for use by std::transform.
28  * @see @ref scale().
29  */
30 template<class T> struct timesConstant : public std::unary_function<T, double> {
31  //! Constructor
32  /*!
33  * @param c Constant of templated type T
34  * that will be stored internally within the object
35  * and used in the multiplication operation
36  */
37  timesConstant(T c) : m_c(c) {}
38 
39  //! Parenthesis operator returning a double
40  /*!
41  * @param x Variable of templated type T that will be
42  * used in the multiplication operator
43  *
44  * @return Returns a value of type double from the internal
45  * multiplication
46  */
47  double operator()(T x) {
48  return m_c * x;
49  }
50 
51  //! Stored constant value of time T
52  T m_c;
53 };
54 
55 //! Templated Inner product of two vectors of length 4.
56 /*!
57  * If either \a x
58  * or \a y has length greater than 4, only the first 4 elements
59  * will be used.
60  *
61  * @param x first reference to the templated class V
62  * @param y second reference to the templated class V
63  * @return
64  * This class returns a hard-coded type, doublereal.
65  */
66 template<class V>
67 inline doublereal dot4(const V& x, const V& y)
68 {
69  return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3];
70 }
71 
72 
73 //! Templated Inner product of two vectors of length 5
74 /*!
75  * If either \a x
76  * or \a y has length greater than 4, only the first 4 elements
77  * will be used.
78  *
79  * @param x first reference to the templated class V
80  * @param y second reference to the templated class V
81  * @return
82  * This class returns a hard-coded type, doublereal.
83  */
84 template<class V>
85 inline doublereal dot5(const V& x, const V& y)
86 {
87  return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] +
88  x[4]*y[4];
89 }
90 
91 //! Templated Inner product of two vectors of length 6
92 /*!
93  * If either \a x
94  * or \a y has length greater than 4, only the first 4 elements
95  * will be used.
96  *
97  * @param x first reference to the templated class V
98  * @param y second reference to the templated class V
99  * @return
100  * This class returns a hard-coded type, doublereal.
101  */
102 template<class V>
103 inline doublereal dot6(const V& x, const V& y)
104 {
105  return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] +
106  x[4]*y[4] + x[5]*y[5];
107 }
108 
109 //! Function that calculates a templated inner product.
110 /*!
111  * This inner product is templated twice. The output variable is hard coded
112  * to return a doublereal.
113  *
114  * template<class InputIter, class InputIter2>
115  *
116  * @code
117  * double x[8], y[8];
118  * doublereal dsum = dot<double *,double *>(x, &x+7, y);
119  * @endcode
120  *
121  * @param x_begin Iterator pointing to the beginning, belonging to the
122  * iterator class InputIter.
123  * @param x_end Iterator pointing to the end, belonging to the
124  * iterator class InputIter.
125  * @param y_begin Iterator pointing to the beginning of y, belonging to the
126  * iterator class InputIter2.
127  * @return
128  * The return is hard-coded to return a double.
129  */
130 template<class InputIter, class InputIter2>
131 inline doublereal dot(InputIter x_begin, InputIter x_end,
132  InputIter2 y_begin)
133 {
134  return inner_product(x_begin, x_end, y_begin, 0.0);
135 }
136 
137 //! Multiply elements of an array by a scale factor.
138 /*!
139  * \code
140  * vector_fp in(8, 1.0), out(8);
141  * scale(in.begin(), in.end(), out.begin(), factor);
142  * \endcode
143  *
144  * @param begin Iterator pointing to the beginning, belonging to the
145  * iterator class InputIter.
146  * @param end Iterator pointing to the end, belonging to the
147  * iterator class InputIter.
148  * @param out Iterator pointing to the beginning of out, belonging to the
149  * iterator class OutputIter. This is the output variable
150  * for this routine.
151  * @param scale_factor input scale factor belonging to the class S.
152  */
153 template<class InputIter, class OutputIter, class S>
154 inline void scale(InputIter begin, InputIter end,
155  OutputIter out, S scale_factor)
156 {
157  std::transform(begin, end, out, timesConstant<S>(scale_factor));
158 }
159 
160 /*!
161  * Multiply elements of an array, y, by a scale factor, f and add the
162  * result to an existing array, x. This is essentially a templated daxpy_
163  * operation.
164  *
165  * The template arguments are: template<class InputIter,
166  * class OutputIter, class S>
167  *
168  * Simple Code Example of the functionality;
169  * @code
170  * double x[10], y[10], f;
171  * for (i = 0; i < n; i++) {
172  * y[i] += f * x[i]
173  * }
174  * @endcode
175  * Example of the function call to implement the simple code example
176  * @code
177  * double x[10], y[10], f;
178  * increment_scale(x, x+10, y, f);
179  * @endcode
180  *
181  * It is templated with three parameters. The first template
182  * is the iterator, InputIter, which controls access to y[].
183  * The second template is the iterator OutputIter, which controls
184  * access to y[]. The third iterator is S, which is f.
185  *
186  * @param begin InputIter Iterator for beginning of y[]
187  * @param end inputIter Iterator for end of y[]
188  * @param out OutputIter Iterator for beginning of x[]
189  * @param scale_factor Scale Factor to multiply y[i] by
190  */
191 template<class InputIter, class OutputIter, class S>
192 inline void increment_scale(InputIter begin, InputIter end,
193  OutputIter out, S scale_factor)
194 {
195  for (; begin != end; ++begin, ++out) {
196  *out += scale_factor * *begin;
197  }
198 }
199 
200 
201 //! Multiply each entry in x by the corresponding entry in y.
202 /*!
203  * The template arguments are: template<class InputIter, class OutputIter>
204  *
205  * Simple code Equivalent:
206  * \code
207  * double x[10], y[10]
208  * for (n = 0; n < 10; n++) {
209  * x[n] *= y[n];
210  * }
211  * \endcode
212  * Example of function call usage to implement the simple code example:
213  * \code
214  * double x[10], y[10]
215  * multiply_each(x, x+10, y);
216  * \endcode
217  *
218  * @param x_begin Iterator pointing to the beginning of the vector x, belonging to the
219  * iterator class InputIter.
220  * @param x_end Iterator pointing to the end of the vector x, belonging to the
221  * iterator class InputIter. The difference between end and begin
222  * determines the loop length
223  * @param y_begin Iterator pointing to the beginning of the vector y, belonging to the
224  * iterator class outputIter.
225  */
226 template<class InputIter, class OutputIter>
227 inline void multiply_each(OutputIter x_begin, OutputIter x_end,
228  InputIter y_begin)
229 {
230  for (; x_begin != x_end; ++x_begin, ++y_begin) {
231  *x_begin *= *y_begin;
232  }
233 }
234 
235 //! Invoke method 'resize' with argument \a m for a sequence of objects (templated version)
236 /*!
237  * The template arguments are: template<class InputIter>
238  *
239  * Simple code Equivalent:
240  * \code
241  * vector<vector<double> *> VV;
242  * for (n = 0; n < 20; n++) {
243  * vector<double> *vp = VV[n];
244  * vp->resize(m);
245  * }
246  * \endcode
247  * Example of function call usage to implement the simple code example:
248  * \code
249  * vector<vector<double> *> VV;
250  * resize_each(m, &VV[0], &VV[20]);
251  * \endcode
252  *
253  * @param m Integer specifying the size that each object should be resized to.
254  * @param begin Iterator pointing to the beginning of the sequence of object, belonging to the
255  * iterator class InputIter.
256  * @param end Iterator pointing to the end of the sequence of objects, belonging to the
257  * iterator class InputIter. The difference between end and begin
258  * determines the loop length
259  *
260  * @note This is currently unused.
261  */
262 template<class InputIter>
263 inline void resize_each(int m, InputIter begin, InputIter end)
264 {
265  for (; begin != end; ++begin) {
266  begin->resize(m);
267  }
268 }
269 
270 //! The maximum absolute value (templated version)
271 /*!
272  * The template arguments are: template<class InputIter>
273  *
274  * Simple code Equivalent:
275  * \code
276  * double x[10] amax = 0.0;
277  * for (int n = 0; n < 10; n++) {
278  * if (fabs(x[n]) > amax) amax = fabs(x[10]);
279  * }
280  * return amax;
281  * \endcode
282  * Example of function call usage to implement the simple code example:
283  * \code
284  * double x[10]
285  * double amax = absmax(x, x+10);
286  * \endcode
287  *
288  * @param begin Iterator pointing to the beginning of the x vector, belonging to the
289  * iterator class InputIter.
290  * @param end Iterator pointing to the end of the x vector, belonging to the
291  * iterator class InputIter. The difference between end and begin
292  * determines the loop length
293  */
294 template<class InputIter>
295 inline doublereal absmax(InputIter begin, InputIter end)
296 {
297  doublereal amax = 0.0;
298  for (; begin != end; ++begin)
299  if (fabs(*begin) > amax) {
300  amax = fabs(*begin);
301  }
302  return amax;
303 }
304 
305 //! Normalize the values in a sequence, such that they sum to 1.0 (templated version)
306 /*!
307  * The template arguments are: template<class InputIter, class OutputIter>
308  *
309  * Simple Equivalent:
310  * \code
311  * double x[10], y[10], sum = 0.0;
312  * for (int n = 0; n < 10; n++) {
313  * sum += x[10];
314  * }
315  * for (int n = 0; n < 10; n++) {
316  * y[n] = x[n]/sum;
317  * }
318  * \endcode
319  * Example of function call usage:
320  * \code
321  * double x[10], y[10];
322  * normalize(x, x+10, y);
323  * \endcode
324  *
325  * @param begin Iterator pointing to the beginning of the x vector, belonging to the
326  * iterator class InputIter.
327  * @param end Iterator pointing to the end of the x vector, belonging to the
328  * iterator class InputIter. The difference between end and begin
329  * determines the loop length
330  * @param out Iterator pointing to the beginning of the output vector, belonging to the
331  * iterator class OutputIter.
332  */
333 template<class InputIter, class OutputIter>
334 inline void normalize(InputIter begin, InputIter end,
335  OutputIter out)
336 {
337  doublereal sum = accumulate(begin, end, 0.0);
338  for (; begin != end; ++begin, ++out) {
339  *out = *begin/sum;
340  }
341 }
342 
343 //! Templated divide of each element of \a x by the corresponding element of \a y.
344 /*!
345  * The template arguments are: template<class InputIter, class OutputIter>
346  *
347  * Simple Equivalent:
348  * \code
349  * double x[10], y[10];
350  * for (n = 0; n < 10; n++) {
351  * x[n] /= y[n];
352  * }
353  * \endcode
354  * Example of code usage:
355  * \code
356  * double x[10], y[10];
357  * divide_each(x, x+10, y);
358  * \endcode
359  *
360  * @param x_begin Iterator pointing to the beginning of the x vector, belonging to the
361  * iterator class OutputIter.
362  * @param x_end Iterator pointing to the end of the x vector, belonging to the
363  * iterator class OutputIter. The difference between end and begin
364  * determines the number of inner iterations.
365  * @param y_begin Iterator pointing to the beginning of the yvector, belonging to the
366  * iterator class InputIter.
367  */
368 template<class InputIter, class OutputIter>
369 inline void divide_each(OutputIter x_begin, OutputIter x_end,
370  InputIter y_begin)
371 {
372  for (; x_begin != x_end; ++x_begin, ++y_begin) {
373  *x_begin /= *y_begin;
374  }
375 }
376 
377 //! Increment each entry in \a x by the corresponding entry in \a y.
378 /*!
379  * The template arguments are: template<class InputIter, class OutputIter>
380  *
381  * @param x_begin Iterator pointing to the beginning of the x vector, belonging to the
382  * iterator class OutputIter.
383  * @param x_end Iterator pointing to the end of the x vector, belonging to the
384  * iterator class OutputIter. The difference between end and begin
385  * determines the number of inner iterations.
386  * @param y_begin Iterator pointing to the beginning of the yvector, belonging to the
387  * iterator class InputIter.
388  */
389 template<class InputIter, class OutputIter>
390 inline void sum_each(OutputIter x_begin, OutputIter x_end,
391  InputIter y_begin)
392 {
393  for (; x_begin != x_end; ++x_begin, ++y_begin) {
394  *x_begin += *y_begin;
395  }
396 }
397 
398 //! Copies a contiguous range in a sequence to indexed
399 //! positions in another sequence.
400 /*!
401  * The template arguments are: template<class InputIter, class OutputIter, class IndexIter>
402  *
403  * Example:
404  *
405  * \code
406  * vector<double> x(3), y(20), ;
407  * vector<int> index(3);
408  * index[0] = 9;
409  * index[1] = 2;
410  * index[3] = 16;
411  * scatter_copy(x.begin(), x.end(), y.begin(), index.begin());
412  * \endcode
413  *
414  * This routine is templated 3 times.
415  * InputIter is an iterator for the source vector
416  * OutputIter is an iterator for the destination vector
417  * IndexIter is an iterator for the index into the destination vector.
418  *
419  * @param begin Iterator pointing to the beginning of the source vector, belonging to the
420  * iterator class InputIter.
421  * @param end Iterator pointing to the end of the source vector, belonging to the
422  * iterator class InputIter. The difference between end and begin
423  * determines the number of inner iterations.
424  * @param result Iterator pointing to the beginning of the output vector, belonging to the
425  * iterator class outputIter.
426  * @param index Iterator pointing to the beginning of the index vector, belonging to the
427  * iterator class IndexIter.
428  */
429 template<class InputIter, class OutputIter, class IndexIter>
430 inline void scatter_copy(InputIter begin, InputIter end,
431  OutputIter result, IndexIter index)
432 {
433  for (; begin != end; ++begin, ++index) {
434  *(result + *index) = *begin;
435  }
436 }
437 
438 
439 //! Multiply selected elements in an array by a contiguous
440 //! sequence of multipliers.
441 /*!
442  * The template arguments are: template<class InputIter, class RandAccessIter, class IndexIter>
443  *
444  * Example:
445  * \code
446  * double multipliers[] = {8.9, -2.0, 5.6};
447  * int index[] = {7, 4, 13};
448  * vector_fp data(20);
449  * ...
450  * // Multiply elements 7, 4, and 13 in data by multipliers[0], multipliers[1],and multipliers[2],
451  * // respectively
452  * scatter_mult(multipliers, multipliers + 3, data.begin(), index);
453  * \endcode
454  *
455  * @param mult_begin Iterator pointing to the beginning of the multiplier vector, belonging to the
456  * iterator class InputIter.
457  * @param mult_end Iterator pointing to the end of the multiplier vector, belonging to the
458  * iterator class InputIter. The difference between end and begin
459  * determines the number of inner iterations.
460  * @param data Iterator pointing to the beginning of the output vector, belonging to the
461  * iterator class RandAccessIter, that will be selectively multiplied.
462  * @param index Iterator pointing to the beginning of the index vector, belonging to the
463  * iterator class IndexIter.
464  */
465 template<class InputIter, class RandAccessIter, class IndexIter>
466 inline void scatter_mult(InputIter mult_begin, InputIter mult_end,
467  RandAccessIter data, IndexIter index)
468 {
469  for (; mult_begin != mult_end; ++mult_begin, ++index) {
470  *(data + *index) *= *mult_begin;
471  }
472 }
473 
474 
475 //! Divide selected elements in an array by a contiguous sequence of divisors.
476 /*!
477  * The template arguments are: template<class InputIter, class OutputIter, class IndexIter>
478  *
479  * Example:
480  * \code
481  * double divisors[] = {8.9, -2.0, 5.6};
482  * int index[] = {7, 4, 13};
483  * vector_fp data(20);
484  * ...
485  * // divide elements 7, 4, and 13 in data by divisors[7] divisors[4], and divisors[13]
486  * // respectively
487  * scatter_divide(divisors, divisors + 3, data.begin(), index);
488  * \endcode
489  *
490  * @param begin Iterator pointing to the beginning of the source vector, belonging to the
491  * iterator class InputIter.
492  * @param end Iterator pointing to the end of the source vector, belonging to the
493  * iterator class InputIter. The difference between end and begin
494  * determines the number of inner iterations.
495  * @param result Iterator pointing to the beginning of the output vector, belonging to the
496  * iterator class outputIter.
497  * @param index Iterator pointing to the beginning of the index vector, belonging to the
498  * iterator class IndexIter.
499  */
500 template<class InputIter, class OutputIter, class IndexIter>
501 inline void scatter_divide(InputIter begin, InputIter end,
502  OutputIter result, IndexIter index)
503 {
504  for (; begin != end; ++begin, ++index) {
505  *(result + *index) /= *begin;
506  }
507 }
508 
509 //! Compute \f[ \sum_k x_k \log x_k. \f].
510 /*!
511  * The template arguments are: template<class InputIter>
512  *
513  * A small number (1.0E-20) is added before taking the log. This templated
514  * class does the indicated sun. The template must be an iterator.
515  *
516  * @param begin Iterator pointing to the beginning, belonging to the
517  * iterator class InputIter.
518  * @param end Iterator pointing to the end, belonging to the
519  * iterator class InputIter.
520  * @return
521  * The return from this class is a double.
522  */
523 template<class InputIter>
524 inline doublereal sum_xlogx(InputIter begin, InputIter end)
525 {
526  doublereal sum = 0.0;
527  for (; begin != end; ++begin) {
528  sum += (*begin) * std::log(*begin + Tiny);
529  }
530  return sum;
531 }
532 
533 //! Compute \f[ \sum_k x_k \log Q_k. \f].
534 /*!
535  * The template arguments are: template<class InputIter1, class InputIter2>
536  *
537  * This class is templated twice. The first template, InputIter1
538  * is the iterator that points to $x_k$. The second iterator
539  * InputIter2, point to $Q_k$.
540  * A small number (1.0E-20) is added before taking the log.
541  *
542  * @param begin Iterator pointing to the beginning, belonging to the
543  * iterator class InputIter1.
544  * @param end Iterator pointing to the end, belonging to the
545  * iterator class InputIter1.
546  * @param Q_begin Iterator pointing to the beginning of Q_k, belonging to the
547  * iterator class InputIter2.
548  * @return
549  * The return from this class is hard coded to a doublereal.
550  */
551 template<class InputIter1, class InputIter2>
552 inline doublereal sum_xlogQ(InputIter1 begin, InputIter1 end,
553  InputIter2 Q_begin)
554 {
555  doublereal sum = 0.0;
556  for (; begin != end; ++begin, ++Q_begin) {
557  sum += (*begin) * std::log(*Q_begin + Tiny);
558  }
559  return sum;
560 }
561 
562 //! Scale a templated vector by a constant factor.
563 /*!
564  * The template arguments are: template<class OutputIter>
565  *
566  * This function is essentially a wrapper around the stl
567  * function %scale(). The function is has one template
568  * parameter, OutputIter. OutputIter is a templated iterator
569  * that points to the vector to be scaled.
570  *
571  * @param N Length of the vector
572  * @param alpha scale factor - double
573  * @param x Templated Iterator to the start of the vector
574  * to be scaled.
575  */
576 template<class OutputIter>
577 inline void scale(int N, double alpha, OutputIter x)
578 {
579  scale(x, x+N, x, alpha);
580 }
581 
582 
583 //! Templated evaluation of a polynomial of order 6
584 /*!
585  * @param x Value of the independent variable - First template parameter
586  * @param c Pointer to the polynomial - Second template parameter
587  */
588 template<class D, class R>
589 R poly6(D x, R* c)
590 {
591  return ((((((c[6]*x + c[5])*x + c[4])*x + c[3])*x +
592  c[2])*x + c[1])*x + c[0]);
593 }
594 
595 //! Templated evaluation of a polynomial of order 8
596 /*!
597  * @param x Value of the independent variable - First template parameter
598  * @param c Pointer to the polynomial - Second template parameter
599  */
600 template<class D, class R>
601 R poly8(D x, R* c)
602 {
603  return ((((((((c[8]*x + c[7])*x + c[6])*x + c[5])*x + c[4])*x + c[3])*x +
604  c[2])*x + c[1])*x + c[0]);
605 }
606 
607 //! Templated evaluation of a polynomial of order 10
608 /*!
609  * @param x Value of the independent variable - First template parameter
610  * @param c Pointer to the polynomial - Second template parameter
611  */
612 template<class D, class R>
613 R poly10(D x, R* c)
614 {
615  return ((((((((((c[10]*x + c[9])*x + c[8])*x + c[7])*x
616  + c[6])*x + c[5])*x + c[4])*x + c[3])*x
617  + c[2])*x + c[1])*x + c[0]);
618 }
619 
620 //! Templated evaluation of a polynomial of order 5
621 /*!
622  * @param x Value of the independent variable - First template parameter
623  * @param c Pointer to the polynomial - Second template parameter
624  */
625 template<class D, class R>
626 R poly5(D x, R* c)
627 {
628  return (((((c[5]*x + c[4])*x + c[3])*x +
629  c[2])*x + c[1])*x + c[0]);
630 }
631 
632 //! Evaluates a polynomial of order 4.
633 /*!
634  * @param x Value of the independent variable.
635  * @param c Pointer to the polynomial coefficient array.
636  */
637 template<class D, class R>
638 R poly4(D x, R* c)
639 {
640  return ((((c[4]*x + c[3])*x +
641  c[2])*x + c[1])*x + c[0]);
642 }
643 
644 //! Templated evaluation of a polynomial of order 3
645 /*!
646  * @param x Value of the independent variable - First template parameter
647  * @param c Pointer to the polynomial - Second template parameter
648  */
649 template<class D, class R>
650 R poly3(D x, R* c)
651 {
652  return (((c[3]*x + c[2])*x + c[1])*x + c[0]);
653 }
654 
655 //! Templated deep copy of a std vector of pointers
656 /*!
657  * Performs a deep copy of a std vectors of pointers to an object. This template assumes that
658  * that the templated object has a functioning copy constructor.
659  * It also assumes that pointers are zero when they are not malloced.
660  *
661  * @param fromVec Vector of pointers to a templated class. This will be
662  * deep-copied to the other vector
663  * @param toVec Vector of pointers to a templated class. This will be
664  * overwritten and on return will be a copy of the fromVec
665  */
666 template<class D>
667 void deepStdVectorPointerCopy(const std::vector<D*> &fromVec, std::vector<D*> &toVec)
668 {
669  size_t is = toVec.size();
670  for (size_t i = 0; i < is; i++) {
671  delete toVec[i];
672  }
673  is = fromVec.size();
674  toVec.resize(is);
675  for (size_t i = 0; i < is; i++) {
676  if (fromVec[i]) {
677  toVec[i] = new D(*(fromVec[i]));
678  } else {
679  toVec[i] = 0;
680  }
681  }
682 }
683 
684 //@}
685 
686 //! Check to see that a number is finite (not NaN, +Inf or -Inf)
687 void checkFinite(const double tmp);
688 }
689 
690 #endif
doublereal dot6(const V &x, const V &y)
Templated Inner product of two vectors of length 6.
Definition: utilities.h:103
R poly3(D x, R *c)
Templated evaluation of a polynomial of order 3.
Definition: utilities.h:650
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.
Definition: utilities.h:369
timesConstant(T c)
Constructor.
Definition: utilities.h:37
void checkFinite(const double tmp)
Check to see that a number is finite (not NaN, +Inf or -Inf)
Definition: checkFinite.cpp:33
doublereal dot4(const V &x, const V &y)
Templated Inner product of two vectors of length 4.
Definition: utilities.h:67
R poly5(D x, R *c)
Templated evaluation of a polynomial of order 5.
Definition: utilities.h:626
R poly10(D x, R *c)
Templated evaluation of a polynomial of order 10.
Definition: utilities.h:613
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
Unary operator to multiply the argument by a constant.
Definition: utilities.h:30
double operator()(T x)
Parenthesis operator returning a double.
Definition: utilities.h:47
void multiply_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Multiply each entry in x by the corresponding entry in y.
Definition: utilities.h:227
void resize_each(int m, InputIter begin, InputIter end)
Invoke method 'resize' with argument m for a sequence of objects (templated version) ...
Definition: utilities.h:263
R poly4(D x, R *c)
Evaluates a polynomial of order 4.
Definition: utilities.h:638
void increment_scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Definition: utilities.h:192
R poly8(D x, R *c)
Templated evaluation of a polynomial of order 8.
Definition: utilities.h:601
void normalize(InputIter begin, InputIter end, OutputIter out)
Normalize the values in a sequence, such that they sum to 1.0 (templated version) ...
Definition: utilities.h:334
R poly6(D x, R *c)
Templated evaluation of a polynomial of order 6.
Definition: utilities.h:589
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.
Definition: utilities.h:466
doublereal absmax(InputIter begin, InputIter end)
The maximum absolute value (templated version)
Definition: utilities.h:295
doublereal sum_xlogQ(InputIter1 begin, InputIter1 end, InputIter2 Q_begin)
Compute .
Definition: utilities.h:552
doublereal sum_xlogx(InputIter begin, InputIter end)
Compute .
Definition: utilities.h:524
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
Definition: utilities.h:131
static size_t amax(double *x, size_t j, size_t n)
Finds the location of the maximum component in a vector x
void sum_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Increment each entry in x by the corresponding entry in y.
Definition: utilities.h:390
doublereal dot5(const V &x, const V &y)
Templated Inner product of two vectors of length 5.
Definition: utilities.h:85
void deepStdVectorPointerCopy(const std::vector< D * > &fromVec, std::vector< D * > &toVec)
Templated deep copy of a std vector of pointers.
Definition: utilities.h:667
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:154
const doublereal Tiny
Small number to compare differences of mole fractions against.
Definition: ct_defs.h:155
void scatter_copy(InputIter begin, InputIter end, OutputIter result, IndexIter index)
Copies a contiguous range in a sequence to indexed positions in another sequence. ...
Definition: utilities.h:430
T m_c
Stored constant value of time T.
Definition: utilities.h:52
void scatter_divide(InputIter begin, InputIter end, OutputIter result, IndexIter index)
Divide selected elements in an array by a contiguous sequence of divisors.
Definition: utilities.h:501