dune-fem  2.8-git
gridpart/filter/simple.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_GRIDPART_FILTER_SIMPLE_HH
2 #define DUNE_FEM_GRIDPART_FILTER_SIMPLE_HH
3 
4 #include <array>
5 #include <tuple>
6 #include <utility>
7 #include <vector>
8 
9 #include <dune/geometry/dimension.hh>
10 
11 #include <dune/grid/common/mcmgmapper.hh>
12 
15 
16 namespace Dune
17 {
18 
19  namespace Fem
20  {
21 
22  // Internal Forward Declarations
23  // -----------------------------
24 
25  template< class GridPart >
26  struct SimpleFilter;
27 
28 
29 
30  // SimpleFilterTraits
31  // ---------------------
32 
33  template< class GridPart >
35  {
37 
38  template< int codim >
39  struct Codim
40  {
41  typedef typename GridPart::template Codim< codim >::EntityType EntityType;
42  };
43  };
44 
45 
46 
47  // SimpleFilter
48  // ---------------
49 
50  template< class GridPart >
52  : public FilterDefaultImplementation< SimpleFilterTraits< GridPart > >
53  {
56 
57  typedef std::make_integer_sequence< int, GridPart::dimension+1 > AllCodims;
58 
59  public:
60  template< int codim >
61  using Codim = typename Base::template Codim< codim >;
62 
63  template< class Contains >
64  SimpleFilter ( const GridPart &gridPart, Contains contains, int domainId )
65  : mapper_( gridPart.gridView(),
66  [](Dune::GeometryType,int ) {return true;} ),
67  contains_( mapper_.size(), false ),
68  mapper0_( gridPart.gridView(),
69  [](Dune::GeometryType gt,int dim) {return gt.dim()==dim;} ),
70  domainIds_( mapper0_.size(), -1 )
71  {
72  for( const typename Codim< 0 >::EntityType &entity : elements( gridPart ) )
73  {
74  domainIds_[ mapper0_.index( entity ) ] = contains( entity );
75  if( domainIds_[ mapper0_.index( entity ) ] == domainId )
76  mark( entity, AllCodims() );
77  }
78  }
79 
80  template< int codim >
81  bool contains ( const typename Codim< codim >::EntityType &entity ) const
82  {
83  return contains_[ mapper_.index( entity ) ];
84  }
85 
86  template< class Entity >
87  bool contains ( const Entity &entity ) const
88  {
89  return contains< Entity::codimension >( entity );
90  }
91 
92  template< class Intersection >
93  bool interiorIntersection ( const Intersection &intersection ) const
94  {
95  return contains( intersection.outside() );
96  }
97 
98  template< class Intersection >
99  bool intersectionBoundary ( const Intersection & ) const
100  {
101  return true;
102  }
103 
104  template< class Intersection >
105  int intersectionBoundaryId ( const Intersection &intersection ) const
106  {
107  return ( intersection.boundary() ?
109  domainIds_[ mapper0_.index( intersection.outside() ) ] );
110  }
111 
112  template< class Intersection >
113  bool intersectionNeighbor ( const Intersection & ) const
114  {
115  return false;
116  }
117 
118  private:
119  template< int codim >
120  void mark ( const typename Codim< 0 >::EntityType &entity, Dune::Codim< codim > )
121  {
122  for( unsigned int i = 0, n = entity.subEntities( codim ); i < n; ++i )
123  contains_[ mapper_.subIndex( entity, i, codim ) ] = true;
124  }
125 
126  template< int... codim >
127  void mark ( const typename Codim< 0 >::EntityType &entity, std::integer_sequence< int, codim... > )
128  {
129  std::ignore = std::make_tuple( (mark( entity, Dune::Codim< codim >() ), codim)... );
130  }
131 
132  MultipleCodimMultipleGeomTypeMapper< typename GridPart::GridViewType > mapper_;
133  std::vector< bool > contains_;
134  MultipleCodimMultipleGeomTypeMapper< typename GridPart::GridViewType > mapper0_;
135  std::vector< int > domainIds_;
136  };
137 
138  } // namespace Fem
139 
140 } // namespace Dune
141 
142 #endif // #ifndef DUNE_FEM_GRIDPART_FILTER_SIMPLE_HH
Definition: bindguard.hh:11
Definition: filter/filter.hh:156
Definition: gridpart/filter/simple.hh:53
bool intersectionNeighbor(const Intersection &) const
Definition: gridpart/filter/simple.hh:113
bool contains(const Entity &entity) const
Definition: gridpart/filter/simple.hh:87
bool contains(const typename Codim< codim >::EntityType &entity) const
Definition: gridpart/filter/simple.hh:81
bool interiorIntersection(const Intersection &intersection) const
Definition: gridpart/filter/simple.hh:93
typename Base::template Codim< codim > Codim
Definition: gridpart/filter/simple.hh:61
int intersectionBoundaryId(const Intersection &intersection) const
Definition: gridpart/filter/simple.hh:105
bool intersectionBoundary(const Intersection &) const
Definition: gridpart/filter/simple.hh:99
SimpleFilter(const GridPart &gridPart, Contains contains, int domainId)
Definition: gridpart/filter/simple.hh:64
Definition: gridpart/filter/simple.hh:35
SimpleFilter< GridPart > FilterType
Definition: gridpart/filter/simple.hh:36
Definition: gridpart/filter/simple.hh:40
GridPart::template Codim< codim >::EntityType EntityType
Definition: gridpart/filter/simple.hh:41
Definition: boundaryidprovider.hh:36