HAL Id: hal-01476313
https://hal.sorbonne-universite.fr/hal-01476313
Submitted on 15 Jun 2017
HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entic research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.
L’archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diusion de documents
scientiques de niveau recherche, publiés ou non,
émanant des établissements d’enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.
New development in freefem++
Frédéric Hecht
To cite this version:
Frédéric Hecht. New development in freefem++. Journal of Numerical Mathematics, De Gruyter,
2012, 20 (3-4), pp.1-14. �10.1515/jnum-2012-0013�. �hal-01476313�
J. Numer. Math., Vol. 0, No. 0, pp. 1–14 (2013)
DOI 10.1515/ JNUM.2013.000
Prepared using jnm.sty [Version: 20.02.2007 v1.3]
New Developments in FreeFem++
F. HECHT
∗
Received May 30, 2012 Communicated by Yu. A. Kuznetsov
Received in revised form March 1, 2012
Abstract — This is a short presentation to the capability of the freefem++ software, in section 1, we
recall most of the characteristics of the software, In section 2, we recall how to to build a weak form
form of an partial differential equation (PDE) from the strong form of the PDE. In three last sections,
we present different problem, tools to illustrated the software. First we do mesh adaptation problem in
two and three dimension,, secondly, we solve numerically a Phase change with Natural Convection,
and the finally to show the HPC possibility we show a Schwarz Domain Decomposition problem on
parallel computer.
Keywords: Finite Element
1. Introduction
This paper intends to give a small presentation of the software FreeFem++ .
A partial differential equation is a relation between a function of several vari-
ables and its (partial) derivatives. Many problems in physics, engineering, mathem-
atics and even banking are modeled by one or several partial differential equations.
FreeFem++ is a software to solve these equations numerically in dimensions
two or three. As its name implies, it is a free software based on the Finite Ele-
ment Method; it is not a package, it is an integrated product with its own high
level programming language; it runs on most UNIX, WINDOWS and MacOs
computers. Moreover FreeFem++ is highly adaptive. Many phenomena involve
several coupled systems, for example: fluid-structure interactions, Lorentz forces
for aluminum casting and ocean-atmosphere coupling. Multiphysics problems re-
quire different finite element approximations or different polynomial degrees, pos-
sibly on different meshes. Some algorithms like Schwarz’ domain decomposition
method also require data interpolation on multiple meshes within one program.
FreeFem++ can handle these difficulties, i.e. arbitrary finite element spaces on
arbitrary unstructured and adapted meshes.
∗
UPMC, Univ. Paris 06, UMR 7598, F-75005 Paris, France. E-mail: frederic.hecht@upmc.fr
This work was partially supported by ANR grant No. 01-2345-6789.
2 F. Hecht
The characteristics of FreeFem++ are:
• Problem description (real or complex valued) by their variational formula-
tions, with access to the internal vectors and matrices if needed.
• Multi-variables, multi-equations, bi-dimensional and three-dimensional static
or time dependent, linear or nonlinear coupled systems; however the user is
required to describe the iterative procedures which reduce the problem to a
set of linear problems.
• Easy geometric input by analytic description of boundaries by pieces; how-
ever this part is not a CAD system; for instance when two boundaries inter-
sect, the user must specify the intersection points.
• Automatic mesh generator, based on the Delaunay-Voronoi algorithm; the
inner point density is proportional to the density of points on the boundaries
[17].
• Metric-based anisotropic mesh adaptation. The metric can be computed auto-
matically from the Hessian of any FreeFem++ function [20].
• High level user friendly typed input language with an algebra of analytic or
finite element functions.
• Multiple finite element meshes within one application with automatic inter-
polation of data on different meshes and possible storage of the interpolation
matrices.
• A large variety of triangular finite elements : linear, quadratic Lagrangian
elements and more, discontinuous P1 and Raviart-Thomas elements, elements
of a non-scalar type, the mini-element,. . . but no quadrangles.
• Tools to define discontinuous Galerkin finite element formulations P0, P1dc,
P2dc and keywords: jump, mean, intalledges.
• A large variety of linear direct and iterative solvers (LU, Cholesky, Crout,
CG, GMRES, UMFPACK [13], MUMPS [2], SuperLU, ...) and eigenvalue
and eigenvector solvers (ARPARK) [24],and Optimatiztion tools like Ipopt
[33]
• Near optimal execution speed (compared with compiled C++ implementa-
tions programmed directly).
• Online graphics, generation of ,.txt,.eps,.gnu, mesh files for fur-
ther manipulations of input and output data.
• Many examples and tutorials: elliptic, parabolic and hyperbolic problems,
Navier-Stokes flows, elasticity, Fluid structure interactions, Schwarz’s do-
main decomposition method, eigenvalue problem, residual error indicator, ...
FreeFem++ 3
• A parallel version using mpi
2. Weak formulation
For the first example consider a Poisson problem on a Domain Ω with a partition of
the boundary ∂ Ω in Γ
2
,Γ
e
: Find u such that:
− ∆u = 1 in Ω, u = 2 on Γ
2
,
∂ u
∂~n
= 0 on Γ
e
(2.1)
Denote V
g
= {v ∈ H
1
(Ω)/v
|Γ
2
= g}, and the weak form of the equation is obtained
by multiplying by v and integrating by parts (2.1). The variational formulation is:
find u ∈ V
2
(Ω) , such that
∀v ∈ V
0
(Ω),
Z
Ω
∇u.∇v =
Z
Ω
1v+
Z
Γ
∂ u
∂ n
v, (2.2)
Note that due to
∂ u
∂~n
= 0 on Γ
2
and v = 0 the term
R
Γ
∂ u
∂ n
v disappears on Γ
2
. Finally
the finite method simply replaces V
g
with a finite element space, such as
V
gh
= {v
h
∈ C
0
(
¯
Ω) : ∀K ∈ T
h
,v
h
|
K
∈ P
1
and v
h
|
Γ
2
= 0}
in the case of linear elements; for full detail see [10,21].
Below, we give an example of an elaborate mesh for a 3d fish and the Poisson
problem; the FreeFem++ code is below and the results are on Figures 1&2
load "msh3" load "medit" load "tetgen"
mesh3 Ths("Y5177_Fish_cut.mesh"); // read skin fish mesh ..
real hh = 10; // the final mesh size
real[int] domaine = [0,0,0,1,hhˆ3/6.];
mesh3 Th=tetg(Ths,switch="pqaAYY",regionlist=domaine);
fespace Xh(Th,P2);
real x0=-200,y0=0,z0=0;
func ball = sqrt((x-x0)ˆ2+(y-y0)ˆ2+(z-z0)ˆ2) <30;
macro Grad(u) [dx(u),dy(u),dz(u)] // EOM
Xh p,q;
solve laplace(p,q,solver=CG) =
int3d(Th)( ball
*
p
*
q+Grad(p)’
*
Grad(q) )
- int3d(Th) ( 1
*
q) ;
plot(p,fill=1,wait=1,value=0,nbiso=50); // see figure 1
The skin mesh of the 3d fish come from the url
∗
. And the graphics solution of the
problem is 2d and 3d is display figure 2 and 1 respectively.
∗
http://www-roc.inria.fr/gamma/download/counter.php?dir=FISH/
&get_obj=Y5177_Fish_cut.mesh&acces=Y5177_Fish
4 F. Hecht
Figure 1. 3d Poisson solution iso-surface Figure 2. 2d Poisson solution iso-value
3. Mesh adaptation
In FreeFem++ a lot of adaptation tools are implemented; this corresponding to the
work of many people [20,17,26,25,32,19,29,9,6].
All these tools are based a Delaunay-Voronoi algorithm with a distance (or Met-
ric) between two points q
1
,q
2
given by
p
t
(q
1
− q
2
)M (q
1
− q
2
) where the matrix
M is symmetric positive definite matrix field defined on the mesh T
h
. Consequently
the length `
M
of a curve γ for ]0,1[∈ R
d
with respect to M is
`
M
=
Z
1
0
p
t
γ
0
(t)M (γ(t))γ
0
(t)dt (3.1)
The computation of M can be implicit of explicit; the tools to compute M , in
isotropic cases are scalar fields h which represent the local mesh size such that
M =
1
h
2
I
d
, where I
d
is the identity matrix.
The idea is to build a meshes with edges of equal length with respect of M , i.e.
the length with respect to M of all the mesh edges should be closed to one so as
to get an equi-repartion of the error close to err in norm L
∞
. So for P
1
continuous
finites elements, The metric can be defined by:
`
M
=
1
err
|∂
2
h
u
h
| (3.2)
where |∂
2
h
u
h
| =
q
(∂
2
h
u
h
)
2
and ∂
2
h
u is an approximation of the Hessian matrix of
u
h
. FreeFem++ does it automatically by default with adaptmesh function (2d) ,
MetricPk (2d) , or with mshmet (2d) .
An example of L
∞
error mesh adaptation with metric for the Poisson problem in
an L-shape domain Ω =]0,1[
2
\[1/2,1[
2
. Find u ∈ H
1
(Ω) such that
− ∆u = (x − y) in Ω,
∂ u
∂ n
n
n
= 0 on ∂Ω;
Z
Ω
u = 0 (3.3)