Introduction to CFD analysis . Grid genaration, application of CFD in various disciplines.
Size: 5.42 MB
Language: en
Added: Jun 01, 2024
Slides: 46 pages
Slide Content
A short course on FEM for CFD Week 1 : Basics of FEM and FreeFEM , and Poisson equation Dr Chennakesava Kadapa Email: [email protected] 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 Acceleration term Viscous term Pressure gradient Local Acceleration Convective Acceleration Body force 5
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 ( ) 8
Poisson’s equation (Cont’d) We can also write as where is the gradient operator and is the divergence operator. Gradient operator ( ) Thus 9
Boundary conditions Boundary conditions Dirichlet boundary condition: Neumann boundary condition: 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 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 ● is a node. 19
Discretised problem Weak form: Using the discretization, the system of equations can be written as where, 20
FEM ingredients We need to evaluate 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. 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 = ; 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
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, 1 0); // rectangle of size 10x5, starting at (0,0) mesh Th = square(10, 1 0, [10*x, 5*y]); // rectangle of size 5x10, starting at (-4,-2) mesh Th = square(10, 1 0, [-4+5*x, -2+10*y]); 34 //display mesh plot(Th);
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 ”. on all boundaries. 38
Solution for exercise #2 39
Exercise #3 Solve the Poisson equation for the following problem. Use the mesh from “ cylinder- gmsh - mesh.msh ”. 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