A short course on
FEM for CFD
Week 1: Basics of FEM and FreeFEM, and Poisson equation
Dr Chennakesava Kadapa
Email: c.kadapa@napier.ac.uk
1
Contents
• Introduction to the course
• Poisson’s equation
• Navier-Stokes equation
• Introduction to Finite Element Method
• Introduction to the FreeFEM library
• Examples
2
Delivery mode
• Lecture
• Tutorial
• Exercise
3
4
References
More references at
https://github.com/chennachaos/awesome-FEM4CFD
Incompressible Navier-Stokes equation
𝜌
𝜕𝒖
𝜕𝑡
+ 𝒖 ∙ ∇ 𝒖 − 𝜇∆𝒖 + 𝛻𝑝 = 𝒇
𝛻 ∙ 𝒖 = 0
𝒖 = 𝑣𝑒𝑙𝑜𝑐𝑖𝑡𝑦
𝑝 = 𝑝𝑟𝑒𝑠𝑠𝑢𝑟𝑒
𝜌 = 𝑑𝑒𝑛𝑠𝑖𝑡𝑦
𝜇 = 𝑑𝑦𝑛𝑎𝑚𝑖𝑐 𝑣𝑖𝑠𝑐𝑜𝑠𝑖𝑡𝑦
Acceleration term Viscous term Pressure gradient
Local
Acceleration
Convective
Acceleration
Body force
5
Course structure
• Poisson’s equation
−𝜇∆𝑢 = 𝑓
• Steady Advection-Diffusion equation
𝒂 ∙ ∇ 𝑢 − 𝜇∆𝑢 = 𝑓
• Unsteady Advection-Diffusion equation
𝜌
𝜕𝑢
𝜕𝑡
+ 𝒂 ∙ ∇ 𝑢 − 𝜇∆𝑢 = 𝑓
• Stokes equation
𝜌
𝜕𝒖
𝜕𝑡
− 𝜇∆𝒖 + 𝛻𝑝 = 𝒇
𝛻 ∙ 𝒖 = 0
• Navier-Stokes equation
𝜌
𝜕𝒖
𝜕𝑡
+ 𝒖 ∙ ∇ 𝒖 − 𝜇∆𝒖 + 𝛻𝑝 = 𝒇
𝛻 ∙ 𝒖 = 0
6
Week 1
Week 2
Week 3
Week 4,5,6
Week 4,5,6
Poisson’s equation
7
Poisson’s equation
• Is an elliptic PDE
• Many applications
• Diffusion, heat transfer, electrostatics, magnetostatics
• Poisson’s equation is
−∆𝑢 = 𝑓
where 𝑢 is the (scalar) field, 𝑓 is the source term and ∆ is the Laplacian operator.
• Laplacian operator (∆)
∆𝑢 = ∇2𝑢 = ∇ ∙ ∇𝑢 =
𝜕2
𝑢
𝜕𝑥2
+
𝜕2
𝑢
𝜕𝑦2
+
𝜕2
𝑢
𝜕𝑧2
8
Poisson’s equation (Cont’d)
• We can also write as
−∇ ∙ (∇𝑢) = 𝑓
where ∇ is the gradient operator and ∇ ∙ is the divergence operator.
• Gradient operator (∇)
∇=
𝜕
𝜕𝑥
𝜕
𝜕𝑦
𝜕
𝜕𝑧
𝑇
• Thus
∇ ∙ ∇𝑢 =
𝜕
𝜕𝑥
𝜕
𝜕𝑦
𝜕
𝜕𝑧
∙
𝜕𝑢
𝜕𝑥
𝜕𝑢
𝜕𝑦
𝜕𝑢
𝜕𝑧
=
𝜕2𝑢
𝜕𝑥2
+
𝜕2𝑢
𝜕𝑦2
+
𝜕2𝑢
𝜕𝑧2
9
∇𝑢 =
𝜕𝑢
𝜕𝑥
𝜕𝑢
𝜕𝑦
𝜕𝑢
𝜕𝑧
Boundary conditions
• Boundary conditions
Dirichlet boundary condition: 𝑢 = 𝑢 on Γ𝐷
Neumann boundary condition: ∇𝑢 ∙ 𝒏 = 𝑡 on Γ𝑁
where 𝑢 is the specified solution field on the Dirichlet boundary Γ𝐷
𝑡 is the specified flux on the Neumann boundary Γ𝑁.
10
Finite Element Method
11
• Finite Element Method (FEM) is a numerical method for solving problems modelled by partial
differential equations (PDEs).
• FEM is not just for solid mechanics.
• FEM has become the de-facto numerical method for many problems in science and engineering.
• Simulation software and/or libraries based on FEM are available for
• Solid mechanics – stress analysis
• Structural dynamics
• Wave propagation
• Heat transfer
• Fluid dynamics
• Chemical diffusion
• Electromagnetics
12
What is FEM?
Check my papers for the details.
 FEM offers a flexible numerical framework with a rich set of
elements of different shapes, orders and families.
 Applicability to complex geometries.
 Different element shapes – triangle, quadrilateral,
tetrahedron, brick, pyramid, wedge.
 Different element families – Lagrange family, Bézier family,
Spectral elements, IGA, H-Div and H-Curl elements.
 Ease of extensions to higher-order approximations
 Ease of extension to Multiphysics problems
 Better accuracies compared to FVM for unstructured meshes
13
Why FEM?
 Dates back to 1940s
 Originally used for problems in structural mechanics
 1960-1990 was the golden age of FEM
 Since 1990, an explosion of industrial applications of FEM
14
History of FEM
https://link.springer.com/article/10.1007/s11831-022-09740-9
• The points are called nodes.
• The cells are called elements.
• The variables are usually stored at nodes.
Variable per cell is also possible.
• The solution variables at nodes are called as degrees of freedom (DOFs).
• The value at nodes (DOFs) can be a
• Scalar: temperature, pressure, density
• Vector: displacement, velocity
• Tensor: deformation gradient, strain, stress
15
FEM terminology
Weak formulation
16
Weak form
• Poisson’s equation
−∇ ∙ (∇𝑢) = 𝑓
• Weighted residual statement
Ω
𝑤 𝑅 𝑑𝑉 = 0
• Splitting the integral
−
Ω
𝑤 ∇ ∙ ∇𝑢 𝑑𝑉 =
Ω
𝑤 𝑓 𝑑𝑉
• After using the integrating by parts and divergence theorem
Ω
∇𝑤 ∙ ∇𝑢 𝑑𝑉 −
Γ
𝑤 ∇𝑢 ∙ 𝒏 𝑑𝐴 =
Ω
𝑤 𝑓 𝑑𝑉
• Using boundary conditions
Ω
∇𝑤 ∙ ∇𝑢 𝑑𝑉 =
Ω
𝑤 𝑓 𝑑𝑉 +
Γ𝑁
𝑤 𝑡 𝑑𝐴
Residual: 𝑅 = −∇ ∙ ∇𝑢 − 𝑓
Weak form
17
Weak form
• Weak form in compact form
Ω
∇𝑤 ∙ ∇𝑢 𝑑𝑉 =
Ω
𝑤 𝑓 𝑑𝑉 +
Γ𝑁
𝑤 𝑡 𝑑𝐴
• Weak form in component form
Ω
𝜕𝑤
𝜕𝑥
𝜕𝑤
𝜕𝑦
𝜕𝑤
𝜕𝑧
∙
𝜕𝑢
𝜕𝑥
𝜕𝑢
𝜕𝑦
𝜕𝑢
𝜕𝑧
𝑑𝑉 =
Ω
𝑤 𝑓 𝑑𝑉 +
Γ𝑁
𝑤 𝑡 𝑑𝐴
Ω
𝜕𝑤
𝜕𝑥
𝜕𝑢
𝜕𝑥
+
𝜕𝑤
𝜕𝑦
𝜕𝑢
𝜕𝑦
+
𝜕𝑤
𝜕𝑧
𝜕𝑢
𝜕𝑧
𝑑𝑉 =
Ω
𝑤 𝑓 𝑑𝑉 +
Γ𝑁
𝑤 𝑡 𝑑𝐴
1D
2D
3D
18
Finite Element Method
• In the FEM, we split the domain into smaller parts, called elements.
• As the size of the elements is reduced, the approximation error is reduced.
• Elements are described by their connections to nodes.
• Discretisation
𝑢 =
𝑖=1
𝑛𝑒𝑛
𝑁𝑖𝑢𝑖 = 𝑁1 𝑁2 ⋯ 𝑁𝑛𝑒𝑛
𝑢1
𝑢2
⋮
𝑢𝑛𝑒𝑛
= 𝐍𝐮
𝑤 =
𝑖=1
𝑛𝑒𝑛
𝑁𝑖𝑤𝑖 = 𝐍𝐰
● is a node.
19
∇𝑢 =
𝜕𝑢
𝜕𝑥
𝜕𝑢
𝜕𝑦
𝜕𝑢
𝜕𝑧
=
𝜕𝑁1
𝜕𝑥
𝜕𝑁2
𝜕𝑥
⋯
𝜕𝑁𝑛𝑒𝑛
𝜕𝑥
𝜕𝑁1
𝜕𝑦
𝜕𝑁1
𝜕𝑧
𝜕𝑁2
𝜕𝑦
𝜕𝑁2
𝜕𝑧
⋯
⋯
𝜕𝑁𝑛𝑒𝑛
𝜕𝑦
𝜕𝑁𝑛𝑒𝑛
𝜕𝑧
𝑢1
𝑢1
⋮
𝑢𝑛𝑒𝑛
=
𝜕𝑵
𝜕𝒙
𝐮
∇𝑤 =
𝜕𝑵
𝜕𝒙
𝐰
Discretised problem
• Weak form:
Ω
∇𝑤 ∙ ∇𝑢 𝑑𝑉 =
Ω
𝑤 𝑓 𝑑𝑉 +
Γ𝑁
𝑤 𝑡 𝑑𝐴
• Using the discretization, the system of equations can be written as
𝐊 𝐮 = 𝐅
where,
𝐊 = 𝐀
e=1
𝐊𝒆; 𝐊𝒆 =
Ω𝑒
𝜕𝑵
𝜕𝑥
𝑇
𝜕𝑵
𝜕𝑥
𝑑𝑉
𝐅 = 𝐀
e=1
𝐅𝒆; 𝐅𝒆 =
Ω𝑒
𝑵𝑇𝑓𝑑𝑉 +
Γ𝑁
𝑒
𝑵𝑇𝑡 𝑑𝐴
20
FEM ingredients
We need to evaluate
𝐊 = 𝐀
e=1
𝐊𝒆; 𝐊𝒆 =
Ω𝑒
𝜕𝑵
𝜕𝑥
𝑇
𝜕𝑵
𝜕𝑥
𝑑𝑉
𝐅 = 𝐀
e=1
𝐅𝒆
; 𝐅𝒆
=
Ω𝑒
𝑵𝑇
𝑓𝑑𝑉 +
Γ𝑁
𝑒
𝑵𝑇
𝑡 𝑑𝐴
Information needed:
• Mesh – nodal coordinates and connectivity
• Element – basis functions
• Stiffness matrix and force vector - numerical quadrature
• Linear system – matrix solver (LU, CG, etc..)
21
FreeFEM library
22
Introduction to FreeFEM
23
• An opensource library for FEM.
• Not an application/solver library like OpenFOAM.
• Library that provides all the basic FEM ingredients.
• To develop custom solvers.
Well supported.
Easy to install and use.
Up-to-date tutorials.
x Supports triangular and tetrahedral elements only.
• Input through scripts
• File extension “.edp”
• Similar to C++ syntax
• No need to compile
• FreeFem++.exe <inp-script-file>
Tutorial #1
24
Tutorial #1
25
File: Week1-Tutorial1.edp
Tutorial #1
// The triangulated domain Th
mesh Th = square(10,10);
// The finite element space defined over Th is called here Vh
fespace Vh(Th, P1);
// Define u and w in the function space
Vh u, w;
// Define functions
func uexact = (cosh(pi*y)-sinh(pi*y)/tanh(pi))*sin(pi*x);
func f= 0;
Mesh over a square
or mapped square
Finite element space.
Element type, order etc.
P1 is 3-noded triangle.
Solution and test function
Functions for use
26
Tutorial #1 (cont’d)
// Define the weak formulation
solve Poisson(u, w, solver=LU)
= int2d(Th)( // The bilinear part
dx(w)*dx(u) + dy(w)*dy(u)
)
- int2d(Th)( // The right hand side
w*f
)
// The Dirichlet boundary condition
+ on(1,2,3,4, u=uexact)
;
// Plot the result
plot(u);
load "iovtk"
int[int] Order = [1];
string filename = "Poisson2D-square-Dirichlet.vtu";
savevtk(filename, Th, u, dataname="u", order=Order);
Weak form LHS
Weak form RHS
Boundary conditions
Plot the solution
Export solution in VTK format.
Available only as first-order elements.
27
Ω
𝜕𝑤
𝜕𝑥
𝜕𝑢
𝜕𝑥
+
𝜕𝑤
𝜕𝑦
𝜕𝑢
𝜕𝑦
𝑑𝑉 =
Ω
𝑤 𝑓 𝑑𝑉 +
Γ𝑁
𝑤 𝑡 𝑑𝐴
Tutorial #1 (cont’d)
// Error
real error = int2d(Th)(
(uexact-u)^2
);
error = sqrt(error);
28
• Error
𝑒 = 𝑢𝑒𝑥𝑎𝑐𝑡 − 𝑢
• L2 norm of error
𝑒𝐿2 =
Ω
𝑒2 𝑑𝑉 =
Ω
(𝑢𝑒𝑥𝑎𝑐𝑡 − 𝑢)2 𝑑𝑉
Exercise #1
29
• Different number of elements
// The triangulated domain Th
mesh Th = square(10,10);
mesh Th = square(20,20);
mesh Th = square(80,80);
• Different orders of element
// The finite element space defined over Th is called here Vh
fespace Vh(Th, P1);
fespace Vh(Th, P2);
load "Element_P3";
fespace Vh(Th, P3);
Solve the problem in Tutorial 1 using different
number of elements and different orders of
elements and observe the error.
Neumann BCs
30
Tutorial #2
31
Ω
∇𝑤 ∙ ∇𝑢𝑑𝑉 =
Ω
𝑤 𝑓 𝑑𝑉 +
Γ𝑁
𝑤 𝑡 𝑑𝐴
Tutorial #2 (cont’d)
// Define the weak form
solve Poisson(u, w, solver=LU)
= int2d(Th)( // The bilinear part
dx(w)*dx(u) + dy(w)*dy(u)
)
- int2d(Th)( // Source term
w*f
)
- int1d(Th,3)( // Neumann BC term
w*tbar
)
+ on(1,2,4, u=20) // Dirichlet BC
;
32
Ω
𝜕𝑤
𝜕𝑥
𝜕𝑢
𝜕𝑥
+
𝜕𝑤
𝜕𝑦
𝜕𝑢
𝜕𝑦
𝑑𝑉 =
Ω
𝑤 𝑓 𝑑𝑉 +
Γ𝑁
𝑤 𝑡 𝑑𝐴
Complex geometries
33
“square” function
// The triangulated domain Th
// unit square, starting at (0,0)
mesh Th = square(10, 10);
// rectangle of size 10x5, starting at (0,0)
mesh Th = square(10, 10, [10*x, 5*y]);
// rectangle of size 5x10, starting at (-4,-2)
mesh Th = square(10, 10, [-4+5*x, -2+10*y]);
34
//display mesh
plot(Th);
Complex geometries – inbuilt functions
int boundary = 1;
border C01(t=0, 1){x=t; y=0.0; label=boundary;}
border C02(t=0, 1){x=1; y=0.5*t; label=boundary;}
border C03(t=0, 1){x=1.0-0.5*t; y=0.5; label=boundary;}
border C04(t=0, 1){x=0.5; y=0.5+0.5*t; label=boundary;}
border C05(t=0, 1){x=0.5-0.5*t; y=1.0; label=boundary;}
border C06(t=0, 1){x=0.0; y=1-t; label=boundary;}
int n = 20;
mesh Th = buildmesh(C01(n) + C02(n/2) + C03(n/2) + C04(n/2) + C05(n/2) + C06(n));
plot(Th);
C01
C02
C03
C04
C05
C06
35
https://doc.freefem.org/examples/mesh-generation.html
Complex geometries – using GMSH
load "gmsh"
// The triangulated domain Th
mesh Th = gmshload("Lshaped-gmsh-mesh.msh");
int boundary = 1;
mesh Th = gmshload("cylinder-gmsh-mesh.msh");
int inlet = 1;
int outlet = 2;
int topwall = 3;
int bottomwall = 4;
int cylinder = 5;
36
//display mesh
plot(Th);
Exercises
37
Exercise #2
Solve the Poisson equation over the L-shaped domain.
Use the mesh from “Lshaped-gmsh-mesh.msh”.
𝑢 = 0 on all boundaries.
𝑓 = 20
38
Solution for exercise #2
39
Exercise #3
Solve the Poisson equation for the following problem.
Use the mesh from “cylinder-gmsh-mesh.msh”.
𝑢 = 10
𝜕𝑢
𝜕𝑦
= 0
𝜕𝑢
𝜕𝑦
= −2
𝑢 = 30
𝑓 = 0
𝑢 = 50
40
Solution for exercise #3
41
42
Access to matrix and vector
// Define the weak (variational) formulation
varf PoissonLHS(u, w)
= int2d(Th)( // The bilinear part
dx(w)*dx(u)
+ dy(w)*dy(u)
)
// The Dirichlet boundary condition
+ on(1,2,3,4, u=uexact)
;
matrix A = PoissonLHS(Vh, Vh); //stiffness matrix
cout << A << endl;
// Define the weak (variational) formulation
varf PoissonRHS(unused, w)
= int2d(Th)(
f*w
)
// The Dirichlet boundary condition
+ on(1,2,3,4, u=uexact)
;
Vh F;
//F[] is the vector associated to the function F
F[] = PoissonRHS(0,Vh);
cout << F[] << endl;
//u[] is the vector associated to the function u
u[] = A^-1*F[];
cout << u[] << endl;
43
More practice with FreeFEM
• FreeFEM - Getting started
https://doc.freefem.org/tutorials/poisson.html
• FreeFEM – Additional examples
https://doc.freefem.org/tutorials/index.html
44
45
46

More Related Content

PPTX
chapter 1- introduction to finite element method
PDF
ff++-ANEDP.pdf
PPT
Finite Element Method.ppt
PDF
01-Chapter 01 Moaveni.pdf
PDF
322892315 notes-dixit-pdf
PDF
Lecture on Introduction to finite element methods & its contents
PPT
INTRODUCTION TO FINITE ELEMENT METHODS PPT
PPTX
Introduction to fem
chapter 1- introduction to finite element method
ff++-ANEDP.pdf
Finite Element Method.ppt
01-Chapter 01 Moaveni.pdf
322892315 notes-dixit-pdf
Lecture on Introduction to finite element methods & its contents
INTRODUCTION TO FINITE ELEMENT METHODS PPT
Introduction to fem

Similar to Introduction to CFd analysis.FEM4CFD-Week1.pptx (20)

PPTX
tuttuturtCH 1 and 2 FEM ppt finite el.pptx
PPT
Finite_Element_Method_FULL_FULL_FULL.ppt
PDF
IRJET- Stress – Strain Field Analysis of Mild Steel Component using Finite El...
PDF
Finite Element Method
PPT
PPT
06_finite_elements_basics.ppt
PPT
5994944.ppt
PPT
Introduction to Finite Element Methods - basics
PPTX
FEM: Modern Computational Mechanics.pptx
PPT
FEM Lecture.ppt
PDF
FINITE ELEMENT METHOD I lecture notes.pdf
PDF
A Comprehensive Introduction of the Finite Element Method for Undergraduate C...
PPTX
PPT
Finite_Element_Method analysis and theory of yeild line .ppt
PPT
Finite element method
PDF
Fem notes
PDF
Lecture 01 - Introduction to Finite EM.pdf
PPT
Introduction to FEA
PPT
Unit I fdocuments.in_introduction-to-fea-and-applications.ppt
tuttuturtCH 1 and 2 FEM ppt finite el.pptx
Finite_Element_Method_FULL_FULL_FULL.ppt
IRJET- Stress – Strain Field Analysis of Mild Steel Component using Finite El...
Finite Element Method
06_finite_elements_basics.ppt
5994944.ppt
Introduction to Finite Element Methods - basics
FEM: Modern Computational Mechanics.pptx
FEM Lecture.ppt
FINITE ELEMENT METHOD I lecture notes.pdf
A Comprehensive Introduction of the Finite Element Method for Undergraduate C...
Finite_Element_Method analysis and theory of yeild line .ppt
Finite element method
Fem notes
Lecture 01 - Introduction to Finite EM.pdf
Introduction to FEA
Unit I fdocuments.in_introduction-to-fea-and-applications.ppt
Ad

Recently uploaded (20)

PDF
electrical machines course file-anna university
PPTX
WN UNIT-II CH4_MKaruna_BapatlaEngineeringCollege.pptx
PDF
CELDAS DE COMBUSTIBLE TIPO MEMBRANA DE INTERCAMBIO PROTÓNICO.pdf
PDF
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
PDF
Beginners-Guide-to-Artificial-Intelligence.pdf
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PDF
Lesson 3 .pdf
PDF
VTU IOT LAB MANUAL (BCS701) Computer science and Engineering
PDF
IAE-V2500 Engine for Airbus Family 319/320
DOCX
ENVIRONMENTAL PROTECTION AND MANAGEMENT (18CVL756)
PPTX
SE unit 1.pptx aaahshdhajdviwhsiehebeiwheiebeiev
PPTX
Real Estate Management PART 1.pptxFFFFFFFFFFFFF
PPTX
Quality engineering part 1 for engineering undergraduates
PPTX
AI-Reporting for Emerging Technologies(BS Computer Engineering)
PPT
UNIT-I Machine Learning Essentials for 2nd years
PDF
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
DOCX
An investigation of the use of recycled crumb rubber as a partial replacement...
PDF
LS-6-Digital-Literacy (1) K12 CURRICULUM .pdf
PDF
Artificial Intelligence_ Basics .Artificial Intelligence_ Basics .
PPTX
CS6006 - CLOUD COMPUTING - Module - 1.pptx
electrical machines course file-anna university
WN UNIT-II CH4_MKaruna_BapatlaEngineeringCollege.pptx
CELDAS DE COMBUSTIBLE TIPO MEMBRANA DE INTERCAMBIO PROTÓNICO.pdf
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
Beginners-Guide-to-Artificial-Intelligence.pdf
MLpara ingenieira CIVIL, meca Y AMBIENTAL
Lesson 3 .pdf
VTU IOT LAB MANUAL (BCS701) Computer science and Engineering
IAE-V2500 Engine for Airbus Family 319/320
ENVIRONMENTAL PROTECTION AND MANAGEMENT (18CVL756)
SE unit 1.pptx aaahshdhajdviwhsiehebeiwheiebeiev
Real Estate Management PART 1.pptxFFFFFFFFFFFFF
Quality engineering part 1 for engineering undergraduates
AI-Reporting for Emerging Technologies(BS Computer Engineering)
UNIT-I Machine Learning Essentials for 2nd years
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
An investigation of the use of recycled crumb rubber as a partial replacement...
LS-6-Digital-Literacy (1) K12 CURRICULUM .pdf
Artificial Intelligence_ Basics .Artificial Intelligence_ Basics .
CS6006 - CLOUD COMPUTING - Module - 1.pptx
Ad

Introduction to CFd analysis.FEM4CFD-Week1.pptx

  • 1. A short course on FEM for CFD Week 1: Basics of FEM and FreeFEM, and Poisson equation Dr Chennakesava Kadapa Email: [email protected] 1
  • 2. Contents • Introduction to the course • Poisson’s equation • Navier-Stokes equation • Introduction to Finite Element Method • Introduction to the FreeFEM library • Examples 2
  • 3. Delivery mode • Lecture • Tutorial • Exercise 3
  • 5. Incompressible Navier-Stokes equation 𝜌 𝜕𝒖 𝜕𝑡 + 𝒖 ∙ ∇ 𝒖 − 𝜇∆𝒖 + 𝛻𝑝 = 𝒇 𝛻 ∙ 𝒖 = 0 𝒖 = 𝑣𝑒𝑙𝑜𝑐𝑖𝑡𝑦 𝑝 = 𝑝𝑟𝑒𝑠𝑠𝑢𝑟𝑒 𝜌 = 𝑑𝑒𝑛𝑠𝑖𝑡𝑦 𝜇 = 𝑑𝑦𝑛𝑎𝑚𝑖𝑐 𝑣𝑖𝑠𝑐𝑜𝑠𝑖𝑡𝑦 Acceleration term Viscous term Pressure gradient Local Acceleration Convective Acceleration Body force 5
  • 6. Course structure • Poisson’s equation −𝜇∆𝑢 = 𝑓 • Steady Advection-Diffusion equation 𝒂 ∙ ∇ 𝑢 − 𝜇∆𝑢 = 𝑓 • Unsteady Advection-Diffusion equation 𝜌 𝜕𝑢 𝜕𝑡 + 𝒂 ∙ ∇ 𝑢 − 𝜇∆𝑢 = 𝑓 • Stokes equation 𝜌 𝜕𝒖 𝜕𝑡 − 𝜇∆𝒖 + 𝛻𝑝 = 𝒇 𝛻 ∙ 𝒖 = 0 • Navier-Stokes equation 𝜌 𝜕𝒖 𝜕𝑡 + 𝒖 ∙ ∇ 𝒖 − 𝜇∆𝒖 + 𝛻𝑝 = 𝒇 𝛻 ∙ 𝒖 = 0 6 Week 1 Week 2 Week 3 Week 4,5,6 Week 4,5,6
  • 8. Poisson’s equation • Is an elliptic PDE • Many applications • Diffusion, heat transfer, electrostatics, magnetostatics • Poisson’s equation is −∆𝑢 = 𝑓 where 𝑢 is the (scalar) field, 𝑓 is the source term and ∆ is the Laplacian operator. • Laplacian operator (∆) ∆𝑢 = ∇2𝑢 = ∇ ∙ ∇𝑢 = 𝜕2 𝑢 𝜕𝑥2 + 𝜕2 𝑢 𝜕𝑦2 + 𝜕2 𝑢 𝜕𝑧2 8
  • 9. Poisson’s equation (Cont’d) • We can also write as −∇ ∙ (∇𝑢) = 𝑓 where ∇ is the gradient operator and ∇ ∙ is the divergence operator. • Gradient operator (∇) ∇= 𝜕 𝜕𝑥 𝜕 𝜕𝑦 𝜕 𝜕𝑧 𝑇 • Thus ∇ ∙ ∇𝑢 = 𝜕 𝜕𝑥 𝜕 𝜕𝑦 𝜕 𝜕𝑧 ∙ 𝜕𝑢 𝜕𝑥 𝜕𝑢 𝜕𝑦 𝜕𝑢 𝜕𝑧 = 𝜕2𝑢 𝜕𝑥2 + 𝜕2𝑢 𝜕𝑦2 + 𝜕2𝑢 𝜕𝑧2 9 ∇𝑢 = 𝜕𝑢 𝜕𝑥 𝜕𝑢 𝜕𝑦 𝜕𝑢 𝜕𝑧
  • 10. Boundary conditions • Boundary conditions Dirichlet boundary condition: 𝑢 = 𝑢 on Γ𝐷 Neumann boundary condition: ∇𝑢 ∙ 𝒏 = 𝑡 on Γ𝑁 where 𝑢 is the specified solution field on the Dirichlet boundary Γ𝐷 𝑡 is the specified flux on the Neumann boundary Γ𝑁. 10
  • 12. • Finite Element Method (FEM) is a numerical method for solving problems modelled by partial differential equations (PDEs). • FEM is not just for solid mechanics. • FEM has become the de-facto numerical method for many problems in science and engineering. • Simulation software and/or libraries based on FEM are available for • Solid mechanics – stress analysis • Structural dynamics • Wave propagation • Heat transfer • Fluid dynamics • Chemical diffusion • Electromagnetics 12 What is FEM? Check my papers for the details.
  • 13.  FEM offers a flexible numerical framework with a rich set of elements of different shapes, orders and families.  Applicability to complex geometries.  Different element shapes – triangle, quadrilateral, tetrahedron, brick, pyramid, wedge.  Different element families – Lagrange family, Bézier family, Spectral elements, IGA, H-Div and H-Curl elements.  Ease of extensions to higher-order approximations  Ease of extension to Multiphysics problems  Better accuracies compared to FVM for unstructured meshes 13 Why FEM?
  • 14.  Dates back to 1940s  Originally used for problems in structural mechanics  1960-1990 was the golden age of FEM  Since 1990, an explosion of industrial applications of FEM 14 History of FEM https://link.springer.com/article/10.1007/s11831-022-09740-9
  • 15. • The points are called nodes. • The cells are called elements. • The variables are usually stored at nodes. Variable per cell is also possible. • The solution variables at nodes are called as degrees of freedom (DOFs). • The value at nodes (DOFs) can be a • Scalar: temperature, pressure, density • Vector: displacement, velocity • Tensor: deformation gradient, strain, stress 15 FEM terminology
  • 17. Weak form • Poisson’s equation −∇ ∙ (∇𝑢) = 𝑓 • Weighted residual statement Ω 𝑤 𝑅 𝑑𝑉 = 0 • Splitting the integral − Ω 𝑤 ∇ ∙ ∇𝑢 𝑑𝑉 = Ω 𝑤 𝑓 𝑑𝑉 • After using the integrating by parts and divergence theorem Ω ∇𝑤 ∙ ∇𝑢 𝑑𝑉 − Γ 𝑤 ∇𝑢 ∙ 𝒏 𝑑𝐴 = Ω 𝑤 𝑓 𝑑𝑉 • Using boundary conditions Ω ∇𝑤 ∙ ∇𝑢 𝑑𝑉 = Ω 𝑤 𝑓 𝑑𝑉 + Γ𝑁 𝑤 𝑡 𝑑𝐴 Residual: 𝑅 = −∇ ∙ ∇𝑢 − 𝑓 Weak form 17
  • 18. Weak form • Weak form in compact form Ω ∇𝑤 ∙ ∇𝑢 𝑑𝑉 = Ω 𝑤 𝑓 𝑑𝑉 + Γ𝑁 𝑤 𝑡 𝑑𝐴 • Weak form in component form Ω 𝜕𝑤 𝜕𝑥 𝜕𝑤 𝜕𝑦 𝜕𝑤 𝜕𝑧 ∙ 𝜕𝑢 𝜕𝑥 𝜕𝑢 𝜕𝑦 𝜕𝑢 𝜕𝑧 𝑑𝑉 = Ω 𝑤 𝑓 𝑑𝑉 + Γ𝑁 𝑤 𝑡 𝑑𝐴 Ω 𝜕𝑤 𝜕𝑥 𝜕𝑢 𝜕𝑥 + 𝜕𝑤 𝜕𝑦 𝜕𝑢 𝜕𝑦 + 𝜕𝑤 𝜕𝑧 𝜕𝑢 𝜕𝑧 𝑑𝑉 = Ω 𝑤 𝑓 𝑑𝑉 + Γ𝑁 𝑤 𝑡 𝑑𝐴 1D 2D 3D 18
  • 19. Finite Element Method • In the FEM, we split the domain into smaller parts, called elements. • As the size of the elements is reduced, the approximation error is reduced. • Elements are described by their connections to nodes. • Discretisation 𝑢 = 𝑖=1 𝑛𝑒𝑛 𝑁𝑖𝑢𝑖 = 𝑁1 𝑁2 ⋯ 𝑁𝑛𝑒𝑛 𝑢1 𝑢2 ⋮ 𝑢𝑛𝑒𝑛 = 𝐍𝐮 𝑤 = 𝑖=1 𝑛𝑒𝑛 𝑁𝑖𝑤𝑖 = 𝐍𝐰 ● is a node. 19 ∇𝑢 = 𝜕𝑢 𝜕𝑥 𝜕𝑢 𝜕𝑦 𝜕𝑢 𝜕𝑧 = 𝜕𝑁1 𝜕𝑥 𝜕𝑁2 𝜕𝑥 ⋯ 𝜕𝑁𝑛𝑒𝑛 𝜕𝑥 𝜕𝑁1 𝜕𝑦 𝜕𝑁1 𝜕𝑧 𝜕𝑁2 𝜕𝑦 𝜕𝑁2 𝜕𝑧 ⋯ ⋯ 𝜕𝑁𝑛𝑒𝑛 𝜕𝑦 𝜕𝑁𝑛𝑒𝑛 𝜕𝑧 𝑢1 𝑢1 ⋮ 𝑢𝑛𝑒𝑛 = 𝜕𝑵 𝜕𝒙 𝐮 ∇𝑤 = 𝜕𝑵 𝜕𝒙 𝐰
  • 20. Discretised problem • Weak form: Ω ∇𝑤 ∙ ∇𝑢 𝑑𝑉 = Ω 𝑤 𝑓 𝑑𝑉 + Γ𝑁 𝑤 𝑡 𝑑𝐴 • Using the discretization, the system of equations can be written as 𝐊 𝐮 = 𝐅 where, 𝐊 = 𝐀 e=1 𝐊𝒆; 𝐊𝒆 = Ω𝑒 𝜕𝑵 𝜕𝑥 𝑇 𝜕𝑵 𝜕𝑥 𝑑𝑉 𝐅 = 𝐀 e=1 𝐅𝒆; 𝐅𝒆 = Ω𝑒 𝑵𝑇𝑓𝑑𝑉 + Γ𝑁 𝑒 𝑵𝑇𝑡 𝑑𝐴 20
  • 21. FEM ingredients We need to evaluate 𝐊 = 𝐀 e=1 𝐊𝒆; 𝐊𝒆 = Ω𝑒 𝜕𝑵 𝜕𝑥 𝑇 𝜕𝑵 𝜕𝑥 𝑑𝑉 𝐅 = 𝐀 e=1 𝐅𝒆 ; 𝐅𝒆 = Ω𝑒 𝑵𝑇 𝑓𝑑𝑉 + Γ𝑁 𝑒 𝑵𝑇 𝑡 𝑑𝐴 Information needed: • Mesh – nodal coordinates and connectivity • Element – basis functions • Stiffness matrix and force vector - numerical quadrature • Linear system – matrix solver (LU, CG, etc..) 21
  • 23. Introduction to FreeFEM 23 • An opensource library for FEM. • Not an application/solver library like OpenFOAM. • Library that provides all the basic FEM ingredients. • To develop custom solvers. Well supported. Easy to install and use. Up-to-date tutorials. x Supports triangular and tetrahedral elements only. • Input through scripts • File extension “.edp” • Similar to C++ syntax • No need to compile • FreeFem++.exe <inp-script-file>
  • 26. Tutorial #1 // The triangulated domain Th mesh Th = square(10,10); // The finite element space defined over Th is called here Vh fespace Vh(Th, P1); // Define u and w in the function space Vh u, w; // Define functions func uexact = (cosh(pi*y)-sinh(pi*y)/tanh(pi))*sin(pi*x); func f= 0; Mesh over a square or mapped square Finite element space. Element type, order etc. P1 is 3-noded triangle. Solution and test function Functions for use 26
  • 27. Tutorial #1 (cont’d) // Define the weak formulation solve Poisson(u, w, solver=LU) = int2d(Th)( // The bilinear part dx(w)*dx(u) + dy(w)*dy(u) ) - int2d(Th)( // The right hand side w*f ) // The Dirichlet boundary condition + on(1,2,3,4, u=uexact) ; // Plot the result plot(u); load "iovtk" int[int] Order = [1]; string filename = "Poisson2D-square-Dirichlet.vtu"; savevtk(filename, Th, u, dataname="u", order=Order); Weak form LHS Weak form RHS Boundary conditions Plot the solution Export solution in VTK format. Available only as first-order elements. 27 Ω 𝜕𝑤 𝜕𝑥 𝜕𝑢 𝜕𝑥 + 𝜕𝑤 𝜕𝑦 𝜕𝑢 𝜕𝑦 𝑑𝑉 = Ω 𝑤 𝑓 𝑑𝑉 + Γ𝑁 𝑤 𝑡 𝑑𝐴
  • 28. Tutorial #1 (cont’d) // Error real error = int2d(Th)( (uexact-u)^2 ); error = sqrt(error); 28 • Error 𝑒 = 𝑢𝑒𝑥𝑎𝑐𝑡 − 𝑢 • L2 norm of error 𝑒𝐿2 = Ω 𝑒2 𝑑𝑉 = Ω (𝑢𝑒𝑥𝑎𝑐𝑡 − 𝑢)2 𝑑𝑉
  • 29. Exercise #1 29 • Different number of elements // The triangulated domain Th mesh Th = square(10,10); mesh Th = square(20,20); mesh Th = square(80,80); • Different orders of element // The finite element space defined over Th is called here Vh fespace Vh(Th, P1); fespace Vh(Th, P2); load "Element_P3"; fespace Vh(Th, P3); Solve the problem in Tutorial 1 using different number of elements and different orders of elements and observe the error.
  • 31. Tutorial #2 31 Ω ∇𝑤 ∙ ∇𝑢𝑑𝑉 = Ω 𝑤 𝑓 𝑑𝑉 + Γ𝑁 𝑤 𝑡 𝑑𝐴
  • 32. Tutorial #2 (cont’d) // Define the weak form solve Poisson(u, w, solver=LU) = int2d(Th)( // The bilinear part dx(w)*dx(u) + dy(w)*dy(u) ) - int2d(Th)( // Source term w*f ) - int1d(Th,3)( // Neumann BC term w*tbar ) + on(1,2,4, u=20) // Dirichlet BC ; 32 Ω 𝜕𝑤 𝜕𝑥 𝜕𝑢 𝜕𝑥 + 𝜕𝑤 𝜕𝑦 𝜕𝑢 𝜕𝑦 𝑑𝑉 = Ω 𝑤 𝑓 𝑑𝑉 + Γ𝑁 𝑤 𝑡 𝑑𝐴
  • 34. “square” function // The triangulated domain Th // unit square, starting at (0,0) mesh Th = square(10, 10); // rectangle of size 10x5, starting at (0,0) mesh Th = square(10, 10, [10*x, 5*y]); // rectangle of size 5x10, starting at (-4,-2) mesh Th = square(10, 10, [-4+5*x, -2+10*y]); 34 //display mesh plot(Th);
  • 35. Complex geometries – inbuilt functions int boundary = 1; border C01(t=0, 1){x=t; y=0.0; label=boundary;} border C02(t=0, 1){x=1; y=0.5*t; label=boundary;} border C03(t=0, 1){x=1.0-0.5*t; y=0.5; label=boundary;} border C04(t=0, 1){x=0.5; y=0.5+0.5*t; label=boundary;} border C05(t=0, 1){x=0.5-0.5*t; y=1.0; label=boundary;} border C06(t=0, 1){x=0.0; y=1-t; label=boundary;} int n = 20; mesh Th = buildmesh(C01(n) + C02(n/2) + C03(n/2) + C04(n/2) + C05(n/2) + C06(n)); plot(Th); C01 C02 C03 C04 C05 C06 35 https://doc.freefem.org/examples/mesh-generation.html
  • 36. Complex geometries – using GMSH load "gmsh" // The triangulated domain Th mesh Th = gmshload("Lshaped-gmsh-mesh.msh"); int boundary = 1; mesh Th = gmshload("cylinder-gmsh-mesh.msh"); int inlet = 1; int outlet = 2; int topwall = 3; int bottomwall = 4; int cylinder = 5; 36 //display mesh plot(Th);
  • 38. Exercise #2 Solve the Poisson equation over the L-shaped domain. Use the mesh from “Lshaped-gmsh-mesh.msh”. 𝑢 = 0 on all boundaries. 𝑓 = 20 38
  • 40. Exercise #3 Solve the Poisson equation for the following problem. Use the mesh from “cylinder-gmsh-mesh.msh”. 𝑢 = 10 𝜕𝑢 𝜕𝑦 = 0 𝜕𝑢 𝜕𝑦 = −2 𝑢 = 30 𝑓 = 0 𝑢 = 50 40
  • 42. 42
  • 43. Access to matrix and vector // Define the weak (variational) formulation varf PoissonLHS(u, w) = int2d(Th)( // The bilinear part dx(w)*dx(u) + dy(w)*dy(u) ) // The Dirichlet boundary condition + on(1,2,3,4, u=uexact) ; matrix A = PoissonLHS(Vh, Vh); //stiffness matrix cout << A << endl; // Define the weak (variational) formulation varf PoissonRHS(unused, w) = int2d(Th)( f*w ) // The Dirichlet boundary condition + on(1,2,3,4, u=uexact) ; Vh F; //F[] is the vector associated to the function F F[] = PoissonRHS(0,Vh); cout << F[] << endl; //u[] is the vector associated to the function u u[] = A^-1*F[]; cout << u[] << endl; 43
  • 44. More practice with FreeFEM • FreeFEM - Getting started https://doc.freefem.org/tutorials/poisson.html • FreeFEM – Additional examples https://doc.freefem.org/tutorials/index.html 44
  • 45. 45
  • 46. 46