Compute Integrals
We start with setting the Feel++ environment and loading the Feel++ library.
Set the Feel++ environment with local repository
import feelpp
import sys
app = feelpp.Environment(["myapp"],config=feelpp.localRepository(""))
python
Results
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) File:1 ----> 1 import feelpp 2 import sys 3 app = feelpp.Environment(["myapp"],config=feelpp.localRepository("")) ModuleNotFoundError: No module named 'feelpp'
1. Integral of a function
∫Ωf(x)dx∫Ωf(x)dx is the integral of the function f over the domain Ω. The domain Ω is a subset of Rn and f is a function defined on Ω. The domain Ω is discretized as a mesh T and the function f may be approximated by a finite element function ˆf. The integral is approximated by the sum of the integrals over the elements of the mesh T. The integral over each element is computed using a quadrature formula.
We first load a mesh
Load a mesh T
geo=feelpp.download( "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}", worldComm=app.worldCommPtr() )[0]
print("geo file: {}".format(geo))
mesh = feelpp.load(feelpp.mesh(dim=2,realdim=2), geo, 0.1)
python
Results
--------------------------------------------------------------------------- NameError Traceback (most recent call last) File:1 ----> 1 geo=feelpp.download( "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}", worldComm=app.worldCommPtr() )[0] 2 print("geo file: {}".format(geo)) 3 mesh = feelpp.load(feelpp.mesh(dim=2,realdim=2), geo, 0.1) NameError: name 'feelpp' is not defined
Then we can define functions f and compute the integral of f over the mesh T.
Compute integrals
from feelpp.integrate import integrate
i1 = integrate(range=feelpp.elements(mesh),expr="sin(x+y):x:y")
i2 = integrate(range=feelpp.boundaryfaces(mesh),expr="x*nx+y*ny+z*nz:x:y:z:nx:ny:nz")
i3 = integrate(range=feelpp.markedelements(mesh, "marker"), expr="1")
print(f"i1 = {i1}, i2 = {i2}, i3 = {i3}")
python
Results
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) File:1 ----> 1 from feelpp.integrate import integrate 3 i1 = integrate(range=feelpp.elements(mesh),expr="sin(x+y):x:y") 4 i2 = integrate(range=feelpp.boundaryfaces(mesh),expr="x*nx+y*ny+z*nz:x:y:z:nx:ny:nz") ModuleNotFoundError: No module named 'feelpp'