Anda di halaman 1dari 32

Lehrstuhl Informatik V

Part II: Finite Difference/Volume Discretisation for


CFD

Finite Volume Method of the Advection-Diffusion Equation

A Finite Difference/Volume Method for the Incompressible


Navier-Stokes Equations
Marker-and-Cell Method, Staggered Grid
Spatial Discretisation of the Continuity Equation
Spatial Discretisation of the Momentum Equations
Time Discretisation
Chorin Projection
Implementation Aspects

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 19
Lehrstuhl Informatik V

Finite Volume Method –


Advection-Diffusion Equation
• compute tracer concentration q with diffusion β and convection v :

−βqxx + (vq)x = 0 on Ω = (0, 1)

with boundary conditions q(0) = 1 and q(1) = 0.


• equidistant grid points xi = ih, grid cells [xi , xi+1 ]
• back to representation via conservation law (for one grid cell):
Z xi+1 xi+1

F (x) dx = F (x) =0
xi ∂x xi

with F (x) = F (q(x)) = −βqx (x) + vq(x).


• we need to compute the flux F at the boundaries of the grid cells;
however, assume q(x) piecewise constant within the grid cells

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 20
Lehrstuhl Informatik V

Finite Volume Method –


Advection-Diffusion Equation (2)
• wanted: compute F (xi ) with F (q(x)) = −βqx (x) + vq(x)
• where q(x) := qi for each Ωi = [xi , xi+1 ]
• computing the diffusive flux is straightforward:
q(xi+1 ) − q(xi )

−βqx x
= −β
i+1 h
• options for advective flux vq:
• symmetric flux:
vq(xi ) + vq(xi+1 )
vq xi+1
=
2
• “upwind” flux:

vq(xi ) if v > 0
vq xi+1
=
vq(xi+1 ) if v < 0

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 21
Lehrstuhl Informatik V

Finite Volume Method –


Advection-Diffusion Equation (3)
• system of equations: for all i
xi+1

F (x) = F (xi+1 ) − F (xi ) = 0
xi

• for symmetric flux:


q(xi+1 ) − 2q(xi ) + q(xi−1 ) q(xi+1 ) − q(xi−1 )
−β 2
+ v =0
h 2h
leads to non-physical behaviour as soon as β < vh
2
(observe signs of matrix elements!)
• system of equations for upwind flux (assume v > 0):
q(xi+1 ) − 2q(xi ) + q(xi−1 ) q(xi ) − q(xi−1 )
−β 2
+ v =0
h h
→ stable, but overly diffusive solutions (positive definite matrix)
Tobias Neckel: Scientific Computing I
Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 22
Lehrstuhl Informatik V

Marker-and-Cell Method – Staggered Grid


Marker-and-Cell method (Harlow and Welch, 1965):
• discretization scheme: Finite Differences
• can be shown to be equivalent to Finite Volumes, however
• based on a so-called staggered grid:
• Cartesian grid (rectangular grid cells),
with cell centres at xi,j := (ih, jh), e.g.
• pressure located in cell centres
• velocities (those in normal direction) located on cell edges

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 23
Lehrstuhl Informatik V

Spatial Discretisation – Continuity Equation:

• mass conservation: discretise ∇ · ~


u
→ evaluate derivative at cell centres, allows central derivatives:


∂u ∂v ui,j − ui−1,j vi,j − vi,j−1
(∇ · ~u ) i,j = + ≈ +
∂x i,j ∂y i,j h h

remember: ui,j and vi,j located on cell edges



u ) i,j := (∇ · ~u ) x
• notation: (∇ · ~
i,j
(evaluate expression at cell centre xi,j )

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 24
Lehrstuhl Informatik V

Spatial Discretisation – Pressure Terms

• note: velocities located on midpoints of cell edges



∂u ∂v
= ... , = ...
∂t i+ 1 ,j ∂t i,j+ 1
2 2

=⇒ all derivatives need to be approximated at midpoints of cell


edges!
• pressure term ∇p: central differences for first derivatives
(as pressure is located in cell centres)

∂p pi+1,j − pi,j ∂p pi,j+1 − pi,j
≈ , ≈
∂x i+ 1 ,j h ∂y i,j+ 1 h
2 2

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 25
Lehrstuhl Informatik V

Spatial Discretisation – Diffusion Term


• for diffusion term ∆~
u : use standard 5- or 7-point stencil
• 2D:

ui−1,j + ui,j−1 − 4ui,j + ui+1,j + ui,j+1


∆u i,j ≈
h2
• 3D:

ui−1,j,k + ui,j−1,k + ui,j,k−1 − 6ui,j,k + ui+1,j,k + ui,j+1,k + ui,j,k+1


∆u ≈
i,j,k h2
Tobias Neckel: Scientific Computing I
Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 26
Lehrstuhl Informatik V

Spatial Discretisation – Convection Terms


• treat derivatives of nonlinear terms (~
u · ∇)~u :
• central differences (for momentum equation in x-direction):

∂u ui+1,j − ui−1,j ∂u
ui,j+1 − ui,j−1
u ≈ ui,j , v ≈v x
∂x i+ 1 ,j 2h ∂y i+ 1 ,j i+ 1 ,j
2
2h
2 2

1

with v xi+ 1 ,j
= 4 vi,j + vi,j−1 + vi+1,j + vi+1,j−1
2

• upwind differences (for momentum equation in x-direction):



∂u ui,j − ui−1,j ∂u ui,j − ui,j−1
u ≈ ui,j , v ≈ v
∂x x 2h ∂y x xi+ 1 ,j
2
2h
i+ 1 ,j i+ 1 ,j
2 2


if ui,j > 0 and v x >0
i+ 1 ,j
2

• mix of central and upwind differences possible and used

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 27
Lehrstuhl Informatik V

Time Discretisation

• recall the incompressible Navier-Stokes equations:

∇ · ~u = 0
∂ 1
~u + (~u · ∇)~u = −∇p + ∆~u + f
∂t Re
• note the role of the unknowns:
→ 2 or 3 equations for velocities (x, y , and z component)
resulting from momentum conservation
→ 4th equation (mass conservation) to “ close” the system;
required to determine pressure p
→ however, p does not occur explicitly in mass conservation
• possible approach: Chorin’s projection method
→ p acts as a variable to enforce the mass conservation as
“side condition”

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 28
Lehrstuhl Informatik V

Time Discretisation – Chorin Projection


• continuous NSE:
 

ρ ~u + (~u · ∇)~u + ∇p − µ∆~u = f
∂t
∇ · ~u = 0
• semi-discrete NSE (after spatial discretisation):

A~u˙ h + D~uh + C(~uh )~uh − M T ph = fh , (3)


M ~uh = 0, (4)
• derive semi-discrete continuity equation (4) w.r.t. t:

M ~u˙ h = 0. (5)
u˙ h and insert into (5)
• formally invert Eq. (3) w.r.t. ~
⇒ discrete pressure Poisson equation (PPE):
(MA−1 M T ) ph = MA−1 (−f + D~uh + C(~uh )~uh ), (6)
| {z }
=:Q
Tobias Neckel: Scientific Computing I
Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 29
Lehrstuhl Informatik V

Time Discretisation – Chorin Projection

• updating the velocities:


• discretise time with explicit method (explicit Euler, e.g.):

~uh(n+1) − ~uh(n)
= ...
τ
• update velocity “correctly”: solve momentum equations (3)
• use pressure ph of PPE solution to compute discrete
pressure gradients M T ph :
 
= ~uh + τ −D~uh − C(~uh )~uh + ~fh + M T ph
(n+1) (n) (n) (n) (n) (n)
⇒ ~uh

• costs: solve 1 linear system of equations in each time step!

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 30
Lehrstuhl Informatik V

Implementation

• geometry representation as a flag field (Marker-and-Cell)

flag field as an array of booleans:


000000000000000000000000
000000000000000000000000
000000001100000000000000
000000000110000000000000
000000000011000000000000
000000000001100000000000
000000000000000000000000
000000000000000000000000

• input data (boundary conditions) and output data (computed


results) as arrays

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 31
Lehrstuhl Informatik V

Implementation (2)

Lab course “Scientific Computing – Computational Fluid Dynamics”:


• modular C/C++ code
• parallelization:
• simple data parallelism, domain decomposition
• straightforward MPI-based parallelization (exchange of
ghost layers)
• target architectures:
• parallel computers with distributed memory
• clusters
• possible extensions:
• free-surface flows (“the falling drop”)
• multigrid solver for the pressure equation
• heat transfer

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 32
Lehrstuhl Informatik V

Part III: The Shallow Water Equations and Finite


Volumes Revisited

The Shallow Water Equations


Modelling Scenario: Tsunami Simulation

Finite Volume Discretisation


Central and Upwind Fluxes
Lax-Friedrichs Flux

Towards Tsunami Simulation


Wave Speed of Tsunamis
Treatment of Bathymetry Data

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 33
Lehrstuhl Informatik V

The Shallow Water Equations


     
h hu hv
∂   ∂  2 1 2 ∂ 
hu + hu + 2 gh + huv  = S(t, x, y )
∂t ∂x ∂y
hv huv hv 2 + 12 gh2

Comments on modelling:
• generalized 2D hyperbolic PDE: q = (h, hu, hv )T

∂ ∂ ∂
q+ F (q) + G(q) = S(t, x, y )
∂t ∂x ∂y

derived from conservations laws for mass and momentum


• may be derived by vertical averaging from the 3D incompressible
Navier-Stokes equations
• compare to Euler equations: density ρ vs. water depth h

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 34
Lehrstuhl Informatik V

Modelling Scenario: Tsunami Simulation

The Ocean as “Shallow Water”??


• compare horizontal (∼ 1000 km) to vertical (∼ 5 km) length scale
• wave lengths large compared to water depth
• vertical flow may be neglected; movement of the “entire water
column”

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 35
Lehrstuhl Informatik V

Modelling Scenario: Tsunami Simulation

The Ocean as “Shallow Water”??


• compare horizontal (∼ 1000 km) to vertical (∼ 5 km) length scale
• wave lengths large compared to water depth
• vertical flow may be neglected; movement of the “entire water
column”

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 35
Lehrstuhl Informatik V

Modelling Scenario: Tsunami Simulation

The Ocean as “Shallow Water”??


• compare horizontal (∼ 1000 km) to vertical (∼ 5 km) length scale
• wave lengths large compared to water depth
• vertical flow may be neglected; movement of the “entire water
column”

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 35
Lehrstuhl Informatik V

Modelling Scenario: Tsunami Simulation

The Ocean as “Shallow Water”??


• compare horizontal (∼ 1000 km) to vertical (∼ 5 km) length scale
• wave lengths large compared to water depth
• vertical flow may be neglected; movement of the “entire water
column”

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 35
Lehrstuhl Informatik V

Modelling Scenario: Tsunami Simulation (2)

Tsunami Modelling with the Shallow Water equations:


• source term S(x, y) includes bathymetry data (i.e., elevation of
ocean floor)
• Coriolis forces, friction, etc., as possible further terms
• boundary conditions are difficult: coastal inundation, outflow at
domain boundaries
Tobias Neckel: Scientific Computing I
Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 36
Lehrstuhl Informatik V

Modelling Scenario: Tsunami Simulation (2)

Tsunami Modelling with the Shallow Water equations:


• source term S(x, y) includes bathymetry data (i.e., elevation of
ocean floor)
• Coriolis forces, friction, etc., as possible further terms
• boundary conditions are difficult: coastal inundation, outflow at
domain boundaries
Tobias Neckel: Scientific Computing I
Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 36
Lehrstuhl Informatik V

Modelling Scenario: Tsunami Simulation (2)

Tsunami Modelling with the Shallow Water equations:


• source term S(x, y) includes bathymetry data (i.e., elevation of
ocean floor)
• Coriolis forces, friction, etc., as possible further terms
• boundary conditions are difficult: coastal inundation, outflow at
domain boundaries
Tobias Neckel: Scientific Computing I
Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 36
Lehrstuhl Informatik V

Modelling Scenario: Tsunami Simulation (2)

Tsunami Modelling with the Shallow Water equations:


• source term S(x, y) includes bathymetry data (i.e., elevation of
ocean floor)
• Coriolis forces, friction, etc., as possible further terms
• boundary conditions are difficult: coastal inundation, outflow at
domain boundaries
Tobias Neckel: Scientific Computing I
Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 36
Lehrstuhl Informatik V

Finite Volume Discretisation


• discretise system of PDEs

∂ ∂ ∂
q+ F (q) + G(q) = S(t, x, y )
∂t ∂x ∂y
• with      
h hu hv
q := hu  F (q) := hu 2 + 12 gh2  G(q) :=  huv 
hv huv hv 2 + 12 gh2

• basic form of numerical schemes:


(n+1) (n) τ  (n) (n)
 τ 
(n) (n)

Qi,j = Qi,j − Fi+ 1 ,j − Fi− 1 ,j − Gi,j+ 1 − Gi,j− 1
h 2 2 h 2 2

(n) (n)
where Fi+ 1 ,j , Gi,j+ 1 , . . . approximate the flux functions F (q) and
2 2
G(q) at the grid cell boundaries

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 37
Lehrstuhl Informatik V

Central and Upwind Fluxes


(n) (n)
• define fluxes F 1 , G , . . . via 1D numerical flux function F:
i+ ,j i,j+ 1 2 2

(n) (n) (n)  (n) (n) (n) 


Fi+ 1 =F Qi , Qi+1 Gj− 1 =F Qj−1 , Qj
2 2

• central flux:

(n) (n) (n)  1 (n)  (n)  


Fi+ 1 = F Qi , Qi+1 := F Qi + F Qi+1
2 2
leads to unstable methods for convective transport
• upwind flux (here, for h-equation, F (h) = hu):
(
 hu if u 1 >0
(n) (n) (n) i i+ 2
Fi+ 1 = F hi , hi+1 :=
2 hu i+1 if u i+ 1 < 0
2

stable, but includes artificial diffusion


Tobias Neckel: Scientific Computing I
Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 38
Lehrstuhl Informatik V

(Local) Lax-Friedrichs Flux


• classical Lax-Friedrichs method uses as numerical flux:

(n) (n) (n)  1 (n)  (n) 


 h
(n) (n) 
Fi+ 1 =F Qi , Qi+1 := F Qi + F Qi+1 − Qi+1 −Qi
2 2 2τ
• can be interpreted as central flux plus diffusion flux:
(n) (n)
h (n) (n)  h2 Qi+1 − Qi
Qi+1 − Qi = ·
2τ 2τ h
h2
with diffusion coefficient where c := τh is some kind of
2τ ,
velocity (“one grid cell per time step”)
• idea of local Lax-Friedrichs method: use the “appropriate”
velocity

(n) 1 (n)  (n) 


 ai+ 1
(n) (n) 
Fi+ 1 := F Qi + F Qi+1 − 2
Qi+1 − Qi
2 2 2

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 39
Lehrstuhl Informatik V

Wave Speed of Tsunamis


• consider the 1D case
   
∂ h ∂ hu
+ =0
∂t hu ∂x hu 2 + 12 gh2

• with q = (q1 , q2 )T := (h, hu)T , we obtain


   
∂ q1 ∂ q2
+ =0
∂t q2 ∂x q22 /q1 + 12 gq12
• write in convective form:
   
∂ q1 0 ∂ q1
+f =0
∂t q2 ∂x q2

with
     
∂f1 /∂q1 ∂f1 /∂q2 0 1 0 1
f0 = = =
∂f2 /∂q1 ∂f2 /∂q2 −q22 /q12 + gq1 2q2 /q1 −u 2 + gh 2u

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 40
Lehrstuhl Informatik V

Wave Speed of Tsunamis (2)


• compute eigenvectors and eigenvalues of f 0 :
 
1/2
p 1/2 1p
λ = u ± gh r =
u± gh
• and then with f 0 = RΛR −1 , where R := (r 1 , r 2 ) and
Λ := diag(λ1 , λ2 ), we can diagonalise the PDE:
   
∂ w1 ∂ w1
+Λ = 0, w = R −1 q
∂t w2 ∂x w2
• for small changes in h and small velocities, we thus obtain
p that
waves are “advected” (i.e., travel) at speed λ1/2 ≈ ± gh
• recall local Lax-Friedrichs method:
1     ai+ 1
(n) (n) (n) (n) (n) 
Fi+ 1 := F Qi + F Qi+1 − 2
Qi − Qi−1
2 2 2
→ choose ai+ 1 = max{λk }
2

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 41
Lehrstuhl Informatik V

Shallow Water Equations with Bathymetry

h
b

       
h hu hv 0
∂   ∂  2 1 2 ∂ 
hu + hu + 2 gh + huv  = −(ghb)x 
∂t ∂x ∂y
hv huv hv 2 + 12 gh2 −(ghb)y

Questions for numerics:


• treat (bh)x and (bh)y as source terms or include these into flux
computations?
• preserve certain properties of solutions – e.g., “lake at rest”
Tobias Neckel: Scientific Computing I
Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 42
Lehrstuhl Informatik V

Shallow Water Equations with Bathymetry (2)


Consider “Lake at Rest” Scenario:
• “at rest”: velocities u = 0 and v = 0
• examine local Lax-Friedrichs flux in h equation:

(n) 1 (n) (n)


 ai+ 1
(n) (n) 
Fi+ 1 = (hu)i + (hu)i+1 − 2
hi+1 − hi =0
2 2 2
(n) (n)
ai+ 1 (n) (n) 
ai− 1 (n) (n) 
⇒ Fi+ 1 − Fi− 1 =− 2
hi+1 − hi + 2
hi − hi−1 =0
2 2 2 2
p
• note: ai± 1 ≈ gh and if bi−1 6= bi 6= bi+1 then hi−1 6= hi 6= hi+1
2

• thus: “lake at rest” not an equilibrium solution for local


Lax-Friedrichs flux

Additional problems:
• complicated numerics close to the shore
• in particular: “wetting and drying” (inundation of the coast)
Tobias Neckel: Scientific Computing I
Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 43
Lehrstuhl Informatik V

References and Literature

Course material is mostly based on:


• R. J. LeVeque: Finite Volume Methods for Hyperbolic Equations,
Cambridge Texts in Applied Mathematics, 2002.
• M. Griebel, T. Dornseifer and T. Neunhoeffer: Numerical
Simulation in Fluid Dynamics: A Practical Introduction,
SIAM Monographs on Mathematical Modeling and Computation,
SIAM, 1997.

Shallow Water Code SWE:


→ http://www5.in.tum.de/SWE/

Tobias Neckel: Scientific Computing I


Module 9: Case Study – Computational Fluid Dynamics, Winter 2013/2014 44

Anda mungkin juga menyukai