23.6 s

Working with VoronoiFVM.jl

We show how to define scalar linear and nonlinear diffusion problems in the VoronoiFVM package.

In general, the package allows to work with multiple species, so all constitutive functions and the solution array need to handle species indices.

For more information, see its documentation.

15.4 μs

Linear diffusion problem with Dirichlet boundary conditions

Regard

(Du)=fin Ωu=gonΩ

The following data characterize the problem:

  • Flux j=Du

  • Dirichlet data g

  • Source/sink term f

  • Domain Ω

These can be replaced by the following discretization data:

2.4 ms

Diffusion coefficient D

5.2 μs
D
10.0
65.0 ns

Diffusion flux g(uk,uL)=D(ukul).

The following function receives the parameters in _u. This is an array containing the unkowns uk, ul and possibly several more parameters. The unknowns method extracts the unknowns from _u, creatimg a two-dimensional array, where the first parameter is the species index and the second the local number of the node wrt. the edge. The result is written into f for species index 1.

4.3 μs
diffusion_flux! (generic function with 1 method)
42.2 μs

Right hand side function f(x)=1 (just for an example). Once again, the species index is 1.

5.2 μs
diffusion_source! (generic function with 1 method)
13.1 μs

Discretization grid

2.4 μs

Grid in domain Ω=(0,1) consisting of N=11 points.

42.1 ms
X
2.8 μs
grid1d
ExtendableGrids.ExtendableGrid{Float64,Int32};
dim: 1 nodes: 11 cells: 10 bfaces: 2

16.2 μs
96.1 ms

System creation and solution methods

The problem description is subdivided in two parts: the discretization grid which is used to define the Voronoi cells and the form factors, and the physics part containing the constitutive functions, like the fluxes between neigboring species, the source term, and, possibly, more.

3.3 μs
create_system (generic function with 1 method)
25.1 μs

After setting boundary conditions, we can solve the system. Dirichlet boundary conditions are implemented by the penalty method.

2.3 μs
mysolve (generic function with 1 method)
53.9 μs

Set the Dirichlet boundary data:

  • u_L=0.01

  • u_R=0.01

89.1 ms

1D Linear diffusion

2.6 μs
system1d
VoronoiFVM.DenseSystem{Float64,Int32,Int32}(num_species=1)
49.1 μs

Using default settings, the system is solved.

4.9 μs
280 μs
58.9 ms

2D Linear diffusion

For solving a 2D problem, we just need to replace the 1D grid with a 2D grid.

3.4 μs
grid2d
ExtendableGrids.ExtendableGrid{Float64,Int32};
dim: 2 nodes: 121 cells: 200 bfaces: 40

30.1 μs
113 ms
system2d
VoronoiFVM.DenseSystem{Float64,Int32,Int32}(num_species=1)
106 μs

By default, the left boundary is marked by 4 and the right boundary is marked by 2, and we pass the data this way.

2.4 μs
2.1 ms
101 ms

Nonlinear diffusion

Here, we define a nonlinear diffusion problem:

Let j=D(u)u with D(u)=2u.

Then D(u)=0uD(ξ)dξ=u2.

So we can define g(uk,ul)=uk2ul2

5.2 μs
nldiffusion_flux! (generic function with 1 method)
25.3 μs

1D Nonlinear diffusion

2.4 μs
nlsystem1d
VoronoiFVM.DenseSystem{Float64,Int32,Int32}(num_species=1)
56.4 μs

Here, Newton's method is used in order to solve the nonlinear system of equations. The Jacobi matrix is assembled from the partial derivatives of the flux function g(uk,ul).

2.6 μs
1
1×11 Array{Float64,2}:
 0.01  0.212368  0.283019  0.324191  0.346554  …  0.324191  0.283019  0.212368  0.01
2
546 μs
55.2 ms
23.6 ms

2D Nonlinear diffusion

2.5 μs
nlsystem2d
VoronoiFVM.DenseSystem{Float64,Int32,Int32}(num_species=1)
102 μs
9.8 ms
99.1 ms
40.8 ms
3.0 ms
Status `/tmp/jl_Vy3imp/Project.toml`
  [cfc395e8] ExtendableGrids v0.7.4
  [5eed8a63] GridVisualize v0.1.2
  [7f904dfe] PlutoUI v0.7.1
  [d330b81b] PyPlot v2.9.0
  [82b139dc] VoronoiFVM v0.10.3
1.5 s