We're solving a matrix equation for
the stream function a Psi equals b,
where Psi now is a column vector consisting of
the values of the stream function
on all the points of the grid,
the interior points and the boundary points.
A is an mn by mn matrix.
We've written the equations for
Psi on the interior points.
Now we have to discuss the equations for
the stream function Psi on the boundary points.
This is our domain.
The boundary has four sides.
I've labeled them left,
right, bottom, and top.
We're doing natural ordering.
The first grid point is labeled one,
and then we go along the x-axis to the grid point n,
then we come back to the beginning again and
keep going across until we get to the top,
which is starting at 1 plus m minus 1
times n and finishing at m times
n. We need to now discuss what are
the appropriate equations for
the stream function on the boundary.
Let's go one by one.
We'll start with the left-hand side.
That's at the first grid point in cosine,
which is on the cylinder.
The left-hand side is the cylinder boundary condition.
The cylinder boundary condition for
the stream function is simply the stream function at
the first grid point on Psi at
all the grid points and Theta is equal to 0.
What are the k values then on the left-hand side?
We have k starting at one and then
the next grid point has to increment by n because we're
doing natural ordering going along the x-axis first.
If I use the MATLAB notation,
it will go up by n,
and then it will finish at the last grid point,
which is 1 plus m minus 1 times
n. This one j index
then translates into k and then in the matrix a,
we need to replace row k by
the corresponding row of the identity matrix.
The identity matrix here is the mn by mn identity matrix.
Then the one in that row will
pick out the right side and then
the right-hand side in
the same row corresponding to that value of k,
we have a zero element.
That will force Psi to be
zero for the values on this left boundary.
For the right boundary,
that's the maximum value of Psi,
so that's the free stream.
The free stream boundary condition is
Psi at the largest value of i, which is n,
for all of the angles,
is equal to e to the cosine_n times sine Theta j.
That's the free stream boundary condition.
What are the values of k here?
We start at n,
we increment at n and we end at mn.
The value here would be k equals
n increment n finish add mn.
For these rows of the matrix a,
we need to replace by
the corresponding rows of the identity matrix.
But now this is inhomogeneous boundary conditions.
We have a non-zero right-hand side
and in those rows on the right-hand side,
we have to put the free stream condition,
so that will force Psi to equal
the free stream boundary condition
on the right-hand side of this boundary.
Now let's go to the bottom.
The bottom and the top are periodic boundary conditions.
The bottom corresponds to Theta equal to minus h,
where one grid point below zero.
What is the boundary condition on the bottom?
We have our Psi at the bottom,
this is for all i,
the bottom will be the first grid point,
and that's supposed to be equal to the m minus 1 value.
One before we get to the top side.
I'm going to write that as minus Psi, i,
m minus 1 and that is equal to 0.
What are the k values here for the bottom?
That's fairly simple,
k starts at one, increments by one.
In MATLAB, we don't need to write the increment,
and then ends up at n. That's the value here.
This is k then,
so this would be Psi_k minus,
and then this is something shifted from
k. You're going to have to work that
out yourself using a paper.
How is this shifted,
and you can also look at my lecture notes.
Then in this k row of a,
we need to replace that k row by
the difference between two rows of the identity matrix.
Then we'll have two ones in that row and
that row will enforce that
this equation is equal to zero,
meaning the right-hand side has to be a zero.
Then the last one is the top is also
periodic boundary conditions and
the value of Theta here at the top is 2 Pi.
We have Psi for all values of
i and for the last value in Theta,
that's m and then that's
supposed to be equal to the second point.
That means minus Psi,
i, 2 equals 0.
What are the k values for the top?
The k value for the top,
we're starting here now on the left.
That's 1 plus m minus 1 times n,
and we're finishing on the right,
which is m times n.
The increment across the top is again one.
The i, m index then becomes k and the i, 2 index,
you have to figure out what is
the appropriate index in terms of
k. Those two rows of the identity matrix
get subtracted and get put into the k row of a
and the right-hand side is again zero Let me summarize.
We're trying to put the boundary conditions
into our equation a Psi equals b.
To do that, we need to replace
rows of a by corresponding rows
of the identity matrix or the difference
between two rows of the identity matrix.
We also have to replace the corresponding rows of b by
a zero in the case
of the homogeneous boundary conditions,
and by this free stream condition
for the right-hand side.
Personally, I found putting
the proper boundary conditions in the matrix a and into
the right-hand side b was
the most difficult part of constructing the code,
or at least was one of
the more difficult parts of constructing this code.
You have to get it right or
else your code will have a bug.
I'm Jeff Chasnov.
Thanks for watching,
and I'll see you in the next video.