Cantera 2.6.0
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
13#include "cantera/numerics/eigen_sparse.h"
14
15namespace Cantera
16{
17
18//! Linearly interpolate a function defined on a discrete grid.
19/*!
20 * Vector xpts contains a monotonic sequence of grid points, and vector fpts
21 * contains function values defined at these points. The value returned is the
22 * linear interpolate at point x. If x is outside the range of xpts, the value
23 * of fpts at the nearest end is returned.
24 *
25 * @param x value of the x coordinate
26 * @param xpts value of the grid points
27 * @param fpts value of the interpolant at the grid points
28 * @returns the value of of the interpolated function at x.
29 */
30doublereal linearInterp(doublereal x, const vector_fp& xpts,
31 const vector_fp& fpts);
32
33//! Numerical integration of a function using the trapezoidal rule.
34/*!
35 * Vector x contanins a monotonic sequence of grid points, and
36 * Vector f contains function values defined at these points.
37 * The size of x and f must be the same.
38 *
39 * @param f vector of function value
40 * @param x vector of function coordinate
41 */
42double trapezoidal(const Eigen::ArrayXd& f, const Eigen::ArrayXd& x);
43
44//! Numerical integration of a function using Simpson's rule
45//! with flexibility of taking odd and even number of points.
46//! For even number, Simpson's rule is used for the first
47//! N-2 intervals with a trapezoidal rule on the last interval.
48/*!
49 * Vector x contanins a monotonic sequence of grid points, and
50 * Vector f contains function values defined at these points.
51 * The size of x and f must be the same.
52 *
53 * @param f vector of function value
54 * @param x vector of function coordinate
55 */
56double simpson(const Eigen::ArrayXd& f, const Eigen::ArrayXd& x);
57
58//! Numerical integration of a function.
59/*!
60 * Vector x contanins a monotonic sequence of grid points, and
61 * Vector f contains function values defined at these points.
62 * The size of x and f must be the same.
63 *
64 * @param method method name
65 * @param f vector of function value
66 * @param x vector of function coordinate
67 */
68double numericalQuadrature(const std::string& method,
69 const Eigen::ArrayXd& f,
70 const Eigen::ArrayXd& x);
71}
72#endif
This file contains definitions of constants, types and terms that are used in internal routines and a...
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
doublereal linearInterp(doublereal x, const vector_fp &xpts, const vector_fp &fpts)
Linearly interpolate a function defined on a discrete grid.
Definition: funcs.cpp:15
double trapezoidal(const Eigen::ArrayXd &f, const Eigen::ArrayXd &x)
Numerical integration of a function using the trapezoidal rule.
Definition: funcs.cpp:32
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:184
double numericalQuadrature(const std::string &method, const Eigen::ArrayXd &f, const Eigen::ArrayXd &x)
Numerical integration of a function.
Definition: funcs.cpp:115
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:90