Professional Documents
Culture Documents
Radek Slesinger
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 1 / 37
Most physical problems described by means of partial differential
equations (PDEs)
Analytical solution (i.e., a formula to calculate the desired quantity in
a given place/time/. . . ) usually available only for trivial cases
Need to find an approximate solution
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 2 / 37
Finite Element Method (FEM)
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 3 / 37
Key notions
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 4 / 37
1 Solving on
= [0, 1]
Divide into 5 cells: [0, 0.2], [0.2, 0.4], [0.4, 0.6], [0.6, 0.8], [0.8, 1.0]
2 Equation in 1D:
u + x u0 = 1
Solve on [0, 1] (u called trial function) with Dirichlet boundary
condition u(1) = 1, i.e. D = {1}, f (x) = 1
3 If the equation above holds, then
hu + x u 0 , v i = h1, v i,
precisely Z 1 Z 1
0
(u v + x u v ) dx = 1 v dx
0 0
also holds for any nice function v (x) defined on [0, 1] (called test
function)
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 5 / 37
1 Restrict the space of nice functions (infinitely many) to simple
functions residing at individual vertices value 1 in the vertex, 0 in
others
I 5 equations for , . . . ,
1 5
I Look for u = a + . . . a calculate the coefficients
1 1 5 5
a1 , . . . , a5
2 Solve
Z 1 Z 1 Z 1
a1 (1 1 + x01 1 ) dx + + a5 (5 1 + x05 1 ) dx = 1 dx
|0 {z } |0 {z } | 0
{z }
.. .. ..
. . .
Z 1 Z 1 Z 1
a1 (1 5 + x01 5 ) dx + + a5 (5 5 + x05 5 ) dx = 5 dx
0 0
| {z } | {z } | 0 {z }
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 6 / 37
Mesh
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 8 / 37
Assembly
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 9 / 37
Solution
Solving linear system Ax = b
Direct solver
calculate the solution explicitly (using matrix element manipulation)
more time- and memory- demanding
Preconditioner
modify the system, instead of Ax = b, solve PAx = Pb
same solution, easier to solve when PA is nicer than A
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 10 / 37
Post-processing & visualization
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 11 / 37
Meshing
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 12 / 37
BLAS (Basic Linear Algebra Subroutines)
Elementary operations (vector-vector, matrix-vector, matrix-matrix)
BLAS (netlib.org) reference implementation, original, free
Intel MKL requires Intel compilers, fast, not free
OpenBLAS with optimization for some modern CPUs (auto-detect),
speed comparable to MKL, free
ATLAS (Automatically Tuned Linear Algebra Software)
optimization for the specific system at compile time, free
Proprietary implementations from high-performance computing
system vendors
GPU-accelerated libraries
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 13 / 37
MPI (Message Parsing Interface)
Standard system for programming and running parallel applications
Supported by a variety of applications, libraries and languages used in
computing
Open MPI
MPICH
Commercial implementations
mpirun -n 200 mycomputation
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 14 / 37
Equation solving
Complex libraries, including a range of configurable solvers
SuiteSparse collection of sparse-matrix tools, includes direct solvers
(UMFPack) usable for smaller/2D problems (memory limitations)
PETSc direct and Krylov solvers, preconditioners, nonlinear solvers,
can be run in parallel, might employ other libraries
Trilinos a large collection of libraries for various computing areas
(incl. solvers and preconditioners)
Python modules
Extending standard capabilities of Python language for practical use in
computations
NumPy data types and functions for working with them
SciPy more advanced functions (numerical integration,
interpolation, regression, optimization, . . . )
SymPy symbolic computations (like Maple, Mathematica, Maxima)
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 15 / 37
Visualization
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 16 / 37
Free FEM packages
FEniCS
Automated solution (user specifies the problem in the weak form,
chooses solving method, no need for low-level programming)
Not domain-specific, modern features, well-documented
SfePy (Simple Finite Elements in Python)
Similar approach (user specifies the problem as combination of
pre-defined terms)
Elmer, deal.II, DUNE, FreeFEM++, Code Aster, MOOSE, many
others
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 17 / 37
Example: beam bending
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 18 / 37
Geometry
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 19 / 37
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 20 / 37
Coarse mesh Fine mesh
(1189 vertices, 3496 cells) (3771 vertices, 11164 cells)
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 21 / 37
Code example
E = 350 e9
nu = 0.25
u = TrialFunction ( V )
v = TestFunction ( V )
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 22 / 37
Code example
class Fixed ( SubDomain ):
def inside ( self , x , on_boundary ):
return ( near ( x [0] , 0.0) and on_boundary )
fixed = Fixed ()
tr_load = -96000
contact_area = assemble (1* ds (2))
def epsilon ( v ):
return 0.5 * ( grad ( v ) + transpose ( grad ( v )))
def sigma ( v ):
return 2 * mu * epsilon ( v ) + lmbda * tr ( epsilon ( v ))
u = Function ( V )
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 24 / 37
Code example
problem = L i n e a r V a r i a t i o n a l P r o b l e m (a ,L ,u , bcs )
solver = L i n e a r V a r i a t i o n a l S o l v e r ( problem )
solver . parameters [ linear_solver ] = petsc
solver . parameters [ preconditioner ] = jacobi
solver . solve ()
plot ( u )
plot ( mesh )
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 25 / 37
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 26 / 37
Effect of mesh quality and element order
4 F l3
d=
E b h3
Formula C1 F1 C2 F2 C3 F3
Time (s) 0 1.4 2.2 4.6 19.6 35 160
Memory (GB) 0 0.075 0.1 0.2 0.6 0.76 2.5
Deflection 1.097 0.139 0.269 1.06 1.07 1.06 1.07
(Timings only for illustration; can be improved using a parallel or Krylov
solver, or using preconditioning)
Formula assumes = 0, i.e. perfectly compressible material;
Standard materials (with > 0) then appear softer than they really are
F 2 using = 0 yields d = 1.09
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 27 / 37
Element locking
occurs with linear (1st order) triangle/tetrahedral elements in
mechanical problems
material appears stiffer due to limited freedom of movement when
some element vertices are fixed (volume preservation)
use higher order (FEniCS) or hexahedral (SfePy) elements
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 28 / 37
Adaptivity
Adaptivity
Refine mesh (h-adaptivity) or use higher-order elements (p-adaptivity) only
locally.
1 Calculate solution.
2 Determine regions with highest error.
3 Refine mesh or increase element order in these regions.
4 Repeat until error is sufficiently low.
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 29 / 37
Roughness effects (A. Charvatova Campbell)
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 30 / 37
AFM scan of sample
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 31 / 37
Example of mesh created from calculated vertices
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 32 / 37
Pattern of imprints Map of reduced elasticity modulus
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 33 / 37
160
140
120
100
f(E)
80
60
40
20
0
5 10 15 20 25 30
Er/GPa
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 34 / 37
Simulated scan along a profile
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 35 / 37
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 36 / 37
The height profile of raw height data (green squares), filtered
height data (green line), FEM simulated contact modulus (red squares)
and Hertz model contact modulus (red line)
Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 37 / 37