Now what we are going to do is to solve the 2D burgers equation before we actually start solving it.
Let's look a little bit on the equation and just understand the terms that we need to consider.
Of course, this time the solution will be.
The numerically finite difference, however.
In later stages.
We will solve the using pens.
But first let's try deal with a 2D equation.
So in here what we can see is we have two equations actually.
The first one is du dt, which is basically the change, the temporal difference, the change of U in
relation to temperature to sorry, the time and the other term is multiplied u d u d which is the spatial.
Well, the spatial component in which you will change with x plus v, d, u d y, in which also u will
change with y.
So this is the first one is in the horizontal direction and the second equation is in the vertical direction.
So we call it u v.
Now, after that, we have new this one, which is the diffusion coefficient.
The kinematic diffusion coefficient.
The main thing like it's just shows how strong this diffusion or we can control how strong the diffusion
is from this factor.
And so after that we have it will be multiplied by a.
The second derivative of U with X and the second derivative of U with Y.
So basically, this is the the the U in the X direction, and the other one is the V, which is the
velocity in the Y direction.
And we can see it in here.
Basically it's the same thing like DV become DV over dt du over d x become dv over d dx plus dv over
dy.
Just look into or like notice this u is still here.
Become here and here is going to be the same.
This is going to be same.
The only thing will change is this component.
And it goes like all the way.
Basically the same thing in the end is everything will change with v over d, v over d.
The diffusion coefficient Nu is considered to be like similar in both x and y direction.
If we don't want to do that, we have to, you know, like we have a coefficient for this and coefficient
for this.
If this is the same then it will be we just put it here.
Okay, so this is how the burgers equation are going to work and the components of the burgers equation.
How can we make it into a code?
So in order to do so, let's write a code related with burgers equations.
We can start by writing.
The name of this file is Burgers.
Uh, 2D and Main.
I like to call Main because it is always.
Because I have many files.
It's and it's kind of nice thing to have in programming main to know which is the main file.
So import also like we call the now the first thing is we call the A libraries.
We need numpy.
As imp import.
Matplot.
Lip.
Dot pyplot as plt import seaborn.
Although I don't think we will use Seaborn anyway.
It's nice.
And shift enter.
So after that, we need to start.
Uh, well, the post-processing we need to set the problem that we have.
And to do so, we have to consider a n t, which is the number of time step we can consider.
N t equals 500 and x equals 51 and y equals 51.
And C equals one.
And she will be.
I think it's.
No, we don't need this.
This is not needed.
And u equals a point one.
And d t equals because we don't have C, we have new the diffusive term and actually we're not really
using two diffusion like in different directions.
So this is why it's I got confused a little bit.
So here we have in new is 0.1 and 0.001 for the time step.
So this is going to be time step and this is 500.
So 500 multiplied.
This one, it will be well, just.
A 0.5 second.
0.5 second.
Yeah.
So so it will it's not so much time for this, but of course, this is kind of we're not really care
about the dimensions, we're just numerically solving the things.
But of course, when you deal with a real numerical problem, we have to be very careful about the dimensions
and the common sense of what we are calculating.
But as we learned the numerical things, it's okay, we just write something and we solve the equation.
So D, x A and x minus one.
Divided by two because our domain is going to be from 0 to 2, and in Y, it's going to be another from
0 to 2 and again in X and Y minus one divided by the whole domain like length.
And now X.
We start, we will start making the domain we have.
So the first thing is we need a Or we can just put it here like this and shift enter and then we start
defining the domain.
So np dot line space and from 0 to 2 and we have an x steps and x steps 51 means we have actually 50
until 50 steps.
So here we have the line step and equals.
Here in.
Dot line space also from 0 to 2 and in Y.
Yep.
So.
This is a.
Is just going to to make a basically a list, a list like this will show that will have these line spaces
starting from 0 to 2.
Now, what we need to do is we need to make a grid.
So in order to to do that, like basically 51 by 51 a grid, we.
This is going to be our grid.
And we can initiate it.
Zero.
In X and in Y.
Shift into an X0.
Yeah.
So now what we have is.
A we have a 51 rows and every row will have 51 components so we can see this shape.
Shape.
Is 51 by 51.
So now we have a rather than.
Only like a line.
In both cases we will have now a mesh.
Of course, this is just a placeholder.
It's not going.
We didn't really populate it with actual numbers.
Of course, it's the type of it is numpy array, as we already use numpy.
So now what we need to do is we need to a placeholder for everything else.
And the reason I'm doing this because we have to be careful when we are making the placeholders and
when we are populating them.
So here you in sorry, in X or in y.
In x in no problem.
Like we can we can do it.
And here.
Actually this one, the sign convention in this code is in Y in X.
This is better in Y.
In x.
Anyway, it's not going to be different.
They are the same, but just in case.
So you.
We initiated U and V, and this is the going to be the speed at the time step we are dealing with.
But we need a placeholder for the time step one time step before because the method we are using is
explicit method.
We're actually calculating every time step.
So we take the time step and we calculate the the next time step.
The scheme is going to be central difference scheme and basically we will compute everything in terms
of the previous time and we will update the solution for the next time step.
So this is called a explicit.
The other option is called implicit in which we consider the time is another vector and we solve all
the time steps together by converging into, we call it implicit methods.
It's another we have iterations that we need kind of like to reduce the loss.
So.
Yeah, this is basically what we are doing.
What we are doing.
Just just a side note.
So u v u n which is the previous, um, space holder.
We keep it here and.
Also you.
V in which is the previous space, is also here.
F is going to be the actual.
So this is the time step, the next time step or yeah, the next time step.
This is the previous time step and it's or this is yeah this is the the current time step, the one
we are calculating this is the one be be before it and this one is going to be the, the one in which
we will save all our solutions.
So again, zeros, but we need to consider the time.
So we say NY and X, so this one we have in T and in T, I think we already identified it.
500.
Yes, this one.
So yeah, this is the.
Basically the the placeholder for the U and V, the solution at the end.
Again burgers equation we need to solve u and v, we already have x and y and we need to solve u and
v.
So this is u v u.
The previous time step and the basically the we save this the solution and then shift enter just a problem
here zero.
Sorry I always forget to put s.
Now.
It's okay if you want to see the shape.
Of course.
Shape.
It will be 51 by 51.
And this one, the placeholder, it will be a little bit bigger.
Or like one dimension bigger, which is we will have 500.
So it will be this array.
So now.
Pretty much we are defined our problem.
But what we need to do is we need initial condition and boundary condition.
Now, the boundary condition, we will keep updating the boundary, basically not allowing the solver
to update the boundary points at when we are doing the solving loop.
So this is where we are going to put the boundary condition.
But what we can do now is to set the initial conditions.
To do that, we start.
A basically.
We take.
We need you.
V.
This one, which is the current time and we need.
Even this one.
So how we can initiate it?
It's, um.
Or let's start by.
By first populating everything with ones.
So the reason is what we need to do is we need, um, we need this.
I'll just put it this.
This is going to be our initial condition.
It's the whole domain.
Will be like this with all the domain will have a speed of one in you and one in V.
However, we will have a little bit higher speed in here or not a little bit.
We will put it as five.
So here we will have five.
So our domain will will basically look like this.
Here is one.
And of course, this is in you.
I put it.
You.
All of this is the direction of speed is one, except this area.
It will have a high speed, which is like a five.
So this is what we are going to do.
So the first thing is we will put everything is one.
And to do so, we just put np.ones.
So this is our current time and here we will put everything.
So even all the time steps will be one.
Or you can just put this one to be zero or just we populate specific like specific, uh, the just only
the zero, the initial condition.
But anyway, we will update everything and here it's, it's easier to do it like this, although we
are rewriting this component, but it's not a problem.
The reason I did like this is to show that there are we we always start with putting the place and later
we have to identify the initial condition.
So this is but of course, if you did like this, you just all of them ones you can put this and this
ones from the beginning.
But yeah, it's it's it's up to you.
So the first thing is we put it everything is ones and what we need is we need to, we need to to have
the you.
From Integer.
0.75 over.
D.
Basically the location is going to be from 0.7 5 to 1.1.
.25.
This is where the location of the high speed.
And integer.
1.25.
We divide by D plus one because the way the python works, it will start from zero.
So we need to accommodate this one and everything has to be of course, integer So all of this location.
And.
The same thing with.
The other direction.
So this is the X and this is the Y.
What is going to be this one is going to be.
A five.
Same thing here.
The.
X, Y, and it's good.
The last thing we need.
And.
But.
Oh, sorry.
We need here.
We need to add only.
Zero.
And shift enter.
So what we did is we first assign everything to be one.
And then the initial condition, which is this is our current because we'll start calculating from the
first one.
We put it as like basically the initial condition.
And here the computation for this thing, like for the, the placeholder for um, for our whole computation,
we set it to be this much of course another way, like we don't really care because we will rewrite
everything we can just put it like this or sorry, like.
Like this.
And it will work because we now overwrite everything all the solution to be initial condition.
But as we said this one and will be updated later.
So you do whatever you want.
I will just put it in a simple way like zero, but it will work.
Like wherever it is, it will.
It will it will work just fine.
Last, let's see our initial condition.
So we just want to plot the thing x y equals numpy.
Dot, mish mish.
I just want to take some space here.
Mish grid.
Great.
And we have X and Y.
Just a little here.
And plt dot.
Figures.
So this is just a little bit, um, boring thing.
Like we just need to.
The plot things.
But anyway, like it's a course for all levels.
So please.
Consider some other people might find it easier to actually we explain everything.
So we have the contour.
Contour equals plt dot.
Contour.
If.
X.
Why?
And.
You.
Everything.
A map is, of course, many ways to show the the numbers or like the colors.
Peel.
This is Jet.
It is the one.
We usually like it as engineers.
PLT title.
The scientists.
Of course you solution.
Plot X.
Label.
And this is going to be X and Y label will be Y.
Just we add lasting.
Colors bar equals BLT.
We need to add the legend.
Colour bar.
Gunter.
This code.
Last code is just to add the legend.
Label.
I don't know where we call it.
You skill.
Contours, Matlab.
Colors.
Another buck.
Okay.
So this is.
You have it.
Everything is here is one you can see here.
And this area is going to be the high speed part.
So you is going to be five.
Same thing to do to see the.
Of course, this is only with you.
What we need also to see is the V, so we just change V here and just write it nicely.
V Here your solution becomes v solution small little v we used and.
So you this is better use Molotov just to be.
And this is you scale, this is you and this is now the scale and this is the solution.
So this is the the direction.
So the of course, the speed means like it will go in the X direction one and Y direction one.
That means the the total velocity will go like this.
Of course, if you want to just you calculate the velocity from this from these two components.
So this way we already finished the first part of our class, which is mainly writing post-processing
the 2D burgers equation and next step we need to solve it.
And after that of course, the post-processing part.