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 MidPointQuadrature ( double(*)(double)  f,
double  x0,
double  xn,
int  n 
)

Integrates f with composite midpoint 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 + h(i-\frac{1}{2})$, the integral is calculated as:

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

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

Test:
ElmerModuleDriver::TestingObject::Test__MidPointQuadrature tests this function by sending linear and quadratic test functions.

Definition at line 51 of file Third_Party_Modules/ElmerFSI/trunk/src/ExampleSourceFile.C.

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

52  {
53  double h = (xn - x0)/(static_cast<double>(n));
54  if(std::fabs(h) < 1e-12) throw 1;
55  double sum = 0.0;
56  for(int i = 1;i <= n;i++)
57  sum += f(x0+((static_cast<double>(i)-.5)*h));
58  return(h*sum);
59  }

Here is the caller graph for this function: