Part II: Finite Difference/Volume Discretisation for CFD Finite Volume Metod of te Advection-Diffusion Equation A Finite Difference/Volume Metod for te Incompressible Navier-Stokes Equations Marker-and-Cell Metod, Staggered Grid Spatial Discretisation of te Continuity Equation Spatial Discretisation of te Momentum Equations Time Discretisation Corin Projection Implementation Aspects Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 19
Finite Volume Metod Advection-Diffusion Equation compute tracer concentration q wit diffusion β and convection v: βq xx + vq) x = 0 on Ω = 0, 1) wit boundary conditions q0) = 1 and q1) = 0. equidistant grid points x i = i, grid cells [x i, x i+1 ] back to representation via conservation law for one grid cell): xi+1 x i x x i+1 F x) dx = Fx) = 0 x i wit Fx) = F qx)) = βq x x) + vqx). we need to compute te flux F at te boundaries of te grid cells; owever, assume qx) piecewise constant witin te grid cells Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 0
Finite Volume Metod Advection-Diffusion Equation ) wanted: compute Fx i ) wit Fqx)) = βq x x) + vqx) were qx) := q i for eac Ω i = [x i, x i+1 ] computing te diffusive flux is straigtforward: options for advective flux vq: symmetric flux: βq x xi+1 = β qx i+1) qx i ) upwind flux: vq xi+1 = vqx i) + vqx i+1 ) vq xi+1 = { vqxi ) if v > 0 vqx i+1 ) if v < 0 Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 1
Finite Volume Metod Advection-Diffusion Equation 3) system of equations: for all i x i+1 F x) = F x i+1 ) Fx i ) = 0 x i for symmetric flux: β qx i+1) qx i ) + qx i 1 ) + v qx i+1) qx i 1 ) = 0 leads to non-pysical beaviour as soon as β < v observe signs of matrix elements!) system of equations for upwind flux assume v > 0): β qx i+1) qx i ) + qx i 1 ) + v qx i) qx i 1 ) = 0 stable, but overly diffusive solutions positive definite matrix) Module 9: Case Study Computational Fluid Dynamics, Winter 013/014
Marker-and-Cell Metod Staggered Grid Marker-and-Cell metod Harlow and Welc, 1965): discretization sceme: Finite Differences can be sown to be equivalent to Finite Volumes, owever based on a so-called staggered grid: Cartesian grid rectangular grid cells), wit cell centres at x i,j := i, j), e.g. pressure located in cell centres velocities tose in normal direction) located on cell edges Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 3
Spatial Discretisation Continuity Equation: mass conservation: discretise u evaluate derivative at cell centres, allows central derivatives: u) i,j = u x + v i,j y u i,j u i 1,j + v i,j v i,j 1 i,j remember: u i,j and v i,j located on cell edges notation: u) i,j := u) xi,j evaluate expression at cell centre x i,j ) Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 4
Spatial Discretisation Pressure Terms note: velocities located on midpoints of cell edges u v t =..., i+ 1,j t =... i,j+ 1 = 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 x p i+1,j p i,j p, i+ 1,j y p i,j+1 p i,j i,j+ 1 Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 5
Spatial Discretisation Diffusion Term for diffusion term u: use standard 5- or 7-point stencil D: 3D: u i,j u i 1,j + u i,j 1 4u i,j + u i+1,j + u i,j+1 u i,j,k u i 1,j,k + u i,j 1,k + u i,j,k 1 6u i,j,k + u i+1,j,k + u i,j+1,k + u i,j,k+1 Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 6
Spatial Discretisation Convection Terms treat derivatives of nonlinear terms u ) u: central differences for momentum equation in x-direction): u u u i+1,j u i 1,j x u i,j, v u i+ 1,j y v u i,j+1 u i,j 1 xi+ i+ 1,j 1,j wit v ) xi+ = 1 1 4 vi,j + v i,j 1 + v i+1,j + v i+1,j 1,j upwind differences for momentum equation in x-direction): u u u i,j u i 1,j x u i,j, v u xi+ y v u i,j u i,j 1 xi+ 1 1 xi+,j 1,j,j if u i,j > 0 and v xi+ 1,j > 0 mix of central and upwind differences possible and used Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 7
Time Discretisation recall te incompressible Navier-Stokes equations: u = 0 t u + u ) u = p + 1 Re u + f note te role of te unknowns: or 3 equations for velocities x, y, and z component) resulting from momentum conservation 4t equation mass conservation) to close te system; required to determine pressure p owever, p does not occur explicitly in mass conservation possible approac: Corin s projection metod p acts as a variable to enforce te mass conservation as side condition Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 8
Time Discretisation Corin Projection continuous NSE: ) ρ t u + u ) u + p µ u = f u = 0 semi-discrete NSE after spatial discretisation): A u + D u + C u ) u M T p = f, 3) derive semi-discrete continuity equation 4) w.r.t. t: M u = 0, 4) M u = 0. 5) formally invert Eq. 3) w.r.t. u and insert into 5) discrete pressure Poisson equation PPE): MA 1 M T ) p = MA 1 f + D u + C u ) u ), 6) } {{ } =:Q Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 9
Time Discretisation Corin Projection updating te velocities: discretise time wit explicit metod explicit Euler, e.g.): u n+1) u n) τ =... update velocity correctly : solve momentum equations 3) use pressure p of PPE solution to compute discrete pressure gradients M T p : u n+1) = u n) + τ D u n) C u n) ) u n) + f n) + M T p ) costs: solve 1 linear system of equations in eac time step! Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 30
Implementation geometry representation as a flag field Marker-and-Cell) flag field as an array of booleans: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 input data boundary conditions) and output data computed results) as arrays Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 31
Implementation ) Lab course Scientific Computing Computational Fluid Dynamics : modular C/C++ code parallelization: simple data parallelism, domain decomposition straigtforward MPI-based parallelization excange of gost layers) target arcitectures: parallel computers wit distributed memory clusters possible extensions: free-surface flows te falling drop ) multigrid solver for te pressure equation eat transfer Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 3
Part III: Te Sallow Water Equations and Finite Volumes Revisited Te Sallow Water Equations Modelling Scenario: Tsunami Simulation Finite Volume Discretisation Central and Upwind Fluxes Lax-Friedrics Flux Towards Tsunami Simulation Wave Speed of Tsunamis Treatment of Batymetry Data Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 33
Te Sallow Water Equations t u v + x u u + 1 g + y uv v uv = St, x, y) v + 1 g Comments on modelling: generalized D yperbolic PDE: q =, u, v) T t q + x Fq) + y Gq) = St, x, y) derived from conservations laws for mass and momentum may be derived by vertical averaging from te 3D incompressible Navier-Stokes equations compare to Euler equations: density ρ vs. water dept Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 34
Modelling Scenario: Tsunami Simulation Te Ocean as Sallow Water?? compare orizontal 1000 km) to vertical 5 km) lengt scale wave lengts large compared to water dept vertical flow may be neglected; movement of te entire water column Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 35
Modelling Scenario: Tsunami Simulation Te Ocean as Sallow Water?? compare orizontal 1000 km) to vertical 5 km) lengt scale wave lengts large compared to water dept vertical flow may be neglected; movement of te entire water column Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 35
Modelling Scenario: Tsunami Simulation Te Ocean as Sallow Water?? compare orizontal 1000 km) to vertical 5 km) lengt scale wave lengts large compared to water dept vertical flow may be neglected; movement of te entire water column Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 35
Modelling Scenario: Tsunami Simulation Te Ocean as Sallow Water?? compare orizontal 1000 km) to vertical 5 km) lengt scale wave lengts large compared to water dept vertical flow may be neglected; movement of te entire water column Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 35
Modelling Scenario: Tsunami Simulation ) Tsunami Modelling wit te Sallow Water equations: source term Sx, y) includes batymetry data i.e., elevation of ocean floor) Coriolis forces, friction, etc., as possible furter terms boundary conditions are difficult: coastal inundation, outflow at domain boundaries Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 36
Modelling Scenario: Tsunami Simulation ) Tsunami Modelling wit te Sallow Water equations: source term Sx, y) includes batymetry data i.e., elevation of ocean floor) Coriolis forces, friction, etc., as possible furter terms boundary conditions are difficult: coastal inundation, outflow at domain boundaries Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 36
Modelling Scenario: Tsunami Simulation ) Tsunami Modelling wit te Sallow Water equations: source term Sx, y) includes batymetry data i.e., elevation of ocean floor) Coriolis forces, friction, etc., as possible furter terms boundary conditions are difficult: coastal inundation, outflow at domain boundaries Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 36
Modelling Scenario: Tsunami Simulation ) Tsunami Modelling wit te Sallow Water equations: source term Sx, y) includes batymetry data i.e., elevation of ocean floor) Coriolis forces, friction, etc., as possible furter terms boundary conditions are difficult: coastal inundation, outflow at domain boundaries Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 36
Finite Volume Discretisation discretise system of PDEs t q + x Fq) + y Gq) = St, x, y) wit q := u F q) := v u u + 1 g Gq) := uv v uv v + 1 g basic form of numerical scemes: Q n+1) i,j = Q n) i,j τ F n) i+ 1,j F n) i 1,j ) τ G n) i,j+ 1 ) G n) i,j 1 were F n) i+ 1 Gn),j,,... approximate te flux functions F q) and i,j+ 1 Gq) at te grid cell boundaries Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 37
Central and Upwind Fluxes define fluxes F n) i+ 1 Gn),j,,... via 1D numerical flux function F: i,j+ 1 F n) i+ 1 central flux: F n) i+ 1 = F Q n) i, Q n) ) i+1 = F Q n) i, Q n) ) 1 i+1 := G n) j 1 F Q n) i = F Q n) j 1, ) Qn) j ) n) ) ) + F Q i+1 leads to unstable metods for convective transport upwind flux ere, for -equation, F ) = u): F n) i+ 1 = F { n) i, n) ) u i if u i+ 1 i+1 := u i+1 if u i+ 1 > 0 < 0 stable, but includes artificial diffusion Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 38
Local) Lax-Friedrics Flux classical Lax-Friedrics metod uses as numerical flux: F n) = F Q n) i+ 1 i, Q n) ) 1 i+1 := F Q n) ) n) i + F Q i+1) ) n) ) Q i+1 τ Qn) i can be interpreted as central flux plus diffusion flux: τ n) Q i+1 ) Qn) i = τ Qn) wit diffusion coefficient τ, were c := τ velocity one grid cell per time step ) i+1 Qn) i is some kind of idea of local Lax-Friedrics metod: use te appropriate velocity F n) i+ 1 := 1 F Q n) i ) n) ) ) + F Q i+1 a i+ 1 n) Q i+1 ) Qn) i Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 39
Wave Speed of Tsunamis consider te 1D case t ) u + x u ) u + 1 g = 0 wit q = q 1, q ) T :=, u) T, we obtain ) q1 + q t q x q /q 1 + 1 gq 1 ) = 0 write in convective form: t q1 q ) + f x q1 q ) = 0 wit ) ) f f1 / q = 1 f 1 / q 0 1 = f / q 1 f / q q /q 1 + gq 1 q /q 1 = 0 ) 1 u + g u Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 40
Wave Speed of Tsunamis ) compute eigenvectors and eigenvalues of f : λ 1/ = u ± ) g r 1/ 1 = u ± g and ten wit f = RΛR 1, were R := r 1, r ) and Λ := diagλ 1, λ ), we can diagonalise te PDE: ) w1 + Λ ) w1 = 0, w = R 1 q t w x w for small canges in and small velocities, we tus obtain tat waves are advected i.e., travel) at speed λ 1/ ± g recall local Lax-Friedrics metod: F n) i+ 1 := 1 coose a i+ 1 F Q n) i = max{λ k } ) n) ) ) + F Q i+1 a i+ 1 Q n) i Q n) ) i 1 Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 41
Sallow Water Equations wit Batymetry b t u + x v u u + 1 g + y uv v uv = v + 1 g 0 gb) x gb) y Questions for numerics: treat b) x and b) y as source terms or include tese into flux computations? preserve certain properties of solutions e.g., lake at rest Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 4
Sallow Water Equations wit Batymetry ) Consider Lake at Rest Scenario: at rest : velocities u = 0 and v = 0 examine local Lax-Friedrics flux in equation: F n) i+ 1 = 1 u) n) i ) + u) n) i+1 a i+ 1 n) i+1 ) n) i = 0 F n) i+ 1 F n) i 1 = a i+ 1 n) i+1 ) a i 1 n) i + n) i n) i 1) = 0 note: a i± 1 g and if b i 1 b i b i+1 ten i 1 i i+1 tus: lake at rest not an equilibrium solution for local Lax-Friedrics flux Additional problems: complicated numerics close to te sore in particular: wetting and drying inundation of te coast) Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 43
References and Literature Course material is mostly based on: R. J. LeVeque: Finite Volume Metods for Hyperbolic Equations, Cambridge Texts in Applied Matematics, 00. M. Griebel, T. Dornseifer and T. Neunoeffer: Numerical Simulation in Fluid Dynamics: A Practical Introduction, SIAM Monograps on Matematical Modeling and Computation, SIAM, 1997. Sallow Water Code SWE: ttp://www5.in.tum.de/swe/ Module 9: Case Study Computational Fluid Dynamics, Winter 013/014 44