1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 57

//******************_________________________________________******************

//****************** ******************

//******************`````````````````````````````````````````******************

//******************# FLOW COMPUTATION IN REGULAR GEOMETRY #******************

//******************~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~******************

//******************_________________________________________******************

//******************# QUICK SCHEME #******************

/* this program is developed to solve lid driven cavity problem using central

deference scheme for border control volumes and deferred QUICK scheme in the

internal control volumes. u & v momentum equations are converged in

separate while loop.*/

//***************************#### CODE STARTS ####*****************************

// Library file access

#include<math.h>

#include<stdio.h>

#include<stdlib.h>

#include<iostream>

#include<fstream>

#include<string>

//*************************#### CLASS "simple" ####**************************

class simple

{
private:

double **u,**v,**T,**u_prev,**v_prev,**uface,**vface,**T_prev,**p,**p_dash,

**a_E,**a_W,**a_N,**a_S,**a_0,**a_P,**Co,**C_prev,

**b_E,**b_W,**b_N,**b_S,**b_P,**b_EE,**b_WW,**b_NN,**b_SS,**shi,**omega,dx,dy,x_l,y_l;

double **bc;

double *x,*y,*x_at_f,*y_at_f,*A,*B,*C,*D,*P,*Q;

double F_e,F_w,F_n,F_s,D_e,D_w,D_n,D_s;

double dt,theta,alfa_p,error_u,error_v,error_T,error_bm,error_b,

ru_k,rv_k,rp_k,rT_k,gamma_p;

double Pr,Ri,GrT,Re,Le,Sc,Da,poro,Nr,forch;

double MAX(double m1,double m2);

int i,j,NI,NJ,VAR,data;

public:

void get_data();

void memory_allocation();

void grid_generation();

void boundary_condition();

void u_calculation();

void v_calculation();

void T_calculation();

void C_calculation();

void p_dash_calculation();

void b_calculation();

void correction();

void convergence();

void coefficients();

void schemes();
void central_difference();

void QUICK();

void pressure();

void output();

void omega_calculation();

void streamfunction();

void boundary2();

void data_store();

void freeall();

};

//******************************### INPUT ###**********************************

void simple::get_data()

/* system("clear");

printf("\n\n\n\n");

printf("\t\tEnter the value of NI (odd no.): ");

scanf("%d",&NI);

printf("\t\tEnter the value of NJ (odd no.): ");

scanf("%d",&NJ);

printf("\t\tEnter the value of Reynolds Number: ");

scanf("%lf",&Re);

printf("\t\tEnter the value of Prandtl Number: ");

scanf("%lf",&Pr);

*/

NI=81;

NJ=81;

data=1;
x_l=1.0;

y_l=1.0;

dx=x_l/(NI-2);

dy=y_l/(NJ-2);

forch=1.0;

poro=1.0;

GrT=10000.0;

Re=100.0;

Ri=(GrT/pow(Re,2));

Nr=0.0;

Le=1.0;

Pr=5.0;

Sc=Le*Pr;// Pr is varied accordingly with Le.

//Da=1.0;

dt=0.01;

memory_allocation();

grid_generation();

if(data==1)

boundary_condition();

else

boundary2();

std::ifstream fdata("data_store.dat");

for(j=1;j<=NJ;j++)

for(i=1;i<=NI;i++)
{

fdata>>u[i][j]>>v[i][j]>>T[i][j]>>Co[i][j]>>p[i][j]>>uface[i][j]>>vface[i][j];

fdata.close();

}//else loop

theta=1.15;

alfa_p=0.02;

error_u=1e-4;

error_v=1e-4;

error_T=1e-6;

error_bm=1e-10;

gamma_p=0.2;

return;

//***********************### MEMORY ALLOCATION ###*****************************

void simple::memory_allocation()

x=(double*)malloc((NI+2)*sizeof(double));

y=(double*)malloc((NI+2)*sizeof(double));

x_at_f=(double*)malloc((NI+2)*sizeof(double));

y_at_f=(double*)malloc((NI+2)*sizeof(double));

A=(double*)malloc((NI+2)*sizeof(double));

B=(double*)malloc((NI+2)*sizeof(double));

C=(double*)malloc((NI+2)*sizeof(double));

D=(double*)malloc((NI+2)*sizeof(double));
P=(double*)malloc((NI+2)*sizeof(double));

Q=(double*)malloc((NI+2)*sizeof(double));

u=(double**)malloc((NI+2)*sizeof(double));

v=(double**)malloc((NI+2)*sizeof(double));

T=(double**)malloc((NI+2)*sizeof(double));

Co=(double**)malloc((NI+2)*sizeof(double));

C_prev=(double**)malloc((NI+2)*sizeof(double));

u_prev=(double**)malloc((NI+2)*sizeof(double));

v_prev=(double**)malloc((NI+2)*sizeof(double));

T_prev=(double**)malloc((NI+2)*sizeof(double));

uface=(double**)malloc((NI+2)*sizeof(double));

vface=(double**)malloc((NI+2)*sizeof(double));

omega=(double**)malloc((NI+2)*sizeof(double));

shi=(double**)malloc((NI+2)*sizeof(double));

p=(double**)malloc((NI+2)*sizeof(double));

p_dash=(double**)malloc((NI+2)*sizeof(double));

a_E=(double**)malloc((NI+2)*sizeof(double));

a_W=(double**)malloc((NI+2)*sizeof(double));

a_N=(double**)malloc((NI+2)*sizeof(double));

a_S=(double**)malloc((NI+2)*sizeof(double));

a_0=(double**)malloc((NI+2)*sizeof(double));

a_P=(double**)malloc((NI+2)*sizeof(double));

b_E=(double**)malloc((NI+2)*sizeof(double));

b_W=(double**)malloc((NI+2)*sizeof(double));

b_N=(double**)malloc((NI+2)*sizeof(double));
b_S=(double**)malloc((NI+2)*sizeof(double));

b_P=(double**)malloc((NI+2)*sizeof(double));

b_EE=(double**)malloc((NI+2)*sizeof(double));

b_WW=(double**)malloc((NI+2)*sizeof(double));

b_NN=(double**)malloc((NI+2)*sizeof(double));

b_SS=(double**)malloc((NI+2)*sizeof(double));

bc=(double**)malloc((NI+2)*sizeof(double));

for(j=1;j<=(NI+2);j++)

u[j]=(double*)malloc((NJ+2)*sizeof(double));

v[j]=(double*)malloc((NJ+2)*sizeof(double));

u_prev[j]=(double*)malloc((NJ+2)*sizeof(double));

v_prev[j]=(double*)malloc((NJ+2)*sizeof(double));

uface[j]=(double*)malloc((NJ+2)*sizeof(double));

vface[j]=(double*)malloc((NJ+2)*sizeof(double));

T[j]=(double*)malloc((NJ+2)*sizeof(double));

T_prev[j]=(double*)malloc((NJ+2)*sizeof(double));

Co[j]=(double*)malloc((NJ+2)*sizeof(double));

C_prev[j]=(double*)malloc((NJ+2)*sizeof(double));

omega[j]=(double*)malloc((NJ+2)*sizeof(double));

shi[j]=(double*)malloc((NJ+2)*sizeof(double));

p[j]=(double*)malloc((NJ+2)*sizeof(double));

p_dash[j]=(double*)malloc((NJ+2)*sizeof(double));

a_E[j]=(double*)malloc((NJ+2)*sizeof(double));

a_W[j]=(double*)malloc((NJ+2)*sizeof(double));
a_N[j]=(double*)malloc((NJ+2)*sizeof(double));

a_S[j]=(double*)malloc((NJ+2)*sizeof(double));

a_0[j]=(double*)malloc((NJ+2)*sizeof(double));

a_P[j]=(double*)malloc((NJ+2)*sizeof(double));

b_E[j]=(double*)malloc((NJ+2)*sizeof(double));

b_W[j]=(double*)malloc((NJ+2)*sizeof(double));

b_N[j]=(double*)malloc((NJ+2)*sizeof(double));

b_S[j]=(double*)malloc((NJ+2)*sizeof(double));

b_P[j]=(double*)malloc((NJ+2)*sizeof(double));

b_EE[j]=(double*)malloc((NJ+2)*sizeof(double));

b_WW[j]=(double*)malloc((NJ+2)*sizeof(double));

b_NN[j]=(double*)malloc((NJ+2)*sizeof(double));

b_SS[j]=(double*)malloc((NJ+2)*sizeof(double));

bc[j]=(double*)malloc((NJ+2)*sizeof(double));

return;

//*************************### GRID GENERATION ###*****************************

void simple::grid_generation()

double lamda,pi;

int gridchoice=1;
lamda=0.7;

pi=3.1417;

if(gridchoice==0)

//*** uniform grid ***

x_at_f[1]=0.0;

for(i=2;i<NI;i++)

x_at_f[i]=x_at_f[i-1]+dx;

y_at_f[1]=0.0;

for(j=2;j<NJ;j++)

y_at_f[j]=y_at_f[j-1]+dy;

x[1]=x_at_f[1];

for(i=2;i<NI;i++)

x[i]=x_at_f[i-1]+(x_at_f[i]-x_at_f[i-1])/2.0;

x[NI]=x_at_f[NI-1];

y[1]=y_at_f[1];

for(j=2;j<NJ;j++)

y[j]=y_at_f[j-1]+(y_at_f[j]-y_at_f[j-1])/2.0;

y[NJ]=y_at_f[NJ-1];

else

//******* nonuniform grid in x dirn. at grid point p of *********

//******* nonuniform grid in x dirn. at grid point p of *********


for(j=1;j<=NJ;j++)

y[j] = y_l*(j-1)/(NJ-1) - lamda/(2.0*pi)*sin(2.0*pi*(j-1)/(NJ-1));

for(i=1;i<=NI;i++)

x[i] = x_l*(i-1)/(NI-1) - lamda/(2.0*pi)*sin(2.0*pi*(i-1)/(NI-1));

for(j=1;j<=NJ;j++)

y[j]=y[j]/y[NJ];

for(i=1;i<=NI;i++)

x[i]=x[i]/x[NI];

//******* nonuniform grid in x dirn. at grid point of u *********

x_at_f[1]=0.0;

for(i=2;i<NI-1;i++)

x_at_f[i]=(x[i]+x[i+1])/2;

x_at_f[NI-1]=x_l;

//******** nonuniform grid in y dirn. at grid point of v ********

y_at_f[1]=0.0;

for(j=2;j<NJ-1;j++)
y_at_f[j]=(y[j]+y[j+1])/2;

y_at_f[NJ-1]=y_l;

return;

//************************### BOUNDARY CONDITIONS ###**************************

void simple::boundary2()

for(i=1;i<=NI;i++)

for(j=1;j<=NJ;j++)

omega[i][j]=0.0;

shi[i][j]=0.0;

return;

void simple::boundary_condition()

//****** initial value of u velocity except boundary ******

for(i=1;i<=NI;i++)

for(j=2;j<=NJ-1;j++)

{
u[i][j]=0.0;

for(i=1;i<=NI;i++)

for(j=1;j<=NJ;j++)

uface[i][j]=0.0;

omega[i][j]=0.0;

shi[i][j]=0.0;

//****** u velocity at left & right wall ******

for(j=1;j<=NJ-1;j++)

u[1][j]=0.0;

u[NI-1][j]=0.0;

u[NI][j]=0.0;

//****** u velocity at bottom & top wall ******

for(i=1;i<=NI;i++)

u[i][1]=0.0;
u[i][NJ]=1.0;

//****** initial value of v velocity except boundary ******

for(i=1;i<=NI;i++)

for(j=2;j<=NJ-1;j++)

v[i][j]=0.0;

for(i=1;i<=NI;i++)

for(j=1;j<=NJ;j++)

vface[i][j]=0.0;

//****** v velocity at left & right wall ******

for(j=1;j<=NJ;j++)

v[1][j]=0.0;

v[NI][j]=0.0;

}
//****** v velocity at bottom & top wall ******

for(i=1;i<=NI;i++)

v[i][1]=0.0;

v[i][NJ]=0.0;

//****** initial value of temperature except boundary ******

for(i=1;i<=NI;i++)

for(j=1;j<=NJ;j++)

T[i][j]=0.0;

Co[i][j]=0.0;

//****** temperature at left & right wall ******

for(j=1;j<=NJ;j++)

T[1][j]=1.0;

T[NI][j]=0.0;

Co[1][j]=1.0;

Co[NI][j]=0.0;

}
//****** temperature at bottom & top wall ******

for(i=2;i<=NI-1;i++)

T[i][1]=T[i][2];

T[i][NJ]=T[i][NJ-1];

Co[i][1]=Co[i][2];

Co[i][NJ]=Co[i][NJ-1];

//****** initial value of pressure & pr. correction ******

for(i=1;i<=NI;i++)

for(j=1;j<=NJ;j++)

p[i][j]=0.0;

p_dash[i][j]=0.0;

return;

void simple::coefficients()

double gamma,eps;

if(VAR==1 || VAR==2)

eps=poro;

gamma=1.0/(eps*Re);
}

else

if(VAR==3)

eps=1.0;

gamma=1.0/(Re*Pr);

else

eps=1.0;

gamma=1.0/(Re*Sc);

//*** calculation of fluxes ***

F_e=uface[i][j]*(y_at_f[j]-y_at_f[j-1])/(eps*eps);

F_w=uface[i-1][j]*(y_at_f[j]-y_at_f[j-1])/(eps*eps);

F_n=vface[i][j]*(x_at_f[i]-x_at_f[i-1])/(eps*eps);

F_s=vface[i][j-1]*(x_at_f[i]-x_at_f[i-1])/(eps*eps);

//*** calculation of diffusion conductance ***

D_e=gamma*(y_at_f[j]-y_at_f[j-1])/((x[i+1]-x[i]));

D_w=gamma*(y_at_f[j]-y_at_f[j-1])/((x[i]-x[i-1]));

D_n=gamma*(x_at_f[i]-x_at_f[i-1])/((y[j+1]-y[j]));

D_s=gamma*(x_at_f[i]-x_at_f[i-1])/((y[j]-y[j-1]));
return;

void simple::schemes()

double s_term,eps;

for(i=2;i<=NI-1;i++)

for(j=2;j<=NJ-1;j++)

coefficients();

if(i==2||i==NI-1||j==2||j==NJ-1)

central_difference(); // call of function

else

QUICK(); // call of function

if(VAR==1 ||VAR==2)

s_term=0.0;/*((x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-y_at_f[j-1])*1.0/(Re*Da))

+
((pow((u_prev[i][j]*u_prev[i][j]+v_prev[i][j]*v_prev[i][j]),0.5)*1.75)/(pow(150,0.5)*pow(Da,0.5)*pow(po
ro,1.5)))

*(x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-y_at_f[j-1]);

*/

eps=poro;

else

{
s_term=0.0;

eps=1.0;

a_0[i][j]=(x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-y_at_f[j-1])/(eps*dt);

if(VAR==4)

a_0[i][j]=poro*a_0[i][j];

a_P[i][j]=a_E[i][j]+a_W[i][j]+a_N[i][j]+a_S[i][j]+a_0[i][j]+s_term;

return;

//*********************### CENTRAL DIFFERENCE SCHEME ###***********************

void simple::central_difference()

a_E[i][j]=D_e+MAX(0.0,-F_e);

a_W[i][j]=D_w+MAX(0.0,F_w);

a_N[i][j]=D_n+MAX(0.0,-F_n);

a_S[i][j]=D_s+MAX(0.0,F_s);

b_E[i][j]=-MAX(0.0,-F_e)-0.5*F_e;

b_W[i][j]=-MAX(0.0,F_w)+0.5*F_w;

b_N[i][j]=-MAX(0.0,-F_n)-0.5*F_n;

b_S[i][j]=-MAX(0.0,F_s)+0.5*F_s;

b_P[i][j]=-(b_E[i][j]+b_W[i][j]+b_N[i][j]+b_S[i][j]);

return;
}

//*************************### QUICK SCHEME ###********************************

void simple::QUICK()

a_E[i][j]=D_e+MAX(0.0,-F_e);

a_W[i][j]=D_w+MAX(0.0,F_w);

a_N[i][j]=D_n+MAX(0.0,-F_n);

a_S[i][j]=D_s+MAX(0.0,F_s);

b_E[i][j]=-(3.0/8.0)*MAX(0.0,F_e)-(2.0/8.0)*MAX(0.0,-F_e)+(1.0/8.0)* MAX(0.0,-F_w);

b_W[i][j]=-(3.0/8.0)*MAX(0.0,-F_w)-(2.0/8.0)*MAX(0.0,F_w)+(1.0/8.0)* MAX(0.0,F_e);

b_N[i][j]=-(3.0/8.0)*MAX(0.0,F_n)-(2.0/8.0)*MAX(0.0,-F_n)+(1.0/8.0)* MAX(0.0,-F_s);

b_S[i][j]=-(3.0/8.0)*MAX(0.0,-F_s)-(2.0/8.0)*MAX(0.0,F_s)+(1.0/8.0)*MAX(0.0,F_n);

b_EE[i][j]=-(1.0/8.0)*MAX(0.0,-F_e);

b_WW[i][j]=-(1.0/8.0)*MAX(0.0,F_w);

b_NN[i][j]=-(1.0/8.0)*MAX(0.0,-F_n);

b_SS[i][j]=-(1.0/8.0)*MAX(0.0,F_s);

b_P[i][j]=-(b_E[i][j]+b_W[i][j]+b_N[i][j]+b_S[i][j]+b_EE[i][j]+b_WW[i][j]+b_NN[i][j]+b_SS[i][j]);

return;

//******************### SOLUTION OF u MOMENTUM EQUATION ###********************

void simple::u_calculation()
{

double um_diff,s_term,p_term,b_term,sum=0.0;

int count=0;

ru_k=10.0;

while(ru_k>error_u && count<10)

for(j=NJ-1;j>=2;j--)

for(i=2;i<=NI-1;i++)

p_term=((p[i-1][j]-p[i+1][j])/(x[i+1]-x[i-1]))*(x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-y_at_f[j-1]);

b_term=0.0;

//*** For the border control volumes, the central difference scheme is used ***

if(i==2||i==NI-1||j==2||j==NJ-1)

s_term=p_term+b_term+a_N[i][j]*u[i][j+1]+a_S[i][j]*u[i][j-1]+a_0[i][j]*u_prev[i][j]+

b_P[i][j]*u_prev[i][j]+b_E[i][j]*u_prev[i+1][j]+b_W[i][j]*u_prev[i-1][j]+

b_N[i][j]*u_prev[i][j+1]+b_S[i][j]*u_prev[i][j-1];

//*** For the internal control volumes, the deferred QUICK scheme is used ***

else

s_term=p_term+b_term+a_N[i][j]*u[i][j+1]+a_S[i][j]*u[i][j-1]+a_0[i][j]*u_prev[i][j]+

b_P[i][j]*u_prev[i][j]+b_E[i][j]*u_prev[i+1][j]+b_W[i][j]*u_prev[i-1][j]+

b_N[i][j]*u_prev[i][j+1]+b_S[i][j]*u_prev[i][j-1]+b_EE[i][j]*u_prev[i+2][j]+

+b_WW[i][j]*u_prev[i-2][j]+b_NN[i][j]*u_prev[i][j+2]+b_SS[i][j]*u_prev[i][j-2];
}

//**** solution procedure by TriDiagonal-Matrix Algorithm ****

A[i]=a_P[i][j];

B[i]=a_E[i][j];

C[i]=a_W[i][j];

if(i==2||i==NI-1)

//*** special treatment near left wall ***

if(i==2)

C[i]=0;

D[i]=a_W[i][j]*u[i-1][j]+s_term;

//*** special treatment near right wall ***

else

B[i]=0;

D[i]=a_E[i][j]*u[i+1][j]+s_term;

else

D[i]=s_term;

} // here i loop is closed


B[1]=0; C[1]=0; A[1]=1.0; D[1]=u[1][j];

P[1]=B[1]/A[1]; Q[1]=D[1]/A[1];

for(i=2;i<=NI-1;i++)

//*** here recurrence relations are used to find out P & Q ***

P[i]=B[i]/(A[i]-C[i]*P[i-1]);

Q[i]=(C[i]*Q[i-1]+D[i])/(A[i]-C[i]*P[i-1]);

for(i=NI-1;i>=2;i--)

//*** back-substitution to find out u ***

u[i][j]=u[i+1][j]*P[i]+Q[i];

} // here j loop is closed

//******************** calculation of u mom. RESIDUAL ********************

sum=0.0;

for(i=2;i<=NI-1;i++)

for(j=2;j<=NJ-1;j++)

p_term=((p[i-1][j]-p[i+1][j])/(x[i+1]-x[i-1]))*(x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-
y_at_f[j-1]);

b_term=0.0;
if(i==2||i==NI-1||j==2||j==NJ-1)

//*** difference of u momentum equation at border control volumes using central difference scheme
***

um_diff=p_term+b_term+a_E[i][j]*u[i+1][j]+a_W[i][j]*u[i-1][j]+

a_N[i][j]*u[i][j+1]+a_S[i][j]*u[i][j-1]+a_0[i][j]*u_prev[i][j]+

b_P[i][j]*u_prev[i][j]+b_E[i][j]*u_prev[i+1][j]+b_W[i][j]*u_prev[i-1][j]+

b_N[i][j]*u_prev[i][j+1]+b_S[i][j]*u_prev[i][j-1]-a_P[i][j]*u[i][j];

else

//*** difference of u momentum equation at interior control volumes using QUICK scheme ***

um_diff=p_term+b_term+a_E[i][j]*u[i+1][j]+a_W[i][j]*u[i-1][j]+

a_N[i][j]*u[i][j+1]+a_S[i][j]*u[i][j-1]+a_0[i][j]*u_prev[i][j]+

b_P[i][j]*u_prev[i][j]+b_E[i][j]*u_prev[i+1][j]+b_W[i][j]*u_prev[i-1][j]+

b_N[i][j]*u_prev[i][j+1]+b_S[i][j]*u_prev[i][j-
1]+b_EE[i][j]*u_prev[i+2][j]+

+b_WW[i][j]*u_prev[i-2][j]+b_NN[i][j]*u_prev[i][j+2]+

b_SS[i][j]*u_prev[i][j-2]-a_P[i][j]*u[i][j];

sum=sum+pow(um_diff,2);

} // here j loop is closed

} // here i loop is closed

ru_k=sqrt(sum);

//******************** end of RESIDUAL calculation ********************


count++;

} // here while loop is closed

//printf("No of iteration of u calculation == %d\n ",count);

return;

//******************### SOLUTION OF v MOMENTUM EQUATION ###********************

void simple::v_calculation()

double vm_diff,s_term,p_term,b_term,sum=0.0,J=0.0;

int count=0;

rv_k=10.0;

while(rv_k>error_v && count<10)

for(j=2;j<=NJ-1;j++)

for(i=2;i<=NI-1;i++)

p_term=((p[i][j-1]-p[i][j+1])/(y[j+1]-y[j-1]))*(x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-y_at_f[j-1]);

b_term=(T[i][j]+Nr*Co[i][j])*(GrT/pow(Re,2))*(x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-y_at_f[j-
1])+

J*v[i][j]*v[i][j]*(x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-y_at_f[j-1]);

//*** For the border control volumes, the central difference scheme is used ***
if(i==2||i==NI-1||j==2||j==NJ-1)

s_term=p_term+b_term+a_N[i][j]*v[i][j+1]+a_S[i][j]*v[i][j-1]+a_0[i][j]*v_prev[i][j]+

b_P[i][j]*v_prev[i][j]+b_E[i][j]*v_prev[i+1][j]+b_W[i][j]*v_prev[i-1][j]+

b_N[i][j]*v_prev[i][j+1]+b_S[i][j]*v_prev[i][j-1];

//*** For the internal control volumes, the deferred QUICK scheme is used ***

else

s_term=p_term+b_term+a_N[i][j]*v[i][j+1]+a_S[i][j]*v[i][j-1]+a_0[i][j]*v_prev[i][j]+

b_P[i][j]*v_prev[i][j]+b_E[i][j]*v_prev[i+1][j]+b_W[i][j]*v_prev[i-1][j]+

b_N[i][j]*v_prev[i][j+1]+b_S[i][j]*v_prev[i][j-1]+b_EE[i][j]*v_prev[i+2][j]+

+b_WW[i][j]*v_prev[i-2][j]+b_NN[i][j]*v_prev[i][j+2]+b_SS[i][j]*v_prev[i][j-2];

//**** solution procedure by TriDiagonal-Matrix Algorithm ****

A[i]=a_P[i][j];

B[i]=a_E[i][j];

C[i]=a_W[i][j];

if(i==2||i==NI-1)

//*** special treatment near left wall ***

if(i==2)

C[i]=0;

D[i]=a_W[i][j]*v[i-1][j]+s_term;

}
//*** special treatment near right wall ***

else

B[i]=0;

D[i]=a_E[i][j]*v[i+1][j]+s_term;

else

D[i]=s_term;

} // here i loop is closed

B[1]=0; C[1]=0; A[1]=1.0; D[1]=v[1][j];

P[1]=B[1]/A[1]; Q[1]=D[1]/A[1];

for(i=2;i<=NI-1;i++)

//*** here recurrence relations are used to find out P & Q ***

P[i]=B[i]/(A[i]-C[i]*P[i-1]);

Q[i]=(C[i]*Q[i-1]+D[i])/(A[i]-C[i]*P[i-1]);

for(i=NI-1;i>=2;i--)

//*** back-substitution to find out v ***

v[i][j]=v[i+1][j]*P[i]+Q[i];
}

} // here j loop is closed

//******************** calculation of v mom RESIDUAL ********************

sum=0.0;

for(i=2;i<=NI-1;i++)

for(j=2;j<=NJ-1;j++)

p_term=((p[i][j-1]-p[i][j+1])/(y[j+1]-y[j-1]))*(x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-
y_at_f[j-1]);

b_term=(T[i][j]+Nr*Co[i][j])*(GrT/pow(Re,2))*(x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-
y_at_f[j-1])+

J*v[i][j]*v[i][j]*(x_at_f[i]-x_at_f[i-1])*(y_at_f[j]-y_at_f[j-1]); //source Term

if(i==2||i==NI-1||j==2||j==NJ-1)

//*** difference of v momentum equation at border control volumes using central difference scheme
***

vm_diff=p_term+b_term+a_E[i][j]*v[i+1][j]+a_W[i][j]*v[i-1][j]+

a_N[i][j]*v[i][j+1]+a_S[i][j]*v[i][j-1]+a_0[i][j]*v_prev[i][j]+

b_P[i][j]*v_prev[i][j]+b_E[i][j]*v_prev[i+1][j]+b_W[i][j]*v_prev[i-1][j]+

b_N[i][j]*v_prev[i][j+1]+b_S[i][j]*v_prev[i][j-1]-a_P[i][j]*v[i][j];

else

//*** difference of v momentum equation at interior control volumes using QUICK scheme ***

vm_diff=p_term+b_term+a_E[i][j]*v[i+1][j]+a_W[i][j]*v[i-1][j]+

a_N[i][j]*v[i][j+1]+a_S[i][j]*v[i][j-1]+a_0[i][j]*v_prev[i][j]+
b_P[i][j]*v_prev[i][j]+b_E[i][j]*v_prev[i+1][j]+b_W[i][j]*v_prev[i-1][j]+

b_N[i][j]*v_prev[i][j+1]+b_S[i][j]*v_prev[i][j-1]+b_EE[i][j]*v_prev[i+2][j]+

+b_WW[i][j]*v_prev[i-2][j]+b_NN[i][j]*v_prev[i][j+2]+

b_SS[i][j]*v_prev[i][j-2]-a_P[i][j]*v[i][j];

sum=sum+pow(vm_diff,2);

} // here j loop is closed

} // here i loop is closed

rv_k=sqrt(sum);

//******************** end of RESIDUAL calculation ********************

count++;

} // here while loop is closed

//printf("No of iteration of v calculation ==%d\n ",count);

return;

//********************### SOLUTION OF ENERGY EQUATION ###**********************

void simple::T_calculation()

double s_term,b_term,sum=0.0,T_old,D_f=1.0;

int count=0;

rT_k=10.0;
while(rT_k>error_T && count<=20)

rT_k=0;

for(j=2;j<=NJ-1;j++)

for(i=2;i<=NI-1;i++)

b_term=0.0;//(D_f/Re)*(((((Co[i+1][j]-Co[i][j])/(x[i+1]-x[i]))-((Co[i][j]-Co[i-1][j])/(x[i]-x[i-1])))*(y_at_f[j]-
y_at_f[j-1]))

//+((((Co[i][j+1]-Co[i][j])/(y[j+1]-y[j]))-((Co[i][j]-Co[i][j-1])/(y[j]-y[j-1])))*(x_at_f[i]-x_at_f[i-1])));

//*** For the border control volumes, the central difference scheme is used ***

if(i==2||i==NI-1||j==2||j==NJ-1)

s_term=b_term+a_N[i][j]*T[i][j+1]+a_S[i][j]*T[i][j-1]+a_0[i][j]*T_prev[i][j]+

b_P[i][j]*T_prev[i][j]+b_E[i][j]*T_prev[i+1][j]+b_W[i][j]*T_prev[i-1][j]+

b_N[i][j]*T_prev[i][j+1]+b_S[i][j]*T_prev[i][j-1];

//*** For the internal control volumes, the deferred QUICK scheme is used ***

else

s_term=b_term+a_N[i][j]*T[i][j+1]+a_S[i][j]*T[i][j-1]+a_0[i][j]*T_prev[i][j]+

b_P[i][j]*T_prev[i][j]+b_E[i][j]*T_prev[i+1][j]+b_W[i][j]*T_prev[i-1][j]+

b_N[i][j]*T_prev[i][j+1]+b_S[i][j]*T_prev[i][j-1]+b_EE[i][j]*T_prev[i+2][j]+

+b_WW[i][j]*T_prev[i-2][j]+b_NN[i][j]*T_prev[i][j+2]+b_SS[i][j]*T_prev[i][j-2];

}
//**** solution procedure by TriDiagonal-Matrix Algorithm ****

A[i]=a_P[i][j];

B[i]=a_E[i][j];

C[i]=a_W[i][j];

if(i==2||i==NI-1)

//*** special treatment near left wall ***

if(i==2)

C[i]=0;

D[i]=a_W[i][j]*T[i-1][j]+s_term;

//*** special treatment near right wall ***

else

B[i]=0;

D[i]=a_E[i][j]*T[i+1][j]+s_term;

else

D[i]=s_term;

} // here i loop is closed

B[1]=0; C[1]=0; A[1]=1.0; D[1]=T[1][j];


P[1]=B[1]/A[1]; Q[1]=D[1]/A[1];

for(i=2;i<=NI-1;i++)

//*** here recurrence relations are used to find out P & Q ***

P[i]=B[i]/(A[i]-C[i]*P[i-1]);

Q[i]=(C[i]*Q[i-1]+D[i])/(A[i]-C[i]*P[i-1]);

for(i=NI-1;i>=2;i--)

T_old=T[i][j];

//*** back-substitution to find out v ***

T[i][j]=T[i+1][j]*P[i]+Q[i];

rT_k=MAX(rT_k,fabs(T[i][j]-T_old));

} // here j loop is closed

count++;

} // here while loop is closed

//if(k==count2)

for(i=2;i<=NI-1;i++)

{
T[i][1]=T[i][2];

T[i][NJ]=T[i][NJ-1];

/*

for(j=2;j<=NJ-1;j++)

T[1][j]=T[2][j];

T[NI][j]=T[NI-1][j];

*/

//printf("No of iteration of T calculation ==%d\n ",count);

return;

//********************### SOLUTION OF ENERGY EQUATION ###**********************

void simple::C_calculation()

double s_term,b_term,sum=0.0,T_old,S_r=0.0;

int count=0;

rT_k=10.0;

while(rT_k>error_T && count<=20)

{
rT_k=0;

for(j=2;j<=NJ-1;j++)

for(i=2;i<=NI-1;i++)

b_term=(S_r/Re)*(((((T[i+1][j]-T[i][j])/(x[i+1]-x[i]))-((T[i][j]-T[i-1][j])/(x[i]-x[i-1])))*(y_at_f[j]-y_at_f[j-1]))

+((((T[i][j+1]-T[i][j])/(y[j+1]-y[j]))-((T[i][j]-T[i][j-1])/(y[j]-y[j-1])))*(x_at_f[i]-x_at_f[i-1])));

//*** For the border control volumes, the central difference scheme is used ***

if(i==2||i==NI-1||j==2||j==NJ-1)

s_term=b_term+a_N[i][j]*Co[i][j+1]+a_S[i][j]*Co[i][j-1]+a_0[i][j]*C_prev[i][j]+

b_P[i][j]*C_prev[i][j]+b_E[i][j]*C_prev[i+1][j]+b_W[i][j]*C_prev[i-1][j]+

b_N[i][j]*C_prev[i][j+1]+b_S[i][j]*C_prev[i][j-1];

//*** For the internal control volumes, the deferred QUICK scheme is used ***

else

s_term=b_term+a_N[i][j]*Co[i][j+1]+a_S[i][j]*Co[i][j-1]+a_0[i][j]*C_prev[i][j]+

b_P[i][j]*C_prev[i][j]+b_E[i][j]*C_prev[i+1][j]+b_W[i][j]*C_prev[i-1][j]+

b_N[i][j]*C_prev[i][j+1]+b_S[i][j]*C_prev[i][j-1]+b_EE[i][j]*C_prev[i+2][j]+

+b_WW[i][j]*C_prev[i-2][j]+b_NN[i][j]*C_prev[i][j+2]+b_SS[i][j]*C_prev[i][j-2];

//**** solution procedure by TriDiagonal-Matrix Algorithm ****

A[i]=a_P[i][j];
B[i]=a_E[i][j];

C[i]=a_W[i][j];

if(i==2||i==NI-1)

//*** special treatment near left wall ***

if(i==2)

C[i]=0;

D[i]=a_W[i][j]*Co[i-1][j]+s_term;

//*** special treatment near right wall ***

else

B[i]=0;

D[i]=a_E[i][j]*Co[i+1][j]+s_term;

else

D[i]=s_term;

} // here i loop is closed

B[1]=0; C[1]=0; A[1]=1.0; D[1]=Co[1][j];

P[1]=B[1]/A[1]; Q[1]=D[1]/A[1];
for(i=2;i<=NI-1;i++)

//*** here recurrence relations are used to find out P & Q ***

P[i]=B[i]/(A[i]-C[i]*P[i-1]);

Q[i]=(C[i]*Q[i-1]+D[i])/(A[i]-C[i]*P[i-1]);

for(i=NI-1;i>=2;i--)

T_old=Co[i][j];

//*** back-substitution to find out v ***

Co[i][j]=Co[i+1][j]*P[i]+Q[i];

rT_k=MAX(rT_k,fabs(Co[i][j]-T_old));

} // here j loop is closed

count++;

} // here while loop is closed

for(i=2;i<=NI-1;i++)

Co[i][1]=Co[i][2];

Co[i][NJ]=Co[i][NJ-1];

/*
for(j=2;j<=NJ-1;j++)

Co[1][j]=Co[2][j];

Co[NI][j]=Co[NI-1][j];

//printf("No of iteration of T calculation ==%d\n ",count);

*/

return;

//****************### SOLUTION OF PRESSURE CORRECTION EQUATION ###***************

void simple::p_dash_calculation()

double a_Pr,error_p,rp_o,pd_diff,s_term,sum=0.0;

int count=0;

rp_k=100.0;

for(i=1;i<=NI;i++)

for(j=1;j<=NJ;j++)

{ // initial value of p_dash in every time step

p_dash[i][j]=0.0;

//******************** calculation of p_dash RESIDUAL *******************

for(i=2;i<=NI-1;i++)

{
for(j=2;j<=NJ-1;j++)

pressure(); // call of pressure function

a_Pr=a_E[i][j]+a_W[i][j]+a_N[i][j]+a_S[i][j];

pd_diff=a_E[i][j]*p_dash[i+1][j]+a_W[i][j]*p_dash[i-1][j]+

a_N[i][j]*p_dash[i][j+1]+a_S[i][j]*p_dash[i][j-1]+bc[i][j]-a_Pr*p_dash[i][j];

sum=sum+pow(pd_diff,2);

rp_o=sqrt(sum);

error_p=gamma_p*rp_o;

//******************** end of RESIDUAL calculation *********************

while(rp_k>error_p && count<50)

for(j=2;j<=NJ-1;j++)

for(i=2;i<=NI-1;i++)

pressure(); // call of pressure function

//**** solution procedure by TriDiagonal-Matrix Algorithm ****

A[i]=a_E[i][j]+a_W[i][j]+a_N[i][j]+a_S[i][j];

B[i]=a_E[i][j];

C[i]=a_W[i][j];

s_term=a_N[i][j]*p_dash[i][j+1]+a_S[i][j]*p_dash[i][j-1]+bc[i][j];

if(i==2||i==NI-1)
{

//*** special treatment near left wall ***

if(i==2)

C[i]=0;

D[i]=a_W[i][j]*p_dash[i-1][j]+s_term;

//*** special treatment near right wall ***

else

B[i]=0;

D[i]=a_E[i][j]*p_dash[i+1][j]+s_term;

else

D[i]=s_term;

} // here i loop is closed

B[1]=0; C[1]=0; A[1]=1.0; D[1]=p_dash[1][j];

P[1]=B[1]/A[1]; Q[1]=D[1]/A[1];

for(i=2;i<=NI-1;i++)

//*** here recurrence relations are used to find out P & Q ***

P[i]=B[i]/(A[i]-C[i]*P[i-1]);
Q[i]=(C[i]*Q[i-1]+D[i])/(A[i]-C[i]*P[i-1]);

for(i=NI-1;i>=2;i--)

//*** back-substitution to find out v ***

p_dash[i][j]=p_dash[i+1][j]*P[i]+Q[i];

} // here j loop is closed

//******************** calculation of p_dash RESIDUAL *******************

sum=0.0;

for(i=2;i<=NI-1;i++)

for(j=2;j<=NJ-1;j++)

a_Pr=a_E[i][j]+a_W[i][j]+a_N[i][j]+a_S[i][j];

pd_diff=a_E[i][j]*p_dash[i+1][j]+a_W[i][j]*p_dash[i-1][j]+

a_N[i][j]*p_dash[i][j+1]+a_S[i][j]*p_dash[i][j-1]+bc[i][j]-a_Pr*p_dash[i][j];

sum=sum+pow(pd_diff,2);

rp_k=sqrt(sum);

//******************** end of RESIDUAL calculation *********************

count++;
} // here while loop is closed

//printf("\nNo of iteration of p_dash calculation ==%d\n ",count);

return;

//*******************### PRESSURE & VELOCITY CORRECTION ###********************

void simple::correction()

//*** pressure update ***

for(j=2;j<=NJ-1;j++)

for(i=2;i<=NI-1;i++)

p[i][j]=p[i][j]+alfa_p*p_dash[i][j]; // interior point

for(j=2;j<=NJ-1;j++)

p[1][j]=p[2][j]; // left wall

p[NI][j]=p[NI-1][j]; // right wall

for(i=2;i<=NI-1;i++)

p[i][1]=p[i][2]; // bottom wall

p[i][NJ]=p[i][NJ-1]; // top wall


}

p[1][1]=p[2][2]; // left-bottom corner

p[NI][1]=p[NI-1][2]; // right-bottom corner

p[1][NJ]=p[2][NJ-1]; // left-top corner

p[NI][NJ]=p[NI-1][NJ-1];// right-top corner

//*** u velocity update ***

for(j=2;j<=NJ-1;j++)

for(i=2;i<=NI-1;i++)

u[i][j]=u[i][j]+(y_at_f[j]-y_at_f[j-1])*(x_at_f[i]-x_at_f[i-1])*(p_dash[i-1][j]-
p_dash[i+1][j])/(a_P[i][j]*(x[i+1]-x[i-1]));

//*** v velocity update ***

for(j=2;j<=NJ-1;j++)

for(i=2;i<=NI-1;i++)

v[i][j]=v[i][j]+(y_at_f[j]-y_at_f[j-1])*(x_at_f[i]-x_at_f[i-1])*(p_dash[i][j-1]-
p_dash[i][j+1])/(a_P[i][j]*(y[j+1]-y[j-1]));

return;

}
//*********************### MASS RESIDUAL CALCULATION ###***********************

void simple::b_calculation()

error_b=0.0;

for(i=2;i<=NI-2;i++)

for(j=2;j<=NJ-1;j++)

uface[i][j]=0.5*(u[i+1][j]+u[i][j])+((x[i+1]-x[i])*(y_at_f[j]-y_at_f[j-1])*0.5*((1.0/a_P[i+1][j])+

(1.0/a_P[i][j]))*(((p[i][j]-p[i+1][j])/(x[i+1]-x[i]))-0.5*(((p[i][j]-p[i+2][j])/(x[i+2]-x[i]))+((p[i-1][j]-
p[i+1][j])/(x[i+1]-x[i-1])))));

for(i=2;i<=NI-1;i++)

for(j=2;j<=NJ-2;j++)

vface[i][j]=0.5*(v[i][j]+v[i][j+1])+((y[j+1]-y[j])*(x_at_f[i]-x_at_f[i-1])*0.5*((1.0/a_P[i][j])+

(1.0/a_P[i][j+1]))*(((p[i][j]-p[i][j+1])/(y[j+1]-y[j]))-0.5*(((p[i][j]-p[i][j+2])/(y[j+2]-y[j]))+((p[i][j-1]-
p[i][j+1])/(y[j+1]-y[j-1])))));

for(i=2;i<=NI-1;i++)

for(j=2;j<=NJ-1;j++)
{

bc[i][j]=((uface[i-1][j]-uface[i][j])*(y_at_f[j]-y_at_f[j-1]))+((vface[i][j-1]-vface[i][j])*(x_at_f[i]-
x_at_f[i-1]));

error_b=error_b+fabs(bc[i][j]);

// cout<<"\n The mass residual is = "<<error_b;

return;

//*********************### VORTICITY CALCULATION ###*******************************

void simple::omega_calculation()

double vx,uy;

for(j=1;j<=NJ;j++)

for(i=1;i<=NI;i++)

if(i==1 || i==NI)

if(i==1)

vx=(v[2][j]-v[1][j])/(x[2]-x[1]);

}
else

vx=(v[NI][j]-v[NI-1][j])/(x[NI]-x[NI-1]);

else

vx=(v[i+1][j]-v[i-1][j])/(x[i+1]-x[i-1]);

if(j==1 || j==NJ)

if(j==1)

uy=(u[i][2]-u[i][1])/(y[2]-y[1]);

else

uy=(u[i][NJ]-u[i][NJ-1])/(y[NJ]-y[NJ-1]);

else

uy=(u[i][j+1]-u[i][j-1])/(y[j+1]-y[j-1]);

omega[i][j]=vx-uy;

}
}

return;

void simple::streamfunction()

int t;

double temp,error_max,xf,yf,xe,xw,yn,ys,error,ini_error;

for(i=1;i<=NI;i++)

for(j=1;j<=NJ;j++)

shi[i][j]=0.0;

t=0;

ini_error=1.0;

error=1.0;

while(error>1e-10)

error=0.0;

t++;

for(i=2;i<=NI-1;i++)

for(j=2;j<=NJ-1;j++)

xf=x_at_f[i]-x_at_f[i-1];

yf=y_at_f[j]-y_at_f[j-1];

xe=x[i+1]-x[i];

xw=x[i]-x[i-1];
yn=y[j+1]-y[j];

ys=y[j]-y[j-1];

temp=shi[i][j];

shi[i][j]=(1-0.7)*shi[i][j]+ 0.7*( -omega[i][j]+(shi[i+1][j]*(1.0/(xe*xf))

+shi[i-1][j]*(1.0/(xw*xf))+shi[i][j+1]*(1.0/(yn*yf))+shi[i][j-
1]*(1.0/(ys*yf))))

/((1.0/(xe*xf))+(1.0/(xw*xf))+(1.0/(yn*yf))+(1.0/(ys*yf)));

error+=fabs(shi[i][j]-temp)/ini_error;

if(t==1)

ini_error=error;

// printf("\nerror=%e",error);

//printf("\n no of iterations %d", t);

return;

void simple::data_store()

std::ofstream fdata("data_store.dat");

for(j=1;j<=NJ;j++)

for(i=1;i<=NI;i++)
{

fdata<<"\n"<<u[i][j]<<"\t"<<v[i][j]<<"\t"<<T[i][j]<<"\t"<<Co[i][j]<<"\t"<<p[i][j]<<"\t"<<uface[i][j]
<<"\t"<<vface[i][j];

fdata.close();

return;

//******************### CONVERGENCE CONVERGENCE


LOOP*************************************

void simple::convergence()

// FILE *fures,*fvres,*fpres,

FILE *fbres;

/* fures=fopen("ures.dat","w");

fvres=fopen("vres.dat","w");

fpres=fopen("pres.dat","w"); */

fbres=fopen("bres.dat","w");

int count=0;

error_b=1.0;

while(error_b>error_bm && count<100000)

//*** storing value for previous iteration ***


for(i=1;i<=NI;i++)

for(j=1;j<=NJ;j++)

u_prev[i][j]=u[i][j];

v_prev[i][j]=v[i][j];

T_prev[i][j]=T[i][j];

C_prev[i][j]=Co[i][j];

VAR=1;

schemes();

u_calculation(); // u momentum solution

VAR=2;

v_calculation(); // v momentum solution

b_calculation(); // mass residual calculation

if(error_b>error_bm)

p_dash_calculation(); // pressure correction solution

correction(); // update of pressure and velocities

if(error_u>2*error_b)

error_u=2*error_b;;
error_v=2*error_b;;

VAR=3;

schemes();

T_calculation(); // T energy solution

VAR=4;

schemes();

C_calculation(); // T energy solution

count++;

if(count%500==0)

omega_calculation();

streamfunction();

output();

data_store();

// printing residuals in files

/* fprintf(fures,"%d\t %e\n",count,ru_k);

fprintf(fvres,"%d\t %e\n",count,rv_k);

fprintf(fpres,"%d\t %e\n",count,rp_k); */

fprintf(fbres,"%d\t %e\n",count,error_b);

printf("\nMass residual =%e\t%d\n",error_b,count+1);

//printf("No of GLOBAL iteration ==%d\n ",count+1);


} // here while loop is closed

omega_calculation();

streamfunction();

/* fclose(fures);

fclose(fvres);

fclose(fpres); */

fclose(fbres);

return;

//**********************### MAXIMIZATION ###***********************************

double simple::MAX(double m1,double m2)

if(m1>=m2)

return(m1);

else

return(m2);

//**************### FUNCTION FOR PRESSURE CORRECTION EQUATION ###**************

void simple::pressure()

if(i==2)

a_W[i][j]=0.0;

}
else

a_W[i][j]=pow((y_at_f[j]-y_at_f[j-1]),2)*0.5*(1.0/a_P[i-1][j]+1.0/a_P[i][j]);

if(i==NI-1)

a_E[i][j]=0.0;

else

a_E[i][j]=pow((y_at_f[j]-y_at_f[j-1]),2)*0.5*(1.0/a_P[i+1][j]+1.0/a_P[i][j]);

if(j==2)

a_S[i][j]=0.0;

else

a_S[i][j]=pow((x_at_f[i]-x_at_f[i-1]),2)*0.5*(1.0/a_P[i][j-1]+1.0/a_P[i][j]);

if(j==NJ-1)

a_N[i][j]=0.0;

else

a_N[i][j]=pow((x_at_f[i]-x_at_f[i-1]),2)*0.5*(1.0/a_P[i][j+1]+1.0/a_P[i][j]);

return;
}

//**********### OUTPUT OF u & v VELOCITY, TEMPERATURE AND PRESSURE ###*********

void simple::output()

double L_nu,avg_nu;

FILE *fu,*fv,*fuv,*fT,*fp,*fmu,*fmv,*fnu,*fmt,*favg,*fbotnu;

fu=fopen("u.dat","w");

fv=fopen("v.dat","w");

fuv=fopen("uv.plt","w");

fp=fopen("pr.plt","w");

fT=fopen("tempr.plt","w");

fmu=fopen("mu.dat","w");

fmv=fopen("mv.dat","w");

fnu=fopen("nu.dat","w");

fmt=fopen("mtheta.dat","w");

favg=fopen("avgnu.txt","w");

fbotnu=fopen("botnu.dat","w");

//************ printing in output file ****************

fprintf(fuv,"\n\t\tTITLE=\"2D\"\n\tVARIABLES=\"X\",\"Y\",\"U\",\"V\",\"T\",\"Co\",\"S\",\"O\"\n
\t ZONE T=\"BLOCK1\",I=%d,J=%d,F=POINT\n\n",NI,NJ);

fprintf(fT,"\n\t\tTITLE=\"2D\"\n\tVARIABLES=\"X\",\"Y\",\"T\"\n\t ZONE
T=\"BLOCK1\",I=%d,J=%d,F=POINT\n\n",NI,NJ);

fprintf(fp,"\n\t\tTITLE=\"2D\"\n\tVARIABLES=\"X\",\"Y\",\"P\"\n\t ZONE
T=\"BLOCK1\",I=%d,J=%d,F=POINT\n\n",NI,NJ);

for(j=1;j<=NJ;j++)

for(i=1;i<=NI;i++)
{

fprintf(fu,"%lf\t%lf\t%lf\n",x[i],y[j],u[i][j]);

fprintf(fv,"%lf\t%lf\t%lf\n",x[i],y[j],v[i][j]);

fprintf(fuv,"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",x[i],y[j],u[i][j],v[i][j],T[i][j],Co[i][j],shi[i][j],om
ega[i][j]);

fprintf(fT,"%lf\t%lf\t%lf\n",x[i],y[j],T[i][j]);

fprintf(fp,"%lf\t%lf\t%lf\n",x[i],y[j],p[i][j]);

fprintf(fu,"\n");

fprintf(fv,"\n");

fprintf(fuv,"\n");

fprintf(fT,"\n");

fprintf(fp,"\n");

avg_nu=0.0;

/*

for(i=2;i<=NI-1;i++) //Top wall

L_nu=(T[i][NJ]-T[i][NJ-1])/(y[NJ]-y[NJ-1]);

fprintf(fnu,"\n%lf\t%lf",x[i],L_nu);

avg_nu=avg_nu+L_nu*(x_at_f[i]-x_at_f[i-1]);

*/

for(j=2;j<=NJ-1;j++) //Left wall

L_nu=(T[2][j]-T[1][j])/(x[2]-x[1]);

fprintf(fnu,"\n%lf\t%lf",y[j],L_nu);

avg_nu=avg_nu+L_nu*(y_at_f[j]-y_at_f[j-1]);
}

fprintf(favg,"%lf",avg_nu);

for(j=2;j<=NJ-1;j++) //Left wall

L_nu=(Co[2][j]-Co[1][j])/(x[2]-x[1]);

fprintf(fnu,"\n%lf\t%lf",y[j],L_nu);

avg_nu=avg_nu+L_nu*(y_at_f[j]-y_at_f[j-1]);

/* for(i=2;i<=NI-1;i++)//Top wall

L_nu=(Co[i][NJ]-Co[i][NJ-1])/(y[NJ]-y[NJ-1]);

//fprintf(fsh,"\n%lf\t%lf",x[i],L_nu);

avg_nu=avg_nu+L_nu*(x_at_f[i]-x_at_f[i-1]);

}*/

fprintf(favg,"\t%lf",avg_nu);

//*********** output of u velocity at vertical mid plane *************

double temp=0.0;

int n,mid_p;

n=NI%2;

if(n!=0)

mid_p=(NI+1)/2;

for(j=1;j<=NJ;j++)

{
fprintf(fmu,"%lf\t %lf\n",u[mid_p][j],y[j]);

else

mid_p=(NI+1)/2;

for(j=1;j<=NJ;j++)

temp=(u[mid_p-1][j]+u[mid_p][j])/2.0;

fprintf(fmu,"%lf\t %lf\n",temp,y[j]);

//*********** output of v velocity at vertical mid plane *************

n=NJ%2;

if(n!=0)

mid_p=(NJ+1)/2;

for(i=1;i<=NI;i++)

fprintf(fmv,"%lf\t %lf\n",x[i],v[i][mid_p]);

else

mid_p=(NJ+1)/2;

for(i=1;i<=NI;i++)

temp=(v[i][mid_p-1]+v[i][mid_p])/2.0;
fprintf(fmv,"%lf\t %lf\n",x[i],temp);

for(j=1;j<=NJ;j++)

if(NI%2!=0)

fprintf(fmt,"%lf\t %lf\n",T[(NI+1)/2][j],y[j]);

else

fprintf(fmt,"%lf\t %lf\n",(T[NI/2][j]+T[NI/2+1][j])/2.0,y[j]);

/*for(i=1;i<=NI;i++)

fprintf(fmt,"%lf\t %lf\n",T[i][1],x[i]);*/

//**** closing of files ****

fclose(fu); fclose(fv); fclose(fuv); fclose(fT); fclose(fp); fclose(fmu); fclose(fmv); fclose(fnu); fclose(fmt);


fclose(favg);fclose(fbotnu);

return;

void simple::freeall()

//**** free of memory ****

free(u); free(v); free(T); free(u_prev); free(v_prev); free(T_prev); free(uface);free(vface); free(p);


free(p_dash);

free(a_E); free(a_W); free(a_N); free(a_S);free(a_0); free(a_P);

free(b_E); free(b_W); free(b_N); free(b_S); free(b_P); free(b_EE); free(b_WW); free(b_NN); free(b_SS);


free(bc);

free(x); free(y); free(x_at_f); (y_at_f); free(A); free(B); free(C); free(D); free(P); free(Q);

return;

//**************************### MAIN PROGRAM ###*******************************


int main()

simple s;

s.get_data();

// s.memory_allocation();

//s.grid_generation();

//s.boundary_condition();

s.convergence();

// s.schemes();

// s.T_calculation();

s.output();

s.freeall();

return(0);

//**************************### END OF PROGRAM ###*****************************

You might also like