int main() { init(); double *fluxl = calculate_flux(ul,vl,rhol); double *fluxr = calculate_flux(ur,vr,rhor); riemann_roe_isothermal(fluxl, fluxr); free(fluxl); free (fluxr); return 0; }
void main() { long i, j, index, index_left, index_back, t; double div_flux; initialize(phi, mu, V); boundary( phi, mu, V); write2file(phi, mu, V, 0); for (t=0; t < ntimesteps; t++) { if (t%5==0) { printf("Iteration=%ld\n", t); } Gauss_siedel(phi, mu, V); //Finding the update in phi laplacian(phi, lap_phi); for (i=0; i < (MESHX); i++) { for (j=0; j < (MESHY); j++) { index = i*MESHY + j; deltaphi[index] = (deltat/(tau*epsilon)) *(2.0*(gamma*epsilon)*lap_phi[index] - 18.0*(gamma/epsilon)*(phi[index]*(1.0-phi[index])*(1.0-2.0*phi[index])) + (mu[index]-mu_eq)*6.0*(phi[index]*(1.0-phi[index]))); } } //Ending update of phi //Finding update in mu calculate_Ddcdmu(phi, mu, Ddcdmu); calculate_flux(phi, mu, V, grad_flux, Ddcdmu); for (i=1; i < (MESHX-1); i++) { for (j=1; j < (MESHY-1); j++) { index = i*MESHY + j; index_left = index - 1; index_back = index - MESHY; div_flux = (grad_flux[index][Y] - grad_flux[index_left][Y])*inv_deltay2; div_flux += (grad_flux[index][X] - grad_flux[index_back][X])*inv_deltax2; deltamu[index] = (deltat*div_flux - dc_dphi(phi[index], mu[index])*(deltaphi[index]))/dc_dmu(phi[index],mu[index]); } } //update in mu update(phi, mu); if(t%saveT==0) { write2file(phi, mu, V, t); } } }
void sweep( double state[3][N][M][2], double rho[N][M][2], double u[N][M][2], double v[N][M][2], double tstep, double xspacing, double cs, int N, int M, int offsetleft[2], int offsetright[2]) // ONE TIMESTEP { for(int i=0;i<N;i++) { for (int j=0;j<M;j++) { for (int k=0; k<3; k++) { state[k][i][j][1]=0; } rho[i][j][1] = 0; u[i][j][1] = 0; v[i][j][1] = 0; } } for(int i=0;i<N;i++) { for (int j=0;j<M;j++) { int left[2]; int right[2]; int cell[2]; cell[0] = i; cell[1] = j; for (int jj = 0; jj<2; jj++) {left[jj] = cell[jj] + offsetleft[jj]; right[jj] = cell[jj] + offsetright[jj];} // BOUNDARY CONDITIONS if (left[0] == -1) left[0] = N-1; if (right[0] == N) right[0] = 0; if (left[1] == -1) left[1] = M-1; if (right[1] == M) right[1] = 0; double uleft = u[left[0]][left[1]][0]; double uright = u[right[0]][right[1]][0]; double vleft = v[left[0]][left[1]][0]; double vright = v[right[0]][right[1]][0]; double rholeft = rho[left[0]][left[1]][0]; double rhoright = rho[right[0]][right[1]][0]; double *fluxl = calculate_flux(uleft,vleft,rholeft); double *fluxr = calculate_flux(u[i][j][0],v[i][j][0],rho[i][j][0]); double *fluxL = riemann_roe_isothermal(fluxl,fluxr,rholeft,uleft,vleft,rho[i][j][0],u[i][j][0],v[i][j][0]); double *fluxl2 = calculate_flux(u[i][j][0],v[i][j][0],rho[i][j][0]); double *fluxr2 = calculate_flux(uright,vright,rhoright); double *fluxR = riemann_roe_isothermal(fluxl2,fluxr2,rho[i][j][0],u[i][j][0],v[i][j][0],rhoright,uright,vright); for (int k=0; k<3; k++) { state[k][i][j][1] = state[k][i][j][0] + (tstep/xspacing)*(fluxL[k]-fluxR[k]); } rho[i][j][1] = state[0][i][j][1]; u[i][j][1] = state[1][i][j][1]/rho[i][j][1]; v[i][j][1] = state[2][i][j][1]/rho[i][j][1]; } } for(int i=0;i<N;i++) { for(int j=0; j<M;j++) { printf("%f ", rho[i][j][1]); } printf("\n"); } }