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

Multiple schemes tests #1300

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/t8_schemes/t8_scheme.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class t8_scheme {
return std::holds_alternative<TEclassScheme> (eclass_schemes[tree_class]);
}

/** Get the eclass an eclas scheme is valid for. \Note: This function should return the input value as long as the
/** Get the eclass an eclass scheme is valid for. \Note: This function should return the input value as long as the
* eclass schemes are soreted correctly. In the future, the trees will access the schemes by a key and then this
* function will make more sense.
* \param [in] tree_class The eclass of the current tree.
Expand Down
2 changes: 1 addition & 1 deletion test/t8_forest/t8_gtest_element_is_leaf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ t8_test_element_is_leaf_for_forest (t8_forest_t forest)
{
const t8_locidx_t num_local_trees = t8_forest_get_num_local_trees (forest);

const t8_scheme *scheme = t8_forest_get_scheme (forest);
for (t8_locidx_t itree = 0; itree < num_local_trees; ++itree) {
const t8_locidx_t num_elements_in_tree = t8_forest_get_tree_num_elements (forest, itree);
const t8_eclass_t tree_class = t8_forest_get_tree_class (forest, itree);
const t8_scheme *scheme = t8_forest_get_scheme (forest);
/* Allocate memory to build a non-leaf element. */
t8_element_t *not_leaf;
scheme->element_new (tree_class, 1, &not_leaf);
Expand Down
25 changes: 17 additions & 8 deletions test/t8_forest_incomplete/t8_gtest_recursive.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <t8.h>
#include <t8_cmesh/t8_cmesh_examples.h>
#include <t8_forest/t8_forest.h>
#include <t8_schemes/t8_default/t8_default.hxx>
#include <test/t8_gtest_schemes.hxx>
#include <test/t8_gtest_macros.hxx>

/* In this test, we recursively constructs a mesh containing only the first
Expand All @@ -37,17 +37,21 @@
* Note, that each rank has its own local/global tree. No trees are shared.
*/

class recursive_tree: public testing::TestWithParam<t8_eclass_t> {
class recursive_tree: public testing::TestWithParam<int> {
protected:
void
SetUp () override
{
tree_class = GetParam ();
scheme_id = GetParam ();
scheme = t8_scheme_all_schemes ();
tree_class = scheme->get_eclass_scheme_eclass (static_cast<t8_eclass_t>(scheme_id));
if (tree_class == T8_ECLASS_ZERO) {
GTEST_SKIP ();
}
sc_MPI_Comm_size (sc_MPI_COMM_WORLD, &MPI_size);

/* Construct a cmesh such that each process will get one rooted tree */
cmesh = t8_cmesh_new_bigmesh (tree_class, MPI_size, sc_MPI_COMM_WORLD);
scheme = t8_scheme_new_default ();

scheme->ref ();
t8_cmesh_ref (cmesh);
Expand All @@ -60,10 +64,16 @@ class recursive_tree: public testing::TestWithParam<t8_eclass_t> {
void
TearDown () override
{
t8_forest_unref (&forest);
t8_forest_unref (&forest_base);
if (tree_class != T8_ECLASS_ZERO) {
t8_forest_unref (&forest);
t8_forest_unref (&forest_base);
}
else {
scheme->unref ();
}
}
int MPI_size;
int scheme_id;
t8_eclass_t tree_class;
t8_scheme *scheme;
t8_cmesh_t cmesh;
Expand Down Expand Up @@ -145,5 +155,4 @@ TEST_P (recursive_tree, test_recursive)
ASSERT_TRUE (t8_forest_is_equal (forest, forest_base));
}

INSTANTIATE_TEST_SUITE_P (t8_gtest_recursive, recursive_tree, testing::Range (T8_ECLASS_LINE, T8_ECLASS_COUNT),
print_eclass);
INSTANTIATE_TEST_SUITE_P (t8_gtest_recursive, recursive_tree, AllSchemes);
13 changes: 7 additions & 6 deletions test/t8_gtest_custom_assertion.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@
*/
testing::AssertionResult
element_equality (const char *ts_expr, const char *tree_class_expr, const char *elem_1_expr, const char *elem_2_expr,
const t8_scheme *scheme, const t8_eclass_t tree_class, const t8_element_t *elem_1,
const t8_scheme *scheme, const int scheme_id, const t8_element_t *elem_1,
const t8_element_t *elem_2)
{
if (scheme->element_is_equal (tree_class, elem_1, elem_2)) {
if (scheme->element_is_equal (static_cast<t8_eclass_t>(scheme_id), elem_1, elem_2)) {
return testing::AssertionSuccess ();
}
else {
#if T8_ENABLE_DEBUG
char elem_1_string[BUFSIZ];
char elem_2_string[BUFSIZ];
scheme->element_to_string (tree_class, elem_1, elem_1_string, BUFSIZ);
scheme->element_to_string (tree_class, elem_2, elem_2_string, BUFSIZ);
const t8_eclass_t tree_class = scheme->get_eclass_scheme_eclass (static_cast<t8_eclass_t>(scheme_id));
scheme->element_to_string (static_cast<t8_eclass_t>(scheme_id), elem_1, elem_1_string, BUFSIZ);
scheme->element_to_string (static_cast<t8_eclass_t>(scheme_id), elem_2, elem_2_string, BUFSIZ);
return testing::AssertionFailure () << elem_1_expr << " " << elem_1_string << " is not equal to \n"
<< elem_2_expr << " " << elem_2_string << " given scheme " << ts_expr
<< " and tree class " << tree_class_expr << " "
Expand All @@ -70,8 +71,8 @@ element_equality (const char *ts_expr, const char *tree_class_expr, const char *
}
}

#define EXPECT_ELEM_EQ(scheme, tree_class, elem1, elem2) \
EXPECT_PRED_FORMAT4 (element_equality, (scheme), (tree_class), (elem1), (elem2))
#define EXPECT_ELEM_EQ(scheme, scheme_id, elem1, elem2) \
EXPECT_PRED_FORMAT4 (element_equality, (scheme), (scheme_id), (elem1), (elem2))

/**
* \brief Test if two 3D vectors are equal with respect to a given precision
Expand Down
3 changes: 3 additions & 0 deletions test/t8_gtest_macros.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#include <gtest/gtest.h>
#include <t8_eclass.h>
#include <t8_schemes/t8_default/t8_default.hxx>
#include <iostream>
#include <t8_schemes/t8_scheme.hxx>

/**
* lambda to pass to an INSTANTIATE_TEST_SUITE_P to print the current cmesh_example_base
Expand Down
51 changes: 51 additions & 0 deletions test/t8_gtest_schemes.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
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_SCHEMES_HXX
#define T8_GTEST_SCHEMES_HXX

#include <t8_schemes/t8_default/t8_default.hxx>
#include <t8_schemes/t8_scheme_builder.hxx>
#include <gtest/gtest.h>

t8_scheme *
t8_scheme_all_schemes (void)
{
t8_scheme_builder builder;

builder.add_eclass_scheme<t8_default_scheme_vertex> ();
builder.add_eclass_scheme<t8_default_scheme_line> ();
builder.add_eclass_scheme<t8_default_scheme_quad> ();
builder.add_eclass_scheme<t8_default_scheme_tri> ();
builder.add_eclass_scheme<t8_default_scheme_hex> ();
builder.add_eclass_scheme<t8_default_scheme_tet> ();
builder.add_eclass_scheme<t8_default_scheme_prism> ();
builder.add_eclass_scheme<t8_default_scheme_pyramid> ();

return builder.build_scheme ();
}

#define NUM_SCHEMES 8

#define AllSchemes ::testing::Range (0, NUM_SCHEMES)

#endif /* T8_GTEST_SCHEMES_HXX */
23 changes: 14 additions & 9 deletions test/t8_schemes/t8_gtest_boundary_extrude.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,25 @@ class class_test_boundary_extrude: public TestDFS {
void
check_element () override
{
const int num_faces = scheme->element_get_num_faces (tree_class, element);
const int num_faces = scheme->element_get_num_faces (static_cast<t8_eclass_t>(scheme_id), element);
for (int iface = 0; iface < num_faces; iface++) {
/* Iterate over all faces that are also root faces and determine the face element */
if (scheme->element_is_root_boundary (tree_class, element, iface)) {
if (scheme->element_is_root_boundary (static_cast<t8_eclass_t>(scheme_id), element, iface)) {
/* Get face scheme */
const int tree_face = scheme->element_get_tree_face (tree_class, element, iface);
const int tree_face = scheme->element_get_tree_face (static_cast<t8_eclass_t>(scheme_id), element, iface);

/* Note: This wont work with non-default schemes, where the order of schemes is not the same as
* in the default scheme. */
const t8_eclass_t face_eclass = (t8_eclass_t) t8_eclass_face_types[tree_class][tree_face];

t8_element_t *boundary;
scheme->element_new (face_eclass, 1, &boundary);

scheme->element_get_boundary_face (tree_class, element, iface, boundary);
scheme->element_get_boundary_face (static_cast<t8_eclass_t>(scheme_id), element, iface, boundary);

scheme->element_extrude_face (tree_class, boundary, check, tree_face);
scheme->element_extrude_face (static_cast<t8_eclass_t>(scheme_id), boundary, check, tree_face);

EXPECT_ELEM_EQ (scheme, tree_class, element, check);
EXPECT_ELEM_EQ (scheme, scheme_id, element, check);

scheme->element_destroy (face_eclass, 1, &boundary);
}
Expand All @@ -63,17 +66,19 @@ class class_test_boundary_extrude: public TestDFS {
{
dfs_test_setup ();
/* Get element and initialize it */
scheme->element_new (tree_class, 1, &check);
scheme->element_new (static_cast<t8_eclass_t>(scheme_id), 1, &check);
tree_class = scheme->get_eclass_scheme_eclass (static_cast<t8_eclass_t>(scheme_id));
}
void
TearDown () override
{
/* Destroy element */
scheme->element_destroy (tree_class, 1, &check);
scheme->element_destroy (static_cast<t8_eclass_t>(scheme_id), 1, &check);

/* Destroy DFS test */
dfs_test_teardown ();
}
t8_eclass_t tree_class;
t8_element_t *check;
};

Expand All @@ -87,4 +92,4 @@ TEST_P (class_test_boundary_extrude, test_boundary_extrude_dfs)
check_recursive_dfs_to_max_lvl (maxlvl);
}

INSTANTIATE_TEST_SUITE_P (t8_gtest_test_all_imps, class_test_boundary_extrude, AllEclasses, print_eclass);
INSTANTIATE_TEST_SUITE_P (t8_gtest_test_all_imps, class_test_boundary_extrude, AllSchemes);
16 changes: 8 additions & 8 deletions test/t8_schemes/t8_gtest_child_parent_face.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ class class_child_parent_face: public TestDFS {
void
check_element () override
{
const int num_faces = scheme->element_get_num_faces (tree_class, element);
const int num_faces = scheme->element_get_num_faces (static_cast<t8_eclass_t>(scheme_id), element);
for (int iface = 0; iface < num_faces; iface++) {
/* Iterate over all faces and determine the facechildren*/
const int num_face_children = scheme->element_get_num_face_children (tree_class, element, iface);
const int num_face_children = scheme->element_get_num_face_children (static_cast<t8_eclass_t>(scheme_id), element, iface);
t8_element_t **children;
children = T8_ALLOC (t8_element_t *, num_face_children);
scheme->element_new (tree_class, num_face_children, children);
scheme->element_new (static_cast<t8_eclass_t>(scheme_id), num_face_children, children);

scheme->element_get_children_at_face (tree_class, element, iface, children, num_face_children, NULL);
scheme->element_get_children_at_face (static_cast<t8_eclass_t>(scheme_id), element, iface, children, num_face_children, NULL);

for (int ifacechild = 0; ifacechild < num_face_children; ifacechild++) {
/* Iterate over those children and determine the childface corresponding to the parentface */
const int childface = scheme->element_face_get_child_face (tree_class, element, iface, ifacechild);
const int childface = scheme->element_face_get_child_face (static_cast<t8_eclass_t>(scheme_id), element, iface, ifacechild);
ASSERT_NE (childface, -1);
/* Determine the parentface corresponding to the childface */
const int parentface = scheme->element_face_get_parent_face (tree_class, children[ifacechild], childface);
const int parentface = scheme->element_face_get_parent_face (static_cast<t8_eclass_t>(scheme_id), children[ifacechild], childface);
/* Check, that this is equal to the face that we started with */
EXPECT_EQ (iface, parentface);
}
scheme->element_destroy (tree_class, num_face_children, children);
scheme->element_destroy (static_cast<t8_eclass_t>(scheme_id), num_face_children, children);
T8_FREE (children);
}
}
Expand Down Expand Up @@ -80,4 +80,4 @@ TEST_P (class_child_parent_face, t8_recursive_dfs_child_parent_face)
check_recursive_dfs_to_max_lvl (maxlvl);
}

INSTANTIATE_TEST_SUITE_P (t8_gtest_child_parent_face, class_child_parent_face, AllEclasses, print_eclass);
INSTANTIATE_TEST_SUITE_P (t8_gtest_child_parent_face, class_child_parent_face, AllSchemes);
Loading
Loading