0% found this document useful (0 votes)
29 views

Program For Problem-4

This document contains code to simulate the propagation of a shock wave through a tube using the Liu-Lax scheme. It initializes the density, velocity, and pressure fields with different values to the left and right of x=0. It then performs the main iteration loop, calculating fluxes at each time step using flux splitting and updating the conserved variables. Finally, it plots the pressure, velocity, and density fields after the simulation.

Uploaded by

maruthinh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Program For Problem-4

This document contains code to simulate the propagation of a shock wave through a tube using the Liu-Lax scheme. It initializes the density, velocity, and pressure fields with different values to the left and right of x=0. It then performs the main iteration loop, calculating fluxes at each time step using flux splitting and updating the conserved variables. Finally, it plots the pressure, velocity, and density fields after the simulation.

Uploaded by

maruthinh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGRAM TO SOLVE SHOCK TUBE PROBLEM USING LIU-LAX

SCHEME (SIMPLE FLUX SPLITTING)


PROBLEM-5

clear all
close all
clc
%% GRID GENERATION %5

N=input('enter the no of grid points=');


x=linspace(-10,10,N);
gamma=1.4;

%% INITIAL CONDITION %%

for i=1:N

if x(i)<0

rho(i)=1;
u(i)=0;
p(i)=100000;

else

rho(i)=0.125;
u(i)=0;
p(i)=10000;

end
end

%% PLOTS FOR INITIAL CONDITION %5

plot(x,rho);
xlabel('x')
ylabel('rho')
figure(2)
plot(x,u);
xlabel('x')
ylabel('u')
figure(3)
plot(x,p);
xlabel('x')
ylabel('p')

dx=20/N;
dt=(dx*0.25)/(374.17);
k=round(0.01/dt);
%% MAIN ITERATION LOOP %5

iter=1;

while iter<=k

for i=1:N

a(i)=sqrt(gamma*p(i)/rho(i));

%% SPECTRAL RADIUS %%

alpha(i)=max((u(i)+a(i)),(u(i)-a(i)));

E(i)=(p(i)/(rho(i)*(gamma-1)))+0.5*u(i)^2;

%% FLUXES %5

G1(i)=rho(i)*u(i);
G2(i)=p(i)+rho(i)*u(i)^2;
G3(i)=(rho(i)*u(i)*E(i))+p(i)*u(i);

U1(i)=rho(i);
U2(i)=rho(i)*u(i);
U3(i)=rho(i)*E(i);

G1plus(i)=(G1(i)+alpha(i)*U1(i))/2;
G1minus(i)=(G1(i)-alpha(i)*U1(i))/2;

G2plus(i)=(G2(i)+alpha(i)*U2(i))/2;
G2minus(i)=(G2(i)-alpha(i)*U2(i))/2;

G3plus(i)=(G3(i)+alpha(i)*U3(i))/2;
G3minus(i)=(G3(i)-alpha(i)*U3(i))/2;

end

for i=2:N-1

%% FLUXES AT LEFT AND RIGHT STATES %5

G1jplushalf(i)=G1plus(i)+G1minus(i+1);
G1jminushalf(i)=G1plus(i-1)+G1minus(i);

G2jplushalf(i)=G2plus(i)+G2minus(i+1);
G2jminushalf(i)=G2plus(i-1)+G2minus(i);

G3jplushalf(i)=G3plus(i)+G3minus(i+1);
G3jminushalf(i)=G3plus(i-1)+G3minus(i);
U1(i)=U1(i)-(dt/dx)*( G1jplushalf(i)-G1jminushalf(i));
U2(i)=U2(i)-(dt/dx)*( G2jplushalf(i)-G2jminushalf(i));
U3(i)=U3(i)-(dt/dx)*( G3jplushalf(i)-G3jminushalf(i));

%% UPDATED VALUES %5

rho(i)=U1(i);
u(i)=U2(i)/U1(i);
E(i)=U3(i)/U1(i);
p(i)=(E(i)-0.5*u(i)^2)*rho(i)*0.4;
a(i)=sqrt(gamma*p(i))/rho(i);

end
iter=iter+1;
end

%% PLOTS %%

figure(4)
plot(x,p);
xlabel('x')
ylabel('p')
figure(5)
plot(x,u)
xlabel('x')
ylabel('u')
figure(6)
plot(x,rho)
xlabel('x')
ylabel('rho')

You might also like