Dune Core Modules (2.4.2)

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
7
9#include <dune/geometry/genericgeometry/topologytypes.hh>
10#include <dune/geometry/genericgeometry/subtopologies.hh>
11
12namespace 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 {
47 typedef DuneGeometryType< BaseTopology, linetype > DuneBaseGeometryType;
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 >
150 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 >
163 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 >
177 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 >
185 type;
186 };
187
188 }
189
190}
191
192#endif // #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_CONVERSION_HH
statically convert a generic topology type into a GeometryType
Definition: conversion.hh:30
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
Dune namespace.
Definition: alignment.hh:10
dynamically convert a generic topology type into a GeometryType
Definition: conversion.hh:108
static const unsigned int numTopologies
number of possible topologies
Definition: conversion.hh:113
static const GeometryType & type(unsigned int topologyId)
obtain a Geometry type from a topology id
Definition: conversion.hh:131
static const unsigned int dimension
dimension of the topologies to be converted
Definition: conversion.hh:110
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)