Lecture 34 : Multistep Schemes, MATLAB Linear II

IIT Kanpur July 201
20 followers
Sep 6, 2024
[Music]
hello everyone welcome
back in the last class we started
looking at uh schemes for nonlinear
problems and we started uh looking at
multi-step schemes and we saw uh two
schemes one is the
twep relx f off
okay and second was Rick
Meer
okay and both the schemes use two steps
one is uh basically The Lax
fedc and secondly Lea
frog okay this uh in the two step expon
drop it you do the calculation at I +
half and so on and so forth here you do
at I okay and uh we saw that when you
combined both steps for a linear problem
you basically um get
a uh L type of scheme okay uh today
we'll look at the macor scheme okay this
is also a uh multi-step scheme and this
is very very popular in the cfd
community in fact when you start solving
let's say isers problem uh for a
nonlinear uh problem let's say the sock
tube and uh other problems the first
team of your scheme of your choice will
be the macmic scheme okay so like the uh
DM or the two step xand drop Mac cormic
also has two steps okay uh so this is
more simpler than that so in this you'll
basically use first the forward
differencing and then use the backward
differencing okay and you can actually
do the opposite you can first have the
backward defencing and then have the for
def it does not change anything
okay so uh let's look at this my scheme
okay so we have the predictor
step okay which is uh basically the
forward defensing or you can use the
backward defensing okay and we'll use it
uh
for so you can get UI
star will be U
y uh so star is nothing but my predictor
step so I'm calling it this is n + one
okay uh but this is the predictor so
maybe you can write and plus one bar
okay
minus delta T by Delta X and this is
basically you're using the forward step
first so this is UI + 1 n minus UI
n okay so this is your predictor step
and and then you go the the correct
step okay but with the step of Delta 2x
2 okay and this will be backward
differencing okay so if you do the
backward differencing so this will be
UI n +
1 minus UI now we're doing it delta T by
2 this will be n + half right
by delta T will
be equal to minus
C and uh we are doing the backward
differencing so that will become u n
minus u - 1
n by Delta X
right and U this will use the value at
we calculated earlier UI star and UI
minus one star okay and how do you get
this UI n + half UI n+ half will become
half of u n plus UI star okay so we have
calculated this UI star which is
basically uh it's like uh n+ half bar
okay so we want to get the value at n+
half this is basically Delta 2 by2 right
so this is UI plus UI star so ultimately
your scheme will become UI n + 1 will
be half UI n plus UI star which is the
predicted value
minus Lambda by 2 okay this is
UI star
minus U minus one star okay which we
have predict earlier
okay so this scheme this two steps are
called the Mac me
scheme okay and if you combine both of
them uh go back and try this this will
give you the LAX V of scheme
okay and because of that it will have
the same property as the uh laand Dr so
this will be stable for Lambda less than
equal to 1 and accuracy is Delta x²
delta T
squ okay and as I told earlier you can
also do first step with the backward
differencing okay so that will be UI
star it will be u n minus T delta T by
Delta X UI n minus UI
-1 n okay and then you do the uh forward
differencing but with time
step delta T by 2 okay your final value
u n + 1 will become half u n + UI
star okay minus Lambda by 2 now use the
forward differencing this is UI + 1 star
minus UI
star okay both are equivalent
okay so same thing is shown here
okay so this is how you can get and this
is HT lamb Sigma less than equal to one
okay so this is also a second method it
is equival to LX vandr you can alternate
this two uh the advantage of this is no
store values you don't need like I +
half and IUS half and so on and so forth
okay and this works well for the
nonlinear problems okay so with that we
have basically discussed several schemes
in the last few classes uh and let's
look at how these schemes behave okay
practically on many different problems
okay so I'll be taking three examples
one is the function which is like an
exponential function this is like e to
the power minus xus some value x0 squ
okay so if the x is less than x zero
this is uh basically uh decaying
otherwise it is increasing okay so that
is in one exponential function I'll look
at the sign function okay and then I'll
also look at the we'll look at the step
function okay why step function because
you know that there's a discontinuity
here and as we have seen that you might
get some Wiggles there okay and we'll
check it uh for the linear problem and
the not the problem okay so I'll take
you to uh M lab online but you can also
use uh your favorite uh coding tool you
might use Python you might use C C++
foron whatever you want and uh you can
just try out the schemes and see how it
works okay so let me take you through
some examples you can if you have a
stand on mat lab that also you can use
uh and there are two ways to use the mat
lab I mean you can do the coding as a
script which is mile
and you can also do the the LI script
basically where what you can do is uh uh
you can uh basically write your equation
and see uh I mean for your future you
can try
it and uh I'm showing you some examples
here but you should really trite it out
okay uh you should write these codes and
these are not very difficult codes okay
so I hope you able to uh see the screen
okay so I'm solving this linear
convection problem okay which is
basically
uh d by DT plus c d by d x equal to0 let
me just make a little big okay and so
the convection speed this is the see is
the convection speed so this can change
okay so I'm using 0.5 now but you can
use different values and this is the
initial function which is exponential -
x - 2 squ so if you can see that if
initially if it is X less than two okay
then it is uh basically growing
otherwise it will be decaying because
there's a negative sign here if it is
negative minus sign then it will be
growing otherwise it will be decaying
okay uh okay and for this the analytical
solution will be x - CT so as as you
know that for the linear problem d by DX
plus C DT plus C DX and if the function
U is equal to let's say FX the solution
will be FX - CT uh so that we have
discussed while we are talking about the
characteristic of the equation okay so
you can just replace this initial
solution uh with an in of X you put x-
CT that will give the uh the analytical
solution so we'll compare those solution
and this is the intervals that have
chosen L equal to this is a length total
length Delta X Delta t uh this is the
convection velocity and amount of time
steps okay so let's look at uh I have
couple of more uh problems okay but uh
let's let me just do it for uh this
problem first okay so these are the
parameters that you can Define L equal
to basically 10 Delta xal to .1 and then
x 0 to DX Delta let me just run this for
you once
okay okay so now it is
running you can see that it's showing
busy so uh that's because it is running
okay yeah let me just stop it
here yeah so you can see that uh uh
because I've used the X so this you can
use the Len space or you can use 0 to
dx2 so I'm have chosen DX equal to 0.1
okay so the X will be 0 to 10 it will
divide in the steps of 0.1 so this is
the value of x will be like this okay
these are the values okay and then I've
taken DT equal to 0.1 okay okay so uh if
you choose like this so your CFL number
which is Lambda is CDT by DX so that
will become 0.5 right because C is .5 DT
is 1 1 and DX is 0.1 so your Lambda okay
you can just see it here is equal to5 so
this is less than one so the most of the
schemes should be stable okay except the
ftcs okay and I'm this is just a
definition that I want the zero of size
length x and and this is my initial
function
okay and now I have written the code for
different schemes okay so here you can
see this is the up scheme C delta T by
DX ui- ui- 1 n so I'm judging C Delta
tal to Lambda my Lambda but this is a
very simple code go from two to length
of U basically the total size okay why
am I starting from two because it takes
the value of i - one right so it cannot
go to I equal to Z right the M starts
from from one right so I'm taking from
two so that means you need Bond
condition at basically you need Bond
both the sides okay so here I'm using a
periodic Bond condition actually you
don't need to do that because I'm not
letting the wave conve and come back
again I'm limiting myself to um uh the
point where it has not touch the ether
boundary okay but I can use a periodic
bonding condition and it can continue
going okay similarly this is the central
defensing scheme okay which is C delta T
by2 Del X and the function I be Central
here I calculate Lambda and this is05
into Lambda u i + 1 and U ius1
right this LX fed scheme okay which is
uh uh the U in term is replaced by half
of UI + 1 and UI minus one so I just
replaced this term here okay and all
other terms
basically uh Remains the Same okay this
is The Lax FC scheme okay LAX f of a
scheme where you are adding the
disspation term here so this Alpha is
basically equal to Lambda square right
for the L drop but I have used the
general Alpha value okay I'll see we'll
see what happens if you increase the
value of uh Alpha and how the schemes
becomes more and more dissipative okay
so these are the four schemes
implemented here now let's uh do it one
by one okay so first I'm trying to do it
for okay let's do it for the central
scheme okay so let's let me call that
okay
uh do have upwind so yeah let me do the
upwind scheme first
okay
okay so let me run
that yeah so on the right hand you can
basically see uh how things are growing
okay I hope you're able to see the movie
okay so you can see that as it is going
on the right uh the peak is going down
right that is because of the dissipation
in the upending scheme so so as it moves
right the peak will keep on going down
okay so that is what we are observing
here okay and uh if you depending on the
CFL number and the delta T and Delta X
you will have basically uh the peak May
uh dissipate much more faster okay you
can see that how much it has dissipated
okay now let's go and try some other
scheme okay let's try the central scheme
okay so we know the central scheme is
not stable but still let's try and see
how it
behaves
okay so you can see that now it is going
above okay and you can see that this
veal have started coming okay I have
limited it uh probably y limit of 0 to 1
okay I'll just change the limit and show
it to you okay so you can see that it
has started developing
oscillations okay and uh let me just
change this while
limit let me let's see how it
happens okay so now it has gone uh
Beyond one okay and
uh this uh oscillation started
developing okay and you can see that now
they are growing okay and in this place
Focus near uh the xaxis of 0 2 okay and
this will become bigger and bigger okay
with time okay because uh there's no
dissipation in the central defensing
scheme to basically kill this out and
eventually you can see the limit the XIs
it's say minus 6 and six and keeps on
growing and now it basically it blow up
okay if you run it for more a long time
you'll not see anything so this is how
the central defensing scheme behaves
okay let's go and look at the Lex
federic scheme okay
Le F scheme as we know it is a very very
dissipative scheme okay and that is
observed here you can see that how is it
is attenuating okay let me just fix the
Y limit here
okay okay now it was initially up to one
now see how much it has attenuated okay
because of the dissipation in the uh LAX
fed scheme
okay so you can uh do one interesting
thing so in the Lex fic we know that the
dissipation error the leading term is 1
by Lambda minus Lambda where Lambda is
the CFL number so the dation is very
very high that's what we have learned in
the last class is because 1 by Lambda
terms becomes very very high so if you
use a small value of Lambda let's say
0.1 the 1 by Lambda becomes 10 so 10
minus 0.1 is basically 9.9 so let's try
that okay let's uh uh use the value of
uh such a value that my
CFL becomes one 0.1 okay so for that you
can probably use uh so my DX is
0.1 okay and uh Lambda let's say I want
to keep equal to
0.1 okay so DT will
become so DT will
become uh DX into Lambda by C DX into
lamb
by
C
okay so that is 0.02 okay let's use the
value of
0.02 okay and then we have to run it for
okay just run it
okay you can see that de is much faster
now okay from the peak uh value DK is
very very fast okay that is because we
have used the CF a number the Lambda
value which is very very low and that is
why the disspation is very very high
okay let's uh stop it here and use our
old value okay which is 0.1 and let's
look at the last scheme which is the uh
LAX vend scheme Lex vend scheme we know
that uh is uh uh it has I mean uh we
just add the right amount of dissipation
in this to make the fdcs balance okay so
let's run the uh Le wind scheme and you
can see that uh the amplitude does not
go down so this is Le amplitude look at
the top of the curve okay and then the
amplitude is not really going down that
means it does not have any dissipation
okay it has some disperson as you can
see that some vehicles are getting
developed here okay uh but it does not
have any dissipation okay so it is it is
not dissipating uh it may have very
little little dissipation at the higher
order but here uh you cannot see any
dissipation here
okay uh now we'll do one thing uh let's
stop it here okay and add some more
dissipation in this okay so how do you
add dissipation so in the last V drop
your Alpha is equal to Lambda Square
what what if I use the double of the
dissipation okay this is 2 into Lambda
Square
okay and then you will try that so this
is not LAX drop but I have a scheme
which has added some dissipation and the
dissipation is higher than the Lambda
Square value okay then I run it again
okay okay so now you can see because we
have added the higher dissipation I'm
still using the LAX scheme but because
the at dissipation is higher then it is
basically uh going on the right hand
side and the dissipation is happening uh
it is convecting with the speed C which
is05 and depending on the delta T it is
basically covering that distance in
every delta T but there's a lot of
dissipation happening here okay so you
can control the dissipation and as you
can see that if you have a high
dissipation all these things the vles
that were growing here is basically not
appearing right which you would have
been seeing in the left of the curve
that is not appearing here right so that
is the the the advantage of having
disspation that if you have any problem
or any V that gets developed you can
basically uh uh that gets killed that
gets killed with time okay or that gets
minimized with time okay so now let's uh
uh show you some uh relative plots okay
so here
uh I will use this uh uh same example
but I'll show all the plots together so
I have some more cases so uh in the last
one we only saw the exponent IAL
function but I also have the sign
function here okay which is basically
sin 2 pi K so I have seeing a traveling
sign wave so the initial thing is two
periods in a distance of 1 M this is
Lambda = to 1 by 2 so k = 2 pi by Lambda
that is 4 Pi so uh U is 2 pi K right and
then you have this heavy side function
so heavy side is basically
uh uh you will have the curve going up
then discontinuity and then come down
okay it's like a box
okay so uh let's try with the first one
only and we plot all of these things
together okay same value 0.1 L = to 10
okay DX .1 and we want to see all of
this schemes together okay so I have
some more schemes also implemented in
this up Central defensing le le pandr
then I have also beam warming
implemented okay this is backward this
is backward okay this is one step beam
warming okay
then I also implemented two step macor
and two step rickm
okay uh let's first see uh the schemes
that is uh very common that we have seen
earlier so here you can see that I'm
just calling all of these schemes and
updating my value so my upwind is uup my
central is UC okay uh lxf is Ulf okay
LAX W is basically ulw so I'm calling
all the functions and storing in the
variables okay okay Mac is Mac is umac
beam Waring is ubw and Rick m is urri
okay so we also have the analytical
solution so let me just plot this uh
value up to LAX
VR
okay okay and what are the schemes that
we have we have
initial value analytical value and upnd
scheme and not putting the the central
scheme because this is unstable Lex fedc
and Lex fend okay let's do up to this
point okay
R okay this exponential function Lambda
equal to
0.5 okay and you can see this uh curve
probably better here let me open it
here okay so I hope you're able to see
my screen okay so this is my initial
wave
uh the black one okay and this is the
final solution so the one here on the
top you see is the analytical solution
okay in the black color okay and then
you have this this is the upnd scheme
there's lot of dissipation so I'm
planting at a particular time okay The
Lax fedric is even more dissipation here
okay uh because of the high disribution
that we have in the LAX fedc okay and
that is why it is most stable also but
the LX VR is maintaining almost like the
analytical one okay so that is uh what
we found here
okay let me just uh call one more thing
because the plot is not looking properly
so this is just a setting for the
plot okay so that I can see it more
clearly okay so yeah you can probably
see it better
now okay
yeah so here uh this is the initial
condition and this is the final one okay
now let's do it
for the other cases maybe I want to do
the uh include the B Beam warming Also
let's include the beam warming
also
okay so this is the beam warming screen
now
so beam warming is also you see that
there is very little dissipation but one
thing we are uh uh seeing here is the
phase error that means that your beam
warming is actually traveling on the
right side of the analytical solution so
let me just blow this up so that you can
see it properly yeah so this is The Lax
F drop this the black one is analytical
and the one in the sand color is the
beam warming and you can see the beam
Waring has got some phase error because
it is not in uh of course I mean Lex VR
also has some phase error but beam
Waring has much higher phasor
okay uh let's look at some other
function okay so let me change you to
the sign function here now okay uh so
the sign function is as we saw earlier
so the sign function is sin 2 pi K okay
which is basically s sin 2 K so that is
8 Pi k
right
so and then we're putting it between
some values so I'll show you the initial
profile also and we have the analytical
solution also and let's see how it
behaves okay different schemes
okay
okay yeah so this is a traveling sine
wave okay so it has basically traveled
here some point uh so you have this
black one which you can't see because it
is overlapped here antical solution then
you have the upwind which is this yellow
value LAX fedric dissipation High
dissipation and LAX B and beam warming
are almost at the same place okay
so just me just blow this up and you can
see here the black one is the analytical
one uh upwind LAX fedric and the LA SP
on beam warming are almost the same
place of course beam warming is
traveling little bit right okay uh what
is the value of Lambda
here okay Lambda is 0.95 okay let me
change the Lambda and let's use the
value
of25 okay in this case I can directly
check change the value of Lambda so as I
change the value of Lambda my DT almost
uh immediately gets set okay so if I'm
changing the value of Lambda done it
okay yeah you can see this
now now Lambda is
uh very small value okay I think uh 25
or so okay you can look at the LAX fedc
okay it is completely dissipated okay
because of very high dissipation okay
the upwind also has dissipated more okay
uh but the last V drop on beam warming
are almost similar okay uh
the the one thing you should note here
is basically these vles okay so this
vles is because of the disperson error
that we have in the LAX vend uh VR
scheme okay Lex fedc is completely
dissipated beam warming also has some
dispersion as you can see here probably
on the right side here
so this side okay so this is the the the
leading error okay uh the the last SP up
you have the lagging error okay so this
is the effect of uh Lambda okay so this
is Lambda to 025 so as we discussed last
time that Lambda should not be very
small if you're using the Lex ftic
scheme because the dis will be very very
high okay finally we use the let me
change it back
to.5 finally I will show you the heavy
side function okay so change the input
to three
okay so three is my this is my third
input which is the heavy side function
okay uh which is basically initially uh
a box and let me just run
this
okay
so uh the initial profile is sh here the
black one
okay okay
so you can see that uh this dotted black
is the initial profile and the solid
black lines is the final analytical
solution and uh the upwind uh you can
probably see it better if I zoom this in
okay
yeah
so you can see here at the corner okay
so the uh LAX fedc I mean it has
dissipated the most okay then we have
the up wind and then we have the LAX
pendra okay and beam warming is showing
some mulations here okay so
um the profile is as expected okay and
you have lot of vles here in the beam
warming as well as in The Lax vandr okay
near the discontinuity so that is also
expected because at the discontinuity if
you do not add any dissipation okay it's
going to show you this kind of behavior
so if you are trying to solve a problem
which has uh got socks and all and if
you're using LAX V drop or the B Maring
scheme that will not work because you'll
get a lot of this phenomena this is
called the Gibs phenomena okay at the
discontinuity we'll have this kind of
vles that will be coming
okay uh the final thing that I want to
show you is uh basically the macor and
the Rick Mar scheme which are the
two-step scheme okay and as we've
discussed that for the linear uh problem
uh uh it is like uh your uh uh LAX point
of SK so let's see if we are seeing the
same thing okay I'm just just close all
these
things okay I'll only open this Mac cor
Mac
okay and let's see how it looks
like let me close this initial profile
also okay it's
done I'm showing you for the exponential
function okay yeah
okay so now this is only the riar and
the Mac Cormac okay so the black one is
the analytical and riar is slightly
different because you know that it is
using four values it's a five stensil
scheme in one step and macmic is three
stencil so macmic is almost like the
analytical one okay I wanted to show you
compare with the LAX bandr okay so let
put the LAX bandr also okay
use this LAX also okay so we have LAX
spend Mac
andic nickm and of course you have the
analytical one so let's uh run this
section
okay
yeah okay so here uh you can see that uh
your Mac Cormac uh and the uh LAX drop
is actually on top of each other so
that's why you cannot see the LAX vand
drop okay uh if I blow this I can
probably show it to you and the rck m is
this scheme so this is slightly
different from The Lax drop okay let me
just blow this
up okay no so yeah I mean the Lex VR and
the Mac corm for the line problem they
are exactly the same so that's why you
are not seeing anything here if I just
uh remove this okay probably I'll put
this some markers here
okay yeah so you can see that uh it is
just coming on top of the LA scheme
okay so uh with this we end the class
today in the next class I'll show you
some uh I mean how these schemes behave
when you go to the nonlinear problem
I'll show you solutions for non problem
and eventually we'll go to solving a uh
proper NE problem we'll start with a
problem and we'll solve a sock Tu
problem uh in the next class okay with
that we stop uh today but I'll request
you please uh go back and uh write these
schemes uh uh solve it uh okay and try
to plot these results and get a feel of
how these schemes work okay so that will
be very very important when you start
solving your cfd problem
okay thank you very much
[Music]
[Music]
[Music]
