All Courses
All Courses
Problem Statement:- Numerical solution to the One-dimensional Linear Convection equation. 1. Assume that the domain length is L = 1m 2. The initial velocity profile is a step function. It is equal to 2m/s between x= 0.1 and 0.3 and 1m/s everywhere else 3. Use first-order forward differencing for the time derivative…
Pratik Ghosh
updated on 19 Jan 2021
Problem Statement:-
Numerical solution to the One-dimensional Linear Convection equation.
1. Assume that the domain length is L = 1m
2. The initial velocity profile is a step function. It is equal to 2m/s between x= 0.1 and 0.3 and 1m/s everywhere else
3. Use first-order forward differencing for the time derivative
4. Use first-order backward/rearward differencing for the space term.
5. Constant convection coefficient, c = 1 m/s
6. Time step, dt = 0.01
7. Simulation run time, t = 0.4 seconds.
Perform the simulation for the Number of nodes, n=20,40,80, and 160.
Objective:- The work is focused on solving the below-mentioned 1D Linear Convection equation using Finite Difference Method (FDM) where we will be making use of Forward Differencing (FD) scheme for the time derivative term & Backward Differencing (BD) scheme for the space term. The initial & final velocities are compared with various values of the number of divisions of the domain, denoted by 'n'. The goal is to plot these variations of 'n' for values of 20, 40, 80 & 160.
∂u∂t+C∂u∂x
where ∂u∂t= time derivative ; ∂u∂x= space term
Discretizing:-
We have the differential equation, ∂u∂t+C∂u∂x
Applying Forward Difference scheme to the "time term" we get, ∂u∂t=un+1(i)-un(i)△t
where, ∂udt= First Order time derivative of velocity
un+1(i)= Velocity at node (i) & time step (n+1)
un(i)= velocity at node (i) at time step (n)
△t=timestep
Applying Backward Difference scheme to the "time term" we get ∂u∂x=un(i)-un(i-1)△x
where, ∂udtx= First Order space derivative of velocity
un(i-1)= Velocity at node (i-1) & time step (n)
un(i)= velocity at node (i) at time step (n)
△x= grid spacing
Finally ∂u∂t+C∂u∂x=0
⇒ un+1(i)-un(i)△t-C un(i)-un(i-1)△x = 0
⇒un+1(i)=un(i)+C(△t△x)[un(i)-un(i-1)]
⇒CFL=C△t△x
⇒un+1(i)=un(i)+CFL[un(i)-un(i-1)]
MATLAB/Octave Code:-
#User Defined Function For Varying Value of 'n'
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function y= f(n,x)
for i = 1:length(x)
if x(i) == n
y = (i);
break;
elseif x(i)>n
y=i;
break;
endif
endfor
endfunction
#Main Program Code For Linear Convection
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
clear all
close all
clc
%Inputs parameters for linear convection problem
c=1;
n=[20 40 80 160];
%Creating a loop for each value of 'n'
for j = 1:length (n)
%Given Space Variables
L=1;
x=linspace(0,L,n(j));
dx(j)= x(2)-x(1);
%Time Variables
dt=0.01; %Time step
time=0.4; %Unit=seconds(s)
nt= time/dt;
%Definign the start & end positions of the wave
n_start= f(0.1,x); %f=function
n_end= f(0.3,x);
%Initial Velocity Profile
u=1*ones(1,n(j));
u(n_start:n_end)=2;
%Setting up the Boundary Conditions (BC's)
u(1)=1;
uold=u;
u_initial=u;
%CFL formula from the derivation above
CFL= (c*dt/dx(j));
if CFL >1 disp (sprintf("%d. Solution Blown upnError : CFL value greater than Time Step & Grid Distance values",j))
else disp (sprintf("%d. CFL <=1 Solution Reliable",j))
%Time Loop
for k = 1:nt
for i = 2:n(j)
u(i) = uold(i)-(c*dt/dx(j))*(uold(i)-uold(i-1));
end
uold = u;
end
%Plotting
subplot(2,2,j)
plot(x,u_initial,'r')
hold on
plot(x,u,'b')
caption = sprintf('CFL = %3.2fnn = %2.0fndx = %2.4f', CFL, n(j), dx(j));
title (caption, 'FontSize', 20);
ylim([0 6])
xlabel("x")
ylabel("velocity")
xlim([0 L])
legend('initial velocity', 'final velocity', 'Location','northwest')
grid on
pause(0.03)
end
end
Observation:-
From the above graphs, we can conclude that as we increase the number of grid points 'n' the accuracy of the solution keeps increasing but after a certain value of 'n' the solution of the velocity profile will blowoff & the solution will become unstable.
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...
Visualize 2D Flow Simulation Through A Backward Facing Step For 3 Distinct Mesh Grid Size Using openFOAM & ParaView
Abstract:- The work is focused on simulating fluid flow through a backward-facing step channel that would be subjected to a sudden increase in the cross-sectional area, this would result in flow separation & reattachment zones. The geometry will be designed by creating vertices & then joining them to form blocks.…
19 Jan 2021 06:26 AM IST
Week 12 - Symmetry vs Wedge vs HP equation
Objective:- The work is focused on performing a CFD simulation for a flow through a cylindrical pipe with reference to Hagen Poiseuille's principle that refers to the laminar flow formation inside a smooth cylindrical tube. Since the computation will be carried out on a laptop, we will not be able to consider the entire…
19 Jan 2021 06:26 AM IST
Writing A MATLAB/Octave Code To Perform A 1D Super-Sonic Nozzle Flow Simulation Using Macormack Method.
Abstract:- The work is focused on writing a MATLAB/Octave code to simulate the isentropic flow through a quasi 1D supersonic nozzle using both the conservation and non-conservation forms of the governing equations and solving them using MacCormack's technique and compare their solutions by performing a grid dependency…
19 Jan 2021 06:24 AM IST
Writing A MATLAB/Octave Program To Solve the 2D Heat Conduction Equation For Both Steady & Transient State Using Jacobi, Gauss-Seidel & Successive Over Relaxation (SOR) Schemes.
Problem Statement:- 1. Steady-state analysis & Transient State Analysis Solve the 2D heat conduction equation by using the point iterative techniques that were taught in the class. The Boundary conditions for the problem are as follows; Top Boundary = 600 K Bottom Boundary = 900 K Left Boundary = 400 K Right Boundary…
19 Jan 2021 06:23 AM IST
Related Courses