Skip to content

Home

Welcome to the FreeFem++ language reference documentation.

Your contribution is needed, please check the TODO page.

Introduction#

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

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.

Example

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