static void mesh_run (mpi_context_t * mpi, p4est_connectivity_t * connectivity, int uniform, int compute_tree_index, int compute_level_lists, p4est_connect_type_t mesh_btype) { int mpiret; unsigned crc; long local_used[4], global_used[4]; p4est_t *p4est; p4est_ghost_t *ghost; p4est_mesh_t *mesh; user_data_t *ghost_data; p4est = p4est_new (mpi->mpicomm, connectivity, sizeof (user_data_t), init_fn, NULL); if (!uniform) p4est_vtk_write_file (p4est, NULL, P4EST_STRING "_mesh_new"); /* refinement */ if (uniform) { p4est_refine (p4est, 1, refine_uniform, init_fn); } else { p4est_refine (p4est, 1, refine_normal, init_fn); p4est_vtk_write_file (p4est, NULL, P4EST_STRING "_mesh_refined"); } /* balance */ p4est_balance (p4est, P4EST_CONNECT_FULL, init_fn); if (!uniform) p4est_vtk_write_file (p4est, NULL, P4EST_STRING "_mesh_balanced"); /* partition */ p4est_partition (p4est, 0, NULL); if (!uniform) { p4est_vtk_write_file (p4est, NULL, P4EST_STRING "_mesh_partition"); } crc = p4est_checksum (p4est); /* print and verify forest checksum */ P4EST_GLOBAL_STATISTICSF ("Tree %s checksum 0x%08x\n", uniform ? "uniform" : "adapted", crc); /* create ghost layer and mesh */ ghost = p4est_ghost_new (p4est, P4EST_CONNECT_FULL); ghost_data = P4EST_ALLOC (user_data_t, ghost->ghosts.elem_count); p4est_ghost_exchange_data (p4est, ghost, ghost_data); mesh = p4est_mesh_new_ext (p4est, ghost, compute_tree_index, compute_level_lists, mesh_btype); test_mesh (p4est, ghost, mesh, compute_tree_index, compute_level_lists, mesh_btype, ghost_data, uniform); /* compute memory used */ local_used[0] = (long) p4est_connectivity_memory_used (p4est->connectivity); local_used[1] = (long) p4est_memory_used (p4est); local_used[2] = (long) p4est_ghost_memory_used (ghost); local_used[3] = (long) p4est_mesh_memory_used (mesh); mpiret = sc_MPI_Allreduce (local_used, global_used, 4, sc_MPI_LONG, sc_MPI_SUM, mpi->mpicomm); SC_CHECK_MPI (mpiret); P4EST_GLOBAL_PRODUCTIONF ("Total %s memory used %ld %ld %ld %ld\n", uniform ? "uniform" : "adapted", global_used[0], global_used[1], global_used[2], global_used[3]); /* destroy ghost layer and mesh */ P4EST_FREE (ghost_data); p4est_mesh_destroy (mesh); p4est_ghost_destroy (ghost); /* destroy the p4est structure */ p4est_destroy (p4est); }
int main(int argc, char *argv[]) { int mpiret; sc_MPI_Comm mpicomm; int proc_size; p4est_connectivity_t *conn; p4est_geometry_t *geom; p4est_t* p4est; int seed = time(NULL); srand(seed); /* MPI init */ mpiret = sc_MPI_Init(&argc, &argv); SC_CHECK_MPI(mpiret); mpicomm = sc_MPI_COMM_WORLD; sc_init (mpicomm, 1, 1, NULL, SC_LP_ESSENTIAL); mpiret = MPI_Comm_size(mpicomm, &proc_size); SC_CHECK_MPI (mpiret); /* pXest init */ p4est_init(NULL, SC_LP_PRODUCTION); conn = p4est_connectivity_new_disk(); /* geom = p4est_geometry_new_connectivity(conn); */ geom = p4est_geometry_new_disk(conn,1.,2.); p4est = p4est_new_ext (mpicomm, conn, -1, 0, 1, sizeof(curved_element_data_t), NULL, NULL); int world_rank,world_size; sc_MPI_Comm_rank(sc_MPI_COMM_WORLD, &world_rank); sc_MPI_Comm_size(sc_MPI_COMM_WORLD, &world_size); /* start just-in-time dg-math */ dgmath_jit_dbase_t* dgmath_jit_dbase = dgmath_jit_dbase_init(); geometric_factors_t* geometric_factors = geometric_factors_init(p4est); curved_element_data_init(p4est, geometric_factors, dgmath_jit_dbase, geom, 4); /* int local_nodes = curved_element_data_get_local_nodes(p4est); */ /* double* u = P4EST_ALLOC(double, local_nodes); */ /* for (int i = 0; i < local_nodes; i++){ */ /* /\* u = x *\/ */ /* u[i] = geometric_factors->xyz[i]; */ /* } */ int num_of_refinements = 2; /* p4est_vtk_write_all */ /* (p4est, */ /* geom, */ /* 0.99, */ /* 1, */ /* 1, */ /* 1, */ /* 0, */ /* 0, */ /* 0, */ /* "disk0" */ /* ); */ for (int i = 0; i < num_of_refinements; i++){ p4est_refine_ext (p4est, 0, -1, random_h_refine, NULL, refine_uniform_replace_callback); p4est_balance_ext(p4est, P4EST_CONNECT_FACE, NULL, refine_uniform_replace_callback); /* p4est_vtk_write_all */ /* (p4est, */ /* geom, */ /* 0.99, */ /* 1, */ /* 1, */ /* 1, */ /* 0, */ /* 0, */ /* 0, */ /* "disk" */ /* ); */ } curved_element_data_init(p4est, geometric_factors, dgmath_jit_dbase, geom, -1); int local_nodes = curved_element_data_get_local_nodes(p4est); double* u = P4EST_ALLOC(double, local_nodes); for (int i = 0; i < local_nodes; i++){ /* u = x */ u[i] = geometric_factors->xyz[i]; } /* curved_element_data_init(p4est, geometric_factors, dgmath_jit_dbase, geom, -1); */ /* store vector */ curved_element_data_copy_from_vec_to_storage ( p4est, u ); test_curved_data_t test_curved_data; test_curved_data.mortar_err = 0.; test_curved_data.hanging_proj_err = 0.; test_curved_data.full_proj_err = 0.; test_curved_data.print_data = 1; test_curved_data.no_reorient = 0; test_curved_data.geom = geom; p4est_ghost_t* ghost = p4est_ghost_new (p4est, P4EST_CONNECT_FACE); /* create space for storing the ghost data */ curved_element_data_t* ghost_data = P4EST_ALLOC (curved_element_data_t, ghost->ghosts.elem_count); p4est_ghost_exchange_data (p4est, ghost, ghost_data); curved_compute_flux_user_data_t curved_compute_flux_user_data; curved_compute_flux_user_data.dgmath_jit_dbase = dgmath_jit_dbase; curved_flux_fcn_ptrs_t flux_fcns = (test_curved_data_fetch_fcns(&test_curved_data)); curved_compute_flux_user_data.flux_fcn_ptrs = &flux_fcns; p4est->user_pointer = &curved_compute_flux_user_data; p4est_iterate (p4est, ghost, (void *) ghost_data, NULL, curved_compute_flux_on_local_elements, #if (P4EST_DIM)==3 NULL, #endif NULL); test_curved_data.mortar_err = 0.; if (world_rank == 0) printf("mortar_err = %.20f\n", test_curved_data.mortar_err ); p4est_ghost_destroy (ghost); P4EST_FREE (ghost_data); ghost = NULL; ghost_data = NULL; /* curved_hp_amr(p4est, */ /* &u, */ /* test_nonconform_random_hp, */ /* NULL, */ /* NULL, */ /* NULL, */ /* dgmath_jit_dbase */ /* ); */ /* curved_element_data_init(p4est, geometric_factors, dgmath_jit_dbase, geom, -1); */ /* double* u_vertex = P4EST_ALLOC(double, p4est->local_num_quadrants*(P4EST_CHILDREN)); */ /* element_data_store_nodal_vec_in_vertex_array */ /* ( */ /* p4est, */ /* u, */ /* u_vertex */ /* ); */ /* char sol_save_as [500]; */ /* sprintf(sol_save_as, "%s_test_nonconform_sym_level_%d_u", P4EST_STRING, i); */ /* curved_hacked_p4est_vtk_write_all */ /* (p4est, */ /* NULL, */ /* 0.99, */ /* 0, */ /* 1, */ /* 1, */ /* 0, */ /* 1, */ /* 0, */ /* sol_save_as, */ /* "u", */ /* u_vertex */ /* ); */ /* P4EST_FREE(u_vertex); */ /* ip_flux_params_t ip_flux_params; */ /* ip_flux_params.ip_flux_penalty_prefactor = atoi(argv[6]); */ /* ip_flux_params.ip_flux_penalty_calculate_fcn = sipg_flux_vector_calc_penalty_maxp2_over_minh; */ /* problem_data_t vecs; */ /* vecs.u = u; */ /* vecs.local_nodes = element_data_get_local_nodes(p4est); */ /* vecs.vector_flux_fcn_data = sipg_flux_vector_dirichlet_fetch_fcns */ /* ( */ /* zero_fcn, */ /* &ip_flux_params */ /* ); */ /* vecs.scalar_flux_fcn_data = sipg_flux_scalar_dirichlet_fetch_fcns(zero_fcn); */ /* weakeqn_ptrs_t fcns; */ /* fcns.apply_lhs = poisson_apply_aij; */ /* matrix_sym_tester */ /* ( */ /* p4est, */ /* &vecs, /\* only needed for # of nodes *\/ */ /* &fcns, */ /* .000000000000001, */ /* dgmath_jit_dbase, */ /* 0, */ /* 0 */ /* ); */ /* } */ P4EST_FREE(u); geometric_factors_destroy(geometric_factors); /* free pointers */ dgmath_jit_dbase_destroy(dgmath_jit_dbase); /* free pXest */ p4est_destroy(p4est); /* p4est_destroy(p4est); */ if (geom != NULL) { p4est_geometry_destroy (geom); } p4est_connectivity_destroy(conn); /* finalize mpi stuff */ sc_finalize(); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI(mpiret); }
/** Timestep the advection problem. * * Update the state, refine, repartition, and write the solution to file. * * \param [in,out] p4est the forest, whose state is updated * \param [in] time the end time */ static void step3_timestep (p4est_t * p4est, double time) { double t = 0.; double dt = 0.; int i; step3_data_t *ghost_data; step3_ctx_t *ctx = (step3_ctx_t *) p4est->user_pointer; int refine_period = ctx->refine_period; int repartition_period = ctx->repartition_period; int write_period = ctx->write_period; int recursive = 0; int allowed_level = P4EST_QMAXLEVEL; int allowcoarsening = 1; int callbackorphans = 0; int mpiret; double orig_max_err = ctx->max_err; double umax, global_umax; p4est_ghost_t *ghost; /* create the ghost quadrants */ ghost = p4est_ghost_new (p4est, P4EST_CONNECT_FULL); /* create space for storing the ghost data */ ghost_data = P4EST_ALLOC (step3_data_t, ghost->ghosts.elem_count); /* synchronize the ghost data */ p4est_ghost_exchange_data (p4est, ghost, ghost_data); /* initialize du/dx estimates */ p4est_iterate (p4est, ghost, (void *) ghost_data, /* pass in ghost data that we just exchanged */ step3_reset_derivatives, /* blank the previously calculated derivatives */ step3_minmod_estimate, /* compute the minmod estimate of each cell's derivative */ #ifdef P4_TO_P8 NULL, /* there is no callback for the edges between quadrants */ #endif NULL); /* there is no callback for the corners between quadrants */ for (t = 0., i = 0; t < time; t += dt, i++) { P4EST_GLOBAL_PRODUCTIONF ("time %f\n", t); /* refine */ if (!(i % refine_period)) { if (i) { /* compute umax */ umax = 0.; /* initialize derivative estimates */ p4est_iterate (p4est, NULL, (void *) &umax, /* pass in ghost data that we just exchanged */ step3_compute_max, /* blank the previously calculated derivatives */ NULL, /* there is no callback for the faces between quadrants */ #ifdef P4_TO_P8 NULL, /* there is no callback for the edges between quadrants */ #endif NULL); /* there is no callback for the corners between quadrants */ mpiret = sc_MPI_Allreduce (&umax, &global_umax, 1, sc_MPI_DOUBLE, sc_MPI_MAX, p4est->mpicomm); SC_CHECK_MPI (mpiret); ctx->max_err = orig_max_err * global_umax; P4EST_GLOBAL_PRODUCTIONF ("u_max %f\n", global_umax); /* adapt */ p4est_refine_ext (p4est, recursive, allowed_level, step3_refine_err_estimate, NULL, step3_replace_quads); p4est_coarsen_ext (p4est, recursive, callbackorphans, step3_coarsen_err_estimate, NULL, step3_replace_quads); p4est_balance_ext (p4est, P4EST_CONNECT_FACE, NULL, step3_replace_quads); p4est_ghost_destroy (ghost); P4EST_FREE (ghost_data); ghost = NULL; ghost_data = NULL; } dt = step3_get_timestep (p4est); } /* repartition */ if (i && !(i % repartition_period)) { p4est_partition (p4est, allowcoarsening, NULL); if (ghost) { p4est_ghost_destroy (ghost); P4EST_FREE (ghost_data); ghost = NULL; ghost_data = NULL; } } /* write out solution */ if (!(i % write_period)) { step3_write_solution (p4est, i); } /* synchronize the ghost data */ if (!ghost) { ghost = p4est_ghost_new (p4est, P4EST_CONNECT_FULL); ghost_data = P4EST_ALLOC (step3_data_t, ghost->ghosts.elem_count); p4est_ghost_exchange_data (p4est, ghost, ghost_data); } /* compute du/dt */ /* *INDENT-OFF* */ p4est_iterate (p4est, /* the forest */ ghost, /* the ghost layer */ (void *) ghost_data, /* the synchronized ghost data */ step3_quad_divergence, /* callback to compute each quad's interior contribution to du/dt */ step3_upwind_flux, /* callback to compute each quads' faces' contributions to du/du */ #ifdef P4_TO_P8 NULL, /* there is no callback for the edges between quadrants */ #endif NULL); /* there is no callback for the corners between quadrants */ /* *INDENT-ON* */ /* update u */ p4est_iterate (p4est, NULL, /* ghosts are not needed for this loop */ (void *) &dt, /* pass in dt */ step3_timestep_update, /* update each cell */ NULL, /* there is no callback for the faces between quadrants */ #ifdef P4_TO_P8 NULL, /* there is no callback for the edges between quadrants */ #endif NULL); /* there is no callback for the corners between quadrants */ /* synchronize the ghost data */ p4est_ghost_exchange_data (p4est, ghost, ghost_data); /* update du/dx estimate */ p4est_iterate (p4est, ghost, (void *) ghost_data, /* pass in ghost data that we just exchanged */ step3_reset_derivatives, /* blank the previously calculated derivatives */ step3_minmod_estimate, /* compute the minmod estimate of each cell's derivative */ #ifdef P4_TO_P8 NULL, /* there is no callback for the edges between quadrants */ #endif NULL); /* there is no callback for the corners between quadrants */ } P4EST_FREE (ghost_data); p4est_ghost_destroy (ghost); }