[MUSIC]
In this video, I'll go over the MATLAB learner template for
calculating a steady flow field solution.
Let's get started.
I want you to write your code as a function with no input arguments and
with two output arguments, the variable psi and omega.
Psi is the stream function and omega is the scale of vorticity and they're
both end by n x m matrices with the values of the fields at every point on the grid.
For the grader,
I want you to obtain a solution when the Reynolds number is equal to 10.
First, we define the grid, we choose 101 points in the psi direction and
101 points in the theta direction.
Those are the values we assign to n and m.
The number of intervals is 1 less than the number of grid points.
And those are the values we assign to N and M.
We define the grid spacing based on the number of intervals in the theta
direction.
And since data goes from 0 to pi, we define h to be pi over M.
We define the grid points themselves in the vectors psi and
theta making use of the colon operator.
Next, we initialize the flow fields at this low Reynolds number,
we can set the initial flow fields equal to 0.
But there's one boundary where the stream function isn't 0.
And that's the free stream boundary.
So here I want you to write the free stream boundary condition for
the stream function.
I then set the relaxation parameters for the SOR method.
After some experimentation, I set the relaxation parameter for
the psi equation to be 1.8 and the relaxation parameter for
the omega equation to be 0.9.
The fields converge for these values and you won't time out in the MATLAB grader.
We have to iterate the SOR equations until the field stopped changing or
at least stop changing below some small value.
I called the small value delta and set it equal to 10 to the -08.
The amount of solution changes with each iteration,
I call error and initially I set the error equal to 2 times delta.
So that the while loop of the iteration can get started.
When the error is less than delta the while loop will exit.
If you wanted to find some additional variables to save computational time,
you can do that here.
These are typically variables that don't depend on the iteration so
that you can compute them once and be done with them.
Now, we're looking at our main SOR iteration loop.
I'm using a while loop, while error is greater than delta will stay in the loop.
Delta is already assigned to 10 to the -8.
To compute the error we're going to take the difference between
the fields at the top of the loop and the fields at the bottom of the loop.
So we'll need to save the fields at the top of the loop and
the variables psi old and omega old.
At the bottom of the loop we'll assign the error variable to the maximum
of the errors that will calculate from the psi and omega fields.
Here is the first loop over the internal grid points.
i goes from 2 to n- 1 and j goes from 2 to m- 1.
This loops over all the internal values of psi.
Here, you need to write the psi iteration equation using the SOR method.
Make sure you type the equation accurately from the lecture notes.
After psi has been updated, we compute the error.
I define the error in the psi equation to be the maximum of the absolute
value of the difference between the current value of psi and
the value from the previous iteration.
The colon operator means that we're looking at every single value of
psi on the grid.
After the psi calculation is done,
the next step is to update the boundary condition on omega.
This is the boundary condition on the cylinder that depends on psi.
So write the boundary condition on omega here.
After the boundary condition for omega is updated, we then loop over
all the grid points again and update the internal values of omega.
So here is where you write the SOR equation for the scale of vorticity.
Get the equation from the lecture notes.
It's a very long equation.
So if you want to use more than one line, you can use the dot dot dots and
text in MATLAB to write the equation across multiple lines.
After we update omega, we then compute the error in omega in
the same way that we computed the error in psi.
And finally we take the maximum of the two errors.
We then go back to the top of the while loop and
if the error is still greater than delta, we iterate another time.
So we keep iterating the SOR equations until the values of both fields
stopped changing down to the level of delta, which we took to be 10 to the -8.
After the error is less than delta, we leave the while loop.
We can then plot the stream function using a program I wrote for
you called plot underscore Re10.
In the next lecture, I'll explain how that program works.
I hope you'll enjoy writing this code after you pass the grader.
Feel free to explore the solutions further running at other Reynolds numbers and
maybe trying different grid sizes.
I'm Jeff Chazanov.
Thanks for watching.
And I'll see you in the next video.