Week 4 - Linear Convection
Objective -: Comparison of 1-D linear convection Plots when four different grid sizes are chosen for time 0.4 seconds having time step of 0.01.
Results and discussion -:
%1-D linear convection challange simulation both video and plot can be done%with this same code%given or desired parameters in questionnx=40; %number of grid pointsL=1; %lengthdx=L/(nx-1); %difference between two space stepsc=1; dt=0.01;t=40; % time stepsx=0:dx:L; %respective grid points distance from origin along lengthk=c*(dt/dx);uold=zeros(1,nx);%initial or boundary conditionfor i=1:nx if ((0.1<=x(i))&&(x(i)<=0.3)) u(i)=2; else u(i)=1; endend%Evaluating velocity profile for each time stepi=2:nx-1;for it=0:t uold=u; %h=plot(x,u); %plotting the velocity profile %axis([0 1 0 3]) %title({['1-D Linear Convection with=',num2str(c),'; CFL (k)=',num2str(k)];['time(dt*it)=',num2str(dt*it)]}) %xlabel('Spatial co-ordinate (x)\rightarrow') %ylabel('Transport property profile(u)\rightarrow') %drawnow; %refreshdata(h) %pause(0.1) %Explicit method with F.D in time and B.D in space u(i)=uold(i-1)*k+(1-k)*uold(i);endh=plot(x,u); axis([0 1 0 3])title({['1-D Linear Convection with=',num2str(c),'; CFL (k)=',num2str(k)];['time(dt*it)=',num2str(dt*it)]})xlabel('Spatial co-ordinate (x)\rightarrow')ylabel('Transport property profile(u)\rightarrow')drawnow;refreshdata(h)legend('nx=40');In the above code if we include the plotting velocity commands within the for loop we can see the variation of velocity with respect to the varying time. Above code is for the final plot.
Code for the comparison plot with slight modifications in above code is as follows-
%1-D linear convection challange simulation both video and plot can be done%with this same code%given or desired parameters in questionnx=160; %number of grid pointsL=1; %lengthdx=L/(nx-1); %difference between two space stepsc=1; dt=0.01;t=40; % time stepsx=0:dx:L; %respective grid points distance from origin along lengthk=c*(dt/dx);uold=zeros(1,nx);%initial or boundary conditionfor i=1:nx if ((0.1<=x(i))&&(x(i)<=0.3)) u(i)=2; else u(i)=1; endend%Evaluating velocity profile for each time stepi=2:nx-1;for it=0:t uold=u; plot(x,uold,'r') hold on plot(x,u) axis([0 1 0 3]) title({['1-D Linear Convection with=',num2str(c),'; CFL (k)=',num2str(k)];['time(dt*it)=',num2str(dt*it)]}) xlabel('Spatial co-ordinate (x)\rightarrow') ylabel('Transport property profile(u)\rightarrow') drawnow; %refreshdata(h) pause(0.1) %Explicit method with F.D in time and B.D in space u(i)=uold(i-1)*k+(1-k)*uold(i);endgrid on;legend('nx=160');%by changing the value of nx we can get series of comparison plots#As per the demand of plot with four different grid size -:
1-D linear convection with c=1.
Case-1
if nx=20 is substituted in above codes the plot arises is as follow-
Fig 1.1 Final plot
Fig 1.2 Comparison plot
Case-2
if nx=40 is substituted in above code the plot arises is as follow-
Fig 2.1 Final plot
Fig 2.2 comparison plot
Case-3
if nx=80 is substituted in above code the plot arises is as follow-
Fig 3.1 Final plot
Fig 3.2 comparison plot
Case-4
if nx=160 is substituted in above code the plot arises is as follow-
Fig 4.1 Final plot
Fig 4.2 comparison plot
CONCLUSION -:
After Visualization of above series of plots it can be concluded that the refinement of grid is not always a better option (nx=160), above certain limit the solution can be unstable. And with the increasing refinement there is less decrement in height and finally the approximate original velocity of 2m/s is being convected throughout the timesteps when we chose nx=80.