-
Notifications
You must be signed in to change notification settings - Fork 74
Improvement: add test for t8_forest_element_neighbor_eclass
#2276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benegee
wants to merge
9
commits into
main
Choose a base branch
from
bg/test_t8_forest_element_neighbor_eclass
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ffc3f84
add new test
benegee 668556d
Merge branch 'main' into bg/test_t8_forest_element_neighbor_eclass
benegee 6d71d8f
make test run
benegee 7f5ce0b
Merge branch 'main' into bg/test_t8_forest_element_neighbor_eclass
benegee c91fc22
typo
benegee a8f3ae4
test level 0..4
benegee 36f516f
add ghost eclass check
benegee 43c744a
only store the forest in the testing struct
benegee 61b8847
add partition to full_hybrid cmesh
benegee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| This file is part of t8code. | ||
| t8code is a C library to manage a collection (a forest) of multiple | ||
| connected adaptive space-trees of general element classes in parallel. | ||
|
|
||
| Copyright (C) 2026 the developers | ||
|
|
||
| t8code is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| t8code is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with t8code; if not, write to the Free Software Foundation, Inc., | ||
| 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| */ | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <test/t8_gtest_schemes.hxx> | ||
|
|
||
| #include <t8_forest/t8_forest_ghost.h> | ||
| #include <t8_cmesh/t8_cmesh_examples.h> | ||
| #include <t8_forest/t8_forest_private.h> | ||
|
|
||
| struct element_neighbor_eclass: public testing::TestWithParam<std::tuple<int, int>> | ||
| { | ||
| protected: | ||
| void | ||
| SetUp () override | ||
| { | ||
| const bool do_ghost = true; | ||
| const int scheme_id = std::get<0> (GetParam ()); | ||
| scheme = create_from_scheme_id (scheme_id); | ||
| const int level = std::get<1> (GetParam ()); | ||
|
|
||
| // Construct a hybrid coarse mesh | ||
| cmesh = t8_cmesh_new_full_hybrid (sc_MPI_COMM_WORLD); | ||
|
|
||
| // Build a uniform forest | ||
| forest = t8_forest_new_uniform (cmesh, scheme, level, do_ghost, sc_MPI_COMM_WORLD); | ||
| } | ||
|
|
||
| void | ||
| TearDown () override | ||
| { | ||
| t8_forest_unref (&forest); | ||
| } | ||
|
|
||
| t8_cmesh_t cmesh; | ||
| t8_forest_t forest; | ||
| const t8_scheme *scheme; | ||
| }; | ||
|
|
||
| TEST_P (element_neighbor_eclass, test_half_neighbors) | ||
| { | ||
| // Iterate over all trees (local and ghosts) | ||
| const t8_locidx_t num_local_trees = t8_forest_get_num_local_trees (forest); | ||
| const t8_locidx_t num_ghost_trees = t8_forest_get_num_ghost_trees (forest); | ||
|
|
||
| for (t8_locidx_t itree = 0; itree < num_local_trees + num_ghost_trees; itree++) { | ||
|
|
||
| const t8_eclass_t tree_eclass = t8_forest_get_tree_class (forest, itree); | ||
| const bool is_ghost = itree >= num_local_trees; | ||
| const t8_locidx_t ghost_tree_id = itree - num_local_trees; | ||
| const t8_element_array_t *leaf_elements = is_ghost ? t8_forest_ghost_get_tree_leaf_elements (forest, ghost_tree_id) | ||
| : t8_forest_get_tree_leaf_element_array (forest, itree); | ||
| const t8_locidx_t num_leaves = t8_element_array_get_count (leaf_elements); | ||
| const t8_locidx_t ltreeid_in_cmesh = t8_forest_ltreeid_to_cmesh_ltreeid (forest, itree); | ||
|
|
||
| // Iterate over all leaf elements | ||
| for (t8_locidx_t ileaf = 0; ileaf < num_leaves; ++ileaf) { | ||
|
|
||
| const t8_element_t *element = t8_element_array_index_locidx (leaf_elements, ileaf); | ||
|
|
||
| // Iterate over all faces | ||
| for (int iface = 0; iface < scheme->element_get_num_faces (tree_eclass, element); iface++) { | ||
|
|
||
| // Get the eclass of the face neighbor (function to test) | ||
| const t8_eclass_t neigh_class = t8_forest_element_neighbor_eclass (forest, itree, element, iface); | ||
|
|
||
| // Inside the current tree | ||
| if (!scheme->element_is_root_boundary (tree_eclass, element, iface)) { | ||
| // We expect to get the same eclass | ||
| EXPECT_EQ (neigh_class, tree_eclass); | ||
| } | ||
| // Crossing a tree boundary | ||
| else { | ||
| // Get neighbor tree id | ||
| const int tree_face = scheme->element_get_tree_face (tree_eclass, element, iface); | ||
| t8_locidx_t const neighbor_id | ||
| = t8_cmesh_get_face_neighbor (cmesh, ltreeid_in_cmesh, tree_face, nullptr, nullptr); | ||
|
|
||
| if (neighbor_id < 0) { | ||
| // No neighbor | ||
| EXPECT_EQ (neigh_class, T8_ECLASS_INVALID); | ||
| } | ||
| else { | ||
| // Neighbor | ||
| const bool neighbor_is_ghost = t8_cmesh_treeid_is_ghost (cmesh, neighbor_id); | ||
| if (!neighbor_is_ghost) { | ||
| EXPECT_EQ (neigh_class, t8_cmesh_get_tree_class (cmesh, neighbor_id)); | ||
| } | ||
| else { | ||
| const t8_locidx_t lghost_neighbor_id = neighbor_id - t8_cmesh_get_num_local_trees (cmesh); | ||
| EXPECT_EQ (neigh_class, t8_cmesh_get_ghost_class (cmesh, lghost_neighbor_id)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| INSTANTIATE_TEST_SUITE_P (t8_gtest_element_neighbor_eclass, element_neighbor_eclass, | ||
| testing::Combine (AllSchemeCollections, testing::Range (0, 4))); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.