dune-geometry  2.4.1
conversion.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_CONVERSION_HH
4 #define DUNE_GEOMETRY_GENERICGEOMETRY_CONVERSION_HH
5 
6 #include <dune/common/visibility.hh>
7 
8 #include <dune/geometry/type.hh>
11 
12 namespace Dune
13 {
14 
15  namespace GenericGeometry
16  {
17 
18  // DuneGeometryType
19  // ----------------
20 
29  template< class Topology, GeometryType::BasicType linetype >
31 
32  template< GeometryType::BasicType linetype >
33  class DuneGeometryType< Point, linetype >
34  {
35  static_assert((linetype == GeometryType::simplex)
36  || (linetype == GeometryType::cube),
37  "Parameter linetype may only be a simplex or a cube.");
38 
39  public:
40  static const unsigned int dimension = 0;
41  static const GeometryType::BasicType basicType = linetype;
42  };
43 
44  template< class BaseTopology, GeometryType::BasicType linetype >
45  class DuneGeometryType< Prism< BaseTopology >, linetype >
46  {
48 
49  static_assert((linetype == GeometryType::simplex)
50  || (linetype == GeometryType::cube),
51  "Parameter linetype may only be a simplex or a cube.");
52 
53  static_assert((DuneBaseGeometryType::basicType == GeometryType::simplex)
54  || (DuneBaseGeometryType::basicType == GeometryType::cube),
55  "Only prisms over simplices or cubes can be converted.");
56 
57  public:
58  static const unsigned int dimension = DuneBaseGeometryType::dimension + 1;
59  static const GeometryType::BasicType basicType
60  = ((dimension == 1)
61  ? linetype
62  : ((dimension == 2) || (DuneBaseGeometryType::basicType == GeometryType::cube))
65  };
66 
67  template< class BaseTopology, GeometryType::BasicType linetype >
68  class DuneGeometryType< Pyramid< BaseTopology >, linetype >
69  {
71 
72  static_assert((linetype == GeometryType::simplex)
73  || (linetype == GeometryType::cube),
74  "Parameter linetype may only be a simplex or a cube.");
75 
76  static_assert((DuneBaseGeometryType::basicType == GeometryType::simplex)
77  || (DuneBaseGeometryType::basicType == GeometryType::cube),
78  "Only pyramids over simplices or cubes can be converted.");
79 
80  public:
81  static const unsigned int dimension = DuneBaseGeometryType::dimension + 1;
82  static const GeometryType::BasicType basicType
83  = ((dimension == 1)
84  ? linetype
85  : ((dimension == 2) || (DuneBaseGeometryType::basicType == GeometryType::simplex))
88  };
89 
90 
91 
92  // DuneGeometryTypeProvider
93  // ------------------------
94 
106  template< unsigned int dim, GeometryType::BasicType linetype >
108  {
110  static const unsigned int dimension = dim;
111 
113  static const unsigned int numTopologies = (1 << dimension);
114 
115  private:
116  GeometryType types_[ (dimension>=1) ? numTopologies / 2 : numTopologies ];
117 
118  DUNE_EXPORT static const DuneGeometryTypeProvider &instance ()
119  {
120  static DuneGeometryTypeProvider inst;
121  return inst;
122  }
123 
124  public:
131  static const GeometryType &type ( unsigned int topologyId )
132  {
133  assert( topologyId < numTopologies );
134  return instance().types_[ topologyId / 2 ];
135  }
136  };
137 
138 
139  // Convert
140  // -------
141 
142  template< GeometryType :: BasicType type, unsigned int dim >
143  struct Convert;
144 
145  template< unsigned int dim >
146  struct Convert< GeometryType :: simplex, dim >
147  {
148  typedef Pyramid
149  < typename Convert< GeometryType :: simplex, dim-1 > :: type >
151  };
152 
153  template<>
154  struct Convert< GeometryType :: simplex, 0 >
155  {
156  typedef Point type;
157  };
158 
159  template<