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
 . 2D geometry file: /scratch/prudhomm/actions-runner/_work/book.feelpp.org/book.feelpp.org/feelppdb/downloads/feelpp2d.geo
 . 3D geometry file: /scratch/prudhomm/actions-runner/_work/book.feelpp.org/book.feelpp.org/feelppdb/downloads/feelpp3d.geo

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
Xh basisname:  lagrange
Xh nDof:  2865
Xh nLocalDof:  2865
Xh nLocalDofWithGhost:  2865
Xh nLocalDofWithoutGhost:  2865

Finally, we can do the same in 3D

3D mesh and function space example
run( fppc.mesh(dim=3,realdim=3), geo['3'] )
Results
Xh basisname:  lagrange
Xh nDof:  21740
Xh nLocalDof:  21740
Xh nLocalDofWithGhost:  21740
Xh nLocalDofWithoutGhost:  21740