1 #ifndef DUNE_FEM_GRIDPART_TEST_CHECKSEED_HH 2 #define DUNE_FEM_GRIDPART_TEST_CHECKSEED_HH 3 4 //- C++ includes 5 #include <limits> 6 #include <type_traits> 7 8 //- dune-common includes 9 #include <dune/fem/common/forloop.hh> 10 #include <dune/common/exceptions.hh> 11 12 //- dune-fem includes 13 #include <dune/fem/gridpart/common/capabilities.hh> 14 15 16 namespace Dune 17 { 18 19 namespace Fem 20 { 21 22 /** \brief Iterate over all entities of all codimensions available in the grid part, 23 * and perform a number of tests on each entity. 24 */ 25 26 template< class GridPartType > 27 class CheckEntitySeed 28 { 29 template< class GridPart, bool > 30 struct If 31 { 32 template< int codim > checkDune::Fem::CheckEntitySeed::If33 static void check ( const GridPart & ) 34 { } 35 }; 36 37 template< class GridPart > 38 struct If< GridPart, true > 39 { 40 template< const int codim > checkDune::Fem::CheckEntitySeed::If41 static void check ( const GridPart &gridPart ) 42 { 43 typedef typename GridPart::template Codim< codim >::EntityType EntityType; 44 typedef typename GridPart::template Codim< codim >::EntitySeedType EntitySeedType; 45 static_assert( std::is_same< EntitySeedType, typename EntityType::EntitySeed >::value, "Types of EntitySeed do not coincide" ); 46 47 for( auto it = gridPart.template begin< codim >(); it != gridPart.template end< codim >(); ++it ) 48 { 49 auto entity = *it; 50 auto seed = entity.seed(); 51 if( gridPart.entity( seed ) != entity ) 52 DUNE_THROW( Dune::Exception, "Could not recover entity from seed" ); 53 } 54 } 55 }; 56 57 template< int codim > 58 struct CheckCodim 59 { 60 template< class GridPart > applyDune::Fem::CheckEntitySeed::CheckCodim61 static void apply ( const GridPart &gridPart ) 62 { 63 // check whether grid part has entity of given codimension 64 constexpr bool hasEntity = Dune::Fem::GridPartCapabilities::hasEntity< GridPart, codim >::v; 65 If< GridPart, hasEntity >::template check< codim >( gridPart ); 66 } 67 }; 68 69 public: 70 static const int dimension = GridPartType::dimension; 71 check(const GridPartType & gridPart)72 static void check ( const GridPartType &gridPart ) 73 { 74 // generic for loop over all codimensions 75 Dune::Fem::ForLoop< CheckCodim, 0, dimension >::apply( gridPart ); 76 } 77 }; 78 79 } // end namespace Fem 80 81 } // end namespace Dune 82 83 #endif // #ifndef DUNE_FEM_GRIDPART_TEST_CHECKSEED_HH 84