Finite Element Modeling of a Plate with … Finite Element ...
Using FEniCS for Finite Element Methods
Transcript of Using FEniCS for Finite Element Methods
Using FEniCS for Finite Element Methods
Andrew Gillette
UC San DiegoDepartment of Mathematics
August 2012
slides adapted from a longer presentation byJohan Hake, Simula Research Laboratory, Norway
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 1 / 26
The finite element method (FEM) can be used to
discretize and solve PDEs for general geometries
∇2u = 0
u(x) = 100 at B1
u(x) = 0 at B2
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 2 / 26
FEniCS and PyDOLFIN are computational tools that
bundle a lot of subtle problem setup into a simple
interface
∂c
∂t= D∇2c
www.fenics.org
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 3 / 26
We will first use FEniCS to solve a stationary diffusion
problem, the Poisson equation on the unit interval
Poisson
−u′′ = f ; u′(0) = 4; u(1) = 0
Source, f(x) Solution, u(x)
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 4 / 26
The problem can be stated, solved and plotted, using
a PyDOLFIN script written in 16 lines
−u′′ = f
u′(0) = 4
u(1) = 0
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 5 / 26
The problem can be stated, solved and plotted, using
a PyDOLFIN script written in 16 lines
−u′′ = f
u′(0) = 4
u(1) = 0
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 6 / 26
The problem can be stated, solved and plotted, using
a PyDOLFIN script written in 16 lines
−u′′ = f
u′(0) = 4
u(1) = 0
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 7 / 26
The problem can be stated, solved and plotted, using
a PyDOLFIN script written in 16 lines
−u′′ = f
u′(0) = 4
u(1) = 0
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 8 / 26
The problem can be stated, solved and plotted, using
a PyDOLFIN script written in 16 lines
−u′′ = f
u′(0) = 4
u(1) = 0
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 9 / 26
The problem can be stated, solved and plotted, using
a PyDOLFIN script written in 16 lines
−u′′ = f
u′(0) = 4
u(1) = 0
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 10 / 26
How did this become a discrete problem?
A FunctionSpace in PyDOLFIN takes a mesh and a finite element asarguments.
The first order Lagrange is the finite element described by thepiecewise linear nodal basis functions.
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 11 / 26
The PDE can be re-written using the discrete weak
formulation
Strong formulation
−u′′ = f
Should be true for every point (strong)in space
Discrete weak formulation
u(x) =5∑
j=0
ujφj(x)
−∫ 1
0u′′φidx =
∫ 1
0fφidx, i = 0, ...,5
By weighting theequation with φi andtaking the integralover the wholedomain, we solve anapproximation of u(weak)
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 12 / 26
Integrate the left side ‘by parts’ and simplify
−∫ 1
0u′′φidx =
∫ 1
0u′φ′idx + u′(0)φi(0)− u′(1)φi(1)
This includes the derivatives at the boundaries!
Recall that our boundary conditions implies thatφi(1) = 0 and u′(0) = 4, which gives us:∫ 1
0u′φ′idx =
∫ 1
0fφidx− 4φi(1), i = 0, ...,5
We use v instead of φi and write the variational problem:
Find u ∈ V such that
a(u, v) = L(v), ∀v ∈ V, where
a(u, v) =
∫Ω
u′v′dx and L(v) =
∫Ω
f v dx−∫∂Ω
4v ds
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 13 / 26
FEniCS can be used to describe variational forms,
and PyDOLFIN can be used to solve
VariationalProblems
Mathematical notation: PyDOLFIN notation:
Find u ∈ V such thata(u, v) = L(v), ∀v ∈ V
where:
a(u, v) =
∫Ω
u′v′dx
L(v) =
∫Ω
f v dx−∫∂Ω
4v ds
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 14 / 26
The approach applies to 2D and 3D
−∇2u = f ; ∂u∂n(:, [0,1]) = g; u([0,1], :) = 0
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 15 / 26
Time dependent system, like the diffusion equation,
can be solved using the same framework
PDE
u = D∇2u in Ω
D∂u∂n = J(t) on ∂Ω1
u = 1 on ∂Ω2
u(0, :) = 1
J(t) =
100 : t ≤ Jstop
0 : t > Jstop
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 16 / 26
Diffusion equation solved using PyDOLFIN
(Domain declarations)
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 17 / 26
Diffusion equation solved using PyDOLFIN
(Domain declarations)
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 18 / 26
Diffusion equation solved using PyDOLFIN
(Domain declarations)
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 19 / 26
Diffusion equation solved using PyDOLFIN
(Domain declarations)
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 20 / 26
Diffusion equation solved using PyDOLFIN
(linear algebra initialization)
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 21 / 26
Diffusion equation solved using PyDOLFIN
(linear algebra initialization)
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 22 / 26
Diffusion equation solved using PyDOLFIN
(linear algebra initialization)
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 23 / 26
Diffusion equation solved using PyDOLFIN
(linear algebra initialization)
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 24 / 26
FEniCS is used in real, modern science!
Steady-state Ca2+ distributions about Troponin C, showing theabsence and presence of an electrostatic potential.
Kekenes-Huskey, Gillette, Hake, McCammonFinite Element Estimation of Protein-Ligand Association Rates with Post-Encounter Effects:
Applications to Calcium binding in Troponin C and SERCA,Submitted 2012.
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 25 / 26
Questions?
Slides from this presentation are available at my website:
http://ccom.ucsd.edu/∼agillette
Thanks to Johan Hake for preparing many of these slides!
Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 26 / 26