Feel++  0.91.4
Manipulating Function Spaces

Defining function spaces and functions

typedef

P0 FunctionSpace typedef

Now we turn to the instantiation of the function space $ X_h $ of type functionspace_type. We have already instantiated a mesh (see this Section) of type mesh_ptrtype. The code looks like this

Then we instantiate $ X_h$ using space_type::New() static member function and obtain a functionspace_ptrtype.

We are now able to instantiate elements of the FunctionSpace $ X_h$. Two ways are presented, one with the auto keyword allowing to infer automatically the type of $ X_h$ elements

and one knowing the actual type of the element

Note:
The strings "u" and "v" are the name we give to these elements of $ X_h$.

Using functions spaces and functions

Projection

First, we define some mathematical expression/functions

\begin{eqnarray} g(x,y,z) &=& \sin(\pi x/2)\ \cos(\pi y/2)\ \cos(\pi*z/2) \\ f(x,y,z) &=& (1-x^2)\ (1-y^2)\ (1-z^2)\ (x^2+y^2+z^2)^{\alpha/2.0},\quad \alpha=3 \end{eqnarray}

They are implemented using the new auto C++ keyword to infer the type of expression automatically.

Then we build the interpolant (Lagrange interpolant in this case since we chose Lagrange basis function), by calling the vf::project() function which can be applied on all or parts of the mesh thanks to the mesh iterators such as elements(mesh) or markedelements(mesh,marker). The return object is the interpolant of the function in the space $ X_h $ given as an argument to vf::project().

Norm computation

It is easy to compute norms

Interpolation

Exporting to Paraview or Gmsh

projection

Execution

Execution on a Simplex

We execute this example on a simplex domain an export to the Gmsh format:

feel_doc_myfunctionspace --shape="simplex"--nochdir --exporter-format=gmsh

the output log of the execution of this example gives

Here are the graphical outputs on the d-simplex, d=1,2,3:

myfunctionspace-simplex-1-f.png
f on the Line
myfunctionspace-simplex-2-f.png
f on the Triangle
myfunctionspace-simplex-3-f.png
f on the Tetrahedron
myfunctionspace-simplex-1-g.png
g on the Line
myfunctionspace-simplex-2-g.png
g on the Triangle
myfunctionspace-simplex-3-g.png
g on the Tetrahedron

Execution on a Hypercube

We execute this example on a hypercube domain an export to the Gmsh format:

feel_doc_myfunctionspace --shape="hypercube"--nochdir --exporter-format=gmsh

the output log of the execution of this example gives

Here are the graphical outputs on the d-hypercube, d=1,2,3:

myfunctionspace-hypercube-1-f.png
f plot on Line
myfunctionspace-hypercube-2-f.png
f plot on Unit Square
myfunctionspace-hypercube-3-f.png
f plot on Unit Cube
myfunctionspace-hypercube-1-g.png
g plot on Line
myfunctionspace-hypercube-2-g.png
g plot on Unit Square
myfunctionspace-hypercube-3-g.png
g plot on Unit Cube