dune-geometry  2.4
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  {
70  typedef DuneGeometryType< BaseTopology, linetype > DuneBaseGeometryType;
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< unsigned int dim >
160  struct Convert< GeometryType :: cube, dim >
161  {
162  typedef Prism< typename Convert< GeometryType :: cube, dim-1 > :: type >
164  };
165 
166  template<>
167  struct Convert< GeometryType :: cube, 0 >
168  {
169  typedef Point type;
170  };
171 
172  template< unsigned int dim >
173  struct Convert< GeometryType :: prism, dim >
174  {
175  typedef Prism
176  < typename Convert< GeometryType :: simplex, dim-1 > :: type >
178  };
179 
180  template< unsigned int dim >
181  struct Convert< GeometryType :: pyramid, dim >
182  {
183  typedef Pyramid
184  < typename Convert< GeometryType :: cube, dim-1 > :: type >
186  };
187 
188  }
189 
190 }
191 
192 #endif // #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_CONVERSION_HH
BasicType
Each entity can be tagged by one of these basic types plus its space dimension.
Definition: type.hh:29
Definition: topologytypes.hh:40
Definition: affinegeometry.hh:18
statically convert a generic topology type into a GeometryType
Definition: conversion.hh:30
static const unsigned int numTopologies
number of possible topologies
Definition: conversion.hh:113
Definition: conversion.hh:143
static const GeometryType & type(unsigned int topologyId)
obtain a Geometry type from a topology id
Definition: conversion.hh:131
Prism< typename Convert< GeometryType::cube, dim-1 >::type > type
Definition: conversion.hh:163
Definition: topologytypes.hh:56
Definition: topologytypes.hh:25
dynamically convert a generic topology type into a GeometryType
Definition: conversion.hh:107
Prism< typename Convert< GeometryType::simplex, dim-1 >::type > type
Definition: conversion.hh:177
Prism element in three dimensions.
Definition: type.hh:33
A unique label for each type of element that can occur in a grid.
Four sided pyramid in three dimensions.
Definition: type.hh:32
Pyramid< typename Convert< GeometryType::simplex, dim-1 >::type > type
Definition: conversion.hh:150
Definition: topologytypes.hh:73
Pyramid< typename Convert< GeometryType::cube, dim-1 >::type > type
Definition: conversion.hh:185
Simplicial element in any nonnegative dimension.
Definition: type.hh:30
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:24
Cube element in any nonnegative dimension.
Definition: type.hh:31
static const unsigned int dimension
dimension of the topologies to be converted
Definition: conversion.hh:110