Beruflich Dokumente
Kultur Dokumente
Outline
Introduction and history
Instructions
Structure of simple programs
Mesh generation
Definition of FE space
Definition of variational form of the problem
Solution
Result analysis
Examples
LSR, RB, Dic 2013
Intro (I)
FreeFem++ is the implementation of a language dedicated
to the Finite Element Method.
It enables to solve PDE relatively easily.
It is a free, open-source software package for 2-D / 3-D
finite element computations.
Platforms: Linux, Windows, MacOS X.
Written in C++, and much of the syntax is similar to that of
C++.
Authors: F. Hecht, O. Pironneau, A. Le Hyaric (Universite
Pierre et Marie Curie, Laboratoire Jacques-Louis Lions).
Intro (II)
The project evolved from MacFem, Pcfem, written in Pascal,
to C (FreeFem version 3.4), which already offered mesh
adaptation on a single mesh. A thorough rewriting in C++
led to FreeFem++.
FreeFem++ includes:
Mesh generation and input
A wide range of finite elements and the ability to add new
elements
A number of integrated linear solvers, including CG,
GMRES, UMFPACK
Visualization tools
LSR, RB, Dic 2013
Instructions
; at line end is always required
No ; means instruction continues in the following line
Comments:
//From now on, only this line is commented
/*
All what is written here is commented,
also in different lines
*/
Instructions: if statement
if (CONDITION1)
{BLOCK of calculations;}
else if (CONDITION2)
{BLOCK of calculations;}
else
{BLOCK of calculations;}
Boolean conditions:
(CONDITION1 && CONDITION2)
(CONDITION1 || CONDITION2)
Instructions: loops
For loops:
for (INITIALIZATION; CONDITION; CHANGE)
{ BLOCK of calculations;}
While loops:
while (CONDITION)
{ BLOCK of calculations or change of control variables;}
Instructions: input
To read from the screen:
cin>>variableName;
To read from a file
{
ifstream infile(''filename.dat''); //also .txt format is ok
infile>>variableName; //variableName[] if it is a FE space
variable
}
10
Instructions: output
To print to the screen:
cout<<Text=<<variableName<<endl;
To write to a file
{
ofstream outfile(''filename.dat''); //also .txt format is ok
outfile<<variableName1<< <<variableName2<<endl;
//variableName[] if it is a FE space variable
}
Use ofstream outfile(''filename'',append); if you want to add
lines to an already open file, e.g. inside a loop.
LSR, RB, Dic 2013
11
Instructions: plots
To produce 2D plots:
plot(TTT, fill=true, value=true, wait=true, eps=figname.eps");
12
2D integrals:
area=int2d(meshname)(1.0);
Tave=int2d(meshname)(T)/area;
RelErr= sqrt(int2d(meshname)((T-Told)^2))/
sqrt(int2d(meshname)(T^2));
13
kappa=k1*(region==region1)+k2*(region== region2);
//boolean instruction
plot(kappa, wait=1, value=1, fill=1); //plot to check
14
15
FreeFem++-cs
Bold black: all standard FreeFem++ keywords.
Blue: user-defined objects. User defined types are in bold face.
Character strings are in dark blue.
Green: macros and include files.
Bold red: spelling mistakes, syntax errors, undefined objects,
macros and include files containing errors.
Purple: comments.
Once you have a coherent program, you can run it just by clicking
on a button (no need to save it) and if FreeFem++ produces an
error the problematic line will be highlighted.
FreeFem++ script file extension: .edp
LSR, RB, Dic 2013
16
Notes
Any version of FreeFem++ does not crash if you do not use
bad instructions
Read carefully the error reporting printed in the command line!!!
The location and type of error is always correctly reported, for
common errors
FreeFem++ can also be run in background mode (no -cs interface)
17
Structure of FreeFem++
simple programs
1. Build a mesh
2. Declare the finite element space and test and trial
functions from that space
3. Write the variational forms / inner products involved in
the problem and construct the problem statement
4. Solve the problem
5. Analyze the results (plots, error calculations, etc.)
Lets try to build, step-by-step, the simple program
corresponding to the solution of Poisson equation on a simple
domain
LSR, RB, Dic 2013
18
Lets start!
19
we can simply
int n=10;
mesh Th=square(n,n);
Or (more flexible):
int n=10, m=10;
real x0=0.0, x1=1.0;
real y0=0.0, y1=1.0;
mesh Th=square(n, m, [x0+(x1x0)x, y0+(y1y0)y]);
20
21
!
Refinement of the mesh is done by increasing the number
of points on the boundary (inner vertices are determined
by the density of the points on boundaries)
Mesh adaptation adaptmesh
LSR, RB, Dic 2013
22
23
24
25
BC (no BCadiabatic)
LSR, RB, Dic 2013
26
27
5. Analyze results:
Mesh refinement
N=10
N=100
N=1000
28
Example 1
29
Example 2
30
Example 3
31
Example 4
32
Example 5
33
Additional infos
Softare official website (for free download):
http://www.freefem.org/
http://www.ljll.math.upmc.fr/lehyaric/ffcs/install.php (for
the GUI installation)
Download the full user manual from:
http://www.freefem.org/ff++/ftp/freefem++doc.pdf
Find the full user manual in the FreeFem++ installation
directory:
MainDisk:\FreeFem++\freefem++doc.pdf
LSR, RB, Dic 2013
34