Integral of a function on the reference FEM element

338 Views Asked by At

Suppose I have a triangulation in 1D with $X_h^1$ being the linear finite element space. The affine map I am using is the following

$$r = x_i + \gamma (x_{i+1} - x_i).$$

Suppose I want to compute the following integral

$$\int_{0}^1 f dx$$

on the reference element, where $f$ is a trigonometric function. To do this I have to map the quadrature point to the reference element, right?

But how can I do this in practice? Do I have to compute the value of the function at $r$ with $\gamma$ being $0$ at $x_i$ and $1$ at $x_{i+1}$?

Here some code I have written to do this:

def func_ref(z, x, a, b):
    return np.power((np.cos(x[a]) - np.cos(x[a]) * (1 - z)+
    np.cos(x[b]) * z) * (x[b] - x[a]), 2)

which is the integrand $\left (f - \Pi_h^1 (f) \right )^2x$ with $f$ being just the cosine function and the interpolant being represented by the linear combination of the function $f$ and the two basis function. Then I simply call the integration function on the interval $[0,1]$.

Thank you.