dune-geometry  2.3.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/static_assert.hh>
7 #include <dune/common/visibility.hh>
8 
9 #include <dune/geometry/type.hh>
12 
13 namespace Dune
14 {
15 
16  namespace GenericGeometry
17  {
18 
19  // DuneGeometryType
20  // ----------------
21 
30  template< class Topology, GeometryType::BasicType linetype >
32 
33  template< GeometryType::BasicType linetype >
34  class DuneGeometryType< Point, linetype >
35  {
36  dune_static_assert( (linetype == GeometryType::simplex)
37  || (linetype == GeometryType::cube),
38  "Parameter linetype may only be a simplex or a cube." );
39 
40  public:
41  static const unsigned int dimension = 0;
42  static const GeometryType::BasicType basicType = linetype;
43  };
44 
45  template< class BaseTopology, GeometryType::BasicType linetype >
46  class DuneGeometryType< Prism< BaseTopology >, linetype >
47  {
49 
50  dune_static_assert( (linetype == GeometryType::simplex)
51  || (linetype == GeometryType::cube),
52  "Parameter linetype may only be a simplex or a cube." );
53 
54  dune_static_assert( (DuneBaseGeometryType::basicType == GeometryType::simplex)
55  || (DuneBaseGeometryType::basicType == GeometryType::cube),
56  "Only prisms over simplices or cubes can be converted." );
57 
58  public:
59  static const unsigned int dimension = DuneBaseGeometryType::dimension + 1;
60  static const GeometryType::BasicType basicType
61  = ((dimension == 1)
62  ? linetype
63  : ((dimension == 2) || (DuneBaseGeometryType::basicType == GeometryType::cube))
66  };
67 
68  template< class BaseTopology, GeometryType::BasicType linetype >
69  class DuneGeometryType< Pyramid< BaseTopology >, linetype >
70  {
72 
73  dune_static_assert( (linetype == GeometryType::simplex)
74  || (linetype == GeometryType::cube),
75  "Parameter linetype may only be a simplex or a cube." );
76 
77  dune_static_assert( (DuneBaseGeometryType::basicType == GeometryType::simplex)
78  || (DuneBaseGeometryType::basicType == GeometryType::cube),
79  "Only pyramids over simplices or cubes can be converted." );
80 
81  public:
82  static const unsigned int dimension = DuneBaseGeometryType::dimension + 1;
83  static const GeometryType::BasicType basicType
84  = ((dimension == 1)
85  ? linetype
86  : ((dimension == 2) || (DuneBaseGeometryType::basicType == GeometryType::simplex))
89  };
90 
91 
92 
93  // DuneGeometryTypeProvider
94  // ------------------------
95 
107  template< unsigned int dim, GeometryType::BasicType linetype >
109  {
111  static const unsigned int dimension = dim;
112 
114  static const unsigned int numTopologies = (1 << dimension);
115 
116  private:
117  GeometryType types_[ (dimension>=1) ? numTopologies / 2 : numTopologies ];
118 
119  DUNE_EXPORT static const DuneGeometryTypeProvider &instance ()
120  {
121  static DuneGeometryTypeProvider inst;
122  return inst;
123  }
124 
125  public:
132  static const GeometryType &type ( unsigned int topologyId )
133  {
134  assert( topologyId < numTopologies );
135  return instance().types_[ topologyId / 2 ];
136  }
137  };
138 
139 
140  // Convert
141  // -------
142 
143  template< GeometryType :: BasicType type, unsigned int dim >
144  struct Convert;
145 
146  template< unsigned int dim >
147  struct Convert< GeometryType :: simplex, dim >
148  {
149  typedef Pyramid
150  < typename Convert< GeometryType :: simplex, dim-1 > :: type >
152  };
153 
154  template<>
155  struct Convert< GeometryType :: simplex, 0 >
156  {
157  typedef Point type;
158  };
159 
160  template< unsigned int dim >
161  struct Convert< GeometryType :: cube, dim >
162  {
163  typedef Prism< typename Convert< GeometryType :: cube, dim-1 > :: type >
165  };
166 
167  template<>
168  struct Convert< GeometryType :: cube, 0 >
169  {
170  typedef Point type;
171  };
172 
173  template< unsigned int dim >
174  struct Convert< GeometryType :: prism, dim >
175  {
176  typedef Prism
177  < typename Convert< GeometryType :: simplex, dim-1 > :: type >
179  };
180 
181  template< unsigned int dim >
182  struct Convert< GeometryType :: pyramid, dim >
183  {
184  typedef Pyramid
185  < typename Convert< GeometryType :: cube, dim-1 > :: type >
187  };
188 
189  }
190 
191 }
192 
193 #endif // #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_CONVERSION_HH
Prism element in three dimensions.
Definition: type.hh:33
static const GeometryType & type(unsigned int topologyId)
obtain a Geometry type from a topology id
Definition: conversion.hh:132
static const unsigned int numTopologies
number of possible topologies
Definition: conversion.hh:114
Definition: topologytypes.hh:57
A unique label for each type of element that can occur in a grid.
dynamically convert a generic topology type into a GeometryType
Definition: conversion.hh:108
Definition: conversion.hh:144
Simplicial element in any nonnegative dimension.
Definition: type.hh:30
static const unsigned int dimension
dimension of the topologies to be converted
Definition: conversion.hh:111
statically convert a generic topology type into a GeometryType
Definition: conversion.hh:31
Prism< typename Convert< GeometryType::cube, dim-1 >::type > type
Definition: conversion.hh:164
Definition: topologytypes.hh:41
Pyramid< typename Convert< GeometryType::simplex, dim-1 >::type > type
Definition: conversion.hh:151
Cube element in any nonnegative dimension.
Definition: type.hh:31
Definition: topologytypes.hh:74
Definition: topologytypes.hh:26
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:24
Pyramid< typename Convert< GeometryType::cube, dim-1 >::type > type
Definition: conversion.hh:186
Four sided pyramid in three dimensions.
Definition: type.hh:32
Prism< typename Convert< GeometryType::simplex, dim-1 >::type > type
Definition: conversion.hh:178
BasicType
Each entity can be tagged by one of these basic types plus its space dimension.
Definition: type.hh:29