with finite element basis functions ϕk(x,y) and numbers wk (k = 0,,M -1). The functions ϕk(x,y) is constructed
from the triangle Tik, so ϕk(x,y) is a shape function. The finite element space
or with ℓ pairs of periodic boundary condition in 2d
and in 3d
where IDspaceis the name of the space (e.g. Vh), IDmeshis the name of the associated mesh and <IDFE>is a identifier of finite element type.
In 2d case, a pair of periodic boundary condition, if [lai,sai],[lbi,sbi]is a pair of int, the 2 labels lai and lbi define the 2 piece of boundary to be in equivalence; If [lai,sai],[lbi,sbi]is a pair of real, then sai and sbi give two common abscissa on the two boundary curve, and two points are identified as one if the two abscissa are equal.
In 2d case, a pair of periodic boundary condition, if [lai,sai,tai],[lbi,sbi,tbi]is a pair of int, the 2 labels lai and lbi define the 2 piece of boundary to be in equivalence;
If [lai,sai,tai],[lbi,sbi,tbi]is a pair of real, then sai,tai and sbi,tbi give two common parameter on the two boundary surface, and two points are identified as one if the two parameter are equal.
Remark, the 2d mesh of the two identified border must be the same, so to be sure, used the parameter fixeborder=truein buildmeshcommand (see 5.1.2) like in example periodic2bis.edp(see 9.7).
As of today, the known types of finite element are:
![]() | (6.3) |
![]() | (6.4) |
where λiK,i = 0,1,2 are the 3 area coordinate functions of the triangle K
![]() | (6.5) |
where P2 is the set of polynomials of 2 of degrees ≤ 2.
![]() | (6.6) |
![]() | (6.7) |
![]() | (6.8) |
where by writing div w = ∂w1∕∂x + ∂w2∕∂y,w = (w1,w2),
If we get the finite element spaces
when h is a mesh 10 ×10 of the unit square ]0,1[2, we only write in FreeFem++ as follows:
where Xh,Mh,Rhexpresses finite element spaces (called FE spaces ) Xh,Mh,Rh, respectively. If
we want use FE-functions uh,vh Xh and ph,qh
Mh and Uh,Vh
Rh , we write in FreeFem++
The functions Uh,Vh have two components so we have
For each triangle Tk, the basis function ϕk in Vh(Th,P0)is given by
then for vertices qki,i = 1,2,3 in Fig. 6.1(a), fh is built as
For each vertex qi, the basis function ϕi in Vh(Th,P1)is given by
then
For each vertex or midpoint qi. the basis function ϕi in Vh(Th,P2)is given by
then
Refer to [23] for details; briefly, we now consider non-continuous approximations so we shall lose the property
then
Strictly speaking ∂ϕi∕∂x,∂ϕi∕∂y contain Dirac distribution ρδ∂Tk. The numerical calculations will automatically ignore them. In [23], there is a proof of the estimation
The basis functions ϕk have the following properties.
See Fig. 6.6 for the projection of f(x,y) = sin(πx) cos(πy) into Vh(Th,P1nc). See Fig. 6.6 for the projection of f(x,y) = sin(πx) cos(πy) into Vh(Th,P1nc).
For each triangle Tk
h, let λk1(x,y),λk2(x,y),λk3(x,y) be the area cordinate of the triangle (see Fig. 6.1), and
put
![]() | (6.9) |
called bubble function on Tk. The bubble function has the feature:
If we write
then
Functions from 2 to
N with N = 1 is called scalar function and called vector valued when N > 1. When N = 2
make the space
In the Raviart-Thomas finite element RT0h, the degree of freedom are the fluxes across edges e of the mesh, where
the flux of the function f : 2-→
2 is ∫
ef.ne, ne is the unit normal of edge e.
This implies a orientation of all the edges of the mesh, for example we can use the global numbering of the edge vertices and we just go from small to large numbers.
To compute the flux, we use a quadrature with one Gauss point, the middle point of the edge. Consider a triangle Tk with three vertices (a,b,c). Let denote the vertices numbers by ia,ib,ic, and define the three edge vectors e1,e2,e3 by sgn(ib -ic)(b -c), sgn(ic -ia)(c -a), sgn(ia -ib)(a -b),
We get three basis functions,
![]() | (6.10) |
where |Tk|is the area of the triangle Tk. If we write
then
Example 6.1
To get the value at a point x = 1,y = 2 of the FE function uh, or [Uxh,Uyh],one writes
To get the value of the array associated to the FE function uh, one writes
Note 6.1 For a none scalar finite element function [Uxh,Uyh]the two array Uxh[]and Uyh[]are the same array, because the degree of freedom can touch more than one component.
In practice one may discretize the variational equations by the Finite Element method. Then there will be one mesh
for Ω1 and another one for Ω2. The computation of integrals of products of functions defined on different
meshes is difficult. Quadrature formulae and interpolations from one mesh to another at quadrature
points are needed. We present below the interpolation operator which we have used and which is new,
to the best of our knowledge. Let h0 = ∪kTk0,
h1 = ∪kTk1 be two triangulations of a domain Ω.
Let
Let f V(
h0). The problem is to find g
V(
h1) such that
Algorithm
The method has 5 steps. First a quadtree is built containing all the vertices of mesh h0 such that in each terminal
cell there are at least one, and at most 4, vertices of
h0 .
For each q1, vertex of h1 do:
Two problems need to be solved:
Note 6.2 Step 3 requires an array of pointers such that each vertex points to one triangle of the triangulation.
Note 6.3 The operator = is the interpolation operator of FreeFem++ , The continuous finite functions are extended by continuity to the outside of the domain. Try the following example
Figure 6.12: Extension of a continuous FE-function
Figure 6.13: Extention of discontinuous FE-function
|
For FreeFem++ a problem must be given in variational form, so we need a bilinear form a(u,v) , a linear form ℓ(f,v), and possibly a boundary condition form must be added.
Note 6.4 When you want to formulate the problem and to solve it in the same time, you can use the keywork solve.
To present the principles of Variational Formulations or also called weak forms fr the PDEs, let us take a model problem : a Poisson equation with Dirichlet and Robin Boundary condition .
The problem is: Find u a real function defined on domain Ω of 2 such that
![]() | (6.11) |
where
Note 6.5 This problem, we can be a classical Neumann boundary condition if a is 0, and if Γd is empty. In this case the function is defined just by derivative, so this defined too a constant (if u is a solution then u + 1 is also a solution).
Let v a regular test function null on Γd , by integration par part we get
![]() | (6.12) |
where ∇v.∇u = +
, and where n is the unitary outside normal of ∂Ω.
Now we note that ν = -au + g on Γr and v = 0 on Γd and ∂Ω = Γd ∪Γn thus
The problem become:
Find u Vg = {v
H1(Ω)∕v = g on Γd}such that
![]() | (6.13) |
where V0 = {v H1(Ω)∕v = 0 on Γd}
The problem (6.13) is generally well posed if we do not have only Neumann boundary condition ( ie. Γd = ∅and a = 0).
Note 6.6 If we have only Neumann boundary condition, then solution is not unique and linear algebra tells us that
the right hand side must be orthogonal to the kernel of the operator. Here the problem is defined to a constant, and
since 1 V0 one way of writing the compatibility condition is: ∫
Ωfdω + ∫
Γbdγ and a way to fix the constant is to
solve for u
H1(Ω) such that:
![]() | (6.14) |
where ε is a small parameter ( ~ 10-10 ).
Remark that if the solution is of order then the compatibility condition is unsatisfied, otherwise we get the solution
such that ∫
Ωu = 0.
In FreeFem++, the problem (6.13) become
where This a mesh of the domain Ω, and gdand gnare respectively the boundary label of boundary Γd and Γn.
The parameters are FE functions real or complex, the number n of parameters is even (n = 2 *k), the k first function parameters are unknown, and the k last are test functions.
Note 6.7 If the functions are a part of vectoriel FE then you must give all the functions of the vectorial FE in the same order (see laplaceMixte problem for example).
Note 6.8 Don’t mix complex and real parameters FE function.
Bug: 1 The mixing of fespace with different periodic boundary condition is not implemented. So all the finite element spaces used for test or unknown functions in a problem, must have the same type of periodic boundary condition or no periodic boundary condition. No clean message is given and the result is impredictible, Sorry.
The parameters are:
The default solver is sparsesolver( it is equal to UMFPACKif not other sparce solver is defined) or is set to LUif no direct sparse solver is available. The storage mode of the matrix of the underlying linear system depends on the type of solver chosen; for LU the matrix is sky-line non symmetric, for Crout the matrix is sky-line symmetric, for Cholesky the matrix is sky-line symmetric positive definite, for CGthe matrix is sparse symmetric positive, and for GMRES, sparsesolver or UMFPACKthe matrix is just sparse.
Below vis the unknown function and wis the test function.
After the ”=” sign, one may find sums of:
Remark, that the name in the ”varf” of the unknow of test function is forgotten, we just used the order in argument list to recall name as in a C++ function, see note 6.12,
The meaning is for all degree of freedom i of this associated boundary, the diagonal term of the matrix aii = tgv with the terrible geant value tgv (=1030 by default) and the right hand side b[i] = ”(Πhg)[i]” × tgv, where the ”(Πhg)g[i]” is the boundary node value given by the interpolation of g.
Note 6.9
Important: it is not possible to write in the same integral the linear part and the bilinear part such as in int1d(Th)( K⋆v⋆w - f⋆w) .
Let D be a N-dimensional bounded domain. For an arbitrary polynomials f of degree r, if we can find particular
points j,j = 1,
,J in D and constants ωj such that
For a domain Ωh = ∑
k=1ntTk,h = {Tk}, we can calculate the integral over Γh = ∂Ωh by
L | (qfe=) | qforder= | point in [qiqj](= t) | ω ℓ | exact on Pk,k = |
1 | qf1pE | 2 | 1∕2 | |qiqj| | 1 |
2 | qf2pE | 3 | (1 ±![]() | |qiqj|∕2 | 3 |
3 | qf3pE | 6 | (1 ±![]() | (5∕18)|qiqj| | 5 |
1∕2 | (8∕18)|qiqj| | ||||
4 | qf4pE | 8 | (1 ±![]() | ![]() | 7 |
(1 ±![]() | ![]() | ||||
5 | qf5pE | 10 | (1 ±![]() | ![]() | 9 |
1∕2 | ![]() | ||||
(1 ±![]() | ![]() | ||||
2 | qf1pElump | 2 | -1 | |qiqj|∕2 | 1 |
+1 | |qiqj|∕2 | ||||
where |qiqj|is the length of segment qiqj. For a part Γ1 of Γh with the label “1”, we can calculate the integral over Γ1 by
For each triangule Tk = [qk1qk2qk3] , the point P(x,y) in Tk is expressed by the area coordinate as P(ξ,η):
L | qft= | qforder= | point in Tk | ωℓ | degree of exact |
1 | qf1pT | 2 | ![]() | |Tk| | 1 |
3 | qf2pT | 3 | ![]() | |Tk|∕3 | 2 |
![]() | |Tk|∕3 | ||||
![]() | |Tk|∕3 | ||||
7 | qf5pT | 6 | ![]() | 0.225|Tk| | 5 |
![]() | ![]() | ||||
![]() | ![]() | ||||
![]() | ![]() | ||||
![]() | ![]() | ||||
![]() | ![]() | ||||
![]() | ![]() | ||||
3 | qf1pTlump | ![]() | |Tk|∕3 | 1 | |
![]() | |Tk|∕3 | ||||
![]() | |Tk|∕3 | ||||
9 | qf2pT4P1 | ![]() | |Tk|∕12 | 1 | |
![]() | |Tk|∕12 | ||||
![]() | |Tk|∕12 | ||||
![]() | |Tk|∕12 | ||||
![]() | |Tk|∕12 | ||||
![]() | |Tk|∕12 | ||||
![]() | |Tk|∕6 | ||||
![]() | |Tk|∕6 | ||||
![]() | |Tk|∕6 | ||||
15 | qf7pT | 8 | see [38] for detail | 7 | |
21 | qf9pT | 10 | see [38] for detail | 9 | |
Note 6.10 By default, we use the formula which is exact for polynomes of degrees 5 on triangles or edges (in bold in two tables).
First, it is possible to define variational forms, and use this forms to build matrix and vector to make very fast script (4 times faster here).
For example solve the Thermal Conduction problem of section 3.4.
The variational formulation is in L2(0,T; H1(Ω)); we shall seek un satisfying
where V0 = {w H1(Ω)∕w|Γ24 = 0}.
So the to code the method with the matrices A = (Aij), M = (Mij), and the vectors un,bn,b′,b”,bcl ( notation if w is a vector then wi is a component of the vector).
![]() | (6.17) |
Where with ν∞ = tgv = 1030 :
Create three variational formulation, and build the matrices A,M.
Now, to build the right hand size we need 4 vectors.
Note 6.11 The boundary condition is implemented by penalization and vector bcn contains the contribution of the boundary condition u=1 , so to change the boundary condition, we have just to multiply the vector bc[] by the current value f of the new boundary condition term by term with the operator .⋆. Section 9.6.2 Examples++-tutorial/StokesUzawa.edp gives a real example of using all this features.
And the new version of the algorithm:
Note 6.12 The functions appearing in the variational form are formal; they must be declared but not necessarily defined, the only important think in the order in the parameter list, like in
To build matrix A from the bilinear part the the variational form a of type varfdo simply
The possible named parameter " [, ... ] "of the construction are
The default solver is GMRES. The storage mode of the matrix of the underlying linear system depends on the type of solver chosen; for LU the matrix is sky-line non symmetric, for Crout the matrix is sky-line symmetric, for Choleskythe matrix is sky-line symmetric positive definite, for CGthe matrix is sparse symmetric positive, and for GMRES, sparsesolver or UMFPACK the matrix is just sparse.
Note 6.13 The line of the matrix corresponding to the space Wh and the column of the matrix corresponding to the space Vh.
To build the dual vector b (of type real[int]) from the linear part of the variational form a do simply
A first example to compute the area of each triangle K of mesh Th, just do:
Effectively, the basic functions of space Nh, are the characteristic function of the element of Th, and the numbering is the numeration of the element, so by construction:
Now, we can use this to compute error indicator like in examples AdaptResidualErrorIndicator.edpin directory examples++-tutorial.
First to compute a continuous approximation to the function h ”density mesh size” of the mesh Th.
To compute error indicator for Poisson equation :
We add automatic expression optimization by default, if this optimization creates problems, it can be removed with the keyword optimizeas in the following example :
Remark, it is all possible to build interpolation matrix, like in the following example:
and after some operations on sparse matrices are available for example
This becomes possible to store the matrix of a linear interpolation operator from a finite element space Vh to Wh with interpolatefunction. Note that the continuous finite functions are extended by continuity to the outside of the domain.
The named parameter of function interpolateare:
Example 6.2 (mat_interpol.edp)
Here, we show how get the informations of a finite element space Wh(n,*), where “*” denotes P1, P2, P1nc, etc.
See the following for an example:
Example 6.3 (FE.edp)
and the output is: