All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Aim: Our objective is to solve the PDE through MatLab code and compare the effect of time step on the solution and compare the simulation time taken for different time steps. Step 1:Here we are creating a function which gives postion of node on whole length and final velocity value at that node as output by taking dt as…
Sai krishna chary Vangala
updated on 07 Mar 2020
Aim: Our objective is to solve the PDE through MatLab code and compare the effect of time step on the solution and compare the simulation time taken for different time steps.
Step 1:Here we are creating a function which gives postion of node on whole length and final velocity value at that node as output by taking dt as input.
Step 2: giving inputs for the linear convection problem
'L' domain length = 1 meter
t = 0.4 sec
c=1
n=80
Step 3:
U array has been defined as U is 1 at all the X values excepts 0.1 to 0.3 band
So we created a function that predict the nodes at 0.1 and 0.3 and gives you the node number.
So using range operator we defined the value of U in between these nodes as 2
Step 4 :
The function has been carried out through two loops one for to move the step function spacely and other timely, where we used first-order forward differencing for time and backwards differencing for space.
step 5:
Then in the main program we are calling this function and calculating the values of final velocity at each node for each time step.then we also calculate the simulation time and compare them at different time steps.
Result:
figure 1
In figure 1 the graph shows the numerical solutions at t = 0.4 seconds for different time steps are compared
figure 2
Figure 2 shows the simulation time as a function of the time step.
Here the small step size took a large simulation time as the number of iterations gets increased nt=t/dt where t is a constant value of 0.4
when
t=0.1 thevelocity profile gets to blow up because of CFL value getting increased more than 1
t=0.01 the velocity profile looks great and no blow up and simulation time is less
t=0.001 as the step time gets lowered the finer the velocity profile becomes and simulation time is more than for 0.01
t=0.0001 it is even more smooth and the simulation time will be very high as the number of iterations is high.
program :
function:
% function which gives postion of node on whole length and final velocity value at that node as output by taking dt as input
function [x,uold] = timestep(dt)
%inputs for the linear convection problem
L=1; %1 meter length
n=80;
c=1;
x=linspace(0,L,n);
%finding dx based on whole length
dx=L/(n-1);
x_start=0.1;
x_end=0.3;
n_start= round((x_start/dx)+1)
n_end=round((x_end/dx)+1)
%calculations
%Creating an array of u as per the given values
u=1*ones(1,n);
u(1)=1;
u(n_start:n_end)=2;
uold = u;
t=0.4;
%Since we need to find out the solution till 0.4 second we have to carry out t/dt number of iterations
nt=t/dt;
%time loop
for k=1:nt
% space loop
for i=2:n
%first order backward differencing for space term and forward differencing for time
u(i)= uold(i)-(c*dt/dx)*(uold(i)-uold(i-1));
end
uold=u;
end
end
main program:
clear all
close all
clc
dt=[1e-4,1e-3,1e-2,1e-1]
% calling the function and finding the simulation time
tic
[x1,u1] = timestep(1e-4)
toc
t1=toc;
tic
[x2,u2] = timestep(1e-3)
toc
t2=toc;
tic
[x3,u3] = timestep(1e-2)
toc
t3=toc;
tic
[x4,u4] = timestep(1e-1)
toc
t4=toc;
figure(1)
% plotting the velocity profile for different time steps
plot(x1, u1,'color', 'g')
hold on
plot(x2,u2,'color', 'y');
hold on
plot(x3, u3,'color', 'r')
hold on
plot(x4,u4,'color', 'b');
axis([0 1 0 2]);
xlabel('length of domain');
ylabel('velocity');
legend('1e-4','1e-3','1e-2','1e-1');
figure(2)
% comparing the simulation time for different time steps on bar graph
simulation_time = [t1 t2 t3 t4]
bar(simulation_time,'g')
set(gca,'xticklabel', {'1e-4','1e-3','1e-2','1e-1'});
xlabel('time steps');
ylabel('simulation time');
title(' simulation time as a function of the time step');
legend('simulation time');
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Solving Steady State 2D Heat Conduction Equation using C++ OOP
Objective : The challenge is to solve the 2D Steady Heat Conduction equation using C++, where alpha is the thermal diffusivity About equation : In physics and mathematics, the heat equation is a partial differential equation that describes how the distribution of some…
18 Sep 2022 12:28 PM IST
Classes and Objects
1) Operator overloading to perform sum of two complex numbers : #include using namespace std; class complex // class definition { int i; int j; public: //member functions complex() //default constructor initialzed values with ' 0 ' as not to have garbage values { i = 0 ; j = 0 ; } complex(int…
25 Jul 2022 04:42 PM IST
Git and GitHub basics and Initialize a git repository of cavity and then pushing this repository to GitHub
Introduction : When you write a code and want to share with many people and even world wide then you can't share it through mail for everyone .If they reviewed and asked to change something and if you change it and again you need to send them .If this process takes many a times they it is difficult to connect with…
22 Jul 2022 06:55 PM IST
Project 1 : CFD Meshing for Tesla Cyber Truck
Objective : To Identifying & cleanup all the topological errors in the given Tesla Cyber Truck Car model. To create a surface mesh. To Create a wind tunnel around Tesla Cyber Truck Car . To create a volumetric mesh to perform an external flow CFD analysis simulation. Introduction : ANSA :…
12 Jan 2022 12:28 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.