true
9.3 s

Finite volume method: further aspects

4.7 μs

Julia packages supporting PDE solution

Up to now we used the Triangulate.jl in order to access mesh generation, for all other functionality, standard Julia packages were used.

There are a number of PDE solution packages in Julia, in particular for the finite element method. During this course, we will use a number of recently developed packages supporting basic functionality for the solution of PDEs. They emerged from the WIAS pdelib project and from scientific computing courses from previous years. These are:

We will use all of them in this lecture.

2.2 ms
4.7 ms

Dirichlet boundary conditions

δu=finΩu=gonΩ

4.1 μs

Three main possibilities to implement Dirichlet boundary conditions:

  • Eliminate Dirichlet BC algebraically after building of the matrix, i.e. fix ``known unknowns'' at the Dirichlet boundary highly technical

  • Modifiy matrix such that equations at boundary exactly result in Dirichlet values loss of symmetry of the matrix

  • Penalty method: replace the Dirichlet boundary condition by a Robin boundary condition with high transfer coefficient

We discuss these possibilities for a 1D problem in Ω=(0,1) with tridiagonal matrix:

Δu=finΩu(0)=g0u(1)=g1

8.3 μs

Algebraic manipulation

  • Matrix A of homogeneous Neumann problem - no regard to boundary values.

AU=(1h1h1h2h1h1h2h1h)(u1u2u3)=(f1f2f3)

  • A is diagonally dominant, but neither idd, nor sdd.

  • Fix the value of u1 and eliminate the corresponding equation:

AU=(2h1h1h2h1h)(u2u3)=(f2+1hgf3)

  • A is idd and stays symmetric

This operation is quite technical to implement, even more so for triangular meshes or for systems with multiple PDEs.

10.4 μs

Modification of boundary equations

  • Modify equation at boundary to exactly represent Dirichlet values

AU=(1h01h2h1h1h2h1h)(u1u2u3)=(1hgf2f3)

  • A is idd ?

  • Loss of symmetry problem e.g. with CG method

6.1 μs

Penalty method: the "lazy" way

This corresponds to replacing the Dirichlet boundary condition u=g with a Robin boundary condition

δnu+1εu=1εg

In practice we perform this operation on a discrete level:

AU=(1ε+1h1h1h2h1h1h2h1h)(u1u2u3)=(f1+1εgf2f3)

  • A is idd, symmetric, and the realization is technically easy.

  • If ε is small enough, u1=g will be satisfied exactly within

floating point accuracy.

  • Drawback: this creates a large condition number

  • Iterative methods should be initialized with Dirichlet values, so we start in a subspace where this is not relevant

  • Works also nonlinear problems, finite volume methods

8.8 μs

Matrix assembly

2.3 μs
trifactors! (generic function with 1 method)
43.2 μs
bfacefactors! (generic function with 1 method)
37.9 μs
assemble! (generic function with 1 method)
64.2 μs

Calculation example

Now we are able to solve our intended problem.

Grid generation

3.3 μs
describe_grid (generic function with 1 method)
30.2 μs
builder
292 ms
2.8 s
grid
ExtendableGrids.ExtendableGrid{Float64,Int32};
dim: 2 nodes: 24 cells: 30 bfaces: 16

504 ms

Desired number of triangles

From the desired number of triangles, we can calculate a value fo the maximum area constraint passed to the mesh generator: Desired number of triangles: 20

17.3 ms

Solving the problem

Problem data

3.4 μs
f (generic function with 1 method)
15.0 μs
g (generic function with 1 method)
12.5 μs
δ
1
92.0 ns

Data of the grid are accessed in a Dictionary like fashion. Coordinates, CellNodes and BFaceNodes are abstract types defined in ExtendableGrids.jl. Behind this is a dictionary with types as keys allowing type-stable access of the contents like in a struct and easy extension by defining additional key types. See here for more information.

6.4 μs
solve_example (generic function with 1 method)
22.5 μs
solution
180 ms
1.2 s

Convergence test

How good is our implementation and the choice of the penalty method for Dirichlet boundary conditions ? - Perform a convergence test on ever finer grids!

For this purpose we need to calculate error norms. Based on the L2-Norm

||u||22=Ωu2dω

we implement a discrete analogon for a discrete solution uh=(uk)kN

||uh||2,h2=Ωuh2dω=kN|ωk|uk2

Further, we implement the "h1"-norm wich measures the error in the gradient. We may discuss the details later.

5.8 μs
fvnorms (generic function with 1 method)
47.7 μs

Run convergence test for a number of grid refinement levels

2.2 μs
convergence_test (generic function with 1 method)
126 μs
16.3 s
362 ms

Conclusions

2.3 μs

We see the second order convergence of the solution and first order convergence of the gradient. This is the typical behavior which we also would expect from the finite element method.

2.2 μs

Concerning the complexity, the ExtendableSparseMatrix uses an intermediate data structure for collecting the matrix entries. If we directly insert data into a compressed column data structure, there is a considerable overhead for reorganization of the long arrays describing the matrix.

2.0 μs