From c5293c046df6a1f45ebc4438a88ef27848febc5a Mon Sep 17 00:00:00 2001 From: Niklas Date: Fri, 17 Apr 2026 11:43:49 +0200 Subject: [PATCH 1/7] Copy root element instead of returning a pointer to the root element when the pfc message is filled --- src/t8_forest/t8_forest_pfc_message.hxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/t8_forest/t8_forest_pfc_message.hxx b/src/t8_forest/t8_forest_pfc_message.hxx index 868aae6d24..8238d0e071 100644 --- a/src/t8_forest/t8_forest_pfc_message.hxx +++ b/src/t8_forest/t8_forest_pfc_message.hxx @@ -214,7 +214,8 @@ struct t8_forest_pfc_message // If we are already the root element, we cannot be part of a split family, so we send any(the root) element and no num_siblings. if (scheme->element_get_level (eclass, element_closest_to_receiver) == 0) { - parent = element_closest_to_receiver; + t8_element_new (scheme, eclass, 1, &parent); + scheme->element_copy (eclass, element_closest_to_receiver, parent); num_siblings = 0; } else { From 591bc9e6a153bfffdae440a079a94d367bfa7985 Mon Sep 17 00:00:00 2001 From: Niklas Date: Fri, 17 Apr 2026 13:15:20 +0200 Subject: [PATCH 2/7] Added comments --- src/t8_forest/t8_forest_pfc_message.hxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/t8_forest/t8_forest_pfc_message.hxx b/src/t8_forest/t8_forest_pfc_message.hxx index 8238d0e071..198b43214b 100644 --- a/src/t8_forest/t8_forest_pfc_message.hxx +++ b/src/t8_forest/t8_forest_pfc_message.hxx @@ -214,8 +214,11 @@ struct t8_forest_pfc_message // If we are already the root element, we cannot be part of a split family, so we send any(the root) element and no num_siblings. if (scheme->element_get_level (eclass, element_closest_to_receiver) == 0) { + // Allocate memory for the parent element. t8_element_new (scheme, eclass, 1, &parent); + // Copy the root element to the allocated parent element. scheme->element_copy (eclass, element_closest_to_receiver, parent); + // Set the number of siblings to zero, since there are none on the root level. num_siblings = 0; } else { From 64703e832739b3245935b44e1bdf7534d911b219 Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 15 Jun 2026 09:10:14 +0200 Subject: [PATCH 3/7] Removed duplicated line --- src/t8_forest/t8_forest_pfc_message.hxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/t8_forest/t8_forest_pfc_message.hxx b/src/t8_forest/t8_forest_pfc_message.hxx index 198b43214b..9041e5dc86 100644 --- a/src/t8_forest/t8_forest_pfc_message.hxx +++ b/src/t8_forest/t8_forest_pfc_message.hxx @@ -212,10 +212,11 @@ struct t8_forest_pfc_message scheme = t8_forest_get_scheme (forest); eclass = t8_forest_get_eclass (forest, t8_forest_get_local_id (forest, itree)); + // Allocate memory for the parent element. + t8_element_new (scheme, eclass, 1, &parent); + // If we are already the root element, we cannot be part of a split family, so we send any(the root) element and no num_siblings. if (scheme->element_get_level (eclass, element_closest_to_receiver) == 0) { - // Allocate memory for the parent element. - t8_element_new (scheme, eclass, 1, &parent); // Copy the root element to the allocated parent element. scheme->element_copy (eclass, element_closest_to_receiver, parent); // Set the number of siblings to zero, since there are none on the root level. @@ -223,7 +224,6 @@ struct t8_forest_pfc_message } else { // Compute parent. - t8_element_new (scheme, eclass, 1, &parent); scheme->element_get_parent (eclass, element_closest_to_receiver, parent); // Distinguish send "direction" From 28c65782830ef30a40a610b23fcbda8969962189 Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 15 Jun 2026 09:14:32 +0200 Subject: [PATCH 4/7] Corrected typo --- test/t8_forest/t8_gtest_partition_for_coarsening.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/t8_forest/t8_gtest_partition_for_coarsening.cxx b/test/t8_forest/t8_gtest_partition_for_coarsening.cxx index bda11ed815..33e63f8cd0 100644 --- a/test/t8_forest/t8_gtest_partition_for_coarsening.cxx +++ b/test/t8_forest/t8_gtest_partition_for_coarsening.cxx @@ -126,7 +126,7 @@ coarsen_all_callback ([[maybe_unused]] t8_forest_t forest, [[maybe_unused]] t8_f const int is_family, [[maybe_unused]] const int num_elements, [[maybe_unused]] t8_element_t *elements[]) { - // Coarsen revery family. + // Coarsen every family. return (is_family ? -1 : 0); } From 163d6eb23049ee6273387a89b01457a88eebfd12 Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 15 Jun 2026 09:57:36 +0200 Subject: [PATCH 5/7] Added a pfc test for root level meshes --- .../t8_gtest_partition_for_coarsening.cxx | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/test/t8_forest/t8_gtest_partition_for_coarsening.cxx b/test/t8_forest/t8_gtest_partition_for_coarsening.cxx index 33e63f8cd0..d0dfaa0ac7 100644 --- a/test/t8_forest/t8_gtest_partition_for_coarsening.cxx +++ b/test/t8_forest/t8_gtest_partition_for_coarsening.cxx @@ -133,7 +133,7 @@ coarsen_all_callback ([[maybe_unused]] t8_forest_t forest, [[maybe_unused]] t8_f /** * Class to test the partition-for-coarsening functionality. */ -struct t8_test_partition_for_coarsening_test: public testing::TestWithParam> +struct t8_test_partition_for_coarsening_test: public testing::TestWithParam> { protected: @@ -149,6 +149,9 @@ struct t8_test_partition_for_coarsening_test: public testing::TestWithParam (GetParam ())->cmesh_create (); cmesh_name = std::get<1> (GetParam ())->name; + // Get the initial uniform refinement level. + level = std::get<2> (GetParam ()); + // Skip empty meshes. if (t8_cmesh_is_empty (cmesh)) { GTEST_SKIP (); @@ -201,6 +204,7 @@ struct t8_test_partition_for_coarsening_test: public testing::TestWithParamref (); @@ -233,8 +234,18 @@ TEST_P (t8_test_partition_for_coarsening_test, test_partition_for_coarsening) // ----------------------------------------------------------- t8_global_productionf ("Adapt uniform forest.\n"); - // Create adapted base forest. - t8_forest_t adapted_base_forest = t8_forest_new_adapt (uniform_forest, refine_some_callback, 0, 0, nullptr); + // In some cases, we will adapt the uniform base forest. + t8_forest_t adapted_base_forest; + + /* Ensure that in case of the root level test there is no adaptation, such that the partition bound will + * definitely fall upon a root level element and the corresponding code section is covered. */ + if (level != 0) { + // In any other case, we perform some adaptation. + adapted_base_forest = t8_forest_new_adapt (uniform_forest, refine_some_callback, 0, 0, nullptr); + } + else { + adapted_base_forest = uniform_forest; + } #if T8_ENABLE_DEBUG // If debug mode and an additional manual flag are set, write forest to vtk. @@ -331,4 +342,5 @@ TEST_P (t8_test_partition_for_coarsening_test, test_partition_for_coarsening) // Instantiate parameterized test to be run for all schemes. INSTANTIATE_TEST_SUITE_P (t8_gtest_partition_for_coarsening, t8_test_partition_for_coarsening_test, - testing::Combine (AllSchemeCollections, AllCmeshsParam), pretty_print_base_example_scheme); + testing::Combine (AllSchemeCollections, AllCmeshsParam, testing::Values (0, 2)), + pretty_print_base_example_scheme); From c308222495db6fe1842365e5195df50b69ffe5f7 Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 15 Jun 2026 10:48:03 +0200 Subject: [PATCH 6/7] Replaced the function pretty_print_level_and_cmesh_params --- test/t8_cmesh_generator/t8_cmesh_example_sets.hxx | 14 ++++++++++++++ test/t8_forest/t8_gtest_element_is_leaf.cxx | 13 ------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/test/t8_cmesh_generator/t8_cmesh_example_sets.hxx b/test/t8_cmesh_generator/t8_cmesh_example_sets.hxx index 83ece334e7..7c0b94f3a6 100644 --- a/test/t8_cmesh_generator/t8_cmesh_example_sets.hxx +++ b/test/t8_cmesh_generator/t8_cmesh_example_sets.hxx @@ -63,6 +63,20 @@ auto pretty_print_base_example_scheme = [] (const testing::TestParamInfo. + * Intended as a lambda to pass to an INSTANTIATE_TEST_SUITE_P + * to print the current scheme, level and \ref cmesh_example_base. */ +auto pretty_print_level_and_cmesh_params + = [] (const testing::TestParamInfo> &info) { + std::string name = std::string ("Level_") + std::to_string (std::get<1> (info.param)); + std::string cmesh_name; + std::get<2> (info.param)->param_to_string (cmesh_name); + name += std::string ("_") + cmesh_name; + name += std::string ("scheme_") + std::to_string (std::get<0> (info.param)); + name += std::string ("_") + std::to_string (info.index); + return name; + }; + namespace cmesh_list { /** Vector of all example cmesh sets. */ diff --git a/test/t8_forest/t8_gtest_element_is_leaf.cxx b/test/t8_forest/t8_gtest_element_is_leaf.cxx index c297f2f856..474eed21cf 100644 --- a/test/t8_forest/t8_gtest_element_is_leaf.cxx +++ b/test/t8_forest/t8_gtest_element_is_leaf.cxx @@ -181,19 +181,6 @@ TEST_P (element_is_leaf_or_ghost, element_is_ghost_adapt) t8_test_element_is_leaf_for_forest (forest_adapt); } -/* Define a lambda to beautify gtest output for tuples . - * This will set the correct scheme, level and cmesh name as part of the test case name. */ -auto pretty_print_level_and_cmesh_params - = [] (const testing::TestParamInfo> &info) { - std::string name = std::string ("Level_") + std::to_string (std::get<1> (info.param)); - std::string cmesh_name; - std::get<2> (info.param)->param_to_string (cmesh_name); - name += std::string ("_") + cmesh_name; - name += std::string ("scheme_") + std::to_string (std::get<0> (info.param)); - name += std::string ("_") + std::to_string (info.index); - return name; - }; - INSTANTIATE_TEST_SUITE_P (t8_gtest_element_is_leaf_or_ghost, element_is_leaf_or_ghost, testing::Combine (AllSchemeCollections, testing::Range (0, T8_IS_LEAF_MAX_LVL), AllCmeshsParam), From 3d565a100c4fe431010c2629b90b63f7a5b9b7c0 Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 15 Jun 2026 10:49:00 +0200 Subject: [PATCH 7/7] Updated the utilized print output lambda function --- .../t8_gtest_partition_for_coarsening.cxx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/t8_forest/t8_gtest_partition_for_coarsening.cxx b/test/t8_forest/t8_gtest_partition_for_coarsening.cxx index d0dfaa0ac7..5f6a9cc71d 100644 --- a/test/t8_forest/t8_gtest_partition_for_coarsening.cxx +++ b/test/t8_forest/t8_gtest_partition_for_coarsening.cxx @@ -133,7 +133,7 @@ coarsen_all_callback ([[maybe_unused]] t8_forest_t forest, [[maybe_unused]] t8_f /** * Class to test the partition-for-coarsening functionality. */ -struct t8_test_partition_for_coarsening_test: public testing::TestWithParam> +struct t8_test_partition_for_coarsening_test: public testing::TestWithParam> { protected: @@ -145,12 +145,12 @@ struct t8_test_partition_for_coarsening_test: public testing::TestWithParam (GetParam ()); scheme = create_from_scheme_id (scheme_id); - // Construct cmesh and store name. - cmesh = std::get<1> (GetParam ())->cmesh_create (); - cmesh_name = std::get<1> (GetParam ())->name; - // Get the initial uniform refinement level. - level = std::get<2> (GetParam ()); + level = std::get<1> (GetParam ()); + + // Construct cmesh and store name. + cmesh = std::get<2> (GetParam ())->cmesh_create (); + cmesh_name = std::get<2> (GetParam ())->name; // Skip empty meshes. if (t8_cmesh_is_empty (cmesh)) { @@ -203,8 +203,8 @@ struct t8_test_partition_for_coarsening_test: public testing::TestWithParam