-
Notifications
You must be signed in to change notification settings - Fork 63
Improvement: Custom competence test for mesh interface #1895
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
Merged
lenaploetzke
merged 9 commits into
1655-define-structure-of-the-unstructured-mesh-class
from
interface-custom-competence-test
Oct 22, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cebf72b
added test with custom competence
lenaploetzke 1a17965
correct access specifier in competence and easier use of members.
lenaploetzke 4b4acb7
faster unstructured mesh test
lenaploetzke c7c6464
added missing !
lenaploetzke 4e293dc
Apply suggestions from code review
lenaploetzke 9f6ace0
code review
lenaploetzke 945b6cd
Merge branch '1655-define-structure-of-the-unstructured-mesh-class' i…
lenaploetzke 13360ae
add has_..._cache functions
lenaploetzke 0d538bf
review
lenaploetzke 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
107 changes: 107 additions & 0 deletions
107
test/t8_unstructured_mesh/t8_gtest_custom_competence.cxx
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,107 @@ | ||
| /* | ||
| 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) 2025 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. | ||
| */ | ||
|
|
||
| /** | ||
| * \file t8_gtest_custom_competence.cxx | ||
| * Checks that custom-defined competences can be used as template parameters for the unstructured mesh interface. | ||
| */ | ||
|
|
||
| #include <gtest/gtest.h> | ||
| #include <test/t8_gtest_schemes.hxx> | ||
| #include <t8.h> | ||
|
|
||
| #include <t8_unstructured_mesh/t8_unstructured_mesh.hxx> | ||
| #include <t8_unstructured_mesh/t8_unstructured_element.hxx> | ||
| #include <t8_unstructured_mesh/t8_element_competences.hxx> | ||
| #include <t8_cmesh.h> | ||
| #include <t8_cmesh/t8_cmesh_examples.h> | ||
| #include <t8_forest/t8_forest_general.h> | ||
| #include <t8_schemes/t8_default/t8_default.hxx> | ||
| #include <t8_types/t8_operators.hxx> | ||
|
|
||
| /** Custom competence that needs access to the public members of the elements. */ | ||
| template <typename TUnderlying> | ||
| struct dummy_get_level: public t8_crtp_operator<TUnderlying, dummy_get_level> | ||
| { | ||
| public: | ||
| t8_element_level | ||
| get_level_dummy () const | ||
| { | ||
| auto forest = this->underlying ().get_unstructured_mesh ()->get_forest (); | ||
| const t8_eclass_t tree_class = t8_forest_get_tree_class (forest, this->underlying ().get_tree_id ()); | ||
| const t8_element_t *element = t8_forest_get_leaf_element_in_tree (forest, this->underlying ().get_tree_id (), | ||
| this->underlying ().get_element_id ()); | ||
| return t8_forest_get_scheme (forest)->element_get_level (tree_class, element); | ||
| } | ||
| }; | ||
|
|
||
| /** Second custom competence. */ | ||
| template <typename TUnderlying> | ||
| struct dummy_trivial: public t8_crtp_operator<TUnderlying, dummy_trivial> | ||
| { | ||
| public: | ||
| int | ||
| get_value_dummy () const | ||
| { | ||
| return 1; | ||
| } | ||
| }; | ||
|
|
||
| /** This tests checks that custom defined competences can be used for the unstructured mesh class and that we can use the functionality defined in the competence. Also checks that we can use more than one custom competence and that predefined competences can be additionally used. */ | ||
| TEST (t8_gtest_custom_competence, custom_competence) | ||
| { | ||
| // Define forest to construct unstructured mesh. | ||
| const int level = 1; | ||
| t8_cmesh_t cmesh = t8_cmesh_new_hypercube_hybrid (sc_MPI_COMM_WORLD, 0, 0); | ||
| const t8_scheme *scheme = t8_scheme_new_default (); | ||
| t8_forest_t forest = t8_forest_new_uniform (cmesh, scheme, level, 0, sc_MPI_COMM_WORLD); | ||
| ASSERT_EQ (true, t8_forest_is_committed (forest)); | ||
|
|
||
| // Check mesh with custom defined competence. | ||
| t8_unstructured_mesh<t8_unstructured_mesh_element<dummy_get_level>> unstructured_mesh | ||
| = t8_unstructured_mesh<t8_unstructured_mesh_element<dummy_get_level>> (forest); | ||
|
|
||
| for (auto it = unstructured_mesh.begin (); it != unstructured_mesh.end (); ++it) { | ||
| EXPECT_EQ (it->get_level (), it->get_level_dummy ()); | ||
| EXPECT_EQ (level, it->get_level_dummy ()); | ||
| } | ||
|
|
||
| // Test with two custom competences and a predefined competence. | ||
| t8_unstructured_mesh<t8_unstructured_mesh_element<dummy_get_level, dummy_trivial, t8_cache_centroid>> | ||
| unstructured_mesh_2competences | ||
| = t8_unstructured_mesh<t8_unstructured_mesh_element<dummy_get_level, dummy_trivial, t8_cache_centroid>> (forest); | ||
|
|
||
| for (auto it = unstructured_mesh_2competences.begin (); it != unstructured_mesh_2competences.end (); ++it) { | ||
| EXPECT_EQ (it->get_level (), it->get_level_dummy ()); | ||
| EXPECT_EQ (it->get_value_dummy (), 1); | ||
| EXPECT_FALSE (it->centroid_cache_filled ()); | ||
| auto centroid = it->get_centroid (); | ||
| for (const auto &coordinate : centroid) { | ||
| EXPECT_GE (1, coordinate); | ||
| EXPECT_LE (0, coordinate); | ||
| } | ||
| EXPECT_TRUE (it->centroid_cache_filled ()); | ||
| } | ||
|
|
||
| // Unref the forest. | ||
| t8_forest_unref (&forest); | ||
| } | ||
Oops, something went wrong.
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.