Project

Effect of Grid Spacing for the 1D Linear Convection Problem

INTRODUCTION:

A multiphysics problem exhibits certain characteristics that are helpful for simulations. The two dimensional Navier Stokes Momentum Equation is given by the formula:

.

The idea is for us to isolate the flow physics and implement numerical schemes in the flow problem.

MATHEMATICAL FORMULATION:

  • The way we can accomplish this is by taking one term and see how it affects our results. We are limiting it to One Dimensional Convection Flow Problem which is given by the partial differential equations shown below:

u is the initial velocity which varies partially with time(t) as well as space(x). c is the constant which determines the convection rate

  • For the partial differential equation to vary with time and space we make use of the numerical scheme and the initial velocity u is presented as,

where,

n represents the time step node

i represents the spatial nodes

  • We are trying to develop a numerical scheme where we apply backward differencing for time derivative and forward differencing for space derivative.

This is the equation we implement for our 1D convection problem.

PROBLEM ASSUMPTIONS:

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. Time step and number of grid points should be variables in your calculation

6. Constant Velocity, C = 1

7. Set time step = 0.01

MATLAB CODE:-

Main Program:

clear all
close all
clc


n=[21 41 61 81 101 161]; %Creating a mesh with suitable number of grid points
dt=1e-2;  % Time Step
figure(1)
subplot(3,2,1)
linear_convection_grid_spacing(n(1),dt)
title('Effect of Grid Spacing in the 1D Linear Convection Problem for 20 grid points')



subplot(3,2,2)
linear_convection_grid_spacing(n(2),dt)
title('Effect of Grid Spacing in the 1D Linear Convection Problem for 40 grid points')


subplot(3,2,3)
linear_convection_grid_spacing(n(3),dt)
title('Effect of Grid Spacing in the 1D Linear Convection Problem for 60 grid points')


subplot(3,2,4)
linear_convection_grid_spacing(n(4),dt)
title('Effect of Grid Spacing in the 1D Linear Convection Problem for 80 grid points')

subplot(3,2,5)
linear_convection_grid_spacing(n(5),dt)
title('Effect of Grid Spacing in the 1D Linear Convection Problem for 100 grid points')

subplot(3,2,6)
linear_convection_grid_spacing(n(6),dt)
title('Effect of Grid Spacing in the 1D Linear Convection Problem for 160 grid points')

Function Program:

function linear_convection_grid_spacing(n,dt)

L=1; %Length of the domain
c=1; %constant velocity
dt=0.01; %time step
nt=40; %Time loop= Simulation Time/Time Step= 0.4/0.01


x=linspace(0,L,n); %Having L and n values we can create a mesh
dx=L/(n-1); %Grid spacing between the individual points

%Define start and end positions of the square wave
n_start=find(x==0.1);
n_stop=find(x==0.3);

%x_start=0.1;
%x_stop=0.3;

%n_start=round((x_start/dx)+1);
%n_stop=round((x_stop/dx)+1);

%Intialize arrays and apply Boundary Conditions
u=ones(1,n);
u(n_start:n_stop)=2;

%Copy Values
uold=u;
uinitial=u;

%Time Loop
for k=1:nt
    
    %Space Loop
    for i=2:n-1
        u(i)=uold(i)-(c*dt/dx)*(uold(i)-uold(i-1));
    end
    
    %Update old velocities
    uold=u;
    
    %Plot for final velocities
    plot(x,u,'b')
    hold on
    grid on
    %Plot for initial velocity wave
    plot(x,uinitial,'r')
    axis([0 1 0 3]);
    legend('Final Velocity Profile','Initial Velocity Profile')
    pause(0.003);
end

%Calculating the value of CFL number to predict the stability
CFL=(c*dt/dx);
fprintf('The CFL number for %g grid points: %g. ',n,CFL)
if CFL<1
    disp('The solution is Stable.')
elseif CFL==1
    disp('The solution is Most Stable.')
else
    disp('The solution is Unstable.')
    
end

OUTPUT:

  • The CFL number for 21 grid points: 0.2. The solution is Stable.
  • The CFL number for 41 grid points: 0.4. The solution is Stable.
  • The CFL number for 61 grid points: 0.6. The solution is Stable.
  • The CFL number for 81 grid points: 0.8. The solution is Stable.
  • The CFL number for 101 grid points: 1. The solution is Most Stable.
  • The CFL number for 161 grid points: 1.6. The solution is Unstable.

RESULTS AND DISCUSSIONS:

  • Along the length of the domain, we see that as the grid spacing(dx) decreases due to an increase in the number of the grid points; as a result, the solutions will become more and more stable.
  • When the wave moves due to solving the linear convection equation, it will also diffuse artificially. This happens because we are introducing errors into a system similar to first-order schemes. This error is reduced because we are refining the grids, by adding more and more grid points, by providing a finer mesh.
  • The gradients will die down as time step moves forward, causing diffusion in the final velocity profile but we can see that while having more grid points say 100 the initial and final velocities remain the same and the profile follows the path of a train.
  • When we keep refining the mesh further, we see that the solution blows up at 160 grid points causing oscillations that never die but keep on growing and destroy the entire solutions.
  • While checking the CFL number we can see that for the most stable solution at 100 grid points its value is 1. But if we increase the grid points further the value of CFL>1 causing unstable solutions.

CONCLUSIONS:

Thus we understood how to make use of numerical methods and appreciate its applications along with the stability criterion to develop foundations in CFD.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.