using fenics for finite element methods

26
Using FEniCS for Finite Element Methods Andrew Gillette UC San Diego Department of Mathematics August 2012 slides adapted from a longer presentation by Johan Hake, Simula Research Laboratory, Norway Andrew Gillette - UCSD FEniCS for Finite Element Methods NBCR Summer Institute 2012 1 / 26

Upload: doandiep

Post on 02-Jan-2017

230 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 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

Page 2: Using FEniCS for Finite Element Methods

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

Page 3: Using FEniCS for Finite Element Methods

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

Page 4: Using FEniCS for Finite Element Methods

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

Page 5: Using FEniCS for Finite Element Methods

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

Page 6: Using FEniCS for Finite Element Methods

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

Page 7: Using FEniCS for Finite Element Methods

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

Page 8: Using FEniCS for Finite Element Methods

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

Page 9: Using FEniCS for Finite Element Methods

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

Page 10: Using FEniCS for Finite Element Methods

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

Page 11: Using FEniCS for Finite Element Methods

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

Page 12: Using FEniCS for Finite Element Methods

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

Page 13: Using FEniCS for Finite Element Methods

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

Page 14: Using FEniCS for Finite Element Methods

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

Page 15: Using FEniCS for Finite Element Methods

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

Page 16: Using FEniCS for Finite Element Methods

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

Page 17: Using FEniCS for Finite Element Methods

Diffusion equation solved using PyDOLFIN

(Domain declarations)

Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 17 / 26

Page 18: Using FEniCS for Finite Element Methods

Diffusion equation solved using PyDOLFIN

(Domain declarations)

Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 18 / 26

Page 19: Using FEniCS for Finite Element Methods

Diffusion equation solved using PyDOLFIN

(Domain declarations)

Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 19 / 26

Page 20: Using FEniCS for Finite Element Methods

Diffusion equation solved using PyDOLFIN

(Domain declarations)

Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 20 / 26

Page 21: Using FEniCS for Finite Element Methods

Diffusion equation solved using PyDOLFIN

(linear algebra initialization)

Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 21 / 26

Page 22: Using FEniCS for Finite Element Methods

Diffusion equation solved using PyDOLFIN

(linear algebra initialization)

Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 22 / 26

Page 23: Using FEniCS for Finite Element Methods

Diffusion equation solved using PyDOLFIN

(linear algebra initialization)

Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 23 / 26

Page 24: Using FEniCS for Finite Element Methods

Diffusion equation solved using PyDOLFIN

(linear algebra initialization)

Andrew Gillette - UCSD ()FEniCS for Finite Element Methods NBCR Summer Institute 2012 24 / 26

Page 25: Using FEniCS for Finite Element Methods

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

Page 26: Using FEniCS for Finite Element Methods

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