Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Weak form in FEM

It is common in FEM to use the weak form formulation instead of the direct formulation (strong form) as
the weak form formulation allows less restrictions on the solution’s behavior (differentiability).

• Statement 1
The problem of solving the following boundary value problem,

−∆u = f in Ω, (1)
u = 0 on ∂Ω. (2)

is equivalent to

• Statement 2
Find u such that
∫ ∫ ∫ ∫
∇u · ∇vdS = f vdS, (3)
Ω Ω
for all v such that v = 0 on ∂Ω.

(Proof)

• Statement 1 ⇒ Statement 2

Multiply a function that vanishes on the boundary, v, on both sides of Eq. (1) to get
∫ ∫ ∫ ∫
− ∆u v dS = f v dS. (4)
Ω Ω

By integrating the left hand side of Eq.(4) by parts, we have


∫ ∫ ∫ ∫
− ∆u v dS = − ∇ · ∇u v dS

I Ω ∫ ∫
= − n · ∇u vdℓ + ∇u · ∇v dS
∫ ∫ ∂Ω Ω

= ∇u · ∇v dS, (5)

because v vanishes on the boundary.


• Statement 2 ⇒ Statement 1

Just go backwards.

In FEM, choose v as the base function, ei , and set u as



N
u= uj ej .
j=1

Equation (3) then becomes


∫ ∫ ∑
N ∫ ∫
∇ uj ej · ∇ei dS = f ei dS, (6)
Ω j=1 Ω

1
or
N (∫ ∫
∑ ) ∫ ∫
∇ei · ∇ej dS uj = f ei dS, (7)
j=1 Ω Ω

or
Lu = c, (8)
where ∫ ∫ ∫ ∫
Lij = ∇ei · ∇ej dS, ci = f ei dS.
Ω Ω
This result is, of course, identical to what we already derived using the Galerkin method in Lecture Note
22. The term “weak” comes from the fact that the weak form requires u to be differentiable only once while
the strong form requires u to be differentiable twice.

FreeFem++
Introduction
FreeFem++ is free software developed by a team at Laboratoire Jacques-Louis Lions, Université Pierre et
Marie Curie, Paris, to solve a system of 2-D and 3-D partial differential equations numerically using the finite
element method. FreeFem++ uses a high-level language similar to C++ to define equations, mesh, the
solution method to be used and plot the result. Unlike commercial software such as ANSYS, it is necessary
that you have to enter the differential equation in weak form directly along with the boundary condition.

• Download and install it on your machine.

• (Optional) Download (Integrated development environment)


Figure 1: Opening Screen of FreeFem++ CS.

Example 1
We wish to solve a Poisson type equation

∂2u ∂2u
+ 2 = 2, (9)
∂x2 ∂y

2
Figure 2: Poisson Equation.

defined over a unit circle shown in Figure 2 with the Dirichlet boundary condition of

u=0

on the boundary of the circle, x2 + y 2 = 1.

The following steps need to be prepared before implementing this example problem in FreeFem++.

1. Define the boundary of the domain by a parameter, t, as

{(x, y), x = cos t, y = sin t, 0 ≤ t ≤ 2π}.

2. Build a mesh where the number of nodes on the boundary needs to be specified. Based on this
information, mesh will be automatically generated.

3. (Important) Rewrite the differential equation in weak form to be entered into FreeFem++.

∆u − 2 = 0. (10)

Multiply v on both sides and integrate the result to get


∫ ∫ ∫ ∫
∆u vds − 2vds = 0, (11)
Ω Ω
where v is an arbitrary function that satisfies the same homogeneous boundary condition as u.
Using integration by parts (Gauss’ theorem), the first term in the left hand side can be rewritten as
∫ ∫ I ∫ ∫
∇ · ∇u vds = ∇u · nvdl − ∇u · ∇vds

I∂Ω ∫ ∫ Ω
∂u
= vdℓ − ∇u · ∇vds
∂n
∫ ∫
∂Ω Ω

= − ∇u · ∇vds, (12)

where we used the fact that v vanishes on the boundary. Therefore, Equation (10) can be written as
∫ ∫ ( ) ∫ ∫
∂u ∂v ∂u ∂v
+ ds + 2vds = 0. (13)
Ω ∂x ∂x ∂y ∂y Ω

This is the equation to be entered into FreeFem++.


Enter the following script into the window of FreeFem++ CS.

3
// Define the border first.
border myBorder(t=0,2*pi){x=cos(t);y=sin(t);};
// Make mesh based on the number of nodes on the border.
mesh myMesh=buildmesh(myBorder(20));
// Let’s plot the mesh.
plot(myMesh);

// Define FEM linear space based on the mesh using P1 (piecewise linear elements).
fespace myVh(myMesh, P1);
// Two functions, myU and myV, are defined in the linear space, myVh.
myVh myU, myV;
// Solve the Poisson equation with prescribed boundary condition.
solve myEq(myU, myV)=int2d(myMesh)(dx(myU)*dx(myV)+dy(myU)*dy(myV))
+int2d(myMesh)(2*myV)+on(myBorder, myU=0);
// Finally, plot the solution in 2-D.
plot(myU,dim=2,fill=true);

In the program above, those words beginning with “my” represent user defined variables. All other words
are system built-in variables.

Figure 3: Mesh Generation.

Figure 4: Solution.

Example 2 (p.1059)

4
Taken from an example in Lecture 21.

∂2u ∂2u
+ 2 = 0 inD, (14)
∂x2 ∂y
u(0, y) = 0 (0 < y < 1) (15)
u(1, y) = f (y) (0 < y < 1) (16)
u(x, 0) = u(x, 1) = 0 (0 < x < 1) (17)

Figure 5: Example from Lecture Note #19.

// Define the square border by four segments.


border myBorder1(t=0,1){x=0;y=1-t;};
border myBorder2(t=0,1){x=t;y=0;};
border myBorder3(t=0,1){x=1;y=t;};
border myBorder4(t=0,1){x=1-t;y=1;};

// Generate the mesh with 10 nodes on each of the segments.


mesh myMesh=buildmesh(myBorder1(10)+myBorder2(10)+myBorder3(10)+myBorder4(10));
plot(myMesh);

// Define FEM space, myVh, based on MyMesh using P1 base functions.


fespace myVh(myMesh, P1);

// Define two functions, myU and myV, in the FEM space, myVh.
myVh myU, myV;

5
// Solving the Poisson equation with the given boundary conditions.
solve myPoisson(myU,myV)=int2d(myMesh)(dx(myU)*dx(myV)+dy(myU)*dy(myV))
+int2d(myMesh)(2*myV)+on(myBorder1,myU=0)+on(myBorder2,myU=0)
+on(myBorder3,myU=1)+on(myBorder4,myU=0);

plot(myU,dim=3,fill=true);

Example 3

// Heat conduction in concentric cylinders


border myCircle1(t=0,2*pi){x=cos(t);y=sin(t);};
border myCircle2(t=0,2*pi){x=2*cos(t);y=2*sin(t);};
mesh myMesh=buildmesh(myCircle1(120)+myCircle2(40));
plot(myMesh);

fespace myVh(myMesh,P1);

// Use the boole function to define heterogeneity


myVh u,v,k=10*(x^2+y^2<1)+1*(x^2+y^2>1);

solve myEq(u,v)=int2d(myMesh)(k*dx(u)*dx(v)+k*dy(u)*dy(v))+int2d(myMesh)(-2*v)+on(myCircle2, u=10);

plot(u,dim=3,fill=true,value=true);

Example 4
Beam (elasticity)

6
Figure 6: Two materials

• Strong form
µ∆ui + (µ + λ)uj,ji + bi = 0

• Weak form ∫ ∫ ∫ ∫ ∫ ∫
−µ ui,j vi,j dS − (µ + λ) uj,j vj,j dS + bi vi dS = 0.

// file lame.edp
mesh Th=square(10,10,[20*x,2*y-1]);
fespace Vh(Th,P2);
Vh u,v,uu,vv;
real sqrt2=sqrt(2.);
macro epsilon(u1,u2) [dx(u1),dy(u2),(dy(u1)+dx(u2))/sqrt2] // EOM
//the sqrt2 is because we want: epsilon(u1,u2)’* epsilon(v1,v2) $== \epsilon(\bm{u}): \epsilon(\bm{v})
macro div(u,v) ( dx(u)+dy(v) ) // EOM

7
Figure 7: Two materials

real E = 21e5, nu = 0.28, mu= E/(2*(1+nu));


real lambda = E*nu/((1+nu)*(1-2*nu)), f = -1; //

solve lame([u,v],[uu,vv])= int2d(Th)(


lambda*div(u,v)*div(uu,vv)
+2.*mu*( epsilon(u,v)’*epsilon(uu,vv) ) )
- int2d(Th)(f*vv)
+ on(4,u=0,v=0);
real coef=100;
plot([u,v],wait=1,ps="lamevect.eps",coef=coef);

mesh th1 = movemesh(Th, [x+u*coef, y+v*coef]);


plot(th1,wait=1,ps="lamedeform.eps");
real dxmin = u[].min;
real dymin = v[].min;

cout << " - dep. max x = "<< dxmin<< " y=" << dymin << endl;
cout << " dep. (20,0) = " << u(20,0) << " " << v(20,0) << endl;

One-liner FEM in Mathematica


sol=NDSolve[{D[u[x, y], {x, 2}] + D[u[x, y], {y, 2}] + u[x, y] == 1,
u[x, 0] == 0, u[1, y] == 0, u[x, 1] == 0, u[0, y] == 0}, u, {x, 0,
1}, {y, 0, 1}]
Plot3D[Evaluate[u[x, y] /. sol], {x, 0, 1}, {y, 0, 1},
PlotRange -> All]

8
Figure 8: Beam (elasticity, before deformation)

9
Figure 9: Beam (elasticity, after deformation)

10

You might also like