dune-fem  2.4.1-rc
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
9 #include <dune/geometry/referenceelements.hh>
10 #include <dune/geometry/type.hh>
11 #include <dune/grid/common/capabilities.hh>
12 
13 namespace Dune
14 {
15 
16  // External Forward Declarations
17  // -----------------------------
18 
19  namespace Fem
20  {
21 
22  // GeometryInformation
23  // -------------------
24 
27  template< class GridImp, int codim >
29  {
31 
32  public:
34  typedef GridImp GridType;
35 
37  static const int dim = GridType::dimension - codim;
38 
40  typedef typename GridType::ctype ctype;
41 
43  typedef Dune::ReferenceElement< ctype, dim > ReferenceElementType;
44 
46  typedef FieldVector<ctype, dim> DomainType;
47 
48  protected:
51  {}
52 
53  public:
55  explicit GeometryInformation( const std::vector< GeometryType > &geomTypes )
56  {
57  buildMaps( geomTypes );
58  }
59 
61  const DomainType &localCenter ( const GeometryType &type ) const
62  {
63  return referenceElement( type ).position( 0, 0 );
64  }
65 
67  double referenceVolume ( const GeometryType &type ) const
68  {
69  return referenceElement( type ).volume();
70  }
71 
73  static const ReferenceElementType &referenceElement ( const GeometryType &type )
74  {
75  return Dune::ReferenceElements< ctype, dim >::general( type );
76  }
77 
78  protected:
80  void buildMaps ( const std::vector< GeometryType > &geomTypes )
81  {}
82  };
83 
84 
88  template< class IndexSetImp, class GridImp >
89  class AllGeomTypes : public GeometryInformation< GridImp , 0>
90  {
91  public:
92  typedef IndexSetImp IndexSetType;
93  typedef GridImp GridType;
94 
95  private:
97  static const unsigned int ncodim = GridType :: dimension + 1;
98 
99  protected:
100  std::vector< std::vector< GeometryType > > geomTypes_;
101 
102  public:
103  // insert all types of the reference element into the geomTypes list
104  template <int dim>
106  {
107  static void apply( std::vector< std::vector< GeometryType > >& geomTypes )
108  {
109  static const int codim = GridType :: dimension - dim ;
110  typedef Dune::ReferenceElements< typename GridType :: ctype, dim > ReferenceElementContainer ;
111  typedef typename ReferenceElementContainer :: Iterator Iterator ;
112  for( Iterator it = ReferenceElementContainer::begin(),
113  end = ReferenceElementContainer::end(); it != end; ++it )
114  {
115  geomTypes[ codim ].push_back( it->type() );
116  }
117  }
118  };
119 
121  inline explicit AllGeomTypes( const IndexSetType &indexSet )
122  : geomTypes_( ncodim )
123  {
124  if( multipleGeomTypes() )
125  {
126  // store all possible geom types
127  ForLoop< InsertGeometryTypes, 0, GridType::dimension > :: apply( geomTypes_ );
128  }
129  else
130  {
131  // single geometry type
132  for( int codim=0; codim<GridType::dimension+1; ++codim )
133  {
134  typename IndexSetType::Types types = indexSet.types( codim );
135  const int size = types.size();
136  geomTypes_[ codim ].resize( size );
137  std::copy_n( types.begin(), size, geomTypes_[ codim ].begin() );
138  }
139  // build geometry information for codim 0
140  this->buildMaps( geomTypes_[ 0 ] );
141  }
142  }
143 
145  const std :: vector< GeometryType > &geomTypes ( unsigned int codim ) const
146  {
147  assert( codim < ncodim );
148  return geomTypes_[ codim ];
149  }
150 
152  static bool multipleGeomTypes ()
153  {
154  return !Dune::Capabilities :: hasSingleGeometryType < GridType > :: v;
155  }
156  };
157 
158  } // namespace Fem
159 
160 } // namespace Dune
161 
162 #endif // #ifndef DUNE_FEM_ALLGEOMTYPES_HH
static const int dim
dimension
Definition: allgeomtypes.hh:37
static void apply(std::vector< std::vector< GeometryType > > &geomTypes)
Definition: allgeomtypes.hh:107
GridImp GridType
grid type
Definition: allgeomtypes.hh:34
Definition: allgeomtypes.hh:105
GridType::ctype ctype
coordinate type
Definition: allgeomtypes.hh:40
AllGeomTypes(const IndexSetType &indexSet)
constructor storing index set reference
Definition: allgeomtypes.hh:121
Dune::ReferenceElement< ctype, dim > ReferenceElementType
type of reference element
Definition: allgeomtypes.hh:43
IndexSetImp IndexSetType
Definition: allgeomtypes.hh:92
ReferenceVolume and local bary center keeper class.
Definition: allgeomtypes.hh:28
void buildMaps(const std::vector< GeometryType > &geomTypes)
build maps
Definition: allgeomtypes.hh:80
GeometryInformation()
constructor creating empty geometry information
Definition: allgeomtypes.hh:50
double referenceVolume(const GeometryType &type) const
return volume of reference element for geometry of type type
Definition: allgeomtypes.hh:67
Definition: coordinate.hh:4
static bool multipleGeomTypes()
UGGrid might have different geom types.
Definition: allgeomtypes.hh:152
GeometryInformation(const std::vector< GeometryType > &geomTypes)
creating geometry information due to given geometry types list
Definition: allgeomtypes.hh:55
default implementation uses method geomTypes of given index set. Used in DiscreteFunctionSpaces.
Definition: allgeomtypes.hh:89
std::vector< std::vector< GeometryType > > geomTypes_
Definition: allgeomtypes.hh:100
const DomainType & localCenter(const GeometryType &type) const
return local bary center for geometry of type type
Definition: allgeomtypes.hh:61
GridImp GridType
Definition: allgeomtypes.hh:93
static const ReferenceElementType & referenceElement(const GeometryType &type)
return reference element for type
Definition: allgeomtypes.hh:73
const std::vector< GeometryType > & geomTypes(unsigned int codim) const
returns vector with geometry tpyes this index set has indices for
Definition: allgeomtypes.hh:145
FieldVector< ctype, dim > DomainType
type of domain vector
Definition: allgeomtypes.hh:46