//============================================================================= // // History: tkcsp (parallel Teukolsky eqn solver implemented by Frans // Pretorius UBC/Penn State Summer School on general relativstic hydro // // AMRD/PAMR code for wmap2d // // Lars Andersson, Matthew W Choptuik, 2007-- // //============================================================================= #include #include #include #include #include enum wmap2d_abortvalues { ABORT_NONE, ABORT_SMAX }; //============================================================================= // Extra hook functions //============================================================================= void wmap2d_pre_tstep(int L); //============================================================================= // Model parameters //============================================================================= real epsilon; //============================================================================= // id parameters //============================================================================= real amp, cx, cy, sx, sy; real cr, sr; real amp1, cr1, sr1, cy1; real amp2, cr2, sr2, cy2; //============================================================================= // Other parameters //============================================================================= real s_threshold; int consrp; //============================================================================= // Convenient, "local" global variables //============================================================================= // Pointers to grid functions on specific (active) grid real *u1_n, *u2_n, *u3_n, *pi1_n, *pi2_n, *pi3_n, *s_n; real *u1_np1, *u2_np1, *u3_np1, *pi1_np1, *pi2_np1, *pi3_np1, *s_np1; real *mask; real *u1_res, *u2_res, *u3_res, *pi1_res, *pi2_res, *pi3_res; real *temp1, *r, *rh, *phi, *sth, *cth, *cons; // Vector of global norms real *g_norms; // Coordinate, bounding box etc. information real *x, *y; // 'size' is total number of points in grid int shape[2], ghost_width[4], Nx, Ny, phys_bnd[4], size; real basebbox[4], bbox[4], dx, dy, dt, t; // Level associated with grid int g_L; // Offsets into grid-function arrays for specific grid-functions int u1_n_gfn, u2_n_gfn, u3_n_gfn, pi1_n_gfn, pi2_n_gfn, pi3_n_gfn, s_n_gfn; int u1_np1_gfn, u2_np1_gfn, u3_np1_gfn, pi1_np1_gfn, pi2_np1_gfn, pi3_np1_gfn, s_np1_gfn; int mask_gfn; int u1_res_gfn, u2_res_gfn, u3_res_gfn, pi1_res_gfn, pi2_res_gfn, pi3_res_gfn; int temp1_gfn, r_gfn, rh_gfn, phi_gfn, sth_gfn, cth_gfn, cons_gfn; //============================================================================= // call after variables have been defined //============================================================================= void set_gfns(void) { if ((u1_n_gfn = PAMR_get_gfn("u1",PAMR_AMRH,2))<0) AMRD_stop("set_gnfs error",0); if ((u1_np1_gfn = PAMR_get_gfn("u1",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((u2_n_gfn = PAMR_get_gfn("u2",PAMR_AMRH,2))<0) AMRD_stop("set_gnfs error",0); if ((u2_np1_gfn = PAMR_get_gfn("u2",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((u3_n_gfn = PAMR_get_gfn("u3",PAMR_AMRH,2))<0) AMRD_stop("set_gnfs error",0); if ((u3_np1_gfn = PAMR_get_gfn("u3",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((pi1_n_gfn = PAMR_get_gfn("pi1",PAMR_AMRH,2))<0) AMRD_stop("set_gnfs error",0); if ((pi1_np1_gfn = PAMR_get_gfn("pi1",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((pi2_n_gfn = PAMR_get_gfn("pi2",PAMR_AMRH,2))<0) AMRD_stop("set_gnfs error",0); if ((pi2_np1_gfn = PAMR_get_gfn("pi2",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((pi3_n_gfn = PAMR_get_gfn("pi3",PAMR_AMRH,2))<0) AMRD_stop("set_gnfs error",0); if ((pi3_np1_gfn = PAMR_get_gfn("pi3",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((s_n_gfn = PAMR_get_gfn("s",PAMR_AMRH,2))<0) AMRD_stop("set_gnfs error",0); if ((s_np1_gfn = PAMR_get_gfn("s",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((u1_res_gfn = PAMR_get_gfn("u1_res",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((u2_res_gfn = PAMR_get_gfn("u2_res",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((u3_res_gfn = PAMR_get_gfn("u3_res",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((pi1_res_gfn = PAMR_get_gfn("pi1_res",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((pi2_res_gfn = PAMR_get_gfn("pi2_res",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((pi3_res_gfn = PAMR_get_gfn("pi3_res",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((r_gfn = PAMR_get_gfn("r",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((rh_gfn = PAMR_get_gfn("rh",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((phi_gfn = PAMR_get_gfn("phi",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((sth_gfn = PAMR_get_gfn("sth",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((cth_gfn = PAMR_get_gfn("cth",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((cons_gfn = PAMR_get_gfn("cons",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((mask_gfn = PAMR_get_gfn("cmask",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); g_norms = AMRD_get_global_norms(); } //============================================================================= // call with valid iter to set up globals: //============================================================================= void ldptr(void) { int rank,dim,ngfs; real *x0[2],*gfs[PAMR_MAX_GFNS],dx0[2]; static int first = 1; if (first) { first = 0; set_gfns(); PAMR_get_global_bbox(basebbox); } if (!(PAMR_get_g_attribs(&rank,&dim,shape,bbox,ghost_width,&t,&ngfs,x0,gfs))) AMRD_stop("ldptr: PAMR_get_g_attribs failed\n",""); u1_n = gfs[u1_n_gfn - 1]; u1_np1 = gfs[u1_np1_gfn - 1]; u2_n = gfs[u2_n_gfn - 1]; u2_np1 = gfs[u2_np1_gfn - 1]; u3_n = gfs[u3_n_gfn - 1]; u3_np1 = gfs[u3_np1_gfn - 1]; pi1_n = gfs[pi1_n_gfn - 1]; pi1_np1 = gfs[pi1_np1_gfn - 1]; pi2_n = gfs[pi2_n_gfn - 1]; pi2_np1 = gfs[pi2_np1_gfn - 1]; pi3_n = gfs[pi3_n_gfn - 1]; pi3_np1 = gfs[pi3_np1_gfn - 1]; s_n = gfs[s_n_gfn - 1]; s_np1 = gfs[s_np1_gfn - 1]; pi1_res = gfs[pi1_res_gfn - 1]; pi2_res = gfs[pi2_res_gfn - 1]; pi3_res = gfs[pi3_res_gfn - 1]; mask = gfs[mask_gfn - 1]; temp1 = gfs[temp1_gfn - 1]; r = gfs[r_gfn - 1]; rh = gfs[rh_gfn - 1]; phi = gfs[phi_gfn - 1]; sth = gfs[sth_gfn - 1]; cth = gfs[cth_gfn - 1]; cons = gfs[cons_gfn - 1]; x = x0[0]; dx = x[1]-x[0]; y = x0[1]; dy = y[1]-y[0]; PAMR_get_g_level(&g_L); PAMR_get_g_t(&t); PAMR_get_dxdt(g_L,dx0,&dt); if ((bbox[0]-basebbox[0])0) { l2norm+=l2norm_pi1/g_norms[pi1_n_gfn-1]; num++; } if (g_norms[pi2_n_gfn-1]>0) { l2norm+=l2norm_pi2/g_norms[pi2_n_gfn-1]; num++; } if (g_norms[pi3_n_gfn-1]>0) { l2norm+=l2norm_pi3/g_norms[pi3_n_gfn-1]; num++; } if (num>0) l2norm/=num; if( ltrace && (g_L == 1) ) { printf("wmap2d_evo_residual: Returning l2norm=%g\n",l2norm); } return l2norm; } //============================================================================= // Returns some norm of the residual for the MG variables, *AND* // stores the point-wise residual in "f_res" for each MG variable "f" (for // computing new RHS's) //============================================================================= real wmap2d_MG_residual(void) { return 0; } //============================================================================= // Performs 1 iteration of the evolution equations // // Calls RNPL generated routine //============================================================================= void wmap2d_evolve(int iter) { ldptr(); update0_(u1_np1,u1_n,u2_np1,u2_n,u3_np1,u3_n,pi1_np1,pi1_n,pi2_np1,pi2_n, pi3_np1,pi3_n,s_np1,s_n,r,rh,cons,&Nx,&Ny,x,y,&dt,&dx,&dy,&epsilon, phys_bnd+1,phys_bnd,phys_bnd+3,phys_bnd+2); } //============================================================================= // Performs 1 relaxation sweep of the MG equations, and returns an estimate // of the norm of the residual. //============================================================================= real wmap2d_MG_relax(void) { return 0; } //============================================================================= // Computes the differential operator L acting on the current grid, // in a region specified by the grid function "mask". Stores the result // in "f_lop" for each MG variable "f" //============================================================================= void wmap2d_L_op(void) { return; } //============================================================================= // Called after calculating the TRE for all variables // // Here, we scale TRE by [csx*csy*csz]^n // // NOTE: USING AMRD GLOBAL POINTER VARIABLES HERE (so that we don't need // to keep track of which vars are used for the TRE) //============================================================================= void wmap2d_scale_tre(void) { return; } //============================================================================= // Called before taking a time step on level L. Implement constraint // projection here. // // Calls RNPL generated routine: cons_rp_ //============================================================================= void wmap2d_pre_tstep_old(int L) { int ltrace = 0; int valid; real s_max; valid = PAMR_init_s_iter(L,PAMR_AMRH,0); while( valid ) { ldptr(); if( consrp ) { cons_rp_(u1_np1,u1_n,u2_np1,u2_n,u3_np1,u3_n,s_np1,s_n, &Nx,&Ny,&t,&consrp,&s_max); if( my_rank == 0 ) printf("s_max=%g s_threshold=%g\n",s_max,s_threshold); } valid = PAMR_next_g(); } } //============================================================================= // Called before taking a time step on level L. Implement constraint // projection here. // // Calls RNPL generated routine: cons_rp_ //============================================================================= void wmap2d_pre_tstep(int L) { int ltrace = 0; int valid; real s_max; if( ltrace ) { printf("wmap2d_pre_step: In routine on level %d, consrp=%d\n",L,consrp); } valid = PAMR_init_s_iter(L,PAMR_AMRH,0); while( valid ) { ldptr(); if( consrp ) { cons_rp_(u1_np1,u1_n,u2_np1,u2_n,u3_np1,u3_n,s_np1,s_n, &Nx,&Ny,&t,&consrp,&s_max); if( my_rank == 0 ) printf("s_max=%g s_threshold=%g\n",s_max,s_threshold); if( s_max > s_threshold ) { printf("wmap2d_pre_tstep: Calling MPI_Abort on level %d grid on proc %d\n",L,my_rank); printf("wmap2d_pre_tstep: s_max(%g) > s_threshold(%g)\n", s_max,s_threshold); MPI_Abort(MPI_COMM_WORLD,ABORT_SMAX); } } valid = PAMR_next_g(); } } void wmap2d_post_tstep(int L) { } void wmap2d_fill_ex_mask(real *mask, int dim, int *shape, real *bbox, real excised) { } //============================================================================= int main(int argc, char **argv) { amrd_set_app_pre_tstep_hook(wmap2d_pre_tstep); amrd(argc,argv,&wmap2d_id,&wmap2d_var_pre_init, &wmap2d_var_post_init, &wmap2d_AMRH_var_clear, &wmap2d_free_data, &wmap2d_t0_cnst_data, &wmap2d_evo_residual, &wmap2d_MG_residual, &wmap2d_evolve, &wmap2d_MG_relax, &wmap2d_L_op, &wmap2d_pre_io_calc, &wmap2d_scale_tre, &wmap2d_post_regrid,&wmap2d_post_tstep, &wmap2d_fill_ex_mask,0); }