Implementing Finite Volume Methods 1 1
Continue on Finite Volume Methods for Elliptic Equations Finite Volumes in Two-Dimensions Poisson’s Equation Boundary Conditions Neumann Dirichlet Using Excel 2 2
Nodes placed at centre of control volumes 2-Dimensional grid development same as 1D. Note that the boundaries are on the control volume surfaces. [In the pictures, dotted lines represent control volumes, solid lines represent node adjacencies/data dependencies.] Control Volumes Control Volumes Nodes placed at centre of control volumes 3 3
Grid Generation - Similar as One-Dimension Use grid spacing h (=Dx) in x direction and k (= Dy) in y Consider Poisson's Equation Control Volume P S W N E e w s n h k ∂ 2 𝑢 ∂ 𝑥 2 + ∂ 2 𝑢 ∂ 𝑦 2 +𝑔=0 4 4
For an area A enclosed by the surface S, and vector field variable v, the DIVERGENCE theorem states: Let The Divergence theorem can be used on the Laplace equation for the scalar field u. Or 𝐴 ∇. 𝑣 𝑑𝐴 = 𝑆 𝑣 . 𝑛 𝑑𝑆 S A 𝑣 = ∂𝑢 ∂𝑥 , ∂𝑢 ∂𝑦 =∇𝑢 𝐴 ∇.(∇𝑢)𝑑𝐴 = 𝑆 ∇𝑢. 𝑛 𝑑𝑆 𝐴 ∂ 2 𝑢 ∂ 𝑥 2 + ∂ 2 𝑢 ∂ 𝑦 2 𝑑𝐴 = 𝑆 ∂𝑢 ∂𝑥 𝑛 𝑥 + ∂𝑢 ∂𝑦 𝑛 𝑦 𝑑𝑆 5 5
Using the divergence theorem it can be shown that: The first order derivatives can be approximated by: 𝑥𝑦 ∂ 2 𝑢 ∂ 𝑥 2 + ∂ 2 𝑢 ∂ 𝑦 2 +𝑔 𝑑𝑥𝑑𝑦 = ∂𝑢 ∂𝑥 𝑒 − ∂𝑢 ∂𝑥 𝑤 𝑘+ ∂𝑢 ∂𝑦 𝑛 − ∂𝑢 ∂𝑦 𝑠 ℎ+𝑔ℎ𝑘=0 ∂𝑢 ∂𝑥 𝑒 = 𝑈 𝐸 − 𝑈 𝑃 ℎ ∂𝑢 ∂𝑥 𝑤 = 𝑈 𝑃 − 𝑈 𝑊 ℎ ∂𝑢 ∂𝑦 𝑛 = 𝑈 𝑁 − 𝑈 𝑃 𝑘 ∂𝑢 ∂𝑦 𝑠 = 𝑈 𝑃 − 𝑈 𝑆 𝑘 P S W N E e w s n 6 6
Therefore at each node we have the following algebraic equations that represent the Poisson equation. 𝐴 𝑃 𝑈 𝑃 = 𝐴 𝐸 𝑈 𝐸 + 𝐴 𝑊 𝑈 𝑊 + 𝐴 𝑁 𝑈 𝑁 + 𝐴 𝑆 𝑈 𝑆 +𝑆 𝐴 𝐸 = 𝐴 𝑊 = 𝑘 ℎ 𝐴 𝑁 = 𝐴 𝑆 = ℎ 𝑘 𝐴 𝑃 = 𝐴 𝐸 + 𝐴 𝑊 + 𝐴 𝑁 + 𝐴 𝑆 𝑆=𝑔ℎ𝑘 P S W N E e w s n h k 7 7
It is normal to write Ap in this way, rather than, say The equation on the previous slide is in the standard form for finite volumes schemes It is normal to write Ap in this way, rather than, say This is because, if you use other volume shapes, such as triangles, rectangles or a mixture, the same sort of results (e.g. that Ap is the sum of the other coefficients) still hold 𝐴 𝑃 =2 𝑘 ℎ + ℎ 𝑘 8 8
The divergence theorem gives: Example: at north boundary ∂𝑢 ∂𝑥 𝑒 − ∂𝑢 ∂𝑥 𝑤 𝑘+ ∂𝑢 ∂𝑦 𝑛 − ∂𝑢 ∂𝑦 𝑠 ℎ+𝑔ℎ𝑘=0 ∂𝑢 ∂𝑦 =𝛼 ∂𝑢 ∂𝑥 𝑒 = 𝑈 𝐸 − 𝑈 𝑃 ℎ ∂𝑢 ∂𝑥 𝑤 = 𝑈 𝑃 − 𝑈 𝑊 ℎ ∂𝑢 ∂𝑦 𝑛 =𝛼 ∂𝑢 ∂𝑦 𝑠 = 𝑈 𝑃 − 𝑈 𝑆 𝑘 9 9
Therefore at each node on the north boundary we have 𝐴 𝑃 𝑈 𝑃 = 𝐴 𝐸 𝑈 𝐸 + 𝐴 𝑊 𝑈 𝑊 + 𝐴 𝑆 𝑈 𝑆 +𝑆 𝐴 𝐸 = 𝐴 𝑊 = 𝑘 ℎ , 𝐴 𝑆 = ℎ 𝑘 𝐴 𝑃 = 𝐴 𝐸 + 𝐴 𝑊 + 𝐴 𝑆 𝑆=𝑔ℎ𝑘+ℎ𝛼 10 10
Similarly at each node on the east boundary, if Similar on other boundaries, but the signs are reversed (south) (west) ∂𝑢 ∂𝑥 𝑒 =𝛽 𝐴 𝑃 𝑈 𝑃 = 𝐴 𝑊 𝑈 𝑊 + 𝐴 𝑁 𝑈 𝑁 + 𝐴 𝑆 𝑈 𝑆 +𝑆 𝐴 𝑊 = 𝑘 ℎ , 𝐴 𝑁 = 𝐴 𝑆 = ℎ 𝑘 𝐴 𝑃 = 𝐴 𝑊 + 𝐴 𝑁 + 𝐴 𝑆 𝑆=𝑔ℎ𝑘+𝑘𝛽 𝑆=𝑔ℎ𝑘−ℎ𝛼 𝑆=𝑔ℎ𝑘−𝑘𝛽 11 11
The divergence theorem gives: Example: at east boundary ∂𝑢 ∂𝑥 𝑒 − ∂𝑢 ∂𝑥 𝑤 𝑘+ ∂𝑢 ∂𝑦 𝑛 − ∂𝑢 ∂𝑦 𝑠 ℎ+𝑔ℎ𝑘=0 𝑢=𝜇 Boundary P h k ∂𝑢 ∂𝑥 𝑒 = 𝜇− 𝑈 𝑃 0.5h ∂𝑢 ∂𝑥 𝑤 = 𝑈 𝑃 − 𝑈 𝑊 ℎ ∂𝑢 ∂𝑦 𝑛 = 𝑈 𝑁 − 𝑈 𝑃 𝑘 ∂𝑢 ∂𝑦 𝑠 = 𝑈 𝑃 − 𝑈 𝑆 𝑘 𝑢=𝜇 12 12
Therefore at each node on the east boundary we have 𝐴 𝑃 𝑈 𝑃 = 𝐴 𝑊 𝑈 𝑊 + 𝐴 𝑁 𝑈 𝑁 + 𝐴 𝑆 𝑈 𝑆 +𝑆 𝐴 𝑊 = 𝑘 ℎ , 𝐴 𝑁 = 𝐴 𝑆 = ℎ 𝑘 𝐴 𝑃 =2 𝑘 ℎ + 𝐴 𝑊 + 𝐴 𝑁 + 𝐴 𝑆 𝑆=𝑔ℎ𝑘+2 𝑘 ℎ 𝜇 13 13
Similarly at each node on the north boundary, if 𝑢=𝜂 𝐴 𝑃 𝑈 𝑃 = 𝐴 𝐸 𝑈 𝐸 + 𝐴 𝑊 𝑈 𝑊 + 𝐴 𝑆 𝑈 𝑆 +𝑆 𝐴 𝐸 = 𝐴 𝑊 = 𝑘 ℎ , 𝐴 𝑆 = ℎ 𝑘 𝐴 𝑃 =2 ℎ 𝑘 + 𝐴 𝐸 + 𝐴 𝑊 + 𝐴 𝑆 𝑆=𝑔ℎ𝑘+2 ℎ 𝑘 𝜂 14 14
At each internal node k h 𝐴 𝑃 𝑈 𝑃 = 𝐴 𝐸 𝑈 𝐸 + 𝐴 𝑊 𝑈 𝑊 + 𝐴 𝑁 𝑈 𝑁 + 𝐴 𝑆 𝑈 𝑆 +𝑆 𝐴 𝐸 = 𝐴 𝑊 = 𝑘 ℎ 𝐴 𝑁 = 𝐴 𝑆 = ℎ 𝑘 𝐴 𝑃 = 𝐴 𝐸 + 𝐴 𝑊 + 𝐴 𝑁 + 𝐴 𝑆 𝑆=𝑔ℎ𝑘 P S W N E e w s n h k 15 15
P k h Can use transformations of source term to calculate BCs Remove the boundary term(s) A[B]=0 where [B]=N,S,E or W Neumann (+east or –west) (+north or –south) Dirichlet (u = UB) (east or west) (north or south) 𝑆→𝑆± ∂𝑢 ∂𝑥 𝑘 𝑆→𝑆± ∂𝑢 ∂𝑦 ℎ Boundary P h k 𝐴 𝑃 → 𝐴 𝑃 +2 𝑘 ℎ 𝑆→𝑆+2 𝑘 ℎ 𝑈 𝐵 𝐴 𝑃 → 𝐴 𝑃 +2 ℎ 𝑘 𝑆→𝑆+2 ℎ 𝑘 𝑈 𝐵 16 16
Disadvantages: Need to use structured mesh. May not be conservative. Finite Difference: Approximate derivatives at each node via a difference formula derived from Taylor series expansions on a regular grid. Advantages: Easy to implement. Easy to obtain higher order derivatives. Disadvantages: Need to use structured mesh. May not be conservative. Finite Volume: Approximate first order derivatives on the faces of each control volume. Advantages: Can use unstructured meshes. Conservative. Disadvantage: Difficult to obtain higher order derivatives. 17 17
Mesh nodes are at the centre of each cell (e.g. for at ) There are no known boundary cell values (even if a boundary value for u is known – different from Finite Differences) Work out general formula, copy to all cells and apply boundary transformations 𝛥𝑥 2 , 3Δx 2 ,… 0<𝑥<1 18 18
Consider the Poisson equation on the following domain: Using h = k = 0.5, g = 2, program the FV method in Excel [class demo] ∂𝑢 ∂𝑦 =0 (0,0) (0,5) (3,2) (3,3) (7,2) (7,3) (10,0) (10,5) ∂𝑢 ∂𝑦 =0 ∂𝑢 ∂𝑥 =0 ∂𝑢 ∂𝑥 =0 ∂𝑢 ∂𝑥 =−5 𝑢=50 ∂𝑢 ∂𝑦 =0 ∂𝑢 ∂𝑦 =0 ∂ 2 𝑢 ∂ 𝑥 2 + ∂ 2 𝑢 ∂ 𝑦 2 +𝑔=0 19 19
At each internal node (see slide 15) So in general However, may be sensible to retain g, h, k in the formula so we can modify the Excel file easily (see example) 𝐴 𝐸 = 𝐴 𝑊 = 𝑘 ℎ = 0.5 0.5 =1 𝐴 𝑁 = 𝐴 𝑆 = ℎ 𝑘 = 0.5 0.5 =1 𝐴 𝑃 = 𝐴 𝐸 + 𝐴 𝑊 + 𝐴 𝑁 + 𝐴 𝑆 =1+1+1+1=4 𝑆=𝑔ℎ𝑘=2×0.5×0.5=0.5 𝑈 𝑃 = 1 4 𝑈 𝐸 + 𝑈 𝑊 + 𝑈 𝑁 + 𝑈 𝑆 +0.5 20 20
At the West boundary we have Neumann BCs ∂𝑢 ∂𝑥 =−5 At the West boundary we have Neumann BCs Use general formula (slide 15) but apply boundary transformations (slide 16) but (transformation) (transformation) So in general on West boundary 𝐴 𝐸 = 𝑘 ℎ = 0.5 0.5 =1 𝐴 𝑊 =0 𝐴 𝑁 = 𝐴 𝑆 = ℎ 𝑘 = 0.5 0.5 =1 𝐴 𝑃 = 𝐴 𝐸 + 𝐴 𝑊 + 𝐴 𝑁 + 𝐴 𝑆 =1+0+1+1=3 𝑆=𝑔ℎ𝑘=2×0.5×0.5=0.5 𝑆→𝑆− ∂𝑢 ∂𝑥 𝑘=0. 5− −5 ×0 .5=3 𝑈 𝑃 = 1 3 𝑈 𝐸 + 𝑈 𝑁 + 𝑈 𝑆 +3 21 21
At the East boundary we have Dirichlet BCs u=50 Use general formula (slide 15) but apply boundary transformations (slide 16) but (transformation) (transformation) So in general on East boundary 𝐴 𝑊 = 𝐴 𝑁 = 𝐴 𝑆 = 0.5 0.5 =1 𝐴 𝐸 =0 𝐴 𝑃 = 𝐴 𝐸 + 𝐴 𝑊 + 𝐴 𝑁 + 𝐴 𝑆 =1+0+1+1=3 𝐴 𝑃 → 𝐴 𝑃 +2 𝑘 ℎ =3+2 0.5 0.5 =5 𝑆=𝑔ℎ𝑘=2×0.5×0.5=0.5 𝑆→𝑆+2 𝑘 ℎ 𝑈 𝐵 =0.5+2 0.5 0.5 50=100.5 𝑈 𝑃 = 1 5 𝑈 𝑊 + 𝑈 𝑁 + 𝑈 𝑆 +100.5 22 22
At the East boundary we have Dirichlet BCs u=50 At the South boundary we have Neumann BCs but (S & E transformation) (E transformation) (S transformation) So for bottom right hand corner ∂𝑢 ∂𝑦 =0 𝐴 𝑊 = 𝐴 𝑁 = 0.5 0.5 =1 𝐴 𝑆 = 𝐴 𝐸 =0 𝐴 𝑃 = 𝐴 𝐸 + 𝐴 𝑊 + 𝐴 𝑁 + 𝐴 𝑆 =0+1+1+0=2 𝐴 𝑃 → 𝐴 𝑃 +2 𝑘 ℎ =2+2 0.5 0.5 =4 𝑆=𝑔ℎ𝑘=2×0.5×0.5=0.5 𝑆→𝑆+2 𝑘 ℎ 𝑈 𝐵 =0.5+2 0.5 0.5 50=100.5 𝑆→𝑆− ∂𝑢 ∂𝑦 ℎ=100.5−0×0.5=100.5 𝑈 𝑃 = 1 4 𝑈 𝑊 + 𝑈 𝑁 +100.5 23 23
24 24