Cantera  2.5.1
funcs.cpp
Go to the documentation of this file.
1 //! @file funcs.cpp file containing miscellaneous numerical functions.
2 
3 // This file is part of Cantera. See License.txt in the top-level directory or
4 // at https://cantera.org/license.txt for license and copyright information.
5 
7 
8 using namespace std;
9 
10 namespace Cantera
11 {
12 
13 doublereal linearInterp(doublereal x, const vector_fp& xpts,
14  const vector_fp& fpts)
15 {
16  if (x <= xpts[0]) {
17  return fpts[0];
18  }
19  if (x >= xpts.back()) {
20  return fpts.back();
21  }
22  auto loc = lower_bound(xpts.begin(), xpts.end(), x);
23  int iloc = int(loc - xpts.begin()) - 1;
24  doublereal ff = fpts[iloc] +
25  (x - xpts[iloc])*(fpts[iloc + 1]
26  - fpts[iloc])/(xpts[iloc + 1] - xpts[iloc]);
27  return ff;
28 }
29 
30 }
Header for a file containing miscellaneous numerical functions.
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:180
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
doublereal linearInterp(doublereal x, const vector_fp &xpts, const vector_fp &fpts)
Linearly interpolate a function defined on a discrete grid.
Definition: funcs.cpp:13