You are on page 1of 37

Tutorial: The Finite Element Method

Radek Slesinger

Czech Metrology Institute

MechProNO 30-Months Meeting


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)

General numerical method for solving PDEs


Invented independently in 1940s, to solve elasticity and structural
analysis problems
Intensively developed in 1960s and 1970s with computers becoming
more available, gained a rigorous mathematical basis
Presently used in a variety of disciplines
Large number of software implementations, ranging from simple &
free through complex & free to complex & expensive


Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 3 / 37
Key notions

Discretization method: computational volume divided into a finite


number of elementary volumes (elements) mesh
Solution sought in the form of combination of simple functions
defined at the individual elements
Instead of the original equation, so-called weak form used for solving
(weak solution). If the original equation has a solution, it is equal to
the weak solution.
Boundary conditions
I Prescribed values the solution should satisfy at (a part of) boundary of
the computational domain
I Determine a unique solution out of a large set of solutions
I Dirichlet: u = f on D
I Neumann: u n = g on N


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

Subdivision of the domain into a number of elements


Topic for algorithm research (how to make a good mesh, how to
compute it quickly)
In general, finer mesh = better result
Mesh quality also important:
I narrow angles = slower convergence of equation solve
I wide angles = lower approximation quality of the result
Mesh optimization (reshape bad looking cells) spend 5 minutes
more on mesh generation = save 30 minutes on computation

Element shape (depends on what FEM software used supports)


2D triangles, 3D tetrahedra
2D rectangles, 3D hexahedra
others (e.g. curved)

Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 7 / 37
Function space

Define elementary functions residing at mesh elements, of which the


solution is combined
Most common: Lagrange elements (continuous functions, values
calculated at vertices, interpolated by a function in the rest of the cell):
constant function (order 0)
linear function (order 1)
polynomial (better precision; requires more DOFs = much more
time & memory; order 2)

For some problems/quantities, other element types (e.g. discontinuous,


involving derivatives, . . . ) are better suitable, or even required


Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 8 / 37
Assembly

Computing the problem matrix A and vector b (may be very large


millions of rows/columns)
Apply Dirichlet boundary conditions put prescribed boundary values
into the matrix and vector
Sparse matrices (most integrals equal 0 since each function is zero
almost everywhere) = efficient storage

http://en.wikipedia.org/wiki/Sparse matrix http://dpo.github.io/pyorder/pymc60.html


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

Krylov solver (iterative solver)


sequence of solution approximations in a sequence of subspaces of the
large space, converging to the exact solution, stops when error is low;
matrix contents not important, only the matrix action on vectors: Ax
necessary for large problems

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

Compute additional quantities (e.g. gradient of solution: electric field


intensity from potential, strain from displacement)
Solve another problem using u as input
View & evaluate results


Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 11 / 37
Meshing

Input as boundary representation


Need to define geometry from bottom to top:
points edges surfaces volumes
Can use measurement data as input
Tetgen
Netgen
GMSH choice of algorithms, including Tetgen & Netgen; GUI /
batch mode

Input as CSG (Constructive Solid Geometry)


Unions/intersections/differences of elementary objects (cubes,
cylinders, balls, . . . )
Input from CAD and 3D modelling tools


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

OpenMP (Open Multi-Processing)


API for shared memory multiprocessing (threads)
Extension to C/C++/Fortran, compiler support required


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

Standard formats for computational data exchange and processing


(VTK, HDF5, XDMF)
ParaView
MayaVi


Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 16 / 37
Free FEM packages

A large number of tools (developed using different approaches,


programming languages, targeted for specific use, . . . )

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

Si3 N4 cantilever (E = 350 GPa, = 0.25)


l = 5 m, b = 1 m, h = 50 nm, F = 96 nN
Clamped at one end, force applied from above at the middle of the
other end
Solving equation
Z Z
((u), (v )) dx = (v , g ) ds
load

with Dirichlet BC u = 0 on D = {x | x0 = 0}, and


load = {x | x0 near 5, x1 near 0.5, x2 = 0.05}


Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 18 / 37
Geometry

Point (1) = {0 ,0 ,0}; Line (11) = {3 ,7};


Point (2) = {5 ,0 ,0}; Line (12) = {4 ,8};
Point (3) = {5 ,1 ,0};
Point (4) = {0 ,1 ,0}; Line Loop (1) = {1 ,2 ,3 ,4};
Line Loop (2) = { -5 , -6 , -7 , -8};
Point (5) = {0 ,0 ,0.05};
Point (6) = {5 ,0 ,0.05}; Line Loop (3) = { -4 ,12 ,8 , -9};
Point (7) = {5 ,1 ,0.05}; Line Loop (4) = { -1 ,9 ,5 , -10};
Point (8) = {0 ,1 ,0.05}; Line Loop (5) = { -2 ,10 ,6 , -11};
Line Loop (6) = { -3 ,11 ,7 , -12};
Line (1) = {1 ,2};
Line (2) = {2 ,3}; Plane Surface (1) = {1};
Line (3) = {3 ,4}; Plane Surface (2) = {2};
Line (4) = {4 ,1}; Plane Surface (3) = {3};
Plane Surface (4) = {4};
Line (5) = {5 ,6}; Plane Surface (5) = {5};
Line (6) = {6 ,7}; Plane Surface (6) = {6};
Line (7) = {7 ,8};
Line (8) = {8 ,5}; Surface Loop (1) = {1 ,2 ,3 ,4 ,5 ,6};
Volume (1) = {1};
Line (9) = {1 ,5};
Line (10) = {2 ,6};


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)

Mesh too coarse: difficult to define geometrical subregions (for boundary


conditions, applying load, . . . ) not enough points/facets satisfying given
conditions


Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 21 / 37
Code example

# !/ usr / bin / python

from dolfin import *

mesh = Mesh ( " beam . xml " )

V = Vecto r F un c t io n S pa c e ( mesh , " Lagrange " , 2)

E = 350 e9
nu = 0.25

lmbda = E * nu / ((1.0 + nu ) * (1.0 - 2.0* nu ))


mu = E / (2 * (1 + nu ))

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 ()

class Load ( SubDomain ):


def inside ( self , x , on_boundary ):
return (( x [0] >= 4.88) and near ( x [2] ,0.05)
and between ( x [1] ,(0.43 ,0.57)) and on_boundary )
load = Load ()

bc_fixed = DirichletBC (V , Constant ((0 ,0 ,0)) , fixed )


bcs = [ bc_fixed ]

boundaries = FacetFunction ( " size_t " , mesh )


boundaries . set_all (0)
fixed . mark ( boundaries ,1)
load . mark ( boundaries ,2)
ds = ds ( domain = mesh , subdomain_data = boundaries )

Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 23 / 37
Code example

tr_load = -96000
contact_area = assemble (1* ds (2))

g = Constant ((0 ,0 , tr_load / contact_area ))

def epsilon ( v ):
return 0.5 * ( grad ( v ) + transpose ( grad ( v )))

def sigma ( v ):
return 2 * mu * epsilon ( v ) + lmbda * tr ( epsilon ( v ))

a = inner ( grad ( v ) , sigma ( u ))* dx


L = inner (v , g )* ds (2)

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 )

file = File ( " beam . pvd " )


file << u


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

Formula (length l, width b, thickness h):

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

Error of the calculated solution can be estimated. Too high? = Increase


number of elements (refine mesh) or element order too expensive.

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)

Solved as part of an internal CMI project.


Aim: evaluate how surface roughness can affect nanoindentation
measurement results
Sample:
prepared using plasma-enhanced chemical vapor deposition of a
mixture of hexamethyldisiloxane (C6 H1 8Si12 HMDSO) and oxygen,
deposited on monocrystalline silicon substrate of (111) orientation
a layer of HMDSO particles in amorphous SiOx Cy Hz with a thickness
of 6050 nm
very elastic (E around 10 GPa)
low plasticity


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

Distribution of reduced elasticity modulus.


Green: value for flat surface


Radek Slesinger (CMI) Tutorial: The Finite Element Method MechProNO 30M Meeting 34 / 37
Simulated scan along a profile

Profile scheme Reduced elasticity modulus


along profile (red) compared
to height (green)
Blue: value for flat surface


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

You might also like