void init(double *f, double *Q0) { int i, j, k, ii, jj, ip, jp, kp, im, jm, km, index; int points = Nx*Ny*Nz; //For hybrid initial condition double theta0, theta, thetalocal, lambda1, lambda2, thetalocali, nlocal[3]={0}; theta0 = ntop[0]*nbot[0]+ntop[1]*nbot[1]+ntop[2]*nbot[2]; theta0 = theta0/sqrt(ntop[0]*ntop[0]+ntop[1]*ntop[1]+ntop[2]*ntop[2]); theta0 = theta0/sqrt(nbot[0]*nbot[0]+nbot[1]*nbot[1]+nbot[2]*nbot[2]); theta0 = acos(theta0); if(newrun==1){ for(i=0;i<(points);i++) Rho[i] = rho; for (k=0; k<Nz; k++) { for (j=0; j<Ny; j++) { for (i=0; i<Nx; i++) { index = i + Nx*j + Ny*Nx*k; if(cav_on && cav_flag[index]==-1){ //for(ii=0;ii<3;ii++) u[3*index+ii] = 0; u[3*index+0] = 0; u[3*index+1] = uy_top*((double)k+0.5)/((double)Nz); u[3*index+2] = 0; } k_eng += 0.5*( u[3*index+0]*+u[3*index+0] + u[3*index+1]*+u[3*index+1] + u[3*index+2]*+u[3*index+2])*Rho[index]; if(Q_on || (cav_on && cav_flag[index]>=0)){ if(rand_init){ double randx, randy, randz; randx = randvec(); randy = randvec(); randz = randvec(); double mag = randx*randx + randy*randy + randz*randz; mag = sqrt(mag); randx /= mag; randy /= mag; randz /= mag; double Srand = 0.5*S; Q0[5*index+0] = Srand*(randx*randx - third); Q0[5*index+1] = Srand*(randx*randy); Q0[5*index+2] = Srand*(randx*randz); Q0[5*index+3] = Srand*(randy*randy - third); Q0[5*index+4] = Srand*(randy*randz); } else { if (theta0<1e-2 && theta0>-1e-2) { lambda1 = 0.5; lambda2 = 0.5; } else { theta = theta0 * ((double)k+0.5)/((double)Nz); lambda1=(cos(theta)-cos(theta0)*cos(theta0-theta)); lambda2=(cos(theta0-theta)-cos(theta)*cos(theta0)); } nlocal[0] = lambda1 * nbot[0] + lambda2 * ntop[0]; nlocal[1] = lambda1 * nbot[1] + lambda2 * ntop[1]; nlocal[2] = lambda1 * nbot[2] + lambda2 * ntop[2]; thetalocal = nlocal[0]*nlocal[0] + nlocal[1]*nlocal[1] + nlocal[2]*nlocal[2]; thetalocali= 1.0/thetalocal; Q0[5*index+0] = S*(nlocal[0]*nlocal[0]*thetalocali - third); Q0[5*index+1] = S*(nlocal[0]*nlocal[1]*thetalocali); Q0[5*index+2] = S*(nlocal[0]*nlocal[2]*thetalocali); Q0[5*index+3] = S*(nlocal[1]*nlocal[1]*thetalocali - third); Q0[5*index+4] = S*(nlocal[1]*nlocal[2]*thetalocali); } } } } } //For finite anchoring for(i=0;i<Nx;i++){ for(j=0;j<Ny;j++){ index = i + j*Nx; if(!rand_init){ Qsurfbot[5*index+0] = S*(nbot[0]*nbot[0] - third); Qsurfbot[5*index+1] = S*(nbot[0]*nbot[1]); Qsurfbot[5*index+2] = S*(nbot[0]*nbot[2]); Qsurfbot[5*index+3] = S*(nbot[1]*nbot[1] - third); Qsurfbot[5*index+4] = S*(nbot[1]*nbot[2]); Qsurftop[5*index+0] = S*(ntop[0]*ntop[0] - third); Qsurftop[5*index+1] = S*(ntop[0]*ntop[1]); Qsurftop[5*index+2] = S*(ntop[0]*ntop[2]); Qsurftop[5*index+3] = S*(ntop[1]*ntop[1] - third); Qsurftop[5*index+4] = S*(ntop[1]*ntop[2]); } if(rand_init){ double randx, randy, randz; randx = randvec(); randy = randvec(); randz = randvec(); double mag = randx*randx + randy*randy + randz*randz; mag = sqrt(mag); randx /= mag; randy /= mag; randz /= mag; double Srand = 0.5*S; Qsurfbot[5*index+0] = Srand*(randx*randx - third); Qsurfbot[5*index+1] = Srand*(randx*randy); Qsurfbot[5*index+2] = Srand*(randx*randz); Qsurfbot[5*index+3] = Srand*(randy*randy - third); Qsurfbot[5*index+4] = Srand*(randy*randz); randx = randvec(); randy = randvec(); randz = randvec(); mag = sqrt(mag); randx /= mag; randy /= mag; randz /= mag; Qsurftop[5*index+0] = Srand*(randx*randx - third); Qsurftop[5*index+1] = Srand*(randx*randy); Qsurftop[5*index+2] = Srand*(randx*randz); Qsurftop[5*index+3] = Srand*(randy*randy - third); Qsurftop[5*index+4] = Srand*(randy*randz); } } } } else read_restart(Q0,Rho,u); //Preferred anchoring Qo_bottom[0] = S*(nbot[0]*nbot[0] - third); Qo_bottom[1] = S*(nbot[0]*nbot[1]); Qo_bottom[2] = S*(nbot[0]*nbot[2]); Qo_bottom[3] = S*(nbot[1]*nbot[1] - third); Qo_bottom[4] = S*(nbot[1]*nbot[2]); Qo_top[0] = S*(ntop[0]*ntop[0] - third); Qo_top[1] = S*(ntop[0]*ntop[1]); Qo_top[2] = S*(ntop[0]*ntop[2]); Qo_top[3] = S*(ntop[1]*ntop[1] - third); Qo_top[4] = S*(ntop[1]*ntop[2]); //populate Q for sides of cavity Qtop[0] = S*(ncavtop[0]*ncavtop[0] - third); Qtop[1] = S*(ncavtop[0]*ncavtop[1]); Qtop[2] = S*(ncavtop[0]*ncavtop[2]); Qtop[3] = S*(ncavtop[1]*ncavtop[1] - third); Qtop[4] = S*(ncavtop[1]*ncavtop[2]); Qsides[0] = S*(ncavsides[0]*ncavsides[0] - third); Qsides[1] = S*(ncavsides[0]*ncavsides[1]); Qsides[2] = S*(ncavsides[0]*ncavsides[2]); Qsides[3] = S*(ncavsides[1]*ncavsides[1] - third); Qsides[4] = S*(ncavsides[1]*ncavsides[2]); cal_dQ(Q0); // if(!newrun){ // cal_stress(Q0); // cal_dtau(Q0); // } cal_sigma(); cal_fequ(f,u); cal_W(); }
void make_mesh() { int ind; // The global index double start_time, end_time; int precond_count=0, restart_count; cout<<"The no. of MG levels "<<mg_levels<<"\n"; /*vector<vertex> node (tot_p); vector<fval> fvar (tot_p); vector<mg_grid> level(mg_levels);*/ vertex * node = new vertex[tot_p]; fval * fvar = new fval[tot_p]; mg_grid * level = new mg_grid[mg_levels]; pbcs pbc; for(int j=0;j<=ny;j++) //Grid generation { for(int i=0;i<=nx;i++) { ind = i + j*str_x; node[ind].x[0] = i*dx; node[ind].x[1] = j*dy; } } omp_set_num_threads(num_threads); if(restart==0) { initialize(node,fvar); mg_initialize(level); restart_count=0; } else { read_restart(fvar,restart_count); mg_restart(fvar,level); } /***Standalone Direct solver***/ /*int lev=0; int nx_level = nx/pow(2,lev)-1; int ny_level = ny/pow(2,lev)-1; mg_coeff(); //Coefficients for smoothing operator at all levels mg_read_coeff(level); //Reading the null space vectors for all grid sizes compute_pbc(pbc,1); mg_evaluate_rhs(level,lev,pbc); mg_compute_rhs_tot(level,lev); double rhs_sum = mg_eval_rhs_sum(level,lev); level[lev].point_correc = rhs_sum/(nx_level*ny_level); cout<<"The RHS sum = "<<rhs_sum<<"\n"; cout<<"The point correction = "<<level[lev].point_correc<<"\n"; //arma_direct_solve(level,lev); arma_direct_trunc(level,lev); mg_bcs_neu(level,0,pbc); mg_final(level,fvar,0); write_to_file(node,fvar); cout<<"The error norm: "<<error_calc(fvar,0)<<"\n"; write_restart(fvar,0);*/ /***Standalone CG Solver****/ /*mg_coeff(); // Coefficients for smoothing operator at all levels mg_read_coeff(level); // Reading the null space vectors for all grid sizes compute_pbc(pbc,1); mg_interpolate(level,3,0); mg_conjugate_gradient(level,0, 100000, 0, 0, pbc); mg_bcs_neu(level,0,pbc); mg_final(level,fvar,0); write_to_file(node,fvar); write_restart(fvar,0); cout<<"The error norm: "<<error_calc(fvar,0)<<"\n";*/ /***Stand alone interpolation + level:2 testing + arma_direct***/ /*mg_coeff(); // Coefficients for smoothing operator at all levels mg_read_coeff(level); // Reading the null space vectors for all grid sizes compute_pbc(pbc,1); mg_interpolate(level,4); mg_interpolate(level,3); mg_conjugate_gradient(level,2, 4000, 0, 2, pbc); mg_bcs_neu(level,0,pbc); mg_final(level,fvar,0); write_to_file(node,fvar); write_restart(fvar,0); cout<<"The error norm: "<<error_calc(fvar)<<"\n";*/ /***V-cycle and FMG solvers*****/ /*mg_poisson_solver(level,fvar,pbc); write_to_file(node,fvar); write_restart(fvar,0); cout<<"The error norm: "<<error_calc(fvar,0)<<"\n";*/ /***Stand alone Bi-CGSTAB Solver***/ /*mg_coeff(); mg_read_coeff(level); // Reading the null space vectors for all grid sizes compute_pbc(pbc,1); mg_bicgstab_corn(level,0, 1000, 0, 0, pbc); mg_bcs_neu(level,0,pbc); mg_final(level,fvar,0); write_to_file(node,fvar); write_restart(fvar,0); cout<<"The error norm: "<<error_calc(fvar,0)<<"\n";*/ /***Computing the truncation error field***/ //The initial condition is an exact solution here /*int lev=0; mg_coeff(); mg_read_coeff(level); // Reading the null space vectors for all grid sizes compute_pbc(pbc,1); trunc_error_map(level,lev,pbc); mg_bcs_neu(level,lev,pbc); mg_final(level,fvar,lev); write_to_file(node,fvar); write_restart(fvar,lev);*/ /***Computation of truncation error from Direct solver***/ /*int lev=0; int nx_level = nx/pow(2,lev)-1; int ny_level = ny/pow(2,lev)-1; mg_coeff(); // Coefficients for smoothing operator at all levels mg_read_coeff(level); // Reading the null space vectors for all grid sizes compute_pbc(pbc,1); mg_evaluate_rhs(level,lev,pbc); mg_compute_rhs_tot(level,lev); arma_direct_trunc(level, lev); mg_bcs_neu(level,0,pbc); mg_final(level,fvar,0); write_to_file(node,fvar); cout<<"The error norm: "<<error_calc(fvar,0)<<"\n";*/ /******Computing for the flow********/ solver(node, fvar, level, pbc, restart_count); /* bcs(node,fvar); mg_clear_levels(level); poisson_source(fvar,level,4.0); compute_pbc(fvar,pbc,1); */ //mg_coeff(); // Coefficients for smoothing operator at all levels //mg_read_coeff(level); // Reading the null space vectors for all grid sizes //mg_bicgstab_corn(fvar, level, 0, 1, 1, 0, pbc); /*mg_poisson_solver(level,fvar,pbc); mg_final(level,fvar,0); tdma1x(fvar,2); tdma1y(fvar,2);*/ //write_to_file(node,fvar,0); //write_to_file(node,fvar); }
void init() { int i, j, k, ii, ip, id; time_t t; double nx, ny, nz, q[6], sita0, sita, lambda1, lambda2; if (newrun_on!=0) { if (myid==0) { sita0 = n_top[0]*n_bot[0]+n_top[1]*n_bot[1]+n_top[2]*n_bot[2]; sita0 = sita0/sqrt(n_top[0]*n_top[0]+n_top[1]*n_top[1]+n_top[2]*n_top[2]); sita0 = sita0/sqrt(n_bot[0]*n_bot[0]+n_bot[1]*n_bot[1]+n_bot[2]*n_bot[2]); sita0 = acos(sita0); if (rand_init==0) { // random random seed srand((unsigned)time(&t)); } else if (rand_init>0) { // random seed from input srand((unsigned)rand_seed); } if ( (wall_on!=0 || npar>0 || patch_on!=0) && Q_on!=0) { for (i=0; i<nsurf; i++) { if (rand_init>=0) { nx = randvec(); ny = randvec(); nz = randvec(); ntoq(nx, ny, nz, &q[0], &q[1], &q[2], &q[3], &q[4], &q[5]); for (j=0; j<5; j++) Qsurf[i*5+j] = q[j]; } else { for (j=0; j<5; j++) Qsurf[i*5+j] = surf[i*10+5+j]; } } } for (k=0; k<Nz; k++) { if (sita0<1e-2 && sita0>-1e-2) { lambda1 = 0.5; lambda2 = 0.5; } else { sita = sita0 * ((double)k+0.5)/((double)Nz); lambda1=(cos(sita)-cos(sita0)*cos(sita0-sita)); lambda2=(cos(sita0-sita)-cos(sita)*cos(sita0)); } nx = lambda1 * n_bot[0] + lambda2 * n_top[0]; ny = lambda1 * n_bot[1] + lambda2 * n_top[1]; nz = lambda1 * n_bot[2] + lambda2 * n_top[2]; for (j=0; j<Ny; j++) { for (i=0; i<Nx; i++) { id = (i + (j+k*Ny)*Nx); if (rand_init>=0) { nx = randvec(); ny = randvec(); nz = randvec(); } ntoq(nx, ny, nz, &q[0], &q[1], &q[2], &q[3], &q[4], &q[5]); for (ii=0; ii<5; ii++) Q[id*5+ii] = q[ii]; if (q[0]+q[3]+q[5]>1e-15 || q[0]+q[3]+q[5]<-1e-15 ) { printf("initial bulk Q not right\n"); exit(-1); } } } } if (flow_on!=0) { for (k=0; k<Nz; k++) { for (j=0; j<Ny; j++) { for (i=0; i<Nx; i++) { id = i + (j+k*Ny)*Nx; Rho[id] = rho; u[id*3] = 0; // u[id*3+1]= uy_bottom + (uy_top-uy_bottom)*((double)k+0.5)/(double)Nz; u[id*3+1]= 0; u[id*3+2]= 0; } } } } } } else { if (myid==0) read_restart(); } MPI_Barrier(MPI_COMM_WORLD); MPI_Win_fence(0, winq); MPI_Win_fence(0, winr); MPI_Win_fence(0, winu); if ( (wall_on!=0 || npar>0) && Q_on!=0 ) MPI_Win_fence(0, winQsurf); }
int main (int ac, char **av) { int rval = 0; tsp_bbnode *rootbbnode = (tsp_bbnode *) NULL; char *probname = (char *) NULL; double restart_upbound = 0.0; int restart_ncount = 0; int bbcount = 0; double branchzeit = 0.0; char format[1024]; double mod = -1.0; CCptrworld bbnode_world; CCptrworld_init (&bbnode_world); rval = parseargs (ac, av); if (rval) return 1; if (dig_before > 0) { int i; mod = 1.0; for (i=0; i<dig_before; i++) mod = mod * 10.0; sprintf (format, "%%0%d.%df", dig_before + dig_after + 1, dig_after); } else { mod = -1.0; sprintf (format, "%%.%df", dig_after); } rval = read_restart (resfname, &probname, &rootbbnode, &restart_upbound, &restart_ncount, &bbcount, &branchzeit, &bbnode_world); if (rval) { fprintf (stderr, "read_restart failed\n"); goto CLEANUP; } if (use_graphics) { rval = draw_tree (probname, restart_upbound, bbcount, branchzeit, arg_maxdepth, rootbbnode); if (rval) { fprintf (stderr, "draw_tree failed\n"); goto CLEANUP; } } else if (leafsummary || nodelist) { rval = report_leaves (probname, restart_upbound, bbcount, branchzeit, mod, format, rootbbnode, nodelist); if (rval) { fprintf (stderr, "report_leaves failed\n"); goto CLEANUP; } } else { rval = report_tree (probname, restart_upbound, bbcount, branchzeit, arg_maxdepth, mod, format, rootbbnode); if (rval) { fprintf (stderr, "report_tree failed\n"); goto CLEANUP; } } rval = 0; CLEANUP: CC_IFFREE (probname, char); free_tree (&rootbbnode, &bbnode_world); CCptrworld_delete (&bbnode_world); return rval; }