Cantera  3.1.0a1
funcs.h
Go to the documentation of this file.
1 /**
2  * @file funcs.h Header for a file containing miscellaneous
3  * numerical functions.
4  */
5 
6 // This file is part of Cantera. See License.txt in the top-level directory or
7 // at https://cantera.org/license.txt for license and copyright information.
8 
9 #ifndef CT_FUNCS_H
10 #define CT_FUNCS_H
11 
12 #include "cantera/base/ct_defs.h"
13 #include "cantera/numerics/eigen_sparse.h"
14 
15 namespace Cantera
16 {
17 
18 /**
19  * @defgroup mathUtils Numerical Integration and Interpolation
20  * Collection of numerical utility functions for integration, interpolation and data
21  * fitting.
22  * @ingroup numerics
23 */
24 
25 //! Linearly interpolate a function defined on a discrete grid.
26 /*!
27  * Vector xpts contains a monotonic sequence of grid points, and vector fpts
28  * contains function values defined at these points. The value returned is the
29  * linear interpolate at point x. If x is outside the range of xpts, the value
30  * of fpts at the nearest end is returned.
31  *
32  * @param x value of the x coordinate
33  * @param xpts value of the grid points
34  * @param fpts value of the interpolant at the grid points
35  * @returns the value of of the interpolated function at x.
36  * @ingroup mathUtils
37  */
38 double linearInterp(double x, const vector<double>& xpts, const vector<double>& fpts);
39 
40 //! Numerical integration of a function using the trapezoidal rule.
41 /*!
42  * Vector x contains a monotonic sequence of grid points, and
43  * Vector f contains function values defined at these points.
44  * The size of x and f must be the same.
45  *
46  * @param f vector of function value
47  * @param x vector of function coordinate
48  * @ingroup mathUtils
49  */
50 double trapezoidal(const Eigen::ArrayXd& f, const Eigen::ArrayXd& x);
51 
52 //! Numerical integration of a function using Simpson's rule
53 //! with flexibility of taking odd and even number of points.
54 //! For even number, Simpson's rule is used for the first
55 //! N-2 intervals with a trapezoidal rule on the last interval.
56 /*!
57  * Vector x contains a monotonic sequence of grid points, and
58  * Vector f contains function values defined at these points.
59  * The size of x and f must be the same.
60  *
61  * @param f vector of function value
62  * @param x vector of function coordinate
63  * @ingroup mathUtils
64  */
65 double simpson(const Eigen::ArrayXd& f, const Eigen::ArrayXd& x);
66 
67 //! Numerical integration of a function.
68 /*!
69  * Vector x contains a monotonic sequence of grid points, and
70  * Vector f contains function values defined at these points.
71  * The size of x and f must be the same.
72  *
73  * @param method method name
74  * @param f vector of function value
75  * @param x vector of function coordinate
76  * @ingroup mathUtils
77  */
78 double numericalQuadrature(const string& method,
79  const Eigen::ArrayXd& f,
80  const Eigen::ArrayXd& x);
81 }
82 #endif
This file contains definitions of constants, types and terms that are used in internal routines and a...
double linearInterp(double x, const vector< double > &xpts, const vector< double > &fpts)
Linearly interpolate a function defined on a discrete grid.
Definition: funcs.cpp:13
double numericalQuadrature(const string &method, const Eigen::ArrayXd &f, const Eigen::ArrayXd &x)
Numerical integration of a function.
Definition: funcs.cpp:112
double trapezoidal(const Eigen::ArrayXd &f, const Eigen::ArrayXd &x)
Numerical integration of a function using the trapezoidal rule.
Definition: funcs.cpp:29
double simpson(const Eigen::ArrayXd &f, const Eigen::ArrayXd &x)
Numerical integration of a function using Simpson's rule with flexibility of taking odd and even numb...
Definition: funcs.cpp:87
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564