Computational Fluid Dynamics
Prof. Sreenivas Jayanti
Department of Computer Science and Engineering
Indian Institute of Technology, Madras
Lecture – 05
Tutorial 1 contd.: Solution for algebraic equation using Gauss- Seidel Method
We have seen now how to convert a partial differential equation into a set of algebraic
equations into A W equal to b type of matrix equation. In the particular case that we have
looked at, we have a matrix with constant coefficients. It is not generally the case, but
this is what we have.
Now, what we look at is how to solve this. Before we attempt the solution, we want to
see whether this is going to give us a unique solution, do we have enough number of
equations and are these equations independent, do we have a matrix equation which is
irreducible, in the sense that there are, how do we know that some of these equations are
not linear combinations of other equations.
(Refer Slide Time: 00:57)
.
So, that is a kind of question that we must ask ourselves. So, one normal way to look at
that is to find out the determinant of A. But in a case like this, there are other thumb rules
and other conditions; some of them are sufficient; some of them are necessary
conditions, which can help us just by looking at it whether or not we can get a unique
solution. One such condition is the condition of diagonal dominance.
So, we would like to use the condition of diagonal dominance to check whether we have
the possibility of getting a unique solution. So, what do we mean by diagonal
dominance? We have nine equations, and each of them is of this particular form, so
where each of them is, for example, minus 1000 times w 2 2 plus 100 times w 3 2 plus
400 times w 2 3 equal to 0, like this.
So, when you have this set of this type of equations, we can define diagonal dominance
as a condition where the modulus of the diagonal term. That is, in this matrix these are
all the diagonal terms. So we have one term. The diagonal term is greater than or equal to
the sum of all modulus of all other terms.
(Refer Slide Time: 03:00)
.
That is, i not equal to j. So, this must be satisfied for each i. So, once we have this
condition satisfied, we can claim diagonal dominance. So, if we have diagonal
dominance, then we can say okay we have; that is one possibility, possible way of
verifying that we have a unique set of equations, and we can get; where we can make use
of some efficient method for the solution here.
So, we will, I will, we will have to edit somewhat here. So, in order to see how to
proceed with the solution of this, we will look at the condition of diagonal dominance.
And, the diagonal dominance can be expressed in this form, where the magnitude or the
absolute value of the diagonal is equal to or greater than the sum of all the off diagonal
elements in the same equation or in the same row. And, when this is satisfied with greater
than symbol in all cases; that is known as the strong form of diagonal dominance. Ok
There is also a weak form of diagonal dominance, which is that the modulus of the
diagonal term is greater than or equal to the sum of the modulus values, the magnitudes
of all the other off diagonal terms for all i, that is, for all equations. And, the modulus of
the diagonal term is greater than the sum of the modulus values of the off diagonal terms,
at least for one equation.
So, we have here nine equations. If for all these nine equations this condition is satisfied,
then we say we have strong form of diagonal dominance. But, if for all of these this
condition is satisfied with either greater than or equal to sign, but there is at least one row
for which this condition is satisfied with the greater than sign, then we say that we have a
weak form of diagonal dominance.
So, let us now try to see what this diagonal dominance is. That if you look at the first row
here, this represents one equation. And that equation, algebraic equation is for w 2 2.
And, in that equation the diagonal term is 1000. The magnitude is 1000 and the other off
diagonal terms is 100 and 400. So, that is the sum of these two is 500, and this is 1000.
So, this condition is satisfied for this equation. If we come to this, the diagonal term is
1000, magnitude is 1000. This is 100 plus 100, 200; 600; total is six hundred. So, this is
also satisfying this condition here; here is again 1000 and the sum is 500. So, again this
condition is satisfied. Here it is 400, 500, 900 and this is 1000. So, again this is satisfied.
For this equation here, 400, 500, 600, 1000 and this is 1000. So, this equation is not
satisfied for this row, but for all the other rows this equation is satisfied. So, that means
that this matrix here is not, does not satisfy the condition of strong form of diagonal
dominance. But, if you look at the weak form, then even this equation satisfies this
condition because in this case, it is equal to.
So, it is this equation, the diagonal dominance condition is not satisfied in the strong
form, but it is satisfied in the weak form. And, for all the other equations it is satisfying
this strong form of with a greater than sign. So, that means that our, we can claim that the
weak form of diagonal dominance condition is satisfied by the set of A w equal to b that
we have. So, now when you have this kind of condition satisfied, the weak form is
satisfied. This often arises in equations that we encounter in CFD, but not all the cases.
But, this is a very desirable form because when you have this condition satisfied, a
number of special techniques can be used to solve this equations A w equal to b type of
equations.
And, we make use of one such method known as Gauss-Seidel method for the solution of
these equations. So, this is an iterative method. Ok. So, that means that we are not
solving A w equal to b. So, this is put in the form of M w equal to N w plus b. And, this
is actually solved as M w k plus one equal to N w k plus b. Now, what this means is that
k is known as the iteration number. So, we start with some initial guess. So, that is k
values of all the w s are known. And then, we substitute this in this. And from this, we
can get the k plus 1th value here. And, once we get the k plus 1th value, then we go back
and put that here. And then, we again get an update thing.
So, we start with k equal to zero. Using this equation we get k equal to one. And then,
you put k equal to one here, you get k equal to two. Put that into this, we get k equal to
three and then we can keep on going like this, until we get a converge solution. We will
get a converge solution, if we have the weak form of diagonal dominance for the
condition A, for the matrix A. If we have coefficient matrix, which satisfies the weak
form of diagonal dominance, this Gauss-Seidel iterative method will converge. No
matter, what the initial guess is. So, when we are solving large sets of equations, when
we are solving with lots and lots of grid points, then this becomes a very good method.
And, we will discuss this more in later weeks. Right now, we take it for granted that this
is a method that we can use to solve these things. And, since our condition or quotient
matrix A satisfies the weak form of diagonal dominance, this would be a good way of,
good method for the solution of these equations.
Now, how do we actually do this? So, what we are actually doing is that we take each
equation here and then we put the; we start with this; the first equation, this is minus
1000 w 2 2 plus 100 w 3 2 plus 400 w.
(Refer Slide Time: 12:33)
So, that is this is two three, wait, we have 3 2, 3 4, and 2 3. Yes. So, this is 3 2 and 2 3
equal to minus 1000. So, we can. in this equation, the diagonal term is always kept on the
left hand side. And, so this is what we are looking for. We can rewrite this equation as
minus 1000 w 2 2 equal to minus 1000 minus 100 w 3 2 minus 400 w 2 3. Ok.
So, now here we can put this as an iterative formula; w 2 2 k plus one equal to minus
1000 minus 100 w 3 2 k minus 400 w 2 3 k. So, if we know the initial conditions, initial
values for this, then we can get this. So, we need to do this for each of the equations. So,
in each equation the diagonal term is put on the left hand side. So, we have; from the first
row we have this. And, from the second row we have minus 1000 w 3 2 k k plus one
equal to minus 1000. And then, we take the other one. This is minus 100 w 2 2. And then,
we have minus 100 w 4 2. And then, we have one, two, three, four, five; one, two, three,
four, five; minus 400 w 3 3.
Now, here this is 3 2 k plus one; two, two values already known from here because we
solve this and then we come to this. So, we can put this as k plus one. And, at this time
we have not yet solved for 4 2. So, we put this as k, and k. And, we come to the third
equation. Here it is w 4 2. So, minus 1000 w 4 2 k plus one equal to minus 1000 minus
100 w 2 2; two, two values already known k plus one. So, this is not 2 2; so, this is 3 2.
So, this is 3 2 is already known anyway. And then, we have 400 w 4 3.
And then, we can write this as; the next equation is for w 2 3. So, in this equation we
come here. So, this is minus 400 w 2 2 k plus one. And, this is w 3 3 minus 100 w 3 3 k
because that is not yet calculated. And then, we have this one here, which is w 2 4. So, in
this way we write down all the nine equations. And, once we write down all the nine
equations, we can get a sequential solution.
So, that is, we start with guess values for all the variables, and the guess values can be
anything. They can be zero, they can all be the same or they can be any value. If you go
through enough number of steps, then it will converge, provided we have the weak form
of diagonal dominance or even the strong form of diagonal dominance.
So, we rewrite the nine equations that we have here, in this particular form. And then, we
start with some initial guess values. And, using the guess values of w 3 2 and w 2 k, we
use this to get w 2 at the first iteration. And then we come here, we evaluate w 3 2 at the
first iteration, w 4 2 at the first iteration, 2 3, like this all the up to the last equation here.
So, we will be completing one sweep through all the nine points. So, starting with some
zero values, zero iteration values, initial guess values, we will be getting the first set of
values for all the nine. We substitute the first set of values from the right hand side, we
get the second set of values, and then we put them in the second set and then we get third
set, like that. If we keep on doing it, we find that gradually the numbers converge. So,
something like this can be done, should be done, will have to be done on a computer. So,
we look at some solutions on the computer generated using the Gauss-Seidel method for
this particular equation.
(Refer Slide Time: 18:45)
Now, we have on the screen; we have the highlighted in yellow portion here, which
contains all the nine equations which have been put up. We will just talk. I need to get
one more. Should I start? Start?
(Refer Slide Time: 19:10)
So, we now have the set of nine equations, which we had them as A w equal to b, now,
rewritten on the screen in the form of Gauss-Seidel method. Let us just go through the
nine equations. We have equations for w 2 2, 3 2, 4 2, 2 3, 3 3, 43, 2 4, 3 4, 4 4. And, this
is the order in which we solve sequentially. And, these each equation is written in the
form of w 2 2 k plus one. So, that is, the updated value of w 2 2 is given in terms of 1000
plus 100 times w 3 2 k. The old value of w 3 2 plus old value of w 2 3, and this whole
thing divided by 1000. So, the 1000 which was there as a coefficient of w 2 2 has been
brought on to the right hand side.
So, we have this first equation for w 2 2 k plus one. And then, when you come to the
second equation, this involves w 2 2. We have already evaluated this at k plus one
iteration. So, we can make use of this. And, 4 2 is not known at k plus one level. It is
known at the kth level or kth iteration. So, we substitute that. And, we substitute again
the old value of w 3 3 and then estimate the new value of w 3 2. And then, we come to 4
2. Here 3 2 is known, so we have k plus one. 4 3 is not known, we have k. 2 3, as w 2 2,
which is at k plus one and w 2 4 and 3 3 are at k. Otherwise, the coefficients remain the
same.
So, it is just rewriting of the equations in such a way that the term with the largest
coefficient in magnitude. In this case, it happens to be the diagonal value. So, that
particular thing is kept, brought to the left hand side and all the others are taken to the
right hand side. And, if their value is known at k plus 1th level times step or iteration
step, then we use it. Otherwise, we make use of the old iteration value; that is, k value
likes this.
So, when you come to this 4 3 k plus one, here 3 3 is already computed here, so we make
use of the latest value; 4 2 is already computed here, so we make use of the latest value;
4 4 is coming down further, so it is not known at the current k plus 1th iteration. We
make use of the old value.
So, in this way we make a sequential evaluation of all the variables. In this case, we have
nine variables. If we have nine thousand grid points, we will have nine thousand
equations like this. And, we go through all the nine thousand equations at k plus 1th
iteration level, before we move on to the next one. So, that is, Gauss-Seidel method is
that we start with initial guesses; k equal to zero for all the variables. And then, we
update each variable one by one in a sequential way like this. And, once we update all
the variables, we go to the next iteration level. So, that is how the Gauss-Seidel method
is supposed to work.
(Refer Slide Time: 22:40)
And, this is the way that these are the values that we have got as a function of iteration
number. So, iteration number of zero corresponds to initial guess. So, this is all of these
or with an initial guess of zero, it can be anything. So, we started with some initial guess.
And then, we updated this first and then this and then this and then this, this, this. Like
this, we updated all the values, using the formulas that we have derived by rewriting A w
b equal A w equal to b form.
And then, once we evaluate all these things, then we come to the next iteration level. We
reevaluate this, revaluate this, reevaluate all these things. And, we can see that we take
any value, it started with zero, one, one point six seven, two point one seven, two point
four six. It is the incremental value is becoming smaller and smaller and smaller. And
then, you can see that at the end of fourteen iterations, it has come down to two point
seven seven one three. So, the increment is only point zero zero zero two. And, this one
is also increment is in the last decimal place here; in the fifth, fourth decimal place here
and here like this. And if we increase the, if we go further and further, we will see that
even the fourth decimal place will not change, the fifth decimal place will change. So,
depending on what accuracy of solution you want, you can stop after so many number of
iterations. And, so this is how the Gauss-Seidel method works. You start with the, you
rewrite your original set of A w equal to b equations, which you got by discretizing the
partial differential equation using finite difference approximations. And, you check
whether the coefficient matrix A satisfies the either the weak form or the strong form of
the diagonal dominance. And if it does satisfy, then you can make use of the Gauss-
Seidel method, and rewrite the equations in this k plus one and k form in a particular
way, which will discuss in later classes.
And, once you have these formulas, then it is just a sequential iteration of this with any
initial guess. It need not to be the same for all the variables, but it does not matter what
they are, eventually they will converge. There is a guarantee of convergence, provided
the equations are linear and they are irreducible, and they satisfy the weak form of
diagonal dominance.
So, in such a case we can make use of the Gauss-Seidel method and get a solution like
this. And, you can see it is converging to some value and the values are not the same in
all the cases. There are some, which are smaller and some which are higher. The highest
value is four point one and the smallest value that we have got is two point seven seven.
And, how is this correct? Four point one one is for w 3 3. And, w 3 3 happens to be; the
w 3 3 happens to be the value, which is right at the center of the domain which is farthest
from all the walls. So, it will have the highest value.
And that kind of logic is followed. w 2 3 and w 4 3 are symmetric. And, you can see that
they have very similar values; three point six two eight four, three point six two eight
five. If you take it to convergence, they both will be the same. And similarly, the
symmetry between 4 2 and 2 4, again between 3 2 and 3 4. So, we could have made use
as symmetry. But, for the illustration we are showing that you have a certain variation of
velocity, which is consistent with our understanding or expectation that as you move
further and further away from the walls, the velocity will be higher. And that is what we
get.
In ideal case having nine unknowns here, it is not going to give us a lot of accuracy
because this is a very gross error. And, if you were to calculate the average velocity from
by taking the average of all these things, then it may not match with the expected value;
because the number of grid points is very small here. So, if you make it instead of five by
five, if you make it ten by ten or twenty by twenty or fifty by fifty, then you will see that
the solution that you get will be converging. So, that is further increase of a grid points
will not make any difference. And, at that point you can say that you have got the correct
solution. Ok. So, this is the essence of CFD approach.
And, the CFD approach is that you start with the equations which describe
mathematically the flow. And, in this particular case we have that as dou square w by
dou x square plus dou square w by dou y square equal to constant. So, that is a partial
differential equation; the solution of which we are seeking and we do not get a value at
any x and y. We get a value at specified values of x and y. These are known as the grid
points. So, wherever you want to have a solution, there you discretize the governing
equation by substituting different formulas for the derivatives.
So, the derivatives expressed in terms of values of the variable at discrete points. And
that will give you a set of algebraic equations. And, the set of algebraic equations
together are determinate. And, you can solve them by using a number of methods. And,
what we have seen for the purpose of illustration is a special method, which is often used
in CFD, which is the Gauss-Seidel method. And, we can see that. Using this method, we
can get a solution using elementary mathematics. In order to get the solution, we did not
have to use any special mathematics. It is just simple finite difference approximations
and solution of algebraic equations. And, that is the advantage of CFD. And, we can use
this same principle for even more complicated equations. So, that is; and that is what
enables us to use this CFD approach for the solution of the much more complicated
equations, which describe fluid flow in any arbitrary geometry. But, we are still a long
way from it.
Before we get to discussion of those complications and all that, in the next module, in the
next week, we look at a different way of doing the same thing. A different way of
converting a partial differential equation into a set of algebraic equations this time. In
this method, we have used finite differences and we will use finite volume method to do
the same thing and end up with again a set of algebraic equations, which can again be
solved using the Gauss-Seidel method. And, the difference between that finite difference
and finite volume method, we will see in the next lecture. And hopefully, you will learn
from that that one could tackle even more complicated geometries than this very simple
geometry that we have done today.