Docsity

Solving Equations by Iteration - Computational Fluid Dynamics - Lecture Notes, Study notes of Fluid Dynamics

Toggle sidebar
bg1
Solving Equations by Iteration
Purpose
These notes provide an introduction to a set of files that illustrate the details of iteration
calculations.
Iteration equations
We have seen that the finite-volume equations resulting from terms considering convection,
diffusion and a source term result in a finite difference equation of the following form.
PNNEEPPWWSS bAAAAA
[1]
The finite volume grid on which this equation is derived is shown at the right. The points at the
center of the finite volumes, indicated by the
symbol .and marked as the center point, P,
and it’s four nearest neighbors to the North,
South, East, and West are the nodes whose
values are related by equation [1]. Equation
[1] applies to a single central node, P. We will
have one such equation for the central node of
each control volume. This set of equations
has to be solved simultaneously to find the
values of at each node. In order to define
the entire set of nodes we will first examine a
simple grid where the geometry is rectangular
with uniform grid spacing, ∆x and ∆y. In this
case we can define the grid coordinates xi and
yj by the following equations.
yj
xi
Niyjyy
Nixixx
,,0,
,,0,
0
0
[2]
With this grid notation, the value of at a given location, (xi,yj), is denoted as ij. If ij is the
center node, P, in equation [1], the North node, located at (xi, yj+1), is denoted as ij+1; the South
node, located at (xi, yj-1), is denoted as ij-1; the East node, located at (xi+1, yj), is denoted as i+1j;
finally, the West node, located at (xi-1, yj), is denoted as i-1j. The various A coefficients may be
different at each grid point. To denote the different values of the A coefficients at different points,
the following notation is used. Each of the five coefficients in equation [1] is written with the P, N,
S, E, W, as a superscript and an ij subscript. This shows that the particular set of coefficients
applies to the equation for the central P node located at (xi,yj). With this notation we can rewrite
equation [1] as follows.
ijij
N
ijji
E
ijij
P
ijji
W
ijij
S
ij bAAAAA 1111 [3]
P
N
W
S
E
s
n
w e
ne nw
sw se
SE
NW
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Solving Equations by Iteration - Computational Fluid Dynamics - Lecture Notes and more Study notes Fluid Dynamics in PDF only on Docsity!

Solving Equations by Iteration

Purpose

These notes provide an introduction to a set of files that illustrate the details of iteration

calculations.

Iteration equations

We have seen that the finite-volume equations resulting from terms considering convection,

diffusion and a source term result in a finite difference equation of the following form.

AS  S  AW  W  AP  P  AE  E  AN  N  b P [1]

The finite volume grid on which this equation is derived is shown at the right. The points at the

center of the finite volumes, indicated by the

symbol .and marked as the center point, P ,

and it’s four nearest neighbors to the N orth,

S outh, E ast, and W est are the nodes whose 

values are related by equation [1]. Equation

[1] applies to a single central node, P. We will

have one such equation for the central node of

each control volume. This set of equations

has to be solved simultaneously to find the

values of  at each node. In order to define

the entire set of nodes we will first examine a

simple grid where the geometry is rectangular

with uniform grid spacing, ∆x and ∆y. In this

case we can define the grid coordinates x i and

yj by the following equations.

j y

i x

y y j y i N

x x i x i N

[2]

With this grid notation, the value of  at a given location, (xi ,yj ), is denoted as ij. If ij is the

center node, P, in equation [1], the N orth node, located at (x i , yj+1), is denoted as ij+1 ; the S outh

node, located at (x i , yj-1), is denoted as ij-1; the E ast node, located at (x i+1, yj ), is denoted as i+1j ;

finally, the W est node, located at (xi-1, yj ), is denoted as i-1j. The various A coefficients may be

different at each grid point. To denote the different values of the A coefficients at different points,

the following notation is used. Each of the five coefficients in equation [1] is written with the P, N,

S, E, W, as a superscript and an ij subscript. This shows that the particular set of coefficients

applies to the equation for the central P node located at (x i ,yj ). With this notation we can rewrite

equation [1] as follows.

ij ij

N

i j ij

E

ij ij

P

i j ij

W

ij ij

S

Aij   1  A  1  A   A  1  A   1  b [3]

P

N

W

S

E

s

n

w e

nw ne

sw (^) se

SE

NW

We have an equation like this for each node in our two-dimensional grid. The set of equations

represents a set of linear algebraic equations that we have to solve simultaneously. If we have a

problem in which the values of u are specified at all the boundaries (called the Dirichlet boundary

conditions) we will have (Nx – 1)(N y – 1) nodes at which we will have to solve an equation like [3].

We can illustrate a typical set of equations by considering a very small grid with N x = 6 and N y =

5. This sample grid is shown in Figure 1. In this case we have (6 – 1)(5 – 1) = 20 nodes in the

grid (not counting boundary nodes.)

Figure 1. Example of small finite-difference grid.

i = 0 i = 1 i = 2 i = 3 i = 4 i = 6 i = 6

The nodes related by the typical finite-difference equation are said to form a computational

molecule as shown in Figure 1. Although we can write this set of equations in a matrix form, we

usually solve the equations by iteration. In doing this we denote the value of ij at a particular

iteration, n, as ij(n)^. In the iteration process, we first have to make an initial guess for each

unknown value of . This initial guess is iteration zero and we denote the initial guesses as ij(o)^.

A typical initial guess is to take all values of ij(0)^. = 0. The basic iteration equation is found by

solving equation [3] for ij.

P

ij

ij

N

i j ij

E

i j ij

W

ij ij

S

ij ij ij

A

b  A   1  A  1  A  1  A   1

  [4]

We can now show the simplest iteration approaches. All iteration approached find the new

values at iteration n in terms of old values at iteration n – 1. The first approach, Jacobi iteration,

finds the new value at iteration n in terms of old values at iteration n – 1.This iteration process is

written by taking all the  values on the right side of equation [4] at iteration n – 1. Here we use

the superscripts (n) and (n-1) to denote the values of  at the two iteration levels.

j = 5

j = 4

j = 3

j = 2

j = 1

j = 0

 43

 11

 10

 21

 12

Boundary nodes

 51

 44

 53

 42

 33

Compu- tational Molecule

N

optimum

2 [9]

Regardless of how the relaxation factor is found, the iteration equation for SOR can be found by

combining equations [8] and [6].

n P ij ij

n ij

N

ij

n i j

E

ij

n i j

W

ij

n ij

S

ij ij

n ij

nGS ij

n ij

nGS ij

n ij

n ij

A

b A A A A [10]

Example problem

The operation of the various iteration processes can be illustrated by using a finite-difference

approximation of Laplace’s equation in two dimensions.

x L y H

y

u

x

u

[11]

We can use the second-order central-difference expression for the second derivative.

[( ) ]

[( ) ]

O y

y

u u u

y

T

O x

x

u u u

x

T ij ij ij

ij

i j i j ij

ij

[12]

Substituting these finite-difference representations into Laplace’s equation and ignoring the

truncation error, which is second order in each independent variable, gives

 ^    

y

u u u

x

u i j ui j uij ij ij ij

[13]

Multiplying through by (x)^2 and defining  = x/y gives the following finite-difference equation.

 uij   ui  j    uij  ui  j  uij   [14]

For this equation, the coefficients have the same values at all the ij points on the grid.

P

ij

W

ij

E

ij

S

ij

N

Aij A A A A [15]

For x = y,  = 1, and we have

P

ij

W

ij

E

ij

S

ij

N

Aij A A A A [16]

The example problem uses a square grid with sides of length L, and x/L = y/L = 0.25 (Nx = N y =

4). The boundary values have a different value at each node of the grid. The boundary values

and the initial guesses for the nodes inside the grid, which are all zero, are shown below.

i = 0 i = 1 i = 2 i = 3 i = 4

j = 4 4.00000 6.00000 8.00000 10.00000 12.

j = 3 3.00000 0.00000 0.00000 0.00000 11.

j = 2 2.00000 0.00000 0.00000 0.00000 10.

j = 1 1.00000 0.00000 0.00000 0.00000 9.

j = 0 0.00000 2.00000 4.00000 6.00000 8.

Files with iteration results

Details of nine iteration steps, using Jacobi, Gauss-Seidel, and SOR are shown on the files

jacobi.txt, gs.txt, and sor.txt. For each node, at each iteration, these files show the iteration

equations, the values used in each equation, and the new iteration result for the node. The

values for the current iteration are designated as u and the values for the old iteration are

designated as uOld. For example, the first iteration at the first node for Gauss-Seidel iterations

are shown as follows:

Calculating u(1,1) = -[ AS(1,1) * u(1,0) + AW(1,1) * u(0,1)

+ AE(1,1) * uOld(2,1) + AN(1,1) * uOld(1,2) ] / AP(1,1)

u(1,1) = [ -(1.00000)(2.00000) - (1.00000)(1.00000)

  • (1.00000)(0.00000) - (1.00000)(0.00000) ] / (-4.00000) = 0.

For Gauss-Seidel and SOR, these equations are followed by a new table of nodal values. In the

example above the following table follows the equations. This table shows the new value of

u(1,1) just computed in the table. This value will be used in the subsequent computations of

u(1,2) and u(2,1).

i = 0 i = 1 i = 2 i = 3 i = 4

j = 4 4.00000 6.00000 8.00000 10.00000 12.

j = 3 3.00000 0.00000 0.00000 0.00000 11.

j = 2 2.00000 0.00000 0.00000 0.00000 10.

j = 1 1.00000 0.75000 0.00000 0.00000 9.

j = 0 0.00000 2.00000 4.00000 6.00000 8.

The detailed output tables are not shown for the Jacobi iteration, since that iteration process uses

only the old values. For Jacobi iteration, the tables of iteration results are presented only at the

end of an iteration step.

At the end of each iteration step a table of residuals and relative changes are presented. The

residuals, in general, are found from the following equation.

P

ij

ij

n ij

N

ij

n i j

E

ij

n i j

W

ij

n ij

S

n ij ij

n ij

A

A A A A b

R

( ) ()^1

[17]

For the problem solved here, b ij = 0. The relative differences are found from the following

equation.

n ij

n ij

n n ij ij

[18]

The files with the iteration details should be available on the same web site where you found this

document.