1 #ifndef DUNE_FEM_GRIDPART_TEST_CHECKGEOMETRY_HH
2 #define DUNE_FEM_GRIDPART_TEST_CHECKGEOMETRY_HH
3 
4 //- dune-common includes
5 #include <dune/fem/common/forloop.hh>
6 #include <dune/common/exceptions.hh>
7 #include <dune/common/stdstreams.hh>
8 
9 //- dune-grid includes
10 #include <dune/grid/test/checkgeometry.hh>
11 
12 //- dune-fem includes
13 #include <dune/fem/gridpart/common/capabilities.hh>
14 #include <dune/fem/gridpart/test/failure.hh>
15 
16 
17 /** \brief Check geometries for all entities in the
18  *         grid part. The tests are implemented in
19  *         \code
20 <dune/grid/test/checkgeometry.cc>
21  *         \endcode
22  *         Thus, failure handlers passed to this test
23  *         will be ignored.
24  *
25  */
26 
27 namespace Dune
28 {
29   namespace Fem
30   {
31 
32     template< class GridPartType, class FailureHandler >
33     class CheckGeometry
34     {
35       template< class GridPart, bool >
36       struct If
37       {
38         template< int codim, class Entity  >
checkDune::Fem::CheckGeometry::If39         static void check ( const Entity&, FailureHandler & )
40         { }
41       };
42 
43       template< class GridPart >
44       struct If< GridPart, true >
45       {
46         template< int codim, class Entity  >
checkDune::Fem::CheckGeometry::If47         static void check ( const Entity &entity, FailureHandler & )
48         {
49           const int subEntities = entity.subEntities( codim );
50           for ( int i = 0; i < subEntities; ++i )
51           {
52             auto subEntity = entity.template subEntity< codim >( i );
53 
54             auto geometry = subEntity.geometry();
55             if( subEntity.type() != geometry.type() )
56               std::cerr << "Error: Entity and geometry report different geometry types on codimension " << codim << "." << std::endl;
57             Dune::checkGeometry( geometry );
58           }
59         }
60       };
61 
62       template< int codim >
63       struct CheckSubEntityGeometry
64       {
65         template< class Entity >
applyDune::Fem::CheckGeometry::CheckSubEntityGeometry66         static void apply ( const Entity &entity, FailureHandler &failureHandler )
67         {
68           // check whether grid part has entity of given codimension
69           constexpr bool hasEntity = Dune::Fem::GridPartCapabilities::hasEntity< GridPartType, codim >::v;
70           If< GridPartType, hasEntity >::template check< codim, Entity >( entity, failureHandler );
71         }
72       };
73 
74     public:
75       static const int dimension = GridPartType::dimension;
76 
check(const GridPartType & gridPart,FailureHandler & failureHandler)77       static void check ( const GridPartType &gridPart, FailureHandler &failureHandler )
78       {
79         // tests will be forwarded to dune-grid, where failures are not supported
80         std::cout << "Note: FailureHandler will be ignored" << std::endl;
81 
82         for( const auto& entity : elements( gridPart ) )
83           Fem::ForLoop< CheckSubEntityGeometry, 0, dimension >::apply( entity, failureHandler );
84       }
85     };
86 
87   } // end namespace Fem
88 
89 } // end namespace Dune
90 
91 #endif // #ifndef DUNE_FEM_GRIDPART_TEST_CHECKGEOMETRY_HH
92