diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index de785d684..8e55986bb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,7 +12,7 @@ test_conn_transformation2 test_brick2 test_join2 test_conn_reduce2 list(APPEND tests test_conn_transformation2 test_brick2 test_join2 test_conn_reduce2 test_version) if(P4EST_HAVE_ARPA_INET_H OR P4EST_HAVE_NETINET_IN_H OR WIN32) # htonl - list(APPEND p4est_tests test_balance2 test_partition_corr2 test_coarsen2 test_balance_type2 test_lnodes2 test_plex2 test_connrefine2 test_search2 test_subcomm2 test_replace2 test_ghost2 test_iterate2 test_nodes2 test_partition2 test_quadrants2 test_valid2 test_conn_complete2 test_wrap2) + list(APPEND p4est_tests test_balance2 test_partition_corr2 test_coarsen2 test_balance_type2 test_lnodes2 test_plex2 test_connrefine2 test_search2 test_subcomm2 test_replace2 test_ghost2 test_iterate2 test_nodes2 test_partition2 test_quadrants2 test_valid2 test_conn_complete2 test_wrap2 test_wrap_adapt2) if(P4EST_HAVE_GETOPT_H) list(APPEND p4est_tests test_load2 test_loadsave2) diff --git a/test/Makefile.am b/test/Makefile.am index 6c14ee12d..33cd0af7f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -26,7 +26,8 @@ p4est_test_programs += \ test/p4est_test_nodes \ test/p4est_test_version \ test/p4est_test_io \ - test/p4est_test_neighbor_transform + test/p4est_test_neighbor_transform \ + test/p4est_test_wrap_adapt if P4EST_WITH_METIS p4est_test_programs += \ test/p4est_test_reorder @@ -110,6 +111,7 @@ test_p4est_test_nodes_SOURCES = test/test_nodes2.c test_p4est_test_neighbor_transform_SOURCES = test/test_neighbor_transform2.c test_p4est_test_version_SOURCES = test/test_version.c test_p4est_test_io_SOURCES = test/test_io2.c +test_p4est_test_wrap_adapt_SOURCES = test/test_wrap_adapt2.c if P4EST_WITH_METIS test_p4est_test_reorder_SOURCES = test/test_reorder2.c endif diff --git a/test/test_wrap_adapt2.c b/test/test_wrap_adapt2.c new file mode 100644 index 000000000..848872199 --- /dev/null +++ b/test/test_wrap_adapt2.c @@ -0,0 +1,468 @@ +#include +#include +#include +#include + +typedef struct mesh_data +{ + int treeid; + int x; + int y; + int level; +} mesh_data_t; +static mesh_data_t *get_initial_mesh(); +static mesh_data_t *get_target_mesh(); + +int quadrants_overlap(p4est_iter_volume_info_t * info, mesh_data_t *target) +{ + int target_length = P4EST_QUADRANT_LEN (target->level); + + return info->treeid == target->treeid && + info->quad->x >= target->x && + info->quad->x < target->x + target_length && + info->quad->y >= target->y && + info->quad->y < target->y + target_length; +} + +typedef struct mark_patches_data +{ + p4est_wrap_t *pp; + mesh_data_t *curr; + mesh_data_t *end; + int verbose; +} mark_patches_data_t; + +static void +mark_patches_cb (p4est_iter_volume_info_t * info, + void *user_data) +{ + mark_patches_data_t *data = (mark_patches_data_t *) user_data; + while(!quadrants_overlap(info, data->curr)) + { + data->curr++; + if (data->curr == data->end) + { + SC_ABORT("No more quadrants to check"); + } + } + int target_level = data->curr->level; + if(target_level > info->quad->level) + { + p4est_wrap_mark_refine (data->pp, info->treeid, info->quadid); + if(data->verbose) + printf("Makring tree %d quadrant %d for refinement\n", info->treeid, info->quadid); + } + else if (target_level < info->quad->level) + { + p4est_wrap_mark_coarsen (data->pp, info->treeid, info->quadid); + if(data->verbose) + printf("Marking tree %d quadrant %d for coarsening\n", info->treeid, info->quadid); + } +} + +static void +mark_patches (p4est_wrap_t *pp, mesh_data_t *mesh, int verbose) +{ + mark_patches_data_t data; + data.pp = pp; + data.curr = &mesh[0]; + data.end = &mesh[164]; + data.verbose = verbose; + p4est_iterate (pp->p4est, NULL, &data, mark_patches_cb, NULL, NULL); +} + +int +main (int argc, char **argv) +{ + int num_errors = 0; + sc_MPI_Comm mpicomm = sc_MPI_COMM_SELF; + p4est_connectivity_t *conn; + p4est_wrap_t *wrap; + p4est_wrap_params_t params; + mesh_data_t *initial_mesh = get_initial_mesh(); + mesh_data_t *target_mesh = get_target_mesh(); + + sc_MPI_Init (&argc, &argv); + sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); + p4est_init (NULL, SC_LP_DEFAULT); + + /* create a 2x2 brick that is uniformly refined to level 2 except for a level 1 + * quadrant with coordinates (0,0,0) in tree 3. At the edges of the coarse + * quadrant there are edgehanging-corner neighbors inside the tree as well as + * across tree faces and edges. */ + conn = p4est_connectivity_new_disk(0,0); + + p4est_wrap_params_init (¶ms); + params.hollow = 0; + wrap = p4est_wrap_new_params (mpicomm, conn, 0, ¶ms); + + for(int i = 0; i < 3; i++) + { + mark_patches(wrap, initial_mesh, 0); + SC_CHECK_ABORT(p4est_wrap_adapt (wrap), "Expected p4est_wrap_adapt to return true"); + if(p4est_wrap_partition(wrap, 0, NULL, NULL, NULL)) + p4est_wrap_complete(wrap); + } + + SC_CHECK_ABORT(wrap->p4est->global_num_quadrants == 164, "wrap->p4est->global_num_quadrants != 164"); + + printf("-----------------------\n"); + printf("Adapting to target mesh\n"); + printf("-----------------------\n"); + mark_patches(wrap, target_mesh, 1); + SC_CHECK_ABORT(p4est_wrap_adapt (wrap), "Expected p4est_wrap_adapt to return true"); + SC_CHECK_ABORT(wrap->p4est->global_num_quadrants == 164, "wrap->p4est->global_num_quadrants != 164"); + + p4est_wrap_destroy (wrap); + //p4est_connectivity_destroy (conn); + + sc_finalize (); + sc_MPI_Finalize (); + + return num_errors; +} + +mesh_data_t before_mesh[164] = +{ +{0,0,0,1}, +{0,536870912,0,2}, +{0,805306368,0,2}, +{0,536870912,268435456,2}, +{0,805306368,268435456,2}, +{0,0,536870912,2}, +{0,268435456,536870912,2}, +{0,0,805306368,2}, +{0,268435456,805306368,2}, +{0,536870912,536870912,2}, +{0,805306368,536870912,2}, +{0,536870912,805306368,2}, +{0,805306368,805306368,2}, +{1,0,0,2}, +{1,268435456,0,2}, +{1,0,268435456,3}, +{1,134217728,268435456,3}, +{1,0,402653184,3}, +{1,134217728,402653184,3}, +{1,268435456,268435456,3}, +{1,402653184,268435456,3}, +{1,268435456,402653184,3}, +{1,402653184,402653184,3}, +{1,536870912,0,2}, +{1,805306368,0,2}, +{1,536870912,268435456,3}, +{1,671088640,268435456,3}, +{1,536870912,402653184,3}, +{1,671088640,402653184,3}, +{1,805306368,268435456,3}, +{1,939524096,268435456,3}, +{1,805306368,402653184,3}, +{1,939524096,402653184,3}, +{1,0,536870912,3}, +{1,134217728,536870912,3}, +{1,0,671088640,3}, +{1,134217728,671088640,3}, +{1,268435456,536870912,2}, +{1,0,805306368,3}, +{1,134217728,805306368,3}, +{1,0,939524096,3}, +{1,134217728,939524096,3}, +{1,268435456,805306368,3}, +{1,402653184,805306368,3}, +{1,268435456,939524096,3}, +{1,402653184,939524096,3}, +{1,536870912,536870912,2}, +{1,805306368,536870912,2}, +{1,536870912,805306368,3}, +{1,671088640,805306368,3}, +{1,536870912,939524096,3}, +{1,671088640,939524096,3}, +{1,805306368,805306368,3}, +{1,939524096,805306368,3}, +{1,805306368,939524096,3}, +{1,939524096,939524096,3}, +{2,0,0,2}, +{2,268435456,0,3}, +{2,402653184,0,3}, +{2,268435456,134217728,3}, +{2,402653184,134217728,3}, +{2,0,268435456,3}, +{2,134217728,268435456,3}, +{2,0,402653184,3}, +{2,134217728,402653184,3}, +{2,268435456,268435456,3}, +{2,402653184,268435456,3}, +{2,268435456,402653184,3}, +{2,402653184,402653184,3}, +{2,536870912,0,3}, +{2,671088640,0,3}, +{2,536870912,134217728,3}, +{2,671088640,134217728,3}, +{2,805306368,0,3}, +{2,939524096,0,3}, +{2,805306368,134217728,3}, +{2,939524096,134217728,3}, +{2,536870912,268435456,3}, +{2,671088640,268435456,3}, +{2,536870912,402653184,3}, +{2,671088640,402653184,3}, +{2,805306368,268435456,2}, +{2,0,536870912,2}, +{2,268435456,536870912,3}, +{2,402653184,536870912,3}, +{2,268435456,671088640,3}, +{2,402653184,671088640,3}, +{2,0,805306368,3}, +{2,134217728,805306368,3}, +{2,0,939524096,3}, +{2,134217728,939524096,3}, +{2,268435456,805306368,3}, +{2,402653184,805306368,3}, +{2,268435456,939524096,3}, +{2,402653184,939524096,3}, +{2,536870912,536870912,3}, +{2,671088640,536870912,3}, +{2,536870912,671088640,3}, +{2,671088640,671088640,3}, +{2,805306368,536870912,3}, +{2,939524096,536870912,3}, +{2,805306368,671088640,3}, +{2,939524096,671088640,3}, +{2,536870912,805306368,3}, +{2,671088640,805306368,3}, +{2,536870912,939524096,3}, +{2,671088640,939524096,3}, +{2,805306368,805306368,2}, +{3,0,0,3}, +{3,134217728,0,3}, +{3,0,134217728,3}, +{3,134217728,134217728,3}, +{3,268435456,0,3}, +{3,402653184,0,3}, +{3,268435456,134217728,3}, +{3,402653184,134217728,3}, +{3,0,268435456,2}, +{3,268435456,268435456,2}, +{3,536870912,0,3}, +{3,671088640,0,3}, +{3,536870912,134217728,3}, +{3,671088640,134217728,3}, +{3,805306368,0,3}, +{3,939524096,0,3}, +{3,805306368,134217728,3}, +{3,939524096,134217728,3}, +{3,536870912,268435456,2}, +{3,805306368,268435456,3}, +{3,939524096,268435456,3}, +{3,805306368,402653184,3}, +{3,939524096,402653184,3}, +{3,0,536870912,3}, +{3,134217728,536870912,3}, +{3,0,671088640,3}, +{3,134217728,671088640,3}, +{3,268435456,536870912,3}, +{3,402653184,536870912,3}, +{3,268435456,671088640,3}, +{3,402653184,671088640,3}, +{3,0,805306368,2}, +{3,268435456,805306368,2}, +{3,536870912,536870912,3}, +{3,671088640,536870912,3}, +{3,536870912,671088640,3}, +{3,671088640,671088640,3}, +{3,805306368,536870912,3}, +{3,939524096,536870912,3}, +{3,805306368,671088640,3}, +{3,939524096,671088640,3}, +{3,536870912,805306368,2}, +{3,805306368,805306368,2}, +{4,0,0,2}, +{4,268435456,0,2}, +{4,0,268435456,2}, +{4,268435456,268435456,2}, +{4,536870912,0,2}, +{4,805306368,0,2}, +{4,536870912,268435456,2}, +{4,805306368,268435456,2}, +{4,0,536870912,2}, +{4,268435456,536870912,2}, +{4,0,805306368,2}, +{4,268435456,805306368,2}, +{4,536870912,536870912,1} +}; + +mesh_data_t after_mesh[164] = +{ +{0,0,0,1}, +{0,536870912,0,2}, +{0,805306368,0,2}, +{0,536870912,268435456,2}, +{0,805306368,268435456,2}, +{0,0,536870912,2}, +{0,268435456,536870912,2}, +{0,0,805306368,2}, +{0,268435456,805306368,2}, +{0,536870912,536870912,2}, +{0,805306368,536870912,2}, +{0,536870912,805306368,2}, +{0,805306368,805306368,2}, +{1,0,0,2}, +{1,268435456,0,2}, +{1,0,268435456,3}, +{1,134217728,268435456,3}, +{1,0,402653184,3}, +{1,134217728,402653184,3}, +{1,268435456,268435456,3}, +{1,402653184,268435456,3}, +{1,268435456,402653184,3}, +{1,402653184,402653184,3}, +{1,536870912,0,2}, +{1,805306368,0,2}, +{1,536870912,268435456,3}, +{1,671088640,268435456,3}, +{1,536870912,402653184,3}, +{1,671088640,402653184,3}, +{1,805306368,268435456,3}, +{1,939524096,268435456,3}, +{1,805306368,402653184,3}, +{1,939524096,402653184,3}, +{1,0,536870912,3}, +{1,134217728,536870912,3}, +{1,0,671088640,3}, +{1,134217728,671088640,3}, +{1,268435456,536870912,3}, +{1,402653184,536870912,3}, +{1,268435456,671088640,3}, +{1,402653184,671088640,3}, +{1,0,805306368,3}, +{1,134217728,805306368,3}, +{1,0,939524096,3}, +{1,134217728,939524096,3}, +{1,268435456,805306368,3}, +{1,402653184,805306368,3}, +{1,268435456,939524096,3}, +{1,402653184,939524096,3}, +{1,536870912,536870912,2}, +{1,805306368,536870912,2}, +{1,536870912,805306368,3}, +{1,671088640,805306368,3}, +{1,536870912,939524096,3}, +{1,671088640,939524096,3}, +{1,805306368,805306368,3}, +{1,939524096,805306368,3}, +{1,805306368,939524096,3}, +{1,939524096,939524096,3}, +{2,0,0,2}, +{2,268435456,0,3}, +{2,402653184,0,3}, +{2,268435456,134217728,3}, +{2,402653184,134217728,3}, +{2,0,268435456,3}, +{2,134217728,268435456,3}, +{2,0,402653184,3}, +{2,134217728,402653184,3}, +{2,268435456,268435456,3}, +{2,402653184,268435456,3}, +{2,268435456,402653184,3}, +{2,402653184,402653184,3}, +{2,536870912,0,3}, +{2,671088640,0,3}, +{2,536870912,134217728,3}, +{2,671088640,134217728,3}, +{2,805306368,0,3}, +{2,939524096,0,3}, +{2,805306368,134217728,3}, +{2,939524096,134217728,3}, +{2,536870912,268435456,2}, +{2,805306368,268435456,2}, +{2,0,536870912,2}, +{2,268435456,536870912,2}, +{2,0,805306368,3}, +{2,134217728,805306368,3}, +{2,0,939524096,3}, +{2,134217728,939524096,3}, +{2,268435456,805306368,3}, +{2,402653184,805306368,3}, +{2,268435456,939524096,3}, +{2,402653184,939524096,3}, +{2,536870912,536870912,3}, +{2,671088640,536870912,3}, +{2,536870912,671088640,3}, +{2,671088640,671088640,3}, +{2,805306368,536870912,3}, +{2,939524096,536870912,3}, +{2,805306368,671088640,3}, +{2,939524096,671088640,3}, +{2,536870912,805306368,3}, +{2,671088640,805306368,3}, +{2,536870912,939524096,3}, +{2,671088640,939524096,3}, +{2,805306368,805306368,2}, +{3,0,0,3}, +{3,134217728,0,3}, +{3,0,134217728,3}, +{3,134217728,134217728,3}, +{3,268435456,0,3}, +{3,402653184,0,3}, +{3,268435456,134217728,3}, +{3,402653184,134217728,3}, +{3,0,268435456,2}, +{3,268435456,268435456,2}, +{3,536870912,0,3}, +{3,671088640,0,3}, +{3,536870912,134217728,3}, +{3,671088640,134217728,3}, +{3,805306368,0,3}, +{3,939524096,0,3}, +{3,805306368,134217728,3}, +{3,939524096,134217728,3}, +{3,536870912,268435456,3}, +{3,671088640,268435456,3}, +{3,536870912,402653184,3}, +{3,671088640,402653184,3}, +{3,805306368,268435456,3}, +{3,939524096,268435456,3}, +{3,805306368,402653184,3}, +{3,939524096,402653184,3}, +{3,0,536870912,3}, +{3,134217728,536870912,3}, +{3,0,671088640,3}, +{3,134217728,671088640,3}, +{3,268435456,536870912,3}, +{3,402653184,536870912,3}, +{3,268435456,671088640,3}, +{3,402653184,671088640,3}, +{3,0,805306368,2}, +{3,268435456,805306368,2}, +{3,536870912,536870912,3}, +{3,671088640,536870912,3}, +{3,536870912,671088640,3}, +{3,671088640,671088640,3}, +{3,805306368,536870912,3}, +{3,939524096,536870912,3}, +{3,805306368,671088640,3}, +{3,939524096,671088640,3}, +{3,536870912,805306368,2}, +{3,805306368,805306368,2}, +{4,0,0,2}, +{4,268435456,0,2}, +{4,0,268435456,2}, +{4,268435456,268435456,2}, +{4,536870912,0,2}, +{4,805306368,0,2}, +{4,536870912,268435456,2}, +{4,805306368,268435456,2}, +{4,0,536870912,2}, +{4,268435456,536870912,2}, +{4,0,805306368,2}, +{4,268435456,805306368,2}, +{4,536870912,536870912,1} +}; + +mesh_data_t *get_initial_mesh() +{ + return before_mesh; +} +mesh_data_t *get_target_mesh() +{ + return after_mesh; +} \ No newline at end of file