p4est_wrap_t * p4est_wrap_new_corner (sc_MPI_Comm mpicomm, int initial_level) { return p4est_wrap_new_conn (mpicomm, p4est_connectivity_new_corner (), initial_level); }
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; /* 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 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) { int rank; int num_procs; int mpiret; sc_MPI_Comm mpicomm; p4est_t *p4est, *copy; p4est_connectivity_t *connectivity; int i; p4est_topidx_t t; size_t qz; p4est_locidx_t num_quadrants_on_last; p4est_locidx_t *num_quadrants_in_proc; p4est_gloidx_t *pertree1, *pertree2; p4est_quadrant_t *quad; p4est_tree_t *tree; user_data_t *user_data; int64_t sum; unsigned crc; mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_rank (mpicomm, &rank); SC_CHECK_MPI (mpiret); sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); /* create connectivity and forest structures */ #ifdef P4_TO_P8 connectivity = p8est_connectivity_new_twocubes (); #else connectivity = p4est_connectivity_new_corner (); #endif p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0, sizeof (user_data_t), init_fn, NULL); pertree1 = P4EST_ALLOC (p4est_gloidx_t, p4est->connectivity->num_trees + 1); pertree2 = P4EST_ALLOC (p4est_gloidx_t, p4est->connectivity->num_trees + 1); num_procs = p4est->mpisize; num_quadrants_in_proc = P4EST_ALLOC (p4est_locidx_t, num_procs); /* refine and balance to make the number of elements interesting */ test_pertree (p4est, NULL, pertree1); p4est_refine (p4est, 1, refine_fn, init_fn); test_pertree (p4est, NULL, pertree1); /* Set an arbitrary partition. * * Since this is just a test we assume the global number of * quadrants will fit in an int32_t */ num_quadrants_on_last = (p4est_locidx_t) p4est->global_num_quadrants; for (i = 0; i < num_procs - 1; ++i) { num_quadrants_in_proc[i] = (p4est_locidx_t) i + 1; /* type ok */ num_quadrants_on_last -= (p4est_locidx_t) i + 1; /* type ok */ } num_quadrants_in_proc[num_procs - 1] = num_quadrants_on_last; SC_CHECK_ABORT (num_quadrants_on_last > 0, "Negative number of quadrants on the last processor"); /* Save a checksum of the original forest */ crc = p4est_checksum (p4est); /* partition the forest */ (void) p4est_partition_given (p4est, num_quadrants_in_proc); test_pertree (p4est, pertree1, pertree2); /* Double check that we didn't loose any quads */ SC_CHECK_ABORT (crc == p4est_checksum (p4est), "bad checksum, missing a quad"); /* count the actual number of quadrants per proc */ SC_CHECK_ABORT (num_quadrants_in_proc[rank] == p4est->local_num_quadrants, "partition failed, wrong number of quadrants"); /* check user data content */ for (t = p4est->first_local_tree; t <= p4est->last_local_tree; ++t) { tree = p4est_tree_array_index (p4est->trees, t); for (qz = 0; qz < tree->quadrants.elem_count; ++qz) { quad = p4est_quadrant_array_index (&tree->quadrants, qz); user_data = (user_data_t *) quad->p.user_data; sum = quad->x + quad->y + quad->level; SC_CHECK_ABORT (user_data->a == t, "bad user_data, a"); SC_CHECK_ABORT (user_data->sum == sum, "bad user_data, sum"); } } /* do a weighted partition with uniform weights */ p4est_partition (p4est, 0, weight_one); test_pertree (p4est, pertree1, pertree2); SC_CHECK_ABORT (crc == p4est_checksum (p4est), "bad checksum after uniformly weighted partition"); /* copy the p4est */ copy = p4est_copy (p4est, 1); SC_CHECK_ABORT (crc == p4est_checksum (copy), "bad checksum after copy"); /* do a weighted partition with many zero weights */ weight_counter = 0; weight_index = (rank == 1) ? 1342 : 0; p4est_partition (copy, 0, weight_once); test_pertree (copy, pertree1, pertree2); SC_CHECK_ABORT (crc == p4est_checksum (copy), "bad checksum after unevenly weighted partition 1"); /* do a weighted partition with many zero weights */ weight_counter = 0; weight_index = 0; p4est_partition (copy, 0, weight_once); test_pertree (copy, pertree1, pertree2); SC_CHECK_ABORT (crc == p4est_checksum (copy), "bad checksum after unevenly weighted partition 2"); /* do a weighted partition with many zero weights * * Since this is just a test we assume the local number of * quadrants will fit in an int */ weight_counter = 0; weight_index = (rank == num_procs - 1) ? ((int) copy->local_num_quadrants - 1) : 0; p4est_partition (copy, 0, weight_once); test_pertree (copy, pertree1, pertree2); SC_CHECK_ABORT (crc == p4est_checksum (copy), "bad checksum after unevenly weighted partition 3"); /* check user data content */ for (t = copy->first_local_tree; t <= copy->last_local_tree; ++t) { tree = p4est_tree_array_index (copy->trees, t); for (qz = 0; qz < tree->quadrants.elem_count; ++qz) { quad = p4est_quadrant_array_index (&tree->quadrants, qz); user_data = (user_data_t *) quad->p.user_data; sum = quad->x + quad->y + quad->level; SC_CHECK_ABORT (user_data->a == t, "bad user_data, a"); SC_CHECK_ABORT (user_data->sum == sum, "bad user_data, sum"); } } /* Add another test. Overwrites pertree1, pertree2 */ test_partition_circle (mpicomm, connectivity, pertree1, pertree2); /* clean up and exit */ P4EST_FREE (pertree1); P4EST_FREE (pertree2); P4EST_FREE (num_quadrants_in_proc); p4est_destroy (p4est); p4est_destroy (copy); p4est_connectivity_destroy (connectivity); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char *argv[]) { MPI_Comm comm = MPI_COMM_WORLD; p4est_t *p4est; p4est_connectivity_t *conn; p4est_ghost_t *ghost_layer; p4est_lnodes_t *lnodes; int rank; const int degree = 1; BFAM_MPI_CHECK(MPI_Init(&argc,&argv)); BFAM_MPI_CHECK(MPI_Comm_rank(comm, &rank)); bfam_log_init(rank, stdout, BFAM_LL_DEFAULT); bfam_signal_handler_set(); sc_init(comm, 0, 0, NULL, SC_LP_DEFAULT); p4est_init(NULL, SC_LP_DEFAULT); conn = p4est_connectivity_new_corner(); p4est = p4est_new_ext(comm, conn, 0, 0, 0, 0, NULL, NULL); refine_level = 1; p4est_refine(p4est, 1, refine_fn, NULL); p4est_balance(p4est, P4EST_CONNECT_FACE, NULL); p4est_partition(p4est, 1, NULL); p4est_vtk_write_file(p4est, NULL, "mesh"); ghost_layer = p4est_ghost_new(p4est, P4EST_CONNECT_FULL); lnodes = p4est_lnodes_new(p4est, ghost_layer, degree); /* * Output the mesh. It can be read using something like following command: * * mpirun -np 3 ./bfam_exam_p4est | grep MESH | sort -n -k 2 | sort -n -k 5 | gvim - */ fflush(stdout); BFAM_MPI_CHECK(MPI_Barrier(comm)); BFAM_ROOT_INFO("MESH 0 ------------ Mesh Begin ------------"); BFAM_ROOT_INFO("MESH 1 degree = %d", lnodes->degree); BFAM_ROOT_INFO("MESH 2 vnodes = %d", lnodes->vnodes); BFAM_INFO("MESH 3 num_local_elements = %jd", (intmax_t)lnodes->num_local_elements); BFAM_INFO("MESH 4 num_local_nodes = %jd", (intmax_t)lnodes->num_local_nodes); BFAM_INFO("MESH 5 owned_count = %jd", (intmax_t)lnodes->owned_count); BFAM_INFO("MESH 6 global_offset = %jd", (intmax_t)lnodes->global_offset); sc_array_t *global_nodes = sc_array_new(sizeof (p4est_gloidx_t)); sc_array_resize(global_nodes, lnodes->num_local_nodes); for(size_t zz = 0; zz < global_nodes->elem_count; ++zz) { *((p4est_gloidx_t *) sc_array_index(global_nodes, zz)) = p4est_lnodes_global_index(lnodes, zz); } p4est_lnodes_share_owned(global_nodes, lnodes); for(size_t zz = 0; zz < global_nodes->elem_count; ++zz) { const p4est_gloidx_t gn = *((p4est_gloidx_t *)sc_array_index(global_nodes, zz)); SC_CHECK_ABORT (gn == p4est_lnodes_global_index(lnodes, zz), "Lnodes: bad global index across procesors"); BFAM_INFO("MESH 7 global_nodes[%zu] = %jd", zz, (intmax_t)gn); } sc_array_destroy(global_nodes); p4est_topidx_t flt = p4est->first_local_tree; p4est_topidx_t llt = p4est->last_local_tree; p4est_locidx_t elid, elnid; p4est_topidx_t t; const double *v = conn->vertices; const p4est_topidx_t *tree_to_vertex = conn->tree_to_vertex; for(elid = 0, elnid = 0, t = flt; t <= llt; ++t) { p4est_tree_t *tree = p4est_tree_array_index(p4est->trees, t); const size_t count = tree->quadrants.elem_count; p4est_topidx_t vt[P4EST_CHILDREN]; for (int c = 0; c < P4EST_CHILDREN; ++c) { vt[c] = tree_to_vertex[t * P4EST_CHILDREN + c]; } for (size_t zz = 0; zz < count; ++zz, ++elid) { p4est_quadrant_t *q = p4est_quadrant_array_index(&tree->quadrants, zz); for(int jind = 0; jind < degree + 1; ++jind) { for(int iind = 0; iind < degree + 1; ++iind, ++elnid) { double xyz[3]; for (int j = 0; j < 3; ++j) { const p4est_qcoord_t len = P4EST_QUADRANT_LEN(q->level); const double rlen = (double) P4EST_ROOT_LEN; const double deg = (double) degree; const double qlen = ((double) len) / rlen; const double eta_x = ((double) q->x) / rlen + (((double) iind) / deg) * qlen; const double eta_y = ((double) q->y) / rlen + (((double) jind) / deg) * qlen; xyz[j] = ((1. - eta_y) * ((1. - eta_x) * v[3 * vt[0] + j] + eta_x * v[3 * vt[1] + j]) + eta_y * ((1. - eta_x) * v[3 * vt[2] + j] + eta_x * v[3 * vt[3] + j])); } const p4est_locidx_t nid = lnodes->element_nodes[elnid]; BFAM_INFO( "MESH 8 local_node[%03jd] = %03jd ( %25.16e %25.16e %25.16e )", (intmax_t)elnid, (intmax_t)nid, xyz[0], xyz[1], xyz[2]); } } } } BFAM_ROOT_INFO("MESH 9 ------------ Mesh End ------------"); p4est_lnodes_destroy(lnodes); p4est_ghost_destroy(ghost_layer); p4est_destroy(p4est); p4est_connectivity_destroy(conn); sc_finalize(); BFAM_MPI_CHECK(MPI_Finalize()); return EXIT_SUCCESS; }
/* main */ int main (int argc, char **argv) { int rank, num_procs, mpiret, i; sc_MPI_Comm mpicomm = sc_MPI_COMM_WORLD; p4est_t *p4est_1tree, *p4est_ntrees; p4est_connectivity_t *connectivity_1tree, *connectivity_ntrees; /* initialize MPI and p4est internals */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_size (mpicomm, &num_procs); 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 connectivity */ #ifdef P4_TO_P8 connectivity_1tree = p8est_connectivity_new_unitcube (); connectivity_ntrees = p8est_connectivity_new_twocubes (); #else connectivity_1tree = p4est_connectivity_new_unitsquare (); connectivity_ntrees = p4est_connectivity_new_corner (); #endif /* create p4est structure */ p4est_1tree = p4est_new_ext (mpicomm, connectivity_1tree, 15, 0, 0, sizeof (user_data_t), init_fn, NULL); p4est_ntrees = p4est_new_ext (mpicomm, connectivity_ntrees, 15, 0, 0, sizeof (user_data_t), init_fn, NULL); /* write output: new */ p4est_vtk_write_file (p4est_1tree, NULL, P4EST_STRING "_partition_corr_1tree_new"); p4est_vtk_write_file (p4est_ntrees, NULL, P4EST_STRING "_partition_corr_ntrees_new"); /* refine */ p4est_refine (p4est_1tree, 1, refine_fn, init_fn); p4est_refine (p4est_ntrees, 1, refine_fn, init_fn); /* write output: refined */ p4est_vtk_write_file (p4est_1tree, NULL, P4EST_STRING "_partition_corr_1tree_refined"); p4est_vtk_write_file (p4est_ntrees, NULL, P4EST_STRING "_partition_corr_ntrees_refined"); /* run partition and coarsen till one quadrant per tree remains */ i = 0; while (p4est_1tree->global_num_quadrants > 1 && i <= P4EST_MAXLEVEL) { (void) p4est_partition_ext (p4est_1tree, 1, NULL); p4est_coarsen (p4est_1tree, 0, coarsen_fn, init_fn); i++; } SC_CHECK_ABORT (p4est_1tree->global_num_quadrants == 1, "coarsest forest with one tree was not achieved"); i = 0; while (p4est_ntrees->global_num_quadrants > connectivity_ntrees->num_trees && i <= P4EST_MAXLEVEL) { (void) p4est_partition_ext (p4est_ntrees, 1, NULL); p4est_coarsen (p4est_ntrees, 0, coarsen_fn, init_fn); i++; } SC_CHECK_ABORT (p4est_ntrees->global_num_quadrants == connectivity_ntrees->num_trees, "coarsest forest with multiple trees was not achieved"); /* run partition on coarse forest (one quadrant per tree) once again */ (void) p4est_partition_ext (p4est_1tree, 1, NULL); (void) p4est_partition_ext (p4est_ntrees, 1, NULL); /* write output: coarsened */ p4est_vtk_write_file (p4est_1tree, NULL, P4EST_STRING "_partition_corr_1tree_coarsened"); p4est_vtk_write_file (p4est_ntrees, NULL, P4EST_STRING "_partition_corr_ntrees_coarsened"); /* destroy the p4est and its connectivity structure */ p4est_destroy (p4est_1tree); p4est_destroy (p4est_ntrees); p4est_connectivity_destroy (connectivity_1tree); p4est_connectivity_destroy (connectivity_ntrees); /* clean up and exit */ sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }