1d supersonic nozzle flow for conservative and non conservative form
OBJECTIVE : - 1). Implementing conservative and non conservative form on 1D quasi supersonic nozzle flow
2). Performing grid dependence test on the both form.
1).Conservative form :-
1).In conservative form properties are conserved and formed based on the conservative variable.
2).Conservative equation are applicable to the stationary system either fixed control volume fixed in space or infinitesimally small element fixed in space
3).In conservative form rho is always inside the equation.
2). Non conservative form:-
1).In non conservative equations applicable to Finite control with volume fixed mass moving with flow or infinitesimally small fluid element of fixed mass (fluid particle) moving with the flow.
2).That is why total derivative is used in non-conservative equations.
To solve problems we are using macormack technique.
- Macormack consist of two part.
1). Predictor step
2). Corrector step - The MacCormack method is a variation of the two-step Lax–Wendroff scheme but is much simpler in application. To illustrate the algorithm, consider the following first order hyperbolic equation
1) Non- conservative form - applying macormack techniques to continuity 1-D equation in non conservative form.
Contiuity equation given by :-
`(delu)/(delt) = rho*(delu)/(delx) + u*(delrho)/(delx)`
1) predictor step :
Provide spatial derivative with forward difference on the right hand side
`((delu)/(delt))^t(i)^= (rho^t(i)*((u(i+1)-u(i))/(Deltax)) + u^t(i)*(rho(i+1)-rho(i))/(Deltax)) ------2`
From Taylor series rho(t+dt) given by.
`bar(rho) (i)^(t+Deltat) = rho(i)+ ((delu)/(delt))^t(i) * Deltat ----3`
Where rho(i) and ((delu)/(delt)) is known from equation 2)
2) Corrector step:
In corrector step value obtain at (t+Deltat) in predictor step use in right side of continuity equation with backward step.
`bar((delu)/(delt))^(t+Deltat)(i)= (barrho^(t+Deltat)(i)*(baru^(t+Deltat)(i)-(baru)^(t+Deltat)(i-1))/(Deltax)) + (baru^(t+Deltat)(i)*(barrho^(t+Deltat)(i)- (barrho)^(t+Deltat)(i-1))/(Deltax))` ------4
Avarege value is obtained by arithmetic means value from equation. 3 and 4
`((delu)/(delt))(avg)=0.5(((delu) /(delt) ) ^t(i) + (bar(delu) /(delt) ) ^(t+Deltat)(i) )-------------------5`
Final value at`t + Deltat` given by.
`rho^(t+Deltat)(i) = rho^t(i )+((delu)/(delt))(avg)*(Deltat)-----------6`
equation 6 is the final value computed at `t+Deltat`.
- GOVERNING EQUATION FOR NON - CONSERVATIVE FORM GIVEN BY:
1).Continuity equation :
`(del(rho*A))/(delt) + rho*del((A*V))/(delx) +A*del((rho*V))/(delx)+V*del((rho*A))/(delx)=0-------------------------(1)`
2). Momentum equation :
`rho*(delv)/(delt) + rho*v*(del(rho*v))/(delx) = -R( (T*(delrho)/(delx)) + (rho*(delT)/(delx)))`---------------------------(2)`
3). Energy eqaution :
`rho*Cv (delT)/(delt) + rho*Cv*v * (delT)/(delx) = -rho*R*Cv * (((delv)/(delx) + v*(del(lnA)/(delx)))`---------------(3)
- above equation 1 to 3 in the form dimensional number
- in C.F.D we are using non dimensional number which has advantages of presenting final results , in which (p/po) & (T/To) values varies between 0 to 1.
- non dimension number noted by `dotrho =rho/(rhoo) and dotT = T/(To) and dotV = v/(vo) , dotx=x/L , dotA = A/Ao` and mutiplying with above equation according to dimension both right and left hand side final equation given as below with non- dimensional no.
`(del(dotrho))/(del(dott)) = -dotrho*(del(dotv))/(del(dotx)) - dotrho*dotv*del((lndotA))/(deldotx)-dotv*(del(dotp))/(deldotx)-----------(4-n)`
`(deldotv)/(deldott) = - dotv*(deldotv)/(deldotx) -(1/gamma)*(((deldotT)/(deldotx))+ (dotT/dotrho)*((deldotp)/(deldotx)))`------------(5-n)`
`(deldotT)/(deldott) = - dotv*(deldotT)/(deldotx) -(gamma-1)*dotT(((deldotv)/(deldotx))+ (dotv)*((deltlndotA)/(deldotx)))`------------(6-n)`
- GOVERNING EQUATION FOR CONSERVATIVE FORM GIVEN BY WITH NON -DIMENSIONAL NUMBR GIVEN BY :
`(del(dotrho*dotA))/(deldott) +( del((dotrho*dotA*dotV)))/(deldotx)=0`-------(7-c`
`( del((dotrho*dotA*dotV)))/(deldott) + ( del((dotrho*dotA*dotV^2)+ (1/gamma)*dotp*dotA))/(deldott) = (1/gamma)*dotp*(deldotA)/(deldotx)`------(8-c`
`(del((dotrho*dotA*((dote/(gamma-1))+(gamma/2)*dotv^2))))/(deldott) + (del((dotrho*dotA*dotv((dote/(gamma-1))+(gamma/2)*dotv^2))+dotrho*dotA*dotv))/(deldotx) = 0`-------------------(9-c`
- lets define above above equation isn solution vector U , Flux vector in F and fixed term J
- `U1=dotrho*dotA`
- `U2=dotrho*dotA*dotv`
- `U3=((dotrho*dotA*((dote/(gamma-1))+(gamma/2)*dotv^2))))`
- `F1=dotrho*dotA*dotv`
- `F2 = ((dotrho*dotA*dotV^2)+ (1/gamma)*dotp*dotA))`
- `F3=((dotrho*dotA*dotv((dote/(gamma-1))+(gamma/2)*dotv^2))+dotrho*dotA*dotv))`
- `J2=(1/gamma)*dotp*(deldotA)/(deldotx)`
- with above element equation (7-c &8-c& 9-c) wriiten as below
- `(delU1)/(deldott) =- (delF1)/(deldotx)`-------------(10)
- `(delU2)/(deldott) =- (delF2)/(deldotx) + J2`--------(11)
- `(delU3)/(deldott) =- (delF3)/(deldotx)`---------------(12)
- ON ABOVE EQUATION WE WILL APPLY MACCORMACK TECHNIQUE TO SOLVE PROBLEM :
- TO OBTAIN PREMETIV VARIBLE WE DECODE VARIABLE U1,U2,U3 AND ONCE WE GOT WE WILL USE VALUE OF U1,U2,U3 TO FIND OUT rho,v,T,p after each time step
- `dotrho = U1/dotA`
- `dotv =(U2)/(U1)`
- `dotT=dote=(gamma-1) ((U3)/(U1) -(gamma)*0.5*dotv^2)`
- `dotp=dotrho*dotT`
- PURE FORM OF FLUX TERM :
- `F1=U2`
- `F2=((U2^2)/(U1) + (gamma-1)/(gamma)*(U3-0.5*gamma*((U2^2)/(U1)))`
- `F3 =(gamma*U2*U3)/(U1) - (gamma/2*(gamma-1)*(U2^3)/(U1^2))`
- `J2=(gamma-1)/(gamma)*(U3-0.5*gamma*((U2^2)/(U1)))*(del(lndotA))/(deldotx)`
- ABOVE VALUE OF F1,F2,F3 AND J2 ARE PUT IN EQUATION 10,11,12.
CASE SETUP FOR NON-CONSERVATIVE FORM :
- WE GOT GOVERNING EQUATION SHOWN ABOVE (4-n & 5-n & 6-n) WE WILL APPLY MACORMACK TECHNIQUES ON THOSE EQUATION .
- CALCULATION OF TIME STEP :
- `DeltaT= C*(Deltax)/(a+v)` equation is used for calculating time at every node point out minimum value is choosed for DeltaT
- where C= courant no. , a= speed of sound in medium & v= speed of propogating flow
- `DeltaT = min(T^t(1) + T^t(2) +(T^t(3).....)
3. BOUNDARY CONDITION :
1)Inlet boundary :
- `v(1)= 2*v(2)- v(3)` using linear extrapolation at point 1 & 2 & 3
2) Outlet boundary :
- `v(n)= 2*v(n-1) - v(n-2)`)
- `rho(n)= 2*rho(n-1)- rho(n-2)`)
- `T(n)= 2*T(n-1) - T(n-2)`)
4. INITIAL CONDITION :
-
A=1+2.2*(`dotx`-1.5).^(2)
-
rho=1-0.3146*`dotx`
-
T = 1-0.231*`dotx`
-
v=(0.1+1.09*`dotx`).*T.^(1/2)
CASE SETUP FOR CONSERVATIVE FORM :
- WE GOT GOVERNING EQUATION SHOWN ABOVE (10 ,11,12) WE WILL APPLY MACORMACK TECHNIQUES ON THOSE EQUATION .
- CALCULATION OF TIME STEP :
- `DeltaT= C*(Deltax)/(a+v)` equation is used for calculating time at every node point out minimum value is choosed for DeltaT
- where C= courant no. , a= speed of sound in medium & v= speed of propogating flow
- `DeltaT = min(T^t(1) + T^t(2) +(T^t(3).....)
3. BOUNDARY CONDITION :
Inlet
U1(1) = rho(1)*a(1)
U2(1) = 2*U2(2)-U2(3)
U3(1) = U1(1)*((T(1)/(gamma-1))+(0.5*gamma*(v(1).^2)))
Outlet
U1(n) = 2*U1(n-1)-U1(n-2);
U2(n) = 2*U2(n-1)-U2(n-2);
U3(n) = 2*U3(n-1)-U3(n-2);
4. INITIAL CONDITION :
- A=1+2.2*(`dotx`-1.5).^(2)
for (0<`dotx`< 0.5)
`dotrho`=1
`dotT`=1
for(0.5 <=`dotx`<= 1.5)
`dotrho`=1-(0.366*(x-0.5))
`dotT` = 1-0.167*(x-0.5)
for(1.5 <=`dotx`<= 3.5)
`dotrho`=0.634-(0.3879*(x-1.5))
`dotT`= 0.833-(0.3507*(x-1.5))
3). `dotv= 0.59/(dotrho*dotA)`
CODE 1-D SUPERSONIC NON CONSERVATIVE FORM :
close all
clear all
clc
n=31;
gamma=1.4;
x =linspace(0,3,n);
dx=x(2)-x(1);
a=1+2.2*(x-1.5).^(2);
th=find(a==1);
rho=1-0.3146*x;
T = 1-0.231*x;
v=(0.1+1.09*x).*T.^(1/2);
p=rho.*T;
%plot(x,a)
c=0.5
nt=1000;
for k=1:nt;
dt = min(c*(dx./(sqrt(T)+v)));
rho_old =rho;
v_old=v;
T_old=T;
% predctor method
for i=2:n-1;
% continuity equation
dv_dx = (v(i+1)-v(i))/dx;
dlog_a_dx =(log(a(i+1))-log(a(i)))/dx;
drho_dx = (rho(i+1)-rho(i))/dx;
dT_dx= (T(i+1)-T(i)) /dx;
drho_dt_p(i) = -rho(i)*(dv_dx) - rho(i)*v(i)*(dlog_a_dx) - v(i)*(drho_dx);
dv_dt_p(i) = -v(i)*(dv_dx)-(1/gamma)*((dT_dx)+(T(i)/rho(i))*drho_dx);
dT_dt_p(i) = -v(i)*(dT_dx) - (gamma-1)*T(i)*(dv_dx +v(i)*dlog_a_dx);
rho(i)=rho(i)+drho_dt_p(i)*(dt);
v(i)=v(i)+dv_dt_p(i)*(dt);
T(i)=T(i)+dT_dt_p(i)*(dt);
end
%CORRECTOR METHOD
for j =2:n-1
dv_dx = (v(j)-v(j-1))/dx;
dlog_a_dx =(log(a(j))-log(a(j-1)))/dx;
drho_dx = (rho(j)-rho(j-1))/dx;
dT_dx= (T(j)-T(j-1)) /dx;
drho_dt_c(j) = -rho(j).*(dv_dx) - rho(j)*v(j)*(dlog_a_dx) - v(j)*(drho_dx);
dv_dt_c(j) = -v(j)*dv_dx - (1/gamma)*(dT_dx + (T(j)/rho(j))*drho_dx);
dT_dt_c(j) = -v(j)*dT_dx - (gamma-1)*T(j)*(dv_dx +v(j)*dlog_a_dx);
end
drho_dt=0.5*(drho_dt_c + drho_dt_p);
dv_dt=0.5*(dv_dt_c + dv_dt_p);
dT_dt=0.5*(dT_dt_c + dT_dt_p);
for i=2:n-1
rho(i)=rho_old(i)+drho_dt(i)*dt;
v(i)=v_old(i)+dv_dt(i)*dt;
T(i)=T_old(i)+dT_dt(i)*dt;
end
%boundary condition
%inlet
v(1) =2*v(2)-v(3);
%outlet
rho(n) =2*rho(n-1)-rho(n-2);
v(n) =2*v(n-1)-v(n-2);
T(n) =2*T(n-1)-T(n-2);
M =v./ sqrt(T);
p=rho.*T;
mass =rho.*v.*a;
M_throat(k) = M(th);
p_throat(k) = p(th);
T_throat(k) = T(th);
rho_throat(k) = rho(th);
plot_nonconservative_diferent_time(x,k,mass)
end
% plot_nonconservative_diferent_time(x,k,mass)
figure(1)
hold on
plot(T_throat,\'b\')
plot(p_throat,\'g\')
plot(rho_throat,\'magenta\')
plot(M_throat,\'black\')
legend(\'T throat\',\'p throat\',\'rho throat\',\'M throat\')
xlabel(\'no. of iteration\');
title(sprintf(\'Variaation of properties at throat section \\n NON CORSERVATIVE FORM\'))
figure(2)
subplot(4,1,1)
plot(x,M)
ylabel(\'M--->\')
title(sprintf(\'ONE DIMENSIONAL SUPERSONIC NOZZLE FLOW \\n (NON CONSERVATION FORM) \\n NO. OF TIME STEP=%d\',k))
subplot(4,1,2)
plot(x,T)
% xlabel(\'LENGTH--->\')
ylabel(\'Temprature ratio--->\')
subplot(4,1,3)
plot(x,rho)
% xlabel(\'NON DIMENSIONAL LENGTH-->\')
ylabel(\'Density ratio-->\')
subplot(4,1,4)
plot(x,p)
xlabel(\'NON DIMENSIONAL LENGTH-->\')
ylabel(\'pressure ratio-->\')
pause(0.03)
-code for function plot_ nonconservative_different_time
function[] = plot_nonconservative_diferent_time(x,k,mass)
figure(3)
grid on
if k==1
plot(x,mass,\'magenta\')
hold on
elseif k==100
plot(x,mass,\'b\')
elseif(k==300)
plot(x,mass,\'cyan\')
elseif(k==500)
plot(x,mass,\'g\')
elseif(k==700)
plot(x,mass,\'y\')
elseif(k==850)
plot(x,mass,\'r\')
elseif(k==1000)
plot(x,mass,\'black\')
legend(\'k=1\',\'k=100\',\'k=300\',\'k=500\',\'k=700\',\'k=850\',\'k=1000\')
xlabel(\'non dimensional length\')
ylabel(\'non dimensional mass flow rate\')
title(\'Variation in mass flow rate at diffetent time step ( NON CONSERVATIVE FORM)\')
end
end
OUTPUT:-
CODE 1-D SUPERSONIC CONSERVATIVE FORM :
close all
clear all
clc
n=31;
x=linspace(0,3,n);
dx=x(2)-x(1);
a= 1+2.2*(x-1.5).^(2);
th= find(a==1);
for i=1:n
if (0<= x(i))&&(x(i)<= 0.5)
rho(i)=1;
T(i)=1;
elseif (0.5 < x(i))&&(x(i)<= 1.5)
rho(i)=1-(0.366*(x(i)-0.5));
T(i) = 1-0.167*(x(i)-0.5);
else
rho(i) =0.634-(0.3879*(x(i)-1.5));
T(i) = 0.833-(0.3507*(x(i)-1.5));
end
end
u1=rho.*a;
% u2=0.590
gamma=1.4;
v=0.590./(u1);
u2=u1.*v;
u3=u1.*((T/(gamma-1)+ (0.5*gamma*v.^2)));
c=0.5;
for t=1:1500
dt = min(c*(dx./(sqrt(T)+v)));
u1_old=u1;
u2_old=u2;
u3_old=u3;
%Flux variables for predictor step
f1 = u2;
f2 = ((u2.^2)./u1) + (((gamma-1)/gamma)*(u3 - ((gamma*0.5*(u2.^2))./u1)));
f3 = ((gamma*u2.*u3)./u1) - ((gamma*0.5*(gamma-1)*(u2.^3))./(u1.^2));
%Predictor step
for i=2:n-1
a_dx=(a(i+1)-a(i))/dx;
j2(i)=(rho(i).*T(i).*a_dx)/gamma;
du1_dt_p(i)= -(f1(i+1)-f1(i))/dx;
du2_dt_p(i)= -(f2(i+1)-f2(i))/dx + j2(i);
du3_dt_p(i) = -(f3(i+1)-f3(i))/dx;
u1(i) = u1_old(i) + du1_dt_p(i)*dt;
u2(i) = u2_old(i) + du2_dt_p(i)*dt;
u3(i) = u3_old(i) + du3_dt_p(i)*dt;
%find premitive variable for corrector term
rho(i)=u1(i)./a(i);
v(i)=u2(i)./u1(i);
T(i) = (gamma-1)*((u3(i)./u1(i))-(0.5*gamma)*(v(i)^2));
end
%Updated Flux variables for corrector step
f1 = u2;
f2 = ((u2.^2)./u1) + (((gamma-1)/gamma)*(u3 - ((gamma*0.5*(u2.^2))./u1)));
f3 = ((gamma*u2.*u3)./u1) - ((gamma*0.5*(gamma-1)*(u2.^3))./(u1.^2));
%Corrector step
for i=2:n-1
a_dx=(a(i)-a(i-1))/dx;
j2(i)=(rho(i).*T(i).*a_dx)/gamma;
du1_dt_c(i)= -(f1(i)-f1(i-1))/dx;
du2_dt_c(i)= -(f2(i)-f2(i-1))/dx + j2(i);
du3_dt_c(i) = -(f3(i)-f3(i-1))/dx;
end
% Average values
du1_dt =0.5*((du1_dt_p) + (du1_dt_c));
du2_dt =0.5*((du2_dt_p) + (du2_dt_c)) ;
du3_dt =0.5*((du3_dt_p) + (du3_dt_c));
for i =2:n-1
u1(i)= u1_old(i) + du1_dt(i)*dt;
u2(i)= u2_old(i) + du2_dt(i)*dt;
u3(i)= u3_old(i) + du3_dt(i)*dt;
end
%Final update of primitive variables
rho = u1./a;
v = u2./u1;
T = (gamma-1)*((u3./u1)-((0.5*gamma)*(v.^2)));
%Boundary conditions
%Inlet
u1(1) = rho(1)*a(1);
u2(1) = 2*u2(2)-u2(3);
u3(1) = u1(1)*((T(1)/(gamma-1))+(0.5*gamma*(v(1).^2)));
%Outlet
u1(n) = 2*u1(n-1)-u1(n-2);
u2(n) = 2*u2(n-1)-u2(n-2);
u3(n) = 2*u3(n-1)-u3(n-2);
p = rho.*T;
mass= rho.*v.*a;
M = v./(sqrt(T));
%CALCUTING PROPERTIES AT THROAT SECTION
T_throat(t) = T(th);
M_throat(t)=M(th);
rho_throat(t)=rho(th);
v_throat=v(th);
mass_throat = rho_throat.*v_throat.*a(th);
p_throat=rho_throat.*T_throat;
plot_conservative_diff_time(mass,x,t)
figure(1)
end
plot_conservative_throat(T_throat,M_throat,rho_throat,p_throat)
plot_conservation(x,M,T,rho,p,t)
Code for function plot_conservative_diff_time
function[] = plot_conservative_diff_time(mass,x,t)
figure(1)
if t==1
plot(x,mass,\'r\')
hold on
elseif t==100
plot(x,mass,\'b\')
elseif(t==300)
plot(x,mass)
elseif(t==500)
plot(x,mass,\'g\')
elseif(t==700)
plot(x,mass,\'y\')
elseif(t==1000)
plot(x,mass,\'black\')
elseif(t==1400)
plot(x,mass,\'magenta\')
legend(\'t=1\',\'t=100\',\'t=300\',\'t=500\',\'t=700\',\'t=1000\',\'t=1400\')
xlabel(\'non dimensional length\')
ylabel(\'non dimensional mass flow rate\')
title(\'Variation in mass flow rate at diffetent time step ( CONSERVATIVE FORM)\')
end
end
Code for function plot_conservative_throat
function[] = plot_conservative_throat(T_throat,M_throat,rho_throat,p_throat)
figure(2)
plot(T_throat,\'g\')
hold on
plot(M_throat,\'r\')
plot(rho_throat,\'b\')
plot(p_throat,\'m\')
legend(\'T throat\',\'M throat\',\'rho throat\',\'p throat\')
xlabel(\'no. of iteration\')
title(sprintf(\'Variation of properties according to iteration at throat position \\n CONSERVATIVE FORM\'))
end
Code for function plot_conservation
function[] = plot_conservation(x,M,T,rho,p,t)
grid on
figure(3)
subplot(4,1,1)
plot(x,M)
ylabel(\'M--->\')
title(sprintf(\'ONE DIMENSIONAL SUPERSONIC NOZZLE FLOW \\n ( CONSERVATION FORM) \\n NO. OF TIME STEP=%d\',t))
subplot(4,1,2)
plot(x,T)
% xlabel(\'LENGTH--->\')
ylabel(\'Temprature ratio--->\')
subplot(4,1,3)
plot(x,rho)
% xlabel(\'NON DIMENSIONAL LENGTH-->\')
ylabel(\'Density ratio-->\')
subplot(4,1,4)
plot(x,p)
%xlabel(\'NON DIMENSIONAL LENGTH-->\')
ylabel(\'pressure ratio-->\')
pause(0.03)
end
OUTPUT:-
1). MATTER OF GRID INDEPENDENCE TEST : IN GRID INDEPENDENCE TEST WE INCREASE VALUE OF GRID POINT FROM N TO 2N , 3N AND OBSERVATION CAN BE SHOWN AS BELOW :
1) FOR GRID POINT =31
-
NON CONSERVATION YELLOW & RED LINE OVERLAPPING BETWEEN HENCE SOLUTION CONVEGRES AT 700 &850 WHILE IN CONSEVATION = BLCK& PINK LINE OVERLAPPING NEAR ABOUT BETWEEN 1000 &1100.
2). FOR GRID POINT = 62
- .
-
NON CONSERVATION HENCE SOLUTION CONVEGRES AT BETWEEN 1300 & 1400 WHILE IN CONSERVATION FORM ITS TAKES MORE THAN 1400 SOLUTION TO CONVERGES.
-
GRID INDEPENDENCE ACHIEVED AT 124 GRID POINT , IT,S EFFECT OF UNCHANGED RESULT EVEN AFTER WE INCREASE THE N. OF GRID POINTS.
- COMPARISION OF RESULTS OF MASS FLOW RATE AT THROAT SECTION FOR CONSERVATIVE PART AND NON CONSERVATIVE :
at i=16 (throat section )
NON CONSERVATIVE (mass)= 0.5838
CONSERVATIVE (mass) = 0.5852
EXACT SOLUTION (mass) = 0.579
CONCLUSION :
- NON CONSERVATION FORM YEILDS FASTER RESULTS COMPARED TO CONSERVATION FORM AND ITS TAKE LESS NO. OF ITERATION.
- ACCURACY OF SOLUTION IS INCREASE AS WE INCRESE NO. OF GRID POINT
- CONSERVATION FORM FORMULATION CONTAINED MORE COMPLEXITY COMPARED TO NON CONSERVATION HENCE NON CONSERVATION FORM IS EASY TO CODDED AND TAKES LESS NO. OF ITERATION.
- FOR SAME NO. OF GRID POINTS NON CONSERVATIVE GIVES FASTER RESULTS THAN CONSERVATIVE PART.
- FOR SAME NO. OF GRID POINT VALUE FOR CONSERVATIVE PART IS VERY NEARER TO EXACT SOLUTION ALTHOUGH ITS NOT SAME .