ElmerFoamFSI  2.0
ElmerFoamFSI is fluid-solid interaction simulation application built up from OpenFOAM CFD and Elmer CSM coupled through the IMPACT multiphysics software integration infrastructure.
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Groups Pages
double TrapezoidQuadrature ( double(*)(double)  f,
double  x0,
double  xn,
int  n 
)

Integrates f with composite trapezoid rule.

Parameters
fFunction to integrate takes a double argument, x, and returns a double value
x0The lower integration domain limit.
xnThe upper integration domain limit.
nThe number of intervals into which to break the domain.
Returns
The numerical approximation for $\int_{x_0}^{x_n}{f(x)}{dx}$.

With $h = \frac{(x_n - x_0)}{n}$, and $x_i = x_0 + {i}{h}$, the integral is calculated as:

$\int_{x_0}^{x_n}{f(x)}{dx} \approx \frac{h}{2}\sum_{i=1}^{n}(f(x_{i-1}) + f(x_i))$

The error of this method is $O(h^2)$.

Test:
ElmerFoamFSI::TestingObject::Test__TrapezoidQuadrature tests this function by sending linear and quadratic test functions.

Definition at line 39 of file src/ExampleSourceFile.C.

Referenced by TestingObject< ResultsType >::Test__TrapezoidQuadrature().

40  {
41  double h = (xn - x0)/(static_cast<double>(n));
42  if(std::fabs(h) < 1e-12) throw 1;
43  double sum = .5*(f(x0)+f(xn));
44  for(int i = 1; i < n;i++)
45  sum += f(x0 + i*h);
46  return(h*sum);
47  };

Here is the caller graph for this function: