A guide for prospective developers Johan Hoffman & Anders Logg - - PowerPoint PPT Presentation

a guide for prospective developers
SMART_READER_LITE
LIVE PREVIEW

A guide for prospective developers Johan Hoffman & Anders Logg - - PowerPoint PPT Presentation

Current status of DOLFIN A guide for prospective developers Johan Hoffman & Anders Logg dolfin@math.chalmers.se Department of Computational Mathematics CM seminar 20030911: Current status of DOLFIN p. 1 Outline Overview


slide-1
SLIDE 1

Current status of DOLFIN

A guide for prospective developers

Johan Hoffman & Anders Logg

dolfin@math.chalmers.se

Department of Computational Mathematics

CM seminar 2003–09–11: Current status of DOLFIN – p. 1

slide-2
SLIDE 2

Outline

  • Overview
  • Input / output
  • A very quick guide to C++
  • Development with DOLFIN
  • Summary of features

CM seminar 2003–09–11: Current status of DOLFIN – p. 2

slide-3
SLIDE 3

Overview

CM seminar 2003–09–11: Current status of DOLFIN – p. 3

slide-4
SLIDE 4

Introduction

  • An adaptive finite element solver for PDEs (and ODEs)
  • Written by people at the Department of Computational

Mathematics (Hoffman/Logg)

  • Written in C++
  • Only a solver. No grid generation. No visualisation.
  • Licensed under the GNU GPL
  • http://www.phi.chalmers.se/dolfin

CM seminar 2003–09–11: Current status of DOLFIN – p. 4

slide-5
SLIDE 5

Evolution of DOLFIN

  • First public version, 0.2.6, was released Feb 2002.
  • The latest version, 0.3.10, was released Sep 2003.
  • The main part of the code has been written by

Hoffman/Logg but contains contributions from 8 other people.

  • At www.freshmeat.net, 13 people are listed as

subscribers to new versions of DOLFIN.

  • The latest CVS version consists of 35.000 lines of code.

As you can see, DOLFIN is yet quite a small project, but we hope to grow! (Not necessarily in terms of klocs. . . )

CM seminar 2003–09–11: Current status of DOLFIN – p. 5

slide-6
SLIDE 6

GNU and the GPL

  • Makes the software free for all users
  • Free to modify, change, copy, redistribute
  • Derived work must also use the GPL license
  • Enables sharing of code
  • Simplifies distribution of the program
  • Linux is distributed under the GPL license
  • See http://www.gnu.org

CM seminar 2003–09–11: Current status of DOLFIN – p. 6

slide-7
SLIDE 7

Features

  • 2D or 3D
  • Automatic assembling
  • Triangles or tetrahedrons
  • Linear elements
  • Algebraic solvers: LU, GMRES, CG, preconditioners

CM seminar 2003–09–11: Current status of DOLFIN – p. 7

slide-8
SLIDE 8

Everyone loves a screenshot

CM seminar 2003–09–11: Current status of DOLFIN – p. 8

slide-9
SLIDE 9

Examples

Start movie 1 (driven cavity, solution) Start movie 2 (driven cavity, dual) Start movie 3 (driven cavity, dual) Start movie 4 (bluff body, solution) Start movie 5 (bluff body, dual) Start movie 6 (jet, solution) Start movie 7 (transition to turbulence)

CM seminar 2003–09–11: Current status of DOLFIN – p. 9

slide-10
SLIDE 10

Input / output

CM seminar 2003–09–11: Current status of DOLFIN – p. 10

slide-11
SLIDE 11

Input / output

  • OpenDX: free open-source visualisation program based on

IBM:s Visualization Data Explorer.

  • MATLAB: commercial software (2000 Euros)
  • GiD: commercial software (570 Euros)

Note: Input / output has been redesigned in the 0.3.x versions of DOLFIN and support has not yet been added for OpenDX and GiD.

CM seminar 2003–09–11: Current status of DOLFIN – p. 11

slide-12
SLIDE 12

GiD / MATLAB

Poisson’s equation: −∆u(x) = f(x), x ∈ Ω,

(1)

  • n the unit square Ω = (0, 1) × (0, 1) with the source term f

localised to the middle of the domain. Grid generation with GiD and visualisation using the pdesurf command in MATLAB.

CM seminar 2003–09–11: Current status of DOLFIN – p. 12

slide-13
SLIDE 13

GiD / MATLAB

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 1 2 3 4 5 6 7

CM seminar 2003–09–11: Current status of DOLFIN – p. 13

slide-14
SLIDE 14

MATLAB / GiD

Convection–diffusion: ˙ u + b · ∇u − ∇ · (ǫ∇u) = f,

(2)

with b = (−10, 0), f = 0 and ǫ = 0.1 around a hot dolphin. Grid generation with MATLAB and visualisation using contour lines in GiD.

CM seminar 2003–09–11: Current status of DOLFIN – p. 14

slide-15
SLIDE 15

MATLAB / GiD

CM seminar 2003–09–11: Current status of DOLFIN – p. 15

slide-16
SLIDE 16

OpenDX

Incompressible Navier–Stokes: ˙ u + u · ∇u − ν∆u + ∇p = f, ∇ · u = 0.

(3)

Visualisation in OpenDX of the isosurface for the velocity in a computation of transition to turbulence in shear flow on a mesh consisting of 1,600,000 tetrahedral elements.

CM seminar 2003–09–11: Current status of DOLFIN – p. 16

slide-17
SLIDE 17

OpenDX

CM seminar 2003–09–11: Current status of DOLFIN – p. 17

slide-18
SLIDE 18

A very quick guide to C++

CM seminar 2003–09–11: Current status of DOLFIN – p. 18

slide-19
SLIDE 19

C++

  • Invented by Bjarne Stroupstrup at AT&T Bell Laboratories in

the early 1980’s

  • Extends the C programming language to provide support for
  • bject-oriented programming
  • Widely used
  • Standardised by ANSI
  • Fundamental concept: class

CM seminar 2003–09–11: Current status of DOLFIN – p. 19

slide-20
SLIDE 20

Hello world in C++

#include <iostream> using namespace std; int main() { cout << ‘‘Hello world!’’ << endl; return 0; }

CM seminar 2003–09–11: Current status of DOLFIN – p. 20

slide-21
SLIDE 21

Hello world in C++

#include <iostream> using namespace std; int main() { int n = 10; for (int i = 0; i < n; i++) cout << ‘‘Hello world!’’ << endl; return 0; }

CM seminar 2003–09–11: Current status of DOLFIN – p. 21

slide-22
SLIDE 22

A basic C++ vocabulary

  • Fundamental data types:

char, int, float, bool

  • Conditions and loops:

if, else, switch, case, for, while, break, continue

  • Classes:

class, public, private, protected

  • General:

#include, namespace, new, delete

CM seminar 2003–09–11: Current status of DOLFIN – p. 22

slide-23
SLIDE 23

Definition of a variable

  • Note how in the Hello World-program each variable is

defined as Type name;

  • A variable must be introduced before it is used.
  • A variable can be defined almost anywhere in the code.

CM seminar 2003–09–11: Current status of DOLFIN – p. 23

slide-24
SLIDE 24

Declaration of a class

class Vector { public: Vector(int n); // Constructor ˜Vector(); // Destructor void resize(int n); // A function int size(); // Another function private: int n; // Size of the vector double* values; // The values };

CM seminar 2003–09–11: Current status of DOLFIN – p. 24

slide-25
SLIDE 25

Using the Vector class

Vector x(10); Vector y(10); for (int i = 0; i < 10; i++) x(i) = (double) i*i; x *= 5.0; // x <- 5x y += x; // y <- y + x

CM seminar 2003–09–11: Current status of DOLFIN – p. 25

slide-26
SLIDE 26

Development with DOLFIN

CM seminar 2003–09–11: Current status of DOLFIN – p. 26

slide-27
SLIDE 27

Code structure

Tools fem la grid quadrature elements math common io main.cpp Settings Log system Solvers/modules Poisson Conv-diff Navier-Stokes User level Kernel level Module level

CM seminar 2003–09–11: Current status of DOLFIN – p. 27

slide-28
SLIDE 28

Three levels

  • Simple C/C++ interface for the user who just wants to solve

an equation with specified geometry and boundary conditions.

  • New algorithms are added at module level by the developer
  • r advanced user.
  • Core features are added at kernel level.

CM seminar 2003–09–11: Current status of DOLFIN – p. 28

slide-29
SLIDE 29

Solving Poisson’s equation

int main() { Grid grid("grid.xml.gz"); Problem poisson("poisson", grid); poisson.set("source", f); poisson.set("boundary condition", mybc); poisson.solve(); return 0; }

CM seminar 2003–09–11: Current status of DOLFIN – p. 29

slide-30
SLIDE 30

Implementing a solver

void PoissonSolver::solve() { Galerkin fem; Matrix A; Vector x, b; Function u(grid, x); Function f(grid, "source"); Poisson poisson(f); KrylovSolver solver; File file("poisson.m"); fem.assemble(poisson, grid, A, b); solver.solve(A, x, b); u.rename("u", "temperature"); file << u; }

CM seminar 2003–09–11: Current status of DOLFIN – p. 30

slide-31
SLIDE 31

Automatic assembling

class Poisson : public PDE { ... real lhs(const ShapeFunction& u, const ShapeFunction& v) { return (grad(u),grad(v)) * dK; } real rhs(const ShapeFunction& v) { return f*v * dK; } ... };

CM seminar 2003–09–11: Current status of DOLFIN – p. 31

slide-32
SLIDE 32

Automatic assembling

class ConvDiff : public PDE { ... real lhs(const ShapeFunction& u, const ShapeFunction& v) { return (u*v + k*((b,grad(u))*v + a*(grad(u),grad(v))))*dK; } real rhs(const ShapeFunction& v) { return (up*v + k*f*v) * dK; } ... };

CM seminar 2003–09–11: Current status of DOLFIN – p. 32

slide-33
SLIDE 33

Grid management

Basic concepts:

  • Grid
  • Node, Cell, Edge, Face
  • Boundary
  • GridHierarchy
  • NodeIterator

CellIterator EdgeIterator FaceIterator

CM seminar 2003–09–11: Current status of DOLFIN – p. 33

slide-34
SLIDE 34

Grid management

Reading and writing grids:

File file(‘‘grid.xml’’); Grid grid; file >> grid; // Read grid from file file << grid; // Save grid to file

CM seminar 2003–09–11: Current status of DOLFIN – p. 34

slide-35
SLIDE 35

Grid management

Iteration over a grid:

for (CellIterator c(grid); !c.end(); ++c) for (NodeIterator n1(c); !n1.end(); ++n1) for (NodeIterator n2(n1); !n2.end(); ++n2) cout << *n2 << endl;

CM seminar 2003–09–11: Current status of DOLFIN – p. 35

slide-36
SLIDE 36

Linear algebra

Basic concepts:

  • Vector
  • Matrix (sparse, dense or generic)
  • KrylovSolver
  • DirectSolver

CM seminar 2003–09–11: Current status of DOLFIN – p. 36

slide-37
SLIDE 37

Linear algebra

Using the linear algebra:

int N = 100; Matrix A(N,N); Vector x(N); Vector b(N); b = 1.0; for (int i = 0; i < N; i++) { A(i,i) = 2.0; if ( i > 0 ) A(i,i-1) = -1.0; if ( i < (N-1) ) A(i,i+1) = 1.0; } A.solve(x,b);

CM seminar 2003–09–11: Current status of DOLFIN – p. 37

slide-38
SLIDE 38

Summary of features

CM seminar 2003–09–11: Current status of DOLFIN – p. 38

slide-39
SLIDE 39

Summary of features

Implemented features:

  • Automatic assembling
  • Linear elements in 2D and 3D
  • Basic grid management
  • Basic linear algebra
  • Solvers for Poisson and convection–diffusion
  • Log system
  • Parameter management

CM seminar 2003–09–11: Current status of DOLFIN – p. 39

slide-40
SLIDE 40

Summary of features

In preparation:

  • Adaptive grid refinement (Hoffman/Logg)
  • Multi-adaptive ODE-solver (Jansson/Logg)
  • Improved preconditioners (Hoffman/Svensson)
  • Improved linear algebra (Hoffman/Logg)

CM seminar 2003–09–11: Current status of DOLFIN – p. 40

slide-41
SLIDE 41

Summary of features

Wishlist / help wanted:

  • Multi-grid (Målqvist/Svensson?)
  • Implementation of boundary conditions
  • Eigenvalue solvers
  • Higher-order elements (Svensson?)
  • Parallelization
  • Documentation
  • New solvers / modules (everyone invited!)
  • Testing, bug fixes (everyone invited!)

CM seminar 2003–09–11: Current status of DOLFIN – p. 41

slide-42
SLIDE 42

Web page

  • www.phi.chalmers.se/dolfin

Detailed documentation of the API for DOLFIN is automatically generated every night and is available from the web page.

CM seminar 2003–09–11: Current status of DOLFIN – p. 42