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

Merged
merged 26 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1f40ce5
add num_eclasses in t8_scheme_cxx
ole-alb Nov 13, 2024
bf95e23
add iterator to test eclasses of multiple schemes
ole-alb Nov 13, 2024
0760a2b
adjust example test to work with scheme iterator
ole-alb Nov 13, 2024
033bf70
Update test/t8_schemes/t8_gtest_iterator.cxx
ole-alb Nov 14, 2024
edbcfe3
add namespace for schemes in the macros
ole-alb Nov 14, 2024
365def0
Merge branch 'multiple-schemes-tests' of github.com:DLR-AMR/t8code in…
ole-alb Nov 14, 2024
1edafd7
crtp update
ole-alb Nov 27, 2024
94c8e99
update iterator for crtp scheme update
ole-alb Nov 27, 2024
e0f5717
Merge remote-tracking branch 'origin/feature-template_multilevel' int…
ole-alb Dec 10, 2024
f81b05a
Merge remote-tracking branch 'origin/feature-template_multilevel' int…
Davknapp Dec 10, 2024
5dc2d6f
Use a scheme-collection with all schemes
Davknapp Dec 13, 2024
440f3a7
remove iterator
Davknapp Dec 13, 2024
8c5f125
Merge remote-tracking branch 'origin/main' into multiple-schemes-tests
Davknapp Dec 13, 2024
a25e694
Merge branch 'main' into multiple-schemes-tests
Davknapp Dec 13, 2024
82c6c91
Add test/t8_gtest_schemes.hxx
Davknapp Dec 13, 2024
eaca0b3
Indentation
Davknapp Dec 13, 2024
59a7562
Indentation
Davknapp Dec 13, 2024
24f1573
Merge branch 'main' into multiple-schemes-tests
Davknapp Jan 6, 2025
e4e5ff3
Distinguish between eclass and scheme_id
Davknapp Jan 6, 2025
086f8fd
Resolve eclass and scheme_id issues
ole-alb Jan 13, 2025
7d59204
add changes to scheme_id
ole-alb Jan 13, 2025
b0e98a7
Merge remote-tracking branch 'origin/main' into multiple-schemes-tests
Davknapp Jan 13, 2025
6ae5d97
Simplify multiple scheme testing
Davknapp Jan 13, 2025
261c08a
Merge remote-tracking branch 'origin/multiple-schemes-tests' into mul…
Davknapp Jan 13, 2025
48e0576
Indentation
Davknapp Jan 13, 2025
c50f6bd
Merge branch 'main' into multiple-schemes-tests
lukasdreyer Jan 16, 2025
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
3 changes: 3 additions & 0 deletions src/t8_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ struct t8_scheme_cxx

/** This array holds one virtual table per element class. */
t8_eclass_scheme_c *eclass_schemes[T8_ECLASS_COUNT];

/** Number of eclasses implemented in the scheme*/
int num_eclasses;
};

/** This array holds the reference coordinates of each vertex of each element.
Expand Down
1 change: 1 addition & 0 deletions src/t8_schemes/t8_default/t8_default.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ t8_scheme_new_default_cxx (void)
T8_ASSERT (s->eclass_schemes[T8_ECLASS_QUAD]->t8_element_maxlevel ()
>= s->eclass_schemes[T8_ECLASS_PYRAMID]->t8_element_maxlevel ());

s->num_eclasses = T8_ECLASS_COUNT;
return s;
}

Expand Down
12 changes: 12 additions & 0 deletions test/t8_gtest_macros.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@

#include <gtest/gtest.h>
#include <t8_eclass.h>
#include <t8_schemes/t8_default/t8_default.hxx>
#include <test/t8_schemes/t8_gtest_iterator.cxx>
#include <iostream>

extern t8_scheme_cxx *
t8_scheme_new_default_cxx ();

/**
* lambda to pass to an INSTANTIATE_TEST_SUITE_P to print the current cmesh_example_base
Expand All @@ -46,6 +52,12 @@ auto print_eclass = [] (const testing::TestParamInfo<t8_eclass> &info) { return
#define T8_NUM_SAMPLE_POINTS 10000
#endif

const t8_scheme_cxx *default_scheme = t8_scheme_new_default_cxx ();
Davknapp marked this conversation as resolved.
Show resolved Hide resolved
const t8_scheme_cxx *sa_scheme = t8_scheme_new_default_cxx ();
const std::vector<const t8_scheme_cxx *> schemes = { default_scheme, sa_scheme };
scheme_iterators scheme_iter (schemes);

#define AllSchemesEclasses testing::ValuesIn (scheme_iter.begin (), scheme_iter.end ())
#define AllEclasses testing::Range (T8_ECLASS_ZERO, T8_ECLASS_COUNT)
#define AllEclasses2D testing::Values (T8_ECLASS_QUAD, T8_ECLASS_TRIANGLE)

Expand Down
103 changes: 103 additions & 0 deletions test/t8_schemes/t8_gtest_iterator.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include <gtest/gtest.h>
#include <t8_eclass.h>
#include <t8_schemes/t8_default/t8_default.hxx>
#include <vector>

/**
* \class scheme_iterators
* Class to iterate over all eclasses of all schemes an return the t8_eclass_scheme_c*.
*/
class scheme_iterators {
public:
/**
* Initialize the iterator with a list of schemes.
* \param [in] schemes The list of schemes to iterate over.
*/
scheme_iterators (const std::vector<const t8_scheme_cxx*>& schemes): schemes (schemes)
{
}

/**
* \struct Iterator
* Iterator to iterate over all eclasses of all schemes.
*/
struct Iterator
{
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = t8_eclass_scheme_c*;
using pointer = t8_eclass_scheme_c**;
using reference = t8_eclass_scheme_c*&;

/**
* Constructor for the iterator.
* \param [in] schemes The list of schemes to iterate over.
* \param [in] is_end Flag to indicate if the iterator is at the end.
*/
Iterator (const std::vector<const t8_scheme_cxx*>& schemes, bool is_end = false)
ole-alb marked this conversation as resolved.
Show resolved Hide resolved
: schemes (schemes), scheme_index (is_end ? schemes.size () : 0), eclass_index (0)
{
if (!is_end && !schemes.empty ()) {
eclass_count = schemes[scheme_index]->num_eclasses;
}
}

/**
* Dereference operator.
* \return The current eclass scheme or tree scheme ts.
*/
t8_eclass_scheme_c*
operator* () const
{
const t8_scheme_cxx* current_scheme = schemes[scheme_index];
return current_scheme->eclass_schemes[eclass_index];
}

/**
* Prefix increment operator to move the iterator to the next element.
* \return A reference to the updated iterator.
*/
Iterator&
operator++ ()
{
if (++eclass_index >= eclass_count) {
eclass_index = 0;
if (++scheme_index < schemes.size ()) {
eclass_count = schemes[scheme_index]->num_eclasses;
}
}
return *this;
}

/**
* Inequality operator to compare two iterators.
* \param [in] other Another iterator to compare with.
* \return True if the iterators are not equal, false otherwise.
*/
bool
operator!= (const Iterator& other) const
{
return scheme_index != other.scheme_index || eclass_index != other.eclass_index;
}

private:
const std::vector<const t8_scheme_cxx*>& schemes;
size_t scheme_index;
size_t eclass_index;
size_t eclass_count;
};

Iterator
begin () const
{
return Iterator (schemes);
}
Iterator
end () const
{
return Iterator (schemes, true);
}

private:
const std::vector<const t8_scheme_cxx*>& schemes;
};
11 changes: 3 additions & 8 deletions test/t8_schemes/t8_gtest_root.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,22 @@
#include <t8_eclass.h>
#include <t8_schemes/t8_default/t8_default.hxx>

class root: public testing::TestWithParam<t8_eclass> {
class root: public testing::TestWithParam<t8_eclass_scheme_c *> {
protected:
void
SetUp () override
{
eclass = GetParam ();
scheme = t8_scheme_new_default_cxx ();
ts = scheme->eclass_schemes[eclass];
ts = GetParam ();
ts->t8_element_new (1, &element);
ts->t8_element_root (element);
}
void
TearDown () override
{
ts->t8_element_destroy (1, &element);
t8_scheme_cxx_unref (&scheme);
}
t8_element_t *element;
t8_scheme_cxx *scheme;
t8_eclass_scheme_c *ts;
t8_eclass_t eclass;
};

/*Test root*/
Expand All @@ -68,4 +63,4 @@ TEST_P (root, equals_linear_id_0_0)
ts->t8_element_destroy (1, &root_compare);
}

INSTANTIATE_TEST_SUITE_P (t8_gtest_root, root, AllEclasses, print_eclass);
INSTANTIATE_TEST_SUITE_P (t8_gtest_root, root, AllSchemesEclasses);
Loading