Discuss and Contribute
Use Issue 858 to drive development of this
section. Your contributions make a difference. No contribution is too small.

This document is under active development and discussion!
If you find errors or omissions in this document, please don’t hesitate to submit an issue or open a pull request with a fix. We also encourage you to ask questions and discuss any aspects of the project on the Feel++ Gitter forum. New contributors are always welcome! 
The following typographical conventions are used in the book
Italic indicates new terms
typewriter
is used on program listings as well as when referring to
programming elements, e.g. functions, variables, statements, data types,
environment variables or keywords.
$ typewriter
or > typewriter
displays commands that the user types literally without the $
or >
.
this is a general note. 
this is a general warning. 
be cautious 
\(d=1,2,3\) geometrical dimension
\(\Omega \subset \mathbb{R}^d\)
\(K\) a cell or element of a mesh
\(h\) characteristic mesh size
\(k_{\mathrm{geo}}\) polynomial order of the geometrical transformation
\(\delta=(h,k_{\mathrm{geo}})\) discretization parameter pair for the geometrical transformation, default value \(k_{\mathrm{geo}}=1\) (straight cells or elements)
\(\varphi^K_\delta: \hat{K} \rightarrow K\), geometrical transformation
\(\mathcal{T}_{\delta}\) a triangulation, \(\mathcal{T}_\delta = \{ K\;  \; K=\varphi^K_\delta (\hat{K}) \} \)
\(\Omega_h \equiv \cup_K {K}\)
\(P^k_{c,h} = \{ v_h \in C^0(\bar{\Omega}); \forall K \in \mathcal{T}_h,\ v_h \circ T_K \in \mathbb{P}^k\}\) Space of continuous piecewise polynomial of total degree \(\leq k\).
Discuss and Contribute
Use Issue 858 to drive development of this
section. Your contributions make a difference. No contribution is too small.

Feel++ is a unified C++ implementation of Galerkin methods (finite and spectral element methods) in 1D, 2D and 3D to solve partial differential equations.
Feel++ is
a versatile mathematical kernel solving easily problems using different techniques thus allowing testing and comparing methods, e.g. cG versus dG.
a small and manageable library which nevertheless encompasses a wide range of numerical methods and techniques and in particular reduced order methods such as the reduced basis method.
a software that follows closely the mathematical abstractions associated with partial differential equations (PDE) and in particular the finite element mathematical framework and variational formulations.
a library that offers solving strategies that scales up to thousands and even tens of thousands of cores.
a library entirely in C++ allowing to create C++ complex and typically nonlinear multiphysics applications currently in industry, physics and healthcare.
Using Feel++ inside Introduction is the recommended and fastest way to use Feel++. The Docker chapter is dedicated to Docker and using Feel++ in Docker.
We strongly encourage you to follow these steps if you begin with Feel++ in particular as an enduser.
People who would like to develop with and in Feel++ should read through the remaining sections of this chapter.
Start the Docker container feelpp/feelppbase
or feelpp/feelpptoolboxes
as follows
> docker run it v $HOME/feel:/feel feelpp/feelpptoolboxes
these steps are explained in the chapter on Feel++ Containers. 
Then run e.g. the Quickstart Laplacian that solves the Laplacian problem in Quickstart Laplacian sequential or in Quickstart Laplacian on 4 cores in parallel.
> feelpp_qs_laplacian_2d configfile Testcases/quickstart/laplacian/feelpp2d/feelpp2d.cfg
The results are stored in Docker in
/feel/qs_laplacian/feelpp2d/np_1/exports/ensightgold/qs_laplacian/
and on your computer
$HOME/feel/qs_laplacian/feelpp2d/np_1/exports/ensightgold/qs_laplacian/
The mesh and solutions can be visualized using e.g. Parariew or Visit.

> mpirun np 4 feelpp_qs_laplacian_2d configfile Testcases/quickstart/laplacian/feelpp2d/feelpp2d.cfg
The results are stored in a simular place as above: just replace np_1
by np_4
in the paths above. The results should look like
Solution 
Mesh 
Here are some excerpts from Quickstart Laplacian that solves the Laplacian problem. It shows some of the features of Feel++ and in particular the domain specific language for Galerkin methods.
First we load the mesh, define the function space define some expressions
tic();
auto mesh = loadMesh(_mesh=new Mesh<Simplex<FEELPP_DIM,1>>);
toc("loadMesh");
tic();
auto Vh = Pch<2>( mesh );
auto u = Vh>element("u");
auto mu = expr(soption(_name="functions.mu")); // diffusion term
auto f = expr( soption(_name="functions.f"), "f" );
auto r_1 = expr( soption(_name="functions.a"), "a" ); // Robin left hand side expression
auto r_2 = expr( soption(_name="functions.b"), "b" ); // Robin right hand side expression
auto n = expr( soption(_name="functions.c"), "c" ); // Neumann expression
auto g = expr( soption(_name="functions.g"), "g" );
auto v = Vh>element( g, "g" );
toc("Vh");
Second we define the linear and bilinear forms to solve the problem
tic();
auto l = form1( _test=Vh );
l = integrate(_range=elements(mesh),
_expr=f*id(v));
l+=integrate(_range=markedfaces(mesh,"Robin"), _expr=r_2*id(v));
l+=integrate(_range=markedfaces(mesh,"Neumann"), _expr=n*id(v));
toc("l");
tic();
auto a = form2( _trial=Vh, _test=Vh);
a = integrate(_range=elements(mesh),
_expr=mu*gradt(u)*trans(grad(v)) );
a+=integrate(_range=markedfaces(mesh,"Robin"), _expr=r_1*idt(u)*id(v));
a+=on(_range=markedfaces(mesh,"Dirichlet"), _rhs=l, _element=u, _expr=g );
//! if no markers Robin Neumann or Dirichlet are present in the mesh then
//! impose Dirichlet boundary conditions over the entire boundary
if ( !mesh>hasAnyMarker({"Robin", "Neumann","Dirichlet"}) )
a+=on(_range=boundaryfaces(mesh), _rhs=l, _element=u, _expr=g );
toc("a");
tic();
//! solve the linear system, find u s.t. a(u,v)=l(v) for all v
if ( !boption( "nosolve" ) )
a.solve(_rhs=l,_solution=u);
toc("a.solve");
More explanations are available in Learning by examples.
This section describes the available ways to to download, compile and install Feel++.
Using Feel++ inside Introduction is the recommended and fastest way to use Feel++. The Docker is dedicated to Docker and Feel++ Containers is dedicated to Feel++ in Docker.
We strongly encourage you to follow these steps if you begin with Feel++ in particular as an enduser.
People who would like to develop with and in Feel++ should read through the remaining sections of this chapter.
Feel++ uses C++14 compilers such as GCC6 and Clang. Currently it is not mandatory to have a C++14 stantard library but it will be soon.
There used to be a major compatibility issue between llvm/clang and GCC compilers since GCC5 released the ABI tag which makes it impossible to compile Feel++ using llvm/clang with GCC5 or GCC6 standard libraries for a time. Please see the following table to understand the working C++ compiler / C++ standard library combinations. 
Compiler  Standard Library 

clang (3.6, 3.7, 3.8) 
libstdc++ 4.9 
clang 
libc++ (corresponding clang version) 
clang (3.8(requires patches), 3.9) 
libstdc++ 6 
GCC 6 
libstdc++ 6 
GCC 6.2.1 seems to be problematic on debian/testing — the tests in the testsuite fail. — GCC 6.3.1 or GCC 6.2.0 don’t have any problems. 
Other than C++14 compilers, Feel++ requires only a few tools and libraries, namely CMake, Boost C++ libraries and an MPI implementation such as openmpi or mpich. The table below provides information regarding the minimum and maximum version supported. A — means it has not necessarily been tested with the latest version but we do not expect any issues. Note that for MPI, an implementation with MPIIO support would be best.
Name  Minimum Version  Maximum Version  Notes 

CMake 
3.0 
— 

MPI 
— 
— 
openmpi or mpich 
Boost 
1.55 
1.63 
Here is a list of libraries that we recommend to use jointly with Feel++.
Library  Minimum Version  Maximum Version  Notes 

HDF5 
1.8.6 
1.8.16 
Enables high performance I/O; Enables MED Support; Be careful on Debian/sid a more recent version of HDF5 breaks MED support 
PETSc 
3.2 
3.7 
Last is best; a requirement for parallel and high performance computing 
SLEPc 
3.2 
3.7 
last is best; a requirement for eigenvalue problem; depends on PETSc 
Gmsh 
2.8.7 
2.16 
last is best; a requirement if you want to be able to read many file formats; HDF5 version in Debian/sid currently breaks MED format support. 
Superlu 
superlu and superlu_dist 

Suitesparse 
umfpack (colamd,amd) 

OpenTURNS 
2.0 
Uncertainty quantification 
Here is a list of tools that we recommend to use jointly with Feel++.
Tool  License  Notes 

Computer Aided Design 

Gmsh 
Open Source 

Mesh Generation 

Gmsh 
Open Source 

MeshGems 
Commercial 

PostProcessing 

Paraview 
Open Source 

Ensight 
Commercial 

Octave 
Open Source 

Gmsh 
Open Source 
Note that all these packages are available under Debian GNU/Linux and Ubuntu. Once you have installed those dependencies, you can go to Compiling.
Here is a list of tools that we suggest to use jointly with Feel++.
Tool  License  Notes 

Computer Aided Design (CAD) 

Freecad 
Open Source 

Salome 
Open Source 
HDF5 version in Debian/sid currently breaks MED format support. 
Modeling, Compilation and Simulation Environment 

Open Modelica 
Open Source 

Debugging and Profiling 

Google perftools 
Open Source 

Valgrind 
Open Source 
We now turn to the installation of the Feel++ dependencies on Linux. Feel++ is currently support on Ubuntu (16.04, 16.10) and Debian (Sid, Testing).
Here is the suggested installation of the Feel++ dependencies on Ubuntu 16.10
$ sudo aptget qq update
$ sudo aptget install automake autoconf libtool libboostalldev\
bashcompletion emacs24 gmsh libgmshdev libopenturnsdev \
libbz2dev libhdf5openmpidev libeigen3dev libcgaldev \
libopenblasdev libclndev libcppunitdev libopenmpidev \
libanndev libglpkdev libpetsc3.7dev libslepc3.7dev \
liblapackdev libmpfrdev paraview pythondev libhwlocdev \
libvtk6dev libpcre3dev pythonh5py pythonurllib3 xterm tmux \
screen pythonnumpy pythonvtk6 pythonsix pythonply wget \
bison sudo xauth cmake flex gcc6 g++6 clang3.9 \
clang++3.9 git ipython openmpibin pkgconfig
Here is the suggested installation of the Feel++ dependencies on Ubuntu LTS 16.04
$ sudo aptget install autoconf automake bashcompletion bison\
clang++3.8 clang3.8 cmake emacs24 flex g++6 gcc6 git gmsh\
ipython libanndev libbz2dev libcgaldev libclndev \
libcppunitdev libeigen3dev libglpkdev libgmshdev \
libhdf5openmpidev libhwlocdev liblapackdev libmpfrdev\
libopenblasdev libopenmpidev libopenturnsdev libpcre3dev \
libpetsc3.6.2dev libprojdev libslepc3.6.1dev libtool \
libvtk6dev openmpibin paraview pkgconfig pythondev \
pythonh5py pythonnumpy pythonply pythonsix \
pythonurllib3 pythonvtk6 screen sudo tmux wget xauth xterm
We are unfortunately stung by the ABI change in GCC 6 when using clang. You need to recompile the Boost C++ libraries to be able to use clang, see the section in the Annexes on Compiling Boost. 
At the time of writing there is little difference between Sid and Testing, here is the recommend dependencies installation command line:
$ aptget y install \
autoconf automake bashcompletion bison cmake emacs24 \
flex git gmsh ipython libanndev libboostalldev \
libbz2dev libcgaldev libclndev libcppunitdev \
libeigen3dev libglpkdev libgmshdev \
libhdf5openmpidev libhwlocdev liblapackdev \
libmpfrdev libopenblasdev libopenmpidev \
libopenturnsdev libpcre3dev libtool libvtk6dev \
openmpibin paraview petscdev pkgconfig pythondev \
pythonh5py pythonnumpy pythonply pythonsix \
pythonurllib3 pythonvtk6 screen slepcdev sudo \
tmux wget xauth xterm zsh
Unfortunately the older distributions have the ABI GCC issue with clang, e.g. Debian/jessie, or they are too old to support a simple installation procedure.
Feel++ is supported on Mac OSX, starting from OS X 10.9 Mavericks to OS X 10.12 Sierra using Homebrew or MacPorts.
Xcode is required on Mac OSX to install Feel++.
The easiest way to do so is to go through the Apple Store application and to search for Xcode. Xcode will provide the programming environment, e.g clang, for the next steps.
Homebrew is a free/open source software introduced to simplify the installation of other free/open source software on MacOS X. Homebrew is distributed under the BSD 2 Clause (NetBSD) license. For more information, visit their website.
To install the latest version of Homebrew, simply visit their website and follow the instructions. Each new package Homebrew installs is built into an intermediate place called the Cellar (usually /usr/local/Cellar) and then the packages are symlinked into /usr/local (default).
Homebrew base command is brew
. Here is a list of base available commands:
brew doctor
: Check if the system has any problem with the current installation of Homebrew;
brew install mypackage
: This command installs the package mypackage;
brew install [develHEAD] mypackage
: These options respectively installs either the development version or the HEAD version of the package mypackage, if such versions are specified in the Formula file;
brew uninstall mypackage
: This command allows to uninstall the package mypackage.
A Formula is a Ruby script format specific to Homebrew. It allows to describe the installation process of a package. Feel[]+ uses specific Formulae that you can get in the Feel+ github repository: feelpp/homebrewfeelpp.
This section is aimed at users that do not have Homebrew already installed.
In order to build Feel++ from Homebrew, you have to do the following steps:
First install Homebrew
pass:[\( /usr/bin/ruby e "\)](curl fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
then check your Homebrew installation and fix warnings/errors if necessary
$ brew doctor
Install Homebrewscience tap to get the scientific software recommended or suggested for Feel++.
$ brew tap homebrew/homebrewscience
you should see something like
==> Tapping homebrew/science
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrewscience'...
remote: Counting objects: 661, done.
remote: Compressing objects: 100% (656/656), done.
remote: Total 661 (delta 0), reused 65 (delta 0), packreused 0
Receiving objects: 100% (661/661), 591.93 KiB  0 bytes/s, done.
Tapped 644 formulae (680 files, 1.9M)
Next you install Feel++ tap with
brew tap feelpp/homebrewfeelpp
you should read something like
==> Tapping feelpp/feelpp
Cloning into '/usr/local/Homebrew/Library/Taps/feelpp/homebrewfeelpp'...
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 4 (delta 0), packreused 0
Unpacking objects: 100% (5/5), done.
Tapped 1 formula (30 files, 60.7K)
The final step is to either install Feel++
$ brew install feelpp
or just Feel++ dependencies if you plan to build Feel++ from sources yourself
$ brew install onlydependencies feelpp
Note If you encounter problems, you can fix them using
brew doctor
. A frequent issue is to forceopenmpi
withbrew link overwrite openmpi
If Homebrew is already installed on your system, you might want to customize your installation for the correct dependencies to be met for Feel++.
You can browse Feel++ dependencies using the following command:
$ brew deps feelpp  column
you get the list of formulas Feel++ depends on for its installation
ann fftw libtool slepc
arpack gcc metis suitesparse
autoconf glpk mumps sundials
automake gmp netcdf superlu
boost gmsh openmpi superlu_dist
cln hdf5 parmetis szip
cmake hwloc petsc tbb
eigen hypre scalapack veclibfort
If you want to customize the compilation process for a dependency (Set debug mode, Remove checking steps, Remove the link with certain libraries, etc.), you can access to the building options with the info
flag. For exemple, with openmpi:
$ brew info openmpi
You get various information about the openmpi
formula
openmpi: stable 2.0.1 (bottled), HEAD
High performance message passing library
https://www.openmpi.org/
Conflicts with: lcdftypetools, mpich
/usr/local/Cellar/openmpi/2.0.1 (688 files, 8.6M) *
Built from source on 20160926 at 10:36:46 with: c++11 withmpithreadmultiple
From: https://github.com/Homebrew/homebrewcore/blob/master/Formula/openmpi.rb
==> Dependencies
Required: libevent ✔
==> Requirements
Recommended: fortran ✔
Optional: java ✔
==> Options
c++11
Build using C++11 mode
withcxxbindings
Enable C++ MPI bindings (deprecated as of MPI3.0)
withjava
Build with java support
withmpithreadmultiple
Enable MPI_THREAD_MULTIPLE
withoutfortran
Build without fortran support
HEAD
Install HEAD version
Then, you then just have to pass the needed flags, when installing the dependency.
Important:
boost
has to be installed with mpi and c++11 support andmumps
needs to be installed with the following scotch5 support.
MacPorts is an opensource community projet which aims to design an easytouse system for compiling, installing and upgrading opensource software on Mac OS X operating system. It is distributed under BSD License and facilitate the access to thousands of ports (software) without installing or compiling opensource software. MacPorts provides a single software tree which includes the latest stable releases of approximately 17700 ports targeting the current Mac OS X release (10.9). If you want more information, please visit their website.
To install the latest version of MacPorts, please go
to Installing
MacPorts page and follow the instructions. The simplest way is to
install it with the Mac OS X Installer using the pkg
file
provided on their website. It is recommended that you install X11 (X Window System) which is normally used to display X11 applications.
If you have installed with the package installer (MacPorts2.x.x.pkg
) that means MacPorts will be installed in
/opt/local
. From now on, we will suppose that macports has
been installed in /opt/local
which is the default MacPorts
location. Note that from now on, all tools installed by MacPorts will be installed in /opt/local/bin
or /opt/local/sbin
for example (that’s here you’ll find gcc4.7 or later e.g
/opt/local/bin/g++mp4.7
once being installed).
In your commandline, the software MacPorts is called by the command port
. Here is a list of key commands for using MacPorts, if you want more informations please go to MacPorts Commands.
sudo port v selfupdate
: This action should be used regularly to update the local tree with the global MacPorts ports. The option v
enables verbose which generates verbose messages.
port info mypackage
: This action is used to get information about a port. (description, license, maintainer, etc.)
sudo port install mypackage
: This action install the port mypackage.
sudo port uninstall mypackage
: This action uninstall the port mypackage.
port installed
: This action displays all ports installed and their versions, variants and activation status. You can also use the v
option to also display the platform and CPU architecture(s) for which the ports were built, and any variants which were explicitly negated.
sudo port upgrade mypackage
: This action updgrades installed ports and their dependencies when a Portfile
in the repository has been updated. To avoid the upgrade of a port’s dependencies, use the option n
.
A Portfile is a TCL script which usually contains simple
keyword values and TCL expressions. Each package/port has a
corresponding Portfile but it’s only a part of a port description.
Feel[]+ provides some mandatory Portfiles for its compilation which are either not available in MacPorts or are buggy but Feel+ also provides some Portfiles which are already available in MacPorts such as gmsh or petsc. They usually provide either some fixes to ensure Feel++ works properly or new version not yet available in MacPorts. These Portfiles are installed in ports/macosx/macports
.
To be able to install Feel++, add the following line in
/opt/local/etc/macports/source.conf
at the top of the file
before any other sources:
file:///<path to feel top directory>/ports/macosx/macports
Once it’s done, type in a commandline:
$ cd <your path to feel top directory>/ports/macosx/macports
$ sudo portindex f
You should have an output like this:
Reading port index in pass:[\(<\)]your path to feel top directorypass:[\(>\)]/ports/macosx/macports
Adding port science/feel++
Adding port science/gmsh
Adding port science/petsc
Total number of ports parsed: 3
Ports successfully parsed: 3
Ports failed: 0
Uptodate ports skipped: 0
Your are now able to type
$ sudo port install feel++
It might take some time (possibly an entire day) to compile all the requirements for Feel++ to compile properly. If you have several cores on your MacBook Pro, iMac or MacBook, we suggest that you configure macports to use all or some of them.
To do that uncomment the following line in the file
/opt/local/etc/macports/macports.conf
buildmakejobs 0 pass:[\(\#\)] all the cores
At the end of the sudo port install feel++
, you have all
dependencies installed. To build all the Makefile, \cmake
is
automatically launched but can have some libraries may not be found but they are not mandatory for build Feel++, only the features related to the missing libraries will be missing.
Missing ports

Once the steps to install on Linux or MacOS X has been followed, we explain, in this section, how to download and build Feel++ from source.
First retrieve the source
$ git clone https://github.com/feelpp/feelpp.git
Create a build directory
$ mkdir build
$ cd build
Configure Feel++
$ CXX=clang++ ../feelpp/configure r
Compile the Feel++ library
$ make feelpp
you can speed up the make process by passing the option j<N> where N is the number of concurrent make subprocesses. It compiles N files at a time and respect dependencies. For example j4 compiles 4 C++ files at a time.

Be aware that Feel++ consumes memory. The Feel++ library compile with 2Go of RAM. But to be more comfortable, 4Go or more would be best. The more, the better. 
Compile your first Feel++ applications
$ make quickstart
Execute your first Feel++ application in sequential
$ cd quickstart
$ ./feelpp_qs_laplacian_2d configfile qs_laplacian_2d.cfg
Execute your first Feel++ application using 4 mpi processes
$ mpirun np 4 feelpp_qs_laplacian_2d configfile qs_laplacian_2d.cfg
Feel is distributed as tarballs following each major release. The tarballs are available on the link:https://github.com/feelpp/feelpp/releases[Feel Releases] web page.
Download the latest tarball, then uncompress it with:
$ tar xzf feelppX.YY.0.tar.gz
$ cd feelppX.YY.0
You can now move to the section Using cmake.
Alternatively, you can download the sources of Feel++ directly from the Git repository.
$ git clone https://github.com/feelpp/feelpp.git
You should read something like
Cloning into 'feelpp'...
remote: Counting objects: 129304, done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 129304 (delta 6), reused 0 (delta 0), packreused 129283
Receiving objects: 100% (129304/129304), 150.52 MiB  1.69 MiB/s, done.
Resolving deltas: 100% (94184/94184), done.
Checking out files: 100% (7237/7237), done.
$ cd feelpp
The first level directory tree is as follows
$ tree L 1 d  column
. ├── databases ├── research
├── applications ├── doc ├── testsuite
├── benchmarks ├── feel └── tools
├── cmake ├── ports 14 directories
├── contrib ├── projects
├── data ├── quickstart
For now on, we assume that clang++
has been installed in /usr/bin
. Yor mileage
may vary depending on your installation of course.
It is not allowed to build the library in the top source directory. 
It is recommended to have a directory (e.g.

The configuration step with cmake
is as follows
$ cd FEEL/feel.opt
$ cmake ../feelpp DCMAKE_CXX_COMPILER=/usr/bin/clang++3.6 DCMAKE_C_COMPILER=/usr/bin/clang3.6 DCMAKE_BUILD_TYPE=RelWithDebInfo
CMake supports different build type that you can set with 
Alternatively you can use the configure
script which calls cmake
. configure help
will provide the following help.
Options:
b, build build type: Debug, Release, RelWithDebInfo
d, debug debug mode
rd, relwithdebinfo relwithdebinfo mode
r, release release mode
std=c++xx c++ standard: c++14, c++1z (default: c++14)
stdlib=libxx c++ standard library: stdc++(GCC), c++(CLANG) (default: stdc++)
maxorder=x maximum polynomial order to instantiate(default: 3)
cxxflags override cxxflags
cmakeflags add extra cmake flags
prefix=PATH define install path
v, verbose enable verbose output
h, help help page
<package>dir=PACKAGE_PATH define <package> install directory
disable<package> disable <package>
generator=GENERATOR cmake generator
We display below a set of possible configurations:
Compile using Release build type, default c compiler and libstdc
$ ../feelpp/configure r
Compile using Release build type, clang compiler and libstdc
$ CXX=clang++ ../feelpp/configure r
Compile using Debug build type, clang compiler and libc
CXX=clang++ ../feelpp/configure d stdlib=c++
Once cmake
or configure
have done their work successfully, you are ready to compile Feel++
$ make
You can speed up the compilation process, if you have a multicore processor by specifying the number of parallel jobs make
will be allowed to spawn using the j
flag:
$ make j4 feelpp
From now on, all commands should be typed in build directory (e.g feel.opt ) or its subdirectories.

If you encounter issues with Feel++, you can run the testsuite and send the resulting report. Feel++ has more than 300 tests running daily on our servers. Most of the tests are run both in sequential and in parallel.
The testsuite is in the testsuite
directory.
$ cd testsuite
The following command will compile 10 tests at a time
$ make j10
$ ctest j4 R .
It will run 4 tests at a time thanks to the option j4
.
Docker is the recommended way if you are beginning using Feel++.
This chapter explains step by step how to get the Feel++ Container System(FCS), how to execute a precompiled application, how to parameter and run models.
Container based technologies are revolutionizing development, deployment and execution of softwares. Containers encapsulate a software and allow to run seamlessly on different platforms — clusters, workstations, laptops — The developer doesn’t have to worry about specific environments and users spend less time in configuring and installing the software. Containers appear to be lightweight virtual machines (VMs) — they are started in a fraction of a second — but they, in fact, have important differences.
One of the differences is the isolation process. The VMs share only the hypervisor, the OS and hardware whereas containers may share, between each other, large parts of filesystems rather than having copies. Another difference is that, unlike in VMs, processes in a container are similar to native processes and they do not incur the overhead due to the VM hypervisor. The figure below illustrates these fundamental differences. We see in particular that the applications 2 and 3 are sharing lib 2 without redundancy.
Docker is a container technology providing:
an engine to start and stop containers,
a user friendly interface from the creation to the distribution of containers and
a hub — cloud service for container distribution — that provides publicly a huge number of containers to download and avoid duplicating work.
This section covers briefly the installation of Docker. It should be a relatively simple smooth process to install Docker.
Docker offers two channels: the stable and beta channels.
is fully baked and tested software providing a reliable platform to work with. Releases are not frequent.
offers cutting edge features and experimental versions of the Docker Engine. This is a continuation of the initial Beta program of Docker to experiment with the latest features in development. It incurs far more instabilities than the stable channel but releases are done frequently — possibly several releases per month.
In the latter we shall consider only installing and using the stable channel.
At the time of writing this section, Docker is available on Linux, Mac and Windows.
The support for Mac and Windows as Host OS was recently released and Docker Inc provides installation processes Docker For Mac and Docker for Windows which are the recommended way of installing Docker on these platforms.
Most Linux distributions have their own packages but they tend to lag behind the stable releases of Docker which could be a serious issue considering the development speed of Docker.
To follow Docker releases, it is probably best to use the packages distributed by Docker.
The last possibility is to use Docker Binaries to install Docker. This should be used at the last resort if packages are provided neither by your distribution nor by Docker Inc.
At the time of writing this book, the Docker version we used is Docker 1.12. All commands have been tested with this version.
On Linux, Docker is a priviledged binary, you need to prefix all your commands with sudo
, e.g. on Ubuntu. You need first to belong to the docker
group with the following command on Ubuntu
$ sudo usermod aG docker
It creates the docker
group if it doesn’t already exist and adds the current user to the docker
group. Then you need to log out and log in again. Similar process is available on other distributions. You need also to restart the docker
service
$ sudo service docker restart
From now on, we omit the sudo command when using Docker for the sake of brevity.

Adding a user to the docker group has security implications. On a shared machine, you should consider reading the Docker security page.

We now check your installation by running docker version
To make sure everything is installed correctly and working, try running the docker version command. You should see something like the following on Linux or Mac.
docker version
on Linux> docker version Client: Version: 1.12.1 API version: 1.24 Go version: go1.6.3 Git commit: 23cf638 Built: Mon, 10 Oct 2016 21:38:17 +1300 OS/Arch: linux/amd64 Server: Version: 1.12.1 API version: 1.24 Go version: go1.6.3 Git commit: 23cf638 Built: Mon, 10 Oct 2016 21:38:17 +1300 OS/Arch: linux/amd64
docker version
on Mac> docker version Client: Version: 1.12.6 API version: 1.24 Go version: go1.6.4 Git commit: 78d1802 Built: Wed Jan 11 00:23:16 2017 OS/Arch: darwin/amd64 Server: Version: 1.12.6 API version: 1.24 Go version: go1.6.4 Git commit: 78d1802 Built: Wed Jan 11 00:23:16 2017 OS/Arch: linux/amd64
If so, you are ready for the next step. If instead you get something like
docker version
on Linux> docker version Client: Version: 1.12.1 API version: 1.24 Go version: go1.6.3 Git commit: 23cf638 Built: Mon, 10 Oct 2016 21:38:17 +1300 OS/Arch: linux/amd64 Cannot connect to the Docker daemon. Is the docker daemon running on this host?
docker version
on Mac> docker version Client: Version: 1.12.6 API version: 1.24 Go version: go1.6.4 Git commit: 78d1802 Built: Wed Jan 11 00:23:16 2017 OS/Arch: darwin/amd64 Error response from daemon: Bad response from Docker engine
then it means that the Docker daemon is not running or that the client cannot access it.
To investigate the problem you can try running the daemon manually — e.g. sudo docker daemon
. This should give you some informations of
what might have gone wrong with your installation.
Feel++ leverages the power of Docker and provides a stack of container images.
To test Docker is installed properly, try
$ docker run feelpp/feelppenv echo 'Hello World!'
We have called the docker run
command which takes care of executing
containers. We passed the argument feelpp/feelppenv
which is a
Feel++ Ubuntu 16.10 container with the required programming
and execution environment for Feel++.

This may take a while depending on your internet connection but eventually you should see something like
Unable to find image 'feelpp/feelppenv:latest' locally (1) latest: Pulling from feelpp/feelppenv 8e21f82d32cf: Pull complete [...] 0a8dee947f9b: Pull complete Digest: sha256:457539dbd781594eccd4ddf26a7aefdf08a2fff9dbeb1f601a22d9e7e3761fbc Status: Downloaded newer image for feelpp/feelppenv:latest Hello World!
1  The first line tells us that there is no local copy of this Feel++ image. Docker checks automatically online on the Docker Hub if an image is available. 
Once the image is downloaded, Docker launches the container and
executes the command we provided echo 'Hello World!'
from inside the
container. The result of the command is showed on the last line of the
output log above.
If you run the command again, you won’t see the download part and the command will be executed very fast.
We can ask Docker to give us a shell using the following command
$ docker run it feelpp/feelppenv
It provides a shell prompt from inside the container which is very
similar to what you obtain when login with ssh
on a remote
machine. The flags i
and t
tell Docker to provide an interactive
session (i
) with a TTY attached (t
).
The Feel++ Container System (FCS) is organized in layers and provides a set of images.
The naming convention of the FCS allows the user to know where they come from and where they are stored on the Docker Hub. The name of the images is built as follows
feelpp/feelp<component>[:tag]
where
feelpp/
is the namespace of the image and organization name
feelpp<component>
the image name and Feel++ component
[:tag]
an optional tag for the image, by default set to :latest
Feel++ images(components) are defined as layers in the FCS in the table below.
Component  Description  Built From 


Execution and Programming environment 
<OS> 

Feel++ libraries and tools 


Feel++ base applications 


Feel++ toolboxes 

 Note: feelppenv
depends on an operating system image <OS>
, the recommended and default <OS>
is Ubuntu 16.10. In the future, we will build upon the next Ubuntu LTS or Debian Stable releases.
By default, the :latest
tag is assumed in the name of the images, for example when running
$ docker run it feelpp/feelppbase
it is in fact feelpp/feelppbase:latest
which is being launched.
The following table displays how the different images depend from one another.
Image  Built from 


Ubuntu 16.10 






As we said before the default Host OS is Ubuntu 16.10.
However Docker shines in continuous integration. It provides a large set of operating system to build upon and allows to check the software in various contexts. The FCS takes advantage of Docker to build feelpplibs
for several operating systems provided by feelppenv
and with different compilers any time a commit in the Feel++ repository is done.
Operating system  version  feelppenv Tags 
Compilers 

Ubuntu 
16.10 

GCC 6.x, Clang 3.9 
Ubuntu 
16.04 

GCC 6.x, Clang 3.8 
Debian 
sid 

GCC 6.x, Clang 3.9,4.0 
Debian 
testing 

GCC 6.x, Clang 3.9 
If you are interested in testing Feel++ in these systems, you can run these flavors.
feelpplibs
builds from feelppenv
and provides:
the Feel++ libraries
the Feel++ mesh partitioner application
$ docker run feelpp/feelpplibs
feelppbase
builds from feelpplibs
and provides two basic applications:
feelpp_qs_laplacian_*
: 2D and 3D laplacian problem
feelpp_qs_stokes_*
: 2D stokes problem
$ docker run feelpp/feelppbase
feelpptoolboxes
builds from feelppbase
and provides
$ docker run feelpp/feelpptoolboxes
To run Feel++ applications in docker, you need first to create a directory where you will store the Feel++ simulation files. For example, type
> mkdir $HOME/feel
and then type the following docker command
> docker run it v $HOME/feel:/feel feelpp/feelpplibs
The previous command will execute the latest feelpp/feelpplibs
docker
image in interactive mode in a terminal (ti
) and mount $HOME/feel
in the directory /feel
of the docker image.
Running the command df
inside the Docker container launched by the previous command
feelpp@4e7b485faf8e:~$ df
will get you this kind of output
Filesystem 1Kblocks Used Available Use% Mounted on none 982046716 505681144 426457452 55% / tmpfs 132020292 0 132020292 0% /dev tmpfs 132020292 0 132020292 0% /sys/fs/cgroup /dev/sda2 982046716 505681144 426457452 55% /feel shm 65536 0 65536 0% /dev/shm
You see on the last but one line the directory $HOME/feel
mounted on /feel
in the Docker image.
Note that mouting a host subdirectory on /feel is
mandatory. If you don’t, the Feel++ applications will exit due to lack
of permissions. If you prefer running inside the docker environment
you can type unset FEELPP_REPOSITORY and then all results from
Feel++ applications will be store in $HOME/feel. But then
you will have to use `rsync or ssh to copy your results out of the
docker image if needed.

We are interested in this section in the conforming finite element approximation of the following problem:
Look for \(u\) such that
\(\partial \Omega_D\), \(\partial \Omega_N\) and \(\partial \Omega_R\) can be empty sets. In the case \(\partial \Omega_D =\partial \Omega_R = \emptyset\), then the solution is known up to a constant. 
In the implementation presented later, \(\partial \Omega_D =\partial \Omega_N = \partial \Omega_R = \emptyset\), then we set Dirichlet boundary conditions all over the boundary. The problem then reads like a standard laplacian with inhomogeneous Dirichlet boundary conditions: Laplacian Problem with inhomogeneous Dirichlet conditions
Look for \(u\) such that Inhomogeneous Dirichlet Laplacian problem
\[\Delta u = f\ \text{ in } \Omega,\quad u = g \text{ on } \partial \Omega\]

We assume that \(f, h, l \in L^2(\Omega)\). The weak formulation of the problem then reads:
Look for \(u \in H^1_{g,\Gamma_D}(\Omega)\) such that
We now turn to the finite element approximation using Lagrange finite element. We assume \(\Omega\) to be a segment in 1D, a polygon in 2D or a polyhedron in 3D. We denote \(V_\delta \subset H^1(\Omega)\) an approximation space such that \(V_{g,\delta} \equiv P^k_{c,\delta}\cap H^1_{g,\Gamma_D}(\Omega)\).
The weak formulation reads:
Look for \(u_\delta \in V_\delta \) such that
from now on, we omit \(\delta\) to lighten the notations. Be careful that it appears both the geometrical and approximation level. 
In Feel++, \(V_{g,\delta}\) is not built but rather \(P^k_{c,\delta}\).
The Dirichlet boundary conditions can be treated using different techniques and we use from now on the elimination technique. 
We start with the mesh
auto mesh = loadMesh(_mesh=new Mesh<Simplex<FEELPP_DIM,1>>);
the keyword auto enables type inference, for more details see Wikipedia C++11 page.

Next the discretization setting by first defining Vh=Pch<k>(mesh)
\(\equiv P^k_{c,h}\), then elements of Vh
and expressions f
, n
and g
given by command line options or configuration file.
auto Vh = Pch<2>( mesh );
auto u = Vh>element("u");
auto mu = doption(_name="mu");
auto f = expr( soption(_name="functions.f"), "f" );
auto r_1 = expr( soption(_name="functions.a"), "a" ); // Robin left hand side expression
auto r_2 = expr( soption(_name="functions.b"), "b" ); // Robin right hand side expression
auto n = expr( soption(_name="functions.c"), "c" ); // Neumann expression
auto g = expr( soption(_name="functions.g"), "g" );
auto v = Vh>element( g, "g" );
at the following line

the variational formulation is implemented below, we define the
bilinear form a
and linear form l
and we set strongly the
Dirichlet boundary conditions with the keyword on
using
elimination. If we don’t find Dirichlet
, Neumann
or Robin
in the
list of physical markers in the mesh data structure then we impose
Dirichlet boundary conditions all over the boundary.
auto l = form1( _test=Vh );
l = integrate(_range=elements(mesh),
_expr=f*id(v));
l+=integrate(_range=markedfaces(mesh,"Robin"), _expr=r_2*id(v));
l+=integrate(_range=markedfaces(mesh,"Neumann"), _expr=n*id(v));
toc("l");
tic();
auto a = form2( _trial=Vh, _test=Vh);
a = integrate(_range=elements(mesh),
_expr=mu*gradt(u)*trans(grad(v)) );
a+=integrate(_range=markedfaces(mesh,"Robin"), _expr=r_1*idt(u)*id(v));
a+=on(_range=markedfaces(mesh,"Dirichlet"), _rhs=l, _element=u, _expr=g );
//! if no markers Robin Neumann or Dirichlet are present in the mesh then
//! impose Dirichlet boundary conditions over the entire boundary
if ( !mesh>hasAnyMarker({"Robin", "Neumann","Dirichlet"}) )
a+=on(_range=boundaryfaces(mesh), _rhs=l, _element=u, _expr=g );
We have the following correspondance:

next we solve the algebraic problem
//! solve the linear system, find u s.t. a(u,v)=l(v) for all v
if ( !boption( "nosolve" ) )
a.solve(_rhs=l,_solution=u);
next we compute the \(L^2\) norm of \(u_\deltag\), it could serve as an \(L^2\) error if \(g\) was manufactured to be the exact solution of the Laplacian problem.
cout << "u_hg_L2=" << normL2(_range=elements(mesh), _expr=idv(u)g) << std::endl;
and finally we export the results, by default it is in the ensight gold format and the files can be read with Paraview and Ensight. We save both \(u\) and \(g\).
auto e = exporter( _mesh=mesh );
e>addRegions();
e>add( "u", u );
e>add( "g", v );
e>save();
The Feel++ Implementation comes with testcases in 2D and 3D.
circle
is a 2D testcase where \(\Omega\) is a disk whose boundary
has been split such that \(\partial \Omega=\partial \Omega_D \cup
\partial \Omega_N \cup \partial \Omega_R\).
Here are some results we can observe after use the following command
cd Testcases/quickstart/circle
mpirun np 4 /usr/local/bin/feelpp_qs_laplacian_2d configfile circle.cfg
This give us some data such as solution of our problem or the mesh used in the application.
Solution \(u_\delta\) 
Mesh 
This testcase solves the Laplacian problem in \(\Omega\) an quadrangle or hexadra containing the letters of Feel++
After running the following command
cd Testcases/quickstart/feelpp2d
mpirun np 4 /usr/local/bin/feelpp_qs_laplacian_2d configfile feelpp2d.cfg
we obtain the result \(u_\delta\) and also the mesh
/images/Laplacian/TestCases/Feelpp2d/meshfeelpp2d.png[] 

Solution \(u_\delta\) 
Mesh 
We can launch this application with the current line
cd Testcases/quickstart/feelpp3d
mpirun np 4 /usr/local/bin/feelpp_qs_laplacian_3d configfile feelpp3d.cfg
When it’s finish, we can extract some informations
Solution \(u_\delta\) 
Mesh 
Christophe Prud’homme <@prudhomm> v1.0, 2017/03/07
merge with 02SettingUpEnvironment.adoc and rewrite pending! 
Feel++ generates various files that are spread over various directories. For this tutorial, it would be beneficial to check the content of these files to familiarize yourself with Feel++.
Some of Feel++ behavior can be driven by environment variables such as
FEELPP_REPOSITORY
FEELPP_WORKDIR
Both variables should point to the same place. They define the root directory where the simulation results will be stored. By default they are set to $HOME/feel
.
If you want to change the root directory where the results are stored, define e.g. FEELPP_REPOSITORY. For example in the docker image feel/apps:latest
, it points to /feel
.
For running,
docker run it v $HOME/feel:/feel feelpp/apps:latest
should get you this output
# Feel++ applications
This image provides the Feel++ applications in
. advection
. fluid mechanics
. solid mechanics
. fluidstructure interaction
. thermodynamics
The testcases are in $HOME/Testcases/ and the results are in
$HOME/feel
Follow the steps described in
http://book.feelpp.org/content/Applications/Models/readme.html
to use the models.
feelpp@50381de2bd23:~$
and here is the result of echo $FEELPP_REPOSITORY
in the docker image
feelpp@50381de2bd23:~pass:[\( echo \)]FEELPP_REPOSITORY
/feel
Results $FEELPP_REPOSITORY/feel/<your_app_name>/np_1
Feel++ uses Google Glog.
Log files : $FEELPP_REPOSITORY/feel/<your_app_name>/np_1/logs
Mesh : $FEELPP_REPOSITORY/feel/<your_app_name>/np_1
Config files : $FEELPP_REPOSITORY/<your_build_folder>/doc/manual/tutorial
merge with 01OutputDirectories.adoc and rewrite pending! 
Let’s begin with our first program using the Feel++ framework. To start, you include the Feel++ headers.
We use the C++ namespace
to avoid Feel::
prefix before
Feel++ objects.
We initialize the environment variables through the Feel++
Environment
class, which can be found
here.
Unresolved directive in 06programming/02SettingUpEnvironment.adoc  include::../../codes/02environment.cpp[]
and the config file
Unresolved directive in 06programming/02SettingUpEnvironment.adoc  include::{sourcedir}02environment.cfg[lines=2..3]
We pass command line options using the Boost Program Options, library using the prefix po::
which is a Feel++ alias for the Boost::program_options namespace. To add a new Feel++ option, we must create a new Feel++ options_description
. You must add the default Feel++ options
and the new one that we choose here as a double value. Note that the default value will be assigned if not specified by the user.
To compile a tutorial, just use the GNU make command.
make feelpp_tut_<appname>
where <appname>
is the name of the application you wish to compile (here, myapp
). Go to the execution directory as specified in the program, and execute it.You can list the log files created :
ls /tmp/<your login>/feelpp/feelpp_tut_myapp/
If you open one of these log, you should be able to see your value and the processor number used to compute. You can run your application on several processors using MPI :
mpirun np 2 feelpp_tut_myapp
Note that there will be one log for each processor in that case.
A config file can be parsed to the program to profile your options. The default config paths are,
current dir
$HOME/Feelpp/config/
$INSTALL_PREFIX/share/Feelpp/config/
then you have to write inside one of these folders a file called
<app_name>.cfg
or feelpp_<app_name>.cfg
. For example, our
myapp.cfg
would look like :
value=0.53
Note that you can specify the config file through the option configfile=<path>
It’s also possible to give several configuration files with the option configfiles <path1> <path2> <path3>
./feelpp_tut_myapp configfiles ex1.cfg ex2.cfg ex3.cfg
In the case where some options are duplicated in the files, the priority is given at the end :
ex3.cfg
can overwrite options in ex2.cfg
and ex1.cfg
ex2.cfg
can overwrite options in ex1.cfg
All files in configfiles
can overwrite options given by configfile
. And all options in the command line can overwrite all options given in cfg files.
PETSc is a suite of data structures and routines for the scalable (parallel) solution of scientific applications modeled by partial differential equations. It employs the MPI standard for parallelism.
Feel++ supports the PETSc framework, the Environment
takes care of initializing the associated PETSc environment.
The next step is to load a mesh.
The loadMesh
function has a _name
option set by default as the
default value of the gmsh.filename
option that point either to a
.geo
, either to a .msh
, or a .h5
file. Meshes in general are
more detail into this section.
auto mesh=loadMesh( _mesh=new Mesh<Simplex<2>> );
See this section for more details about exporting and visualizing meshes.
An implementation reads as follows:
Unresolved directive in 06programming/03LoadingMesh.adoc  include::../../codes/03mymesh.cpp[]
and the associated config file
Unresolved directive in 06programming/03LoadingMesh.adoc  include::../../codes/03mymesh.cfg[]
The next step is to construct a function space over the mesh.
We start by loading a Mesh in 2D.
Unresolved directive in 06programming/04UsingExpressions.adoc  include::../../codes/04myexpression.cpp[tag=mesh]
then we define some expression through the command line of config
file: g
is a scalar field and f
is a vector field, here is an
example how to enter them :
./feelpp_tut_myexpression a=3 functions.g="a*x*y:x:y:a" functions.f="{sin(pi*x),cos(pi*y)}:x:y"
You can print back the expression to the screen to check that
everything is ok. You want to use as expression a*x+b*y
, you have to
define a
and b
as option (either in your code, either in the
library).
then we compute the gradient of g
and f
.
Unresolved directive in 06programming/04UsingExpressions.adoc  include::../../codes/04myexpression.cpp[tag=grad]
template argument are given to grad to specify the
shape of the gradient: in the case of \(\nabla g\), it is \(1\times2\)
and \(2\times 2\) for \(\nabla f\) since we are in 2D.

then we compute the laplacian of g
and f
.
Unresolved directive in 06programming/04UsingExpressions.adoc  include::../../codes/04myexpression.cpp[tag=laplacian]
then we compute the divergence of f
.
Unresolved directive in 06programming/04UsingExpressions.adoc  include::../../codes/04myexpression.cpp[tag=div]
and the curl of f
Unresolved directive in 06programming/04UsingExpressions.adoc  include::../../codes/04myexpression.cpp[tag=curl]
Finally we evaluate these expressions at one point given by the option x
and y
.
An implementation reads as follows:
Unresolved directive in 06programming/04UsingExpressions.adoc  include::../../codes/04myexpression.cpp[tag=all]
and the associated config file
Unresolved directive in 06programming/04UsingExpressions.adoc  include::../../codes/04myexpression.cfg[]
$ ./feelpp_tut_myexpression
or
$ ./feelpp_tut_myexpression a=3 functions.g="<your_function>" functions.f="<your_function>"
We start with the following function \(\)g=1\(\) and \(\)f=(1,1)\(\).
$./feelpp_tut_myexpression functions.g=1:x:y functions.f="{1,1}:x:y"
and get something like this
g=1
f={1,1}
i=(xaVal)*y
grad(g)=[[0,0]]
grad(f)=[[0,0],[0,0]]
laplacian(g)=[[0]]
laplacian(f)=[[0],[0]]
div(f)=[[0]]
curl(f)=[[0]]
Evaluation at (0,0):
g(x,y)=1
f(x,y)=1
1
i(x,y)=0
Gradient:
grad(g)(x,y)=0 0
grad(f)(x,y)=0 0
0 0
Divergence:
div(f)(x,y)=0
Curl:
curl(f)(x,y)=0
Laplacian:
laplacian(g)(x,y)=0
laplacian(f)(x,y)=0
0
The symbolic calculus system worked as expected.
Once you have created an element, you may want to give it a value, that can depends on a lot of parameters ( mainly spaces, but others may apply ).
To do so, Feel++ relies on expressions. We may use various kind of expressions :
Let’s begin with the evaluation of the expression \(sin(\pi x)\) on a unit circle.
First at all, we define the unit circle and its function space :
Unresolved directive in 06programming/05EvaluatingFunctions.adoc  include::../../codes/05myexporter.cpp[tags=meshspace]
Then the expression we would like to evaluate :
Unresolved directive in 06programming/05EvaluatingFunctions.adoc  include::../../codes/05myexporter.cpp[tags=expr]
Px()
refers to the variable \(\)x\(\) of our space.
With this,we can project
it on our function space :
Unresolved directive in 06programming/05EvaluatingFunctions.adoc  include::../../codes/05myexporter.cpp[tags=project]
The expression will be evaluated on each point of our mesh.
In order to visualize the result, we create an exporter, named exhi
, and add to it the projection.
Unresolved directive in 06programming/05EvaluatingFunctions.adoc  include::../../codes/05myexporter.cpp[tags=project]
In this second method, we will use Functor :
Unresolved directive in 06programming/05EvaluatingFunctions.adoc  include::../../codes/myfunctor.cpp[tags=functor]
We create a unit square meshed by triangles and we define the associated function space :
Unresolved directive in 06programming/05EvaluatingFunctions.adoc  include::../../codes/myfunctor.cpp[tags=meshspace]
From this space, we can define two elements, here one equals to the
variable \(x\) and the other to the variable \(y\), obtain from
Functor
class.
Unresolved directive in 06programming/05EvaluatingFunctions.adoc  include::../../codes/myfunctor.cpp[tags=elements]
The data exportation is the final step to visualize our expression \(\)x\(\) and \(\)y\(\) on the defined mesh.
[import:"exporter",unindent:"true"](../codes/myfunctor.cpp)
The next step is to visualize function over the mesh. The source code that generate our output is available in myexporter.cpp, presented in the previous section.
You can visualize data via :
The results files are in
$HOME/feel/myexporter/np_1
or
$FEELPP_WORKDIR/feel/myexporter/np_1
.
We discriminate output directories based on the name of the simulation
(the parameter _name
in the environment), the number of process
(mpirun np …
) and the type of the chosen exporter
exporter.format={ensightensightgoldgmsh...}
You’ve learned how to discretize the space you want to compute on. You now have to learn how to define and use function spaces and elements of functions spaces. For advanced informations on this subject, you can look in the Function Spaces documentation.
Loading a Mesh in 2D
auto mesh = loadMesh(_mesh=new Mesh<Simplex<2>>);
For basic function spaces, we have predetermined constructors:
auto Xh = Pch<2>( mesh );
Defining an element
auto u = Xh>element( "u" );
auto w = Xh>element( "w" );
One can also use :
Pdh<ORDER>(mesh)
: Polynomial Discontinuous
Pvh<ORDER>(mesh)
: Polynomial Continuous Vectorial
Pdhv<ORDER>(mesh)
: Polynomial Discontinuous Vectorial
Pchm<ORDER>(mesh)
: Polynomial Continuous Matrix
Ned1h<ORDER>(mesh)
: Nedelec function spaces
The implementation reads are follows
Unresolved directive in 06programming/07SpaceElements.adoc  include::../../codes/07myfunctionspace.cpp[tag=all]
and the associated config file
Unresolved directive in 06programming/07SpaceElements.adoc  include::../../codes/07myfunctionspace.cfg[]
The next step is to compute integrals over the mesh ( See this for detailed methods ).
We start by loading a Mesh in 2D
then we define the Feel[]+ expression that we are going to integrate
using the soption function that retrieves the command line option
string `functions.g`. We then transform this string into a Feel+
expression using expr().
then we compute two integrals over the domain and its boundary respectively
\(\int_\Omega g\)
\(\int_{\partial \Omega} g\)
and we print the results to the screen.
Only the rank 0 process (thanks to Environment
) isMasterRank()
prints to the screen as the result is the same over all mpi processes
if the application was run in parallel. Note also that the code
actually prints the expression passed by the user through the command
line option functions.g
.
We start with the following function \(g=1\). Recall that by default the domain is the unit square, hence the \(\int_\Omega g\) and \(\int_{\partial\Omega} g\) should be equal to 1 and 4 respectively.
./feelpp_tut_myintegrals functions.g=1
int_Omega 1 = 1
int_{boundary of Omega} 1 = 4
Now we try \(g=x\). We need to tell Feel++ what are the symbols
associated with the expression: here the symbol is x
and it works as
follows
./feelpp_tut_myintegrals functions.g=x:x
int_Omega x = 0.5
int_{boundary of Omega} x = 2
remember that there is a separator : between the expression and each symbol
composing it.

Now we try \(g=x y\). We need to tell Feel++ what are the symbols
associated with the expression: here the symbol is x
and y
and it
works as follows
./feelpp_tut_myintegrals functions.g=x*y:x:y
int_Omega x*y = 0.25
int_{boundary of Omega} x*y = 1
More complicated functions are of course doable, such as \(g=\sin( x y ).\)
./feelpp_tut_myintegrals functions.g="sin(x*y):x:y"
int_Omega sin(x*y) = 0.239812
int_{boundary of Omega} sin(x*y) = 0.919395
Here is the last example in parallel over 4 processors which returns, of course, the exact same results as in sequential
mpirun np 4 ./feelpp_doc_myintegrals functions.g="sin(x*y):x:y"
int_Omega sin(x*y) = 0.239812
int_{boundary of Omega} sin(x*y) = 0.919395
Finally we can change the type of domain and compute the area and perimeter of the unit disk as follows
./feelpp_doc_myintegrals functions.g="1:x:y" gmsh.domain.shape=ellipsoid gmsh.hsize=0.05
int_Omega 1 = 0.784137
int_{boundary of Omega} 1 = 3.14033
Note that we don’t get the exact results due to the fact that [stem]:[\Omega_h = \cup_{K \in \mathcal{T}_h} K] which we use for the numerical integration is different from the exact domain \(\Omega = \{ (x,y)\in \mathbb{R}^2  x^2+y^2 < 1\}\).
To compile just type
$ ./feelpp_tut_myintegrals
The complete code reads as follows :
Unresolved directive in 06programming/08ComputingIntegrals.adoc  include::../../codes/08myintegrals.cpp[]
Unresolved directive in 06programming/08ComputingIntegrals.adoc  include::../../codes/08myintegrals.cfg[]
With all the previously notions we approach, the definition of a partial differential equation and boundary conditions are our next step. More details on these aspects can be retrieve at this page.
This example refers to a laplacian problem, define by
After turning the Strong formulation into its weak form, we have
where \(u\) is the unknown and \(v\) a test function. The left side is known as the bilinear form \(a\) and the right side is the linear form \(l\).
The steps to implement this problem are
Loading a 2D mesh, creating the function space \(V_h\), composed of piecewise polynomial functions of order 2, and its associated elements
auto mesh = loadMesh(_mesh=new Mesh<Simplex<2>>);
auto Vh = Pch<2>( mesh );
auto u = Vh>element();
auto v = Vh>element();
Define the linear form \(l\) with test function space \(V_h\)
auto l = form1( _test=Vh );
l = integrate(_range=elements(mesh),
_expr=id(v));
Define the bilinear form \(a\) with \(V_h\) as test and trial function spaces
auto a = form2( _trial=Vh, _test=Vh);
a = integrate(_range=elements(mesh),
_expr=gradt(u)*trans(grad(v)) );
form1
and form2
are used to define respectively the left and right
side of our partial differential equation.
Add Dirichlet boundary condition on \(\)u\(\)
a+=on(_range=boundaryfaces(mesh),
_rhs=l, _element=u, _expr=cst(0.) );
We impose, in this case, \(u=0\) on \(\partial\Omega\), with the keyword on
.
Solving the problem
a.solve(_rhs=l,_solution=u);
Exporting the solution
auto e = exporter( _mesh=mesh );
e>add( "u", u );
e>save();
The complete code reads as follows :
Unresolved directive in 06programming/11SolveAnEquation.adoc  include::../../codes/11mylaplacian.cpp[]
and the corresponding config file
Unresolved directive in 06programming/11SolveAnEquation.adoc  include::../../codes/11mylaplacian.cfg[]
After the discretization process, one may have to solve a (non) linear system. Feel++ interfaces with PETSc/SLEPc and Eigen3. Consider this system
We call Backend
an object that manages the solution strategy to
solve it. Some explanation are available at
Solver and
Preconditioner.
Feel++ provides a default backend that is mostly hidden to the final user. In many examples, you do not have to take care of the backend. You change the backend behavior via the command line or config files. For example
./feelpp_doc_mybackend backend.pctype=id
will use the identity matrix as a right preconditionner for the default backend. The size of the preconditionner will be defined from the size of the A matrix.
If you try to solve a different system \(A_1 y= c\) (in size) with the same backend or the default without rebuilding it, it will fail.
backend(_rebuild=true)>solve(_matrix=A1,_rhs=c,_sol=y);
Each of that options can be retrieved via the helplib
argument in the command line.
You may need to manage more than one backend in an application: you have different systems to solve and you want to keep some already computed objects such as preconditioners.
The default backend is in fact an unnamed backend: in order to distinguish between backend you have to name them. For example
Unresolved directive in 06programming/09UsingBackend.adoc  include::../../codes/09mybackend.cpp[tag=marker_opt]
After that, you create the backend object:
Unresolved directive in 06programming/09UsingBackend.adoc  include::../../codes/09mybackend.cpp[tag=marker_obj]
the backend’s name has to match the name you gave at the options step. 
Then, you load meshes, creates spaces etc. At solve time, or you solve with the default backend:
Unresolved directive in 06programming/09UsingBackend.adoc  include::../../codes/09mybackend.cpp[tag=marker_default]
One of the important backend option is to be able to monitor the residuals and iteration count
./feelpp_tut_mybackend pctype=id kspmonitor=true myBackend.kspmonitor=true
Finally you can create a named backend:
Unresolved directive in 06programming/09UsingBackend.adoc  include::../../codes/09mybackend.cpp[tag=marker_hm]
The implementation reads as follows:
Unresolved directive in 06programming/09UsingBackend.adoc  include::../../codes/09mybackend.cpp[tag=marker_main]
and the associated config file
Unresolved directive in 06programming/09UsingBackend.adoc  include::../../codes/09mybackend.cfg[]
It is well known an equation can describe a huge range of physical problems. Each of theses problems will have a particular environment, but the equation to solve will be the same. To make our program applicable to theses range of problem, we have defined a model. Models definitions can be retrieve in this section.
A model is defined by :
a Name
a Description
a Model
Parameters
Materials
Boundary Conditions
Post Processing
A parameter is a non physical property for a model.
To retrieve the materials properties, we use :
ModelMaterials materials = model.materials();
Thanks to GiNaC, we handle boundary conditions (Dirichlet, Neumann, Robin) as expression. You have to indicate in the json file the quantity to handle (velocity, pressure…) and the associated expression.
map_scalar_field<2> bc_u { model.boundaryConditions().getScalarFields<2>("heat","dirichlet") };
We can apply theses boundary condition this way
for(auto it : bc_u){
if(boption("myVerbose") && Environment::isMasterRank() )
std::cout << "[BC]  Applying " << it.second << " on " << it.first << std::endl;
a+=on(_range=markedfaces(mesh,it.first), _rhs=l, _element=u, _expr=it.second );
}
Unresolved directive in 06programming/12CreateModels.adoc  include::../../codes/10model1.cpp[]
TODO: explanation pending.
We have set up an example : an anisotropic laplacian.
Unresolved directive in 06programming/12CreateModels.adoc  include::../../codes/10model2.cpp[]
Unresolved directive in 06programming/README.adoc  include::https://raw.githubusercontent.com/feelpp/feelpp/develop/CONTRIBUTING.adoc[]
Christophe Prud’homme <@prudhomm> v1.0, 2017/03/07
This is an overview of the coding conventions we use when writing Feel++ code.
clangformat
is a powerful tool to reformat your code according to
rules defined in a .clangformat
file at the toplevel directory of
your software.
Feel++ has such a file and define the indentation, space and breaks rules defined later on.
For clangformat
to function properly, follow the Comments rules.
To apply Feel++ rules on a file a.cpp
in a Feel++ subdirectory, type
clangformat a.cpp
to dump the results of the reformating to the standard output or type
clangformat i a.cpp
which will replace a.cpp
by the reformated file.
be careful when reformating, make sure nobody is working on that file, to avoid creating possibly massive conflicts with the persons currently modifying the same code when they get merged. 
To avoid multiple inclusions, wrap every header files using the following technique
// say we have myheader.hpp
#if !defined(FEELPP_MYHEADER_HPP)
#define FEELPP_MYHEADER_HPP 1
// your header here...
#endif // FEELPP_MYHEADER_HPP
more details here
In Feel++, we basically follow the same naming conventions as in Qt and KDE.
Class names starts with a capital. The rest is in camel case. Function names starts with a lower case, but the first letter of each successive word is capitalized.
Functions and classes should be in the Feel
namespace.
The prefix set
is used for setters, but the prefix get
is not used
for accessors. Accessors are simply named with the name of the property
they access. The exception is for accessors of a boolean which may start
with the prefix is
.
Acronyms are lowercased too. Example: Url instead of URL and isFemEnabled() instead of isFEMEnabled()
Accessors should usually be const.
This example shows some possible functions names
class A
{
public:
void setMatrix(const Matrix& c);
Matrix matrix() const;
void setDiagonal(bool b);
bool isDiagonal() const;
};
Do not use underscores to start identifiers, see StackOverFlow comments here for the reasons
4 spaces are used for indentation but not in namespace
Spaces, not tabs!
Suggestion: use emacs and [http://emacswiki.org/emacs/dirvars.el
dirvars.el], here is the content of .emacsdirvars
in top Feel++
directory
indenttabsmode: nil tabwidth: 4 cbasicoffset: 4 evaluate: (csetoffset 'innamespace '0) showtrailingwhitespace: t indicateemptylines: t evaluate: (addhook 'writefilehooks 'deletetrailingwhitespace)
namespace Feel
{
// no space indentation in namespace
Class A
{
// 4 spaces indentation
A() {};
void f();
};
}
Use C++ style comment //
rather than /* */
. It uses less
characters but also it is easier to reflow using clang format.
/* Wrong
the doc
*/
// Correct
// the doc
Doxygen is the tool to document Feel++ and create a reference manual 
Use //!
to comment function, variables, classes rather than /**
*/
, it allows to reflow comments using clang format.
//!
//! @brief the class
//! @author me <me@email>
//!
class TheClass
{
public:
//! constructor
TheClass() {}
private:
//! member
int member;
};
//! the function
void thefunction() {}
Feel++ used to promote /** */ but this is no longer the case.
The comment style will be updated progressively to match the new style using //!

Declare each variable on a separate line
Avoid short (e.g. a
, rbarr
, nughdeget
) names whenever possible
Single character variable names are only okay for counters and temporaries, where the purpose of the variable is obvious
Wait when declaring a variable until it is needed
// Wrong
int a, b;
char __c, __d;
// Correct
int height;
int width;
char __nameOfThis;
char __nameOfThat;
Variables and functions start with a lowercase letter. Each consecutive word in a variable’s or function’s name starts with an uppercase letter
Avoid abbreviations
// Wrong
short Cntr; char ITEM_DELIM = '';
// Correct
short counter; char itemDelimiter = '';
Classes always start with an uppercase letter.
// Wrong
class meshAdaptation {};
// Correct
class MeshAdaptation {};
Nonstatic data members name of structures and classes always start with M_
. M stands for Member. The rational behind this is for example :
to be able to immediately see that the data is a member of a class or a struct
to easily search and queryreplace
// Wrong
class meshAdaptation { std::vector directions_; };
// Correct
class MeshAdaptation { std::vector M_directions; };
Static data members name of structures and classes always start with S_
. S
stands for Static. The rational behind this is for example :
to be able to immediately see that the data is a static member of a class or a struct
to easily search and queryreplace
// Wrong
class meshAdaptation { static std::vector directions_; };
// Correct
class MeshAdaptation { static std::vector S_directions; };
Use blank lines to group statements together where suited
Always use only one blank line
Always use a single space after a keyword and before a curly brace.
// Correct
if (foo) { }
// Wrong
if(foo) { }
For pointers or references, always use a single space between the type and or
&
, but no space between the or
&
and the variable name.
char *x;
const std::string &myString;
const char * const y = "hello";
Surround binary operators with spaces.
No space after a cast.
Avoid Cstyle casts when possible.
// Wrong
char* blockOfMemory = (char* ) malloc(data.size());
// Correct
char *blockOfMemory = reinterpret_cast(malloc(data.size()));
As a base rule, the left curly brace goes on the same line as the start of the statement:
// Wrong
if (codec) { }
// Correct
if (codec) { }
Function implementations and class declarations always have the left brace on the start of a line:
static void foo(int g) { std::cout << g << "" }
class Moo { };
Use curly braces when the body of a conditional statement contains more than one line, and also if a single line statement is somewhat complex.
// Wrong
if (address.isEmpty()) { return false; }
for (int i = 0; i < 10; ++i) { std::cout << "i=" << i << ""; }
// Correct
if (address.isEmpty()) return false;
for (int i = 0; i < 10; ++i) std::cout << "=" << i << "";
Exception 1: Use braces also if the parent statement covers several lines / wraps
// Correct
if (address.isEmpty()  !isValid()  !codec)
{
return false;
}
Exception 2: Use braces also in ifthenelse blocks where either the ifcode or the elsecode covers several lines
// Wrong
if (address.isEmpty())
return false;
else
{
std::cout << address << ""; ++it;
}
// Correct
if (address.isEmpty())
{
return false;
}
else
{
std::cout << address << ""; ++it;
}
// Wrong
if (a) if (b) ... else ...
// Correct
if (a) { if (b) ... else ... }
Use curly braces when the body of a conditional statement is empty
// Wrong
while (a);
// Correct
while (a) {}
Use parentheses to group expressions:
// Wrong
if (a && b  c)
// Correct
if ((a && b)  c)
// Wrong
a + b & c
// Correct
(a + b) & c
The case labels are in the same column as the switch
Every case must have a break (or return) statement at the end or a comment to indicate that there’s intentionally no break, unless another case follows immediately.
switch (myEnum)
{
case Value1:
doSomething();
break;
case Value2:
case Value3:
doSomethingElse(); // fall through
default:
defaultHandling();
break;
}
Keep lines shorter than 100 characters; insert breaks if necessary.
Commas go at the end of a broken line; operators start at the beginning of the new line. An operator at the end of the line is easy to not see if your editor is too narrow.
// Correct
if (longExpression + otherLongExpression + otherOtherLongExpression) { }
// Wrong
if (longExpression + otherLongExpression + otherOtherLongExpression) { }
virtual
keywordWhen reimplementing a virtual method, do not put the virtual
keyword in the header file.
In this chapter, we develop a quick reference for the various stages of a simulation using Feel++. 
Feel++ offers a development environment for solving partial differential equations. It uses many tools to cover the different steps preprocessing, processing and postprocessing and large range of numerical methods and needs. To this end it is crucial to have a powerful build environment. Feel++ uses CMake from Kitware and provides various macros to help setting up your own application or research project.
See section Using Feel++.
See section Using Feel++.
For a give application or multiple applications you may define testcases. testcases are difrectory containing a set of files that may include geometry, mesh, cfg or json files.
To define a new testcase case, create a subdirectory where your
application, say myapp
like in the previous section, stands and copy
the required files there.
cd <source directory of my application>
mkdir mytestcase
# copy files (.geo, .msh, .cfg...) to mytestcase
...
then edit the CMakeLists.txt
in your application directory and add
the following line:
feelpp_add_testcase(mytestcase)
Then type make feelpp_add_testcase_mytestcase
in the build directory
of your application myapp
. It will copy in the build directory of
your application the directory mytestcase.
INFO: if you updated the testcase data files, executing make
feelpp_testcase_mytestcase
will use rsync
to update the files that
were changed in the source.
The macro feelpp_add_testcase
supports options:
PREFIX
(default is feelpp
) set the prefix of the target to avoid eg name clash
feelpp_add_testcase(mytestcase PREFIX foo)
then the target is foo_add_testcase_mytestcase
.
DEPS
set the dependencies of the testcase
feelpp_add_testcase(mytestcase DEPS myothertestcase)
it allows to update a testcase depending on changes in an other one.
In this section, we present some tools to initialize and manipulate Feel++ environment.
Environment class is necessary to initialize your application, as seen in FirstApp. Interface is as follows:
Environment env( _argc, _argv, _desc, _about );
None of those parameters are required but it is highly recommended to use the minimal declaration:
Environment env( _argc=argc, _argv=argv,
_desc=feel_option(),
_about=about(_name="name_of_your_app",
_author="your_name",
_email="your_email_adress"));
_argc
and _argv
are the arguments of your main function.
_desc
is a description of your options.
_about
is a brief description of your application.
feel_options()
returns a list of default options used in Feel++.
You can create your own list of options as follows:
using namespace Feel;
inline
po::options_description
makeOptions()
{
po::options_description myappOptions( "My app options" );
myappOptions.add_options()
( "option1", po::value<type1>()>default_value( value1 ), "description1" )
( "option2", po::value<type2>()>default_value( value2 ), "description2" )
( "option3", po::value<type3>()>default_value( value3 ), "description3" )
;
// Add the default feel options to your list
return myappOptions.add( feel_options() );
}
makeOptions
is the usual name of this routine but you can change it amd myappOptions
is the name of you options list.
Parameter 
Description 

the name of parameter 

the type parameter 

the default value of parameter 

the description of parameter 
You can then use makeOptions()
to initialize the Feel++ Environment as follows
Environment env( _argc=argc, _argv=argv,
_desc=makeOptions(),
_about=about(_name="myapp",
_author="myname",
_email="my@email.com") );
Then, at runtime, you can change the parameter as follows
$ ./myapp option1=alpha option2=beta option3=gamma
quickstart/qs_laplacian.cpp
using namespace Feel;
using Feel::cout;
po::options_description laplacianoptions( "Laplacian options" );
laplacianoptions.add_options()
( "nosolve", po::value<bool>()>default_value( false ), "No solve" )
;
Environment env( _argc=argc, _argv=argv,
_desc=laplacianoptions,
_about=about(_name="qs_laplacian",
_author="Feel++ Consortium",
_email="feelppdevel@feelpp.org"));
Environment::optionsDescription();
Returns options description data structure of type po::options_description
po
where is a namespace alias defined in Feel++ for boost::program_options
.
You can access to the parameters of your application environment using the following function:
Environment::vm(_name);
_name
is the name of the parameter as seen in the previous paragraph. This function returns a data structure of type po::variable_value
. You can then extract the proper parameter value as follows
const double E = Environment::vm(_name="E").template as<double>();
const double nu = Environment::vm(_name="nu").template as<double>();
auto Tfinal = Environment::vm( _name="test" ).template as<int>()*dt;
You can change the default repository where the results are stored
void changeRepository( _directory, _subdir, _filename );
Parameter 
Description 
Status 
Default value 

directory name 
Required 






You can use boost
format to customize the path as follows:
Environment::changeRepository( boost::format( "doc/manual/laplacian/%1%/%2%%3%/P%4%/h_%5%/" )
% this>about().appName()
% shape
% Dim
% Order
% meshSize );
Then results will be store in: /doc/manual/laplacian/<appName>/<shape><Dim>/P<Order>/h_<meshSize>/
std::string findFile( std::string const& filename );
Returns the string containing the filename path.
The lookup is as follows:
look into current path
look into paths that went through changeRepository()
, it means that we look for example into the path from which the executable was run
If the file has an extension .geo or .msh, try also to
look into localGeoRepository()
which is usually $HOME/feel/geo
look into systemGeoRepository()
which is usually $FEELPP_DIR/share/feel/geo
If filename
is not found, then the empty string is returned.
A lot of data structures, in fact most of them, in Feel++ are parallel and are associated with a WorldComm
data structure which allows us to access and manipulate the MPI communicators.
We provide some utility free functions that allow a transparent access to the WorldComm
data structure.
We denote by c
a Feel++ data structure associated to a WorldComm
.
Feel++ Keyword 
Description 
rank(c) 
returns the local MPI rank of the data structure 
globalRank(c) 
returns the global MPI rank of the data 
For example to print the rank of a mesh data structure
// initialise environment...
auto mesh = makeMesh<Simplex<2,1>>();
std::cout << "local rank : " << rank(mesh) << "\n";
Feel++ provides some tools to manipulate meshes. Here is a basic example that shows how to generate a mesh for a square geometry
codes/mymesh.cpp
Unresolved directive in 07quickref/Mesh/README.adoc  include::../../../codes/03mymesh.cpp[tag=mesh]
As always, we initialize the Feel[]+ environment (see section link:[FirstApp] ). The `unitSquare()` will generate a mesh for a square geometry. Feel+ provides several functions to automate the GMSH mesh generation for different topologies. These functions will create a geometry file .geo
and a mesh file .msh
. We can visualize them in GMSH.
$ gmsh <entity_name>.msh
Finally we use the exporter()
(see \ref Exporter) function to export the mesh for post processing. It will create by default a Paraview format file .sos
and an Ensight format file .case
.
$ paraview <app_name>.case
In this section, we present some of the mesh definition and manipulation tools provided by Feel++. For more information you can also see \ref Gmsh.
There is a list of basic geometries you can automatically generate with Feel++ library.
Feel++ function 
Dim 
Description 

1 
Build a mesh of the unit segment \(\)[0,1]\(\) 

2 
Build a mesh of the unit square \(\)[0,1]^2\(\) using triangles 

2 
Build a mesh of the unit circle using triangles 

3 
Build a mesh of the unit hypercube \(\)[0,1]^3\(\) using tetrahedrons 

3 
Build a mesh of the unit sphere using tetrahedrons 
Examples:
From doc/manual/tutorial/myfunctionspace.cpp
auto mesh = unitSquare();
You can use this function to:
load a .msh
file and use the mesh data structure
load a .geo
file and automatically generate a mesh data structure on this geometrical structure
Interface:
mesh_ptrtype loadMesh(_mesh, _filename, _refine, _update, physical_are_elementary_regions);
Required Parameters:
_mesh
a mesh data structure.
Optional Parameters:
_hsize
(double): characteristic size of the mesh. This option will edit the .geo
file and change the variable h
if defined
Default: 0.1
Option: gmsh.hsize
_geo_variables_list
(string): Set a list of variable that may be defined in a .geo
file
Default: ""
Option: gmsh.geo
variableslist
_filename
(string): filename with extension.
Default: feel.geo
Option: gmsh.filename
_depends
(string): list of files (separated by , or ;) on which gmsh.filename
depends
Default: ""
Option: gmsh.depends
_refine
(boolean): optionally refine with \p refine levels the mesh.
Default: 0.
Option: gmsh.refine
_update
(integer): update the mesh data structure (build internal faces and edges).
Default: true
_physical_are_elementary_regions
(boolean): to load specific meshes formats.
Default: false.
Option: gmsh.physical_are_elementary_regions
_straighten
(boolean): in case of curvilinear elements, straighten the elements which are not touching with a face the boundary of the domain
Default: true
Option: gmsh.straighten
_partitioner
(integer): define the mesh partitioner to use:
Default: 1
(if Metis is available) 0
if not (CHACO)
Option: gmsh.partitioner
The file you want to load has to be in an appropriate repository.
Feel++ looks for .geo
and .msh
files in the following directories (in this order):
current path
paths that went through changeRepository()
, it means that we look for example into the path from which the executable was run
localGeoRepository()
which is usually "$HOME/feel/geo" (cf Environment )
systemGeoRepository()
which is usually "$FEELPP_DIR/share/feel/geo" (cf Environment)
Examples:
Load a mesh data structure from the file "$HOME/feel/mymesh.msh".
auto mesh = loadMesh(_mesh=new mesh_type,
_filename="mymesh.msh");
Load a geometric structure from the file ./mygeo.geo
and automatically create a mesh data structure.
auto mesh = loadMesh(_mesh=new mesh_type,
_filename="mygeo.geo");
Create a mesh data structure from the file ./feel.geo
.
auto mesh = loadMesh(_mesh=new Mesh<Simplex< 2 > > );
In order to load only .msh
file, you can also use the loadGMSHMesh.
Interface:
mesh_ptrtype loadGMSHMesh(_mesh, _filename, _refine, _update, _physical_are_elementary_regions);
Required Parameters:
_mesh
a mesh data structure.
_filename
filename with extension.
Optional Parameters:
_refine
optionally refine with \p refine levels the mesh.  Default =0
_update
update the mesh data structure (build internal faces and edges).
Default =true
_physical_are_elementary_regions
to load specific meshes formats.
Default = false
The file you want to load has to be in an appropriate repository. See LoadMesh.
Examples:
From doc/manual/heatns.cpp
mesh_ptrtype mesh = loadGMSHMesh( _mesh=new mesh_type,
_filename="piece.msh",
_update=MESH_CHECKMESH_UPDATE_FACESMESH_UPDATE_EDGESMESH_RENUMBER );
From applications/check/check.cpp
mesh = loadGMSHMesh( _mesh=new mesh_type,
_filename=soption("filename"),
_rebuild_partitions=(Environment::worldComm().size() > 1),
_update=MESH_RENUMBERMESH_UPDATE_EDGESMESH_UPDATE_FACESMESH_CHECK );
Interface:
mesh_ptrtype createGMSHMesh(_mesh, _desc, _h, _order, _parametricnodes, _refine, _update, _force_rebuild, _physical_are_elementary_regions);
Required Parameters:
_mesh
mesh data structure.
_desc
descprition. See further.
Optional Parameters:
_h
characteristic size.
Default = 0.1
_order
order.
Default = 1
_parametricnodes
Default = 0
_refine
optionally refine with \p refine levels the mesh.
Default =0
_update
update the mesh data structure (build internal faces and edges).
Default =true
_force_rebuild
rebuild mesh if already exists.
Default = false
_physical_are_elementary_regions
to load specific meshes formats.
Default = false
To generate your mesh you need a description parameter. This one can be create by one the two following function.
Use this function to create a description from a .geo
file.
Interface:
gmsh_ptrtype geo(_filename, _h, _dim, _order, _files_path);
Required Parameters:
filename
: file to load.
Optional Parameters:
_h
characteristic size of the mesh.
Default = 0.1.
_dim
dimension.
Default = 3.
_order
order.
Default = 1.
_files_path
path to the file.
Default = localGeoRepository().
The file you want to load has to be in an appropriate repository. See LoadMesh.
Example:
From doc/manual/heat/ground.cpp
mesh = createGMSHMesh( _mesh=new mesh_type,
_desc=geo( _filename="ground.geo",
_dim=2,
_order=1,
_h=meshSize ) );
From doc/manual/fd/penalisation.cpp
mesh = createGMSHMesh( _mesh=new mesh_type,
_desc=geo( _filename=File_Mesh,
_dim=Dim,
_h=Environment::vm(_name="hsize").template as<double>() ),
_update=MESH_CHECKMESH_UPDATE_FACESMESH_UPDATE_EDGESMESH_RENUMBER );
Use this function to generate a simple geometrical domain from parameters.
Interface:
gmsh_ptrtype domain(_name, _shape, _h, _dim, _order, _convex, \
_addmidpoint, _xmin, _xmax, _ymin, _ymax, _zmin, _zmax);
Required Parameters:
_name
name of the file that will ge generated without extension.
_shape
shape of the domain to be generated (simplex or hypercube).
Optional Parameters:
_h
characteristic size of the mesh.
Default = 0.1
_dim
dimension of the domain.
Default = 2
_order
order of the geometry.
Default = 1
_convex
type of convex used to mesh the domain.
Default = simplex
_addmidpoint
add middle point.
Default = true
_xmin
minimum x coordinate.
Default = 0
_xmax
maximum x coordinate.
Default = 1
_ymin
minimum y coordinate.
Default = 0
_ymax
maximum y coordinate.
Default = 1.
_zmin
minimum z coordinate.
Default = 0
_zmax
maximum z coordinate.
Default = 1
Example:
From doc/manual/laplacian/laplacian.ccp
mesh_ptrtype mesh = createGMSHMesh( _mesh=new mesh_type,
_desc=domain( _name=( boost::format( "%1%%2%" ) % shape % Dim ).str() ,
_usenames=true,
_shape=shape,
_h=meshSize,
_xmin=1,
_ymin=1 ) );
From doc/manual/stokes/stokes.cpp
mesh = createGMSHMesh( _mesh=new mesh_type,
_desc=domain( _name=(boost::format("%1%%2%%3%")%"hypercube"%convex_type().dimension()%1).str() ,
_shape="hypercube",
_dim=convex_type().dimension(),
_h=meshSize ) );
From doc/manual/solid/beam.cpp
mesh_ptrtype mesh = createGMSHMesh( _mesh=new mesh_type,
_update=MESH_UPDATE_EDGESMESH_UPDATE_FACESMESH_CHECK,
_desc=domain( _name=( boost::format( "beam%1%" ) % nDim ).str(),
_shape="hypercube",
_xmin=0., _xmax=0.351,
_ymin=0., _ymax=0.02,
_zmin=0., _zmax=0.02,
_h=meshSize ) );
Explanation pending on straightenMesh

Feel++ mesh data structure allows to iterate over its entities: elements, faces, edges and points.
The following table describes freefunctions that allow to define mesh region over which to operate. MeshType denote the type of mesh passed to the free functions in the table.
MeshType can be a pointer, a shared_pointer or a reference to a mesh type. 
For example :
auto mesh = loadMesh( _mesh=Mesh<Simplex<2>>);
auto r1 = elements(mesh); // OK
auto r2 = elements(*mesh); // OK
Type  Function  Description 



All the elements of a mesh 


All the elements marked by marked id 


All the elements of the mesh which share a face with the boundary of the mesh. 


All the elements of the mesh which share a face with the boundary of the mesh. 


All the faces of the mesh. 


All the faces of the mesh which are marked. 


All elements that own a topological dimension one below the mesh. For example, if you mesh is a 2D one, 


All the elements of the mesh which are stricly within the domain that is to say they do not share a face with the boundary. 


All the edges of the mesh. 


All boundary edges of the mesh. 


All the points of the mesh. 


All the points marked id of mesh. 


All boundary points of the mesh. 


All internal points of the mesh(not on the boundary) 
Here are some examples on how to use these functionSpace
auto mesh = ...;
auto r1 = elements(mesh);
// iterate over the set of elements local to the process(no ghost cell selected, see next section)
for ( auto const& e : r2 )
{
auto const& elt = unwrap_ref( e );
// work with element elt
...
}
auto r2 = markedelements(mesh,"iron");
// iterate over the set of elements marked iron in the mesh
for ( auto const& e : r2 )
{
auto const& elt = unwrap_ref( e );
// work with element elt
...
}
auto r3 = boundaryfaces(mesh);
// iterate over the set of faces on the boundary of the mesh
for ( auto const& e : r3 )
{
auto const& elt = unwrap_ref( e );
// work with element elt
...
}
auto r4 = markededges(mesh,"line");
// iterate over the set of edges marked "line" in the mesh
for ( auto const& e : r4 )
{
auto const& elt = unwrap_ref( e );
// work with element elt
...
}
Feel++ allows also to select an extended sets of entities from the mesh, you can extract entities which belongs to the local process but also ghost entities which satisfy the same property as the local ones.
Actually you can select both or one one of them thanks to the enum data structure entity_process_t which provides the following options
entity_process_t 
Description 

only local entities 

only ghost entities 

both local and ghost entities 
Type 
Function 
Description 


all the elements of mesh associated to entity_process_t. 


all the elements marked id of mesh associated to entity_process_t. 


all the faces of mesh associated to entity_process_t. 


all the faces marked id of mesh associated to entity_process_t. 


all the edges of mesh associated to entity_process_t. 


all the edges marked id of mesh associated to entity_process_t. 
The type of the object returned for an entity is always the same, for elements it is ext_elements_t<MeshType> whether the elements are marked or not.
The reason is that in fact we have to create a temporary data structure embedded in the range object that stores a reference to the elements which are selected.

Here is how to select both local and ghost elements from a Mesh
auto mesh =...;
auto r = elements(mesh,entity_process_t::ALL);
for (auto const& e : r )
{
// do something on the local and ghost element
...
// do something special on ghost cells
if ( unwrap_ref(e).isGhostCell() )
{...}
}
Denote \(\mathcal{E}_{1}, \ldots ,\mathcal{E}_{n}\) \(n\) disjoints sets of the same type of entities (eg elements, faces,edges or points), \(\cup_{i=1}^{n} \mathcal{E}_i\) with \(\cap_{i=0}^{n} \mathcal{E}_i = \emptyset\).
We wish to concatenate these \(n\) sets. To this end, we use concatenate
which takes an arbitrary number of disjoints sets.
#include <feel/feelmesh/concatenate.hpp>
...
auto E_1 = internalfaces(mesh);
auto E_2 = markedfaces(mesh,"Gamma_1");
auto E_3 = markedfaces(mesh,"Gamma_2");
auto newset = concatenate( E_1, E_2, E_3 );
cout << "measure of newset = " << integrate(_range=newset, _expr=cst(1.)).evaluate() << std::endl;
Denote \(\mathcal{E}\) a set of entities, eg. the set of all faces
(both internal and boundary faces). Denote \(\mathcal{E}_\Gamma\) a
set of entities marked by \(\Gamma\). We wish to build
\({\Gamma}^c=\mathcal{E}\backslash\Gamma\). To compute the complement,
Feel++ provides a complement
template function that requires
\(\mathcal{E}\) and a predicate that return true
if an entity of
\(\mathcal{E}\) belongs to \(\Gamma\), false
otherwise. The function
returns mesh iterators over \(\Gamma^c\).
#include <feel/feelmesh/complement.hpp>
...
auto E = faces(mesh);
// build set of boundary faces, equivalent to boundaryfaces(mesh)
auto bdyfaces = complement(E,[](auto const& e){return e.isOnBoundary()});
cout << "measure of bdyfaces = " << integrate(_range=bdyfaces, _expr=cst(1.)).evaluate() << std::endl;
// should be the same as above
cout << "measure of boundaryfaces = " << integrate(_range=boundaryfaces(mesh), _expr=cst(1.)).evaluate() << std::endl;
Feel++ provides some helper functions to apply on set of entities. We denote by range_t the type of the entities set.
Type 
Function 
Description 
size_type 
nelements(range_t,bool) 
returns the local number of elements in entities set range_t of bool is false, other the global number which requires communication (default: global number) 
WorldComm 
worldComm(range_t) 
returns the WorldComm associated to the entities set 
A range can be also build directly by the user. This customized range is stored in a std container which contains the c++ references of entity object. We use boost::reference_wrapper for take c++ references and avoid copy of mesh data. All entities enumerated in the range must have same type (elements,faces,edges,points). Below we have an example which select all active elements in mesh for the current partition (i.e. identical to elements(mesh)).
auto mesh = ...;
// define reference entity type
typedef boost::reference_wrapper<typename mesh_type::element_type const> element_ref_type;
// store entities in a vector
typedef std::vector<element_ref_type> cont_range_type;
boost::shared_ptr<cont_range_type> myelts( new cont_range_type );
for (auto const& elt : elements(mesh) )
{
myelts>push_back(boost::cref(elt));
}
// generate a range object usable in feel++
auto myrange = boost::make_tuple( mpl::size_t<MESH_ELEMENTS>(),
myelts>begin(),myelts>end(),myelts );
Next, this range can be used in feel++ language.
double eval = integrate(_range=myrange,_expr=cst(1.)).evaluate()(0,0);
Elements and their associated subentities can be marked.
A marker is an integer specifying for example a material id, a boundary condition id or some other property associated with the entity.
A dictionary can map string to marker ids.
The dictionary is stored in the Mesh data structures and provides the set of correspondances between strings and ids.
To access a marker, it is necessary to verify that it exists as follows
for( auto const& ewrap : elements(mesh))
{
auto const& e = unwrap_ref( ewrap );
if ( e.hasMarker() ) (1)
{
std::cout << "Element " << e.id() << " has marker " << e.marker() << std::endl;
}
if ( e.hasMarker(5) ) (2)
{
std::cout << "Element " << e.id() << " has marker 5 " << e.marker(5) << std::endl;
}
}
1  check if marker 1 (the default marker) exists, if yes then print it 
2  check if marker 5 exists, if yes then print it 
You should be able to create a mesh now. If it is not the case, get back to the section Mesh.
Feel++ provide the integrate() function to define integral expressions which can be used to compute integrals, define linear and bilinear forms.
integrate( _range, _expr, _quad, _geomap );
Please notice that the order of the parameter is not important, these
are boost
parameters, so you can enter them in the order you
want. To make it clear, there are two required parameters and 2
optional and they of course can be entered in any order provided you
give the parameter name. If you don’t provide the parameter name (that
is to say _range
= or the others) they must be entered in the order
they are described below.
Required parameters:
_range
= domain of integration
_expr
= integrand expression
Optional parameters:
_quad
= quadrature to use instead of the default one, wich means _Q<integer>()
where the integer is the polynomial order to integrate exactely
_geomap
= type of geometric mapping to use, that is to say:
Feel Parameter 
Description 

High order approximation (same of the mesh) 

Optimal approximation: high order on boundary elements order 1 in the interior 

Order 1 approximation (same of the mesh) 
From doc/manual/tutorial/dar.cpp
form1( ... ) = integrate( _range = elements( mesh ),
_expr = f*id( v ) );
From doc/manual/tutorial/myintegrals.cpp
// compute integral f on boundary
double intf_3 = integrate( _range = boundaryfaces( mesh ),
_expr = f );
From doc/manual/advection/advection.cpp
form2( _test = Xh, _trial = Xh, _matrix = D ) +=
integrate( _range = internalfaces( mesh ),
_quad = _Q<2*Order>(),
_expr = ( averaget( trans( beta )*idt( u ) ) * jump( id( v ) ) )
+ penalisation*beta_abs*( trans( jumpt( trans( idt( u ) )) )
*jump( trans( id( v ) ) ) ),
_geomap = geomap );
From doc/manual/laplacian/laplacian.cpp
auto l = form1( _test=Xh, _vector=F );
l = integrate( _range = elements( mesh ),
_expr=f*id( v ) ) +
integrate( _range = markedfaces( mesh, "Neumann" ),
_expr = nu*gradg*vf::N()*id( v ) );
This part explains how to integrate on a mesh with Feel++ (source
doc/manual/tutorial/myintegrals.cpp
).
Let’s consider the domain \(\Omega=[0,1\)^d] and associated meshes. Here, we want to integrate the following function
on the whole domain \(\Omega\) and on part of the boundary \(\Omega\).
There is the appropriate code:
int
main( int argc, char** argv )
{
// Initialize Feel++ Environment
Environment env( _argc=argc, _argv=argv,
_desc=feel_options(),
_about=about( _name="myintegrals" ,
_author="Feel++ Consortium",
_email="feelppdevel@feelpp.org" ) );
// create the mesh (specify the dimension of geometric entity)
auto mesh = unitHypercube<3>();
// our function to integrate
auto f = Px()*Px() + Py()*Py() + Pz()*Pz();
// compute integral of f (global contribution)
double intf_1 = integrate( _range = elements( mesh ),
_expr = f ).evaluate()( 0,0 );
// compute integral of f (local contribution)
double intf_2 = integrate( _range = elements( mesh ),
_expr = f ).evaluate(false)( 0,0 );
// compute integral f on boundary
double intf_3 = integrate( _range = boundaryfaces( mesh ),
_expr = f ).evaluate()( 0,0 );
std::cout << "int global ; local ; boundary" << std::endl
<< intf_1 << ";" << intf_2 << ";" << intf_3 << std::endl;
}
Let \(f\) a bounded function on domain \(\Omega\). You can evaluate the mean value of a function thanks to the mean()
function :
mean( _range, _expr, _quad, _geomap );
Required parameters:
_range
= domain of integration
_expr
= mesurable function
Optional parameters:
_quad
= quadrature to use.
Default = _Q<integer>()
_geomap
= type of geometric mapping.
Default = GEOMAP_OPT
mean
Unresolved directive in 07quickref/Integrals/mean.adoc  include::../../../codes/mystokes.cpp[tag=main]
Let \(f\) a bounded function on domain \(\Omega\).
Let \(\)f \in L^2(\Omega)\(\) you can evaluate the \(\)L^2\(\) norm using the normL2() function:
\(\) \parallel f\parallel_{L^2(\Omega)}=\sqrt{\int_\Omega f^2} \(\)
normL2( _range, _expr, _quad, _geomap );
or squared norm:
normL2Squared( _range, _expr, _quad, _geomap );
Required parameters:
_range
= domain of integration
_expr
= mesurable function
Optional parameters:
_quad
= quadrature to use.
Default = _Q<integer>()
_geomap
= type of geometric mapping.
Default = GEOMAP_OPT
From doc/manual/laplacian/laplacian.cpp
double L2error =normL2( _range=elements( mesh ),
_expr=( idv( u )g ) );
From doc/manual/stokes/stokes.cpp
mean
Unresolved directive in 07quickref/Integrals/norms.adoc  include::../../../codes/mystokes.cpp[tag=main]
In the same idea, you can evaluate the H1 norm or semi norm, for any function \(f \in H^1(\Omega)\):
where \(*\) is the scalar product \(\cdot\) when \(f\) is a scalar field and the frobenius scalar product \(:\) when \(f\) is a vector field.
normH1( _range, _expr, _grad_expr, _quad, _geomap );
or semi norm:
normSemiH1( _range, _grad_expr, _quad, _geomap );
Required parameters:
_range
= domain of integration
_expr
= mesurable function
_grad_expr
= gradient of function (Row vector!)
Optional parameters:
_quad
= quadrature to use.
Default = _Q<integer>()
_geomap
= type of geometric mapping.
Default = GEOMAP_OPT
normH1() returns a float containing the \(\)H^1\(\) norm.
With expression:
auto g = sin(2*pi*Px())*cos(2*pi*Py());
auto gradg = 2*pi*cos(2* pi*Px())*cos(2*pi*Py())*oneX()
2*pi*sin(2*pi*Px())*sin(2*pi*Py())*oneY();
// There gradg is a column vector!
// Use trans() to get a row vector
double normH1_g = normH1( _range=elements(mesh),
_expr=g,
_grad_expr=trans(gradg) );
With test or trial function u
double errorH1 = normH1( _range=elements(mesh),
_expr=(ug),
_grad_expr=(gradv(u)trans(gradg)) );
You can evaluate the infinity norm using the normLinf() function:
normLinf( _range, _expr, _pset, _geomap );
Required parameters:
_range
= domain of integration
_expr
= mesurable function
_pset
= set of points (e.g. quadrature points)
Optional parameters:
_geomap
= type of geometric mapping.
Default = GEOMAP_OPT
The normLinf()
function returns not only the maximum of the function
over a sampling of each element thanks to the _pset
argument but
also the coordinates of the point where the function is maximum. The
returned data structure provides the following interface
value()
: return the maximum value
operator()()
: synonym to value()
arg()
: coordinates of the point where the function is maximum
auto uMax = normLinf( _range=elements(mesh),
_expr=idv(u),
_pset=_Q<5>() );
std::cout << "maximum value : " << uMax.value() << std::endl
<< " arg : " << uMax.arg() << std::endl;
The prerequisites are
We now turn to the next crucial mathematical ingredient: the function space, whose definition depends on \(\Omega_h\)  or more precisely its partitioning \(\mathcal{T}_h\)  and the choice of basis function. Function spaces in Feel++ follow the same definition and Feel++ provides support for continuous and discontinuous Galerkin methods and in particular approximations in \(L^2\), \(H^1\)conforming and \(H^1\)nonconforming, \(H^2\), \(H(\mathrm{div})\) and \(H(\mathrm{curl})\)[^1].
We introduce the following spaces
where \(\mathbb{R}\mathbb{T}_k\) and \(\mathbb{N}_k\) are respectively the RaviartThomas and Nédélec finite elements of degree \(k\).
The Legrendre and Dubiner basis yield implicitely discontinuous
approximations, the Legendre and Dubiner boundary adapted basis,
see~\cite MR1696933, are designed to handle continuous approximations
whereas the Lagrange basis can yield either discontinuous or
continuous (default behavior) approximations.
\(\mathbb{R}\mathbb{T}_h\) and \(\mathbb{N}_h\) are implicitely spaces
of vectorial functions \(\mathbf{f}\) such that \(\mathbf{f}: \Omega_h
\subset \mathbb{R}^d \mapsto \mathbb{R}^d\). As to the other basis
functions, i.e. Lagrange, Legrendre, Dubiner, etc., they are
parametrized by their values namely Scalar
, Vectorial
or
Matricial.
Products of function spaces must be supported. This is very powerful to describe complex multiphysics problems when coupled with operators, functionals and forms described in the next section. Extracting subspaces or component spaces are part of the interface. 
Function spaces support is provided by the FunctionSpace
class
The FunctionSpace
class
constructs the table of degrees of freedom which maps local (elementwise) degrees of freedom to the global ones with respect to the geometrical entities,
embeds the definition of the elements of the function space allowing for a tight coupling between the elements and their function spaces,
stores an interpolation data structure (e.g. region tree) for rapid localisation of point sets (determining in which element they reside).
C++ Function 
C++ Type 
Function Space [1] 


\(P^N_{c,h}\) 


\([P^N_{c,h}\)^d] 


\(P^N_{d,h}\) 


\([P^N_{d,h}\)^d] 


\([P^{N+1}_{c,h}\)^d \times P^N_{c,h}] 


\(\mathbb{R}\mathbb{T}_h\) 


\(\mathbb{N}_h\) 
[1]: see Notations for the function spaces definitions.
Here are some examples how to define function spaces with Lagrange basis functions.
#include <feel/feeldiscr/pch.hpp>
// Mesh with triangles
using MeshType = Mesh<Simplex<2>>;
// Space spanned by P3 Lagrange finite element
FunctionSpace<MeshType,bases<Lagrange<3>>> Xh;
// is equivalent to (they are the same type)
Pch_type<MeshType,3> Xh;
// using the auto keyword
MeshType mesh = loadMesh( _mesh=new MeshType );
auto Xh = Pch<3>( mesh );
// is equivalent to
auto Xh = FunctionSpace<MeshType,bases<Lagrange<3>>>::New( mesh );
auto Xh = Pch_type<MeshType,3>::New( mesh );
One important feature in FunctionSpace is that it embeds the
definition of element which allows for the strict definition of an
Element of a FunctionSpace and thus ensures the correctness of the
code.

An element has its representation as a vector, also in the case of product of multiple spaces.
#include <feel/feeldiscr/pch.hpp>
// Mesh with triangles
using MeshType = Mesh<Simplex<2>>;
auto mesh = loadMesh( _mesh=new MeshType );
// define P3 Lagrange finite element space
auto P3ch = Pch<3>(mesh);
// definie an element from P3ch, initialized to 0
auto u = P3ch.element();
// definie an element from P3ch, initialized to x^2+y^2
auto v = P3ch.element(Px()*Px()+Py()*Py());
FunctionSpace<Mesh<Simplex<2> >,
bases<Lagrange<2,Vectorial>, Lagrange<1,Scalar>,
Lagrange<1,Scalar> > > P2P1P1;
auto U = P2P1P1.element();
// Views: changing a view changes U and vice versa
// view on element associated to P2
auto u = U.element<0>();
// extract view of first component
auto ux = u.comp(X);
// view on element associated to 1st P1
auto p = U.element<1>();
// view on element associated to 2nd P1
auto q = U.element<2>();
Feel++ has a very powerful interpolation framework which allows to:
transfer functions from one mesh to another
transfer functions from one space type to another.
this is done seamlessly in parallel. The framework provides a set of C++ classes and C++ freefunctions enabled short, concise and expressive handling of interpolation.
using MeshType = Mesh<Simplex<2>>;
auto mesh loadMesh( _mesh=new MeshType );
auto P1h = Pch<1>( mesh );
auto P0h = Pdh<0>( mesh );
auto Ih = I( _domain=P1h, _image=P0h );
The De Rahm diagram reads as follows: the range of each of the operators coincides with the null space of the next operator in the sequence below, and the last map is a surjection.
An important result is that the diagram transfers to the discrete level
The diagram above is commutative which means that we have the following properties:
The diagram can be restricted to functions satisfying the homogeneous Dirichlet boundary conditions 
Interpolation operators are provided as is or as shared pointers. The table below presents the alternatives.
C++ object 
C++ Type 
C++ shared object 
C++ Type 
Mathematical operator 




\(\)I: X_h \rightarrow Y_h \(\) 




\(\)\nabla: X_h \rightarrow W_h \(\) 




\(\)\nabla \times : W_h \rightarrow V_h \(\) 




\(\)\nabla \cdot: V_h \rightarrow Z_h \(\) 
auto mesh = loadMesh( _mesh=new Mesh<Simplex<Dim>>());
auto Xh = Pch<1>(mesh);
auto Gh = Ned1h<0>(mesh);
auto Ch = Dh<0>(mesh);
auto P0h = Pdh<0>(mesh);
auto Igrad = Grad( _domainSpace = Xh, _imageSpace=Gh );
auto Icurl = Curl( _domainSpace = Gh, _imageSpace=Ch );
auto Idiv = Div( _domainSpace = Ch, _imageSpace=P0h );
auto u = Xh>element(<expr>);
auto w = Igrad(u); // w in Gh
auto x = Icurl(w); // z in Ch
auto y = Idiv(x); // y in P0h
To save a function on disk to use it later, for example in another
application, you can use the save
function.
The saved file will be named after the name registered for the
variable in the constructor (default : u
).
auto Vh = Pch<1>( mesh );
auto u = Vh>element("v");
// do something with u
...
// save /path/to/save/v.h5
u.save( _path="/path/to/save", _type="hdf5" );
The path
parameter creates a directory at this path to store all the
degrees of liberty of this function.
The type
parameter can be binary
, text
or hdf5
. The first two
will create one file per processor, whereas "hdf5" will creates only
one file.
To load a function, the mesh need to be exactly the same as the one used when saving it. 
auto Vh = Pch<1>( mesh );
auto u = Vh>element("v");
// load /path/to/load/v.h5
u.load( _path="/path/to/load/", _type="hdf5" );
The path
and type
parameters need to be the same as the one used
to save the function.
In some cases, when we use parallel data, informations from other interfaces of partitions are need. To manage this, we can add ghost degree of freedom on ghost elements at these locations. However, we have to know if data have extended parallel doftable to load and use it.
In order to pass above this restriction, the two function load
and
save
has been updated to use hdf5 format. With this format, extended
parallel doftable or not, the function will work without any
issues. More than that, we can load elements with extended parallel
doftable and resave it without it, and vice versa. This last feature
isn’t available with other formats than hdf5.
We consider in this section bilinear and linear forms \(a: X_h \times X_h \rightarrow \mathbb{R}\) and \(\ell: X_h \rightarrow \mathbb{R}.\)
We suppose in this section that you know how to define your Mesh and your function spaces. You may need integration tools too, see Integrals.
There are Feel++ tools you need to create linear and bilinear forms in order to solve variational formulation.
from now on, u denotes an element from your trial function
space (unknown function) and v an element from your test function
space

form1
To construct a linear form \(\)\ell: X_h \rightarrow \mathbb{R}\(\), proceed as follows
auto mesh = ...;
// build a P1/Q1 approximation space
auto Xh = Pch<1>( mesh );
auto l = form1(_test=Xh);
Name 
Parameter 
Description 
Status 

function space e.g. 
define test function space 
Required 
Here are some examples taken from the Feel++ tutorial.
From mylaplacian.cpp
// right hand side
auto l = form1( _test=Vh );
l = integrate(_range=elements(mesh), _expr=id(v));
From myadvection.cpp
// right hand side
auto l = form1( _test=Xh );
l+= integrate( _range=elements( mesh ), _expr=f*id( v ) );
The operators += and = are supported by linear and bilinear forms.

auto a1 = form2(_test=Xh,_trial=Xh);
auto a2 = form2(_test=Xh,_trial=Xh);
// operations on a2 ...
// check that they have the same type and
// copy matrix associated to a2 in a1
a1 = a2;
form2
To define a bilinear form \(\)a: X_h \times X_h \rightarrow \mathbb{R}\(\), for example \(\)a(u,v)=\int_\Omega uv\(\)
form2
The freefunction form2
allows you to simply define such a bilinear form using the Feel++ language:
// define function space
auto Xh = ...;
// define a : Xh x Xh > R
auto a = form2(_trial=Xh, _test=Xh );
// a(u,v) = \int_\Omega u v
a = integrate(_range=elements(mesh), _expr=idt(u)*id(v));
Name 
Parameter 
Description 
Status 

function space e.g. 
define test function space 
Required 

function space e.g. 
define trial function space 
Optional 
Here are some examples taken from the Feel++ tutorial
From mylaplacian.cpp
// left hand side
auto a = form2( _trial=Vh, _test=Vh );
a = integrate(_range=elements(mesh),
_expr=gradt(u)*trans(grad(v)) );
From mystokes.cpp
:
// left hand side
auto a = form2( _trial=Vh, _test=Vh );
a = integrate(_range=elements(mesh),
_expr=trace(gradt(u)*trans(grad(u))) );
a+= integrate(_range=elements(mesh),
_expr=div(u)*idt(p)divt(u)*id(p));
see note above on operators += and =

Once you created your linear and bilinear forms you can use the solve()
member function of your bilinear form.
The following generic example solves: find \(\)u \in X_h \text{ such that } a(u,v)=l(v) \forall v \in X_h\(\)
auto Xh = ...; // function space
auto u = Xh>element();
auto a = form2(_test=Xh, _trial=Xh);
auto l = form1(_test=Xh);
a.solve(_solution=u, _rhs=l, _rebuild=false, _name="");
Name 
Parameter 
Description 
Status 

element of domain function space 
the solution 
Required 

linear form 
right hand side 
Required 

boolean(Default = 
rebuild the solver components 
Optional 

string(Default = "") 
name of the associated Backend 
Optional 
Here are some examples from the Feel++ tutorial.
laplacian.cpp
// solve the equation a(u,v) = l(v)
a.solve(_rhs=l,_solution=u);
on
for Dirichlet conditionsThe function on()
allows you to add Dirichlet conditions to your bilinear form before using the solve
function.
The interface is as follows
on(_range=..., _rhs=..., _element=..., _expr=...);
Required Parameters:
_range
domain concerned by this condition (see Integrals ).
_rhs
right hand side. The linear form.
_element
element concerned.
_expr
the condition.
This function is used with += operator.
Here are some examples from the Feel++ tutorial.
mylaplacian.cpp
// apply the boundary condition
a+=on(_range=boundaryfaces(mesh),
_rhs=l,
_element=u,
_expr=expr(soption("functions.alpha")) );
There we add the condition: \(\)u = 0 \text{ on }\;\partial\Omega \;\(\).
mystokes.cpp
a+=on(_range=boundaryfaces(mesh), _rhs=l, _element=u,
_expr=expr<2,1,5>(u_exact,syms));
You can also apply boundary conditions per component:
a+=on(_range=markedfaces(mesh,"top"),
_element=u[Component::Y],
_rhs=l,
_expr=cst(0.))
The notation u[Component:Y]
allows to access the Y
component of
u
. Component::X
and Component::Z
are respectively the X
and
Z
components.
Matrix Definition A matrix is a linear transformation between finite dimensional vector spaces.
Assembling a matrix Assembling a matrix means defining its action as entries stored in a sparse or dense format. For example, in the finite element context, the storage format is sparse to take advantage of the many zero entries.
Symmetric matrix \(\)A = A^T\(\)
Definite (resp. semidefinite) positive matrix All eigenvalue are 1. \(\)>0\(\) (resp \(\)\geq 0\(\)) or 2. \(\)x^T A x > 0, \forall\ x \(\) (resp. \(\)x^T\ A\ x \geq 0\, \forall\ x\(\))
Definite (resp. seminegative) matrix All eigenvalue are 1. \(\)<0\(\) (resp. \(\)\leq 0\(\)) or 2. \(\)x^T\ A\ x < 0\ \forall\ x\(\) (resp. \(\)x^T\ A\ x \leq 0\, \forall\ x\(\))
Indefinite matrix There exists 1. positive and negative eigenvalue (Stokes, Helmholtz) or 2. there exists \(\)x,y\(\) such that \(\)x^TAx > 0 > y^T A y\(\)
Let \(\)A\(\) be a \(\)\mathbb{R}^{n\times n}\(\) matrix, \(\)x\(\) and \(\)b\(\) be \(\)\mathbb{R}^n\(\) vectors, we wish to solve \(\)A x = b.\(\)
Definition: A preconditioner \(\)\mathcal{P}\(\) is a method for constructing a matrix (just a linear function, not assembled!) \(\)P^{1} = \mathcal{P}(A,A_p)\(\) using a matrix \(\)A\(\) and extra information \(\)A_p\(\), such that the spectrum of \(\)P^{1}A\(\) (left preconditioning) or \(\)A P^{1}\(\) (right preconditioning) is wellbehaved. The action of preconditioning improves the conditioning of the previous linear system.
Left preconditioning: We solve for \(\) (P^{1} A) x = P^{1} b \(\) and we build the Krylov space \(\)\{ P^{1} b, (P^{1}A) P^{1} b, (P^{{1}A)}2 P^{1} b, \dots\}\(\)
Right preconditioning: We solve for \(\) (A P^{1}) P x = b \(\) and we build the Krylov space \(\)\{ b, (P^{1}A)b, (P^{{1}A)}2b, \dotsc \}\(\)
Note that the product \(\)P^{1}A\(\) or \(\)A P^{1}\(\) is never assembled.
Let us now describe some properties of preconditioners
\(\)P^{1}\(\) is dense, \(\)P\(\) is often not available and is not needed
\(\)A\(\) is rarely used by \(\)\mathcal{P}\(\), but \(\)A_p = A\(\) is common
\(\)A_p\(\) is often a sparse matrix, the \e preconditioning \e matrix
Here are some numerical methods to solve the system \(\)A x = b\(\)
Matrixbased: Jacobi, GaussSeidel, SOR, ILU(k), LU
Parallel: BlockJacobi, Schwarz, Multigrid, FETIDP, BDDC
Indefinite: Schurcomplement, Domain Decomposition, Multigrid
Split into lower, diagonal, upper parts: \(\) A = L + D + U \(\).
Cheapest preconditioner: \(\)P^{{1}=D}{1}\(\).
# sequential
pctype=jacobi
# parallel
pctype=block_jacobi
\(\) \left(L + \frac 1 \omega D\right) x_{n+1} = \left[\left(\frac 1\omega1\right)D  U\right] x_n + \omega b \\ P^{1} = \text{\(k\) iterations starting with \(x_0=0\)}\\ \(\)
Implemented as a sweep.
\(\)\omega = 1\(\) corresponds to GaussSeidel.
Very effective at removing highfrequency components of residual.
# sequential
pctype=sor
Two phases
symbolic factorization: find where fill occurs, only uses sparsity pattern.
numeric factorization: compute factors.
preconditioner.
Expensive, for \(\)m\times m\(\) sparse matrix with bandwidth \(\)b\(\), traditionally requires \(\)\mathcal{O}(mb^2)\(\) time and \(\)\mathcal{O}(mb)\(\) space.
Bandwidth scales as \(\)m^{\frac{d1}{d}}\(\) in \(\)d\(\)dimensions.
Optimal in 2D: \(\)\mathcal{O}(m \cdot \log m)\(\) space, \(\)\mathcal{O}(m^{3/2})\(\) time.
Optimal in 3D: \(\)\mathcal{O}(m^{4/3})\(\) space, \(\)\mathcal{O}(m^2)\(\) time.
Symbolic factorization is problematic in parallel.
Allow a limited number of levels of fill: ILU(\(\)k\(\)).
Only allow fill for entries that exceed threshold: ILUT.
Usually poor scaling in parallel.
No guarantees.
Domain size pass:[\(\)]Lpass:[\(\)], subdomain size pass:[\(\)]Hpass:[\(\)], element size pass:[\(\)]hpass:[\(\)]
Overlapping/Schwarz
Solve Dirichlet problems on overlapping subdomains.
No overlap: \(\)\textit{its} \in \mathcal{O}\big( \frac{L}{\sqrt{Hh}} \big)\(\).
Overlap \(\)\delta\(\): \(\)\textit{its} \in \big( \frac L {\sqrt{H\delta}} \big)\(\).
pctype=gasm # has a coarse grid preconditioner
pctype=asm
NeumannNeumann
Solve Neumann problems on nonoverlapping subdomains.
\(\)\textit{its} \in \mathcal{O}\big( \frac{L}{H}(1+\log\frac H h) \big)\(\).
Tricky null space issues (floating subdomains).
Need subdomain matrices, not globally assembled matrix.
Notes: Multilevel variants knock off the leading \(\)\frac L H\(\).
Both overlapping and nonoverlapping with this bound.
BDDC and FETIDP
Neumann problems on subdomains with coarse grid correction.
\(\)\textit{its} \in \mathcal{O}\big(1 + \log\frac H h \big)\(\).
Hierarchy: Interpolation and restriction operators \(\) \Pi^\uparrow : X_{\text{coarse}} \to X_{\text{fine}} \qquad \Pi^\downarrow : X_{\text{fine}} \to X_{\text{coarse}} \(\)
Geometric: define problem on multiple levels, use grid to compute hierarchy.
Algebraic: define problem only on finest level, use matrix structure to build hierarchy.
Galerkin approximation
Assemble this matrix: \(\)A_{\text{coarse}} = \Pi^\downarrow A_{\text{fine}} \Pi^\uparrow\(\)
Application of multigrid preconditioner (\(\) V \(\)cycle)
Apply presmoother on fine level (any preconditioner).
Restrict residual to coarse level with \(\)\Pi^\downarrow\(\).
Solve on coarse level \(\)A_{\text{coarse}} x = r\(\).
Interpolate result back to fine level with \(\)\Pi^\uparrow\(\).
Apply postsmoother on fine level (any preconditioner).
Textbook: \(\)P^{1}A\(\) is spectrally equivalent to identity
Constant number of iterations to converge up to discretization error.
Most theory applies to SPD systems
variable coefficients (e.g. discontinuous): low energy interpolants.
mesh and/or physicsinduced anisotropy: semicoarsening/line smoothers.
complex geometry: difficult to have meaningful coarse levels.
Deeper algorithmic difficulties
nonsymmetric (e.g. advection, shallow water, Euler).
indefinite (e.g. incompressible flow, Helmholtz).
Performance considerations
Aggressive coarsening is critical in parallel.
Most theory uses SOR smoothers, ILU often more robust.
Coarsest level usually solved semiredundantly with direct solver.
Multilevel Schwarz is essentially the same with different language
assume strong smoothers, emphasize aggressive coarsening.
See this PETSc page for a complete list.
PETSc 
Description 
Parallel 
none 
No preconditioner 
yes 
jacobi 
diagonal preconditioner 
yes 
bjacobi 
block diagonal preconditioner 
yes 
sor 
SOR preconditioner 
yes 
lu 
Direct solver as preconditioner 
depends on the factorization package (e.g.mumps,pastix: OK) 
shell 
User defined preconditioner 
depends on the user preconditioner 
mg 
multigrid prec 
yes 
ilu 
incomplete lu 

icc 
incomplete cholesky 

cholesky 
Cholesky factorisation 
yes 
asm 
Additive Schwarz Method 
yes 
gasm 
Scalable Additive Schwarz Method 
yes 
ksp 
Krylov subspace preconditioner 
yes 
fieldsplit 
block preconditioner framework 
yes 
lsc 
Least Square Commutator 
yes 
gamg 
Scalable Algebraic Multigrid 
yes 
hypre 
Hypre framework (multigrid…) 

bddc 
balancing domain decomposition by constraints preconditioner 
yes 
Feel++ abstracts the PETSc library and provides a subset (sufficient in most cases) to the PETSc features. It interfaces with the following PETSc libraries: Mat
, Vec
, KSP
, PC
, SNES.
Vec
Vector handling library
Mat
Matrix handling library
KSP
Krylov SubSpace library implements various iterative solvers
PC
Preconditioner library implements various preconditioning strategies
SNES
Nonlinear solver library implements various nonlinear solve strategies
All linear algebra are encapsulated within backends using the command line option backend=<backend>
or config file option backend=<backend>
which provide interface to several libraries
Library 
Format 
Backend 
PETSc 
sparse 

Eigen 
sparse 

Eigen 
dense 

The default backend
is petsc.
The configuration files .cfg
allow for a wide range of options to solve a linear or nonlinear system.
We consider now the following example [import:"marker1"](../../codes/mylaplacian.cpp)
To execute this example
# sequential
./feelpp_tut_laplacian
# parallel on 4 cores
mpirun np 4 ./feelpp_tut_laplacian
As described in section
cholesky
and lu
factorisation are available. However the parallel implementation depends on the availability of MUMPS. The configuration is very simple.
# no iterative solver
ksptype=preonly
#
pctype=cholesky
Using the PETSc backend allows to choose different packages to compute the factorization.
Package 
Description 
Parallel 

PETSc own implementation 
yes 

MUltifrontal Massively Parallel sparse direct Solver 
yes 

Unsymmetric MultiFrontal package 
no 

Parallel Sparse matriX package 
yes 
To choose between these factorization package
# choose mumps
pcfactormatsolverpackage=mumps
# choose umfpack (sequential)
pcfactormatsolverpackage=umfpack
In order to perform a cholesky type of factorisation, it is required to set the underlying matrix to be SPD.
// matrix
auto A = backend>newMatrix(_test=...,_trial=...,_properties=SPD);
// bilinear form
auto a = form2( _test=..., _trial=..., _properties=SPD );
with a relative tolerance of 1e12:
ksprtol=1.e12
ksptype=cg
pctype=icc
pcfactorlevels=3
with a relative tolerance of 1e12 and a restart of 300:
ksprtol=1.e12
ksptype=gmres
kspgmresrestart=300
pctype=ilu
pcfactorlevels=3
With a relative tolerance of 1e12 and a restart of 100:
ksprtol=1.e12
ksptype=gmres
kspgmresrestart 100
pctype=jacobi
# linear
ksp_monitor=1
# nonlinear
snesmonitor=1
# eigen value problem
epsmonitor=1
We start with the quickstart Laplacian example, recall that we wish to, given a domain \(\)\Omega\(\), find \(\)u\(\) such that
\(\) \nabla \cdot (k \nabla u) = f \mbox{ in } \Omega \subset \mathbb{R}^{2},\\ u = g \mbox{ on } \partial \Omega \(\)
feelpp_qs_laplacian kspmonitor=true
shell> mpirun np 2 feelpp_qs_laplacian kspmonitor=1 kspview=1
0 KSP Residual norm 8.953261456448e01
1 KSP Residual norm 7.204431786960e16
KSP Object: 2 MPI processes
type: gmres
GMRES: restart=30, using Classical (unmodified) GramSchmidt
Orthogonalization with no iterative refinement
GMRES: happy breakdown tolerance 1e30
maximum iterations=1000
tolerances: relative=1e13, absolute=1e50, divergence=100000
left preconditioning
using nonzero initial guess
using PRECONDITIONED norm type for convergence test
PC Object: 2 MPI processes
type: shell
Shell:
linear system matrix = precond matrix:
Matrix Object: 2 MPI processes
type: mpiaij
rows=525, cols=525
total: nonzeros=5727, allocated nonzeros=5727
total number of mallocs used during MatSetValues calls =0
not using Inode (on process 0) routines
You can now change the Krylov subspace solver using the ksptype
option and the preconditioner using pcptype
option.
For example,
to solve use the conjugate gradient,cg
, solver and the default preconditioner use the following
./feelpp_qs_laplacian ksptype=cg kspview=1 kspmonitor=1
to solve using the algebraic multigrid preconditioner, gamg
, with cg
as a solver use the following
./feelpp_qs_laplacian ksptype=cg kspview=1 kspmonitor=1 pctype=gamg
We now turn to the quickstart Stokes example, recall that we wish to, given a domain \(\)\Omega\(\), find \(\)(\mathbf{u},p) \(\) such that
This problem is indefinite. Possible solution strategies are
Uzawa,
penalty(techniques from optimisation),
augmented lagrangian approach (Glowinski,Le Tallec)
Note that The Infsup condition must be satisfied. In particular for a multigrid strategy, the smoother needs to preserve it.
The Krylov subspace solvers for indefinite problems are MINRES, GMRES. As to preconditioning, we look first at the saddle point matrix \(\)M\(\) and its block factorization \(\)M = LDL^T\(\), indeed we have :
Elman, Silvester and Wathen propose 3 preconditioners:
where \(\tilde{S} \approx S^{1} = B^T A^{1} B\) and \(\tilde{A}^{1} \approx A^{1}\)
Split into lower, diagonal, upper parts: \(A = L + D + U\).
Cheapest preconditioner: \(P^{1}=D^{1}\).
# sequential
pctype=jacobi
# parallel
pctype=block_jacobi
Implemented as a sweep.
\(\omega = 1\) corresponds to GaussSeidel.
Very effective at removing highfrequency components of residual.
# sequential
pctype=sor
Two phases
symbolic factorization: find where fill occurs, only uses sparsity pattern.
numeric factorization: compute factors.
preconditioner.
Expensive, for \(m\times m\) sparse matrix with bandwidth \(b\), traditionally requires \(\mathcal{O}(mb^2)\) time and \(\mathcal{O}(mb)\) space.
Bandwidth scales as \(m^{\frac{d1}{d}}\) in \(\)d\(\)dimensions.
Optimal in 2D: \(\mathcal{O}(m \cdot \log m)\) space, \(\mathcal{O}(m^{3/2})\) time.
Optimal in 3D: \(\mathcal{O}(m^{4/3})\) space, \(\mathcal{O}(m^2)\) time.
Symbolic factorization is problematic in parallel.
Allow a limited number of levels of fill: ILU(\(k\)).
Only allow fill for entries that exceed threshold: ILUT.
Usually poor scaling in parallel.
No guarantees.
Domain size pass:[\(\)]Lpass:[\(\)], subdomain size pass:[\(\)]Hpass:[\(\)], element size pass:[\(\)]hpass:[\(\)]
Overlapping/Schwarz
Solve Dirichlet problems on overlapping subdomains.
No overlap: \(\textit{its} \in \mathcal{O}\big( \frac{L}{\sqrt{Hh}} \big)\).
Overlap \(\delta: \textit{its} \in \big( \frac L {\sqrt{H\delta}} \big)\).
NeumannNeumann
Solve Neumann problems on nonoverlapping subdomains.
\(\textit{its} \in \mathcal{O}\big( \frac{L}{H}(1+\log\frac H h) \big)\).
Tricky null space issues (floating subdomains).
Need subdomain matrices, not globally assembled matrix.
Multilevel variants knock off the leading \(\frac L H\). Both overlapping and nonoverlapping with this bound. 
BDDC and FETIDP
Neumann problems on subdomains with coarse grid correction.
\(\textit{its} \in \mathcal{O}\big(1 + \log\frac H h \big)\).
Hierarchy: Interpolation and restriction operators \(\Pi^\uparrow : X_{\text{coarse}} \to X_{\text{fine}} \qquad \Pi^\downarrow : X_{\text{fine}} \to X_{\text{coarse}} \)
Geometric: define problem on multiple levels, use grid to compute hierarchy.
Algebraic: define problem only on finest level, use matrix structure to build hierarchy.
Galerkin approximation
Assemble this matrix: \(A_{\text{coarse}} = \Pi^\downarrow A_{\text{fine}} \Pi^\uparrow\)
Application of multigrid preconditioner (\(V\)cycle)
Apply presmoother on fine level (any preconditioner).
Restrict residual to coarse level with \(\Pi^\downarrow\).
Solve on coarse level \(A_{\text{coarse}} x = r\).
Interpolate result back to fine level with \(\)\Pi^\uparrow\(\).
Apply postsmoother on fine level (any preconditioner).
Textbook: \(P^{1}A\) is spectrally equivalent to identity
Constant number of iterations to converge up to discretization error.
Most theory applies to SPD systems
variable coefficients (e.g. discontinuous): low energy interpolants.
mesh and/or physicsinduced anisotropy: semicoarsening/line smoothers.
complex geometry: difficult to have meaningful coarse levels.
Deeper algorithmic difficulties
nonsymmetric (e.g. advection, shallow water, Euler).
indefinite (e.g. incompressible flow, Helmholtz).
Performance considerations
Aggressive coarsening is critical in parallel.
Most theory uses SOR smoothers, ILU often more robust.
Coarsest level usually solved semiredundantly with direct solver.
Multilevel Schwarz is essentially the same with different language
assume strong smoothers, emphasize aggressive coarsening.
See this PETSc page for a complete list.
PETSc 
Description 
Parallel 
none 
No preconditioner 
yes 
jacobi 
diagonal preconditioner 
yes 
bjacobi 
block diagonal preconditioner 
yes 
sor 
SOR preconditioner 
yes 
lu 
Direct solver as preconditioner 
depends on the factorization package (e.g.mumps,pastix: OK) 
shell 
User defined preconditioner 
depends on the user preconditioner 
mg 
multigrid prec 
yes 
ilu 
incomplete lu 

icc 
incomplete cholesky 

cholesky 
Cholesky factorisation 
yes 
asm 
Additive Schwarz Method 
yes 
gasm 
Scalable Additive Schwarz Method 
yes 
ksp 
Krylov subspace preconditioner 
yes 
fieldsplit 
block preconditioner framework 
yes 
lsc 
Least Square Commutator 
yes 
gamg 
Scalable Algebraic Multigrid 
yes 
hypre 
Hypre framework (multigrid…) 

bddc 
balancing domain decomposition by constraints preconditioner 
yes 
NonLinear algebra backends are crucial components of Feel++. They provide a uniform interface between Feel++ data structures and underlying the linear algebra libraries used by Feel++.
Feel++ interfaces the following libraries:
PETSc : Portable, Extensible Toolkit for Scientific Computation
SLEPc : Eigen value solver framework based on PETSc
Eigen3
Backend is a template class parametrized by the numerical type providing access to
vector
matrix : dense and sparse
algorithms : solvers, preconditioners, …
PETSc provides sequential and parallel data structures whereas Eigen3 is only sequential.
To create a Backend, use the free function backend(…)
which has the following interface:
backend(_name="name_of_backend",
_rebuild=... /// truefalse,
_kind=..., // type of backend,
_worldcomm=... // communicator
)
All these parameters are optional which means that the simplest call reads for example:
auto b = backend();
They take default values as described in the following table:
parameter 
type 
default value 

string 
"" (empty string ) 

boolean 
false 

string 
"petsc" 

WorldComm 
Environment::worldComm() 
Backends are store in a Backend factory and handled by a manager that
allows to keep track of allocated backends. They a registered with
respect to their name and kind. The default name value is en empty
string (""
) which names the default Backend. The _name parameter is
important because it provides also the name for the command
line/config file option section associated to the associated Backend.
Only the command line/config file options for the default backend are registered. Developers have to register the option for each new Backend they define otherwise failures at runtime are to be expected whenever a Backend command line option is accessed.
Consider that you create a Backend name projection
in your code like
this
auto b = backend(_name="projection");
to register the command line options of this Backend
Environment env( _argc=argc, _argv=argv,
_desc=backend_options("projection") );
Feel++ supports three kind of Backends:
petsc : PETSC Backend
eigen_dense
eigen_sparse
SLEPc uses the PETSc Backend since it is based on PETSc. 
The kind of Backend can be changed from the command line or configuration file thanks to the "backend" option.
auto b = backend(_name="name",
_kind=soption(_prefix="name",_name="backend"))
and in the config file
[name]
backend=petsc
backend=eigen_sparse
If you want to reuse a Backend and not allocate a new one plus add the corresponding option to the command line/configuration file, you can rebuild the Backend in order to delete the data structures already associated to this Backend and in particular the preconditioner. It is mandatory to do that when you solve say a linear system first with dimensions \(m\times m\) and then solve another one with different dimension \(n \times n\) because in that case the Backend will throw an error saying that the dimensions are incompatible. To avoid that you have to rebuild the Backend.
auto b = backend(_name="mybackend");
// solve A x = f
b>solve(_solution=x,_matrix=A,_rhs=f);
// rebuild: clean up the internal Backend data structure
b = backend(_name="mybackend",_rebuild=true);
// solve A1 x1 = f1
b>solve(_solution=x1,_matrix=A1,_rhs=f1);
Although this feature might appear useful, you have to make sure that the solving strategy applies to all problems because you won’t be able to customize the solver/preconditioner for each problem. If you have different problems to solve and need to have custom solver/preconditioner it would be best to have different Backends. 
One of the strength of Feel++ is to be able to change the communicator and in the case of Feel++ the WorldComm. This allows for example to
solve sequential problems
solve a problem on a subset of MPI processes
For example passing a sequential WorldComm to backend()
would then in the subsequent use of the Backend generate sequential data structures (e.g. IndexSet, Vector and Matrix) and algorithms (e.g. Krylov Solvers).
// create a sequential Backend
auto b = backend(_name="seq",
_worldComm=Environment::worldCommSeq());
auto A = b>newMatrix(); // sequential Matrix
auto f = b>newVector(); // sequential Vector
Info The default WorldComm is provided by
Environment::worldComm()
and it conresponds to the default MPI communicatorMPI_COMM_WORLD
.
To solve standard and generalized eigenvalue problems, Feel++ interfaces SLEPc. SLEPc is a library which extends PETSc to provide the functionality necessary for the solution of eigenvalue problems. It comes with many strategies for both standard and generalized problems, Hermitian or not.
We want to find \((\lambda_i,x_i)\) such that \(Ax = \lambda x\). To do that, most eigensolvers project the problem onto a lowdimensional subspace, this is called a RayleighRitz projection. + Let \(V_j=[v_1,v_2,...,v_j\)] be an orthogonal basis of this subspace, then the projected problem reads:
Find \((\theta_i,s_i)\) for \(i=1,\ldots,j\) such that \(B_j s_i=\theta_i s_i\) where \(B_j=V_j^T A V_j\).
Then the approximate eigenpairs \((\lambda_i,x_i)\) of the original problem are obtained as: \(\lambda_i=\theta_i\) and \(x_i=V_j s_i\).
The eigensolvers differ from each other in the way the subspace is built.
In Feel++, there is two functions that can be used to solve this type
of problems, eigs
and veigs
.
Here is an example of how to use veigs
.
auto Vh = Pch<Order>( mesh );
auto a = form2( _test=Vh, _trial=Vh );
// fill a
auto b = form2( _test=Vh, _trial=Vh );
// fill b
auto eigenmodes = veigs( _formA=a, _formB=b );
where eigenmodes
is a std::vector<std::pair<value_type,
element_type> >
with value_type
the type of the eigenvalue, and
element_type
the type of the eigenvector, a function of the space
Vh
.
The eigs
function does not take the bilinear forms but two
matrices. Also, the solver used, the type of the problem, the position
of the spectrum and the spectral transformation are not read from the
options.
auto Vh = Pch<Order>( mesh );
auto a = form2( _test=Vh, _trial=Vh );
// fill a
auto matA = a.matrixPtr();
auto b = form2( _test=Vh, _trial=Vh );
// fill b
auto matB = b.matrixPtr();
auto eigenmodes = eigs( _matrixA=aHat,
_matrixB=bHat,
_solver=(EigenSolverType)EigenMap[soption("solvereigen.solver")],
_problem=(EigenProblemType)EigenMap[soption("solvereigen.problem")],
_transform=(SpectralTransformType)EigenMap[soption("solvereigen.transform")],
_spectrum=(PositionOfSpectrum)EigenMap[soption("solvereigen.spectrum")]
);
auto femodes = std::vector<decltype(Vh>element())>( eigenmodes.size(), Vh>element() );
int i = 0;
for( auto const& mode : modes )
femodes[i++] = *mode.second.get<2>();
where eigenmodes
is a std::map<real_type, eigenmodes_type>
with
real_type
of the magnitude of the eigenvalue. And eigenmodes_type
is a boost::tuple<real_type, real_type, vector_ptrtype>
with the
first real_type
representing the real part of the eigenvalue, the
second real_type
the imaginary part and the vector_ptrtype
is a
vector but not an element of a functionspace.
The two functions take a parameter _nev
that tel how many eigenpair
to compute. This can be set from the command line option
solvereigen.nev
. + Another important parameter is _ncv
which is
the size of the subspace, j
above. This parameter should always be
greater than nev
. SLEPc recommends to set it to max(nev+15,
2*nev)
. This can be set from the command line option
solvereigen.ncv
.
The standard formulation reads :
Find \(\lambda\in \mathbb{R}\) such that \(Ax = \lambda x\)
where \(\lambda\) is an eigenvalue and \(x\) an eigenvector.
But in the case of the finite element method, we will deal with the generalized form :
Find \(\lambda\in\mathbb{R}\) such that \(Ax = \lambda Bx\)
A standard problem is Hermitian if the matrix \(\)A\(\) is Hermitian (\(A=A^*\)). + A generalized problem is Hermitian if the matrices \(A\) and \(B\) are Hermitian and if \(B\) is positive definite. + If the problem is Hermitian, then the eigenvalues are real. A special case of the generalized problem is when the matrices are not Hermitian but \(B\) is positive definite.
The type of the problem can be specified using the EigenProblemType,
or at run time with the command line option solvereigen.problem
and the following value :
Problem type  EigenProblemType  command line key 

Standard Hermitian 
HEP 
"hep" 
Standard nonHermitian 
NHEP 
"nhep" 
Generalized Hermitian 
GHEP 
"ghep" 
Generalized nonHermitian 
GNHEP 
"gnhep" 
Positive definite Generalized nonHermitian 
PGNHEP 
"pgnhep" 
You can choose which eigenpairs will be computed. The user can set it
programmatically with PositionOfSpectrum
or at run time with the
command line option solvereigen.spectrum
and the following value :
Position of spectrum  PositionOfSpectrum  command line key 

Largest magnitude 
LARGEST_MAGNITUDE 
"largest_magnitude" 
Smallest magnitude 
SMALLEST_MAGNITUDE 
"smallest_magnitude" 
Largest real 
LARGEST_REAL 
"largest_real" 
Smallest real 
SMALLEST_REAL 
"smallest_real" 
Largest imaginary 
LARGEST_IMAGINARY 
"largest_imaginary" 
Smallest imaginary 
SMALLEST_IMAGINARY 
"smallest_imaginary" 
It is observed that the algorithms used to solve the eigenvalue problems find solutions at the extremities of the spectrum. To improve the convergence, one need to compute the eigenpairs of a transformed operator. Those spectral transformations allow to compute solutions that are not on the boundary of the spectrum.
There are 3 types of spectral transformation:
\(A\sigma I\) or \(B^{1}A\sigma I\)
\((A\sigma I)^{1}\) or \((A\sigma B)^{1}B\)
\((A\sigma I)^{1}(A+\nu I)\) or \((A\sigma B)^{1}(A+\nu B)\)
By default, shift and invert is used. You can change it with
solvereigen.transform
.
Spectral transformation  SpectralTransformationType  command line key 

Shift 
SHIFT 
shift 
Shift and invert 
SINVERT 
shift_invert 
Cayley 
CAYLEY 
cayley 
The details of the implementation of the different solvers can be found in the SLEPc Technical Reports.
The default solver is KrylovSchur, but can be modified using
EigenSolverType
or the option solvereigen.solver
.
Solver  EigenSolverType  command line key 

Power 
POWER 
power 
Lapack 
LAPACK 
lapack 
Subspace 
SUBSPACE 
subspace 
Arnoldi 
Arnoldi 
arnoldi 
Lanczos 
LANCZOS 
lanczos 
KrylovSchur 
KRYLOVSCHUR 
krylovschur 
Arpack 
ARPACK 
arpack 
Be careful that all solvers can not compute all the problem types and positions of the spectrum. The possibilities are summarize in the following table.
Solver  Position of spectrum  Problem type 

Power 
Largest magnitude 
any 
Lapack 
any 
any 
Subspace 
Largest magnitude 
any 
Arnoldi 
any 
any 
Lanczos 
any 
standard and generalized Hermitian 
KrylovSchur 
any 
any 
Arpack 
any 
any 
In the case where you want compute a large number of eigenpairs, the
rule for ncv
implies a huge amount of memory to be used. To improve
the performance, you can set the mpd
parameter, which will limit the
dimension of the projected problem.
You can set it via the command line with solvereigen.mpd <mpd>
.
If you want to compute all the eigenpairs in a given interval, you
need to use the option solvereigen.intervala
to set the beginning
of the interval and solvereigen.intervalb
to set the end.
In this case, be aware that the problem need to be generalized and
hermitian. The solver will be set to KrylovSchur and the
transformation to shift and invert. Beside, you’ll need to use a
linear solver that will compute the inertia of the matrix, this is set
to Cholesky, with mumps if you can use it. + For now, this method is
only implemented in the eigs
function.
For performance reasons and allow fast checkpoint restart of simulations, we have develop our own mesh and data file format in parallel.
Format 
Description 
Mode 
Type 

Feel++ parallel file format 
Read/Write 
Metadata & Binary 
The format is decomposed into two files : (i) a json file (.json
file extension) which contain some metadata information on the mesh and (ii) a hdf5 file (.h5
file extension) which contains the mesh data structure.
Feel++ supports various file formats that can be used as input mesh file formats.
Format 
Description 
Mode 
Type 

Acusim(ALTAIR) mesh file format 
Read 
Ascii 

Gmsh mesh file format 
Read/Write 
Ascii/Binary 

Feel++ parallel file format 
Read/Write 
Metadata & Binary 

MED(Salome) mesh file format 
Read/Write 
Ascii/Binary 

MEDIT(INRIA) mesh file format 
Read/Write 
Ascii 
Feel++ supports various file formats that can be used as output mesh and data file formats for postprocessing.
Format 
Description 
Mode 
Type 

Gmsh mesh file format 
Read/Write 
Ascii/Binary 

Ensight Gold case format 
Write 
Binary 

H3D file format 
Read 
Database 

XML/HDF5 file format 
Write 

The H3D file format requires that you have the Altair Hypermesh software installed. 
Copyright © 20102017 by Feel++ Consortium
Copyright © 20052015 by Université Joseph Fourier (Grenoble, France)
Copyright © 20052015 by University of Coimbra (Portugal)
Copyright © 20112015 by Université de Strasbourg (France)
Copyright © 20112015 by CNRS (France)
Copyright © 20052006 by Ecole Polytechnique Fédérale de Lausanne (EPFL, Switzerland)
Free use of this software is granted under the terms of the L License.
See the LICENSE file for details
Feel++ is actively developed by Christophe Prud’homme, Vincent Chabannes, Christophe Trophime, Cécile Daversin, Thibaut Métivet, Guillaume Dollé, JeanBaptiste Wahl, Romain Hild, Lorenzo Sala, and Thomas Lantz.
There are many other contributors.
Feel++ is currently managed by Christophe Prud’homme, Professor in applied mathematic and scientific computing at the University of Strasbourg, France.
Feel++ has been funded by various sources and especially
Feel++ benefits from the many discussions and close research collaborations with the following persons: Mourad Ismail, Zakaria Belhachmi, Silvia Bertoluzza, Micol Pennacchio, Marcela Szopos, Giovanna Guidoboni, Riccardo Sacco, Gonçalo Pena.
Finally Feel++ also benefits from discussions within collaborative projects with many people (in no particular order):
Yannick Hoarau, Philippe Gilotte, Benjamin Surowiec, Yoann Eulalie, Stephie Edwige, Marion Spreng, Benjamin Vanthong, Thomas Lantz, Mamadou Camara, Camille Boulard, Pierre Gerhard, Frédéric Hecht, Michel Fouquembergh, Denis Barbier, JeanMarc Gratien, Daniele Di Pietro.
Feel++ was initially developed at École Polytechnique Fédérale de Lausanne(Suisse) and is now a joint effort between Université de Strasbourg, Université GrenobleAlpes, CNRS, LNCMI and Cemosis.
Unresolved directive in book.adoc  include::GLOSSARY.adoc[]