Compute Integrals

We start with setting the Feel++ environment and loading the Feel++ library.

Set the Feel++ environment with local repository
import feelpp.core as fppc
import sys
app = fppc.Environment(["myapp"],config=fppc.localRepository(""))

1. Integral of a function

\(\int_{\Omega} f(x) dx\) is the integral of the function \(f\) over the domain \(\Omega\). The domain \(\Omega\) is a subset of \(\mathbb{R}^n\) and \(f\) is a function defined on \(\Omega\). The domain \(\Omega\) is discretized as a mesh \(\mathcal{T}\) and the function \(f\) may be approximated by a finite element function \(\hat{f}\). The integral is approximated by the sum of the integrals over the elements of the mesh \(\mathcal{T}\). The integral over each element is computed using a quadrature formula.

We first load a mesh

Load a mesh \(\mathcal{T}\) "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}", worldComm=app.worldCommPtr() )[0]
print("geo file: {}".format(geo))
mesh = fppc.load(fppc.mesh(dim=2,realdim=2), geo, 0.1)
geo file: /nvme0/prudhomm/github-actions/actions-runner-4/_work/

Then we can define functions \(f\) and compute the integral of \(f\) over the mesh \(\mathcal{T}\).

Compute integrals
from feelpp.core.integrate  import integrate

i1 = integrate(range=fppc.elements(mesh),expr="sin(x+y):x:y")
i2 = integrate(range=fppc.boundaryfaces(mesh),expr="x*nx+y*ny+z*nz:x:y:z:nx:ny:nz")
i3 = integrate(range=fppc.markedelements(mesh, "marker"), expr="1")

print(f"i1 = {i1}, i2 = {i2}, i3 = {i3}")
i1 = [3.24282386], i2 = [41.6], i3 = [0.]