Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
13 views

lecture_01_fenics_introduction

FEniCS is an automated programming environment for solving differential equations using a C++/Python library, initiated in 2003. It automates various processes such as the generation of basis functions and finite element assembly, and has been utilized in fields like computational hemodynamics and hyperelasticity. The course provides an introduction to FEniCS, including installation instructions and a basic API overview.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

lecture_01_fenics_introduction

FEniCS is an automated programming environment for solving differential equations using a C++/Python library, initiated in 2003. It automates various processes such as the generation of basis functions and finite element assembly, and has been utilized in fields like computational hemodynamics and hyperelasticity. The course provides an introduction to FEniCS, including installation instructions and a basic API overview.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

FEniCS Course

Lecture 1: Introduction to FEniCS

Contributors
Anders Logg
1 / 14
What is FEniCS?

2 / 14
FEniCS is an automated programming
environment for differential equations

• C++/Python library
• Initiated 2003 in Chicago
• 1000–2000 monthly downloads
• Part of Debian and Ubuntu
• Licensed under the GNU LGPL

http://fenicsproject.org/

Collaborators
Simula Research Laboratory, University of Cambridge,
University of Chicago, Texas Tech University, KTH Royal
Institute of Technology, . . .

3 / 14
FEniCS is automated FEM
• Automated generation of basis functions
• Automated evaluation of variational forms
• Automated finite element assembly
• Automated adaptive error control

4 / 14
What has FEniCS been used for?

5 / 14
Computational hemodynamics

• Low wall shear stress may trigger aneurysm growth


• Solve the incompressible Navier–Stokes equations on
patient-specific geometries

u̇ + u · ∇u − ∇ · σ(u, p) = f
∇·u=0

Valen-Sendstad, Mardal, Logg, Computational hemodynamics (2011)


6 / 14
Computational hemodynamics (contd.)

# Define Cauchy stress tensor


def sigma (v , w ) :
return 2 . 0 * mu * 0 . 5 * ( grad ( v ) + grad ( v ) . T ) -
w * Identity ( v . cell () . d )

# Define symmetric gradient


def epsilon ( v ) :
return 0 . 5 * ( grad ( v ) + grad ( v ) . T )

# Tentative velocity step ( sigma formulation )


U = 0 . 5 * ( u0 + u )
F1 = rho * ( 1 / k ) * inner (v , u - u0 ) * dx +
rho * inner (v , grad ( u0 ) * ( u0 - w ) ) * dx \
+ inner ( epsilon ( v ) , sigma (U , p0 ) ) * dx \
+ inner (v , p0 * n ) * ds - mu * inner ( grad ( U ) . T *n ,
v ) * ds \
- inner (v , f ) * dx
a1 = lhs ( F1 )
L1 = rhs ( F1 )

# Pressure correction
a2 = inner ( grad ( q ) , k * grad ( p ) ) * dx
L2 = inner ( grad ( q ) , k * grad ( p0 ) ) * dx -
q * div ( u1 ) * dx

# Velocity correction
a3 = inner (v , u ) * dx
L3 = inner (v , u1 ) * dx + inner (v , k * grad ( p0 -
p1 ) ) * dx

• The Navier–Stokes solver is implemented in Python/FEniCS


• FEniCS allows solvers to be implemented in a minimal amount of code
Valen-Sendstad, Mardal, Logg, Computational hemodynamics (2011) 7 / 14
Hyperelasticity

class Twist ( Stat icHy perel ast i ci t y ) :

def mesh ( self ) :


n = 8
return UnitCube (n , n , n )

def dirichlet_conditions ( self ) :


clamp = Expression (( " 0 . 0 " , " 0 . 0 " ,
"0.0"))
twist = Expression (( " 0 . 0 " ,
" y0 + ( x [ 1 ] - y0 ) * cos ( theta )
- ( x [ 2 ] - z0 ) * sin ( theta ) - x [ 1 ] " ,
" z0 + ( x [ 1 ] - y0 ) * sin ( theta )
+ ( x [ 2 ] - z0 ) * cos ( theta ) - x [ 2 ] " ) )
twist . y0 = 0 . 5
twist . z0 = 0 . 5
twist . theta = pi / 3
return [ clamp , twist ]

def dirichlet_boundaries ( self ) :


return [ " x [ 0 ] == 0 . 0 " , " x [ 0 ] == 1 . 0 " ]

def material_model ( self ) :


mu = 3 . 8461
lmbda =
Expression ( " x [ 0 ]* 5 . 8 +( 1 - x [ 0 ]) * 5 . 7 " )

material = StVenantKirchhoff ( [ mu ,
lmbda ] )
return material

def __str__ ( self ) :


return " A cube twisted by 60 degrees "

• CBC.Solve is a collection of FEniCS-based solvers developed at CBC


• CBC.Twist, CBC.Flow, CBC.Swing, CBC.Beat, . . .
H. Narayanan, A computational framework for nonlinear elasticity (2011) 8 / 14
How to use FEniCS?

9 / 14
Hello World in FEniCS: problem formulation

Poisson’s equation

−∆u = f in Ω
u=0 on ∂Ω

Finite element formulation


Find u ∈ V such that
Z Z
∇u · ∇v dx = f v dx ∀v∈V
Ω Ω
| {z } | {z }
a(u,v) L(v)

10 / 14
Hello World in FEniCS: implementation

from dolfin import *

mesh = UnitSquare ( 32 , 32 )

V = FunctionSpace ( mesh , " Lagrange " , 1 )


u = TrialFunction ( V )
v = TestFunction ( V )
f = Expression ( " x [ 0 ]* x [ 1 ] " )

a = dot ( grad ( u ) , grad ( v ) ) * dx


L = f * v * dx

bc = DirichletBC (V , 0 .0 , DomainBoundary () )

u = Function ( V )
solve ( a = = L , u , bc )
plot ( u )

11 / 14
Basic API

• Mesh Vertex, Edge, Face, Facet, Cell


• FiniteElement, FunctionSpace
• TrialFunction, TestFunction, Function
• grad(), curl(), div(), . . .
• Matrix, Vector, KrylovSolver, LUSolver
• assemble(), solve(), plot()

• Python interface generated semi-automatically by SWIG


• C++ and Python interfaces almost identical

12 / 14
Installation

Official packages for Debian and Ubuntu

Drag and drop installation on Mac OS X

Binary installer for Windows

Automated installation from source

13 / 14
The FEniCS challenge!

Install FEniCS on your laptop!

http://fenicsproject.org/download/

14 / 14

You might also like