Dune Core Modules (2.3.1)

mappingprovider.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_MAPPINGPROVIDER_HH
4#define DUNE_GEOMETRY_GENERICGEOMETRY_MAPPINGPROVIDER_HH
5
8
9#include <dune/geometry/genericgeometry/maximum.hh>
10#include <dune/geometry/genericgeometry/cachedmapping.hh>
11#include <dune/geometry/genericgeometry/hybridmapping.hh>
12
13namespace Dune
14{
15
16 namespace GenericGeometry
17 {
18
19 // NonHybridMappingFactory
20 // -----------------------
21
22 template< class Topology, class GeometryTraits >
23 class NonHybridMappingFactory
24 {
25 typedef NonHybridMappingFactory< Topology, GeometryTraits > This;
26
27 public:
28 typedef NonHybridMapping< Topology, GeometryTraits > Mapping;
29
30 static const unsigned int maxMappingSize = sizeof( Mapping );
31
32 template< class CoordVector >
33 static Mapping*
34 construct ( const unsigned int topologyId, const CoordVector &coords, char *mappingStorage )
35 {
36 assert( (topologyId >> 1) == (Topology::id >> 1) );
37 return new( mappingStorage ) Mapping( coords );
38 }
39
40 static std::size_t mappingSize ( const unsigned int topologyId )
41 {
42 DUNE_UNUSED_PARAMETER(topologyId);
43 return sizeof( Mapping );
44 }
45 };
46
47
48
49 // VirtualMappingFactory
50 // ---------------------
51
52 template< unsigned int dim, class GeometryTraits >
53 class VirtualMappingFactory
54 {
55 typedef VirtualMappingFactory< dim, GeometryTraits > This;
56
57 static const unsigned int numTopologies = (1 << dim);
58
59 template< int topologyId >
60 struct MappingSize
61 {
62 typedef typename GenericGeometry::Topology< (unsigned int) topologyId, dim >::type Topology;
63 static const int v = sizeof( VirtualMapping< Topology, GeometryTraits > );
64
65 static void apply ( std::size_t (&mappingSize)[ numTopologies ] )
66 {
67 mappingSize[ topologyId ] = v;
68 }
69 };
70
71 template< class CoordVector >
72 class ConstructorTable;
73
74 struct MappingSizeCache;
75
76 public:
77 typedef HybridMapping< dim, GeometryTraits > Mapping;
78
79 static const unsigned int maxMappingSize = Maximum< MappingSize, 0, ((numTopologies > 0) ? (numTopologies-1) : 0) >::v;
80
81 template< class CoordVector >
82 DUNE_EXPORT static Mapping*
83 construct ( const unsigned int topologyId, const CoordVector &coords, char *mappingStorage )
84 {
85 static ConstructorTable< CoordVector > construct;
86 return construct[ topologyId ]( coords, mappingStorage );
87 }
88
89 DUNE_EXPORT static std::size_t mappingSize ( const unsigned int topologyId )
90 {
91 static MappingSizeCache mappingSize;
92 return mappingSize[ topologyId ];
93 }
94 };
95
96
97 // VirtualMappingFactory::ConstructorTable
98 // ---------------------------------------
99
100 template< unsigned int dim, class GeometryTraits >
101 template< class CoordVector >
102 class VirtualMappingFactory< dim, GeometryTraits >::ConstructorTable
103 {
104 typedef Mapping* (*Construct)( const CoordVector &coords, char *mappingStorage );
105
106 template< int i >
107 struct Builder;
108
109 public:
110 ConstructorTable ()
111 {
112 ForLoop< Builder, 0, numTopologies-1 >::apply( construct_ );
113 }
114
115 Construct operator[] ( const unsigned int topologyId )
116 {
117 assert( topologyId < numTopologies );
118 return construct_[ topologyId ];
119 }
120
121 private:
122 template< class Topology >
123 static Mapping*
124 construct ( const CoordVector &coords, char *mappingStorage )
125 {
126 typedef VirtualMapping< Topology, GeometryTraits > VMapping;
127 return new( mappingStorage ) VMapping( coords );
128 }
129
130 Construct construct_[ numTopologies ];
131 };
132
133
134 // VirtualMappingFactory::ConstructorTable::Builder
135 // ------------------------------------------------
136
137 template< unsigned int dim, class GeometryTraits >
138 template< class CoordVector >
139 template< int topologyId >
140 struct VirtualMappingFactory< dim, GeometryTraits >::ConstructorTable< CoordVector >::Builder
141 {
142 static void apply ( Construct (&construct)[ numTopologies ] )
143 {
144 typedef typename GenericGeometry::Topology< (unsigned int) topologyId, dim >::type Topology;
145 construct[ topologyId ] = ConstructorTable< CoordVector >::template construct< Topology >;
146 }
147 };
148
149
150
151 // VirtualMappingFactory::MappingSizeCache
152 // ---------------------------------------
153
154 template< unsigned int dim, class GeometryTraits >
155 struct VirtualMappingFactory< dim, GeometryTraits >::MappingSizeCache
156 {
157 MappingSizeCache ()
158 {
159 ForLoop< MappingSize, 0, numTopologies-1 >::apply( size_ );
160 }
161
162 std::size_t operator[] ( const unsigned int topologyId )
163 {
164 assert( topologyId < numTopologies );
165 return size_[ topologyId ];
166 }
167
168 private:
169 std::size_t size_[ numTopologies ];
170 };
171
172
173
174 // MappingProvider
175 // ---------------
176
177 template< class ElementMapping, unsigned int codim >
178 class MappingProvider;
179
180
181 template< unsigned int dim, class GeometryTraits, unsigned int codim >
182 class MappingProvider< HybridMapping< dim, GeometryTraits >, codim >
183 {
184 typedef MappingProvider< HybridMapping< dim, GeometryTraits >, codim > This;
185
186 dune_static_assert(dim>=codim, "Codim exceeds dimension");
187 public:
188 static const unsigned int dimension = dim;
189 static const unsigned int codimension = codim;
190 static const unsigned int mydimension = dimension - codimension;
191
192 private:
193 typedef VirtualMappingFactory< mydimension, GeometryTraits > Factory;
194
195 public:
196 // Maximal amount of memory required to store a mapping
197 static const unsigned int maxMappingSize = Factory::maxMappingSize;
198
199 typedef typename Factory::Mapping Mapping;
200
201 template< class CoordVector >
202 static Mapping*
203 construct ( const unsigned int topologyId, const CoordVector &coords, char *mappingStorage )
204 {
205 return Factory::construct( topologyId, coords, mappingStorage );
206 }
207
208 template< class CoordVector >
209 static Mapping *create ( const unsigned int topologyId, const CoordVector &coords )
210 {
211 char *mapping = new char[ mappingSize( topologyId ) ];
212 return construct( topologyId, coords, mapping );
213 }
214
215 static std::size_t mappingSize ( const unsigned int topologyId )
216 {
217 return Factory::mappingSize( topologyId );
218 }
219 };
220
221
222 template< class Topology, class GeometryTraits, unsigned int codim >
223 class MappingProvider< NonHybridMapping< Topology, GeometryTraits >, codim >
224 {
225 typedef MappingProvider< NonHybridMapping< Topology, GeometryTraits >, codim > This;
226
227 public:
228 static const unsigned int dimension = Topology::dimension;
229 static const unsigned int codimension = codim;
230 static const unsigned int mydimension = dimension - codimension;
231
232 static const bool hybrid = (mydimension != dimension) && IsHybrid< Topology >::value;
233
234 private:
235 template< bool >
236 struct HybridFactory
237 : public VirtualMappingFactory< mydimension, GeometryTraits >
238 {};
239
240 template< bool >
241 struct NonHybridFactory
242 : public NonHybridMappingFactory
243 < typename SubTopology< Topology, codim, 0 >::type, GeometryTraits >
244 {};
245
246 typedef typename conditional< hybrid, HybridFactory<true>, NonHybridFactory<false> >::type Factory;
247
248 public:
249 // Maximal amount of memory required to store a mapping
250 static const unsigned int maxMappingSize = Factory::maxMappingSize;
251
252 typedef typename Factory::Mapping Mapping;
253
254 template< class CoordVector >
255 static Mapping*
256 construct ( const unsigned int topologyId, const CoordVector &coords, char *mappingStorage )
257 {
258 return Factory::construct( topologyId, coords, mappingStorage );
259 }
260
261 template< class CoordVector >
262 static Mapping *create ( const unsigned int topologyId, const CoordVector &coords )
263 {
264 Mapping *mapping = static_cast< Mapping * >( operator new( mappingSize( topologyId ) ) );
265 construct( topologyId, coords, mapping );
266 return mapping;
267 }
268
269 static std::size_t mappingSize ( const unsigned int topologyId )
270 {
271 return Factory::mappingSize( topologyId );
272 }
273 };
274
275 } // namespace GenericGeometry
276
277} // namespace Dune
278
279#endif // #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_MAPPINGPROVIDER_HH
#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
Traits for type conversions and type information.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
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 (Nov 12, 23:30, 2024)