Finite element method overview
FreeFEM++
FreeFEM++ Helmholtz problem
Consider the partial differential equation in domain , . Examples:
Laplace equation ,
Poisson equation ,
Helmholtz equation ,
Discretize into finite elements, typically simplicia (i.e., triangles in 2D, tetrahedra in 3D)
Introduce a piecewise approximation , where are called form functions, and are nodal values within element . The overall approximation whose restriction on each element is , is an element of an appropriate Sobolev space (intuitively a characterization of smoothness of the function and its derivatives)
Define a scalar product (a bilinear form), , and introduce a finite set of test functions , typically , and (thus defining a Galerkin method)
Find nodal values by solving equations arising from projection ,
Typical problem reformulation , , : boundary conditions
FreeFEM++ (see freefem.org) is a product of the Laboratoire Jacques Louis Lions (LJLL), Sorbonne University, Paris, that provides a high-level language for finite element formulations, very close to mathematical formulations obtained in functional analysis
Example: Poisson equation in an ellipse,
real theta=4.*pi/3.; real a=2.,b=1.; // the length of the semimajor axis and semiminor axis func z=x; border Gamma1(t=0,theta) { x = a * cos(t); y = b*sin(t); } border Gamma2(t=theta,2*pi) { x = a * cos(t); y = b*sin(t); } mesh Th=buildmesh(Gamma1(100)+Gamma2(50)); // construction of mesh plot(Th,wait=true, ps="membraneTh.eps"); fespace Vh(Th,P2); // P2 conforming triangular FEM Vh phi,w, f=1; solve Laplace(phi,w) = int2d(Th)(dx(phi)*dx(w) + dy(phi)*dy(w)) - int2d(Th)(f*w) + on(Gamma1,phi=z); // Solve Poisson equation plot(phi,wait=true, ps="membrane.eps");
|
|
real aL=8., bL=3., cL=2, dL=2., aE = 0.49*aL, bE = 0.49*bL; // geometry // Define region border border B1(t=0,aL) { x = t; y=0; label=1; } border B2(t=0,bL) { x = aL; y=t; label=2; } border B3(t=0,aL-cL) { x = aL-t; y=bL; label=1; } border B4(t=0,dL) { x = cL; y=bL+t; label=1; } border B5(t=0,cL) { x = cL-t; y=bL+dL; label=1; } border B6(t=0,bL+dL) { x = 0; y=bL+dL-t; label=3; } int n=5; // Choose base boundary discretization // Generate mesh of region interior mesh Th=buildmesh(B1(8*n)+B2(3*n)+B3(6*n)+B4(10*n)+B5(10*n)+B6(5*n)); plot(Th,wait=true, ps="Lshape.eps"); real k2=1.; // Wavenumber Vh(Th,P2); // Define finite element space, test functions fespace Vh u,v; // Weak form of Helmholtz operator solve Helmholtz(u,v) = int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v) - k2*u*v) + on(2,u=1) + on(3,u=0) ; plot(u, wait=true, ps="Lmode.eps"); // Display eigenmode
|
|
// Build Helmholtz problem discretization varf vHelmholtz(u,v) = int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v) - k2*u*v) + on(2,u=2) + on(3,u=0); matrix A = vHelmholtz(Vh,Vh); real[int] b = vHelmholtz(0,Vh); // Save the discretization to a file {ofstream fout("A.txt"); fout << A << endl;} {ofstream fout("b.txt"); fout << b << endl;}