Skip to content

Commit 14c650a

Browse files
authored
Merge pull request #2078 from DLR-AMR/handle-add-destructor
Feature: Destructor for mesh handle
2 parents 6aedab7 + b9a66b1 commit 14c650a

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

mesh_handle/mesh.hxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ class mesh {
5959
update_elements ();
6060
}
6161

62+
/**
63+
* Destructor for a mesh of the handle.
64+
* The forest in use will be unreferenced.
65+
* Call \ref t8_forest_ref before if you want to keep it alive.
66+
*/
67+
~mesh ()
68+
{
69+
t8_forest_unref (&m_forest);
70+
}
71+
6272
/**
6373
* Getter for the number of local elements in the mesh.
6474
* \return Number of local elements in the mesh.

test/mesh_handle/t8_gtest_cache_competence.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ class t8_gtest_cache_competence: public testing::Test {
8282
void
8383
TearDown () override
8484
{
85-
t8_forest_unref (&forest);
85+
if (forest->rc.refcount > 0) {
86+
t8_forest_unref (&forest);
87+
}
8688
}
8789

8890
t8_forest_t forest;

test/mesh_handle/t8_gtest_compare_handle_to_forest.cxx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,4 @@ TEST (t8_gtest_compare_handle_to_forest, compare_handle_to_forest)
7676
mesh_iterator++;
7777
}
7878
}
79-
80-
// Unref the forest.
81-
t8_forest_unref (&forest);
8279
}

test/mesh_handle/t8_gtest_custom_competence.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ TEST (t8_gtest_custom_competence, custom_competence)
9696
EXPECT_EQ (level, it->get_level_dummy ());
9797
}
9898

99+
t8_forest_ref (forest);
99100
// Test with two custom competences and a predefined competence.
100101
using mesh_class = t8_mesh_handle::mesh<dummy_get_level, dummy_trivial, t8_mesh_handle::cache_centroid>;
101102
mesh_class mesh_more_competences = mesh_class (forest);
@@ -111,7 +112,4 @@ TEST (t8_gtest_custom_competence, custom_competence)
111112
}
112113
EXPECT_TRUE (it->centroid_cache_filled ());
113114
}
114-
115-
// Unref the forest.
116-
t8_forest_unref (&forest);
117115
}

test/mesh_handle/t8_gtest_ghost.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ class t8_mesh_ghost_test: public testing::TestWithParam<std::tuple<t8_eclass_t,
5454
void
5555
TearDown () override
5656
{
57-
t8_forest_unref (&forest);
57+
if (forest->rc.refcount > 0) {
58+
t8_forest_unref (&forest);
59+
}
5860
}
5961
t8_forest_t forest;
6062
int level;

test/mesh_handle/t8_gtest_mesh_handle.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class t8_mesh_handle_test: public testing::TestWithParam<std::tuple<t8_eclass_t,
5151
void
5252
TearDown () override
5353
{
54-
t8_forest_unref (&forest);
54+
if (forest->rc.refcount > 0) {
55+
t8_forest_unref (&forest);
56+
}
5557
}
5658

5759
t8_forest_t forest;
@@ -133,6 +135,7 @@ TEST_P (t8_mesh_handle_test, test_competences)
133135
}
134136

135137
// --- Version with cached centroid variable. ---
138+
t8_forest_ref (forest);
136139
using mesh_class_centroid = t8_mesh_handle::mesh<t8_mesh_handle::cache_centroid>;
137140
using element_class_centroid = mesh_class_centroid::element_class;
138141
mesh_class_centroid mesh_centroid = mesh_class_centroid (forest);

0 commit comments

Comments
 (0)