Dune Core Modules (2.3.1)

conversion.hh
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
8
10#include <dune/geometry/genericgeometry/topologytypes.hh>
11#include <dune/geometry/genericgeometry/subtopologies.hh>
12
13namespace 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 {
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 {
48 typedef DuneGeometryType< BaseTopology, linetype > DuneBaseGeometryType;
49
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 {
71 typedef DuneGeometryType< BaseTopology, linetype > DuneBaseGeometryType;
72
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 >
151 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 >
164 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 >
178 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 >
186 type;
187 };
188
189 }
190
191}
192
193#endif // #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_CONVERSION_HH
statically convert a generic topology type into a GeometryType
Definition: conversion.hh:31
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
BasicType
Each entity can be tagged by one of these basic types plus its space dimension.
Definition: type.hh:29
@ cube
Cube element in any nonnegative dimension.
Definition: type.hh:31
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:30
@ pyramid
Four sided pyramid in three dimensions.
Definition: type.hh:32
@ prism
Prism element in three dimensions.
Definition: type.hh:33
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
#define dune_static_assert(COND, MSG)
Helper template so that compilation fails if condition is not true.
Definition: static_assert.hh:79
Dune namespace.
Definition: alignment.hh:14
Fallback implementation of the C++0x static_assert feature.
dynamically convert a generic topology type into a GeometryType
Definition: conversion.hh:109
static const unsigned int numTopologies
number of possible topologies
Definition: conversion.hh:114
static const GeometryType & type(unsigned int topologyId)
obtain a Geometry type from a topology id
Definition: conversion.hh:132
static const unsigned int dimension
dimension of the topologies to be converted
Definition: conversion.hh:111
A unique label for each type of element that can occur in a grid.
Definition of macros controlling symbol visibility at the ABI level.
#define DUNE_EXPORT
Export a symbol as part of the public ABI.
Definition: visibility.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)