dune-fem  2.6-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 <map>
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::vector< 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 ].push_back( it->type() );
125  }
126  }
127  };
128 
130  inline explicit AllGeomTypes( const IndexSetType &indexSet )
131  : geomTypes_( ncodim )
132  {
133  if( multipleGeomTypes() )
134  {
135  // store all possible geom types
137  }
138  else
139  {
140  // single geometry type
141  for( int codim=0; codim<GridType::dimension+1; ++codim )
142  {
143  typename IndexSetType::Types types = indexSet.types( codim );
144  const int size = types.size();
145  geomTypes_[ codim ].resize( size );
146  std::copy_n( types.begin(), size, geomTypes_[ codim ].begin() );
147  }
148  // build geometry information for codim 0
149  this->buildMaps( geomTypes_[ 0 ] );
150  }
151  }
152 
154  const std :: vector< GeometryType > &geomTypes ( unsigned int codim ) const
155  {
156  assert( codim < ncodim );
157  return geomTypes_[ codim ];
158  }
159 
161  static bool multipleGeomTypes ()
162  {
163  return !Dune::Capabilities :: hasSingleGeometryType < GridType > :: v;
164  }
165  };
166 
167  } // namespace Fem
168 
169 } // namespace Dune
170 
171 #endif // #ifndef DUNE_FEM_ALLGEOMTYPES_HH
Definition: bindguard.hh:11
static void apply(Args &&... args)
Definition: forloop.hh:21
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:161
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:154
AllGeomTypes(const IndexSetType &indexSet)
constructor storing index set reference
Definition: allgeomtypes.hh:130
Definition: allgeomtypes.hh:115
static void apply(std::vector< std::vector< GeometryType > > &geomTypes)
Definition: allgeomtypes.hh:116