FreeFEM Documentation on GitHub

stars - forks

Language references

In essence FreeFEM is a compiler: its language is typed, polymorphic, with exception and reentrant. Every variable must be declared of a certain type, in a declarative statement; each statement are separated from the next by a semicolon ;.

The language allows the manipulation of basic types integers (int), reals (real), strings (string), arrays (example: real[int]), bi-dimensional (2D) finite element meshes (mesh), 2D finite element spaces (fespace), analytical functions (func), arrays of finite element functions (func[basic_type]), linear and bilinear operators, sparse matrices, vectors , etc. For example:

1 int i, n = 20; //i, n are integer
2 real[int] xx(n), yy(n); //two array of size n
3 for (i = 0; i < 20; i++){ //which can be used in statements such as
4     xx[i] = cos(i*pi/10);
5     yy[i] = sin(i*pi/10);
6 }

The life of a variable is the current block {...}, except the fespace variable, and the variables local to a block are destroyed at the end of the block as follows.

Tip

Example

 1 real r = 0.01;
 2 mesh Th = square(10, 10); //unit square mesh
 3 fespace Vh(Th, P1); //P1 Lagrange finite element space
 4 Vh u = x + exp(y);
 5 func f = z*x + r*log(y);
 6 plot(u, wait=true);
 7 { // new block
 8     real r = 2; //not the same r
 9     fespace Vh(Th, P1); //error because Vh is a global name
10 }// end of block
11 //here r back to 0.01

The type declarations are mandatory in FreeFEM; in the end this feature is an asset because it is easy to make bugs in a language with many implicit types.

The variable name is just an alphanumeric string, the underscore character _ is not allowed, because it will be used as an operator in the future.

Table of content