Solving System of Equations
Solving System of Equations
CFD
Solving system of equations,
Grid generation
Basic steps of CFD
Problem •Discretization •Result
? ui ,t + uij , j + ...
2
Solving system of equations
The type of equations decides solution strategy
P
Domain of
dependence Region of influence
Elliptic
Hyperbolic P
Domain of P
dependence Region of influence
Solving system of equations
Examples: Examples:
•Inviscid supersonic flow •Steady incompressible flow
∂u ∂u
Consider the inviscid Burger equation +u = 0
∂t ∂x
u1,n+1 ui-1,n+1ui,n+1 ui+1,n+1 uN,n+1 ∂u ∂F
∆t
Conserved form + =0 F = F (u )
∂t ∂x
u1,n ui-1,n ui,n ui+1,n uN,n
Start with a Taylor expansion around (x,t+∆t)
∆x
∂u
u (x, t + ∆t ) = u ( x, t ) + ∆t + HOT
u1,1 ui-1,1 ui,1 ui+1,1 uN,1 ∂t x ,t
Marching methods
1st order
The idea is to replace the time derivatives in the expansion by spacial ones
∂u ∂F
First derivative: =− u1,n+1 ui-1,n+1ui,n+1 ui+1,n+1 uN,n+1
∂t ∂x
∆t
Apply 2nd order central differencing: u1,n ui-1,n ui,n ui+1,n uN,n
∆t F n
− F n
uin +1 = uin − i +1 i −1
∆x
∆x 2
∂u ∂u
Consider the inviscid Burger equation +u = 0
∂t ∂x
∂u ∂F
Conserved form + =0 F = F (u )
∂t ∂x
∂u ∆t 2
∂ 2
u
u ( x, t + ∆t ) = u ( x, t ) + ∆t + 2
+ HOT
∂t x ,t 2 ∂t x ,t
Marching methods
Lax-Wendroff scheme
The idea is to replace the time derivatives in the expansion by spacial ones,
which gives a scheme that is 2nd order accurate in space and time.
∂u ∂F
First derivative: =−
∂t ∂x
∂ 2u ∂2F ∂ ∂F
Second derivative: = − = −
∂t 2
∂t∂x ∂x ∂t
Since F is a function of u we can write
∂u ∂F ∂F ∂u ∂u ∂F ∂F ∂u ∂u
=− =− = −A = =A
∂t ∂x ∂u ∂x ∂x ∂t ∂u ∂t ∂t
Jacobian
Marching methods
Lax-Wendroff scheme
∂ 2u ∂ ∂F
Hence, = A
∂t 2
∂x ∂x
∂F ∆t 2 ∂ ∂F
u ( x, t + ∆t ) = u ( x, t ) − ∆t + A + HOT
∂x x ,t 2 ∂x ∂x x ,t
Marching methods
Lax-Wendroff scheme
−
[ ( ) ( )]
n n
∆ ∆
2
+ Anj+1 / 2 F jn+1 − F jn + Anj−1 / 2 F jn − F jn−1
t F + F − 1 t
u nj +1 = u nj −
j 1 j 1
∆x 2 2 ∆x
u2 ∂F u j +1 + u j
Since F = ⇒ A= =u the Jacobian is calculated as A j +1 / 2 =
2 ∂u 2
∆t ∆t
2
A stability analysis gives G = 1 − 2 A (1 − cos θ ) − 2i A sin θ
∆x ∆x
u∆t
Stable if ≤1 the CFL-condition
∆x
Marching methods
MacCormack scheme
This is a two step version of the L-W with the advantage that
no Jacobians are needed. Otherwise it has identical properties
to the L-W
u nj+1 = −
∆t n
u nj
∆x
(
F j +1 − F jn )
Predictor
n +1 1 n
2
n +1
u j = u j + u j −
∆x
(
∆t n +1
)
F j − F jn−+11
Corrector
Solving system of equations
P
Domain of
dependence Region of influence
Elliptic
Hyperbolic P
Domain of P
dependence Region of influence
Relaxation techniques
∂ 2T
=S
Ti +n1+1 − 2Ti n +1 + Ti −n1+1
+ O ( ∆x 2
) = S n
∂x 2
∆x 2
i
13
Relaxation techniques
Basic techniques for solving a system of equations
System of equations Ax = b
Direct methods
a11 a12 a1N x1 b1 •Cramer
a x b •Gauss elimination
•Heavy
21 2 2 •Error accumulation
=
•Thomas algorithm
•Tri-diagonal systems
Iterative methods
a N 1 a NN x N bN
Thomas algorithm
bj
dj = dj − a j −1
Put on upper triangular form: d j −1
bj
cj = cj − c j −1
d j −1
Unknowns computed using j = 2,3,.......N
back-substitution:
d1 a1 0 0 x1 c1
xN =
cN b d2 a2 x c
dN 2 2 2
0 b3
cj − d jxj =
x j −1 =
a j −1 a N −1
j = N − 1, N − 2.........1
0 bN d N x N c N
Jacobi
N
Ax = b ∑a x = b
j =1
ij j i
b −∑a x
i
k −1
ij j
j ≠i
In interation step k: xik =
aii
T k
+ T k
− ∆x 2 n
Si
T1,k Ti-1,k Ti,k Ti+1,k TN,k Ti k +1 = i +1 i −1
2
Ax = b ∑a x = b
j =1
ij j i
bi − ∑j <i
aij x kj −∑a x
j >i
k −1
ij j
In interation step k: xik =
aii
k +1
T k
+ T − ∆x 2 n
Si
T1,k Ti-1,k Ti,k Ti+1,k TN,k Ti k +1 = i +1 i −1
2
Always uses the best value available, gives faster solution
Successive Over-Relaxation (SOR)
• Accelerate convergence
Ti k +1 = Ti k + ω (Ti k +1 − Ti k ) k +1 Ti +k1 + Ti −k1+1 − ∆x 2 Sin
Ti =
T
2
T
Texact Texact
Ti k +1 = Ti k +
Tk+1 T*k+1
∆T
ω∆T Ti +k1 + Ti −k1+1 − ∆x 2 Sin − 2Ti k
Tk T*k ω
2
Lu = Rm
i, j
m
i, j
Jacobi
SOR Gauss-Seidel
Iteration Nr.
Relaxation techniques
Point relaxation
Example: Potential flow
y
Gauss-Seidel, point relaxation:
k +1
φij =
φ k
i +1, j + φ k +1
i −1, j + β (φ
2 k
i , j +1 + φi , j −1 )
k +1
2(1 − β 2 )
j+1
2
∆x
β =
2
j
∆y j-1
i-1 i i+1 x
Relaxation techniques
Line relaxation
y
Gauss-Seidel, line relaxation in x:
k +1
φij =
φ k +1
i +1, j + φ k +1
i −1, j + β (φ
2 k
i , j +1 + φi , j −1 )
k +1
2(1 − β 2 )
j+1
j
j-1
i-1 i i+1 x
Relaxation techniques
ADI, alternating direction implicit
2(1 − β 2 )
j
j-1
i-1 i i+1 x
Multigrid methods
• Accelerate convergence
Multigrid methods
• Accelerate convergence
Multigrid methods
• Accelerate convergence
Multigrid methods
• Accelerate convergence
Multigrid methods
Multigrid methods are used to increase the
computational efficiency of an implicit method
d 2u
Consider the equation: − 2 = f (x) 0 ≤ x ≤1
dx
Periodic boundary conditions u (1) = u (0 )
x j = jh 1
Create a grid: 0 ≤ j ≤ 2n + 1 h=
2n
− u j −1 + 2u j − u j +1 1 ≤ j ≤ 2n
Discretise
2
= fj
h
Remember:
Use the numerical error ξ = u −u
m m m*
j j j
e a +ib = e a (cos(b) + i sin(b))
lim G (θ1 ) = 1
What does this tell us?
h →0
Amplification factor
Multigrid methods
lim G (θ1 ) = 1
h →0
∂ 2u ∂ 2u
+ 2 =0
∂x ∂y
2
6. Transfer the correction back to finer grid, prolongation, uˆim, j+1 = uim, j+1 + I mm+1∆uim, j
and do a few relaxations on each grid until the finest grid is reached
Multigrid methods
Multigrid cycles
V-cycle:
m=M
prolongation
restriction
m=1
= relaxation
Geometric multigrid
• Several grids
explicitly generated
• Suitable for structured
grids
• Several type of
cycles:
– V, W, ...
33
Algebraic multigrid
neccessarily help
Discretisation and grid
Questions:
•How complex is the geometry?
•What accuracy is required? Grid quality?
•What about stability?
•Grid refinement?
Grid generation-classification
Structured Unstructured
Oct-
Mono Multi Cartesian tree
Shape Orthogonality
Orthog Body-
H C O onal fitted
36
Cell types
2-dimensional 3-dimensional
Triangular Tetrahedron
(tri) (tet)
Hexahedron
Quadrilateral
(hex)
(quad)
pyramid wedge
Grid types
Structured grid Unstructured grid
Grid types
Structured grid Unstructured grid
Multi-block
Grid types
Hybrid grid
Grid types
Hybrid grid
Structured Unstructured
42
Mesh quality measures
• Stretching
α • dy2/dy1
dy2
• Best: 1
• Aspect ratio
dy1
• dy1/dx
• Best: 1
dx • Skewness
α
• Best: equi-angle
43
Efficient grids – grid stretching
Large
gradients
Fine
resolution
44
Efficient grids – grid stretching
∂T ∆x ∂ T ∆x ∂ T
2 2 3 3
i+1 Ti −1 = Ti − ∆x + 2 − 3 ...
∂x i 2 ∂x i 6 ∂x i
∂T (r∆x)
2
∂ 2T (r∆x) 3 ∂ 3T
Ti +1 = Ti + r∆x + 2 + 3 ...
i ∂x i 2 ∂x i 6 ∂x i
i-1 ∂T Ti +1 − Ti −1 (r − 1)∆x ∂ 2T
= + 2 + O(∆x 2 )
∂x (r + 1)∆x 2 ∂x i
48
Efficient grids – adaptive
refinement
• Right marker parameter
• P, u, T, dt/dx, etc.
• Not too often
• Comp. Time
• Errors introduced
• Not too late
• Follow the flow
features
49
Refinement techniques