FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and...

222
FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1 Mathematics and Computer Science Division Argonne National Laboratory 2 Department of Computer Science University of Chicago March 5, 2007 Workshop on Automating the Development of Scientific Computing Software LSU, Baton Rouge, LA M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 1 / 111

Transcript of FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and...

Page 1: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

FEniCS and Sieve Tutorial

Matthew G Knepley 1 and Andy R Terrel 2

1Mathematics and Computer Science DivisionArgonne National Laboratory

2Department of Computer ScienceUniversity of Chicago

March 5, 2007Workshop on Automating the Development of

Scientific Computing SoftwareLSU, Baton Rouge, LA

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 1 / 111

Page 2: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Tutorial Goals

Introduce FEniCS Automated Mathematical Modeling paradigm

Enable students to develop new simulations with FEniCS

Demonstrate sample problems and typical operations

Describe PETSc-Sieve project

High performance parallel infrastructure

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 2 / 111

Page 3: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Tutorial Goals

Introduce FEniCS Automated Mathematical Modeling paradigm

Enable students to develop new simulations with FEniCS

Demonstrate sample problems and typical operations

Describe PETSc-Sieve project

High performance parallel infrastructure

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 2 / 111

Page 4: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Tutorial Goals

Introduce FEniCS Automated Mathematical Modeling paradigm

Enable students to develop new simulations with FEniCS

Demonstrate sample problems and typical operations

Describe PETSc-Sieve project

High performance parallel infrastructure

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 2 / 111

Page 5: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

FEM Concepts

Outline

1 FEM Concepts

2 Getting Started

3 Poisson

4 Stokes

5 Function and Operator Abstractions

6 Optimal Solvers

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 3 / 111

Page 6: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

FEM Concepts

FEM at a GlanceStrong Form

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 4 / 111

Page 7: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

FEM Concepts

FEM at a GlanceWeak Form

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 4 / 111

Page 8: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

FEM Concepts

FEM at a GlanceDiscretization

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 4 / 111

Page 9: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

FEM Concepts

FEM at a GlanceDiscretization

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 4 / 111

Page 10: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

FEM Concepts

FEM at a GlanceDiscrete System

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 4 / 111

Page 11: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started

Outline

1 FEM Concepts

2 Getting StartedQuick Introduction to FEniCSQuick Introduction to PETScDownload & Install

3 Poisson

4 Stokes

5 Function and Operator Abstractions

6 Optimal Solvers

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 5 / 111

Page 12: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to FEniCS

The FEniCS Project

Started in 2003 as a collaboration between

ChalmersUniversity of Chicago

Now spans

Chalmers and KTHUniversity of Oslo and Simula ResearchUniversity of Chicago and Argonne National LaboratoryCambridge UniversityTU Delft

Focused on Automated Mathematical Modelling

Allows researchers to easily and rapidly develop simulations

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 6 / 111

Page 13: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to FEniCS

The FEniCS Project

DOLFIN: The simulation engine which pulls all the pieces together.

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 6 / 111

Page 14: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to FEniCS

The FEniCS Project

PETSc, uBlas, UMFPACK (separate projects outside FEniCS)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 6 / 111

Page 15: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to FEniCS

The FEniCS Project

FIAT: Finite element Integrator And TabulatorSyFi: SYmbolic FInite elements

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 6 / 111

Page 16: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to FEniCS

The FEniCS Project

FFC: Fenics Form Compiler, or SyFi

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 6 / 111

Page 17: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to FEniCS

The FEniCS Project

DOLFIN Mesh Library

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 6 / 111

Page 18: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to FEniCS

The FEniCS Project

UNICORN: a unified continuum mechanics solver

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 6 / 111

Page 19: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to FEniCS

The FEniCS Project

Other projectsProject Description

UFC Links equation discretization to algebraic solverViper Uses pyvtk to produce quick plotsInstant JIT C compiler for inline functions in pythonPuffin Educational projectFErari Optimizations for evaluation of variational formsSieve Abstractions for parallel mesh and function representation

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 6 / 111

Page 20: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to FEniCS

The FEniCS Project

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 6 / 111

Page 21: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to PETSc

What is PETSc?

A freely available and supported research code

Download from http://www.mcs.anl.gov/petsc

Free for everyone, including industrial users

Hyperlinked manual, examples, and manual pages for all routines

Hundreds of tutorial-style examples

Support via email: [email protected]

Usable from C, C++, Fortran 77/90, and Python

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 7 / 111

Page 22: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to PETSc

What is PETSc?

Portable to any parallel system supporting MPI, including:Tightly coupled systems

Cray T3E, SGI Origin, IBM SP, HP 9000, Sub Enterprise

Loosely coupled systems, such as networks of workstations

Compaq,HP, IBM, SGI, Sun, PCs running Linux or Windows

PETSc History

Begun September 1991Over 20,000 downloads since 1995 (version 2), currently 300 per month

PETSc Funding and SupportDepartment of Energy

SciDAC, MICS Program, INL Reactor Program

National Science Foundation

CIG, CISE, Multidisciplinary Challenge Program

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 7 / 111

Page 23: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to PETSc

What Can We Handle?

PETSc has run problems with over 500 million unknowns

http://www.scconference.org/sc2004/schedule/pdfs/pap111.pdf

PETSc has run on over 6,000 processors efficiently

ftp://info.mcs.anl.gov/pub/tech reports/reports/P776.ps.Z

PETSc applications have run at 2 Teraflops

LANL PFLOTRAN code

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 8 / 111

Page 24: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to PETSc

What Can We Handle?

PETSc has run problems with over 500 million unknowns

http://www.scconference.org/sc2004/schedule/pdfs/pap111.pdf

PETSc has run on over 6,000 processors efficiently

ftp://info.mcs.anl.gov/pub/tech reports/reports/P776.ps.Z

PETSc applications have run at 2 Teraflops

LANL PFLOTRAN code

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 8 / 111

Page 25: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Quick Introduction to PETSc

What Can We Handle?

PETSc has run problems with over 500 million unknowns

http://www.scconference.org/sc2004/schedule/pdfs/pap111.pdf

PETSc has run on over 6,000 processors efficiently

ftp://info.mcs.anl.gov/pub/tech reports/reports/P776.ps.Z

PETSc applications have run at 2 Teraflops

LANL PFLOTRAN code

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 8 / 111

Page 26: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Download & Install

Download and InstallDebian Packages

UFC:apt-get install ufc

FIAT:apt-get install fiat

FFC:apt-get install ffc

DOLFIN:apt-get install dolfin

Viper:apt-get install dolfin

You also needdeb http://www.fenics.org/debian/ unstable main

deb-src http://www.fenics.org/debian/ unstable main

in your /etc/apt/source.list, and the key

wget http://www.fenics.org/debian/pubring.gpg -O- | sudo apt-key add -

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 9 / 111

Page 27: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Download & Install

Download and InstallSource Tarballs

UFC:http://www.fenics.org/pub/software/ufc/v1.0/ufc-1.1.tar.gz

FIAT:http://www.fenics.org/pub/software/fiat/FIAT-0.3.4.tar.gz

FFC:http://www.fenics.org/pub/software/ffc/v0.4/ffc-0.4.4.tar.gz

DOLFIN:http://www.fenics.org/pub/software/dolfin/v0.7/dolfin-0.7.2.tar.gz

Viper:http://www.fenics.org/pub/software/viper/v0.2/viper-0.2.0.tgz

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 9 / 111

Page 28: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Download & Install

Download and InstallMercurial Repositories

UFC:hg clone http://www.fenics.org/hg/ufcpython setup.py install

FIAT:hg clone http://www.fenics.org/hg/fiatpython setup.py install

FFC:hg clone http://www.fenics.org/hg/ffcpython setup.py install

DOLFIN:hg clone http://www.fenics.org/hg/dolfinSee http://www.fenics.org/wiki/DOLFIN

Viper:hg clone http://www.fenics.org/hg/viperpython setup.py install

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 9 / 111

Page 29: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Download & Install

Cloning PETSc

The full development repository is open to the public

http://petsc.cs.iit.edu/petsc/petsc-devhttp://petsc.cs.iit.edu/petsc/BuildSystem

Why is this better?

You can clone to any release (or any specific ChangeSet)You can easily rollback changes (or releases)You can get fixes from us the same day

We also make release repositories available

http://petsc.cs.iit.edu/petsc/petsc-release-2.3.3

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 10 / 111

Page 30: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Getting Started Download & Install

Automatic Downloads

Starting in 2.2.1, some packages are automatically

DownloadedConfigured and Built (in $PETSC DIR/externalpackages)Installed in PETSc

Currently works for

PETSc documentation utilities (Sowing, lgrind, c2html)BLAS, LAPACK, BLACS, ScaLAPACK, PLAPACKMPICH, MPE, LAMParMetis, Chaco, Jostle, Party, Scotch, ZoltanMUMPS, Spooles, SuperLU, SuperLU Dist, UMFPack, pARMSBLOPEX, FFTW, SPRNGPrometheus, HYPRE, ML, SPAISundialsTriangle, TetGenFIAT, FFC, GeneratorBoost

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 11 / 111

Page 31: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson

Outline

1 FEM Concepts

2 Getting Started

3 PoissonProblem StatementHigher Order ElementsDiscontinuous Galerkin MethodsError Checking

4 Stokes

5 Function and Operator Abstractions

6 Optimal SolversM. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 12 / 111

Page 32: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Problem Statement

Simple Example: PoissonPoisson

−∆u = f on Ω = [0, 1]× [0, 1]

Define our Form and compile (FIAT + FFC)

Define our Simulation (DOLFIN)

Define our meshAssemble and solvePost process (visualize, error, ...)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 13 / 111

Page 33: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Problem Statement

Simple Example: PoissonDefining the form

element = FiniteElement("Lagrange", "triangle", 1)

v = TestFunction(element)u = TrialFunction(element)f = Function(element)g = Function(element)

a = dot(grad(v), grad(u))*dxL = v*f*dxa = dot(grad(v), grad(u))*dxL = v*f*dx + v*g*ds

see ffc/src/demo/Poisson.form, and compile with

$ ffc Poisson.form

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 14 / 111

Page 34: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Problem Statement

Simple Example: Poisson

Writing the Simulation: Define our mesh

UnitSquare mesh(32, 32);

Need to give boundary conditions

Could use other meshing tools and convert to Dolfin xml format

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 15 / 111

Page 35: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Problem Statement

Simple Example: Poisson

Writing the Simulation: Assemble and solve

// Create user defined functionsSource f(mesh); Flux g(mesh);// Create boundary conditionFunction u0(mesh, 0.0);DirichletBoundary boundary;DirichletBC bc(u0, mesh, boundary);// Define PDEPoissonBilinearForm a;PoissonLinearForm L(f, g);LinearPDE pde(a, L, mesh, bc);// Solve PDEFunction u;pde.solve(u);

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 16 / 111

Page 36: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Problem Statement

Simple Example: Poisson

Writing the Simulation: Post process

// Plot solutionplot(u);// Save solution to fileFile file("poisson.pvd");file << u;

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 17 / 111

Page 37: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Problem Statement

Simple Example: Poisson

Now let’s define our source term as:

f (x , y) = 500 ∗ exp

(−(x − 0.5)2 + (y − 0.5)2

0.02

)class Source : public Function Source(Mesh& mesh) : Function(mesh) ;real eval(const real* x) const real dx = x[0] - 0.5;real dy = x[1] - 0.5;return 500.0*exp(-(dx*dx + dy*dy)/0.02);

;

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 18 / 111

Page 38: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Problem Statement

Simple Example: Poisson

Boundary conditions given by

u(x , y) = 0 for x = 0

du/dn(x , y) = 25 sin(5πy) for x = 1

du/dn(x , y) = 0 otherwise

class DirichletBoundary : public SubDomain bool inside(const real* x, bool on_boundary) const return x[0] < DOLFIN_EPS && on_boundary;

;class Flux : public Function Flux(Mesh& mesh) : Function(mesh) ;real eval(const real* x) const if (x[0] > DOLFIN_EPS)

return 25.0*sin(5.0*DOLFIN_PI*x[1]);else return 0.0;

;

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 19 / 111

Page 39: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Problem Statement

Simple Example: Poisson

Include headers and your done1

#include <dolfin.h>#include "Poisson.h"using namespace dolfin;

1See dolfin/src/demo/pde/poisson/cppM. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 20 / 111

Page 40: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Problem Statement

Simple Example: Poisson

Simulate!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 21 / 111

Page 41: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Higher Order Elements

Example: High Order PoissonPoisson

This time use higher order Lagrangian elements

−∆u = f on Ω = [0, 1]× [0, 1]

Define our Form and compile (FIAT + FFC)

Define our Simulation (DOLFIN)

Define our meshAssemble and solvePost process (visualize, error, ...)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 22 / 111

Page 42: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Higher Order Elements

Example: High Order PoissonDefining the form

element = FiniteElement("Lagrange", "triangle", p)

v = TestFunction(element)u = TrialFunction(element)f = Function(element)g = Function(element)

a = dot(grad(v), grad(u))*dxL = v*f*dxa = dot(grad(v), grad(u))*dxL = v*f*dx + v*g*ds

Compile with

$ ffc HOPoisson.form

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 23 / 111

Page 43: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Higher Order Elements

Example: High Order Poisson

Use the same DOLFIN code.

Simulate!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 24 / 111

Page 44: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Discontinuous Galerkin Methods

Example: Discontinuous Galerkin PoissonPoisson

−∆u = f on Ω = [0, 1]× [0, 1]

Using a discontinuous Galerkin formulation (interior penalty method).

Define our Form and compile (FIAT + FFC)

Define our Simulation (DOLFIN)

Define our meshAssemble and solvePost process (visualize, error, ...)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 25 / 111

Page 45: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Discontinuous Galerkin Methods

Example: Discontinuous Galerkin PoissonDefining the form

element = FiniteElement("Discontinuous Lagrange","triangle", 1)

...n = FacetNormal("triangle")h = MeshSize("triangle")alpha = 4.0; gamma = 8.0a = dot(grad(v), grad(u))*dx- dot(avg(grad(v)), jump(u, n))*dS- dot(jump(v, n), avg(grad(u)))*dS+ alpha/h(’+’)*dot(jump(v, n), jump(u, n))*dS- dot(grad(v), mult(u, n))*ds- dot(mult(v, n), grad(u))*ds + gamma/h*v*u*ds

see ffc/src/demo/PoissonDG.form, and compile with

$ ffc PoissonDG.form

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 26 / 111

Page 46: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Discontinuous Galerkin Methods

Example: Discontinuous Galerkin PoissonWriting the Simulation: Assemble and solve

// Create user defined functionsSource f(mesh); Flux g(mesh);FacetNormal n(mesh);AvgMeshSize h(mesh);// Define PDEPoissonBilinearForm a;PoissonLinearForm L(f, g);LinearPDE pde(a, L, mesh, bc);// Solve PDEFunction u;pde.solve(u);

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 27 / 111

Page 47: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Discontinuous Galerkin Methods

Example: Discontinuous Galerkin Poisson

Simulate!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 28 / 111

Page 48: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Error Checking

Example: L2 Error Check

L2 Error:

||u − uh||L2(Ω)

Define our Form and compile (FIAT + FFC)

Add to our Simulation (DOLFIN)

Post process (visualize, error, ...)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 29 / 111

Page 49: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Error Checking

Example: L2 Error Check

Defining the form

P0 = FiniteElement("Discontinuous Lagrange", "triangle", 0)Element1 = FiniteElement("Lagrange", "triangle", 1)

U = Function(Element1)u = Function(Element1)v = BasisFunction(P0)

e = U - u

L = v*dot(e,e)*dx

$ ffc L2Error.form

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 30 / 111

Page 50: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Poisson Error Checking

Example: L2 Error Check

Writing the Simulation: Post process

ExactSolution U_ex;Vector tmp;L2Error::LinearForm L2Error(U,u);FEM::assemble(L2Error, tmp, mesh);real error = sqrt(fabs(tmp.sum()));

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 31 / 111

Page 51: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes

Outline

1 FEM Concepts

2 Getting Started

3 Poisson

4 StokesMixed MethodsIterated Penalty Methods

5 Function and Operator Abstractions

6 Optimal Solvers

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 32 / 111

Page 52: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes

Stokes Equations: Basic Fluids ModelingFunction Space Matters

Stokes Equation

Taylor-Hood

Crouzeix-Raviart

Iterated Penalty

−∆u +∇p = f

∇ · u = 0

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 33 / 111

Page 53: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes

Stokes Equations: Basic Fluids ModelingFunction Space Matters

du

dt+ u · ∇u = −∇p

ρ+ ν∆u

Stokes EquationTaylor-HoodCrouzeix-RaviartIterated Penalty

Navier-Stokes

Stokes Solver

Nonlinear Solver

Time Stepping

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 33 / 111

Page 54: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes

Stokes Equations: Basic Fluids ModelingFunction Space Matters

Stokes EquationTaylor-HoodCrouzeix-RaviartIterated Penalty

Navier-StokesStokes SolverNonlinear SolverTime Stepping

Non-NewtonianFlow

Oldroyd-B

Grade 2

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 33 / 111

Page 55: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes

Stokes Equations: Basic Fluids ModelingFunction Space Matters

Stokes EquationTaylor-HoodCrouzeix-RaviartIterated Penalty

Navier-StokesStokes SolverNonlinear SolverTime Stepping

Non-NewtonianOdroyd-BGrade 2...

Fluid Solid Interfaces

Free BoundaryProblems

Couple to legacyCodes

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 33 / 111

Page 56: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Mixed Methods

Stokes Mixed MethodsStokes: Mixed Method Formulation

Let V = H1(Ω)n and Π = q ∈ L2(Ω) :∫

Ω qdx = 0. Given F ∈ V ′, findfunctions u ∈ V and p ∈ Π such that

a(u, v) + b(v, p) = F (v) ∀v ∈ V

b(u, q) = 0 ∀q ∈ Π

Where,

a(u, v) :=

∫Ω∇u · ∇vdx ,

b(v, q) :=

∫Ω

(∇ · v)qdx

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 34 / 111

Page 57: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Mixed Methods

Stokes Mixed MethodDefining the form

P2 = VectorElement("Lagrange", "triangle", 2)P1 = FiniteElement("Lagrange", "triangle", 1)TH = P2 + P1

(v, q) = TestFunctions(TH)(u, p) = TrialFunctions(TH)

f = Function(P2)

a = (dot(grad(v), grad(u)) - div(v)*p + q*div(u))*dxL = dot(v, f)*dx

see dolfin/src/demo/pde/stokes/taylor-hood/cpp/Stokes.form,and compile with

$ ffc Stokes.form

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 35 / 111

Page 58: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Mixed Methods

Stokes Mixed MethodDefine our mesh

Use a predefined mesh, can be made with Triangle, Gmsh, ... andconverted to DOLFIN mesh form with dolfin-convertUse a MeshFunction to mark up different dof on boundary

// Read mesh and sub domain markersMesh mesh("dolfin-2.xml.gz");MeshFunction<unsigned int> sub_domains(mesh,

"subdomains.xml.gz");

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 36 / 111

Page 59: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Mixed Methods

Stokes Mixed MethodNew Boundary Conditions

// Create functions for boundary conditionsNoslip noslip(mesh); Inflow inflow(mesh);Function zero(mesh, 0.0);

// Define sub systems for boundary conditionsSubSystem velocity(0);SubSystem pressure(1);

// BC’s per fieldDirichletBC bc0(noslip, sub_domains, 0, velocity);DirichletBC bc1(inflow, sub_domains, 1, velocity);DirichletBC bc2(zero, sub_domains, 2, pressure);Array <BoundaryCondition*> bcs(&bc0, &bc1, &bc2);

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 37 / 111

Page 60: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Mixed Methods

Stokes Mixed MethodAssemble and solve

// Set up PDEFunction f(mesh, 0.0);StokesBilinearForm a;StokesLinearForm L(f);LinearPDE pde(a, L, mesh, bcs);

// Solve PDEFunction u;Function p;pde.set("PDE linear solver", "direct");pde.solve(u, p);

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 38 / 111

Page 61: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Mixed Methods

Stokes Mixed Method

Writing the Simulation: Post process

// Plot solutionplot(u);plot(p);// Save solution to fileFile file("velocity.pvd");file << u;File file("pressure.pvd");file << p;

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 39 / 111

Page 62: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Mixed Methods

Stokes Mixed Method

// Functions for boundary condition for velocityclass Noslip : public Function public:Noslip(Mesh& mesh) : Function(mesh) void eval(real* values, const real* x) const values[0] = 0.0;values[1] = 0.0;

;class Inflow : public Function public:Inflow(Mesh& mesh) : Function(mesh) void eval(real* values, const real* x) const values[0] = -1.0;values[1] = 0.0;

;

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 40 / 111

Page 63: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Mixed Methods

Stokes Mixed Method

Simulate!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 41 / 111

Page 64: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Iterated Penalty Methods

Iterated PenaltyStokes: Iterated Penalty Formulation

Let r ∈ R and ρ > 0 define un and p = wn by

a(un, v) + r(∇ · un,∇ · v) = F (v)− (∇ · v,∇ ·wn)

wn+1 = wn + ρun

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 42 / 111

Page 65: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Iterated Penalty Methods

Stokes IP MethodDefining the form

Element = FiniteElement("Vector Lagrange", "triangle", 4)

U = TrialFunction(Element)v = TestFunction(Element)f = Function(Element)w = Function(Element)c = Constant()

a = (dot(grad(v), grad(U)) - c * div(U) * (div(v)))*dxL = dot(v, f) * dx + dot(div(v),div(w))*dx

$ ffc Stokes.form

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 43 / 111

Page 66: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Iterated Penalty Methods

Stokes IP MethodAssemble and solve

Setup is relatively the same.

Function f(mesh, 0.0), w, u;real rho, r, div_u_error;Stokes::BilinearForm a(rho);rho = r = 1.0e3;w.init(mesh, a.trial());

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 44 / 111

Page 67: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Iterated Penalty Methods

Stokes IP MethodAssemble and solve

But we iterate our solution based on L2Error.

for(int j; j<MAX_ITERS; j++)Stokes::LinearForm L(f,w);PDE pde(a, L, mesh, bcs);// Compute solutionpde.solve(U);Vector tmp = w.vector() + r * (U.vector());w = Function(tmp);L2div::LinearForm div_u(U);FEM::assemble(div_u, tmp, mesh);div_u_error = sqrt(fabs(tmp.sum()));if (div_u_error < 5.0e-7) break;

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 45 / 111

Page 68: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Iterated Penalty Methods

Stokes IP Method

Simulate!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 46 / 111

Page 69: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Stokes Iterated Penalty Methods

Questions

Fenics Webpage:http://www.fenics.org/

Join the mailing lists!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 47 / 111

Page 70: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions

Outline

1 FEM Concepts

2 Getting Started

3 Poisson

4 Stokes

5 Function and Operator AbstractionsLinear Algebra & Iterative SolversRethinking the MeshParallelismFEM

6 Optimal SolversM. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 48 / 111

Page 71: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Linear Algebra & Iterative Solvers

Linear Algebra Abstractions

Need clear interfaces to ALL levels in the conceptual hierarchy

Abstractions allow reuse of iterative solvers (Krylov methods)

Vec and Mat objectsKSP uses only the action of Mat on Vec, MatMult()

PETSc provides a range of data types

MPIAIJ, MPIAIJPERM, SuperLU, . . .Arbitrary user code accomodated using MATSHELL objects

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 49 / 111

Page 72: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Linear Algebra & Iterative Solvers

Solver Choice

Can choose solver at runtime

-ksp type bicgstab

Can customize solver

-ksp gmres restart 500Inapplicable options are ignored (same with API calls)

Monitoring

-ksp monitor -ksp view

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 50 / 111

Page 73: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Hierarchy Abstractions

Generalize to a set of linear spaces

Spaces interact through an OverlapSieve provides topology, can also model MatSection generalizes Vec

Basic operations

Restriction to finer subspaces, restrict()/update()Assembly to the subdomain, complete()

Allow reuse of geometric and multilevel algorithms

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 51 / 111

Page 74: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Unstructured Interface (before)

Explicit references to element type

getVertices(edgeID), getVertices(faceID)getAdjaceny(edgeID, VERTEX)getAdjaceny(edgeID, dim = 0)

No interface for transitive closure

Awkward nested loops to handle different dimensions

Have to recode for meshes with different

dimensionshapes

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 52 / 111

Page 75: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Unstructured Interface (before)

Explicit references to element type

getVertices(edgeID), getVertices(faceID)getAdjaceny(edgeID, VERTEX)getAdjaceny(edgeID, dim = 0)

No interface for transitive closure

Awkward nested loops to handle different dimensions

Have to recode for meshes with different

dimensionshapes

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 52 / 111

Page 76: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Unstructured Interface (before)

Explicit references to element type

getVertices(edgeID), getVertices(faceID)getAdjaceny(edgeID, VERTEX)getAdjaceny(edgeID, dim = 0)

No interface for transitive closure

Awkward nested loops to handle different dimensions

Have to recode for meshes with different

dimensionshapes

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 52 / 111

Page 77: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Go Back to the Math

Combinatorial Topology gives us a framework for geometric computing.

Abstract to a relation, covering, on points

Points can represent any mesh elementCovering can be thought of as adjacencyRelation can be expressed in a DAG (for cell complexes)

Simple query set:

provides a general API for geometric algorithmsleads to simpler implementationscan be more easily optimized

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 53 / 111

Page 78: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Go Back to the Math

Combinatorial Topology gives us a framework for geometric computing.

Abstract to a relation, covering, on points

Points can represent any mesh elementCovering can be thought of as adjacencyRelation can be expressed in a DAG (for cell complexes)

Simple query set:

provides a general API for geometric algorithmsleads to simpler implementationscan be more easily optimized

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 53 / 111

Page 79: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Go Back to the Math

Combinatorial Topology gives us a framework for geometric computing.

Abstract to a relation, covering, on points

Points can represent any mesh elementCovering can be thought of as adjacencyRelation can be expressed in a DAG (for cell complexes)

Simple query set:

provides a general API for geometric algorithmsleads to simpler implementationscan be more easily optimized

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 53 / 111

Page 80: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Unstructured Interface (after)

NO explicit references to element type

A point may be any mesh elementgetCone(point): adjacent (d-1)-elementsgetSupport(point): adjacent (d+1)-elements

Transitive closure

closure(cell): The computational unit for FEM

Algorithms independent of mesh

dimensionshape (even hybrid)global topology

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 54 / 111

Page 81: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Unstructured Interface (after)

NO explicit references to element type

A point may be any mesh elementgetCone(point): adjacent (d-1)-elementsgetSupport(point): adjacent (d+1)-elements

Transitive closure

closure(cell): The computational unit for FEM

Algorithms independent of mesh

dimensionshape (even hybrid)global topology

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 54 / 111

Page 82: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Unstructured Interface (after)

NO explicit references to element type

A point may be any mesh elementgetCone(point): adjacent (d-1)-elementsgetSupport(point): adjacent (d+1)-elements

Transitive closure

closure(cell): The computational unit for FEM

Algorithms independent of mesh

dimensionshape (even hybrid)global topology

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 54 / 111

Page 83: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Mesh

5

6

1

2

40

7 8 9 10

0 1

2 3 5 6

7 10

8

9

3

4

Incidence/covering arrowscone(0) = 2, 3, 4support(7) = 2, 3

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 55 / 111

Page 84: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Mesh

5

6

1

2

40

7 8 9 10

0 1

2 3 5 6

7 10

8

9

3

4

Incidence/covering arrowscone(0) = 2, 3, 4support(7) = 2, 3

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 55 / 111

Page 85: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Mesh

5

6

1

2

40

7 8 9 10

0 1

2 3 5 6

7 10

8

9

3

4

Incidence/covering arrowscone(0) = 2, 3, 4support(7) = 2, 3

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 55 / 111

Page 86: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Mesh

5

6

1

2

40

7 8 9 10

0 1

2 3 5 6

7 10

8

9

3

4

Incidence/covering arrowsclosure(0) = 0, 2, 3, 4, 7, 8, 9star(7) = 7, 2, 3, 0

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 55 / 111

Page 87: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Mesh

5

6

1

2

40

7 8 9 10

0 1

2 3 5 6

7 10

8

9

3

4

Incidence/covering arrowsclosure(0) = 0, 2, 3, 4, 7, 8, 9star(7) = 7, 2, 3, 0

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 55 / 111

Page 88: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Section

v1

v3

e3

e5

e4

v2

v4

e2

e1

e6

e8

e7

e9

e0

f1

f2

e9

e0

2

e1

e2e7

e8e3

e4e5

e6

3 4 5 6

v2

v1

f1

f2v3

v4

87 0 1 109

5

62

47 10

8

9

3

10

Map interface

restrict(0) = f 1restrict(7) = v1restrict(4) = 7, 8

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 56 / 111

Page 89: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Section

v1

v3

e3

e5

e4

v2

v4

e2

e1

e6

e8

e7

e9

e0

f1

f2

e9

e0

2

e1

e2e7

e8e3

e4e5

e6

3 4 5 6

v2

v1

f1

f2v3

v4

87 0 1 109

5

62

47 10

8

9

3

10

Map interface

restrict(0) = f 1restrict(7) = v1restrict(4) = 7, 8

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 56 / 111

Page 90: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Section

v1

v3

e3

e5

e4

v2

v4

e2

e1

e6

e8

e7

e9

e0

f1

f2

e9

e0

2

e1

e2e7

e8e3

e4e5

e6

3 4 5 6

v2

v1

f1

f2v3

v4

87 0 1 109

5

62

47 10

8

9

3

10

Map interface

restrict(0) = f 1restrict(7) = v1restrict(4) = 7, 8

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 56 / 111

Page 91: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Section

v1

v3

e3

e5

e4

v2

v4

e2

e1

e6

e8

e7

e9

e0

f1

f2

e9

e0

2

e1

e2e7

e8e3

e4e5

e6

3 4 5 6

v2

v1

f1

f2v3

v4

87 0 1 109

5

62

47 10

8

9

3

10

Map interface

restrict(0) = f 1restrict(7) = v1restrict(4) = 7, 8

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 56 / 111

Page 92: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Section

v1

v3

e3

e5

e4

v2

v4

e2

e1

e6

e8

e7

e9

e0

f1

f2

e9

e0

2

e1

e2e7

e8e3

e4e5

e6

3 4 5 6

v2

v1

f1

f2v3

v4

87 0 1 109

5

62

47 10

8

9

3

10

Topological traversals: follow connectivity

restrictClosure(0) = f 1v1e1e2v2e8e7v4e9e0restrictStar(7) = v1e1e2f 1e0e9

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 56 / 111

Page 93: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Section

v1

v3

e3

e5

e4

v2

v4

e2

e1

e6

e8

e7

e9

e0

f1

f2

e9

e0

2

e1

e2e7

e8e3

e4e5

e6

3 4 5 6

v2

v1

f1

f2v3

v4

87 0 1 109

5

62

47 10

8

9

3

10

Topological traversals: follow connectivity

restrictClosure(0) = f 1v1e1e2v2e8e7v4e9e0restrictStar(7) = v1e1e2f 1e0e9

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 56 / 111

Page 94: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Rethinking the Mesh

Doublet Section

v1

v3

e3

e5

e4

v2

v4

e2

e1

e6

e8

e7

e9

e0

f1

f2

e9

e0

2

e1

e2e7

e8e3

e4e5

e6

3 4 5 6

v2

v1

f1

f2v3

v4

87 0 1 109

5

62

47 10

8

9

3

10

Topological traversals: follow connectivity

restrictClosure(0) = f 1v1e1e2v2e8e7v4e9e0restrictStar(7) = v1e1e2f 1e0e9

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 56 / 111

Page 95: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Restriction

v1

v2

e2

e1

e7

e9

e0

f1

v5

v3

e3

e5

e4

e6

f2

v6

v4

e8

e−

e+

( 12, 9 )

( 8, −7 )

( 4, 11 )

2

47

8

12

3

0

5

6

10111

−7

9

Localization

Restrict to patches (here an edge closure)Compute locally

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 57 / 111

Page 96: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Delta

v5v4

v2v6

e7

e8

v1

v2

e2

e1

e7

e9

e0

f1

v5

v3

e3

e5

e4

e6

f2

v6

v4

e8

e− e

e+

e+

( 12, 9 )

( 8, −7 )

( 4, 11 )

2

47

8

12

3

0

5

6

10111

−7

9

DeltaRestrict further to the overlapOverlap now carries twice the data

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 57 / 111

Page 97: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Fusion

v5v4

v2v6

e7

e8

v5v4

7e

e8

v2v6

v1

v2

e2

e1

e7

e9

e0

f1

v5

v3

e3

e5

e4

e6

f2

v6

v4

e8

e−

e+

e−

e+

( 12, 9 )

( 8, −7 )

( 4, 11 )

2

47

8

12

3

0

5

6

10111

−7

9

Merge/reconcile data on the overlap

Addition (FEM)Replacement (FD)Coordinate transform (Sphere)Linear transform (MG)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 57 / 111

Page 98: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Update

v5

7e

v4

e8

v6

v2

v1

v2

e2

e1

e7

e9

e0

f1

v5

e−

v3

e3

e5

e4

e6

f2

v6

v4

e8

e+e

+

e−

e−

7e

e8

e8

7e

v2

v2

v6

v6

v4

v4

v5

v5 ( 12, 9 )

( 8, −7 )

( 4, 11 )

2

47

8

12

3

0

5

6

10111

−7

9

UpdateUpdate local patch dataCompletion = restrict −→ fuse −→ update, in parallel

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 57 / 111

Page 99: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Completion

v5v4

v2v6

e7

e8

v1

v2

e2

e1

e7

e9

e0

f1

v5

v3

e3

e5

e4

e6

f2

v6

v4

e8

e− e

e+

e+

( 12, 9 )

( 8, −7 )

( 4, 11 )

2

47

8

12

3

0

5

6

10111

−7

9

A ubiquitous parallel form of restrict −→ fuse −→ update

Operates on SectionsSieves can be ”downcast” to Sections

Based on two operationsData exchange through overlapFusion of shared data

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 58 / 111

Page 100: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Uses

Completion has many uses:

FEM accumulating integrals on shared faces

FVM accumulating fluxes on shared cells

FDM setting values on ghost vertices

distributing mesh entities after partition

redistributing mesh entities and data for load balance

accumlating matvec for a partially assembled matrix

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 59 / 111

Page 101: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Uses

Completion has many uses:

FEM accumulating integrals on shared faces

FVM accumulating fluxes on shared cells

FDM setting values on ghost vertices

distributing mesh entities after partition

redistributing mesh entities and data for load balance

accumlating matvec for a partially assembled matrix

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 59 / 111

Page 102: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Uses

Completion has many uses:

FEM accumulating integrals on shared faces

FVM accumulating fluxes on shared cells

FDM setting values on ghost vertices

distributing mesh entities after partition

redistributing mesh entities and data for load balance

accumlating matvec for a partially assembled matrix

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 59 / 111

Page 103: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Uses

Completion has many uses:

FEM accumulating integrals on shared faces

FVM accumulating fluxes on shared cells

FDM setting values on ghost vertices

distributing mesh entities after partition

redistributing mesh entities and data for load balance

accumlating matvec for a partially assembled matrix

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 59 / 111

Page 104: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Uses

Completion has many uses:

FEM accumulating integrals on shared faces

FVM accumulating fluxes on shared cells

FDM setting values on ghost vertices

distributing mesh entities after partition

redistributing mesh entities and data for load balance

accumlating matvec for a partially assembled matrix

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 59 / 111

Page 105: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Uses

Completion has many uses:

FEM accumulating integrals on shared faces

FVM accumulating fluxes on shared cells

FDM setting values on ghost vertices

distributing mesh entities after partition

redistributing mesh entities and data for load balance

accumlating matvec for a partially assembled matrix

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 59 / 111

Page 106: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Uses

Completion has many uses:

FEM accumulating integrals on shared faces

FVM accumulating fluxes on shared cells

FDM setting values on ghost vertices

distributing mesh entities after partition

redistributing mesh entities and data for load balance

accumlating matvec for a partially assembled matrix

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 59 / 111

Page 107: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Mesh Distribution

Distributing a mesh means

distributing the topology (Sieve)

distributing data (Section)

However, a Sieve can be interpreted as a Section of cone()s!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 60 / 111

Page 108: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Mesh Distribution

Distributing a mesh means

distributing the topology (Sieve)

distributing data (Section)

However, a Sieve can be interpreted as a Section of cone()s!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 60 / 111

Page 109: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Mesh Distribution

Distributing a mesh means

distributing the topology (Sieve)

distributing data (Section)

However, a Sieve can be interpreted as a Section of cone()s!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 60 / 111

Page 110: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Mesh Distribution

Distributing a mesh means

distributing the topology (Sieve)

distributing data (Section)

However, a Sieve can be interpreted as a Section of cone()s!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 60 / 111

Page 111: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

The Mesh Dual

(0,0)

(0,1)(0,2)

(0,3)

(0,7)

(0,8)

(0,4)(0,5)

(0,6)

(0,9) (0,10)

(0,11)

(0,12)

(0,12)

(0,10)(0,9)

(0,11)

(0,8) (0,6)

(0,7)

(0,5) (0,4)

(0,3)

(0,0)

(0,1)(0,2)

(0,9) (0,10) (0,11) (0,12)

(0,3) (0,4) (0,5) (0,6) (0,7) (0,8)

(0,0) (0,1) (0,2) (0,9) (0,10) (0,11) (0,12)

(0,3) (0,4) (0,5) (0,6) (0,7) (0,8)

(0,0) (0,1) (0,2)

Construct mesh dual by

reversing sieve arrows

taking the support() of each face

taking the meet() of each cell pair

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 61 / 111

Page 112: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

Mesh Partition

3rd party packages construct a vertex partition

For FEM, partition dual graph vertices

For FVM, construct hyperpgraph dual with faces as vertices

Assign closure(v) and star(v) to same partition

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 62 / 111

Page 113: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

2D Example

A simple triangular mesh

8

9

10

11

12

13

14 15 16

0

1

5

7

4

6

2

3

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 63 / 111

Page 114: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

2D Example

Distributed Mesh

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 63 / 111

Page 115: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

3D Example

A simple hexahedral mesh

1098

11

20

29

19

28

12

21

30

13

22

31

14

23

32

15

24

33

16

25

34

18

27

17

26

0 1

23

45

67

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 64 / 111

Page 116: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions Parallelism

3D Example

Distributed Mesh

1098

11

20

29

19

28

12

21

13

22

15

24

16

25

34

18

27

17

0 1

23

5

6

20

29

19

28

21

30

13

22

31

14

23

32

15

24

33

16

25

34

18

27

17

26

0

3

45

67

Process 0

Process 1

Notice cells are ghostedM. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 64 / 111

Page 117: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

FEM Components

Section definition

Integration

Boundary conditions

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 65 / 111

Page 118: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

FIAT

Finite Element Integrator And Tabulator by Rob Kirby

http://www.fenics.org/fiat

FIAT understands

Reference element shapes (line, triangle, tetrahedron)

Quadrature rules

Polynomial spaces

Functionals over polynomials (dual spaces)

Derivatives

Can build arbitrary elements by specifying the Ciarlet triple (K ,P,P ′)

FIAT is part of the FEniCS project, as is the PETSc Sieve module

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 66 / 111

Page 119: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

FIAT

Finite Element Integrator And Tabulator by Rob Kirby

http://www.fenics.org/fiat

FIAT understands

Reference element shapes (line, triangle, tetrahedron)

Quadrature rules

Polynomial spaces

Functionals over polynomials (dual spaces)

Derivatives

Can build arbitrary elements by specifying the Ciarlet triple (K ,P,P ′)

FIAT is part of the FEniCS project, as is the PETSc Sieve module

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 66 / 111

Page 120: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

FIAT Integration

The quadrature.fiat file contains:

An element (usually a family and degree) defined by FIAT

A quadrature rule

It is run

automatically by make, or

independently by the user

It can take arguments

--element family and --element order, or

make takes variables ELEMENT and ORDER

Then make produces quadrature.h with:

Quadrature points and weights

Basis function and derivative evaluations at the quadrature points

Integration against dual basis functions over the cell

Local dofs for Section allocationM. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 67 / 111

Page 121: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Section Allocation

We only need the fiber dimensions of each point

Determined by discretization

By symmetry, only depend on point depth

Obtained from FIAT

Modified by BC

Decouples storage and parallelism from discretization

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 68 / 111

Page 122: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Section Allocation

We only need the fiber dimensions of each point

Determined by discretization

By symmetry, only depend on point depth

Obtained from FIAT

Modified by BC

Decouples storage and parallelism from discretization

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 68 / 111

Page 123: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Section Allocation

We only need the fiber dimensions of each point

Determined by discretization

By symmetry, only depend on point depth

Obtained from FIAT

Modified by BC

Decouples storage and parallelism from discretization

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 68 / 111

Page 124: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Section Allocation

We only need the fiber dimensions of each point

Determined by discretization

By symmetry, only depend on point depth

Obtained from FIAT

Modified by BC

Decouples storage and parallelism from discretization

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 68 / 111

Page 125: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Section Allocation

We only need the fiber dimensions of each point

Determined by discretization

By symmetry, only depend on point depth

Obtained from FIAT

Modified by BC

Decouples storage and parallelism from discretization

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 68 / 111

Page 126: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Kinds of Unknowns

We must map local unknowns to the global basis

FIAT reports the kind of unknown

Scalars are invariantLagrange

Vectors transform as J−T

Hermite

Normal vectors require Piola transform and a choice of orientationRaviart-Thomas

Moments transform as |J−1|Nedelec

May involve a transformation over the entire closureArgyris

Conjecture by Kirby relates transformation to affine equivalence

We have not yet automated this step (FFC, Mython)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 69 / 111

Page 127: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Kinds of Unknowns

We must map local unknowns to the global basis

FIAT reports the kind of unknown

Scalars are invariantLagrange

Vectors transform as J−T

Hermite

Normal vectors require Piola transform and a choice of orientationRaviart-Thomas

Moments transform as |J−1|Nedelec

May involve a transformation over the entire closureArgyris

Conjecture by Kirby relates transformation to affine equivalence

We have not yet automated this step (FFC, Mython)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 69 / 111

Page 128: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Kinds of Unknowns

We must map local unknowns to the global basis

FIAT reports the kind of unknown

Scalars are invariantLagrange

Vectors transform as J−T

Hermite

Normal vectors require Piola transform and a choice of orientationRaviart-Thomas

Moments transform as |J−1|Nedelec

May involve a transformation over the entire closureArgyris

Conjecture by Kirby relates transformation to affine equivalence

We have not yet automated this step (FFC, Mython)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 69 / 111

Page 129: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Kinds of Unknowns

We must map local unknowns to the global basis

FIAT reports the kind of unknown

Scalars are invariantLagrange

Vectors transform as J−T

Hermite

Normal vectors require Piola transform and a choice of orientationRaviart-Thomas

Moments transform as |J−1|Nedelec

May involve a transformation over the entire closureArgyris

Conjecture by Kirby relates transformation to affine equivalence

We have not yet automated this step (FFC, Mython)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 69 / 111

Page 130: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Kinds of Unknowns

We must map local unknowns to the global basis

FIAT reports the kind of unknown

Scalars are invariantLagrange

Vectors transform as J−T

Hermite

Normal vectors require Piola transform and a choice of orientationRaviart-Thomas

Moments transform as |J−1|Nedelec

May involve a transformation over the entire closureArgyris

Conjecture by Kirby relates transformation to affine equivalence

We have not yet automated this step (FFC, Mython)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 69 / 111

Page 131: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Kinds of Unknowns

We must map local unknowns to the global basis

FIAT reports the kind of unknown

Scalars are invariantLagrange

Vectors transform as J−T

Hermite

Normal vectors require Piola transform and a choice of orientationRaviart-Thomas

Moments transform as |J−1|Nedelec

May involve a transformation over the entire closureArgyris

Conjecture by Kirby relates transformation to affine equivalence

We have not yet automated this step (FFC, Mython)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 69 / 111

Page 132: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Kinds of Unknowns

We must map local unknowns to the global basis

FIAT reports the kind of unknown

Scalars are invariantLagrange

Vectors transform as J−T

Hermite

Normal vectors require Piola transform and a choice of orientationRaviart-Thomas

Moments transform as |J−1|Nedelec

May involve a transformation over the entire closureArgyris

Conjecture by Kirby relates transformation to affine equivalence

We have not yet automated this step (FFC, Mython)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 69 / 111

Page 133: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 134: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) coords = mesh->restrict(coordinates, c);v0, J, invJ, detJ = computeGeometry(coords);<Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 135: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 136: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry>inputVec = mesh->restrict(U, c);for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 137: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 138: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) realCoords = J*refCoords[q] + v0;for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 139: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 140: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) elemVec[f] += basis[q,f]*rhsFunc(realCoords);<Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 141: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 142: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term>for(d = 0; d < dim; ++d)for(e) testDerReal[d] += invJ[e,d]*basisDer[q,f,e];for(g = 0; g < numBasisFuncs; ++g)

for(d = 0; d < dim; ++d)for(e) basisDerReal[d] += invJ[e,d]*basisDer[q,g,e]elemMat[f,g] += testDerReal[d]*basisDerReal[d]

elemVec[f] += elemMat[f,g]*inputVec[g];<Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 143: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 144: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term>elemVec[f] += basis[q,f]*lambda*exp(inputVec[f]);elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 145: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 146: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

mesh->updateAdd(F, c, elemVec);

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 147: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

<Aggregate updates>

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 148: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Integration

cells = mesh->heightStratum(0);for(c = cells->begin(); c != cells->end(); ++c) <Compute cell geometry><Retrieve values from input vector>for(q = 0; q < numQuadPoints; ++q) <Transform coordinates>for(f = 0; f < numBasisFuncs; ++f) <Constant term><Linear term><Nonlinear term>elemVec[f] *= weight[q]*detJ;

<Update output vector>

Distribution<Mesh>::completeSection(mesh, F);

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 70 / 111

Page 149: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Boundary Conditions

Dirichlet conditions may be expressed as

u|Γ = g

and implemented by constraints on dofs in a Section

The user provides a function.

Neumann conditions may be expressed as

∇u · n|Γ = h

and implemented by explicit integration along the boundary

The user provides a weak form.

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 71 / 111

Page 150: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Boundary Conditions

Dirichlet conditions may be expressed as

u|Γ = g

and implemented by constraints on dofs in a Section

The user provides a function.

Neumann conditions may be expressed as

∇u · n|Γ = h

and implemented by explicit integration along the boundary

The user provides a weak form.

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 71 / 111

Page 151: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Boundary Conditions

Dirichlet conditions may be expressed as

u|Γ = g

and implemented by constraints on dofs in a Section

The user provides a function.

Neumann conditions may be expressed as

∇u · n|Γ = h

and implemented by explicit integration along the boundary

The user provides a weak form.

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 71 / 111

Page 152: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Boundary Conditions

Dirichlet conditions may be expressed as

u|Γ = g

and implemented by constraints on dofs in a Section

The user provides a function.

Neumann conditions may be expressed as

∇u · n|Γ = h

and implemented by explicit integration along the boundary

The user provides a weak form.

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 71 / 111

Page 153: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Boundary Conditions

Dirichlet conditions may be expressed as

u|Γ = g

and implemented by constraints on dofs in a Section

The user provides a function.

Neumann conditions may be expressed as

∇u · n|Γ = h

and implemented by explicit integration along the boundary

The user provides a weak form.

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 71 / 111

Page 154: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Boundary Conditions

Dirichlet conditions may be expressed as

u|Γ = g

and implemented by constraints on dofs in a Section

The user provides a function.

Neumann conditions may be expressed as

∇u · n|Γ = h

and implemented by explicit integration along the boundary

The user provides a weak form.

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 71 / 111

Page 155: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Boundary Conditions

Dirichlet conditions may be expressed as

u|Γ = g

and implemented by constraints on dofs in a Section

The user provides a function.

Neumann conditions may be expressed as

∇u · n|Γ = h

and implemented by explicit integration along the boundary

The user provides a weak form.

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 71 / 111

Page 156: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Dirichlet Values

Topological boundary is marked during generation

Cells bordering boundary are marked using markBoundaryCells()

To set values:1 Loop over boundary cells2 Loop over the element closure3 For each boundary point i , apply the functional Ni to the function g

The functionals are generated with the quadrature information

Section allocation applies Dirichlet conditions automatically

Values are stored in the Sectionrestrict() behaves normally, update() ignores constraints

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 72 / 111

Page 157: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Function and Operator Abstractions FEM

Dual Basis Application

We would like the action of a dual basis vector (functional)

< Ni , f >=

∫ref

Ni (x)f (x)dV

Projection onto PCode is generated from FIAT specification

Python code generation package inside PETSc

Common interface for all elements

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 73 / 111

Page 158: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers

Outline

1 FEM Concepts

2 Getting Started

3 Poisson

4 Stokes

5 Function and Operator Abstractions

6 Optimal SolversMultigrid for Structured MeshesMultigrid for Unstructured Meshes

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 74 / 111

Page 159: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers

What Is Optimal?

I will define optimal as an O(N) solution algorithm

These are generally hierarchical, so we need

hierarchy generation

assembly on subdomains

restriction and prolongation

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 75 / 111

Page 160: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers

Payoff

Why should I care?

1 Current algorithms do not efficiently utilize modern machines

2 Processor flops are increasing much faster than bandwidth

3 Multicore processors are the future

4 Optimal multilevel solvers are necessary

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 76 / 111

Page 161: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers

Payoff

Why should I care?

1 Current algorithms do not efficiently utilize modern machines

2 Processor flops are increasing much faster than bandwidth

3 Multicore processors are the future

4 Optimal multilevel solvers are necessary

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 76 / 111

Page 162: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers

Payoff

Why should I care?

1 Current algorithms do not efficiently utilize modern machines

2 Processor flops are increasing much faster than bandwidth

3 Multicore processors are the future

4 Optimal multilevel solvers are necessary

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 76 / 111

Page 163: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers

Payoff

Why should I care?

1 Current algorithms do not efficiently utilize modern machines

2 Processor flops are increasing much faster than bandwidth

3 Multicore processors are the future

4 Optimal multilevel solvers are necessary

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 76 / 111

Page 164: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers

Why Optimal Algorithms?

The more powerful the computer,the greater the importance of optimality

Example:

Suppose Alg1 solves a problem in time CN2, N is the input sizeSuppose Alg2 solves the same problem in time CNSuppose Alg1 and Alg2 are able to use 10,000 processors

In constant time compared to serial,

Alg1 can run a problem 100X largerAlg2 can run a problem 10,000X larger

Alternatively, filling the machine’s memory,

Alg1 requires 100X timeAlg2 runs in constant time

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 77 / 111

Page 165: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers

Multigrid

Multigrid is optimal in that is does O(N) work for ||r || < ε

Brandt, Briggs, Chan & Smith

Constant work per level

Sufficiently strong solverNeed a constant factor decrease in the residual

Constant factor decrease in dof

Log number of levels

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 78 / 111

Page 166: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers

Linear Convergence

Convergence to ||r || < 10−9||b|| using GMRES(30)/ILU

Elements Iterations

128 10256 17512 24

1024 342048 674096 1168192 167

16384 32932768 55865536 920

131072 1730

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 79 / 111

Page 167: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers

Linear Convergence

Convergence to ||r || < 10−9||b|| using GMRES(30)/MG

Elements Iterations

128 5256 7512 6

1024 72048 64096 78192 6

16384 732768 665536 7

131072 6

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 79 / 111

Page 168: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

Flow Control for a PETSc Application

Timestepping Solvers (TS)

Preconditioners (PC)

Nonlinear Solvers (SNES)

Linear Solvers (KSP)

Function

EvaluationPostprocessing

Jacobian

Evaluation

Application

Initialization

Main Routine

PETSc

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 80 / 111

Page 169: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

SNESCallbacks

The SNES interface is based upon callback functions

SNESSetFunction()

SNESSetJacobian()

When PETSc needs to evaluate the nonlinear residual F (x), the solvercalls the user’s function inside the application.

The user function get application state through the ctx variable. PETScnever sees application data.

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 81 / 111

Page 170: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

Higher Level Abstractions

The PETSc DA class is a topology and discretization interface.

Structured grid interface

Fixed simple topology

Supports stencils, communication, reordering

Limited idea of operators

Nice for simple finite differences

The PETSc Mesh class is a topology interface.

Unstructured grid interface

Arbitrary topology and element shape

Supports partitioning, distribution, and global orders

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 82 / 111

Page 171: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

Higher Level Abstractions

The PETSc DM class is a hierarchy interface.

Supports multigrid

DMMG combines it with the MG preconditioner

Abstracts the logic of multilevel methods

The PETSc Section class is a function interface.

Functions over unstructured grids

Arbitrary layout of degrees of freedom

Support distribution and assembly

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 82 / 111

Page 172: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

A DA is more than a Mesh

A DA contains topology, geometry, and an implicit Q1 discretization.

It is used as a template to create

Vectors (functions)

Matrices (linear operators)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 83 / 111

Page 173: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

Structured Meshes

The DMMG allows multigrid which some simple options

-dmmg nlevels, -dmmg view

-pc mg type, -pc mg cycle type

-mg levels 1 ksp type, -dmmg levels 1 pc type

-mg coarse ksp type, -mg coarse pc type

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 84 / 111

Page 174: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

Creating a DA

DACreate2d(comm, wrap, type, M, N, m, n, dof, s, lm[],ln[], DA *da)

wrap: Specifies periodicity

DA NONPERIODIC, DA XPERIODIC, DA YPERIODIC, or DA XYPERIODIC

type: Specifies stencil

DA STENCIL BOX or DA STENCIL STAR

M/N: Number of grid points in x/y-direction

m/n: Number of processes in x/y-direction

dof: Degrees of freedom per node

s: The stencil width

lm/n: Alternative array of local sizes

Use PETSC NULL for the default

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 85 / 111

Page 175: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

Ghost Values

To evaluate a local function f (x), each process requires

its local portion of the vector x

its ghost values, bordering portions of x owned by neighboringprocesses

Local Node

Ghost Node

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 86 / 111

Page 176: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

DA Global Numberings

Proc 2 Proc 3

25 26 27 28 2920 21 22 23 2415 16 17 18 19

10 11 12 13 145 6 7 8 90 1 2 3 4

Proc 0 Proc 1

Natural numbering

Proc 2 Proc 3

21 22 23 28 2918 19 20 26 2715 16 17 24 25

6 7 8 13 143 4 5 11 120 1 2 9 10

Proc 0 Proc 1

PETSc numbering

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 87 / 111

Page 177: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

DA Global vs. Local Numbering

Global: Each vertex belongs to a unique process and has a unique id

Local: Numbering includes ghost vertices from neighboring processes

Proc 2 Proc 3

X X X X XX X X X X12 13 14 15 X

8 9 10 11 X4 5 6 7 X0 1 2 3 X

Proc 0 Proc 1

Local numbering

Proc 2 Proc 3

21 22 23 28 2918 19 20 26 2715 16 17 24 25

6 7 8 13 143 4 5 11 120 1 2 9 10

Proc 0 Proc 1

Global numbering

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 88 / 111

Page 178: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

DA Vectors

The DA object contains only layout (topology) information

All field data is contained in PETSc Vecs

Global vectors are parallel

Each process stores a unique local portionDACreateGlobalVector(DA da, Vec *gvec)

Local vectors are sequential (and usually temporary)

Each process stores its local portion plus ghost valuesDACreateLocalVector(DA da, Vec *lvec)includes ghost values!

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 89 / 111

Page 179: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

DA Local Function

The user provided function which calculates the nonlinear residual in 2Dhas signature

PetscErrorCode (*lfunc)(DALocalInfo *info, PetscScalar **x,PetscScalar **r, void *ctx)

info: All layout and numbering information

x: The current solution

Notice that it is a multidimensional array

r: The residual

ctx: The user context passed to DASetLocalFunction()

The local DA function is activated by calling

SNESSetFunction(snes, r, SNESDAFormFunction, ctx)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 90 / 111

Page 180: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

Bratu Residual Evaluation

∆u + λeu = 0

BratuResidualLocal(DALocalInfo *info,Field **x,Field **f)/* Not Shown: Handle boundaries *//* Compute over the interior points */for(j = info->ys; j < info->xs+info->ym; j++) for(i = info->xs; i < info->ys+info->xm; i++)

u = x[j][i];u_xx = (2.0*u - x[j][i-1] - x[j][i+1])*hydhx;u_yy = (2.0*u - x[j-1][i] - x[j+1][i])*hxdhy;f[j][i] = u_xx + u_yy - hx*hy*lambda*exp(u);

$PETCS DIR/src/snes/examples/tutorials/ex5.c

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 91 / 111

Page 181: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

DA Local Jacobian

The user provided function which calculates the Jacboian in 2D hassignature

PetscErrorCode (*lfunc)(DALocalInfo *info, PetscScalar **x,Mat J, void *ctx)

info: All layout and numbering information

x: The current solution

J: The Jacobian

ctx: The user context passed to DASetLocalFunction()

The local DA function is activated by calling

SNESSetJacobian(snes, J, J, SNESDAComputeJacobian, ctx)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 92 / 111

Page 182: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

Updating Ghosts

Two-step process enables overlapping computation and communication

DAGlobalToLocalBegin(da, gvec, mode, lvec)gvec provides the datamode is either INSERT VALUES or ADD VALUESlvec holds the local and ghost values

DAGlobalToLocalEnd(da, gvec, mode, lvec)Finishes the communication

The process can be reversed with DALocalToGlobal().

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 93 / 111

Page 183: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

DA Stencils

Both the box stencil and star stencil are available.

proc 0 proc 1

proc 10

proc 0 proc 1

proc 10

Box Stencil Star Stencil

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 94 / 111

Page 184: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

Setting Values on Regular Grids

PETSc provides

MatSetValuesStencil(Mat A, m, MatStencil idxm[], n,MatStencil idxn[], values[], mode)

Each row or column is actually a MatStencilThis specifies grid coordinates and a component if necessaryCan imagine for unstructured grids, they are vertices

The values are the same logically dense block in rows and columns

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 95 / 111

Page 185: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

DMMG Integration with SNES

DMMG supplies global residual and Jacobian to SNES

User supplies local version to DMMGThe Rhs *() and Jac *() functions in the example

Allows automatic parallelism

Allows grid hierarchy

Enables multigrid once interpolation/restriction is defined

Paradigm is developed in unstructured work

Notice we have to scatter into contiguous global vectors (initial guess)

Handle Neumann BC using DMMGSetNullSpace()

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 96 / 111

Page 186: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

The Bratu Problem

∆u + λeu = f in Ω (1)

u = g on ∂Ω (2)

Nonlinearly perturbed Poisson

Can be treated as a nonlinear eigenvalue problem

Has two solution branches until λ ∼= 6.28

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 97 / 111

Page 187: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

A 2D Problem

Problem has:

1,329,409 unknowns (on the fine level)

11,950,849 nonzeros

Executable Options Explanation

./bratu -da grid x 10 -da grid y 10 Coarse grid is 10x10-ksp rtol 1.0e-9 Solver tolerance-dmmg nlevels 8 8 levels of refinement-mg levels 4 pc type sor Memory savings-mg levels 5 pc type sor-mg levels 6 pc type sor-mg levels 7 pc type sor-snes view Describe solver

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 98 / 111

Page 188: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Structured Meshes

A 3D Problem

Problem has:

912,673 unknowns (on the fine level)

24,137,569 nonzeros

Executable Options Explanation

./bratu -dim 3 -da grid x 7 Coarse grid is 7x7x7-da grid y 7 -da grid z 7-ksp rtol 1.0e-9 Solver tolerance-dmmg nlevels 5 5 levels of refinement-mg levels 3 pc type sor Memory savings-mg levels 4 pc type sor-snes view Describe solver

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 99 / 111

Page 189: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Sections

Sections associate data to submeshes

Name comes from section of a fiber bundle

Generalizes linear algebra paradigm

Define restrict(),update()

Define complete()

Assembly routines take a Sieve and several Sections

This is called a Bundle

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 100 / 111

Page 190: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Global and Local

Local (analytical)

Discretization/Approximation

FEM integralsFV fluxes

Boundary conditions

Largely dim dependent(e.g. quadrature)

Global (topological)

Data management

Sections (local pieces)Completions (assembly)

Boundary definition

Multiple meshes

Mesh hierarchies

Largely dim independent(e.g. mesh traversal)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 101 / 111

Page 191: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Global and Local

Local (analytical)

Discretization/Approximation

FEM integralsFV fluxes

Boundary conditions

Largely dim dependent(e.g. quadrature)

Global (topological)

Data management

Sections (local pieces)Completions (assembly)

Boundary definition

Multiple meshes

Mesh hierarchies

Largely dim independent(e.g. mesh traversal)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 101 / 111

Page 192: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Global and Local

Local (analytical)

Discretization/Approximation

FEM integralsFV fluxes

Boundary conditions

Largely dim dependent(e.g. quadrature)

Global (topological)

Data management

Sections (local pieces)Completions (assembly)

Boundary definition

Multiple meshes

Mesh hierarchies

Largely dim independent(e.g. mesh traversal)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 101 / 111

Page 193: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Global and Local

Local (analytical)

Discretization/Approximation

FEM integralsFV fluxes

Boundary conditions

Largely dim dependent(e.g. quadrature)

Global (topological)

Data management

Sections (local pieces)Completions (assembly)

Boundary definition

Multiple meshes

Mesh hierarchies

Largely dim independent(e.g. mesh traversal)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 101 / 111

Page 194: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

AMG

Why not use AMG?

Of course we will try AMG

BoomerAMG, ML, SAMG, ASA

Problems with vector character

Geometric aspects to the problem

Material property variationFaults

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 102 / 111

Page 195: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

AMG

Why not use AMG?

Of course we will try AMG

BoomerAMG, ML, SAMG, ASA

Problems with vector character

Geometric aspects to the problem

Material property variationFaults

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 102 / 111

Page 196: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

AMG

Why not use AMG?

Of course we will try AMG

BoomerAMG, ML, SAMG, ASA

Problems with vector character

Geometric aspects to the problem

Material property variationFaults

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 102 / 111

Page 197: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

AMG

Why not use AMG?

Of course we will try AMG

BoomerAMG, ML, SAMG, ASA

Problems with vector character

Geometric aspects to the problem

Material property variationFaults

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 102 / 111

Page 198: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

AMG

Why not use AMG?

Of course we will try AMG

BoomerAMG, ML, SAMG, ASA

Problems with vector character

Geometric aspects to the problem

Material property variationFaults

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 102 / 111

Page 199: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

AMG

Why not use AMG?

Of course we will try AMG

BoomerAMG, ML, SAMG, ASA

Problems with vector character

Geometric aspects to the problem

Material property variationFaults

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 102 / 111

Page 200: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

AMG

Why not use AMG?

Of course we will try AMG

BoomerAMG, ML, SAMG, ASA

Problems with vector character

Geometric aspects to the problem

Material property variationFaults

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 102 / 111

Page 201: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Unstructured Meshes

Same DMMG options as the structured case

Mesh refinement

Ruppert algorithm in Triangle and TetGen

Mesh coarsening

Talmor-Miller algorithm in PETSc

More advanced options

-dmmg refine-dmmg hierarchy

Current version only works for linear elements

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 103 / 111

Page 202: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Coarsening

Users want to control the mesh

Developed efficient, topologicalcoarsening

Miller, Talmor, Tengalgorithm

Provably well-shaped hierarchy

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 104 / 111

Page 203: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Miller-Talmor-Teng Algorithm

Simple Coarsening

1 Compute a spacing function f for the mesh (Koebe)

2 Scale f by a factor C > 1

3 Choose a maximal independent set of vertices for new f

4 Retriangulate

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 105 / 111

Page 204: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Miller-Talmor-Teng Algorithm

Simple Coarsening

1 Compute a spacing function f for the mesh (Koebe)

2 Scale f by a factor C > 1

3 Choose a maximal independent set of vertices for new f

4 Retriangulate

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 105 / 111

Page 205: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Miller-Talmor-Teng Algorithm

Simple Coarsening

1 Compute a spacing function f for the mesh (Koebe)

2 Scale f by a factor C > 1

3 Choose a maximal independent set of vertices for new f

4 Retriangulate

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 105 / 111

Page 206: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Miller-Talmor-Teng Algorithm

Simple Coarsening

1 Compute a spacing function f for the mesh (Koebe)

2 Scale f by a factor C > 1

3 Choose a maximal independent set of vertices for new f

4 Retriangulate

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 105 / 111

Page 207: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Miller-Talmor-Teng Algorithm

Caveats

1 Must generate coarsest grid in hierarchy first

2 Must choose boundary vertices first (and protect boundary)

3 Must account for boundary geometry

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 105 / 111

Page 208: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Miller-Talmor-Teng Algorithm

Caveats

1 Must generate coarsest grid in hierarchy first

2 Must choose boundary vertices first (and protect boundary)

3 Must account for boundary geometry

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 105 / 111

Page 209: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Miller-Talmor-Teng Algorithm

Caveats

1 Must generate coarsest grid in hierarchy first

2 Must choose boundary vertices first (and protect boundary)

3 Must account for boundary geometry

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 105 / 111

Page 210: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

GMG Performance

For simple domains, everything works as expected:Linear solver iterates are constant as system size increases:

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 106 / 111

Page 211: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

GMG Performance

For simple domains, everything works as expected:Work to build the preconditioner is constant as system size increases:

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 106 / 111

Page 212: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Reentrant Problems

Reentrant corners need nonnuiform refinement to maintain accuracy

Coarsening preserves accuracy in MG without user intervention

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 107 / 111

Page 213: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Reentrant Problems

Reentrant corners need nonnuiform refinement to maintain accuracyCoarsening preserves accuracy in MG without user intervention

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 107 / 111

Page 214: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Reentrant Problems

Exact Solution for reentrant problem: u(x , y) = r23 sin( 2

3θ)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 107 / 111

Page 215: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

Reentrant Problems

Exact Solution for reentrant problem: u(x , y) = r23 sin( 2

3θ)

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 107 / 111

Page 216: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

GMG Performance

Linear solver iterates are constant as system size increases:

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 108 / 111

Page 217: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Optimal Solvers Multigrid for Unstructured Meshes

GMG Performance

Work to build the preconditioner is constant as system size increases:

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 108 / 111

Page 218: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Conclusions

Conclusions

Better mathematical abstractions bring concrete benefitsVast reduction in complexity

Operate directly at the equation and discretization levelAutomatic generation of integration/assembly routinesDimension independent code

Expansion of capabilities

Parametric modelsOptimized implementations of integrationMultigrid on arbitrary meshes

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 109 / 111

Page 219: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Conclusions

Conclusions

Better mathematical abstractions bring concrete benefitsVast reduction in complexity

Operate directly at the equation and discretization levelAutomatic generation of integration/assembly routinesDimension independent code

Expansion of capabilities

Parametric modelsOptimized implementations of integrationMultigrid on arbitrary meshes

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 109 / 111

Page 220: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Conclusions

Conclusions

Better mathematical abstractions bring concrete benefitsVast reduction in complexity

Operate directly at the equation and discretization levelAutomatic generation of integration/assembly routinesDimension independent code

Expansion of capabilities

Parametric modelsOptimized implementations of integrationMultigrid on arbitrary meshes

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 109 / 111

Page 221: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Conclusions

References

FEniCS Documentation:http://www.fenics.org/wiki/FEniCS Project

Project documentationUsers manualsRepositories, bug trackingImage gallery

Publications:http://www.fenics.org/wiki/Related presentations and publications

Research and publications that make use of FEniCS

PETSc Documentation:http://www.mcs.anl.gov/petsc/docs

PETSc Users manualManual pagesMany hyperlinked examplesFAQ, Troubleshooting info, installation info, etc.Publication using PETSc

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 110 / 111

Page 222: FEniCS and Sieve Tutorial - Interdisciplinary · FEniCS and Sieve Tutorial Matthew G Knepley 1 and Andy R Terrel 2 1Mathematics and Computer Science Division Argonne National Laboratory

Conclusions

Experimentation is Essential!

Proof is not currrently enough to examine solvers

N. M. Nachtigal, S. C. Reddy, and L. N. Trefethen,How fast are nonsymmetric matrix iterations?, SIAMJ. Matrix Anal. Appl., 13, pp.778–795, 1992.

Anne Greenbaum, Vlastimil Ptak, and ZdenekStrakos, Any Nonincreasing Convergence Curve isPossible for GMRES, SIAM J. Matrix Anal. Appl., 17(3), pp.465–469, 1996.

M. Knepley A. Terrel () FEniCS and Sieve Tutorial FEniCS’08 LSU 111 / 111