/*---------------------------------------------------------------*/ void COMP_TEMP( REAL **U, REAL **V, REAL **TEMP, int **FLAG, int imax, int jmax, REAL delt, REAL delx, REAL dely, REAL gamma, REAL Re, REAL Pr) { int i, j; REAL LAPLT, DUTDX, DVTDY, indelx2, indely2; REAL **T2; T2 = RMATRIX(0, imax+1, 0, jmax+1); indelx2 = 1./delx/delx; indely2 = 1./dely/dely; for (i=1; i<=imax; i++) { for (j=1; j<=jmax; j++) { if( (FLAG[i][j] & C_F) && (FLAG[i][j] < C_E) ) { LAPLT = (TEMP[i+1][j]-2.0*TEMP[i][j]+TEMP[i-1][j])*indelx2 + (TEMP[i][j+1]-2.0*TEMP[i][j]+TEMP[i][j-1])*indely2; DUTDX = ( (U[i][j]*0.5*(TEMP[i][j]+TEMP[i+1][j]) - U[i-1][j]*0.5*(TEMP[i-1][j]+TEMP[i][j])) + gamma*(fabs(U[i][j])*0.5*(TEMP[i][j]-TEMP[i+1][j]) - fabs(U[i-1][j])*0.5*(TEMP[i-1][j]-TEMP[i][j])) )/delx; DVTDY = ( (V[i][j]*0.5*(TEMP[i][j]+TEMP[i][j+1]) - V[i][j-1]*0.5*(TEMP[i][j-1]+TEMP[i][j])) + gamma*(fabs(V[i][j])*0.5*(TEMP[i][j]-TEMP[i][j+1]) - fabs(V[i][j-1])*0.5*(TEMP[i][j-1]-TEMP[i][j])) )/dely; T2[i][j] = TEMP[i][j]+delt*(LAPLT/Re/Pr - DUTDX - DVTDY); } } } for (i=1; i<=imax; i++) { for (j=1; j<=jmax; j++) { if( (FLAG[i][j] & C_F) && (FLAG[i][j] < C_E) ) { TEMP[i][j] = T2[i][j]; } } } FREE_RMATRIX(T2,0,imax+1,0,jmax+1); }
/*------------------------------------------------------------------*/ int main(int argc, char *Inputfile[]) { REAL xlength,ylength,delx,dely,t_end,delt,tau,t; REAL del_trace,del_inj,del_streak,del_vec; REAL pos1x,pos2x,pos1y,pos2y; int imax,jmax,wW,wE,wN,wS,itermax,itersor=0,write,N; REAL Re,Pr,GX,GY,UI,VI,TI,beta; REAL eps,omg,gamma,res; int p_bound; REAL **U,**V,**P,**PSI,**ZETA,**RHS,**F,**G, **TEMP, **HEAT; int **FLAG; int ppc,ifull=0,isurf=0,ibound=0; char problem[30]; char vecfile[30],tracefile[30],streakfile[30]; char infile[30],outfile[30]; struct particleline *Particlelines; int init_case, cycle; int a,j,i,pass,imeas,jmeas; REAL area,oldarea; time_t start = time(NULL); REAL xmeas,ymeas; xmeas = 3; //Here you can enter a point to ymeas = 12; //measure the P and V of over time. /* READ the parameters of the problem. */ /* Stop if problem type or inputfile are not defined */ /*----------------------------------------------------*/ if( READ_PARAMETER(Inputfile[1],problem, &xlength,&ylength,&imax,&jmax,&delx,&dely, &t_end,&delt,&tau, &del_trace,&del_inj,&del_streak,&del_vec, vecfile,tracefile,streakfile, infile,outfile, &N,&pos1x,&pos1y,&pos2x,&pos2y, &itermax,&eps,&omg,&gamma,&p_bound, &Re,&Pr,&beta,&GX,&GY,&UI,&VI,&TI, &wW,&wE,&wN,&wS) != 0 ) return(1); imeas = xmeas/delx; jmeas = ymeas/dely; /* Allocate memory for the arrays */ /*--------------------------------*/ U = RMATRIX(0,imax+1,0,jmax+1); V = RMATRIX(0,imax+1,0,jmax+1); F = RMATRIX(0,imax+1,0,jmax+1); G = RMATRIX(0,imax+1,0,jmax+1); P = RMATRIX(0,imax+1,0,jmax+1); TEMP = RMATRIX(0,imax+1,0,jmax+1); PSI = RMATRIX(0,imax,0,jmax); ZETA = RMATRIX(1,imax-1,1,jmax-1); HEAT = RMATRIX(0,imax,0,jmax); RHS = RMATRIX(0,imax+1,0,jmax+1); FLAG = IMATRIX(0,imax+1,0,jmax+1); ppc = 1; /* Read initial values from file "infile" */ /*----------------------------------------*/ init_case = READ_bin(U,V,P,TEMP,FLAG,imax,jmax,infile); if( init_case > 0 ) return(1); /* Error while reading "infile" */ if( init_case < 0 ){ /* Set initial values if */ /* "infile" is not specified */ INIT_UVP(problem,U,V,P,TEMP,imax,jmax,UI,VI,TI); INIT_FLAG(problem,FLAG,imax,jmax,delx,dely,&ibound); } /* Initialize particles for streaklines or particle tracing */ /*----------------------------------------------------------*/ if (strcmp(streakfile,"none") || strcmp(tracefile,"none")) Particlelines = SET_PARTICLES(N,pos1x,pos1y,pos2x,pos2y); /* Initialize particles for free boundary problems */ /*-------------------------------------------------*/ if (!strcmp(problem,"drop") || !strcmp(problem,"dam")/* || !strcmp(problem,"icecube")*/) Particlelines = INIT_PARTICLES(&N,imax,jmax,delx,dely,ppc,problem,U,V,P); SETBCOND(U,V,P,TEMP,FLAG,imax,jmax,wW,wE,wN,wS); SETSPECBCOND(problem,U,V,P,TEMP,imax,jmax,UI,VI); /* t i m e l o o p */ /*--------------------*/ t = 0.0; cycle = 0; for(pass = 1; pass <=2; pass++) { for(t,cycle; t < t_end; t+=delt,cycle++) { COMP_delt(&delt, t, imax, jmax, delx, dely, U, V, Re, Pr, tau, &write, del_trace, del_inj, del_streak, del_vec); /* Determine fluid cells for free boundary problems */ /* and set boundary values at free surface */ /*--------------------------------------------------*/ if (!strcmp(problem,"drop") || !strcmp(problem,"dam") || !strcmp(problem,"molding") || !strcmp(problem,"wave") || (pass==2 && !strcmp(problem,"icecube"))) { MARK_CELLS(FLAG,imax,jmax,delx,dely,&ifull,&isurf, N,Particlelines); SET_UVP_SURFACE(U,V,P,FLAG,GX,GY,imax,jmax,Re,delx,dely,delt); } else ifull = imax*jmax-ibound; /* Compute new temperature */ /*-------------------------*/ COMP_TEMP(U,V,TEMP,FLAG,imax,jmax,delt,delx,dely,gamma,Re,Pr); /* Compute tentative velocity field (F,G) */ /*----------------------------------------*/ COMP_FG(U,V,TEMP,F,G,FLAG,imax,jmax,delt,delx,dely,GX,GY,gamma,Re,beta); /* Compute right hand side for pressure equation */ /*-----------------------------------------------*/ COMP_RHS(F,G,RHS,FLAG,imax,jmax,delt,delx,dely); /* Debug Code */ /* printf ("\nGeometry of the fluid domain:\n\n"); for(j=jmax+1;j>=0;j--) { for(i=0;i<=imax+1;i++) printf("%d ", (int) P[i][j]); printf("\n"); } printf("\n\n"); scanf("%d", &a); */ /* End Debug */ /* Solve the pressure equation by successive over relaxation */ /*-----------------------------------------------------------*/ if (ifull > 0) itersor = POISSON(P,RHS,FLAG,imax,jmax,delx,dely, eps,itermax,omg,&res,ifull,p_bound); printf("t_end= %1.5g, t= %1.3e, delt= %1.1e, iterations %3d, res: %e, F-cells: %d, S-cells: %d, B-cells: %d\n", t_end, t+delt, delt, itersor,res,ifull,isurf,ibound); /* Compute the new velocity field */ /*--------------------------------*/ ADAP_UV(U,V,F,G,P,FLAG,imax,jmax,delt,delx,dely); /* Set boundary conditions */ /*-------------------------*/ SETBCOND(U,V,P,TEMP,FLAG,imax,jmax,wW,wE,wN,wS); /* Set special boundary conditions */ /* Overwrite preset default values */ /*---------------------------------*/ SETSPECBCOND(problem,U,V,P,TEMP,imax,jmax,UI,VI); if (!strcmp(problem,"drop") || !strcmp(problem,"dam") || !strcmp(problem,"molding") || !strcmp(problem,"wave") || (!strcmp(problem,"icecube") && pass==2)) SET_UVP_SURFACE(U,V,P,FLAG,GX,GY,imax,jmax,Re,delx,dely,delt); /* Write data for visualization */ /*------------------------------*/ area=0; for(i=0; i<=imax+1; i++) for(j=0; j<=jmax+1; j++) { if(j==jmeas && i==imeas){ WRITEPARAMS(P[i][j], t, "presdata.txt"); WRITEPARAMS(U[i][j], t, "veldata.txt", V[i][j]); } if((FLAG[i][j] & C_E) && j<(ylength/delx*.25)) area+=delx*dely; } if(t==0){ WRITEPARAMS(area, t, "voldata.txt"); } if(area!=oldarea) { WRITEPARAMS(area, t, "voldata.txt"); oldarea=area; } if ((write & 8) && strcmp(vecfile,"none")) { COMPPSIZETA(U,V,PSI,ZETA,FLAG,imax,jmax,delx,dely); COMP_HEAT(U,V,TEMP,HEAT,FLAG,Re,Pr,imax,jmax,delx,dely); OUTPUTVEC_bin(U,V,P,TEMP,PSI,ZETA,HEAT,FLAG,xlength,ylength, imax,jmax,vecfile); } if ((write & 8) && strcmp(outfile,"none")) WRITE_bin(U,V,P,TEMP,FLAG,imax,jmax,outfile); if ((strcmp(tracefile,"none")!=0) && pass==2) PARTICLE_TRACING(tracefile,t,imax,jmax,delx,dely,delt,U,V,FLAG, N,Particlelines,write); if (strcmp(streakfile,"none")) STREAKLINES(streakfile,write,imax,jmax,delx,dely,delt,t, U,V,FLAG,N,Particlelines); } t_end = 20; if(pass==1){ for(i=1;i<=imax;i++) for(j=1;j<=jmax;j++) FLAG[i][j] = C_F; Particlelines = INIT_PARTICLES(&N,imax,jmax,delx,dely,ppc,problem,U,V,P); } /* e n d o f t i m e l o o p */ } if (strcmp(vecfile,"none")) { COMPPSIZETA(U,V,PSI,ZETA,FLAG,imax,jmax,delx,dely); COMP_HEAT(U,V,TEMP,HEAT,FLAG,Re,Pr,imax,jmax,delx,dely); OUTPUTVEC_bin(U,V,P,TEMP,PSI,ZETA,HEAT,FLAG,xlength,ylength, imax,jmax,vecfile); } if (strcmp(outfile,"none")) WRITE_bin(U,V,P,TEMP,FLAG,imax,jmax,outfile); /* printf ("\nGeometry of the fluid domain:\n\n"); for(j=jmax+1;j>=0;j--) { for(i=0;i<=imax+1;i++) printf("%d ", (int) P[i][j]); printf("\n"); } printf("\n\n"); scanf("%d", &a); */ /* free memory */ /*-------------*/ FREE_RMATRIX(U,0,imax+1,0,jmax+1); FREE_RMATRIX(V,0,imax+1,0,jmax+1); FREE_RMATRIX(F,0,imax+1,0,jmax+1); FREE_RMATRIX(G,0,imax+1,0,jmax+1); FREE_RMATRIX(P,0,imax+1,0,jmax+1); FREE_RMATRIX(TEMP,0,imax+1,0,jmax+1); FREE_RMATRIX(PSI,0,imax,0,jmax); FREE_RMATRIX(ZETA,1,imax-1,1,jmax-1); FREE_RMATRIX(HEAT,0,imax,0,jmax); FREE_RMATRIX(RHS,0,imax+1,0,jmax+1); FREE_IMATRIX(FLAG,0,imax+1,0,jmax+1); printf("Program completed in "); printf("%f", difftime(time(NULL), start)); printf(" seconds\n"); printf("End of program\n"); return(0); }