//============================================================================= // AMRD/PAMR code for equivarint (rotationally symmetric) wave map // // Lars Andersson, Matthew W Choptuik, 2007-- // //============================================================================= #include #include #include #include #include enum eqwm_abortvalues { ABORT_NONE, ABORT_SMAX }; //============================================================================= // Extra hook functions //============================================================================= void eqwm_pre_tstep(int L); //============================================================================= // Model parameters //============================================================================= real kappa; //============================================================================= // id parameters //============================================================================= real amp, r0, rwid, idsignum; //============================================================================= // In situ dissipation parameter //============================================================================= real epsdis; //============================================================================= // Other parameters //============================================================================= real s_threshold; int consrp; //============================================================================= // Convenient, "local" global variables //============================================================================= // Pointers to grid functions on specific (active) grid real *ph_n, *pi_n; real *ph_np1, *pi_np1; real *mask; real *ph_res, *pi_res; real *rh; // Vector of global norms real *g_norms; // Coordinate, bounding box etc. information real *r; // 'size' is total number of points in grid int shape[1], ghost_width[2], Nr, phys_bnd[2], size; real basebbox[2], bbox[2], dr, dt, t; // Level associated with grid int g_L; // Offsets into grid-function arrays for specific grid-functions int ph_n_gfn, pi_n_gfn; int ph_np1_gfn, pi_np1_gfn; int mask_gfn; int ph_res_gfn, pi_res_gfn; int rh_gfn; //============================================================================= // call after variables have been defined //============================================================================= void set_gfns(void) { if ((ph_n_gfn = PAMR_get_gfn("ph",PAMR_AMRH,2))<0) AMRD_stop("set_gnfs error",0); if ((ph_np1_gfn = PAMR_get_gfn("ph",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((pi_n_gfn = PAMR_get_gfn("pi",PAMR_AMRH,2))<0) AMRD_stop("set_gnfs error",0); if ((pi_np1_gfn = PAMR_get_gfn("pi",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((ph_res_gfn = PAMR_get_gfn("ph_res",PAMR_AMRH,1))<0) AMRD_stop("set_gnfs error",0); if ((pi_res_gfn = PAMR_get_gfn("pi_res",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 ((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[1],*gfs[PAMR_MAX_GFNS],dr0[1]; 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",""); ph_n = gfs[ph_n_gfn - 1]; ph_np1 = gfs[ph_np1_gfn - 1]; pi_n = gfs[pi_n_gfn - 1]; pi_np1 = gfs[pi_np1_gfn - 1]; ph_res = gfs[ph_res_gfn - 1]; pi_res = gfs[pi_res_gfn - 1]; mask = gfs[mask_gfn - 1]; rh = gfs[rh_gfn - 1]; r = x0[0]; dr = r[1]-r[0]; PAMR_get_g_level(&g_L); PAMR_get_g_t(&t); PAMR_get_dxdt(g_L,dr0,&dt); if ((bbox[0]-basebbox[0])0) { l2norm+=l2norm_ph/g_norms[ph_n_gfn-1]; num++; } if (g_norms[pi_n_gfn-1]>0) { l2norm+=l2norm_pi/g_norms[pi_n_gfn-1]; num++; } if (num>0) l2norm/=num; if( ltrace && (g_L == 1) ) { printf("eqwm_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 eqwm_MG_residual(void) { return 0; } //============================================================================= // Performs 1 iteration of the evolution equations // // Calls RNPL generated routine //============================================================================= void eqwm_evolve(int iter) { ldptr(); update0_(ph_np1,ph_n,pi_np1,pi_n,rh,&Nr,r,&dr,&dt,&epsdis,&kappa, phys_bnd,phys_bnd+1); } //============================================================================= // Performs 1 relaxation sweep of the MG equations, and returns an estimate // of the norm of the residual. //============================================================================= real eqwm_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 eqwm_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 eqwm_scale_tre(void) { return; } //============================================================================= // Called before taking a time step on level L. Implement constraint // projection here. // // Calls RNPL generated routine: cons_rp_ //============================================================================= void eqwm_pre_tstep(int L) { return; } void eqwm_post_tstep(int L) { return; } void eqwm_fill_ex_mask(real *mask, int dim, int *shape, real *bbox, real excised) { return; } //============================================================================= int main(int argc, char **argv) { amrd_set_app_pre_tstep_hook(eqwm_pre_tstep); amrd(argc,argv,&eqwm_id,&eqwm_var_pre_init, &eqwm_var_post_init, &eqwm_AMRH_var_clear, &eqwm_free_data, &eqwm_t0_cnst_data, &eqwm_evo_residual, &eqwm_MG_residual, &eqwm_evolve, &eqwm_MG_relax, &eqwm_L_op, &eqwm_pre_io_calc, &eqwm_scale_tre, &eqwm_post_regrid,&eqwm_post_tstep, &eqwm_fill_ex_mask,0); }