introduction to computational fluid dynamics meshes very simple computational domains can be...

46
Structured meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines of a Cartesian mesh are parallel to one another

Upload: trinhtuyen

Post on 09-Jul-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Structured meshes

Very simple computational domains can be discretized usingboundary-fitted structured meshes (also called grids)

The grid lines of a Cartesian mesh are parallel to one another

Page 2: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Structured meshes

A general structured mesh is logically equivalent to a uniformCartesian grid (there exists a one-to-one mapping)

There are d families of grid lines in Rd, d = 1, 2, 3

Members of the same family do not cross each other and cross eachmember of the other families just once

The grid lines of each family can be numbered consecutively

The position of each grid point (or mesh cell) is uniquely identifiedby a set of d indices in Rd, e.g., (xi, yj) ∈ R2, (xi, yj , zk) ∈ R3

Page 3: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Structured meshes

Each internal grid point has 4 nearest neighbors in 2D, 6 in 3D

One of the indices of each pair of neighbor points differs by ±1

This neighbor connectivity simplifies programming, provides fastdata access and leads to efficient numerical algorithms

The matrices of linear algebraic systems are banded and fast solvers(both direct and iterative) are readily available for such systems

Page 4: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Structured meshes

The generation of a structured mesh may be difficult or impossiblefor computational domains of complex geometrical shape

Local mesh refinement in one subdomain produces unnecessarilysmall spacing in other parts of the domain

Long thin cells may adversely affect convergence of iterative solversor result in violations of discrete maximum principles

Page 5: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Block-structured meshes

Two (or more) level subdivision of the computational domain

Decomposition into relatively large overlapping or nonoverlappingsubdomains (blocks, macroelements) on the coarse level

Discretization of these blocks using structured meshes

Page 6: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Block-structured meshes

Block-structured meshes with overlapping blocks are sometimescalled composite or Chimera meshes

Mesh generation for complex domains and flow problems withmoving objects or interfaces becomes relatively easy

Page 7: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Block-structured meshes

More flexibility than with single-block structured meshes

Mesh spacing may be chosen individually for each block

Local refinement in one block does not affect other blocks

Solvers for structured grids can be applied blockwise

Programming is more difficult than for structured meshes

Interpolation and/or conservation errors at block interfaces

Page 8: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Unstructured meshes

No restrictions on the number of neighbor elements or nodes

Automatic mesh generation for complex domains (triangles orquadrilaterals in 2D, tetrahedra or hexaedra in 3D)

Page 9: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Unstructured meshes

Highest flexibility w.r.t. mesh generation and adaptation(refinement, coarsening, redistribution of mesh points)

The coordinates of each mesh point and numbers of nodesbelonging to each element must be stored and retrieved

High implementation effort, irregular sparsity pattern of coefficientmatrices, slow data access due to indirect addressing

Computational cost is significantly higher than that for a structuredgrid with the same number of mesh points/elements

Page 10: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Choice of the mesh

Summary of pros and cons

structured unstructuredcomplex geometries − +local mesh refinement − +automatic mesh generation − +cost of mesh generation + −programming effort + −efficiency of data access + −efficiency of algorithms + −

Page 11: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Finite approximations

Following the choice of the computational mesh, a discretizationmethod for the equations of the mathematical model is selected

Partial derivatives or integrals are commonly approximated bylinear combinations of discrete function values

The choice of the discretization method depends on the mesh

structured meshes: finite differences or finite volumes

unstructured meshes: finite volumes or finite elements

Page 12: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Finite differences

Conservation law∂u

∂t+∇ · f = q in Ω× (0, T )

Discrete unknowns

ui(t) ≈ u(xi, t), i = 1, . . . , N

Approximation of derivatives(∂u

∂x

)i

≈ ui+1 − ui−1

2∆x ,

(∂2u

∂x2

)i

≈ ui+1 − 2ui + ui−1

(∆x)2

Page 13: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Finite differences

This is the simplest and oldest discretization technique

Derivation from the PDE form of the governing equation

The discrete unknowns are solution values at the grid points

The approximation of partial derivatives in terms of these valuesyields one algebraic equation per grid point

The use of a (block-)structured mesh is usually required

Page 14: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Finite volumes

Integral conservation lawddt

∫Vi

u dx +∫

Si

f · nds =∫

Vi

q dx

Discrete solution values

ui(t) = 1|Vi|

∫Vi

u(x, t) dx ≈ u(xi, t)

Vi

Vj

n

ViVj

xj

xi

n

n

Page 15: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Finite volumes

Derivation from the integral form of a conservation law

The discrete unknowns are cell averages or solution values at thecenters of control volumes (mesh cells or dual mesh cells)

Volume and surface integrals that appear in the conservation laware approximated using numerical quadrature rules

Function values at the quadrature points are obtained usinginterpolation techniques (polynomial fitting)

The computational mesh can be structured or unstructured

Page 16: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Finite elements

Variational problem∫Ω

(w∂u

∂t−∇w · f − wq

)dx +

∫Γwf · nds = 0

Discrete solution values

uh(x, t) =∑

j

uj(t)ϕj(x), ui(t) ≈ u(xi, t)

Basis and test functions

ϕi(xi) = 1, ϕi(xj) = 0, ∀j 6= i

Page 17: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Finite elements

Derivation from a variational form of a PDE model

The coefficients of the basis functions ϕi typically representapproximate function values at interpolation points

Inside each cell, the approximate solution uh is a polynomial

Substitution of uh ≈ u into the variational formulation withw ∈ ϕi yields one algebraic equation per mesh node

The computational mesh can be structured or unstructured

Page 18: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Time discretization

Discrete time levels

0 = t0 < t1 < · · · < tM = T, tn = n∆t

Approximation of the time derivative

∂ui

∂t≈ un+1

i − uni

∆t , uni ≈ ui(tn), u0

i = u0(xi)

Linear algebraic systems

Aun+1 = b(un), n = 0, 1, . . . ,M − 1

Page 19: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Linear solvers

Explicit methods: A is a diagonal matrix; the equations of the linearsystem are decoupled and can be solved in a segregated manner

Implicit methods: A is a sparse matrix; the equations of the linearsystem are coupled and must be solved using numerical methods

Iterative solvers that exploit sparsity (and structure, if any) of thecoefficient matrix are usually more efficient than direct methods

Page 20: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Choice of numerical tools

There are many possibilities to discretize a given problem using finitedifference, finite volume or finite element methods

The choice of approximations influences the accuracy of numericalsolutions, programming effort, and computational cost

A compromise between simplicity, ease of implementation, accuracyand computational efficiency has to be made

Numerical algorithms must be stable to produce reasonable results

Page 21: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Design criteria

Consistency: local discretization errors should be proportional topositive powers of the mesh size h and time step ∆t

Stability: rounding and iteration errors that appear in the processof numerical solution should not be magnified

Convergence: numerical solutions should become exact in the limitof vanishing mesh sizes and time steps

Page 22: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Design criteria

Conservation: numerical solutions should satisfy a discrete form ofthe integral conservation law (local or global)

Boundedness: discrete maximum principles should hold if the exactsolution satisfies a maximum principle

Accuracy: at least second-order convergence for smooth data

Page 23: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Finite differences in 1D

Let u : [a, b] 7→ R be a differentiable function of x

A uniform mesh is generated using a subdivision of the domainΩ = (a, b) into N subintervals of equal length ∆x

xi = a+ i∆x, ∆x = b− aN

The discrete unknowns are given by

ui ≈ u(xi), i = 0, 1, . . . , N

Page 24: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

First derivative

The first derivative of u(x) at the mesh point xi is defined by

∂u

∂x(xi) = lim

∆x→0

u(xi + ∆x)− u(xi)∆x

= lim∆x→0

u(xi)− u(xi −∆x)∆x

= lim∆x→0

u(xi + ∆x)− u(xi −∆x)2∆x

and can be approximated using a finite (but small) spacing ∆x

Page 25: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Finite differences

The first derivative of u(x) at xi can be approximated by

forward difference(∂u

∂x

)i

≈ ui+1 − ui

∆x

backward difference(∂u

∂x

)i

≈ ui − ui−1

∆x

central difference(∂u

∂x

)i

≈ ui+1 − ui−1

2∆x

The quality of these approximations depends on u and ∆x

Page 26: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Geometric interpretation

The first derivative of u at the mesh point xi is the slope of thetangent to the curve u(x) at that mesh point

It can be approximated by the slope of a straight line passingthrough two nearby points on the curve

x

i+1

x

i

x

i1

u

x

exa t

entral

forward

ba kward

xx

Page 27: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Derivation from Taylor series

The Taylor series expansion of u about xi is given by

u(x) = u(xi) + (x− xi)(∂u

∂x

)i

+ (x− xi)2

2

(∂2u

∂x2

)i

+ (x− xi)3

6

(∂3u

∂x3

)i

+ · · ·+ (x− xi)n

n!

(∂nu

∂xn

)i

+ . . .

Using this expansion at the neighbor points, we find that

u(xi±1) = u(xi)±∆x(

∂u∂x

)i+ (∆x)2

2

(∂2u∂x2

)i± (∆x)3

6

(∂3u∂x3

)i+ . . .

Page 28: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Truncation errors

Forward difference(∂u

∂x

)i

= ui+1 − ui

∆x − ∆x2

(∂2u

∂x2

)i

− (∆x)2

6

(∂3u

∂x3

)i

+ . . .

Backward difference(∂u

∂x

)i

= ui − ui−1

∆x + ∆x2

(∂2u

∂x2

)i

− (∆x)2

6

(∂3u

∂x3

)i

+ . . .

Central difference(∂u

∂x

)i

= ui+1 − ui−1

2∆x − (∆x)2

6

(∂3u

∂x3

)i

+ . . .

Page 29: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Truncation errors

The local truncation error ε of a finite difference approximation isthe neglected remainder of the Taylor series

ε = αp+1(∆x)p + αp+2(∆x)p+1 + . . .

The term proportional to (∆x)p is the leading truncation errorwhich determines the order of consistency

ε = O(∆x)p

The order of a numerical approximation indicates how fast the erroris reduced when the mesh is refined

It does not, however, provide any information about the accuracyof the approximation on a given mesh

Page 30: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Second derivative

Taylor series expansion about xi

u(xi+1) = u(xi)+∆x(∂u

∂x

)i

+(∆x)2

2

(∂2u

∂x2

)i

+(∆x)3

6

(∂3u

∂x3

)i

+. . .

u(xi−1) = u(xi)−∆x(∂u

∂x

)i

+(∆x)2

2

(∂2u

∂x2

)i

− (∆x)3

6

(∂3u

∂x3

)i

+. . .

Central difference approximation(∂2u

∂x2

)i

= ui+1 − 2ui + ui−1

(∆x)2 +O(∆x)2

Page 31: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Second derivative

Approximation in terms of first-order divided differences

∂2u

∂x2 = ∂

∂x

(∂u

∂x

)⇒

(∂2u

∂x2

)i

(∂u∂x

)i+1/2 −

(∂u∂x

)i−1/2

∆x

Central difference approximation at the points xi±1/2(∂2u

∂x2

)i

≈ui+1−ui

∆x − ui−ui−1∆x

∆x = ui+1 − 2ui + ui−1

(∆x)2

Page 32: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Diffusive fluxes

Approximation in terms of first-order divided differences

f

(x,∂u

∂x

)= a(x)∂u

∂x⇒

(∂f

∂x

)i

≈fi+1/2 − fi−1/2

∆x

Central difference approximation at the points xi±1/2(∂f

∂x

)i

≈ai+1/2

ui+1−ui

∆x − ai−1/2ui−ui−1

∆x

∆x

=ai+1/2ui+1 − (ai+1/2 + ai−1/2)ui + ai−1/2ui−1

(∆x)2

Page 33: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

One-sided approximations

No left or right neighbors at the boundary points x0 = a, xN = b

x0 x1 x2?First-order forward difference

(∂u

∂x

)0

= u1 − u0

∆x +O(∆x)

How can we construct higher-order one-sided approximations?

Page 34: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Polynomial fitting

Taylor expansion about the boundary point x = 0

u(x) = u(0) + x

(∂u

∂x

)0

+ x2

2

(∂2u

∂x2

)0

+ x3

6

(∂3u

∂x3

)0

+ . . .

Approximaton by a polynomial and differentiation

u(x) ≈ a+ bx+ cx2,∂u

∂x≈ b+ 2cx,

(∂u

∂x

)0≈ b

u0 = au1 = a+ b∆x+ c(∆x)2

u2 = a+ 2b∆x+ 4c(∆x)2

c(∆x)2 = u1 − u0 − b∆x

b = −3u0+4u1−u22∆x

Page 35: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Error analysis

Consider a one-sided difference approximation of the form(∂u

∂x

)i

≈ αui + βui+1 + γui+2

∆x , α, β, γ ∈ R

To prove consistency and derive the local truncation error,substitute the Taylor series expansions

ui+1 = ui + ∆x(

∂u∂x

)i+ (∆x)2

2

(∂2u∂x2

)i+ (∆x)3

6

(∂3u∂x3

)i+ . . .

ui+2 = ui + 2∆x(

∂u∂x

)i+ (2∆x)2

2

(∂2u∂x2

)i+ (2∆x)3

6

(∂3u∂x3

)i+ . . .

Page 36: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Error analysis

Substitution of the Taylor series expansions yields

αui + βui+1 + γui+2

∆x = α+ β + γ

∆x ui + (β + 2γ)(∂u

∂x

)i

+ ∆x2 (β + 4γ)

(∂2u

∂x2

)i

+O(∆x)2

The approximation is second-order accurate if

α+ β + γ = 0, β + 2γ = 1, β + 4γ = 0

It follows that(

∂u∂x

)i

= −3ui+4ui+1−ui+22∆x +O(∆x)2

Page 37: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Error analysis

Consider a one-sided difference approximation of the form(∂2u

∂x2

)i

≈ αui + βui+1 + γui+2

(∆x)2 , α, β, γ ∈ R

To prove consistency and derive the local truncation error,substitute the Taylor series expansions

ui+1 = ui + ∆x(

∂u∂x

)i+ (∆x)2

2

(∂2u∂x2

)i+ (∆x)3

6

(∂3u∂x3

)i+ . . .

ui+2 = ui + 2∆x(

∂u∂x

)i+ (2∆x)2

2

(∂2u∂x2

)i+ (2∆x)3

6

(∂3u∂x3

)i+ . . .

Page 38: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Error analysis

Substitution of the Taylor series expansions yields

αui + βui+1 + γui+2

(∆x)2 = α+ β + γ

(∆x)2 ui + β + 2γ∆x

(∂u

∂x

)i

+ β + 4γ2

(∂2u

∂x2

)i

+O(∆x)

The approximation is first-order accurate if

α+ β + γ = 0, β + 2γ = 0, β + 4γ = 2

It follows that(

∂2u∂x2

)i

= ui−2ui+1+ui+2(∆x)2 +O(∆x)

Page 39: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Higher-order approximations

Third-order forward difference / 1st derivative(∂u

∂x

)i

= −ui+2 + 6ui+1 − 3ui − 2ui−1

6∆x +O(∆x)3

Third-order backward difference / 1st derivative(∂u

∂x

)i

= 2ui+1 + 3ui − 6ui−1 + ui−2

6∆x +O(∆x)3

Page 40: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Higher-order approximations

Fourth-order central difference / 1st derivative(∂u

∂x

)i

= −ui+2 + 8ui+1 − 8ui−1 + ui−2

12∆x +O(∆x)4

Fourth-order central difference / 2nd derivative

(∂2u

∂x2

)i

= −ui+2 + 16ui+1 − 30ui + 16ui−1 − ui−2

12(∆x)2 +O(∆x)4

Page 41: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Properties

To achieve higher order accuracy, we need more grid points

One-sided high-order approximations must be used at boundarypoints; the implementation becomes more involved

The larger number of unknowns per equation requires morememory and increases the cost of solving linear systems

Desired accuracy can be attained on coarser meshes

Second-order approximations are usually optimal for CFD

Page 42: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Poisson equation in 1D

Dirichlet problem −∂2u

∂x2 = f in Ω = (0, 1)

u(0) = 0, u(1) = 0

Physical interpretation: u(x) is the displacement of a suspension bridge,f(x) is the load at point x ∈ Ω

Maximum principle: f(x) ≤ 0, ∀x ⇒ u(x) ≤ 0, ∀x

Discretization: xi = i∆x, where ∆x = 1N

ui ≈ u(xi), fi = f(xi)

Page 43: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Poisson equation in 1D

Approximation by central differences−ui−1−2ui+ui+1

(∆x)2 = fi, i = 1, . . . , N − 1u0 = uN = 0 (boundary conditions)

Linear algebraic system

i = 1 −u0−2u1+u2(∆x)2 = f1

i = 2 −u1−2u2+u3(∆x)2 = f2

i = 3 −u2−2u3+u4(∆x)2 = f3

. . .

i = N − 1 uN−2−2uN−1+uN

(∆x)2 = fN−1

Page 44: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Poisson equation in 1D

The matrix form of the linear system is given by

Au = f, A ∈ R(N−1)×(N−1), u, f ∈ RN−1

where A is tridiagonal, symmetric positive-definite

A = 1(∆x)2

2 −1−1 2 −1−1 2 −1

. . .−1 2

The discrete problem is well-posed (the solution u = A−1f existsand is unique since the matrix A is invertible)

There are efficient direct solvers for tridiagonal matrices

Page 45: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Thomas algorithm

Tridiagonal matrix algorithm (TDMA)

aixi−1 + bixi + cixi+1 = di, i = 1, . . . , n

a1 = 0, cn = 0

Matrix form of the linear systemb1 c1a2 b2 c2

a3 b3 c3. . .an bn

x1x2x3·xn

=

d1d2d3·dn

Page 46: Introduction to Computational Fluid Dynamics meshes Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids) The grid lines

Thomas algorithm

Fast Gaussian elimination for tridiagonal systems:

Forward sweepfor k = 2, . . . , n dobk = bk − ak

ck−1bk−1

dk = dk − akdk−1bk−1

end k-loop

Backward sweep

xn = dn

bn

for k = n− 1, . . . , 1 doxk = dk−ckxk+1

bk

end k-loop

Computational cost: just O(n) arithmetic operations instead of O(n3)