From 6ce1f079aae5dbedde8e273c5d99faa2cd717a5e Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Wed, 30 Aug 2023 10:00:31 -0600 Subject: [PATCH 1/9] add test_mesh_corners3.c --- test/test_mesh_corners3.c | 154 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 test/test_mesh_corners3.c diff --git a/test/test_mesh_corners3.c b/test/test_mesh_corners3.c new file mode 100644 index 000000000..09abd874f --- /dev/null +++ b/test/test_mesh_corners3.c @@ -0,0 +1,154 @@ +#include +#include +#include + +#define FALSE 0 +#define TRUE 1 + +static +int refine(p8est_t* p4est, p4est_topidx_t which_tree, p8est_quadrant_t* quadrant) +{ + int refine = TRUE; + if(quadrant->x == 0 && quadrant->y == 0 && quadrant->z == 0) + { + refine = FALSE; + } + return refine; +} + +static +int check_corner(p4est_topidx_t qid, + p4est_locidx_t c, + p4est_locidx_t qtc, + p4est_locidx_t expected_qtc) +{ + if(qtc != expected_qtc) + { + printf("ERROR: qid %d corner %d should have neighbor %d, but has %d\n", + qid, c, expected_qtc, qtc); + return 1; + } + return 0; +} + +int main(int argc, char **argv) +{ + int num_errors = 0; + + sc_MPI_Comm mpicomm = sc_MPI_COMM_SELF; + + sc_MPI_Init(&argc,&argv); + sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); + p4est_init (NULL, SC_LP_DEFAULT); + + p8est_connectivity_t* conn = p8est_connectivity_new_unitcube(); + p8est_t* p8est = p8est_new_ext(mpicomm, conn, 0, 1, 0, 0, NULL, NULL); + + // refine all quadrents to level 2 except quadrent touching 0,0,0 + p8est_refine_ext(p8est, FALSE, 2, refine, NULL, NULL); + + p8est_ghost_t* ghost = p8est_ghost_new(p8est, P8EST_CONNECT_FULL); + + p8est_mesh_t* mesh = p8est_mesh_new(p8est, ghost, P8EST_CONNECT_FULL); + P4EST_ASSERT(mesh->local_num_quadrants == 57); + + // assuming that the coarse quadrent is zero with ordering + p4est_locidx_t coarse_qid = 0; + + // upper x,y,z index + p4est_locidx_t ux_idx = P8EST_FACES * coarse_qid + 1; + p4est_locidx_t uy_idx = P8EST_FACES * coarse_qid + 3; + p4est_locidx_t uz_idx = P8EST_FACES * coarse_qid + 5; + + P4EST_ASSERT(mesh->quad_to_face[ux_idx] < 0); + P4EST_ASSERT(mesh->quad_to_face[uy_idx] < 0); + P4EST_ASSERT(mesh->quad_to_face[uz_idx] < 0); + + // get the quadrents on upper x,y,z faces of coarse quadrent + p4est_locidx_t qtq_ux, qtq_uy, qtq_uz; + qtq_ux = mesh->quad_to_quad[ux_idx]; + qtq_uy = mesh->quad_to_quad[uy_idx]; + qtq_uz = mesh->quad_to_quad[uz_idx]; + + p4est_locidx_t *qth_ux, *qth_uy, *qth_uz; + qth_ux = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_ux); + qth_uy = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_uy); + qth_uz = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_uz); + + p4est_locidx_t qid1, qid2; + p4est_locidx_t c1, c2; + p4est_locidx_t qtc1, qtc2; + + //six pairs of corners with missing information + + //two along upper x upper y edge of coarse quad + + qid1 = qth_ux[1]; //lower quad along edge on x face of coarse quad + qid2 = qth_uy[3]; //upper quad along edge on y face of coarse quad + c1 = 6; // qid1 should have neighbor on uz uy lx corner + c2 = 1; // qid2 should have neighbor on lz ly ux corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + qid1 = qth_ux[3]; //upper quad along edge on x face of coarse quad + qid2 = qth_uy[1]; //lower quad along edge on y face of coarse quad + c1 = 2; // qid1 should have neighbor on lz uy lx corner + c2 = 5; // qid2 should have neighbor on uz ly ux corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + + //two along upper x upper z edge of coarse quad + + qid1 = qth_ux[2]; //lower quad along edge on x face of coarse quad + qid2 = qth_uz[3]; //upper quad along edge on z face of coarse quad + c1 = 6; // qid1 should have neighbor on uz uy lx corner + c2 = 1; // qid2 should have neighbor on lz ly ux corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + qid1 = qth_ux[3]; //upper quad along edge on x face + qid2 = qth_uz[1]; //lower quad along edge on z face + c1 = 4; // qid1 should have neighbor on uz ly lx corner + c2 = 3; // qid2 should have neighbor on lz uy ux corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + //two along upper y upper z edge of coarse quad + + qid1 = qth_uy[2]; //lower quad along edge on y face of coarse quad + qid2 = qth_uz[3]; //upper quad along edge on z face of coarse quad + c1 = 5; // qid1 should have neighbor on uz ly ux corner + c2 = 2; // qid2 should have neighbor on lz uy lx corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + qid1 = qth_uy[3]; //upper quad along edge on y face + qid2 = qth_uz[2]; //lower quad along edge on z face + c1 = 4; // qid1 should have neighbor on uz ly lx corner + c2 = 3; // qid2 should have neighbor on lz uy ux corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + p8est_mesh_destroy(mesh); + p8est_ghost_destroy(ghost); + p8est_destroy(p8est); + p8est_connectivity_destroy(conn); + + sc_finalize(); + sc_MPI_Finalize(); + + return num_errors; +} \ No newline at end of file From 427dce809da2b4a5e1cd2fc5dc25f89a09e4a9d5 Mon Sep 17 00:00:00 2001 From: Hannes Brandt Date: Thu, 31 Aug 2023 11:16:35 +0200 Subject: [PATCH 2/9] add test_mesh_corners to Makefile --- test/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/Makefile.am b/test/Makefile.am index df0f0a894..b442497c9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -40,6 +40,7 @@ p4est_test_programs += \ test/p8est_test_periodic test/p8est_test_loadsave \ test/p8est_test_load test/p8est_test_ghost \ test/p8est_test_mesh_bijective test/p8est_test_conn_transformation \ + test/p8est_test_mesh_corners \ test/p8est_test_iterate test/p8est_test_lnodes \ test/p8est_test_search test/p8est_test_brick \ test/p8est_test_partition_corr \ @@ -128,6 +129,7 @@ test_p8est_test_loadsave_SOURCES = test/test_loadsave3.c test_p8est_test_load_SOURCES = test/test_load3.c test_p8est_test_ghost_SOURCES = test/test_ghost3.c test_p8est_test_mesh_bijective_SOURCES = test/test_mesh_bijective3.c +test_p8est_test_mesh_corners_SOURCES = test/test_mesh_corners3.c test_p8est_test_conn_transformation_SOURCES = test/test_conn_transformation3.c test_p8est_test_brick_SOURCES = test/test_brick3.c test_p8est_test_iterate_SOURCES = test/test_iterate3.c @@ -210,6 +212,7 @@ LINT_CSOURCES += \ $(test_p8est_test_loadsave_SOURCES) \ $(test_p8est_test_load_SOURCES) \ $(test_p8est_test_ghost_SOURCES) \ + $(test_p8est_test_corners_SOURCES) \ $(test_p8est_test_mesh_bijective_SOURCES) \ $(test_p8est_test_conn_transformation_SOURCES) \ $(test_p8est_test_brick_SOURCES) \ From fac20d8dc95983ac409c62805f3313e54a17d81f Mon Sep 17 00:00:00 2001 From: Hannes Brandt Date: Thu, 31 Aug 2023 13:08:48 +0200 Subject: [PATCH 3/9] add test_mesh_corners to CMakeLists.txt --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ccdeb4b08..56d141207 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,7 +22,7 @@ endif() if(enable_p8est) - set(p8est_tests test_conn_transformation3 test_brick3 test_join3 test_conn_reduce3) + set(p8est_tests test_conn_transformation3 test_brick3 test_join3 test_conn_reduce3 test_mesh_corners3) if(P4EST_HAVE_ARPA_INET_H OR P4EST_HAVE_NETINET_IN_H OR P4EST_HAVE_WINSOCK2_H) # htonl list(APPEND p8est_tests test_balance3 test_partition_corr3 test_coarsen3 test_balance_type3 test_lnodes3 test_plex3 test_connrefine3 test_subcomm3 test_replace3 test_ghost3 test_iterate3 test_nodes3 test_partition3 test_quadrants3 test_valid3 test_conn_complete3 test_wrap3) From 533368bde2862be409133d503f799e80472ed059 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 31 Aug 2023 07:18:33 -0600 Subject: [PATCH 4/9] add doc/author_aiton.txt --- doc/author_aiton.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/author_aiton.txt diff --git a/doc/author_aiton.txt b/doc/author_aiton.txt new file mode 100644 index 000000000..6f96f9b17 --- /dev/null +++ b/doc/author_aiton.txt @@ -0,0 +1 @@ +I place my contributions to p4est under FreeBSD license. Scott Aiton (scott@aiton.net) From eb0d4d33f6f96db0126c49058314ce57fd3d31e4 Mon Sep 17 00:00:00 2001 From: Hannes Brandt Date: Wed, 13 Dec 2023 17:49:47 +0100 Subject: [PATCH 5/9] test hanging-corners: use mesh_new_params in test_mesh_corners --- test/test_mesh_corners3.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/test_mesh_corners3.c b/test/test_mesh_corners3.c index 09abd874f..937aef8c0 100644 --- a/test/test_mesh_corners3.c +++ b/test/test_mesh_corners3.c @@ -49,7 +49,12 @@ int main(int argc, char **argv) p8est_ghost_t* ghost = p8est_ghost_new(p8est, P8EST_CONNECT_FULL); - p8est_mesh_t* mesh = p8est_mesh_new(p8est, ghost, P8EST_CONNECT_FULL); + /* create mesh with edgehanging corner neighbor information */ + p8est_mesh_params_t params; + p8est_mesh_params_init (¶ms); + params.btype = P8EST_CONNECT_FULL; + params.edgehanging_corners = 1; + p8est_mesh_t* mesh = p8est_mesh_new_params (p8est, ghost, ¶ms); P4EST_ASSERT(mesh->local_num_quadrants == 57); // assuming that the coarse quadrent is zero with ordering From 1c6a9fb04ef4ed0e542c068d8a655c3bbee5ccc4 Mon Sep 17 00:00:00 2001 From: Hannes Brandt Date: Sat, 28 Oct 2023 21:34:26 +0200 Subject: [PATCH 6/9] test hanging-corners: add intertree case --- test/test_mesh_corners3.c | 135 +++++++++++++++++++++++++++++++++++--- 1 file changed, 126 insertions(+), 9 deletions(-) diff --git a/test/test_mesh_corners3.c b/test/test_mesh_corners3.c index 937aef8c0..5862ae36a 100644 --- a/test/test_mesh_corners3.c +++ b/test/test_mesh_corners3.c @@ -9,7 +9,8 @@ static int refine(p8est_t* p4est, p4est_topidx_t which_tree, p8est_quadrant_t* quadrant) { int refine = TRUE; - if(quadrant->x == 0 && quadrant->y == 0 && quadrant->z == 0) + if(quadrant->x == 0 && quadrant->y == 0 && quadrant->z == 0 && + which_tree == 3) { refine = FALSE; } @@ -41,10 +42,10 @@ int main(int argc, char **argv) sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); - p8est_connectivity_t* conn = p8est_connectivity_new_unitcube(); + p8est_connectivity_t* conn = p8est_connectivity_new_brick(2, 2, 1, 0, 0, 0); p8est_t* p8est = p8est_new_ext(mpicomm, conn, 0, 1, 0, 0, NULL, NULL); - // refine all quadrents to level 2 except quadrent touching 0,0,0 + // refine all quadrents to level 2 except quadrent in tree 3 touching 0,0,0 p8est_refine_ext(p8est, FALSE, 2, refine, NULL, NULL); p8est_ghost_t* ghost = p8est_ghost_new(p8est, P8EST_CONNECT_FULL); @@ -55,28 +56,36 @@ int main(int argc, char **argv) params.btype = P8EST_CONNECT_FULL; params.edgehanging_corners = 1; p8est_mesh_t* mesh = p8est_mesh_new_params (p8est, ghost, ¶ms); - P4EST_ASSERT(mesh->local_num_quadrants == 57); + P4EST_ASSERT(mesh->local_num_quadrants == 249); - // assuming that the coarse quadrent is zero with ordering - p4est_locidx_t coarse_qid = 0; + // assuming that the coarse quadrent is zero in tree 3 with ordering + p4est_locidx_t coarse_qid = 192; - // upper x,y,z index + // upper and lower x,y,z indices + p4est_locidx_t lx_idx = P8EST_FACES * coarse_qid + 0; p4est_locidx_t ux_idx = P8EST_FACES * coarse_qid + 1; + p4est_locidx_t ly_idx = P8EST_FACES * coarse_qid + 2; p4est_locidx_t uy_idx = P8EST_FACES * coarse_qid + 3; p4est_locidx_t uz_idx = P8EST_FACES * coarse_qid + 5; + P4EST_ASSERT(mesh->quad_to_face[lx_idx] < 0); P4EST_ASSERT(mesh->quad_to_face[ux_idx] < 0); + P4EST_ASSERT(mesh->quad_to_face[ly_idx] < 0); P4EST_ASSERT(mesh->quad_to_face[uy_idx] < 0); P4EST_ASSERT(mesh->quad_to_face[uz_idx] < 0); // get the quadrents on upper x,y,z faces of coarse quadrent - p4est_locidx_t qtq_ux, qtq_uy, qtq_uz; + p4est_locidx_t qtq_lx, qtq_ux, qtq_ly, qtq_uy, qtq_uz; + qtq_lx = mesh->quad_to_quad[lx_idx]; qtq_ux = mesh->quad_to_quad[ux_idx]; + qtq_ly = mesh->quad_to_quad[ly_idx]; qtq_uy = mesh->quad_to_quad[uy_idx]; qtq_uz = mesh->quad_to_quad[uz_idx]; - p4est_locidx_t *qth_ux, *qth_uy, *qth_uz; + p4est_locidx_t *qth_lx, *qth_ux, *qth_ly, *qth_uy, *qth_uz; + qth_lx = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_lx); qth_ux = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_ux); + qth_ly = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_ly); qth_uy = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_uy); qth_uz = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_uz); @@ -84,6 +93,7 @@ int main(int argc, char **argv) p4est_locidx_t c1, c2; p4est_locidx_t qtc1, qtc2; + /*** test intra tree corners ***/ //six pairs of corners with missing information //two along upper x upper y edge of coarse quad @@ -147,6 +157,113 @@ int main(int argc, char **argv) num_errors += check_corner(qid1,c1,qtc1,qid2); num_errors += check_corner(qid2,c2,qtc2,qid1); + + /*** test inter-tree corners across tree-face ***/ + //eight pairs of corners with missing information + + //two along lower x upper y edge of coarse quad (across face to tree 2) + + qid1 = qth_lx[1]; //lower quad along edge on x face of coarse quad + qid2 = qth_uy[2]; //upper quad along edge on y face of coarse quad + c1 = 7; // qid1 should have neighbor on uz uy ux corner + c2 = 0; // qid2 should have neighbor on lz ly lx corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + qid1 = qth_lx[3]; //upper quad along edge on x face of coarse quad + qid2 = qth_uy[0]; //lower quad along edge on y face of coarse quad + c1 = 3; // qid1 should have neighbor on lz uy ux corner + c2 = 4; // qid2 should have neighbor on uz ly lx corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + //two along lower x upper z edge of coarse quad (across face to tree 2) + + qid1 = qth_lx[2]; //lower quad along edge on x face of coarse quad + qid2 = qth_uz[2]; //upper quad along edge on z face of coarse quad + c1 = 7; // qid1 should have neighbor on uz uy ux corner + c2 = 0; // qid2 should have neighbor on lz ly lx corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + qid1 = qth_lx[3]; //upper quad along edge on x face of coarse quad + qid2 = qth_uz[0]; //lower quad along edge on z face of coarse quad + c1 = 5; // qid1 should have neighbor on uz ly ux corner + c2 = 2; // qid2 should have neighbor on lz uy lx corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + //two along upper x lower y edge of coarse quad (across face to tree 1) + + qid1 = qth_ux[0]; //lower quad along edge on x face of coarse quad + qid2 = qth_ly[3]; //upper quad along edge on y face of coarse quad + c1 = 4; // qid1 should have neighbor on uz ly lx corner + c2 = 3; // qid2 should have neighbor on lz uy ux corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + qid1 = qth_ux[2]; //upper quad along edge on x face of coarse quad + qid2 = qth_ly[1]; //lower quad along edge on y face of coarse quad + c1 = 0; // qid1 should have neighbor on lz ly lx corner + c2 = 7; // qid2 should have neighbor on uz uy ux corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + //two along lower y upper z edge of coarse quad (across face to tree 1) + + qid1 = qth_ly[2]; //lower quad along edge on y face of coarse quad + qid2 = qth_uz[1]; //upper quad along edge on z face of coarse quad + c1 = 7; // qid1 should have neighbor on uz uy ux corner + c2 = 0; // qid2 should have neighbor on lz ly lx corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + qid1 = qth_ly[3]; //upper quad along edge on y face of coarse quad + qid2 = qth_uz[0]; //lower quad along edge on z face of coarse quad + c1 = 6; // qid1 should have neighbor on uz uy lx corner + c2 = 1; // qid2 should have neighbor on lz ly ux corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + /*** test inter-tree corners across tree-edge ***/ + //two pairs of corners with missing information + + //two along lower x lower y edge of coarse quad (across edge to tree 0) + + qid1 = qth_lx[0]; //lower quad along edge on x face of coarse quad + qid2 = qth_ly[2]; //upper quad along edge on y face of coarse quad + c1 = 5; // qid1 should have neighbor on uz ly ux corner + c2 = 2; // qid2 should have neighbor on lz uy lx corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + + qid1 = qth_lx[2]; //upper quad along edge on x face of coarse quad + qid2 = qth_ly[0]; //lower quad along edge on y face of coarse quad + c1 = 1; // qid1 should have neighbor on lz ly ux corner + c2 = 6; // qid2 should have neighbor on uz uy lx corner + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; + num_errors += check_corner(qid1,c1,qtc1,qid2); + num_errors += check_corner(qid2,c2,qtc2,qid1); + p8est_mesh_destroy(mesh); p8est_ghost_destroy(ghost); p8est_destroy(p8est); From 9d4721ddb598e5dfb332a2068d664900f906dae2 Mon Sep 17 00:00:00 2001 From: Hannes Brandt Date: Sat, 28 Oct 2023 22:44:01 +0200 Subject: [PATCH 7/9] test hanging-corners: adapt corner check to work across trees --- test/test_mesh_corners3.c | 58 +++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/test/test_mesh_corners3.c b/test/test_mesh_corners3.c index 5862ae36a..f7ee5f5e4 100644 --- a/test/test_mesh_corners3.c +++ b/test/test_mesh_corners3.c @@ -32,6 +32,24 @@ int check_corner(p4est_topidx_t qid, return 0; } +static +int check_corner_across_trees(p4est_topidx_t qid, + p4est_locidx_t c, + p4est_locidx_t qtc, + p4est_locidx_t expected_qtc, + p8est_mesh_t *mesh) +{ + int offset; + int cind; + p4est_locidx_t new_qtc; + + cind = qtc - mesh->local_num_quadrants - mesh->ghost_num_quadrants; + P4EST_ASSERT (cind >= 0); + offset = *(int *) sc_array_index (mesh->corner_offset, cind); + new_qtc = *(p4est_locidx_t *) sc_array_index (mesh->corner_quad, offset); + return check_corner (qid, c, new_qtc, expected_qtc); +} + int main(int argc, char **argv) { int num_errors = 0; @@ -169,8 +187,8 @@ int main(int argc, char **argv) c2 = 0; // qid2 should have neighbor on lz ly lx corner qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); + num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); + num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); qid1 = qth_lx[3]; //upper quad along edge on x face of coarse quad qid2 = qth_uy[0]; //lower quad along edge on y face of coarse quad @@ -178,8 +196,8 @@ int main(int argc, char **argv) c2 = 4; // qid2 should have neighbor on uz ly lx corner qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); + num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); + num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); //two along lower x upper z edge of coarse quad (across face to tree 2) @@ -189,8 +207,8 @@ int main(int argc, char **argv) c2 = 0; // qid2 should have neighbor on lz ly lx corner qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); + num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); + num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); qid1 = qth_lx[3]; //upper quad along edge on x face of coarse quad qid2 = qth_uz[0]; //lower quad along edge on z face of coarse quad @@ -198,8 +216,8 @@ int main(int argc, char **argv) c2 = 2; // qid2 should have neighbor on lz uy lx corner qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); + num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); + num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); //two along upper x lower y edge of coarse quad (across face to tree 1) @@ -209,8 +227,8 @@ int main(int argc, char **argv) c2 = 3; // qid2 should have neighbor on lz uy ux corner qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); + num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); + num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); qid1 = qth_ux[2]; //upper quad along edge on x face of coarse quad qid2 = qth_ly[1]; //lower quad along edge on y face of coarse quad @@ -218,8 +236,8 @@ int main(int argc, char **argv) c2 = 7; // qid2 should have neighbor on uz uy ux corner qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); + num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); + num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); //two along lower y upper z edge of coarse quad (across face to tree 1) @@ -229,8 +247,8 @@ int main(int argc, char **argv) c2 = 0; // qid2 should have neighbor on lz ly lx corner qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); + num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); + num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); qid1 = qth_ly[3]; //upper quad along edge on y face of coarse quad qid2 = qth_uz[0]; //lower quad along edge on z face of coarse quad @@ -238,8 +256,8 @@ int main(int argc, char **argv) c2 = 1; // qid2 should have neighbor on lz ly ux corner qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); + num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); + num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); /*** test inter-tree corners across tree-edge ***/ //two pairs of corners with missing information @@ -252,8 +270,8 @@ int main(int argc, char **argv) c2 = 2; // qid2 should have neighbor on lz uy lx corner qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); + num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); + num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); qid1 = qth_lx[2]; //upper quad along edge on x face of coarse quad qid2 = qth_ly[0]; //lower quad along edge on y face of coarse quad @@ -261,8 +279,8 @@ int main(int argc, char **argv) c2 = 6; // qid2 should have neighbor on uz uy lx corner qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); + num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); + num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); p8est_mesh_destroy(mesh); p8est_ghost_destroy(ghost); From 87892e6effbca4f70d59e3d800549827d15ce552 Mon Sep 17 00:00:00 2001 From: Hannes Brandt Date: Thu, 14 Dec 2023 13:55:21 +0100 Subject: [PATCH 8/9] test hanging-corners: indent and add comments --- test/test_mesh_corners3.c | 561 +++++++++++++++++++------------------- 1 file changed, 281 insertions(+), 280 deletions(-) diff --git a/test/test_mesh_corners3.c b/test/test_mesh_corners3.c index f7ee5f5e4..27a2ab1e9 100644 --- a/test/test_mesh_corners3.c +++ b/test/test_mesh_corners3.c @@ -1,294 +1,295 @@ #include #include #include - + #define FALSE 0 #define TRUE 1 - -static -int refine(p8est_t* p4est, p4est_topidx_t which_tree, p8est_quadrant_t* quadrant) + +static int +refine (p8est_t *p4est, p4est_topidx_t which_tree, + p8est_quadrant_t *quadrant) { - int refine = TRUE; - if(quadrant->x == 0 && quadrant->y == 0 && quadrant->z == 0 && - which_tree == 3) - { - refine = FALSE; - } - return refine; + int refine = TRUE; + if (quadrant->x == 0 && quadrant->y == 0 && quadrant->z == 0 && + which_tree == 3) { + refine = FALSE; + } + return refine; } - -static -int check_corner(p4est_topidx_t qid, - p4est_locidx_t c, - p4est_locidx_t qtc, - p4est_locidx_t expected_qtc) + +static int +check_corner (p4est_topidx_t qid, p4est_locidx_t c, p4est_locidx_t qtc, + p4est_locidx_t expected_qtc) { - if(qtc != expected_qtc) - { - printf("ERROR: qid %d corner %d should have neighbor %d, but has %d\n", - qid, c, expected_qtc, qtc); - return 1; - } - return 0; + if (qtc != expected_qtc) { + printf ("ERROR: qid %d corner %d should have neighbor %d, but has %d\n", + qid, c, expected_qtc, qtc); + return 1; + } + return 0; } -static -int check_corner_across_trees(p4est_topidx_t qid, - p4est_locidx_t c, - p4est_locidx_t qtc, - p4est_locidx_t expected_qtc, - p8est_mesh_t *mesh) +static int +check_corner_across_trees (p4est_topidx_t qid, p4est_locidx_t c, + p4est_locidx_t qtc, p4est_locidx_t expected_qtc, + p8est_mesh_t *mesh) { - int offset; - int cind; - p4est_locidx_t new_qtc; - - cind = qtc - mesh->local_num_quadrants - mesh->ghost_num_quadrants; - P4EST_ASSERT (cind >= 0); - offset = *(int *) sc_array_index (mesh->corner_offset, cind); - new_qtc = *(p4est_locidx_t *) sc_array_index (mesh->corner_quad, offset); - return check_corner (qid, c, new_qtc, expected_qtc); + int offset; + int cind; + p4est_locidx_t new_qtc; + + /* corner neighbor information for quadrants from different trees are stored + * in the corner_quad array and have to be accessed using corner_offset */ + cind = qtc - mesh->local_num_quadrants - mesh->ghost_num_quadrants; + P4EST_ASSERT (cind >= 0); + offset = *(int *) sc_array_index (mesh->corner_offset, cind); + new_qtc = *(p4est_locidx_t *) sc_array_index (mesh->corner_quad, offset); + + return check_corner (qid, c, new_qtc, expected_qtc); } -int main(int argc, char **argv) +int +main (int argc, char **argv) { - int num_errors = 0; - - sc_MPI_Comm mpicomm = sc_MPI_COMM_SELF; - - sc_MPI_Init(&argc,&argv); - sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); - p4est_init (NULL, SC_LP_DEFAULT); - - p8est_connectivity_t* conn = p8est_connectivity_new_brick(2, 2, 1, 0, 0, 0); - p8est_t* p8est = p8est_new_ext(mpicomm, conn, 0, 1, 0, 0, NULL, NULL); - - // refine all quadrents to level 2 except quadrent in tree 3 touching 0,0,0 - p8est_refine_ext(p8est, FALSE, 2, refine, NULL, NULL); - - p8est_ghost_t* ghost = p8est_ghost_new(p8est, P8EST_CONNECT_FULL); - - /* create mesh with edgehanging corner neighbor information */ - p8est_mesh_params_t params; - p8est_mesh_params_init (¶ms); - params.btype = P8EST_CONNECT_FULL; - params.edgehanging_corners = 1; - p8est_mesh_t* mesh = p8est_mesh_new_params (p8est, ghost, ¶ms); - P4EST_ASSERT(mesh->local_num_quadrants == 249); - - // assuming that the coarse quadrent is zero in tree 3 with ordering - p4est_locidx_t coarse_qid = 192; - - // upper and lower x,y,z indices - p4est_locidx_t lx_idx = P8EST_FACES * coarse_qid + 0; - p4est_locidx_t ux_idx = P8EST_FACES * coarse_qid + 1; - p4est_locidx_t ly_idx = P8EST_FACES * coarse_qid + 2; - p4est_locidx_t uy_idx = P8EST_FACES * coarse_qid + 3; - p4est_locidx_t uz_idx = P8EST_FACES * coarse_qid + 5; - - P4EST_ASSERT(mesh->quad_to_face[lx_idx] < 0); - P4EST_ASSERT(mesh->quad_to_face[ux_idx] < 0); - P4EST_ASSERT(mesh->quad_to_face[ly_idx] < 0); - P4EST_ASSERT(mesh->quad_to_face[uy_idx] < 0); - P4EST_ASSERT(mesh->quad_to_face[uz_idx] < 0); - - // get the quadrents on upper x,y,z faces of coarse quadrent - p4est_locidx_t qtq_lx, qtq_ux, qtq_ly, qtq_uy, qtq_uz; - qtq_lx = mesh->quad_to_quad[lx_idx]; - qtq_ux = mesh->quad_to_quad[ux_idx]; - qtq_ly = mesh->quad_to_quad[ly_idx]; - qtq_uy = mesh->quad_to_quad[uy_idx]; - qtq_uz = mesh->quad_to_quad[uz_idx]; - - p4est_locidx_t *qth_lx, *qth_ux, *qth_ly, *qth_uy, *qth_uz; - qth_lx = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_lx); - qth_ux = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_ux); - qth_ly = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_ly); - qth_uy = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_uy); - qth_uz = (p4est_locidx_t*) sc_array_index(mesh->quad_to_half,qtq_uz); - - p4est_locidx_t qid1, qid2; - p4est_locidx_t c1, c2; - p4est_locidx_t qtc1, qtc2; - - /*** test intra tree corners ***/ - //six pairs of corners with missing information - - //two along upper x upper y edge of coarse quad - - qid1 = qth_ux[1]; //lower quad along edge on x face of coarse quad - qid2 = qth_uy[3]; //upper quad along edge on y face of coarse quad - c1 = 6; // qid1 should have neighbor on uz uy lx corner - c2 = 1; // qid2 should have neighbor on lz ly ux corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); - - qid1 = qth_ux[3]; //upper quad along edge on x face of coarse quad - qid2 = qth_uy[1]; //lower quad along edge on y face of coarse quad - c1 = 2; // qid1 should have neighbor on lz uy lx corner - c2 = 5; // qid2 should have neighbor on uz ly ux corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); - - - //two along upper x upper z edge of coarse quad - - qid1 = qth_ux[2]; //lower quad along edge on x face of coarse quad - qid2 = qth_uz[3]; //upper quad along edge on z face of coarse quad - c1 = 6; // qid1 should have neighbor on uz uy lx corner - c2 = 1; // qid2 should have neighbor on lz ly ux corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); - - qid1 = qth_ux[3]; //upper quad along edge on x face - qid2 = qth_uz[1]; //lower quad along edge on z face - c1 = 4; // qid1 should have neighbor on uz ly lx corner - c2 = 3; // qid2 should have neighbor on lz uy ux corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); - - //two along upper y upper z edge of coarse quad - - qid1 = qth_uy[2]; //lower quad along edge on y face of coarse quad - qid2 = qth_uz[3]; //upper quad along edge on z face of coarse quad - c1 = 5; // qid1 should have neighbor on uz ly ux corner - c2 = 2; // qid2 should have neighbor on lz uy lx corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); - - qid1 = qth_uy[3]; //upper quad along edge on y face - qid2 = qth_uz[2]; //lower quad along edge on z face - c1 = 4; // qid1 should have neighbor on uz ly lx corner - c2 = 3; // qid2 should have neighbor on lz uy ux corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner(qid1,c1,qtc1,qid2); - num_errors += check_corner(qid2,c2,qtc2,qid1); - - - /*** test inter-tree corners across tree-face ***/ - //eight pairs of corners with missing information - - //two along lower x upper y edge of coarse quad (across face to tree 2) - - qid1 = qth_lx[1]; //lower quad along edge on x face of coarse quad - qid2 = qth_uy[2]; //upper quad along edge on y face of coarse quad - c1 = 7; // qid1 should have neighbor on uz uy ux corner - c2 = 0; // qid2 should have neighbor on lz ly lx corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); - num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); - - qid1 = qth_lx[3]; //upper quad along edge on x face of coarse quad - qid2 = qth_uy[0]; //lower quad along edge on y face of coarse quad - c1 = 3; // qid1 should have neighbor on lz uy ux corner - c2 = 4; // qid2 should have neighbor on uz ly lx corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); - num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); - - //two along lower x upper z edge of coarse quad (across face to tree 2) - - qid1 = qth_lx[2]; //lower quad along edge on x face of coarse quad - qid2 = qth_uz[2]; //upper quad along edge on z face of coarse quad - c1 = 7; // qid1 should have neighbor on uz uy ux corner - c2 = 0; // qid2 should have neighbor on lz ly lx corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); - num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); - - qid1 = qth_lx[3]; //upper quad along edge on x face of coarse quad - qid2 = qth_uz[0]; //lower quad along edge on z face of coarse quad - c1 = 5; // qid1 should have neighbor on uz ly ux corner - c2 = 2; // qid2 should have neighbor on lz uy lx corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); - num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); - - //two along upper x lower y edge of coarse quad (across face to tree 1) - - qid1 = qth_ux[0]; //lower quad along edge on x face of coarse quad - qid2 = qth_ly[3]; //upper quad along edge on y face of coarse quad - c1 = 4; // qid1 should have neighbor on uz ly lx corner - c2 = 3; // qid2 should have neighbor on lz uy ux corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); - num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); - - qid1 = qth_ux[2]; //upper quad along edge on x face of coarse quad - qid2 = qth_ly[1]; //lower quad along edge on y face of coarse quad - c1 = 0; // qid1 should have neighbor on lz ly lx corner - c2 = 7; // qid2 should have neighbor on uz uy ux corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); - num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); - - //two along lower y upper z edge of coarse quad (across face to tree 1) - - qid1 = qth_ly[2]; //lower quad along edge on y face of coarse quad - qid2 = qth_uz[1]; //upper quad along edge on z face of coarse quad - c1 = 7; // qid1 should have neighbor on uz uy ux corner - c2 = 0; // qid2 should have neighbor on lz ly lx corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); - num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); - - qid1 = qth_ly[3]; //upper quad along edge on y face of coarse quad - qid2 = qth_uz[0]; //lower quad along edge on z face of coarse quad - c1 = 6; // qid1 should have neighbor on uz uy lx corner - c2 = 1; // qid2 should have neighbor on lz ly ux corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); - num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); - - /*** test inter-tree corners across tree-edge ***/ - //two pairs of corners with missing information - - //two along lower x lower y edge of coarse quad (across edge to tree 0) - - qid1 = qth_lx[0]; //lower quad along edge on x face of coarse quad - qid2 = qth_ly[2]; //upper quad along edge on y face of coarse quad - c1 = 5; // qid1 should have neighbor on uz ly ux corner - c2 = 2; // qid2 should have neighbor on lz uy lx corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); - num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); - - qid1 = qth_lx[2]; //upper quad along edge on x face of coarse quad - qid2 = qth_ly[0]; //lower quad along edge on y face of coarse quad - c1 = 1; // qid1 should have neighbor on lz ly ux corner - c2 = 6; // qid2 should have neighbor on uz uy lx corner - qtc1 = mesh->quad_to_corner[P8EST_CHILDREN*qid1+c1]; - qtc2 = mesh->quad_to_corner[P8EST_CHILDREN*qid2+c2]; - num_errors += check_corner_across_trees(qid1,c1,qtc1,qid2,mesh); - num_errors += check_corner_across_trees(qid2,c2,qtc2,qid1,mesh); - - p8est_mesh_destroy(mesh); - p8est_ghost_destroy(ghost); - p8est_destroy(p8est); - p8est_connectivity_destroy(conn); - - sc_finalize(); - sc_MPI_Finalize(); - - return num_errors; -} \ No newline at end of file + int num_errors = 0; + sc_MPI_Comm mpicomm = sc_MPI_COMM_SELF; + p8est_connectivity_t *conn; + p8est_t *p8est; + p8est_ghost_t *ghost; + p8est_mesh_params_t params; + p8est_mesh_t *mesh; + p4est_locidx_t coarse_qid; + p4est_locidx_t lx_idx, ux_idx, ly_idx, uy_idx, uz_idx; + p4est_locidx_t qtq_lx, qtq_ux, qtq_ly, qtq_uy, qtq_uz; + p4est_locidx_t *qth_lx, *qth_ux, *qth_ly, *qth_uy, *qth_uz; + p4est_locidx_t qid1, qid2; + p4est_locidx_t c1, c2; + p4est_locidx_t qtc1, qtc2; + + 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 = p8est_connectivity_new_brick (2, 2, 1, 0, 0, 0); + p8est = p8est_new_ext (mpicomm, conn, 0, 1, 0, 0, NULL, NULL); + + /* refine all quadrants to level 2 except quadrant in tree 3 touching 0,0,0 */ + p8est_refine_ext (p8est, FALSE, 2, refine, NULL, NULL); + + ghost = p8est_ghost_new (p8est, P8EST_CONNECT_FULL); + + /* create mesh with edgehanging corner neighbor information */ + p8est_mesh_params_init (¶ms); + params.btype = P8EST_CONNECT_FULL; + params.edgehanging_corners = 1; + mesh = p8est_mesh_new_params (p8est, ghost, ¶ms); + P4EST_ASSERT (mesh->local_num_quadrants == 249); + + /* assuming that the coarse quadrant is zero in tree 3g */ + coarse_qid = 192; + + /* upper and lower x,y,z indices */ + lx_idx = P8EST_FACES * coarse_qid + 0; + ux_idx = P8EST_FACES * coarse_qid + 1; + ly_idx = P8EST_FACES * coarse_qid + 2; + uy_idx = P8EST_FACES * coarse_qid + 3; + uz_idx = P8EST_FACES * coarse_qid + 5; + + P4EST_ASSERT (mesh->quad_to_face[lx_idx] < 0); + P4EST_ASSERT (mesh->quad_to_face[ux_idx] < 0); + P4EST_ASSERT (mesh->quad_to_face[ly_idx] < 0); + P4EST_ASSERT (mesh->quad_to_face[uy_idx] < 0); + P4EST_ASSERT (mesh->quad_to_face[uz_idx] < 0); + + /* get the quadrants on upper x,y,z faces of the coarse quadrant */ + qtq_lx = mesh->quad_to_quad[lx_idx]; + qtq_ux = mesh->quad_to_quad[ux_idx]; + qtq_ly = mesh->quad_to_quad[ly_idx]; + qtq_uy = mesh->quad_to_quad[uy_idx]; + qtq_uz = mesh->quad_to_quad[uz_idx]; + + qth_lx = (p4est_locidx_t *) sc_array_index (mesh->quad_to_half, qtq_lx); + qth_ux = (p4est_locidx_t *) sc_array_index (mesh->quad_to_half, qtq_ux); + qth_ly = (p4est_locidx_t *) sc_array_index (mesh->quad_to_half, qtq_ly); + qth_uy = (p4est_locidx_t *) sc_array_index (mesh->quad_to_half, qtq_uy); + qth_uz = (p4est_locidx_t *) sc_array_index (mesh->quad_to_half, qtq_uz); + + /*** test intra tree corners ***/ + /* six pairs of corners with missing information */ + + /* two along upper x upper y edge of coarse quad */ + qid1 = qth_ux[1]; /* lower quad along edge on x face of coarse quad */ + qid2 = qth_uy[3]; /* upper quad along edge on y face of coarse quad */ + c1 = 6; /* qid1 should have neighbor on uz uy lx corner */ + c2 = 1; /* qid2 should have neighbor on lz ly ux corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner (qid1, c1, qtc1, qid2); + num_errors += check_corner (qid2, c2, qtc2, qid1); + + qid1 = qth_ux[3]; /* upper quad along edge on x face of coarse quad */ + qid2 = qth_uy[1]; /* lower quad along edge on y face of coarse quad */ + c1 = 2; /* qid1 should have neighbor on lz uy lx corner */ + c2 = 5; /* qid2 should have neighbor on uz ly ux corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner (qid1, c1, qtc1, qid2); + num_errors += check_corner (qid2, c2, qtc2, qid1); + + /* two along upper x upper z edge of coarse quad */ + qid1 = qth_ux[2]; /* lower quad along edge on x face of coarse quad */ + qid2 = qth_uz[3]; /* upper quad along edge on z face of coarse quad */ + c1 = 6; /* qid1 should have neighbor on uz uy lx corner */ + c2 = 1; /* qid2 should have neighbor on lz ly ux corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner (qid1, c1, qtc1, qid2); + num_errors += check_corner (qid2, c2, qtc2, qid1); + + qid1 = qth_ux[3]; /* upper quad along edge on x face */ + qid2 = qth_uz[1]; /* lower quad along edge on z face */ + c1 = 4; /* qid1 should have neighbor on uz ly lx corner */ + c2 = 3; /* qid2 should have neighbor on lz uy ux corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner (qid1, c1, qtc1, qid2); + num_errors += check_corner (qid2, c2, qtc2, qid1); + + /* two along upper y upper z edge of coarse quad */ + qid1 = qth_uy[2]; /* lower quad along edge on y face of coarse quad */ + qid2 = qth_uz[3]; /* upper quad along edge on z face of coarse quad */ + c1 = 5; /* qid1 should have neighbor on uz ly ux corner */ + c2 = 2; /* qid2 should have neighbor on lz uy lx corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner (qid1, c1, qtc1, qid2); + num_errors += check_corner (qid2, c2, qtc2, qid1); + + qid1 = qth_uy[3]; /* upper quad along edge on y face */ + qid2 = qth_uz[2]; /* lower quad along edge on z face */ + c1 = 4; /* qid1 should have neighbor on uz ly lx corner */ + c2 = 3; /* qid2 should have neighbor on lz uy ux corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner (qid1, c1, qtc1, qid2); + num_errors += check_corner (qid2, c2, qtc2, qid1); + + /*** test inter-tree corners across tree-face ***/ + /* eight pairs of corners with missing information */ + + /* two along lower x upper y edge of coarse quad (across face to tree 2) */ + qid1 = qth_lx[1]; /* lower quad along edge on x face of coarse quad */ + qid2 = qth_uy[2]; /* upper quad along edge on y face of coarse quad */ + c1 = 7; /* qid1 should have neighbor on uz uy ux corner */ + c2 = 0; /* qid2 should have neighbor on lz ly lx corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner_across_trees (qid1, c1, qtc1, qid2, mesh); + num_errors += check_corner_across_trees (qid2, c2, qtc2, qid1, mesh); + + qid1 = qth_lx[3]; /* upper quad along edge on x face of coarse quad */ + qid2 = qth_uy[0]; /* lower quad along edge on y face of coarse quad */ + c1 = 3; /* qid1 should have neighbor on lz uy ux corner */ + c2 = 4; /* qid2 should have neighbor on uz ly lx corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner_across_trees (qid1, c1, qtc1, qid2, mesh); + num_errors += check_corner_across_trees (qid2, c2, qtc2, qid1, mesh); + + /* two along lower x upper z edge of coarse quad (across face to tree 2) */ + qid1 = qth_lx[2]; /* lower quad along edge on x face of coarse quad */ + qid2 = qth_uz[2]; /* upper quad along edge on z face of coarse quad */ + c1 = 7; /* qid1 should have neighbor on uz uy ux corner */ + c2 = 0; /* qid2 should have neighbor on lz ly lx corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner_across_trees (qid1, c1, qtc1, qid2, mesh); + num_errors += check_corner_across_trees (qid2, c2, qtc2, qid1, mesh); + + qid1 = qth_lx[3]; /* upper quad along edge on x face of coarse quad */ + qid2 = qth_uz[0]; /* lower quad along edge on z face of coarse quad */ + c1 = 5; /* qid1 should have neighbor on uz ly ux corner */ + c2 = 2; /* qid2 should have neighbor on lz uy lx corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner_across_trees (qid1, c1, qtc1, qid2, mesh); + num_errors += check_corner_across_trees (qid2, c2, qtc2, qid1, mesh); + + /* two along upper x lower y edge of coarse quad (across face to tree 1) */ + qid1 = qth_ux[0]; /* lower quad along edge on x face of coarse quad */ + qid2 = qth_ly[3]; /* upper quad along edge on y face of coarse quad */ + c1 = 4; /* qid1 should have neighbor on uz ly lx corner */ + c2 = 3; /* qid2 should have neighbor on lz uy ux corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner_across_trees (qid1, c1, qtc1, qid2, mesh); + num_errors += check_corner_across_trees (qid2, c2, qtc2, qid1, mesh); + + qid1 = qth_ux[2]; /* upper quad along edge on x face of coarse quad */ + qid2 = qth_ly[1]; /* lower quad along edge on y face of coarse quad */ + c1 = 0; /* qid1 should have neighbor on lz ly lx corner */ + c2 = 7; /* qid2 should have neighbor on uz uy ux corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner_across_trees (qid1, c1, qtc1, qid2, mesh); + num_errors += check_corner_across_trees (qid2, c2, qtc2, qid1, mesh); + + /* two along lower y upper z edge of coarse quad (across face to tree 1) */ + qid1 = qth_ly[2]; /* lower quad along edge on y face of coarse quad */ + qid2 = qth_uz[1]; /* upper quad along edge on z face of coarse quad */ + c1 = 7; /* qid1 should have neighbor on uz uy ux corner */ + c2 = 0; /* qid2 should have neighbor on lz ly lx corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner_across_trees (qid1, c1, qtc1, qid2, mesh); + num_errors += check_corner_across_trees (qid2, c2, qtc2, qid1, mesh); + + qid1 = qth_ly[3]; /* upper quad along edge on y face of coarse quad */ + qid2 = qth_uz[0]; /* lower quad along edge on z face of coarse quad */ + c1 = 6; /* qid1 should have neighbor on uz uy lx corner */ + c2 = 1; /* qid2 should have neighbor on lz ly ux corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner_across_trees (qid1, c1, qtc1, qid2, mesh); + num_errors += check_corner_across_trees (qid2, c2, qtc2, qid1, mesh); + + /*** test inter-tree corners across tree-edge ***/ + /* two pairs of corners with missing information */ + + /* two along lower x lower y edge of coarse quad (across edge to tree 0) */ + qid1 = qth_lx[0]; /* lower quad along edge on x face of coarse quad */ + qid2 = qth_ly[2]; /* upper quad along edge on y face of coarse quad */ + c1 = 5; /* qid1 should have neighbor on uz ly ux corner */ + c2 = 2; /* qid2 should have neighbor on lz uy lx corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner_across_trees (qid1, c1, qtc1, qid2, mesh); + num_errors += check_corner_across_trees (qid2, c2, qtc2, qid1, mesh); + + qid1 = qth_lx[2]; /* upper quad along edge on x face of coarse quad */ + qid2 = qth_ly[0]; /* lower quad along edge on y face of coarse quad */ + c1 = 1; /* qid1 should have neighbor on lz ly ux corner */ + c2 = 6; /* qid2 should have neighbor on uz uy lx corner */ + qtc1 = mesh->quad_to_corner[P8EST_CHILDREN * qid1 + c1]; + qtc2 = mesh->quad_to_corner[P8EST_CHILDREN * qid2 + c2]; + num_errors += check_corner_across_trees (qid1, c1, qtc1, qid2, mesh); + num_errors += check_corner_across_trees (qid2, c2, qtc2, qid1, mesh); + + /* check for errors */ + SC_CHECK_ABORT (num_errors == 0, "Missing edge-hanging corner neighbors"); + + /* cleanup */ + p8est_mesh_destroy (mesh); + p8est_ghost_destroy (ghost); + p8est_destroy (p8est); + p8est_connectivity_destroy (conn); + + sc_finalize (); + sc_MPI_Finalize (); + + return num_errors; +} From 87103faf151a68759be2a0b05ab345dd1b888eb7 Mon Sep 17 00:00:00 2001 From: Hannes Brandt Date: Fri, 15 Dec 2023 14:13:59 +0100 Subject: [PATCH 9/9] test hanging-corners: replace TRUE/FALSE by 1/0 --- test/test_mesh_corners3.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/test_mesh_corners3.c b/test/test_mesh_corners3.c index 27a2ab1e9..5e798592b 100644 --- a/test/test_mesh_corners3.c +++ b/test/test_mesh_corners3.c @@ -2,17 +2,14 @@ #include #include -#define FALSE 0 -#define TRUE 1 - static int refine (p8est_t *p4est, p4est_topidx_t which_tree, p8est_quadrant_t *quadrant) { - int refine = TRUE; + int refine = 1; if (quadrant->x == 0 && quadrant->y == 0 && quadrant->z == 0 && which_tree == 3) { - refine = FALSE; + refine = 0; } return refine; } @@ -78,7 +75,7 @@ main (int argc, char **argv) p8est = p8est_new_ext (mpicomm, conn, 0, 1, 0, 0, NULL, NULL); /* refine all quadrants to level 2 except quadrant in tree 3 touching 0,0,0 */ - p8est_refine_ext (p8est, FALSE, 2, refine, NULL, NULL); + p8est_refine_ext (p8est, 0, 2, refine, NULL, NULL); ghost = p8est_ghost_new (p8est, P8EST_CONNECT_FULL);