static void test_read_write(struct mrc_domain *domain) { struct mrc_io *io = mrc_io_create(mrc_domain_comm(domain)); mrc_io_set_from_options(io); mrc_io_setup(io); mrc_io_open(io, "w", 0, 0.); mrc_io_write_path(io, "/domain", "domain", domain); mrc_io_close(io); mrc_io_destroy(io); io = mrc_io_create(mrc_domain_comm(domain)); mrc_io_set_from_options(io); mrc_io_setup(io); mrc_io_open(io, "r", 0, 0.); struct mrc_domain *domain2 = mrc_io_read_path(io, "/domain", "domain", mrc_domain); mrc_io_close(io); mrc_io_destroy(io); mrctest_crds_compare(mrc_domain_get_crds(domain), mrc_domain_get_crds(domain2)); mrc_domain_destroy(domain2); }
static double ggcm_mhd_ic_harris_primitive(struct ggcm_mhd_ic *ic, int m, double crd[3]) { struct ggcm_mhd_ic_harris *sub = ggcm_mhd_ic_harris(ic); struct ggcm_mhd *mhd = ic->mhd; struct mrc_crds *crds = mrc_domain_get_crds(mhd->domain); double pert = sub->pert, cs_width = sub->cs_width; double xx = crd[0], yy = crd[1]; double xl[3], xh[3]; mrc_crds_get_param_double3(crds, "l", xl); mrc_crds_get_param_double3(crds, "h", xh); double lx = xh[0] - xl[0]; double ly = xh[1] - xl[1]; // FIXME, only right if cs_width == .5 (constant factor) ? double rr = sub->n_inf + sub->n_0 / sqr(cosh(yy/cs_width)); switch (m) { case RR: return rr; case PP: return .5 * rr; // B here won't actually be used because the vector potential takes preference case BX: return -pert * ( M_PI/ly) * cos(2*M_PI*xx/lx) * sin(M_PI*yy/ly) + sub->B_0 * tanh(yy/cs_width) - sub->B_0_bg; case BY: return -pert * (2.*M_PI/lx) * sin(2*M_PI*xx/lx) * cos(M_PI*yy/ly); default: return 0.; } }
struct mrc_domain * psc_setup_mrc_domain(struct psc *psc, int nr_patches) { if (psc_ops(psc)->setup_mrc_domain) { return psc_ops(psc)->setup_mrc_domain(psc, nr_patches); } // FIXME, should be split to create, set_from_options, setup time? struct mrc_domain *domain = mrc_domain_create(MPI_COMM_WORLD); // create a very simple domain decomposition int bc[3] = {}; for (int d = 0; d < 3; d++) { if (psc->domain.bnd_fld_lo[d] == BND_FLD_PERIODIC && psc->domain.gdims[d] > 1) { bc[d] = BC_PERIODIC; } } mrc_domain_set_type(domain, "multi"); if(psc->use_dynamic_patches) { psc_patchmanager_timestep(&psc->patchmanager); mrc_domain_set_param_ptr(domain, "activepatches", psc->patchmanager.activepatches); } mrc_domain_set_param_int3(domain, "m", psc->domain.gdims); mrc_domain_set_param_int(domain, "bcx", bc[0]); mrc_domain_set_param_int(domain, "bcy", bc[1]); mrc_domain_set_param_int(domain, "bcz", bc[2]); mrc_domain_set_param_int(domain, "nr_patches", nr_patches); mrc_domain_set_param_int3(domain, "np", psc->domain.np); struct mrc_crds *crds = mrc_domain_get_crds(domain); mrc_crds_set_type(crds, "uniform"); mrc_crds_set_param_int(crds, "sw", 2); mrc_crds_set_param_double3(crds, "l", (double[3]) { psc->domain.corner[0], psc->domain.corner[1], psc->domain.corner[2] });
int main(int argc, char **argv) { MPI_Init(&argc, &argv); libmrc_params_init(argc, argv); struct mrc_domain *domain = mrc_domain_create(MPI_COMM_WORLD); mrc_domain_set_type(domain, "simple"); struct mrc_crds *crds = mrc_domain_get_crds(domain); int testcase = 1; mrc_params_get_option_int("case", &testcase); switch (testcase) { case 1: mrc_crds_set_type(crds, "uniform"); mrc_domain_set_from_options(domain); mrc_domain_setup(domain); test_read_write(domain); break; case 2: ; mrc_crds_set_type(crds, "rectilinear"); mrc_crds_set_param_int(crds, "sw", 2); mrc_domain_set_from_options(domain); mrc_domain_setup(domain); mrctest_set_crds_rectilinear_1(domain); test_read_write(domain); break; } mrc_domain_destroy(domain); MPI_Finalize(); }
int main(int argc, char **argv) { const char *run = "test"; char grid2_fname[MAX_STRLEN]; char hgrid2_fname[MAX_STRLEN]; struct mrc_domain *mrc_domain; struct mrc_crds *mrc_crds; struct mrc_ndarray *nd; FILE *fout1; FILE *fout2; MPI_Init(&argc, &argv); libmrc_params_init(argc, argv); mrc_params_get_option_string("run", &run); snprintf(grid2_fname, MAX_STRLEN - 1, "%s.grid2", run); snprintf(hgrid2_fname, MAX_STRLEN - 1, "%s.hgrid2", run); mrc_domain = mrc_domain_create(MPI_COMM_WORLD); mrc_crds = mrc_domain_get_crds(mrc_domain); mrc_domain_set_from_options(mrc_domain); mrc_domain_setup(mrc_domain); // mrc_domain_view(mrc_domain); /////////////////////////////////////////// // write out a 'high precision' grid2 file fout1 = fopen(grid2_fname, "w"); fout2 = fopen(hgrid2_fname, "w"); for (int d=0; d < 3; d++) { nd = mrc_crds->global_crd[d]; fprintf(fout1, "%d\n", nd->dims.vals[0]); fprintf(fout2, "%d\n", nd->dims.vals[0]); for (int i = nd->nd_acc.beg[0]; i < nd->nd_acc.end[0]; i++) { fprintf(fout1, "%16.10g\n", MRC_D2(nd, i, 0)); fprintf(fout2, "%16.10g\n", MRC_D2(nd, i, 1)); } } fclose(fout1); fclose(fout2); mrc_domain_destroy(mrc_domain); MPI_Finalize(); return 0; }
static double ggcm_mhd_ic_harris_vector_potential(struct ggcm_mhd_ic *ic, int m, double crd[3]) { struct ggcm_mhd_ic_harris *sub = ggcm_mhd_ic_harris(ic); struct ggcm_mhd *mhd = ic->mhd; struct mrc_crds *crds = mrc_domain_get_crds(mhd->domain); double pert = sub->pert, cs_width = sub->cs_width; double xx = crd[0], yy = crd[1]; double xl[3], xh[3]; mrc_crds_get_param_double3(crds, "l", xl); mrc_crds_get_param_double3(crds, "h", xh); double lx = xh[0] - xl[0]; double ly = xh[1] - xl[1]; switch (m) { case 2: return pert * cos(2*M_PI*xx/lx) * cos(M_PI*yy/ly) + sub->B_0 * cs_width * log(cosh(yy/cs_width)) - sub->B_0_bg * yy; default: return 0.; } }
static double ggcm_mhd_ic_harris_asym_vector_potential(struct ggcm_mhd_ic *ic, int m, double crd[3]) { struct ggcm_mhd_ic_harris_asym *sub = ggcm_mhd_ic_harris_asym(ic); struct ggcm_mhd *mhd = ic->mhd; struct mrc_crds *crds = mrc_domain_get_crds(mhd->domain); double pert = sub->pert, B0 = sub->B0, B1 = sub->B1; double xx = crd[0], yy = crd[1]; double xl[3], xh[3]; mrc_crds_get_param_double3(crds, "l", xl); mrc_crds_get_param_double3(crds, "h", xh); double lx = xh[0] - xl[0]; double ly = xh[1] - xl[1]; switch (m) { case 2: return pert * cos(2*M_PI*xx/lx) * cos(M_PI*yy/ly) + (B1 - B0) / 2. * yy - (B1 + B0) / 2. * .5 * log(cosh(2.*yy)); default: return 0.; } }