dune-fem  2.8-git
allgeomtypes.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_ALLGEOMTYPES_HH
2 #define DUNE_FEM_ALLGEOMTYPES_HH
3 
4 //- system includes
5 #include <vector>
6 #include <set>
7 
8 //- Dune includes
10 #include <dune/geometry/referenceelements.hh>
11 #include <dune/geometry/type.hh>
12 #include <dune/grid/common/capabilities.hh>
13 
14 namespace Dune
15 {
16 
17  // External Forward Declarations
18  // -----------------------------
19 
20  namespace Fem
21  {
22 
23  // GeometryInformation
24  // -------------------
25 
28  template< class GridImp, int codim >
30  {
32 
33  public:
35  typedef GridImp GridType;
36 
38  static const int dim = GridType::dimension - codim;
39 
41  typedef typename GridType::ctype ctype;
42 
43  protected:
44  typedef Dune::ReferenceElements< ctype, dim > ReferenceElementsType;
45 
46  public:
48  typedef std::decay_t< decltype( ReferenceElementsType::general( std::declval< const GeometryType & >() ) ) > ReferenceElementType;
49 
51  typedef FieldVector<ctype, dim> DomainType;
52 
53  protected:
56  {}
57 
58  public:
60  explicit GeometryInformation( const std::vector< GeometryType > &geomTypes )
61  {
62  buildMaps( geomTypes );
63  }
64 
66  const DomainType localCenter ( const GeometryType &type ) const
67  {
68  return type.isNone() ? isNoneLocalCenter_ : referenceElement( type ).position( 0, 0 );
69  }
70 
72  ctype referenceVolume ( const GeometryType &type ) const
73  {
74  return type.isNone() ? ctype(1.0) : referenceElement( type ).volume();
75  }
76 
78  static auto referenceElement ( const GeometryType &type )
79  -> decltype( ReferenceElementsType::general( type ) )
80  {
81  assert( ! type.isNone() );
82  return ReferenceElementsType::general( type );
83  }
84 
85  protected:
87 
89  void buildMaps ( const std::vector< GeometryType > &geomTypes )
90  {}
91  };
92 
93 
97  template< class IndexSetImp, class GridImp >
98  class AllGeomTypes : public GeometryInformation< GridImp , 0>
99  {
100  public:
101  typedef IndexSetImp IndexSetType;
102  typedef GridImp GridType;
103 
104  private:
106  static const unsigned int ncodim = GridType :: dimension + 1;
107 
108  protected:
109  std::vector< std::vector< GeometryType > > geomTypes_;
110 
111  public:
112  // insert all types of the reference element into the geomTypes list
113  template <int dim>
115  {
116  static void apply( std::vector< std::set< GeometryType > >& geomTypes )
117  {
118  static const int codim = GridType :: dimension - dim ;
119  typedef Dune::ReferenceElements< typename GridType :: ctype, dim > ReferenceElementContainer ;
120  typedef typename ReferenceElementContainer :: Iterator Iterator ;
121  for( Iterator it = ReferenceElementContainer::begin(),
122  end = ReferenceElementContainer::end(); it != end; ++it )
123  {
124  geomTypes[ codim ].insert( it->type() );
125  }
126  }
127  };
128 
130  inline explicit AllGeomTypes( const IndexSetType &indexSet )
131  : geomTypes_( ncodim )
132  {
133  if( multipleGeomTypes() )
134  {
135  std::vector< std::set< GeometryType > > geomTypes( ncodim );
136 
137  // store all possible geom types
139 
140  auto types = indexSet.types( 0 );
141  for( const auto type : types )
142  {
143  geomTypes[ 0 ].insert( type );
144  }
145 
146  for( unsigned int cd=0; cd < ncodim; ++cd )
147  {
148  geomTypes_[ cd ].reserve( geomTypes[ cd ].size() );
149  for( const auto& type : geomTypes[ cd ] )
150  {
151  geomTypes_[ cd ].push_back( type );
152  }
153  }
154  }
155  else
156  {
157  // single geometry type
158  for( int codim=0; codim<GridType::dimension+1; ++codim )
159  {
160  typename IndexSetType::Types types = indexSet.types( codim );
161  const int size = types.size();
162  geomTypes_[ codim ].resize( size );
163  std::copy_n( types.begin(), size, geomTypes_[ codim ].begin() );
164  }
165  // build geometry information for codim 0
166  this->buildMaps( geomTypes_[ 0 ] );
167  }
168  }
169 
171  const std :: vector< GeometryType > &geomTypes ( unsigned int codim ) const
172  {
173  assert( codim < ncodim );
174  return geomTypes_[ codim ];
175  }
176 
178  static bool multipleGeomTypes ()
179  {
180  return !Dune::Capabilities :: hasSingleGeometryType < GridType > :: v;
181  }
182  };
183 
184  } // namespace Fem
185 
186 } // namespace Dune
187 
188 #endif // #ifndef DUNE_FEM_ALLGEOMTYPES_HH
Definition: bindguard.hh:11
static DUNE_PRIVATE void apply(Args &&... args)
Definition: forloop.hh:23
ReferenceVolume and local bary center keeper class.
Definition: allgeomtypes.hh:30
GridType::ctype ctype
coordinate type
Definition: allgeomtypes.hh:41
GeometryInformation()
constructor creating empty geometry information
Definition: allgeomtypes.hh:55
const DomainType localCenter(const GeometryType &type) const
return local bary center for geometry of type type
Definition: allgeomtypes.hh:66
void buildMaps(const std::vector< GeometryType > &geomTypes)
build maps
Definition: allgeomtypes.hh:89
ctype referenceVolume(const GeometryType &type) const
return volume of reference element for geometry of type type
Definition: allgeomtypes.hh:72
std::decay_t< decltype(ReferenceElementsType::general(std::declval< const GeometryType & >))) > ReferenceElementType
type of reference element
Definition: allgeomtypes.hh:48
static auto referenceElement(const GeometryType &type) -> decltype(ReferenceElementsType::general(type))
return reference element for type
Definition: allgeomtypes.hh:78
static const int dim
dimension
Definition: allgeomtypes.hh:38
GeometryInformation(const std::vector< GeometryType > &geomTypes)
creating geometry information due to given geometry types list
Definition: allgeomtypes.hh:60
Dune::ReferenceElements< ctype, dim > ReferenceElementsType
Definition: allgeomtypes.hh:44
GridImp GridType
grid type
Definition: allgeomtypes.hh:35
FieldVector< ctype, dim > DomainType
type of domain vector
Definition: allgeomtypes.hh:51
DomainType isNoneLocalCenter_
Definition: allgeomtypes.hh:86
default implementation uses method geomTypes of given index set. Used in DiscreteFunctionSpaces.
Definition: allgeomtypes.hh:99
static bool multipleGeomTypes()
UGGrid might have different geom types.
Definition: allgeomtypes.hh:178
GridImp GridType
Definition: allgeomtypes.hh:102
std::vector< std::vector< GeometryType > > geomTypes_
Definition: allgeomtypes.hh:109
IndexSetImp IndexSetType
Definition: allgeomtypes.hh:101
const std ::vector< GeometryType > & geomTypes(unsigned int codim) const
returns vector with geometry tpyes this index set has indices for
Definition: allgeomtypes.hh:171
AllGeomTypes(const IndexSetType &indexSet)
constructor storing index set reference
Definition: allgeomtypes.hh:130
Definition: allgeomtypes.hh:115
static void apply(std::vector< std::set< GeometryType > > &geomTypes)
Definition: allgeomtypes.hh:116