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(""))
Results
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/PETSc.py:3 2 from petsc4py.lib import ImportPETSc # noqa: E402 ----> 3 PETSc = ImportPETSc(ARCH) 4 PETSc._initialize() File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/lib/__init__.py:29, in ImportPETSc(arch) 28 path, arch = getPathArchPETSc(arch) ---> 29 return Import('petsc4py', 'PETSc', path, arch) File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/lib/__init__.py:95, in Import(pkg, name, path, arch) 94 # import extension module from 'path/arch' directory ---> 95 module = import_module(pkg, name, path, arch) 96 module.__arch__ = arch # save arch value File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/lib/__init__.py:73, in Import..import_module(pkg, name, path, arch) 72 sys.modules[fullname] = module ---> 73 spec.loader.exec_module(module) 74 return module File petsc4py/PETSc.pyx:1, in init petsc4py.PETSc() ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject The above exception was the direct cause of the following exception: SystemError Traceback (most recent call last) File :1 ----> 1 import feelpp.core as fppc 2 import sys 3 app = fppc.Environment(["myapp"],config=fppc.localRepository("")) File /usr/lib/python3/dist-packages/feelpp/core/__init__.py:12 10 from ._feelpp import * 11 from ._core import * ---> 12 from ._alg import * 13 from ._mesh import * 14 from ._plot import * SystemError: initialization of _alg raised unreported exception
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}\)
geo=fppc.download( "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)
Results
--------------------------------------------------------------------------- NameError Traceback (most recent call last) File:1 ----> 1 geo=fppc.download( "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}", worldComm=app.worldCommPtr() )[0] 2 print("geo file: {}".format(geo)) 3 mesh = fppc.load(fppc.mesh(dim=2,realdim=2), geo, 0.1) NameError: name 'fppc' is not defined
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}")
Results
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/PETSc.py:3 2 from petsc4py.lib import ImportPETSc # noqa: E402 ----> 3 PETSc = ImportPETSc(ARCH) 4 PETSc._initialize() File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/lib/__init__.py:29, in ImportPETSc(arch) 28 path, arch = getPathArchPETSc(arch) ---> 29 return Import('petsc4py', 'PETSc', path, arch) File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/lib/__init__.py:95, in Import(pkg, name, path, arch) 94 # import extension module from 'path/arch' directory ---> 95 module = import_module(pkg, name, path, arch) 96 module.__arch__ = arch # save arch value File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/lib/__init__.py:73, in Import..import_module(pkg, name, path, arch) 72 sys.modules[fullname] = module ---> 73 spec.loader.exec_module(module) 74 return module File petsc4py/PETSc.pyx:1, in init petsc4py.PETSc() ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject The above exception was the direct cause of the following exception: SystemError Traceback (most recent call last) File :1 ----> 1 from feelpp.core.integrate import integrate 3 i1 = integrate(range=fppc.elements(mesh),expr="sin(x+y):x:y") 4 i2 = integrate(range=fppc.boundaryfaces(mesh),expr="x*nx+y*ny+z*nz:x:y:z:nx:ny:nz") File /usr/lib/python3/dist-packages/feelpp/core/__init__.py:12 10 from ._feelpp import * 11 from ._core import * ---> 12 from ._alg import * 13 from ._mesh import * 14 from ._plot import * SystemError: initialization of _alg raised unreported exception