Skip to content

Commit

Permalink
Merge pull request #871 from DLR-AMR/enhance-cmesh-testing
Browse files Browse the repository at this point in the history
Enhance cmesh testing
  • Loading branch information
jmark committed Feb 13, 2024
2 parents 3dc449a + 9864ad9 commit b6d76b8
Show file tree
Hide file tree
Showing 10 changed files with 666 additions and 19 deletions.
23 changes: 12 additions & 11 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ t8code_googletest_programs = \
test/t8_gtest_basics \
test/t8_schemes/t8_gtest_ancestor \
test/t8_cmesh/t8_gtest_hypercube \
test/t8_cmesh/t8_gtest_cmesh_copy \
test/t8_schemes/t8_gtest_element_count_leaves \
test/t8_schemes/t8_gtest_element_ref_coords \
test/t8_geometry/t8_gtest_geometry \
Expand Down Expand Up @@ -68,7 +67,8 @@ t8code_googletest_programs = \
test/t8_forest_incomplete/t8_gtest_empty_global_tree \
test/t8_cmesh/t8_gtest_cmesh_tree_vertices_negative_volume \
test/t8_schemes/t8_gtest_default \
test/t8_schemes/t8_gtest_child_parent_face
test/t8_schemes/t8_gtest_child_parent_face \
test/t8_cmesh_generator/t8_gtest_cmesh_generator_test

test_t8_IO_t8_gtest_vtk_reader_SOURCES = \
test/t8_gtest_main.cxx \
Expand Down Expand Up @@ -174,10 +174,6 @@ test_t8_cmesh_t8_gtest_cmesh_partition_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_cmesh/t8_gtest_cmesh_partition.cxx

test_t8_cmesh_t8_gtest_cmesh_copy_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_cmesh/t8_gtest_cmesh_copy.cxx

test_t8_cmesh_t8_gtest_cmesh_set_partition_offsets_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_cmesh/t8_gtest_cmesh_set_partition_offsets.cxx
Expand Down Expand Up @@ -294,6 +290,10 @@ test_t8_schemes_t8_gtest_child_parent_face_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_schemes/t8_gtest_child_parent_face.cxx

test_t8_cmesh_generator_t8_gtest_cmesh_generator_test_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_cmesh_generator/t8_gtest_cmesh_generator_test.cxx

#define ld and cpp flags for all targets
t8_gtest_target_ld_add = $(LDADD) test/libgtest.la
t8_gtest_target_ld_flags = $(AM_LDFLAGS) -pthread
Expand Down Expand Up @@ -402,10 +402,6 @@ test_t8_cmesh_t8_gtest_cmesh_partition_LDADD = $(t8_gtest_target_ld_add)
test_t8_cmesh_t8_gtest_cmesh_partition_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_cmesh_t8_gtest_cmesh_partition_CPPFLAGS = $(t8_gtest_target_cpp_flags)

test_t8_cmesh_t8_gtest_cmesh_copy_LDADD = $(t8_gtest_target_ld_add)
test_t8_cmesh_t8_gtest_cmesh_copy_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_cmesh_t8_gtest_cmesh_copy_CPPFLAGS = $(t8_gtest_target_cpp_flags)

test_t8_cmesh_t8_gtest_cmesh_set_partition_offsets_LDADD = $(t8_gtest_target_ld_add)
test_t8_cmesh_t8_gtest_cmesh_set_partition_offsets_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_cmesh_t8_gtest_cmesh_set_partition_offsets_CPPFLAGS = $(t8_gtest_target_cpp_flags)
Expand Down Expand Up @@ -526,6 +522,10 @@ test_t8_schemes_t8_gtest_child_parent_face_LDADD = $(t8_gtest_target_ld_add)
test_t8_schemes_t8_gtest_child_parent_face_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_schemes_t8_gtest_child_parent_face_CPPFLAGS = $(t8_gtest_target_cpp_flags)

test_t8_cmesh_generator_t8_gtest_cmesh_generator_test_LDADD = $(t8_gtest_target_ld_add)
test_t8_cmesh_generator_t8_gtest_cmesh_generator_test_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_cmesh_generator_t8_gtest_cmesh_generator_test_CPPFLAGS = $(t8_gtest_target_cpp_flags)

# If we did not configure t8code with MPI we need to build Googletest
# without MPI support.
if !T8_ENABLE_MPI
Expand Down Expand Up @@ -554,7 +554,6 @@ test_t8_schemes_t8_gtest_find_parent_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags
test_t8_schemes_t8_gtest_equal_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_cmesh_t8_gtest_cmesh_face_is_boundary_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_cmesh_t8_gtest_cmesh_partition_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_cmesh_t8_gtest_cmesh_copy_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_cmesh_t8_gtest_cmesh_set_partition_offsets_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_element_volume_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_cmesh_t8_gtest_multiple_attributes_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
Expand Down Expand Up @@ -585,6 +584,8 @@ test_t8_forest_incomplete_t8_gtest_empty_global_tree_CPPFLAGS += $(t8_gtest_targ
test_t8_cmesh_t8_gtest_cmesh_tree_vertices_negative_volume_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_schemes_t8_gtest_default_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_schemes_t8_gtest_child_parent_face_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_cmesh_generator_t8_gtest_cmesh_generator_test_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)

endif

# Build Googletest library
Expand Down
14 changes: 6 additions & 8 deletions test/t8_cmesh/t8_gtest_cmesh_copy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
#include <t8_schemes/t8_default/t8_default_cxx.hxx>
#include "t8_cmesh/t8_cmesh_trees.h"
#include "t8_cmesh/t8_cmesh_partition.h"
#include <t8_cmesh/t8_cmesh_testcases.h>
#include <test/t8_gtest_macros.hxx>

#include "test/t8_cmesh_generator/t8_cmesh_example_sets.hxx"

/* We create and commit a cmesh, then derive a new cmesh
* from it without any changes.
* We test whether the new and original cmesh are equal.
Expand All @@ -37,17 +38,15 @@
* See: https://github.com/DLR-AMR/t8code/issues/920
*/

class t8_cmesh_copy: public testing::TestWithParam<int> {
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 */
GTEST_SKIP ();
cmesh_id = GetParam ();
cmesh_original = GetParam ()->cmesh_create ();

/* Create cmesh from cmesh_id */
cmesh_original = t8_test_create_cmesh (cmesh_id);
/* Initialized test cmesh that we derive in the test */
t8_cmesh_init (&cmesh);
}
Expand All @@ -61,7 +60,6 @@ class t8_cmesh_copy: public testing::TestWithParam<int> {
t8_cmesh_unref (&cmesh);
}

int cmesh_id;
t8_cmesh_t cmesh;
t8_cmesh_t cmesh_original;
};
Expand All @@ -83,5 +81,5 @@ TEST_P (t8_cmesh_copy, test_cmesh_copy)
EXPECT_TRUE (t8_cmesh_is_equal (cmesh, cmesh_original));
}

/* Test all cmeshes over all different inputs */
INSTANTIATE_TEST_SUITE_P (t8_gtest_cmesh_copy, t8_cmesh_copy, AllCmeshs);
/* Test all cmeshes over all different inputs*/
INSTANTIATE_TEST_SUITE_P (t8_gtest_cmesh_copy, t8_cmesh_copy, AllCmeshsParam, pretty_print_base_example);
60 changes: 60 additions & 0 deletions test/t8_cmesh_generator/t8_cmesh_example_sets.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
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) 2024 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.
*/

#ifndef T8_GTEST_CMESH_COMM_CREATOR_HXX
#define T8_GTEST_CMESH_COMM_CREATOR_HXX

#include <vector>

#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_new_prism_cake_param.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_new_from_class_param.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_new_bigmesh_param.hxx"
#include "test/t8_cmesh_generator/t8_gtest_cmesh_cartestian_product.hxx"
#include "test/t8_cmesh_generator/t8_gtest_cmesh_sum_of_sets.hxx"

T8_EXTERN_C_BEGIN ();

/**
* lambda to pass to an INSTANTIATE_TEST_SUITE_P to print the current cmesh_example_base
*
*/
auto pretty_print_base_example = [] (const testing::TestParamInfo<cmesh_example_base *> &info) {
std::string name;
info.param->param_to_string (name);
return name;
};

namespace cmesh_list
{
std::vector<example_set *> cart_prod_vec
= { new_from_class::cmesh_example, new_prism_cake::cmesh_example, new_bigmesh::cmesh_example };

cmesh_sum_of_sets cmesh_sums (cart_prod_vec);

} // namespace cmesh_list

#define AllCmeshsParam \
::testing::ValuesIn (cmesh_list::cmesh_sums.cmesh_examples.begin (), cmesh_list::cmesh_sums.cmesh_examples.end ())

T8_EXTERN_C_END ();

#endif /* T8_GTEST_CMESH_COMM_CREATOR_HXX */
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
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) 2024 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.
*/

#ifndef T8_CMESH_NEW_BIGMESH_PARAM_HXX
#define T8_CMESH_NEW_BIGMESH_PARAM_HXX

#include "test/t8_cmesh_generator/t8_gtest_cmesh_cartestian_product.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_params.hxx"
#include "t8_cmesh/t8_cmesh_examples.h"
#include <t8_eclass.h>

namespace new_bigmesh
{
std::function<t8_cmesh_t (t8_eclass_t, int, sc_MPI_Comm)> bigmesh = t8_cmesh_new_bigmesh;

std::string
make_param_string (const t8_eclass_t eclass, const int num_trees, const sc_MPI_Comm comm)
{
std::string delimiter = std::string ("_");
std::string params = delimiter + t8_eclass_to_string[eclass] + delimiter + std::to_string (num_trees) + delimiter
+ cmesh_params::comm_to_string (comm);
return params;
}

std::function<std::string (const t8_eclass_t, const int, const sc_MPI_Comm)> make_param_string_wrapper
= make_param_string;

example_set *cmesh_example
= (example_set *) new cmesh_cartesian_product_params<decltype (cmesh_params::eclasses.begin ()),
decltype (cmesh_params::large_mesh.begin ()),
decltype (cmesh_params::my_comms.begin ())> (
std::make_pair (cmesh_params::eclasses.begin (), cmesh_params::eclasses.end ()),
std::make_pair (cmesh_params::large_mesh.begin (), cmesh_params::large_mesh.end ()),
std::make_pair (cmesh_params::my_comms.begin (), cmesh_params::my_comms.end ()), bigmesh, make_param_string_wrapper,
"t8_cmesh_new_bigmesh_");
} // namespace new_bigmesh

#endif /* T8_CMESH_NEW_BIGMESH_PARAM_HXX */
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
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) 2024 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 "test/t8_cmesh_generator/t8_gtest_cmesh_cartestian_product.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_params.hxx"
#include <t8_cmesh/t8_cmesh_examples.h>
#include <t8_eclass.h>

#ifndef T8_CMESH_NEW_FROM_CLASS_PARAM
#define T8_CMESH_NEW_FROM_CLASS_PARAM

namespace new_from_class
{

std::string
make_param_string (const t8_eclass_t &eclass, const sc_MPI_Comm &comm)
{
std::string delimiter = std::string ("_");
std::string params
= delimiter + std::string (t8_eclass_to_string[eclass]) + delimiter + cmesh_params::comm_to_string (comm);
return params;
}

std::function<std::string (const t8_eclass_t &, const sc_MPI_Comm &)> print_function = make_param_string;

std::function<t8_cmesh_t (t8_eclass_t, sc_MPI_Comm)> new_from_class_wrapper = t8_cmesh_new_from_class;

example_set *cmesh_example
= (example_set *) new cmesh_cartesian_product_params<decltype (cmesh_params::eclasses.begin ()),
decltype (cmesh_params::my_comms.begin ())> (
std::make_pair (cmesh_params::eclasses.begin (), cmesh_params::eclasses.end ()),
std::make_pair (cmesh_params::my_comms.begin (), cmesh_params::my_comms.end ()), new_from_class_wrapper,
print_function, "t8_cmesh_new_from_class_");

} // namespace new_from_class

#endif /* T8_CMESH_NEW_FROM_CLASS_PARAM */
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
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) 2024 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 "test/t8_cmesh_generator/t8_gtest_cmesh_cartestian_product.hxx"
#include "test/t8_cmesh_generator/t8_cmesh_parametrized_examples/t8_cmesh_params.hxx"
#include <t8_cmesh/t8_cmesh_examples.h>

#ifndef T8_CMESH_NEW_PRISM_CAKE_PARAM_HXX
#define T8_CMESH_NEW_PRISM_CAKE_PARAM_HXX

namespace new_prism_cake
{
std::function<t8_cmesh_t (sc_MPI_Comm, int)> prism_cake = t8_cmesh_new_prism_cake;

std::string
make_param_string (const sc_MPI_Comm &comm, const int &num_prisms)
{
std::string delimiter = std::string ("_");
std::string params = delimiter + cmesh_params::comm_to_string (comm) + delimiter + std::to_string (num_prisms);
return params;
}

std::function<std::string (const sc_MPI_Comm &, const int &)> make_param_string_wrapper = make_param_string;

example_set *cmesh_example
= (example_set *) new cmesh_cartesian_product_params<decltype (cmesh_params::my_comms.begin ()),
decltype (cmesh_params::num_prisms.begin ())> (
std::make_pair (cmesh_params::my_comms.begin (), cmesh_params::my_comms.end ()),
std::make_pair (cmesh_params::num_prisms.begin (), cmesh_params::num_prisms.end ()), prism_cake,
make_param_string_wrapper, "t8_cmesh_new_prism_cake_");
} // namespace new_prism_cake

#endif /* T8_CMESH_NEW_PRISM_CAKE_PARAM_HXX */
Loading

0 comments on commit b6d76b8

Please sign in to comment.