[MUSIC] In this video, I'll explain my graphics
code for plotting the stream function.
Let's have a look.
I wrote the graphics code as a function with one input argument.
Psi, psi is the stream function on the XI THETA grid.
The code is written for a Reynolds number of 10.
If you want to plot a different Reynolds number,
you might have to slightly modify the code.
The first lines of the code set up the XI THETA grid.
The dimensions of the grid can be grabbed from the matrix psi and I do that here.
Little ann is the number of grid points in the xi direction and
little M is the number of grid points in the theta direction.
These next variables are the same as the CFD code.
The new function here is meshgrid that takes the values of xi and
theta and maps them onto a two dimensional grid.
The variables capital Xi and capital Theta become M by N matrices.
The values of little xi are placed in all the rows of capital Xi and
the values of little theta are placed in all the columns of capital Theta.
If you find this confusing, join the club,
we'll use capital Xi and capital Theta for our interpolation.
We need an xy grid and cartesian coordinates to make our plot.
I specify the number of pixels I want in the x direction and
the number of pixels I want in the y direction.
I divide the number of pixels in y by 2.
Because we'll only need the values and the positive y half of the plane.
I also specify the minimum and maximum values of x.
Remember the cylinder has a radius of one centered at the origin.
So negative 1 is on the cylinder surface and negative 1.5
means one half of the cylinder radius in front of the cylinder.
2.5 means 1.5 cylinder radii behind the cylinder.
The maximum and minimum values of y are determined by the number of pixels.
I then use the Lynn space function to define the x and y grid points and
the mesh grid function to define the cartesian grid.
We want to interpolate to our cartesian grid but our data is on the xi theta grid.
So we need to know the values of the cartesian grid points in the xi theta.
Here we map the cartesian coordinates to the xi theta coordinates.
We make use of the mat lab functions log atan2 and wrapTo2pi.
You can look up these functions on the help pages,
log is just a natural logarithms.
A tan2 is the arc tangent done in a way where you don't need to
worry about the sine of x or y.
And wrapTO2pi always forces data to be in the range between 0 and 2pi.
If you don't wrapTO2p you'll run into trouble
with the interpolation because theta is a periodic coordinate.
We are now ready to interpolate using interp2 a two dimensional
interpolated function here, here I just use the default
interpolation method, which is linear interpolation.
Psi is our values of the stream function on the xi theta grid.
And to interpolate properly we need to take the transpose.
This is related to how mesh grid works.
Capital Xi and capital Theta is the CFD.
Grid and Kasai xi_i and theta_i.
Is the grid we are interpolating to.
So the output of this function, psi_xy.
Are the values of psi on the cartesian grid.
When psi_i.
Is less than 0 our, cartesian grid points are inside the cylinder.
So here I use logical indexing to set the interpolated
values of psi inside the cylinder to be exactly 0.
This will help later with our contour plots.
Now we need to set the contour levels and define the color map.
I needed to experiment quite a bit to get a pretty plot.
I decided to scale the negative values of psi to lie between -1 and
0 and the positive values of psi to lie between 0 and 1.
I do that scaling in these four lines of code, making use of logical indexing,
I then set the contour levels to be evenly spaced between -1 and 1.
And define the color map.
You can find my choice of jet on the mat lab help pages.
The map lab function fli pud just flips the color scheme between positive and
negative.
The call to color map sets the map.
Now we plot the color contours.
I used the image sc function, x and
y are our one dimensional grid points and size of x.
Y are the values of psi on the grid.
I also want to plot color contours for negative values of y.
And I can do that by changing the sine of y and
the sign of psi on top of the color contours.
I want to plot contour lines to make the plot look even
nicer here I specify the lines that I want to plot.
Remember that the values of psi go from -1 to 1.
So I tried to distribute the lines to look as nice as possible.
Then we plot the contour lines for positive values of y.
And then we plot the contour lines for negative values of y.
It looks nice to draw a black circle for the cylinder and
that's an easy thing to do using linspace, the cosine and
sine functions and the fill function.
Finally I needn't up the plot.
One of the things we need to do is make sure the y direction is
specified as normal.
Otherwise it's upside down we also set the axis limits.
Set the background color to white and turn the axis off and
I want to display the value of the Reynolds number on the plot.
So I do that here.
I hope this has given you some insight into how I wrote the graphics code.
After you pass the greater, feel free to modify the code to suit your purposes.
If you increase the Reynolds number, you'll need to increase the domain
behind the cylinder to capture the entire separation vortex.
I'm Jeff Khazanov.
Thanks for watching, and I'll see you in the next video.