Manipulating functions and function spaces

We start with setting the Feel++ environment and loading the Feel++ library. We download a 2D and 3D geometry from the Feel++ github repository.

import feelpp.core as fppc
import sys

app=fppc.Environment(["myapp"],config=fppc.localRepository(""))

geo={
    '2':fppc.download( "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}", worldComm=app.worldCommPtr() )[0],
    '3':fppc.download( "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp3d/feelpp3d.geo}", worldComm=app.worldCommPtr() )[0]
}
print(" . 2D geometry file: {}".format(geo['2']))
print(" . 3D geometry file: {}".format(geo['3']))
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
      4 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. Notations

The domain \(\Omega\) is discretized using a mesh of triangles or tetrahedra. Scalar functions \(f \Omega \rightarrow \mathbb{R}\) are defined on the mesh and are represented by a finite element space.

2. Scalar function spaces

2D mesh and function space example
def run( m, geo ):
    m2d = fppc.load(m,geo,0.1)
    Xh=fppc.functionSpace(mesh=m2d)

    if app.isMasterRank():
        print("Xh basisname: ", Xh.basisName())
        print("Xh nDof: ", Xh.nDof())
        print("Xh nLocalDof: ", Xh.nLocalDof())
        print("Xh nLocalDofWithGhost: ", Xh.nLocalDofWithGhost())
        print("Xh nLocalDofWithoutGhost: ", Xh.nLocalDofWithoutGhost())

    m3=Xh.mesh()

    assert m3==m2d

    u=Xh.element()
    u.on(range=fppc.elements(m2d),expr=fppc.expr("x:x"))

    assert u.functionSpace() == Xh
    assert u.size() == Xh.nDof()

run( fppc.mesh(dim=2), geo['2'] )
Results
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
File :22
     19     assert u.functionSpace() == Xh
     20     assert u.size() == Xh.nDof()
---> 22 run( fppc.mesh(dim=2), geo['2'] )

NameError: name 'fppc' is not defined

Finally, we can do the same in 3D

3D mesh and function space example
run( fppc.mesh(dim=3,realdim=3), geo['3'] )
Results
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
File :1
----> 1 run( fppc.mesh(dim=3,realdim=3), geo['3'] )

NameError: name 'fppc' is not defined