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

Enhance cmesh testing #871

Merged
merged 36 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
26520c8
Add a generator for cmeshes depending on an num_trees-type parameter
Davknapp Nov 23, 2023
e4834aa
indentation
Davknapp Nov 23, 2023
db0899d
WIP: Started another generator
Davknapp Nov 23, 2023
90dbbd3
WIP iterate over two different generators
Davknapp Nov 24, 2023
8f3b239
WIP: use only one class for the cmesh_generators
Davknapp Nov 28, 2023
48baaea
WIP Update initializer
Davknapp Nov 28, 2023
bb06e40
First working version
Davknapp Nov 29, 2023
6484c79
Add Comment
Davknapp Nov 29, 2023
ec4ce9b
Update comment
Davknapp Nov 29, 2023
d99a17e
Iterate until last cmesh
Davknapp Nov 29, 2023
7d6e57b
Merge remote-tracking branch 'origin/main' into enhance-cmesh-testing
Davknapp Jan 17, 2024
199e4f4
Fix typo
Davknapp Jan 17, 2024
21858dd
templated cmesh_test
Davknapp Feb 2, 2024
a3c0fec
Added copy and creator function, added examples
Davknapp Feb 5, 2024
660e4b5
Print example-name
Davknapp Feb 5, 2024
732c65b
Update filenames, remove namespace from test
Davknapp Feb 5, 2024
b070470
Merge remote-tracking branch 'origin/main' into enhance-cmesh-testing
Davknapp Feb 5, 2024
9799e88
Remove hypercube_pad example_set, because geometries are complicated
Davknapp Feb 5, 2024
db336a0
Merge remote-tracking branch 'origin/main' into enhance-cmesh-testing
Davknapp Feb 5, 2024
bef252c
More comments
Davknapp Feb 5, 2024
d51b0e7
Give parametrized examples more structure
Davknapp Feb 6, 2024
0e83002
Iterator implementation
Davknapp Feb 7, 2024
c1482dd
Iterator working
Davknapp Feb 7, 2024
b67bbc9
STL FTW
Davknapp Feb 7, 2024
844f914
updated names of the classes
Davknapp Feb 7, 2024
d3258a4
Merge remote-tracking branch 'origin/main' into enhance-cmesh-testing
Davknapp Feb 7, 2024
807ed99
pretty output
Davknapp Feb 7, 2024
46ee186
fix bug in Communicator print
Davknapp Feb 7, 2024
f96ab2c
Added test for the cmesh-testcase generator
Davknapp Feb 7, 2024
2ef492e
Clean-up
Davknapp Feb 8, 2024
35d12df
Test the parameter-generator and some minor improvements
Davknapp Feb 8, 2024
699c633
Add file
Davknapp Feb 8, 2024
d4ae510
Merge remote-tracking branch 'origin/main' into enhance-cmesh-testing
Davknapp Feb 9, 2024
45a7fbb
base_example -> cmesh_example_base
Davknapp Feb 9, 2024
f48f3f0
Rename classes
Davknapp Feb 9, 2024
9864ad9
Use new feature in the copy-test
Davknapp Feb 9, 2024
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
21 changes: 13 additions & 8 deletions test/t8_cmesh/t8_gtest_cmesh_copy.cxx
jmark marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
#include "t8_cmesh/t8_cmesh_trees.h"
#include "t8_cmesh/t8_cmesh_partition.h"
#include <t8_eclass.h>
#include <t8_cmesh/t8_cmesh_testcases.h>
#include <test/t8_gtest_macros.hxx>
#include "test/t8_cmesh_generator/t8_gtest_cmesh_generator.hxx"

/* Test if a cmesh is committed properly and perform the face consistency check. */

class cmesh_copy_equality: public testing::TestWithParam<int> {
class cmesh_copy_equality: public testing::TestWithParam<cmesh_generator> {
protected:
void
SetUp () override
{
cmesh_id = GetParam ();

cmesh_original = t8_test_create_cmesh (cmesh_id);
cmesh_gen = GetParam ();
cmesh_gen.create_cmesh ();
jmark marked this conversation as resolved.
Show resolved Hide resolved
cmesh_original = cmesh_gen.get_cmesh ();
/* Set up the cmesh copy */
t8_cmesh_init (&cmesh_copy);
/* We need the original cmesh later, so we ref it */
Expand All @@ -50,17 +50,17 @@ class cmesh_copy_equality: public testing::TestWithParam<int> {
{
t8_cmesh_unref (&cmesh_original);
t8_cmesh_unref (&cmesh_copy);
cmesh_gen.unref_cmesh ();
}

t8_cmesh_t cmesh_original;
t8_cmesh_t cmesh_copy;
int cmesh_id;
cmesh_generator cmesh_gen;
};

/* Test wheater the original cmaeh and its copy are committed and face consistent. Test will fail, if one of these is false. */
TEST_P (cmesh_copy_equality, check_cmeshes_and_their_trees)
{

EXPECT_TRUE (t8_cmesh_is_committed (cmesh_original));
EXPECT_TRUE (t8_cmesh_is_committed (cmesh_copy));
EXPECT_TRUE (t8_cmesh_trees_is_face_consistent (cmesh_original, cmesh_original->trees));
Expand All @@ -74,5 +74,10 @@ TEST_P (cmesh_copy_equality, check_equality_of_copied_cmesh_with_original)
EXPECT_TRUE (t8_cmesh_is_equal (cmesh_original, cmesh_copy));
}

/* TODO: I am not happy about this. Can we use something else than a global variable? */
jmark marked this conversation as resolved.
Show resolved Hide resolved
cmesh_generator first (0);
cmesh_generator last ((first.get_last ()));
cmesh_generator step (0);

/* Test all cmeshes over all different inputs we get through their id */
INSTANTIATE_TEST_SUITE_P (t8_gtest_cmesh_copy, cmesh_copy_equality, AllCmeshs);
INSTANTIATE_TEST_SUITE_P (t8_gtest_cmesh_copy, cmesh_copy_equality, ::testing::Range (::first, ::last, ::step));
jmark marked this conversation as resolved.
Show resolved Hide resolved
107 changes: 107 additions & 0 deletions test/t8_cmesh_generator/t8_gtest_cmesh_comm_creator.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
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) 2023 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 <t8_cmesh/t8_cmesh_examples.h>
#include "test/t8_cmesh_generator/t8_gtest_cmesh_creator_base.hxx"

T8_EXTERN_C_BEGIN ();
/* A function creating a cmesh getting a communicator */
typedef t8_cmesh_t (*t8_cmesh_w_comm) (sc_MPI_Comm comm);

/* List of all functions that have a num_elems-parameter*/
const std::vector<t8_cmesh_w_comm> cmeshes_with_comm = { t8_cmesh_new_periodic_tri,
t8_cmesh_new_periodic_hybrid,
t8_cmesh_new_periodic_line_more_trees,
t8_cmesh_new_line_zigzag,
t8_cmesh_new_prism_deformed,
t8_cmesh_new_pyramid_deformed,
t8_cmesh_new_prism_cake_funny_oriented,
t8_cmesh_new_prism_geometry,
t8_cmesh_new_tet_orientation_test,
t8_cmesh_new_hybrid_gate,
t8_cmesh_new_hybrid_gate_deformed,
t8_cmesh_new_full_hybrid };

/**
* A class to generate all cmeshes using only a communicator
*
*/
class all_cmeshes_with_comm: public cmesh_creator {
public:
/* overloading the < operator for gtest-ranges */
bool
operator< (const cmesh_creator &other)
{
return current_creator < other.current_creator;
}

/* The next cmesh is the cmesh with on more element until max_num_trees is reached,
* then we go to the next constructor. */
void
addition (const std::shared_ptr<cmesh_creator> step)
{
current_creator += 1;
T8_ASSERT ((unsigned long int) current_creator < cmeshes_with_comm.size ());
}

/* To save memory, the cmesh is not created by default */
void
create_cmesh ()
{
cmesh = cmeshes_with_comm[current_creator](comm);
}

void
set_first ()
{
current_creator = 0;
}

void
set_last ()
{
current_creator = cmeshes_with_comm.size () - 1;
}

bool
is_at_last ()
{
return (long unsigned int) current_creator == cmeshes_with_comm.size () - 1;
}

/* Destructor */
~all_cmeshes_with_comm ()
{
/* unref the cmesh only if it has been created */
if (cmesh != NULL) {
t8_cmesh_unref (&cmesh);
}
}
};

T8_EXTERN_C_END ();

#endif /* T8_GTEST_CMESH_COMM_CREATOR_HXX */
161 changes: 161 additions & 0 deletions test/t8_cmesh_generator/t8_gtest_cmesh_creator_base.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
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) 2023 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_CREATOR_BASE_HXX
#define T8_GTEST_CMESH_CREATOR_BASE_HXX

#include <t8_cmesh.h>

/**
* A base class for cmesh_creators.
*
*/
class cmesh_creator {
public:
/**
* Construct a new cmesh generator object
* Is set to the first creator, using sc_MPI_COMM_WORLD
*/
cmesh_creator (): current_creator (0), comm (sc_MPI_COMM_WORLD), cmesh (NULL) {};

/**
* Construct a new cmesh generator object, with a creator and comm specified
*
* \param[in] creator The creator to use
* \param[in] comm The communicator to use
*/
cmesh_creator (int creator, sc_MPI_Comm comm): current_creator (creator), comm (comm), cmesh (NULL) {};

/**
* Copy-constructor of a new cmesh generator object
*
* \param other[in] The cmesh_creator to copy
*/
cmesh_creator (const cmesh_creator &other)
: current_creator (other.current_creator), num_trees (other.num_trees), comm (other.comm)
{
if (cmesh != NULL) {
t8_cmesh_ref (other.cmesh);
cmesh = other.cmesh;
}
else {
cmesh = NULL;
}
};

/**
* Compare two cmesh_creator
*
* \param[in] other the cmesh_creator to compare with
* \return true if both cmesh_creators are equal
* \return false if the cmesh_creators differ
*/
virtual bool
operator< (const cmesh_creator &other)
= 0;

/**
* Function to increase to cmesh_creator to the next creator function
*
* \param step A cmesh_creator describing by how much to increase
*/
virtual void
addition (const std::shared_ptr<cmesh_creator> step)
= 0;

/**
* Create the cmesh. Initially no cmesh is created. Calling this function will create the cmesh
*/
virtual void
create_cmesh ()
= 0;

/**
* Set the creator to the first creator function (the function that creates a cmesh) with
* the first set of parameters.
*/
virtual void
set_first ()
= 0;

/**
* Set the creator to the last creator function (the function that creates a cmesh) with
* the last set of parameters.
*/
virtual void
set_last ()
= 0;

/**
* Check if the current set of parameters is the last set of parameters to use.
*
* \return true if the current setup is the last
* \return false ow
*/
virtual bool
is_at_last ()
= 0;

/**
* Get the cmesh object, if it has been created
*
* \return the cmesh, if it has been created, NULL if not.
*/
t8_cmesh_t
get_cmesh ()
{
if (cmesh != NULL) {
t8_cmesh_ref (cmesh);
return cmesh;
}
return NULL;
}

/**
* Dereference the current cmesh. Will be deleted if the last reference is unset.
*
*/
void
unref_cmesh ()
{
if (cmesh != NULL) {
t8_cmesh_unref (&cmesh);
}
}

/**
* Destroy the cmesh generator object
*
*/
virtual ~cmesh_creator () {};

/* Defines the current creator function */
int current_creator = 0;
/* If needed, the number of trees to create by the creator function*/
int num_trees = 1;
/* The communicator to use. */
sc_MPI_Comm comm = sc_MPI_COMM_WORLD;
/* The cmesh. */
t8_cmesh_t cmesh = NULL;
};

#endif /* T8_GTEST_CMESH_CREATOR_BASE_HXX */
Loading
Loading