Dune Core Modules (2.9.0)

checkseiterator.hh
1#ifndef DUNE_SPGRID_CHECKSEITERATOR_HH
2#define DUNE_SPGRID_CHECKSEITERATOR_HH
3
4#include <type_traits>
5#include <vector>
6#include <utility>
7
8#include <dune/common/hybridutilities.hh>
10
11#include <dune/grid/common/gridview.hh>
12
14
15namespace Dune
16{
17
18 template< class VT >
19 struct CheckSuperEntityIterator;
20
21
22
23 template< class VT >
24 void checkSuperEntityIterator ( const Dune::GridView< VT > &gridView )
25 {
26 CheckSuperEntityIterator< VT >::apply( gridView );
27 }
28
29
30
31 template< class VT >
32 struct CheckSuperEntityIterator
33 {
34 typedef Dune::GridView< VT > GridView;
35 typedef typename GridView::Grid Grid;
36
37 template< int codim >
38 struct Check
39 {
40 static void apply ( const GridView &gridView );
41 };
42
43 template< int codim >
44 struct NoCheck
45 {
46 static void apply ( const GridView &gridView )
47 {}
48 };
49
50 static void apply ( const GridView &gridView )
51 {
52 Hybrid::forEach( std::make_integer_sequence< int, GridView::dimension >(), [ &gridView ] ( auto dim ) {
53 const int codim = GridView::dimension - dim;
55 std::conditional< check, Check< codim >, NoCheck< codim > >::type::apply( gridView );
56 } );
57 }
58 };
59
60
61 template< class VT >
62 template< int codim >
63 inline void CheckSuperEntityIterator< VT >::Check< codim >::apply ( const GridView &gridView )
64 {
65 typedef typename GridView::IndexSet IndexSet;
66 std::cout << ">>> Checking SuperEntityIterator for codimension "
67 << codim << "..." << std::endl;
68
69 const IndexSet &indexSet = gridView.indexSet();
70 std::vector< int > count( indexSet.size( codim ), 0 );
71
72 typedef typename GridView::template Codim< 0 >::Iterator ElementIterator;
73
74 const ElementIterator elEnd = gridView.template end< 0 >();
75 for( ElementIterator elIt = gridView.template begin< 0 >(); elIt != elEnd; ++elIt )
76 {
77 const typename ElementIterator::Entity &entity =*elIt;
78 for( unsigned int i = 0; i < entity.subEntities( codim ); ++i )
79 ++count[ indexSet.subIndex( entity, i, codim ) ];
80 }
81
82 typedef typename GridView::template Codim< codim >::Iterator CodimIterator;
83 typedef typename GridView::Implementation::template Codim< codim >::SuperEntityIterator SEIterator;
84
85 const CodimIterator codimEnd = gridView.template end< codim >();
86 for( CodimIterator codimIt = gridView.template begin< codim >(); codimIt != codimEnd; ++codimIt )
87 {
88 const typename CodimIterator::Entity &entity = *codimIt;
89
90 int cnt = 0;
91 const SEIterator seEnd = gridView.impl().superEntityEnd( entity );
92 for( SEIterator seIt = gridView.impl().superEntityBegin( entity ); seIt != seEnd; ++seIt )
93 {
94 const typename SEIterator::Entity &element = *seIt;
95
96 ++cnt;
97
98 int k = 0;
99 const int numSubs = element.subEntities( codim );
100 while( (k < numSubs) && (element.template subEntity< codim >( k ) != *codimIt) )
101 ++k;
102 if( k == numSubs )
103 {
104 std::cout << "Entity " << indexSet.index( entity )
105 << "of codimension " << codim
106 << "is not a subentity of its super entity iterator."
107 << std::endl;
108 }
109 else if( k != seIt.index() )
110 {
111 std::cout << "Entity " << indexSet.index( entity )
112 << "of codimension " << codim
113 << "is subEntity " << k << " instead of " << seIt.index() << "."
114 << std::endl;
115 }
116
117 SEIterator copy = seIt;
118 ++copy;
119 if( copy == seIt )
120 std::cout << "Two subsequent super entity iterators should differ." << std::endl;
121 }
122
123 if( cnt != count[ indexSet.index( entity ) ] )
124 {
125 std::cout << "Number of super entities differs for entity "
126 << indexSet.index( entity )
127 << " of codimension " << codim
128 << " (" << cnt << " != " << count[ indexSet.index( entity ) ] << ")."
129 << std::endl;
130 }
131 }
132 }
133
134} // namespace Dune
135
136#endif // #ifndef DUNE_SPGRID_CHECKSEITERATOR_HH
Grid view abstract base class.
Definition: gridview.hh:66
Traits for type conversions and type information.
interface classes for superentity iterators
Traits::Grid Grid
type of the grid
Definition: gridview.hh:83
Traits::IndexSet IndexSet
type of the index set
Definition: gridview.hh:86
static constexpr int dimension
The dimension of the grid.
Definition: gridview.hh:148
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:268
Dune namespace.
Definition: alignedallocator.hh:13
static const bool v
by default, a grid does not support superentity iterators
Definition: superentityiterator.hh:84
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)