Sdfghjklzxcvbnmqwertyuiopasdf: Digital Simulation Lab
Sdfghjklzxcvbnmqwertyuiopasdf: Digital Simulation Lab
Sdfghjklzxcvbnmqwertyuiopasdf: Digital Simulation Lab
EXPERIMENTS
1.
4.
13
5.
17
21
25
27
29
10. Programm for Blasius solution of Boundary layer over flat plate
31
11.
39
Join the points by selecting geomtry tab, Create curve from points.
Geometry Create surface Curve driven select driving curve and then the
remaining lines under the driven curve Apply.
Geometry Create surface Simple surface for upper and lower surface.
From the model tree right click on parts create part Name
Inlet in_1
Outlet out_1
Top top_1
Side sidewall_1
Bottom Bot _ 1
Airfoil Airfoil_1
Apply
2. Mesh geometry:
Give global mesh parameters in global mesh setup like element scale factor and
element max size = 0.1 display on apply.
3. Export mesh
Output output to cfx save project output type output scale factor - .msh file
created.
4. CFX:
Default Domain Basic Settings Materials Air at 250c, Reference Pressure 1 atm
Domain - Default Domain Modified
Type
Location
Fluid
FLUID
Materials
Air Ideal Gas
Fluid Definition
Material Library
Morphology
Continuous Fluid
Settings
Buoyancy Model
Non Buoyant
Domain Motion
Stationary
Reference Pressure
1.0000e+00 [atm]
Isothermal
Fluid Temperature
2.5000e+01 [C]
Turbulence Model
SST
Scalable
Domain
Boundaries
Boundary - inlet
Type
INLET
Location
IN_1
Settings
Flow Regime
Subsonic
Normal Speed
Normal Speed
1.3000e+02 [m s^-1]
Turbulence
low Intensity = 1%
Boundary - outlet
Type
OUTLET
Location
OUT_1
Settings
Flow Regime
Mass And Momentum
Subsonic
Average Static Pressure
5.0000e-02
Relative Pressure
1.0132e+05 [Pa]
Pressure Averaging
Type
Location
WALL
Airfoil_1, Top_1, Bot _1
Settings
No Slip Wall
Wall Roughness
Smooth Wall
POST PROCESSING
5. Analyze results in CFX POST:
Create plane
Create streamlines
Results:
Aim: To obtain flow field over a 150 Angle wedge length with incoming flow conditions to be
Mach 3, Pressure 1 atm and air at 250c.
Geometry Transform Geomtry Translate/Rotate/Mirror/Scale select Zaxis Select centre of rotation as 2 coordinate Select line Angle 15 0
Apply.
Geometry Create surface Curve driven select driving curve and then the
remaining lines under the driven curve Apply.
From the model tree right click on parts create part Name
Inlet in_1
Outlet out_1
Top top_1
Side Side wall_1
Bottom Bot_1
Wedge Wed_1
Apply
2. Mesh geometry:
Give global mesh parameters in global mesh setup like element scale factor and
element max size = 0.1 height 0.1 height ratio 1.2 display on apply.
3. Export mesh
Output output to cfx save project output type output scale factor - .msh file
created.
4. CFX:
Default Domain Basic Settings Materials Air at 250c, Reference Pressure 0 atm
Domain - Default Domain Modified
Type
Fluid
Location
FLUID
Materials
Material Library
Morphology
Continuous Fluid
Settings
Buoyancy Model
Non Buoyant
Domain Motion
Stationary
Reference Pressure
1.0000e+00 [atm]
Isothermal
Fluid Temperature
2.5000e+01 [C]
Turbulence Model
K- epsilon
Scalable
Domain
Boundaries
Boundary - inlet
Type
INLET
Location
IN_1
Settings
Flow Regime
Supersonic
Normal Speed
Normal Speed
1.04000e+02 [m s^-1]
1 atm
Static temp
300 K
Boundary - outlet
Type
OUTLET
Location
OUT_1
Settings
Flow Regime
8 | Digital Simulation Lab - I
Supersonic
Boundary - WALL
Type
WALL
Location
Top_1, Bot_1, Wed_1
Settings
No Slip Wall
Wall Roughness
Smooth Wall
POST PROCESSING
5. Analyze results in CFX POST:
Create plane
Create streamlines
RESULTS:
Temperature contour
Pressure contour
Aim: To obtain flow field over a flat plate at 0 0 Angle of attack length 10m with incoming flow
conditions to be velocity 30 m/s, Reynolds number 2.5x106 to 3.6 x106 and air at 250c
Join the points 2-3, 3-4, 4-5, 5-6, 6-1, 1-7, 7-8, 8-2, 1-9 by selecting geomtry tab
Create curve from points.
Geometry Create surface Curve driven select driving curve 1-9 and then
the remaining lines under the driven curve Apply.
Geometry Create surface Simple surface Select the lines 5-6 and 3-4
apply.
From the model tree right click on parts create part Name
Inlet in_1
Outlet out_1
Top top_1
Plate flat_ns_1
Bottom back_ns_1 and front _ ns_1
Apply
11 | D i g i t a l S i m u l a t i o n L a b - I
2. Mesh geometry:
Give global mesh parameters in global mesh setup like element scale factor and
element max size = 0.1 display on apply.
3. Export mesh
Output output to cfx save project output type output scale factor - .msh file
created.
4. CFX:
Default Domain Basic Settings Materials Air at 250c, Reference Pressure 1 atm
Domain - Default Domain Modified
Type
Fluid
Location
FLUID
Materials
12 | D i g i t a l S i m u l a t i o n L a b - I
Fluid Definition
Material Library
Morphology
Continuous Fluid
Settings
Buoyancy Model
Non Buoyant
Domain Motion
Stationary
Reference Pressure
1.0000e+00 [atm]
Isothermal
Fluid Temperature
2.5000e+01 [C]
Turbulence Model
SST
Scalable
Domain
Boundaries
Boundary - inlet
Type
INLET
Location
IN_1
Settings
Flow Regime
Subsonic
Normal Speed
Normal Speed
0.3000e+02 [m s^-1]
Turbulence
low Intensity = 1%
Boundary - outlet
Type
OUTLET
Location
OUT_1
Settings
Flow Regime
Mass And Momentum
Pressure Profile Blend
Relative Pressure
13 | D i g i t a l S i m u l a t i o n L a b - I
Subsonic
Average Static Pressure
5.0000e-02
1.0132e+05 [Pa]
Pressure Averaging
Type
Location
WALL
flat_ns_1, back_ns_1 and front _ ns_1
Settings
No Slip Wall
Wall Roughness
Smooth Wall
POST PROCESSING
5. Analyze results in CFX POST:
Create plane
Create streamlines
RESULTS:
14 | D i g i t a l S i m u l a t i o n L a b - I
15 | D i g i t a l S i m u l a t i o n L a b - I
Create the points 1(0,0,0); 2(0,5,0); 3(5,0,0); by selecting geomtry tab Create
point Explicit coordinate method.
Geometry Create curve circle on arc select the center as point 1 select
other two points as 2 and 3 Apply.
Create the point 4(0,0,100); by selecting geomtry tab Create point Explicit
coordinate method.
Join the points 1-4 by selecting geomtry tab Create/modify curve from points
Geometry Create surface Curve driven select driving curve 1-4 and then
the circle lines under the driven curve Apply
From the model tree right click on parts create part Name
Inlet in_1
Outlet out_1
wall wall_1
Apply
16 | D i g i t a l S i m u l a t i o n L a b - I
2. Mesh geometry:
Give global mesh parameters in global mesh setup like element scale factor and
element max size = 1 display on apply.
Create partmesh setup for inlet and outlet element max size = 1 height 0.5
height ratio 1.2, and wall element max size = 0.5.
3. Export mesh
Output output to cfx save project output type output scale factor - .msh file
created.
4. CFX:
Default Domain Basic Settings Materials Air at 250c, Reference Pressure 0 atm
Domain - Default Domain Modified
Type
Fluid
Location
FLUID
Materials
Material Library
Morphology
Continuous Fluid
17 | D i g i t a l S i m u l a t i o n L a b - I
Settings
Buoyancy Model
Non Buoyant
Domain Motion
Stationary
Reference Pressure
1.0000e+00 [atm]
Isothermal
Fluid Temperature
2.5000e+01 [C]
Turbulence Model
K- epsilon
Scalable
Domain
Boundaries
Boundary - inlet
Type
INLET
Location
IN_1
Settings
Flow Regime
Supersonic
Normal Speed
Normal Speed
0.01000 [m s^-1]
1 atm
Static temp
300 K
Boundary - outlet
Type
OUTLET
Location
OUT_1
Settings
Flow Regime
Subsonic
Boundary - WALL
Type
WALL
Location
Top_1, Bot_1, Wed_1
18 | D i g i t a l S i m u l a t i o n L a b - I
Settings
No Slip Wall
Wall Roughness
Smooth Wall
POST PROCESSING
5. Analyze results in CFX POST:
Create plane
Create streamlines
RESULTS:
19 | D i g i t a l S i m u l a t i o n L a b - I
meshed model
velocity contour
Pressure contour
20 | D i g i t a l S i m u l a t i o n L a b - I
Geometry Create curve circle on arc select the center as point 1 select
other two points as 2 and 3 Apply.
Create the point 4(0,0,100); by selecting geomtry tab Create point Explicit
coordinate method.
Join the points 1-4 by selecting geomtry tab Create/modify curve from points
Geometry Create surface Curve driven select driving curve 1-4 and then
the circle lines under the driven curve Apply
From the model tree right click on parts create part Name
Inlet in_1
Outlet out_1
wall wall_1
Cylinder- cyl_1
Apply
2. Mesh geometry:
21 | D i g i t a l S i m u l a t i o n L a b - I
Give global mesh parameters in global mesh setup like element scale factor and
element max size = 10 display on apply.
Create partmesh setup for inlet, outlet and wall element max size = 10 height
0.5 height ratio 1.2, and cylinder element max size = 1.
3. Export mesh
Output output to cfx save project output type output scale factor - .msh file
created.
4. CFX:
Default Domain Basic Settings Materials Air at 250c, Reference Pressure 0 atm
Domain - Default Domain Modified
Type
Fluid
Location
FLUID
Materials
Material Library
Morphology
Continuous Fluid
Settings
Buoyancy Model
Non Buoyant
Domain Motion
Stationary
Reference Pressure
22 | D i g i t a l S i m u l a t i o n L a b - I
1.0000e+00 [atm]
Isothermal
Fluid Temperature
Ideal gas
Turbulence Model
K- epsilon
Scalable
Domain
Boundaries
Boundary - inlet
Type
INLET
Location
IN_1
Settings
Flow Regime
Supersonic
Normal Speed
Normal Speed
34.01000 [m s^-1]
1 atm
Static temp
300 K
Boundary - outlet
Type
OUTLET
Location
OUT_1
Settings
Flow Regime
Subsonic
Type
WALL
Wall_1
Location
Settings
Mass And Momentum
23 | D i g i t a l S i m u l a t i o n L a b - I
free Wall
Wall Roughness
Smooth Wall
Boundary Cyl_1
Type
WALL
Wall_1
Location
Settings
No slipWall
Wall Roughness
Smooth Wall
POST PROCESSING
5. Analyze results in CFX POST:
Create plane
Create streamlines
RESULTS:
24 | D i g i t a l S i m u l a t i o n L a b - I
velocity contour
pressure contour
Aim: Consider the nozzle having a cross sectional area A varies with axial distance from the
throat, according to the formula A = 0.1+X2; where X varies from -0.5<X<0.5. Stagnation
pressure Po = 101325 pa; stagnation temperature To = 300K;
Pre processing:
1. Create geometry in ICEM
Create the vertex data of Nozzle contour variation along axis line with vertices (0.5, 0) and (0.5, 0) and A = 0.1+X2 in excel sheet.
2. Mesh geometry:
Give global mesh parameters in global mesh setup like element scale factor and
element max size.
3. Export mesh
Output output to cfx save project output type output scale factor - .msh file
created.
4. CFX:
26 | D i g i t a l S i m u l a t i o n L a b - I
Fluid
Location
FLUID
Materials
Material Library
Morphology
Continuous Fluid
Settings
Buoyancy Model
Non Buoyant
Domain Motion
Stationary
Reference Pressure
1.0000e+00 [atm]
Isothermal
Fluid Temperature
2.5000e+01 [C]
Turbulence Model
k epsilon
Turbulent Wall
Functions
Scalable
Domain
Default Domain
Modified
Boundaries
Boundary - inlet
Type
INLET
Location
IN
Settings
Flow Regime
Mass And Momentum
Normal Speed
27 | D i g i t a l S i m u l a t i o n L a b - I
Subsonic
Normal Speed
2.8000e+02 [m s^-1]
Turbulence
Type
OUTLET
Location
OUT
Settings
Flow Regime
Mass And Momentum
Subsonic
Average Static Pressure
Pressure Profile
Blend
5.0000e-02
Relative Pressure
Pressure Averaging
1.0132e+05 [Pa]
Average Over Whole Outlet
Boundary - WALL
Type
WALL
Location
Wall
Settings
No Slip Wall
Wall Roughness
Smooth Wall
Advection scheme
Turbulence Numerics
Convergence controls
Convergence criteria
28 | D i g i t a l S i m u l a t i o n L a b - I
POST PROCESSING
6. Analyze results:
Create plane
Create streamlines
29 | D i g i t a l S i m u l a t i o n L a b - I
Pressure contour
d1 = norm([xnod(iv(1))-xnod(iv(3));ynod(iv(1))-ynod(iv(3))]);
d2 = norm([xnod(iv(2))-xnod(iv(4));ynod(iv(2))-ynod(iv(4))]);
if d1 <= d2
nrtri = nrtri+1;
tri(nrtri,:) = iv(ii1);
nrtri = nrtri+1;
tri(nrtri,:) = iv(jj1);
else
nrtri = nrtri+1;
tri(nrtri,:) = iv(ii2);
nrtri = nrtri+1;
tri(nrtri,:) = iv(jj2);
end
end
x=[0:1/(numx):1];
y=[0:1/(numy):1]; %Matlab's meshgrid is used to create 2D grid from specified divisons above
[X,Y] = meshgrid(x,y);
X1=reshape(X',length(x)*length(y),1);
Y1=reshape(Y',length(x)*length(y),1); %Coordinates of the node
node=[X1 Y1]; % Node
tri = triangulate(X1,Y1,element); % element connectivity
nele = size(tri,1);
Z= zeros(length(y)-2,length(x)-2);
nn = tri; % nodes in a long list
xx = X1(nn); yy = Y1(nn); % coordinates corresponding to nodes
xplot = reshape(xx,size(tri));
yplot = reshape(yy,size(tri));figure(1);
clf;
fill(xplot',yplot','w');
31 | D i g i t a l S i m u l a t i o n L a b - I
33 | D i g i t a l S i m u l a t i o n L a b - I
Discussion of Results Enter the number of grid points in the i direction: 50 Enter the number of
grid points in the j direction: 50 Figure shows the algebraic grid generation with the growth rate
=1.05 the grids are very fine at y=0 and it gets coarser as the y increases. The value of growth
rate can be varied and you can see the difference in the growth rate of the grid. 0 0.5 1 1.5 2 2.5
3 0 0.2 0.4 0.6 0.81 1.2 1.4 1.6 1.82 x y Algerbraic Grid.
Burgers Programm
clear all;
34 | D i g i t a l S i m u l a t i o n L a b - I
35 | D i g i t a l S i m u l a t i o n L a b - I
EXPERIMENT 10: Write a Program for Blasius solution for laminar boundary layer over
a flat plate.
% This script animates the solution to the Balsius' model for a boundary
% layer flow over a flat plate. This model assumes steady flow, constant
% density and viscosity. First one must solve the Blasius differential
% equation f'''+0.5*f*f''= 0 with f(0)=0, f'(0)=0 AND f'(infinity)=0 where
% the prime denotes differentiation wuth respect to eta=y*(U*rho/mu)^.5.
clear all
36 | D i g i t a l S i m u l a t i o n L a b - I
set(0,'DefaultAxesFontSize',12);
set(0,'DefaultTextFontSize',12);
eta=linspace(0,10,2001);
deta=.005;
z1=0;
z2=0;
z3=.33193;%input('The second derivative at eta = 0 is');
% Found by trial and error assuming various values until the final
% condition was satisfied.
X=[z1;z2;z3];
for i=1:2000
z1=z1+z2*deta;
z2=z2+z3*deta;
z3=z3-0.5*z1*z3*deta;
X=[X [z1;z2;z3]];
end
figure(1);clf;
subplot(3,1,1)
plot(eta,X(1,:))
xlabel('Variable, \eta')
ylabel('Solution, f(\eta)')
subplot(3,1,2)
plot(eta,X(2,:))
xlabel('Variable, \eta')
ylabel('Solution, df(\eta)/d\eta')
subplot(3,1,3)
plot(eta,X(3,:))
xlabel('Variable, \eta')
ylabel('Solution, d^2f(\eta)/d\eta^2')
F=eta.*X(2,:)-X(1,:);
text(5,1.5,'Press Enter to Continue')
pause
figure(2);clf;
plot(eta,F)
xlabel('Variable, \eta')
ylabel('Solution, \etadf(\eta)/d\eta-f(\eta)')
text(4,.8,'Press Enter to Continue')
pause
y=linspace(0,.003,51);
x=[0 .05 .1 .15 .2 .25 .3 .35 .4 .45 .5]*.1;
figure(3);clf;
axis([0 1 -.0001 .003])
hold on
plot([0 1],[0 0])
hold on
u=zeros(51,11);
eta3=[];
% (U*rho/mu)=1e5:Corresponds to water at 20 C with U=0.1 m/s
for i=2:51 % y loop
for j=2:11 % x loop
eta1=sqrt(1e5/(x(1,j)))*y(1,i);
if y(1,i)==0
fprime=0;
fact=0;
37 | D i g i t a l S i m u l a t i o n L a b - I
else
fprime=interp1(eta,X(2,:),eta1);
fact=interp1(eta,F,eta1);
end
u(i,j)=fprime;
v(i,j)=sqrt(1/(1e5*x(1,j)))*fact;
eta3(i,j)=eta1;
end
end
u(:,1)=ones(51,1);
v(:,1)=zeros(51,1);
v(1,:)=zeros(1,11);
for i=39:51
u(i,2)=1;
end
for j=1:11
plot(u(:,j),y)
hold on
end
text(.8,.6e-3,'x = 0.005');
text(.7,.7e-3,'0.01');
text(.38,1e-3,'0.05');
box on
xlabel('Dimensionless Velocity, u(x,y)/U')
ylabel('Distance Above the Surface, y')
text(0.2,2e-3,['\rhoU/\mu = ' num2str(1e5) ' m^-^1'])
text(.2,2.5e-3,'Press Enter to Continue')
pause
figure(4);clf;
axis([-.01 .06 -.0002 .006])
hold on
patch([0 .005 .062 .06 0],[0 -.0002 -.0002 0 0],'r')
box on
plot([0 .004 .004 0 0],[0 0 3e-3 3e-3 0])
patch([.004 .003 .003 .004],[3e-3 (3e-3)-.0001 (3e-3)+.0001 3e-3],'b')
hold on
for i=2:11
plot(x(1,i)*ones(1,51)+.004*u(:,i)',y(1,:))
xtip=x(1,i)+.004*u(51,i);
ytip=y(1,51);
plot([x(1,i) x(1,i) xtip],[0 ytip ytip])
patch([xtip xtip-.001 xtip-.001 xtip ],[ytip ytip-.0001 ytip+.0001 ytip],'b')
hold on
end
x3=linspace(0,.06,201);
delta3=5*sqrt(x3/1e5);
plot(x3,delta3,'m')
hold on
plot([x3(1,150) .033],[delta3(1,150) 3.5e-3],'m');
text(.004,3.5e-3, 'Boundary Layer Thickness')
xlabel('Distance along the plate x, m')
ylabel('Distance above the plate y, m')
text(-.005,4.8e-3,'U\rho/\mu = 100000 m^-^1, Water at U = 0.1 m/s and 20 C')
text(-.005,5.5e-3,'Horizontal Velocity Profiles vs Distance along the Plate')
38 | D i g i t a l S i m u l a t i o n L a b - I
39 | D i g i t a l S i m u l a t i o n L a b - I
40 | D i g i t a l S i m u l a t i o n L a b - I
41 | D i g i t a l S i m u l a t i o n L a b - I
42 | D i g i t a l S i m u l a t i o n L a b - I
43 | D i g i t a l S i m u l a t i o n L a b - I
44 | D i g i t a l S i m u l a t i o n L a b - I
EXPERIMENT 11: Write a Program Riemann solver for shock tube problem
% Riemann solver for solving shock-tube problem
% 6 possible cases of formation of shock waves and expansionfan have been
% considered including the case of cavitation. The cavitationcheck is
% incorporated in the code. It further prevents plotting formathematically
% possible but physically unlikely case of expansion shocks.
%
clear;
clc;
close all;
% Ratio of specific heats for air
gamma = 1.4;
% Problem definition: Conditions at time t=0
% Case 1 : Sod's Problem
ch=0;
while(ch==0)
fprintf ('Choose one of the following cases :- \n');
fprintf ('\n \t Case 1: Sods problem \n');
fprintf ('\t Case 2: Left running expansion and right running "STRONG" shock \n');
fprintf ('\t Case 3: Left running shock and right running expansion \n');
fprintf ('\t Case 4: Double shock \n');
fprintf ('\t Case 5: Double expansion \n');
fprintf ('\t Case 6: Cavitation \n');
cas=input ('\nEnter a case no. <1-6>: ');
if cas==1
% Case 1:Left Expansion & right Shock
fprintf('Case 1:Sods problem \n');
rho1=1;
rho4=0.125;
u1=0;
u4=0;
p1=1;
p4=0.1;
fprintf ('P1 = %f \n',p1);
fprintf ('P4 = %f \n',p4);
fprintf ('U1 = %f \n',u1);
fprintf ('U4 = %f \n',u4);
fprintf ('rho1 = %f \n',rho1);
fprintf ('rho4 = %f \n',rho4);
ch=1;
elseif cas==2
% Case 2:Strong Expansion & Shock
fprintf('Case 2:Strong Expansion & Shock \n');
rho1=3;
rho4=2;
u1=0;
u4=0;
p1=1000;
p4=0.01;
fprintf ('P1 = %f \n',p1);
fprintf ('P4 = %f \n',p4);
fprintf ('U1 = %f \n',u1);
fprintf ('U4 = %f \n',u4);
fprintf ('rho1 = %f \n',rho1);
fprintf ('rho4 = %f \n',rho4);
ch=1;
45 | D i g i t a l S i m u l a t i o n L a b - I
elseif cas==3
% Case 3:Shock & Expansion
fprintf('Case 3:Shock & Expansion \n');
rho1=1;
rho4=1;
u1=0;
u4=0;
p1=7;
p4=10;
fprintf ('P1 = %f \n',p1);
fprintf ('P4 = %f \n',p4);
fprintf ('U1 = %f \n',u1);
fprintf ('U4 = %f \n',u4);
fprintf ('rho1 = %f \n',rho1);
fprintf ('rho4 = %f \n',rho4);
ch=1;
elseif cas==4
% Case 4:Double Shock
fprintf('Case 4:Double Shock \n');
rho1=6;
rho4=6;
u1=20;
u4=-6;
p1=450;
p4=45;
fprintf ('P1 = %f \n',p1);
fprintf ('P4 = %f \n',p4);
fprintf ('U1 = %f \n',u1);
fprintf ('U4 = %f \n',u4);
fprintf ('rho1 = %f \n',rho1);
fprintf ('rho4 = %f \n',rho4);
ch=1;
elseif cas==5
% Case 5:Double Expansion
fprintf('Case 5:Double Expansion \n');
rho1=1;
rho4=2.5;
u1=-2;
u4=2;
p1=40;
p4=40;
fprintf ('P1 = %f \n',p1);
fprintf ('P4 = %f \n',p4);
fprintf ('U1 = %f \n',u1);
fprintf ('U4 = %f \n',u4);
fprintf ('rho1 = %f \n',rho1);
fprintf ('rho4 = %f \n',rho4);
ch=1;
elseif cas==6
% Case 6:Cavitation
fprintf('Case 6:Cavitation \n');
rho1=1;
rho4=1;
u1=-20;
u4=20;
p1=0.40;
46 | D i g i t a l S i m u l a t i o n L a b - I
p4=0.40;
fprintf ('P1 = %f \n',p1);
fprintf ('P4 = %f \n',p4);
fprintf ('U1 = %f \n',u1);
fprintf ('U4 = %f \n',u4);
fprintf ('rho1 = %f \n',rho1);
fprintf ('rho4 = %f \n',rho4);
ch=1;
else
fprintf ('Please enter an appropriate choice \n');
end % for case selection if-else loop
end % for case selection while loop
% Calculation of flow parameters at initial condition
a1=sqrt(gamma*p1/rho1);
a4=sqrt(gamma*p4/rho4);
M1=u1/a1;
M4=u4/a4;
if u1<0 && u4>0 && (u1+(2/(gamma-1))*a1)<=(u4-(2/(gamma-1))*a4)
%chk for cavitation
fprintf('\n Cavitation is observed in this case of double expansion. No solution possible \n');
break;
else
% Secant Method for getting pressure P*
p23up=(((gamma-1)/2*(u1-u4)+a1+a4)/((a1*(p1)^((2*gamma)/(gamma-1)))+(a4*(p4)^((2*gamma)/(gamma1)))))^((2*gamma)/(gamma-1)); % upper limit
p23down=(rho1*a1*p4+rho4*a4*p1-(rho1*a1*rho4*a4*(u4-u1)))/(rho1*a1+rho4*a4); %lower limit by linear
theory
s=0;
if p23down>=p1
s=1;
end
ss=0;
if p23down>=p4
ss=1;
end
if s==1
m1=rho1*a1*sqrt(1+((gamma+1)*(p23up-p1)/(2*gamma*p1)));
m1d=rho1*a1*sqrt(1+((gamma+1)*(p23downp1)/(2*gamma*p1)));
else
m1=rho1*a1*(gamma-1)/(2*gamma)*(1-p23up/p1)/(1-(p23up/p1)^((gamma-1)/(2*gamma)));
m1d=rho1*a1*(gamma-1)/(2*gamma)*(1-p23down/p1)/(1-(p23down/p1)^((gamma-1)/(2*gamma)));
end
if ss==1
m4=rho4*a4*sqrt(1+((gamma+1)*(p23up-p4)/(2*gamma*p4)));
m4d=rho4*a4*sqrt(1+((gamma+1)*(p23down-p4)/(2*gamma*p4)));
else
m4=rho4*a4*(gamma-1)/(2*gamma)*(1-p23up/p4)/(1-(p23up/p4)^((gamma-1)/(2*gamma)));
m4d=rho4*a4*(gamma-1)/(2*gamma)*(1-p23down/p4)/(1-(p23down/p4)^((gamma-1)/(2*gamma)));
end
p23=(m1*p4+m4*p1-m1*m4*(u4-u1))/(m1+m4);
f=p23up-p23;
p23d=(m1d*p4+m4d*p1-m1d*m4d*(u4-u1))/(m1d+m4d);
ff=p23d-p23;
j=0;
% iteration procedure starts from here
while abs(f)>0.000001
47 | D i g i t a l S i m u l a t i o n L a b - I
p23up=p23up-(f*(p23up-p23d)/(f-ff));
if s==1
m1=rho1*a1*sqrt(1+((gamma+1)*(p23upp1)/(2*gamma*p1)));
m1d=rho1*a1*sqrt(1+((gamma+1)*(p23downp1)/(2*gamma*p1)));
else
m1=rho1*a1*(gamma-1)/(2*gamma)*(1-p23up/p1)/(1-(p23up/p1)^((gamma-1)/(2*gamma)));
m1d=rho1*a1*(gamma-1)/(2*gamma)*(1-p23down/p1)/(1-(p23down/p1)^((gamma-1)/(2*gamma)));
end
if ss==1
m4=rho4*a4*sqrt(1+((gamma+1)*(p23up-p4)/(2*gamma*p4)));
m4d=rho4*a4*sqrt(1+((gamma+1)*(p23down-p4)/(2*gamma*p4)));
else
m4=rho4*a4*(gamma-1)/(2*gamma)*(1-p23up/p4)/(1-(p23up/p4)^((gamma-1)/(2*gamma)));
m4d=rho4*a4*(gamma-1)/(2*gamma)*(1-p23down/p4)/(1-(p23down/p4)^((gamma-1)/(2*gamma)));
end
p23=(m1*p4+m4*p1-m1*m4*(u4-u1))/(m1+m4);
f=p23up-p23;
p23d=(m1d*p4+m4d*p1-m1d*m4d*(u4-u1))/(m1d+m4d);
ff=p23d-p23;
j=j+1;
if j>450000;
fprintf ('No convergance \n');
break;
end
end % for while loop of secant method
% Root finder ends
%Calculation of flow parameters depending whether shock oran
%expansion is observed
u23=(m1*u1+m4*u4-(p4-p1))/(m1+m4);
if s==1
rho2=rho1*(1+(((gamma+1)/(gamma-1))*p23/p1))/(((gamma+1)/(gamma-1))+p23/p1);
if u23>u1
fprintf('Expansion shock-not physically possible\n');
return;
end
else
rho2=rho1*(p23/p1)^(1/gamma);
end
if ss==1
rho3=rho4*(1+(((gamma+1)/(gamma-1))*p23/p4))/(((gamma+1)/(gamma-1))+p23/p4);
if u23<u4
fprintf('Expansion shock-not physically possible\n');
return;
end
else
rho3=rho4*(p23/p4)^(1/gamma);
end
a2=sqrt(gamma*p23/rho2);
a3=sqrt(gamma*p23/rho3);
end % for cavitation test
% Print calculated flow quantities
fprintf ('\n Solution of Riemann problem :- \n');
fprintf ('P* = %f \n',p23);
fprintf ('U* = %f \n',u23);
fprintf ('rho2 = %f \n',rho2);
fprintf ('rho3 = %f \n',rho3);
48 | D i g i t a l S i m u l a t i o n L a b - I
% Variable initialization
cs12=0;
cs34=0;
expc121=0;
expc122=0;
expc341=0;
expc342=0;
% Calculation of shock/expansion speeds
if s==1
cs12l=a1*sqrt(1+(gamma+1)/(2*gamma)*(p23-p1)/p1);
cs12=u1-abs(cs12l);
else
expc121=u1-a1;
expc122=u23-a2;
end
if ss==1
cs34r=a4*sqrt(1+(gamma+1)/(2*gamma)*(p23-p4)/p4);
cs34=u4+abs(cs34r);
else
expc341=u4+a4;
expc342=u23+a3;
end
%Array construction
maxxt=max([cs12 cs34 expc121 expc122 expc341 expc342]);
minxt=min([cs12 cs34 expc121 expc122 expc341 expc342]);
offsetxt=0.1*(maxxt-minxt);
if s==1
xt(1)=cs12-offsetxt;
incr=abs(offsetxt)/1500;
for i=1:1500
xt(i+1)=xt(i)+incr;
u(i)=u1;
rho(i)=rho1;
p(i)=p1;
e(i)=p(i)/(gamma-1)/rho(i);
end
xt(1500)=cs12;
incr=abs(u23-cs12)/1500;
for i=1501:3000
xt(i+1)=xt(i)+incr;
u(i)=u23;
rho(i)=rho2;
p(i)=p23;
e(i)=p(i)/(gamma-1)/rho(i);
end
xt(3000)=u23;
else
xt(1)=expc121-offsetxt;
incr=abs(offsetxt)/1000;
for i=1:1000
xt(i+1)=xt(i)+incr;
u(i)=u1;
rho(i)=rho1;
p(i)=p1;
e(i)=p(i)/(gamma-1)/rho(i);
end
49 | D i g i t a l S i m u l a t i o n L a b - I
xt(1000)=expc121;
incr=abs(expc122-expc121)/1000;
for i=1001:2000
xt(i+1)=xt(i)+incr;
if expc122>=0
u(i)=2/(gamma+1)*(xt(i)-a1)+(gamma-1)/(gamma+1)*u1;
a=((gamma-1)/(gamma+1)*(xt(i)-u1))+(2/(gamma+1)*a1);
else
u(i)=2/(gamma+1)*(xt(i)+a1)+(gamma-1)/(gamma+1)*u1;
a=(-(gamma-1)/(gamma+1)*(xt(i)-u1))+(2/(gamma+1)*a1);
end
rho(i)=rho1*(a/a1)^(2/(gamma-1));
p(i)=p1*(a/a1)^(2*gamma/(gamma-1));
e(i)=p(i)/(gamma-1)/rho(i);
end
xt(2000)=expc122;
incr=abs(expc122-u23)/1000;
for i=2001:3000
xt(i+1)=xt(i)+incr;
u(i)=u23;
rho(i)=rho2;
p(i)=p23;
e(i)=p(i)/(gamma-1)/rho(i);
end
xt(3000)=u23;
end
if ss==1
incr=abs(u23-cs34)/1500;
for i=3001:4500
xt(i)=xt(i-1)+incr;
u(i)=u23;
rho(i)=rho3;
p(i)=p23;
e(i)=p(i)/(gamma-1)/rho(i);
end
xt(4500)=cs34;
incr=abs(offsetxt)/1500;
for i=4501:6000
xt(i)=xt(i-1)+incr;
u(i)=u4;
rho(i)=rho4;
p(i)=p4;
e(i)=p(i)/(gamma-1)/rho(i);
end
else
incr=abs(expc342-u23)/1000;
for i=3001:4000
xt(i)=xt(i-1)+incr;
u(i)=u23;
rho(i)=rho3;
p(i)=p23;
e(i)=p(i)/(gamma-1)/rho(i);
end
xt(4000)=expc342;
incr=abs(expc342-expc341)/1000;
for i=4001:5000
50 | D i g i t a l S i m u l a t i o n L a b - I
xt(i)=xt(i-1)+incr;
if expc341>=0
u(i)=2/(gamma+1)*(xt(i)-a4)+(gamma-1)/(gamma+1)*u4;
a=((gamma-1)/(gamma+1)*(xt(i)-u4))+(2/(gamma+1)*a4);
else
u(i)=2/(gamma+1)*(xt(i)+a4)+(gamma-1)/(gamma+1)*u4;
a=(-(gamma-1)/(gamma+1)*(xt(i)-u4))+(2/(gamma+1)*a4);
end
rho(i)=rho4*(a/a4)^(2/(gamma-1));
p(i)=p4*(a/a4)^(2*gamma/(gamma-1));
e(i)=p(i)/(gamma-1)/rho(i);
end
xt(5000)=expc341;
incr=abs(offsetxt)/1000;
for i=5001:6000
xt(i)=xt(i-1)+incr;
u(i)=u4;
rho(i)=rho4;
p(i)=p4;
e(i)=p(i)/(gamma-1)/rho(i);
end
end
% Plotting instructions
subplot (2,2,1)
plot(xt,u);
title('Plot of U v/s x/t');
xlabel ('x/t');
ylabel ('u');
axis tight;
subplot (2,2,2)
plot(xt,rho);
rho1 = 1.000000
rho4 = 2.500000
Solution of Riemann problem :P* = 24.897610
U* = 0.450296
rho2 = 0.712733
rho3 = 1.781833
54 | D i g i t a l S i m u l a t i o n L a b - I