int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int size, rank; mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_size (mpicomm, &size); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpicomm, &rank); SC_CHECK_MPI (mpiret); sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); (void) check_backward_compatibility (); check_int_types (); #ifndef P4_TO_P8 check_all (mpicomm, p4est_connectivity_new_unitsquare (), "test_unitsquare", 0xef45243bU, 0xbc5d0907U); check_all (mpicomm, p4est_connectivity_new_rotwrap (), "test_rotwrap2", 0x266d2739U, 0x29a31248U); check_all (mpicomm, p4est_connectivity_new_corner (), "test_corner", 0x9dad92ccU, 0x937b27afU); check_all (mpicomm, p4est_connectivity_new_moebius (), "test_moebius", 0xbbc10f7fU, 0x09b6319eU); check_all (mpicomm, p4est_connectivity_new_star (), "test_star", 0xfb28233fU, 0x8e8a32b3); #else check_all (mpicomm, p8est_connectivity_new_unitcube (), "test_unitcube", 0x2574801fU, 0x312559a7U); check_all (mpicomm, p8est_connectivity_new_periodic (), "test_periodic3", 0xdc7e8a93U, 0x0787ca2dU); check_all (mpicomm, p8est_connectivity_new_rotwrap (), "test_rotwrap", 0xa675888dU, 0x626cbe90U); check_all (mpicomm, p8est_connectivity_new_twocubes (), "test_twocubes", 0x7188978aU, 0x4124bcabU); check_all (mpicomm, p8est_connectivity_new_twowrap (), "test_twowrap", 0x8e3f994cU, 0x9dd49e94); check_all (mpicomm, p8est_connectivity_new_rotcubes (), "test_rotcubes", 0xc0e1b235U, 0x974af07a); check_all (mpicomm, p8est_connectivity_new_shell (), "test_shell", 0x558723a2U, 0x4dedf35eU); check_all (mpicomm, p8est_connectivity_new_brick (2, 3, 4, 0, 0, 1), "test_brick", 0x82174e14U, 0x211da6c5); #endif /* clean up and exit */ sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { int mpiret; p4est_connectivity_t *conn_in, *conn_out; p4est_t *p4est; mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); #ifndef P4_TO_P8 conn_in = p4est_connectivity_new_cubed (); #else conn_in = p8est_connectivity_new_rotcubes (); #endif conn_out = p4est_connectivity_refine (conn_in, 5); p4est_connectivity_destroy (conn_in); p4est = p4est_new (sc_MPI_COMM_WORLD, conn_out, 0, NULL, NULL); p4est_vtk_write_file (p4est, NULL, P4EST_STRING "_test_connrefine"); p4est_destroy (p4est); p4est_connectivity_destroy (conn_out); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char *argv[]) { int mpiret; /* initialize MPI and p4est internals */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); #ifndef P4_TO_P8 test_reduce (p4est_connectivity_new_unitsquare (), "unitsquare"); test_reduce (p4est_connectivity_new_periodic (), "periodic"); test_reduce (p4est_connectivity_new_rotwrap (), "rotwrap"); test_reduce (p4est_connectivity_new_corner (), "corner"); test_reduce (p4est_connectivity_new_pillow (), "pillow"); test_reduce (p4est_connectivity_new_moebius (), "moebius"); test_reduce (p4est_connectivity_new_star (), "star"); test_reduce (p4est_connectivity_new_cubed (), "cubed"); test_reduce (p4est_connectivity_new_disk (), "disk"); test_reduce (p4est_connectivity_new_brick (3, 2, 0, 0), "brick00"); test_reduce (p4est_connectivity_new_brick (3, 2, 0, 1), "brick01"); test_reduce (p4est_connectivity_new_brick (3, 2, 1, 0), "brick10"); test_reduce (p4est_connectivity_new_brick (3, 2, 1, 1), "brick11"); #else test_reduce (p8est_connectivity_new_unitcube (), "unitcube"); test_reduce (p8est_connectivity_new_periodic (), "periodic"); test_reduce (p8est_connectivity_new_rotwrap (), "rotwrap"); test_reduce (p8est_connectivity_new_twocubes (), "twocubes"); test_reduce (p8est_connectivity_new_twowrap (), "twowrap"); test_reduce (p8est_connectivity_new_rotcubes (), "rotcubes"); test_reduce (p8est_connectivity_new_brick (4, 3, 2, 0, 0, 0), "brick000"); test_reduce (p8est_connectivity_new_brick (4, 3, 2, 0, 0, 1), "brick001"); test_reduce (p8est_connectivity_new_brick (4, 3, 2, 0, 1, 0), "brick010"); test_reduce (p8est_connectivity_new_brick (4, 3, 2, 0, 1, 1), "brick011"); test_reduce (p8est_connectivity_new_brick (4, 3, 2, 1, 0, 0), "brick100"); test_reduce (p8est_connectivity_new_brick (4, 3, 2, 1, 0, 1), "brick101"); test_reduce (p8est_connectivity_new_brick (4, 3, 2, 1, 1, 1), "brick111"); #endif /* clean up and exit */ sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { int mpiret; mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); #ifndef P4_TO_P8 test_complete (p4est_connectivity_new_unitsquare (), "unitsquare", 1); test_complete (p4est_connectivity_new_periodic (), "2D periodic", 0); test_complete (p4est_connectivity_new_rotwrap (), "rotwrap", 0); test_complete (p4est_connectivity_new_corner (), "corner", 1); test_complete (p4est_connectivity_new_moebius (), "moebius", 1); test_complete (p4est_connectivity_new_star (), "star", 1); test_complete (p4est_connectivity_new_brick (3, 18, 0, 1), "2D periodic brick", 0); test_complete (p4est_connectivity_new_brick (3, 18, 0, 0), "2D brick", 1); #else test_complete (p8est_connectivity_new_unitcube (), "unitcube", 1); test_complete (p8est_connectivity_new_periodic (), "3D periodic", 0); test_complete (p8est_connectivity_new_rotwrap (), "rotwrap", 0); test_complete (p8est_connectivity_new_twowrap (), "twowrap", 1); test_complete (p8est_connectivity_new_twocubes (), "twocubes", 1); test_complete (p8est_connectivity_new_rotcubes (), "rotcubes", 1); test_complete (p8est_connectivity_new_brick (3, 2, 8, 1, 0, 1), "3D periodic brick", 0); test_complete (p8est_connectivity_new_brick (3, 2, 8, 0, 0, 0), "3D brick", 1); #endif sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { int mpirank, mpisize; int mpiret; sc_MPI_Comm mpicomm; p4est_t *p4est; p4est_connectivity_t *connectivity; mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_size (mpicomm, &mpisize); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpicomm, &mpirank); SC_CHECK_MPI (mpiret); sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); /* create connectivity and forest structures */ #ifdef P4_TO_P8 connectivity = p8est_connectivity_new_rotcubes (); #else connectivity = p4est_connectivity_new_star (); #endif p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0, 1, NULL, NULL); p4est_refine_ext (p4est, 1, P4EST_QMAXLEVEL, refine_fn, NULL, replace_fn); p4est_coarsen_ext (p4est, 1, 0, coarsen_fn, NULL, replace_fn); p4est_balance_ext (p4est, P4EST_CONNECT_FULL, NULL, replace_fn); p4est_destroy (p4est); p4est_connectivity_destroy (connectivity); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { int mpiret; int wrongusage; unsigned crc; const char *usage; mpi_context_t mpi_context, *mpi = &mpi_context; p8est_t *p8est; p8est_connectivity_t *connectivity; p8est_geometry_t *geom; p8est_refine_t refine_fn; p8est_coarsen_t coarsen_fn; simple_config_t config; const simple_regression_t *r; /* initialize MPI and p4est internals */ mpiret = MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpi->mpicomm = MPI_COMM_WORLD; mpiret = MPI_Comm_size (mpi->mpicomm, &mpi->mpisize); SC_CHECK_MPI (mpiret); mpiret = MPI_Comm_rank (mpi->mpicomm, &mpi->mpirank); SC_CHECK_MPI (mpiret); sc_init (mpi->mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); /* process command line arguments */ usage = "Arguments: <configuration> <level>\n" " Configuration can be any of\n" " unit|periodic|rotwrap|twocubes|twowrap|rotcubes|shell|sphere\n" " Level controls the maximum depth of refinement\n"; wrongusage = 0; config = P8EST_CONFIG_NULL; if (!wrongusage && argc != 3) { wrongusage = 1; } if (!wrongusage) { if (!strcmp (argv[1], "unit")) { config = P8EST_CONFIG_UNIT; } else if (!strcmp (argv[1], "periodic")) { config = P8EST_CONFIG_PERIODIC; } else if (!strcmp (argv[1], "rotwrap")) { config = P8EST_CONFIG_ROTWRAP; } else if (!strcmp (argv[1], "twocubes")) { config = P8EST_CONFIG_TWOCUBES; } else if (!strcmp (argv[1], "twowrap")) { config = P8EST_CONFIG_TWOWRAP; } else if (!strcmp (argv[1], "rotcubes")) { config = P8EST_CONFIG_ROTCUBES; } else if (!strcmp (argv[1], "shell")) { config = P8EST_CONFIG_SHELL; } else if (!strcmp (argv[1], "sphere")) { config = P8EST_CONFIG_SPHERE; } else { wrongusage = 1; } } if (wrongusage) { P4EST_GLOBAL_LERROR (usage); sc_abort_collective ("Usage error"); } /* assign variables based on configuration */ refine_level = atoi (argv[2]); refine_fn = refine_normal_fn; coarsen_fn = NULL; /* create connectivity and forest structures */ geom = NULL; if (config == P8EST_CONFIG_PERIODIC) { connectivity = p8est_connectivity_new_periodic (); } else if (config == P8EST_CONFIG_ROTWRAP) { connectivity = p8est_connectivity_new_rotwrap (); } else if (config == P8EST_CONFIG_TWOCUBES) { connectivity = p8est_connectivity_new_twocubes (); refine_fn = refine_sparse_fn; } else if (config == P8EST_CONFIG_TWOWRAP) { connectivity = p8est_connectivity_new_twowrap (); refine_fn = refine_sparse_fn; } else if (config == P8EST_CONFIG_ROTCUBES) { connectivity = p8est_connectivity_new_rotcubes (); } else if (config == P8EST_CONFIG_SHELL) { connectivity = p8est_connectivity_new_shell (); geom = p8est_geometry_new_shell (1., .55); } else if (config == P8EST_CONFIG_SPHERE) { connectivity = p8est_connectivity_new_sphere (); geom = p8est_geometry_new_sphere (1., 0.191728, 0.039856); } else { connectivity = p8est_connectivity_new_unitcube (); } p8est = p8est_new_ext (mpi->mpicomm, connectivity, 1, 0, 0, sizeof (user_data_t), init_fn, NULL); #ifdef VTK_OUTPUT p8est_vtk_write_file (p8est, geom, "simple3_new"); #endif /* refinement and coarsening */ p8est_refine (p8est, 1, refine_fn, init_fn); if (coarsen_fn != NULL) { p8est_coarsen (p8est, 1, coarsen_fn, init_fn); } #ifdef VTK_OUTPUT p8est_vtk_write_file (p8est, geom, "simple3_refined"); #endif /* balance */ p8est_balance (p8est, P8EST_CONNECT_FULL, init_fn); #ifdef VTK_OUTPUT p8est_vtk_write_file (p8est, geom, "simple3_balanced"); #endif crc = p8est_checksum (p8est); /* partition */ p8est_partition (p8est, NULL); #ifdef VTK_OUTPUT p8est_vtk_write_file (p8est, geom, "simple3_partition"); #endif #ifdef P4EST_DEBUG /* rebalance should not change checksum */ p8est_balance (p8est, P8EST_CONNECT_FULL, init_fn); P4EST_ASSERT (p8est_checksum (p8est) == crc); #endif /* print and verify forest checksum */ P4EST_GLOBAL_STATISTICSF ("Tree checksum 0x%08x\n", crc); if (mpi->mpirank == 0) { for (r = regression; r->config != P8EST_CONFIG_NULL; ++r) { if (r->config != config || r->mpisize != mpi->mpisize || r->level != refine_level) continue; SC_CHECK_ABORT (crc == r->checksum, "Checksum mismatch"); P4EST_GLOBAL_INFO ("Checksum regression OK\n"); break; } } /* destroy the p8est and its connectivity structure */ p8est_destroy (p8est); P4EST_FREE (geom); p8est_connectivity_destroy (connectivity); /* clean up and exit */ sc_finalize (); mpiret = MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int mpisize, mpirank; unsigned crc; #ifndef P4_TO_P8 size_t kz; int8_t l; p4est_quadrant_t *q; p4est_tree_t stree, *tree = &stree; #endif p4est_t *p4est; p4est_connectivity_t *connectivity; /* initialize MPI */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_size (mpicomm, &mpisize); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpicomm, &mpirank); SC_CHECK_MPI (mpiret); sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); #ifndef P4_TO_P8 connectivity = p4est_connectivity_new_star (); #else connectivity = p8est_connectivity_new_rotcubes (); #endif p4est = p4est_new_ext (mpicomm, connectivity, 0, 0, 0, 4, NULL, NULL); #ifndef P4_TO_P8 /* build empty tree */ sc_array_init (&tree->quadrants, sizeof (p4est_quadrant_t)); for (l = 0; l <= P4EST_MAXLEVEL; ++l) { tree->quadrants_per_level[l] = 0; } tree->maxlevel = 0; /* insert two quadrants */ sc_array_resize (&tree->quadrants, 4); q = p4est_quadrant_array_index (&tree->quadrants, 0); p4est_quadrant_set_morton (q, 3, 13); q = p4est_quadrant_array_index (&tree->quadrants, 1); p4est_quadrant_set_morton (q, 1, 1); q = p4est_quadrant_array_index (&tree->quadrants, 2); p4est_quadrant_set_morton (q, 1, 2); q = p4est_quadrant_array_index (&tree->quadrants, 3); p4est_quadrant_set_morton (q, 1, 3); for (kz = 0; kz < tree->quadrants.elem_count; ++kz) { q = p4est_quadrant_array_index (&tree->quadrants, kz); q->p.user_data = sc_mempool_alloc (p4est->user_data_pool); ++tree->quadrants_per_level[q->level]; tree->maxlevel = (int8_t) SC_MAX (tree->maxlevel, q->level); } /* balance the tree, print and destroy */ #if 0 p4est_balance_subtree (p4est, P4EST_CONNECT_FULL, 0, NULL); p4est_tree_print (SC_LP_INFO, tree); #endif for (kz = 0; kz < tree->quadrants.elem_count; ++kz) { q = p4est_quadrant_array_index (&tree->quadrants, kz); sc_mempool_free (p4est->user_data_pool, q->p.user_data); } sc_array_reset (&tree->quadrants); #endif /* !P4_TO_P8 */ /* check reset data function */ p4est_reset_data (p4est, 0, init_fn, NULL); p4est_reset_data (p4est, 0, NULL, NULL); /* refine and balance the forest */ SC_CHECK_ABORT (p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 1"); p4est_refine (p4est, 1, refine_fn, NULL); SC_CHECK_ABORT (!p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 2"); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); SC_CHECK_ABORT (p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 3"); /* check reset data function */ p4est_reset_data (p4est, 17, NULL, NULL); p4est_reset_data (p4est, 8, init_fn, NULL); /* checksum and partition */ crc = p4est_checksum (p4est); p4est_partition (p4est, 0, NULL); SC_CHECK_ABORT (p4est_checksum (p4est) == crc, "Partition"); SC_CHECK_ABORT (p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 4"); /* check reset data function */ p4est_reset_data (p4est, 3, NULL, NULL); p4est_reset_data (p4est, 3, NULL, NULL); /* checksum and rebalance */ crc = p4est_checksum (p4est); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); SC_CHECK_ABORT (p4est_checksum (p4est) == crc, "Rebalance"); /* clean up and exit */ P4EST_ASSERT (p4est->user_data_pool->elem_count == (size_t) p4est->local_num_quadrants); p4est_destroy (p4est); p4est_connectivity_destroy (connectivity); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { int mpiret; sc_MPI_Comm mpicomm; p4est_t *p4est; p4est_connectivity_t *connectivity; p4est_locidx_t save_local_count; p4est_geometry_t *geom; mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); /* create connectivity and forest structures */ #ifdef P4_TO_P8 connectivity = p8est_connectivity_new_rotcubes (); geom = NULL; #else connectivity = p4est_connectivity_new_star (); geom = p4est_geometry_new_connectivity (connectivity); #endif p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0, 0, NULL, NULL); save_local_count = p4est->local_num_quadrants; refine_callback_count = 0; p4est_refine_ext (p4est, 0, 2, test_refine, NULL, NULL); SC_CHECK_ABORT (refine_callback_count == save_local_count, "Refine count"); refine_callback_count = 0; p4est_refine (p4est, 1, test_refine, NULL); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); coarsen_all = 1; p4est_coarsen_both (p4est, 0, test_coarsen, NULL); coarsen_all = 0; p4est_coarsen_both (p4est, 1, test_coarsen, NULL); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); coarsen_all = 1; p4est_coarsen_both (p4est, 1, test_coarsen, NULL); p4est_vtk_write_file (p4est, geom, P4EST_STRING "_endcoarsen"); if (p4est->mpisize == 1) { SC_CHECK_ABORT (p4est->global_num_quadrants == (p4est_gloidx_t) connectivity->num_trees, "Coarsen all"); } p4est_destroy (p4est); if (geom != NULL) { p4est_geometry_destroy (geom); } p4est_connectivity_destroy (connectivity); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int size, rank; unsigned crcF, crcC; p4est_connectivity_t *connectivity; p4est_t *p4est; p4est_t *p4estF, *p4estC; #ifdef P4_TO_P8 unsigned crcE; p4est_t *p4estE; #endif /* initialize */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_size (mpicomm, &size); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpicomm, &rank); SC_CHECK_MPI (mpiret); sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); /* create forest and refine */ #ifndef P4_TO_P8 connectivity = p4est_connectivity_new_star (); #else connectivity = p8est_connectivity_new_rotcubes (); #endif p4est = p4est_new_ext (mpicomm, connectivity, 0, 0, 0, 0, NULL, NULL); p4est_refine (p4est, 1, refine_fn, NULL); /* test face balance */ p4estF = p4est_copy (p4est, 0); #ifndef P4_TO_P8 p4est_balance (p4estF, P4EST_CONNECT_FACE, NULL); #else p4est_balance (p4estF, P8EST_CONNECT_FACE, NULL); #endif crcF = p4est_checksum (p4estF); P4EST_GLOBAL_INFOF ("Face balance with %lld quadrants and crc 0x%08x\n", (long long) p4estF->global_num_quadrants, crcF); #ifdef P4_TO_P8 /* test edge balance */ p4estE = p4est_copy (p4est, 1); p4est_balance (p4estF, P8EST_CONNECT_EDGE, NULL); p4est_balance (p4estE, P8EST_CONNECT_EDGE, NULL); crcE = p4est_checksum (p4estE); SC_CHECK_ABORT (crcE == p4est_checksum (p4estF), "mismatch A"); P4EST_GLOBAL_INFOF ("Edge balance with %lld quadrants and crc 0x%08x\n", (long long) p4estE->global_num_quadrants, crcE); #endif /* test corner balance */ p4estC = p4est_copy (p4est, 1); #ifndef P4_TO_P8 p4est_balance (p4estF, P4EST_CONNECT_CORNER, NULL); p4est_balance (p4estC, P4EST_CONNECT_CORNER, NULL); #else p4est_balance (p4estF, P8EST_CONNECT_CORNER, NULL); p4est_balance (p4estC, P8EST_CONNECT_CORNER, NULL); #endif crcC = p4est_checksum (p4estC); SC_CHECK_ABORT (crcC == p4est_checksum (p4estF), "mismatch B"); P4EST_GLOBAL_INFOF ("Corner balance with %lld quadrants and crc 0x%08x\n", (long long) p4estC->global_num_quadrants, crcC); /* destroy forests and connectivity */ p4est_destroy (p4est); p4est_destroy (p4estF); #ifdef P4_TO_P8 p4est_destroy (p4estE); #endif p4est_destroy (p4estC); p4est_connectivity_destroy (connectivity); /* clean up and exit */ sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
static void test_build_local (sc_MPI_Comm mpicomm) { sc_array_t *points; p4est_connectivity_t *conn; p4est_t *p4est, *built, *copy; test_build_t stb, *tb = &stb; /* 0. prepare data that we will reuse */ tb->maxlevel = 7 - P4EST_DIM; tb->counter = -1; tb->wrapper = 3; tb->init_default = -1; tb->init_add = -1; tb->count_add = -1; tb->last_tree = -1; tb->build = NULL; #ifndef P4_TO_P8 conn = p4est_connectivity_new_moebius (); #else conn = p8est_connectivity_new_rotcubes (); #endif /* P4_TO_P8 */ p4est = p4est_new_ext (mpicomm, conn, 0, 0, 2, 0, NULL, tb); p4est_refine (p4est, 1, test_build_refine, NULL); p4est_partition (p4est, 0, NULL); /* TODO: enrich tests with quadrant data */ /* 1. Create a p4est that shall be identical to the old one. */ tb->build = p4est_build_new (p4est, 0, NULL, NULL); p4est_search_local (p4est, 0, test_search_local_1, NULL, NULL); built = p4est_build_complete (tb->build); SC_CHECK_ABORT (p4est_is_equal (p4est, built, 0), "Mismatch build_local 1"); p4est_destroy (built); /* 2. Create a p4est that is as coarse as possible. * Coarsen recursively, compare. */ tb->build = p4est_build_new (p4est, 4, NULL, NULL); p4est_search_local (p4est, 0, test_search_local_2, NULL, NULL); built = p4est_build_complete (tb->build); copy = p4est_copy (p4est, 0); p4est_coarsen (copy, 1, test_build_coarsen, NULL); SC_CHECK_ABORT (p4est_is_equal (copy, built, 0), "Mismatch build_local 2"); p4est_destroy (copy); p4est_destroy (built); /* 3. Create a p4est with some random pattern for demonstration */ tb->init_default = 0; tb->init_add = 0; tb->count_add = 0; tb->build = p4est_build_new (p4est, 0, test_search_init_3, tb); p4est_build_init_add (tb->build, test_search_init_add_3); p4est_search_local (p4est, 1, test_search_local_3, NULL, NULL); built = p4est_build_complete (tb->build); p4est_build_verify_3 (built); SC_CHECK_ABORT (p4est_is_valid (built), "Invalid build_local 3"); p4est_destroy (built); /* 4. Create a p4est from a search with one quadrant per tree */ tb->init_default = 0; tb->init_add = 0; tb->count_add = 0; tb->last_tree = -1; tb->build = p4est_build_new (p4est, sizeof (long), test_search_init_4, tb); p4est_build_init_add (tb->build, test_search_init_add_4); p4est_search_local (p4est, 0, test_search_local_4, NULL, NULL); built = p4est_build_complete (tb->build); p4est_build_verify_4 (built); SC_CHECK_ABORT (p4est_is_valid (built), "Invalid build_local 4"); p4est_destroy (built); /* 5. Create a p4est from a multiple-item search */ points = sc_array_new_size (sizeof (int8_t), 2); *(int8_t *) sc_array_index (points, 0) = 0; *(int8_t *) sc_array_index (points, 1) = 1; tb->wrapper = 5; tb->init_default = 0; tb->init_add = 0; tb->build = p4est_build_new (p4est, 0, NULL, tb); p4est_search_local (p4est, 0, NULL, test_search_point_5, points); built = p4est_build_complete (tb->build); #if 0 p4est_build_verify_5 (built); #endif SC_CHECK_ABORT (p4est_is_valid (built), "Invalid build_local 5"); p4est_destroy (built); sc_array_destroy (points); /* clean up */ p4est_destroy (p4est); p4est_connectivity_destroy (conn); }
int main (int argc, char **argv) { int mpiret; int wrongusage; const char *usage; mpi_context_t mpi_context, *mpi = &mpi_context; p4est_connectivity_t *connectivity; simple_config_t config; /* initialize MPI and p4est internals */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpi->mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_size (mpi->mpicomm, &mpi->mpisize); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpi->mpicomm, &mpi->mpirank); SC_CHECK_MPI (mpiret); sc_init (mpi->mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); /* process command line arguments */ usage = "Arguments: <configuration> <level>\n Configuration can be any of\n" #ifndef P4_TO_P8 " unit|three|moebius|star|periodic|rotwrap|cubed|disk\n" #else " unit|periodic|rotwrap|twocubes|twowrap|rotcubes|shell|sphere\n" #endif " Level controls the maximum depth of refinement\n"; wrongusage = 0; config = P4EST_CONFIG_NULL; if (!wrongusage && argc != 3) { wrongusage = 1; } if (!wrongusage) { if (!strcmp (argv[1], "unit")) { #ifndef P4_TO_P8 config = P4EST_CONFIG_UNIT; #else config = P8EST_CONFIG_UNIT; #endif } #ifndef P4_TO_P8 else if (!strcmp (argv[1], "three")) { config = P4EST_CONFIG_THREE; } else if (!strcmp (argv[1], "moebius")) { config = P4EST_CONFIG_MOEBIUS; } else if (!strcmp (argv[1], "star")) { config = P4EST_CONFIG_STAR; } else if (!strcmp (argv[1], "periodic")) { config = P4EST_CONFIG_PERIODIC; } else if (!strcmp (argv[1], "rotwrap")) { config = P4EST_CONFIG_ROTWRAP; } else if (!strcmp (argv[1], "cubed")) { config = P4EST_CONFIG_CUBED; } else if (!strcmp (argv[1], "disk")) { config = P4EST_CONFIG_DISK; } #else else if (!strcmp (argv[1], "periodic")) { config = P8EST_CONFIG_PERIODIC; } else if (!strcmp (argv[1], "rotwrap")) { config = P8EST_CONFIG_ROTWRAP; } else if (!strcmp (argv[1], "twocubes")) { config = P8EST_CONFIG_TWOCUBES; } else if (!strcmp (argv[1], "twowrap")) { config = P8EST_CONFIG_TWOWRAP; } else if (!strcmp (argv[1], "rotcubes")) { config = P8EST_CONFIG_ROTCUBES; } else if (!strcmp (argv[1], "shell")) { config = P8EST_CONFIG_SHELL; } else if (!strcmp (argv[1], "sphere")) { config = P8EST_CONFIG_SPHERE; } #endif else { wrongusage = 1; } } if (wrongusage) { P4EST_GLOBAL_LERROR (usage); sc_abort_collective ("Usage error"); } /* assign variables based on configuration */ refine_level = atoi (argv[2]); /* create connectivity and forest structures */ if (0) { } #ifndef P4_TO_P8 else if (config == P4EST_CONFIG_THREE) { connectivity = p4est_connectivity_new_corner (); } else if (config == P4EST_CONFIG_MOEBIUS) { connectivity = p4est_connectivity_new_moebius (); } else if (config == P4EST_CONFIG_STAR) { connectivity = p4est_connectivity_new_star (); } else if (config == P4EST_CONFIG_PERIODIC) { connectivity = p4est_connectivity_new_periodic (); } else if (config == P4EST_CONFIG_ROTWRAP) { connectivity = p4est_connectivity_new_rotwrap (); } else if (config == P4EST_CONFIG_CUBED) { connectivity = p4est_connectivity_new_cubed (); } else if (config == P4EST_CONFIG_DISK) { connectivity = p4est_connectivity_new_disk (); } #else else if (config == P8EST_CONFIG_PERIODIC) { connectivity = p8est_connectivity_new_periodic (); } else if (config == P8EST_CONFIG_ROTWRAP) { connectivity = p8est_connectivity_new_rotwrap (); } else if (config == P8EST_CONFIG_TWOCUBES) { connectivity = p8est_connectivity_new_twocubes (); } else if (config == P8EST_CONFIG_TWOWRAP) { connectivity = p8est_connectivity_new_twowrap (); } else if (config == P8EST_CONFIG_ROTCUBES) { connectivity = p8est_connectivity_new_rotcubes (); } else if (config == P8EST_CONFIG_SHELL) { connectivity = p8est_connectivity_new_shell (); } else if (config == P8EST_CONFIG_SPHERE) { connectivity = p8est_connectivity_new_sphere (); } #endif else { #ifndef P4_TO_P8 connectivity = p4est_connectivity_new_unitsquare (); #else connectivity = p8est_connectivity_new_unitcube (); #endif } #if 0 /* hack test */ hack_test (mpi, connectivity); #else /* run mesh tests */ mesh_run (mpi, connectivity, 1, 0, 1, P4EST_CONNECT_FULL); mesh_run (mpi, connectivity, 0, 1, 0, P4EST_CONNECT_FULL); mesh_run (mpi, connectivity, 0, 0, 0, P4EST_CONNECT_FACE); mesh_run (mpi, connectivity, 1, 1, 1, P4EST_CONNECT_FACE); #endif /* clean up and exit */ p4est_connectivity_destroy (connectivity); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int mpisize, mpirank; p4est_t *p4est; p4est_connectivity_t *conn; sc_array_t *points_per_dim, *cone_sizes, *cones, *cone_orientations, *coords, *children, *parents, *childids, *leaves, *remotes; p4est_locidx_t first_local_quad = -1; /* initialize MPI */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_size (mpicomm, &mpisize); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpicomm, &mpirank); SC_CHECK_MPI (mpiret); sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); #ifndef P4_TO_P8 conn = p4est_connectivity_new_moebius (); #else conn = p8est_connectivity_new_rotcubes (); #endif p4est = p4est_new_ext (mpicomm, conn, 0, 1, 1, 0, NULL, NULL); p4est_refine (p4est, 1, refine_fn, NULL); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); p4est_partition (p4est, 0, NULL); points_per_dim = sc_array_new (sizeof (p4est_locidx_t)); cone_sizes = sc_array_new (sizeof (p4est_locidx_t)); cones = sc_array_new (sizeof (p4est_locidx_t)); cone_orientations = sc_array_new (sizeof (p4est_locidx_t)); coords = sc_array_new (3 * sizeof (double)); children = sc_array_new (sizeof (p4est_locidx_t)); parents = sc_array_new (sizeof (p4est_locidx_t)); childids = sc_array_new (sizeof (p4est_locidx_t)); leaves = sc_array_new (sizeof (p4est_locidx_t)); remotes = sc_array_new (2 * sizeof (p4est_locidx_t)); p4est_get_plex_data (p4est, P4EST_CONNECT_FULL, (mpisize > 1) ? 2 : 0, &first_local_quad, points_per_dim, cone_sizes, cones, cone_orientations, coords, children, parents, childids, leaves, remotes); #ifdef P4EST_WITH_PETSC { PetscErrorCode ierr; DM plex, refTree; PetscInt pStart, pEnd; PetscSection parentSection; PetscSF pointSF; size_t zz, count; locidx_to_PetscInt (points_per_dim); locidx_to_PetscInt (cone_sizes); locidx_to_PetscInt (cones); locidx_to_PetscInt (cone_orientations); coords_double_to_PetscScalar (coords); locidx_to_PetscInt (children); locidx_to_PetscInt (parents); locidx_to_PetscInt (childids); locidx_to_PetscInt (leaves); locidx_pair_to_PetscSFNode (remotes); P4EST_GLOBAL_PRODUCTION ("Begin PETSc routines\n"); ierr = PetscInitialize (&argc, &argv, 0, help); CHKERRQ (ierr); ierr = DMPlexCreate (mpicomm, &plex); CHKERRQ (ierr); ierr = DMSetDimension (plex, P4EST_DIM); CHKERRQ (ierr); ierr = DMSetCoordinateDim (plex, 3); CHKERRQ (ierr); ierr = DMPlexCreateFromDAG (plex, P4EST_DIM, (PetscInt *) points_per_dim->array, (PetscInt *) cone_sizes->array, (PetscInt *) cones->array, (PetscInt *) cone_orientations->array, (PetscScalar *) coords->array); CHKERRQ (ierr); ierr = PetscSFCreate (mpicomm, &pointSF); CHKERRQ (ierr); ierr = DMPlexCreateDefaultReferenceTree (mpicomm, P4EST_DIM, PETSC_FALSE, &refTree); CHKERRQ (ierr); ierr = DMPlexSetReferenceTree (plex, refTree); CHKERRQ (ierr); ierr = DMDestroy (&refTree); CHKERRQ (ierr); ierr = PetscSectionCreate (mpicomm, &parentSection); CHKERRQ (ierr); ierr = DMPlexGetChart (plex, &pStart, &pEnd); CHKERRQ (ierr); ierr = PetscSectionSetChart (parentSection, pStart, pEnd); CHKERRQ (ierr); count = children->elem_count; for (zz = 0; zz < count; zz++) { PetscInt child = *((PetscInt *) sc_array_index (children, zz)); ierr = PetscSectionSetDof (parentSection, child, 1); CHKERRQ (ierr); } ierr = PetscSectionSetUp (parentSection); CHKERRQ (ierr); ierr = DMPlexSetTree (plex, parentSection, (PetscInt *) parents->array, (PetscInt *) childids->array); CHKERRQ (ierr); ierr = PetscSectionDestroy (&parentSection); CHKERRQ (ierr); ierr = PetscSFSetGraph (pointSF, pEnd - pStart, (PetscInt) leaves->elem_count, (PetscInt *) leaves->array, PETSC_COPY_VALUES, (PetscSFNode *) remotes->array, PETSC_COPY_VALUES); CHKERRQ (ierr); ierr = DMViewFromOptions (plex, NULL, "-dm_view"); CHKERRQ (ierr); /* TODO: test with rigid body modes as in plex ex3 */ ierr = DMDestroy (&plex); CHKERRQ (ierr); ierr = PetscFinalize (); P4EST_GLOBAL_PRODUCTION ("End PETSc routines\n"); } #endif sc_array_destroy (points_per_dim); sc_array_destroy (cone_sizes); sc_array_destroy (cones); sc_array_destroy (cone_orientations); sc_array_destroy (coords); sc_array_destroy (children); sc_array_destroy (parents); sc_array_destroy (childids); sc_array_destroy (leaves); sc_array_destroy (remotes); p4est_destroy (p4est); p4est_connectivity_destroy (conn); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int mpirank; int first_arg; const char *prefix; p4est_connectivity_t *connectivity; sc_options_t *opt; /* initialize MPI */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_rank (mpicomm, &mpirank); SC_CHECK_MPI (mpiret); /* initialize libsc and p4est */ sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); /* handle command line options */ opt = sc_options_new (argv[0]); sc_options_add_int (opt, 'l', "level", &refine_level, default_refine_level, "Refinement level"); sc_options_add_string (opt, 'o', "oprefix", &prefix, P4EST_STRING, "Output prefix"); first_arg = sc_options_parse (p4est_package_id, SC_LP_INFO, opt, argc, argv); SC_CHECK_ABORT (first_arg >= 0, "Option error"); /* create connectivity */ #ifndef P4_TO_P8 connectivity = p4est_connectivity_new_star (); #else connectivity = p8est_connectivity_new_rotcubes (); #endif /* test with vertex information */ test_loadsave (connectivity, prefix, mpicomm, mpirank); /* test without vertex information */ connectivity->num_vertices = 0; P4EST_FREE (connectivity->vertices); connectivity->vertices = NULL; P4EST_FREE (connectivity->tree_to_vertex); connectivity->tree_to_vertex = NULL; p4est_connectivity_set_attr (connectivity, 1); memset (connectivity->tree_to_attr, 0, connectivity->num_trees * sizeof (int8_t)); test_loadsave (connectivity, prefix, mpicomm, mpirank); /* clean up and exit */ p4est_connectivity_destroy (connectivity); sc_options_destroy (opt); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }