Skip to content

Commit

Permalink
Merge pull request #1087 from DLR-AMR/fix_cmesh-copy
Browse files Browse the repository at this point in the history
Fix most of cmesh_copy
  • Loading branch information
Davknapp authored Jun 27, 2024
2 parents 3641025 + 91a38df commit 07bffa6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 34 deletions.
18 changes: 10 additions & 8 deletions src/t8_cmesh/t8_cmesh_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ t8_cmesh_copy (t8_cmesh_t cmesh, t8_cmesh_t cmesh_from, sc_MPI_Comm comm)
if (cmesh_from->tree_offsets != NULL) {
T8_ASSERT (cmesh->tree_offsets == NULL);
cmesh->tree_offsets = t8_cmesh_alloc_offsets (cmesh->mpisize, comm);
sc_shmem_memcpy (cmesh->tree_offsets, cmesh_from->tree_offsets, sizeof (t8_gloidx_t) * (cmesh->mpisize + 1), comm);
t8_shmem_array_copy (cmesh->tree_offsets, cmesh_from->tree_offsets);
}
/* Copy the numbers of trees */
memcpy (cmesh->num_trees_per_eclass, cmesh_from->num_trees_per_eclass, T8_ECLASS_COUNT * sizeof (t8_gloidx_t));
Expand All @@ -69,13 +69,15 @@ t8_cmesh_copy (t8_cmesh_t cmesh, t8_cmesh_t cmesh_from, sc_MPI_Comm comm)
T8_ECLASS_COUNT * sizeof (t8_locidx_t));

/* Copy the tree info */
num_parts = t8_cmesh_trees_get_numproc (cmesh_from->trees);
cmesh->trees = NULL;
t8_cmesh_trees_init (&cmesh->trees, num_parts, cmesh_from->num_local_trees, cmesh_from->num_ghosts);
t8_cmesh_trees_copy_toproc (cmesh->trees, cmesh_from->trees, cmesh_from->num_local_trees, cmesh_from->num_ghosts);
for (iz = 0; iz < num_parts; iz++) {
t8_cmesh_trees_get_part_data (cmesh_from->trees, iz, &first_tree, &num_trees, &first_ghost, &num_ghosts);
t8_cmesh_trees_start_part (cmesh->trees, iz, first_tree, num_trees, first_ghost, num_ghosts, 0);
t8_cmesh_trees_copy_part (cmesh->trees, iz, cmesh_from->trees, iz);
if (cmesh_from->trees) {
num_parts = t8_cmesh_trees_get_numproc (cmesh_from->trees);
t8_cmesh_trees_init (&cmesh->trees, num_parts, cmesh_from->num_local_trees, cmesh_from->num_ghosts);
t8_cmesh_trees_copy_toproc (cmesh->trees, cmesh_from->trees, cmesh_from->num_local_trees, cmesh_from->num_ghosts);
for (iz = 0; iz < num_parts; iz++) {
t8_cmesh_trees_get_part_data (cmesh_from->trees, iz, &first_tree, &num_trees, &first_ghost, &num_ghosts);
t8_cmesh_trees_start_part (cmesh->trees, iz, first_tree, num_trees, first_ghost, num_ghosts, 0);
t8_cmesh_trees_copy_part (cmesh->trees, iz, cmesh_from->trees, iz);
}
}
}
1 change: 1 addition & 0 deletions src/t8_cmesh/t8_cmesh_trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ t8_cmesh_trees_get_attribute (const t8_cmesh_trees_t trees, const t8_locidx_t lt
size_t
t8_cmesh_trees_get_numproc (const t8_cmesh_trees_t trees)
{
T8_ASSERT (trees != NULL);
return trees->from_proc->elem_count;
}

Expand Down
39 changes: 13 additions & 26 deletions test/t8_cmesh/t8_gtest_cmesh_copy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,19 @@
* We test whether the new and original cmesh are equal.
*/

/* Note: This test currently fails on many cmeshes and is thus deavtivated.
* See: https://github.com/DLR-AMR/t8code/issues/920
*/

/* Remove `DISABLED_` from the name of the Test(suite) or use `--gtest_also_run_disabled_tests` when you start working on the issue. */
class DISABLED_t8_cmesh_copy: public testing::TestWithParam<cmesh_example_base *> {
class t8_cmesh_copy: public testing::TestWithParam<cmesh_example_base *> {
protected:
void
SetUp () override
{
/* Skip test since cmesh copy is not yet working. See https://github.com/DLR-AMR/t8code/issues/920 */

cmesh_original = GetParam ()->cmesh_create ();

/* Initialized test cmesh that we derive in the test */
t8_cmesh_init (&cmesh);
}

void
TearDown () override
{
/* Skip test since cmesh copy is not yet working. See https://github.com/DLR-AMR/t8code/issues/920 */

/* Unref both cmeshes */
t8_cmesh_unref (&cmesh);
t8_cmesh_unref (&cmesh_original);
}

t8_cmesh_t cmesh;
t8_cmesh_t cmesh_original;
};

Expand All @@ -72,16 +57,18 @@ test_cmesh_committed (t8_cmesh_t cmesh)
ASSERT_TRUE (t8_cmesh_trees_is_face_consistent (cmesh, cmesh->trees)) << "Cmesh face consistency failed.";
}

TEST_P (DISABLED_t8_cmesh_copy, test_cmesh_copy)
TEST_P (t8_cmesh_copy, test_cmesh_copy)
{
t8_cmesh_set_derive (cmesh, cmesh_original);
t8_cmesh_commit (cmesh, sc_MPI_COMM_WORLD);

test_cmesh_committed (cmesh);

EXPECT_TRUE (t8_cmesh_is_equal (cmesh, cmesh_original));
t8_cmesh_t cmesh_copy;
t8_cmesh_init (&cmesh_copy);
t8_cmesh_ref (cmesh_original);
t8_cmesh_set_derive (cmesh_copy, cmesh_original);
t8_cmesh_commit (cmesh_copy, sc_MPI_COMM_WORLD);

test_cmesh_committed (cmesh_copy);
EXPECT_TRUE (t8_cmesh_is_equal (cmesh_copy, cmesh_original));
t8_cmesh_unref (&cmesh_copy);
}

/* Test all cmeshes over all different inputs*/

INSTANTIATE_TEST_SUITE_P (t8_gtest_cmesh_copy, DISABLED_t8_cmesh_copy, AllCmeshsParam, pretty_print_base_example);
INSTANTIATE_TEST_SUITE_P (t8_gtest_cmesh_copy, t8_cmesh_copy, AllCmeshsParam, pretty_print_base_example);

0 comments on commit 07bffa6

Please sign in to comment.