true
5.3 s
7.4 ms

Implementation of the finite volume method

Here, we specifically introduce the Voronoi finite volume method on triangular grids.

We discuss the implementation of the method for the problem

δu=fδnu+αu=g

4.8 μs

Geometrical data for finite volumes

As seen in the previous lecture, we need to be able to calculate the contributions to the Voronoi cell data for each triangle.

3.2 μs

PA=[3, 3]

95.3 ms
995 ms

Needed data

  • Edge lengths hkl:

a=|PBPC|,b=|PAPC|,c=|PAPB|

  • Contributions to lengths of the interfaces between Voronoi cells |σklT|sa,sb,sc: length fo lines joining the corresponding edge centers PBC,PAC,PAB with the triangle circumcenter PCC.

  • Practically, we need the values of the ratios σklhkl:

ea=saa,eb=sbb,ec=scc

  • Triangle contributions to the Voronoi cell areas around the respective triangle nodes ωA=|PAPABPCCPAC|,ωB=|PBPBCPCCPAB|,ωC=|PCPACPCCPBC|

8.7 μs

Calculation steps for the interface contributions

We show the calculation steps for ea,ωa, the others can be obtained via corresponding permutations.

  1. Semiperimeter:

s=a2+b2+c2

  1. Square area (from Heron's formula):

16A2=16s(sa)(sb)(sc)=(a+b+c)(ab+c)(a+bc)(a+b+c)

  1. Square circumradius:

R2=a2b2c2(a+b+c)(ab+c)(a+bc)(a+b+c)=a2b2c216A2

  1. Square of the Voronoi interface contribution via Pythagoras:

sa2=R2(12a)2=a2(a2b2c2)24(abc)(ab+c)(a+bc)(a+b+c)

  1. Square of interface contribution over edge length:

ea2=sa2a2=(a2b2c2)24(abc)(ab+c)(a+bc)(a+b+c)=(b2+c2a2)264A2

  1. Interface contribution over edge length:

ea=saa=b2+c2a28A

  1. Calculation of the area contributions

ωa=14csc+14bsb=14(c2ec+b2eb)

10.2 μs
  • The sign chosen implies a positive value if the angle αA<π2, and a negative value if it is obtuse. In the latter case, this corresponds to the negative length of the line between edge midpoint and circumcenter, which is exactly the value which needs to be added to the corresponding amount from the opposite triangle in order to obtain the measure of the Voronoi face.

  • If an edge between two triangles is not locally Delaunay, the summary contribution from the two triangles with respect to this edge will become negative.

4.4 μs

Steps to the implenentation

We describe a triangular discretization mesh by three arrays:

  • pointlist: 2×npoints floating point array of node coordinates of the triangulations. pointlist[:,i] then contains the coordinates of point i.

  • trianglelist: 3×nntri integer array describing which three nodes belong to a given triangle. trianglelist[:,i] then contains the numbers of nodes belonging to triangle i.

  • segmentlist: 2×nsegs integer array describing which two nodes belong to a given boundary segment. segmentlist[:,i] contains the numbers of nodes for boundary segment i.

Triangle form factors

For triangle itri, we want to calculate the corresponding form factors e and ω:

7.6 μs
trifactors! (generic function with 1 method)
66.6 μs

Boundary form factors

Here we need for an interface segment of two points PA,PB the contributions to the intersection of the Voronoi cell boundary with the outer boundary which is just the half length: γA=12|PAPB|,γB=12|PAPB|

3.3 μs
bfacefactors! (generic function with 1 method)
22.2 μs

Matrix assembly

The matrix assembly consists of two loops, one over all triangles, and another one over the boundary segments.

The implementation hints at the possibility to work in different space dimensions

3.5 μs
assemble! (generic function with 1 method)
66.7 μs

Graphical representation

It would be nice to have a graphical representation of the solution data. We can interpret the solution as a piecewise linear function on the triangulation: each triangle has three nodes each carrying one solution value.

On the other hand, a linear function of two variables is defined by values in three points. This allows to define a piecewise linear, continuous solution function. This approach is well known for the finite element method which we will introduce later.

3.8 μs
plot (generic function with 1 method)
33.3 μs

An alternative way of showing the result is the 3D plot of the function graph:

2.1 μs
plot3d (generic function with 1 method)
26.4 μs

Calculation example

Now we are able to solve our intended problem.

Grid generation

3.6 μs
make_grid (generic function with 1 method)
69.7 μs
352 ms

Plotting the grid

In the triout data structure, we indeed see a pointlist, a trianglelist and a segmentlist.

We use the plot_in_out function from Triangulate.jl to plot the grid.

Plot grid:

23.1 ms
696 ms

Number of points: 24, number of triangles: 30.

5.7 ms

Desired number of triangles

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

6.3 ms

Solving the problem

Problem data

3.5 μs
f (generic function with 1 method)
14.9 μs
g (generic function with 1 method)
11.7 μs

δ: 1.0 α: 1.0

9.8 ms
solve_example (generic function with 1 method)
22.1 μs
solution
108 ms
72.7 ms

3D Plot ?

7.1 ms
44.0 ns