3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_BASISTEST_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_BASISTEST_HH
9#include <dune/common/test/testsuite.hh>
12#include <dune/functions/functionspacebases/concepts.hh>
17template<
class MultiIndex>
18bool multiIndicesConsecutive(
const MultiIndex& a,
const MultiIndex& b)
23 for (; (i<a.size()) and (i<b.size()) and (a[i] == b[i]); ++i)
27 if ((i<a.size()) and (i==b.size()))
31 if ((i<a.size()) and (i<b.size()))
41 for (; i<b.size(); ++i)
52template<
class MultiIndexSet>
53Dune::TestSuite checkBasisIndexTreeConsistency(
const MultiIndexSet& multiIndexSet)
55 Dune::TestSuite test(
"index tree consistency check");
59 auto it = multiIndexSet.begin();
60 auto end = multiIndexSet.end();
63 auto lastMultiIndex = *it;
66 test.require(lastMultiIndex.size()>0,
"multi-index size check")
67 <<
"empty multi-index found";
70 for (
decltype(lastMultiIndex.size()) i = 0; i<lastMultiIndex.size(); ++i)
72 test.require(lastMultiIndex[i] == 0,
"smallest index check")
73 <<
"smallest index contains non-zero entry " << lastMultiIndex[i] <<
" in position " << i;
77 for(; it != end; ++it)
79 auto multiIndex = *it;
82 test.require(multiIndex.size()>0,
"multi-index size check")
83 <<
"empty multi-index found";
86 test.check(multiIndicesConsecutive(lastMultiIndex, multiIndex),
"consecutive index check")
87 <<
"multi-indices " << lastMultiIndex <<
" and " << multiIndex <<
" are subsequent but not consecutive";
89 lastMultiIndex = multiIndex;
97template<
class Basis,
class MultiIndexSet>
98Dune::TestSuite checkBasisSizeConsistency(
const Basis& basis,
const MultiIndexSet& multiIndexSet)
100 Dune::TestSuite test(
"index size consistency check");
102 auto prefix =
typename Basis::SizePrefix{};
104 for(
const auto& index : multiIndexSet)
107 for (
const auto& i: index)
113 auto prefixSize = basis.size(prefix);
114 test.require(prefixSize > i,
"basis.size(prefix) subtree check")
115 <<
"basis.size(" << prefix <<
")=" << prefixSize <<
" but index " << index <<
" exists";
120 auto prefixSize = basis.size(prefix);
121 test.require(prefixSize == 0,
"basis.size(prefix) leaf check")
122 <<
"basis.size(" << prefix <<
")=" << prefixSize <<
" but the prefix exists as index";
134Dune::TestSuite checkBasisIndices(
const Basis& basis)
136 Dune::TestSuite test(
"basis index check");
138 using MultiIndex =
typename Basis::MultiIndex;
139 auto compare = [](
const auto& a,
const auto& b) {
140 return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
143 auto multiIndexSet = std::set<MultiIndex,
decltype(compare)>{compare};
145 auto localView = basis.localView();
146 for (
const auto& e :
elements(basis.gridView()))
150 test.require(localView.size() <= localView.maxSize(),
"localView.size() check")
151 <<
"localView.size() is " << localView.size() <<
" but localView.maxSize() is " << localView.maxSize();
153 for (
decltype(localView.size()) i=0; i< localView.size(); ++i)
155 auto multiIndex = localView.index(i);
156 multiIndexSet.insert(multiIndex);
160 test.subTest(checkBasisIndexTreeConsistency(multiIndexSet));
161 test.subTest(checkBasisSizeConsistency(basis, multiIndexSet));
169Dune::TestSuite checkBasis(
const Basis& basis)
171 Dune::TestSuite test(
"basis check");
174 using GridView =
typename Basis::GridView;
176 test.check(
Dune::models<Dune::Functions::Concept::GlobalBasis<GridView>, Basis>(),
"global basis concept check")
177 <<
"type passed to checkBasis() does not model the GlobalBasis concept";
179 test.subTest(checkBasisIndices(basis));
Grid view abstract base class.
Definition: gridview.hh:60
Infrastructure for concepts.
constexpr auto models()
Check if concept is modeled by given types.
Definition: concept.hh:182
IteratorRange<... > elements(const GV &gv)
Iterates over all elements / cells (entities with codimension 0) of a GridView.
Dune namespace.
Definition: alignedallocator.hh:14