Skip to content
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

Test ghost for forests with holes #828

Merged
merged 7 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ t8code_googletest_programs = \
test/t8_forest/t8_gtest_user_data \
test/t8_forest/t8_gtest_transform \
test/t8_forest/t8_gtest_ghost_exchange \
test/t8_forest/t8_gtest_ghost_delete \
test/t8_forest/t8_gtest_ghost_and_owner \
test/t8_IO/t8_gtest_vtk_reader \
test/t8_forest_incomplete/t8_gtest_permute_hole \
Expand Down Expand Up @@ -210,6 +211,10 @@ test_t8_forest_t8_gtest_ghost_exchange_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_forest/t8_gtest_ghost_exchange.cxx

test_t8_forest_t8_gtest_ghost_delete_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_forest/t8_gtest_ghost_delete.cxx

test_t8_forest_t8_gtest_ghost_and_owner_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_forest/t8_gtest_ghost_and_owner.cxx
Expand Down Expand Up @@ -399,6 +404,10 @@ test_t8_forest_t8_gtest_ghost_exchange_LDADD = $(t8_gtest_target_ld_add)
test_t8_forest_t8_gtest_ghost_exchange_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS = $(t8_gtest_target_cpp_flags)

test_t8_forest_t8_gtest_ghost_delete_LDADD = $(t8_gtest_target_ld_add)
test_t8_forest_t8_gtest_ghost_delete_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_forest_t8_gtest_ghost_delete_CPPFLAGS = $(t8_gtest_target_cpp_flags)

test_t8_forest_t8_gtest_ghost_and_owner_LDADD = $(t8_gtest_target_ld_add)
test_t8_forest_t8_gtest_ghost_and_owner_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS = $(t8_gtest_target_cpp_flags)
Expand Down Expand Up @@ -469,6 +478,7 @@ test_t8_geometry_t8_gtest_point_inside_CPPFLAGS += $(t8_gtest_target_mpi_cpp_fla
test_t8_forest_t8_gtest_user_data_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_transform_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_ghost_delete_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_IO_t8_gtest_vtk_reader_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_incomplete_t8_gtest_permute_hole_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
Expand Down
120 changes: 120 additions & 0 deletions test/t8_forest/t8_gtest_ghost_delete.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
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) 2015 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 <t8_eclass.h>
#include <t8_schemes/t8_default/t8_default_cxx.hxx>
#include <t8_forest/t8_forest_general.h>
#include <t8_forest/t8_forest_geometrical.h>
#include <t8_forest/t8_forest_ghost.h>
#include <t8_forest/t8_forest_private.h>
#include <t8_cmesh.h>
#include <t8_cmesh/t8_cmesh_examples.h>

/* This test is executed on a subcommunicator of exactly 2 procs, because it demonstrates a configuration that is currently not working
* A partitioned square of uniform refinement level 1 is adapted once, where only the lower half is refined.
* Then the mesh is adapted again, where only the upper half of the lower elements is deleted.
* Now, no element actually has a face connection to an existing element on the other proc, but they send a message anyway.
*/


/* refine elements, whose y coordinate is 0, so that the lowest row is refined
* delete elements, whose y coordniate is 0.25, so that the second row is deleted
*/
static int
test_adapt_holes (t8_forest_t forest, t8_forest_t forest_from, t8_locidx_t which_tree, t8_locidx_t lelement_id,
t8_eclass_scheme_c *ts, const int is_family, const int num_elements, t8_element_t *elements[])
{
double coordinates[3];
t8_forest_element_coordinate (forest_from, which_tree, elements[0], 0, coordinates);
if (fabs (coordinates[1]) < T8_PRECISION_EPS)
return 1; // refine the lowest row
if (fabs (coordinates[1] - 0.25) < T8_PRECISION_EPS)
return -2; // delete the higher row in the lower quadrants
return 0;
}

class forest_ghost_exchange_holes: public testing::Test {
protected:
void
SetUp () override
{
/* adjust communicator size, we split the comm here, because we know that the test fails on 2 procs*/
int size, rank, color, key;

sc_MPI_Comm_size (sc_MPI_COMM_WORLD, &size);
sc_MPI_Comm_rank (sc_MPI_COMM_WORLD, &rank);

if (rank < 2) {
color = 0;
key = rank;
}
else {
color = sc_MPI_UNDEFINED;
key = -1;
}
sc_MPI_Comm_split (sc_MPI_COMM_WORLD, color, key, &comm);
T8_ASSERT (rank < 2 || comm == sc_MPI_COMM_NULL);

if (comm != sc_MPI_COMM_NULL) {
sc_MPI_Comm_size (comm, &size);
T8_ASSERT(size <= 2);
scheme = t8_scheme_new_default_cxx ();
/* Construct a cmesh */
cmesh = t8_cmesh_new_hypercube (T8_ECLASS_QUAD, comm, 0, 0, 0);
}else{
T8_ASSERT(rank >= 2);
}
}
void
TearDown () override
{
//cmesh and scheme are freed taken and freed by forest
if (comm != sc_MPI_COMM_NULL) {
sc_MPI_Comm_free (&comm);
}
sc_MPI_Barrier (sc_MPI_COMM_WORLD);
t8_cmesh_unref (&cmesh);
t8_scheme_cxx_unref (&scheme);
}
sc_MPI_Comm comm;
t8_scheme_cxx_t *scheme;
t8_cmesh_t cmesh;
};

TEST_F (forest_ghost_exchange_holes, errorTest)
{
/* This test tests the functionality described in Issue: https://github.com/DLR-AMR/t8code/issues/825
* Remove the GTEST_SKIP() macros when you start working on the issue.
*/
GTEST_SKIP();
if (comm != sc_MPI_COMM_NULL) {
const int level = 1;
const int execute_ghost = 1;
t8_cmesh_ref(cmesh);
t8_scheme_cxx_ref(scheme);
t8_forest_t forest = t8_forest_new_uniform (cmesh, scheme, level, 1, comm);
forest = t8_forest_new_adapt (forest, test_adapt_holes, 0, execute_ghost, NULL);
forest = t8_forest_new_adapt (forest, test_adapt_holes, 0, execute_ghost, NULL);
t8_forest_unref (&forest);
}
}