3#ifndef DUNE_GEOMETRY_GENERICGEOMETRY_MAPPINGPROVIDER_HH
4#define DUNE_GEOMETRY_GENERICGEOMETRY_MAPPINGPROVIDER_HH
9#include <dune/geometry/genericgeometry/maximum.hh>
10#include <dune/geometry/genericgeometry/cachedmapping.hh>
11#include <dune/geometry/genericgeometry/hybridmapping.hh>
16 namespace GenericGeometry
22 template<
class Topology,
class GeometryTraits >
23 class NonHybridMappingFactory
25 typedef NonHybridMappingFactory< Topology, GeometryTraits > This;
28 typedef NonHybridMapping< Topology, GeometryTraits > Mapping;
30 static const unsigned int maxMappingSize =
sizeof( Mapping );
32 template<
class CoordVector >
34 construct (
const unsigned int topologyId,
const CoordVector &coords,
char *mappingStorage )
36 assert( (topologyId >> 1) == (Topology::id >> 1) );
37 return new( mappingStorage ) Mapping( coords );
40 static std::size_t mappingSize (
const unsigned int topologyId )
43 return sizeof( Mapping );
52 template<
unsigned int dim,
class GeometryTraits >
53 class VirtualMappingFactory
55 typedef VirtualMappingFactory< dim, GeometryTraits > This;
57 static const unsigned int numTopologies = (1 << dim);
59 template<
int topologyId >
62 typedef typename GenericGeometry::Topology< (
unsigned int) topologyId, dim >::type Topology;
63 static const int v =
sizeof( VirtualMapping< Topology, GeometryTraits > );
65 static void apply ( std::size_t (&mappingSize)[ numTopologies ] )
67 mappingSize[ topologyId ] = v;
71 template<
class CoordVector >
72 class ConstructorTable;
74 struct MappingSizeCache;
77 typedef HybridMapping< dim, GeometryTraits > Mapping;
79 static const unsigned int maxMappingSize = Maximum< MappingSize, 0, ((numTopologies > 0) ? (numTopologies-1) : 0) >::v;
81 template<
class CoordVector >
83 construct (
const unsigned int topologyId,
const CoordVector &coords,
char *mappingStorage )
85 static ConstructorTable< CoordVector > construct;
86 return construct[ topologyId ]( coords, mappingStorage );
89 DUNE_EXPORT static std::size_t mappingSize (
const unsigned int topologyId )
91 static MappingSizeCache mappingSize;
92 return mappingSize[ topologyId ];
100 template<
unsigned int dim,
class GeometryTraits >
101 template<
class CoordVector >
102 class VirtualMappingFactory< dim, GeometryTraits >::ConstructorTable
104 typedef Mapping* (*Construct)(
const CoordVector &coords,
char *mappingStorage );
112 ForLoop< Builder, 0, numTopologies-1 >::apply( construct_ );
115 Construct operator[] (
const unsigned int topologyId )
117 assert( topologyId < numTopologies );
118 return construct_[ topologyId ];
122 template<
class Topology >
124 construct (
const CoordVector &coords,
char *mappingStorage )
126 typedef VirtualMapping< Topology, GeometryTraits > VMapping;
127 return new( mappingStorage ) VMapping( coords );
130 Construct construct_[ numTopologies ];
137 template<
unsigned int dim,
class GeometryTraits >
138 template<
class CoordVector >
139 template<
int topologyId >
140 struct VirtualMappingFactory< dim, GeometryTraits >::ConstructorTable< CoordVector >::Builder
142 static void apply ( Construct (&construct)[ numTopologies ] )
144 typedef typename GenericGeometry::Topology< (
unsigned int) topologyId, dim >::type Topology;
145 construct[ topologyId ] = ConstructorTable< CoordVector >::template construct< Topology >;
154 template<
unsigned int dim,
class GeometryTraits >
155 struct VirtualMappingFactory< dim, GeometryTraits >::MappingSizeCache
159 ForLoop< MappingSize, 0, numTopologies-1 >::apply( size_ );
162 std::size_t operator[] (
const unsigned int topologyId )
164 assert( topologyId < numTopologies );
165 return size_[ topologyId ];
169 std::size_t size_[ numTopologies ];
177 template<
class ElementMapping,
unsigned int codim >
178 class MappingProvider;
181 template<
unsigned int dim,
class GeometryTraits,
unsigned int codim >
182 class MappingProvider< HybridMapping< dim, GeometryTraits >, codim >
184 typedef MappingProvider< HybridMapping< dim, GeometryTraits >, codim > This;
188 static const unsigned int dimension = dim;
189 static const unsigned int codimension = codim;
190 static const unsigned int mydimension = dimension - codimension;
193 typedef VirtualMappingFactory< mydimension, GeometryTraits > Factory;
197 static const unsigned int maxMappingSize = Factory::maxMappingSize;
199 typedef typename Factory::Mapping Mapping;
201 template<
class CoordVector >
203 construct (
const unsigned int topologyId,
const CoordVector &coords,
char *mappingStorage )
205 return Factory::construct( topologyId, coords, mappingStorage );
208 template<
class CoordVector >
209 static Mapping *create (
const unsigned int topologyId,
const CoordVector &coords )
211 char *mapping =
new char[ mappingSize( topologyId ) ];
212 return construct( topologyId, coords, mapping );
215 static std::size_t mappingSize (
const unsigned int topologyId )
217 return Factory::mappingSize( topologyId );
222 template<
class Topology,
class GeometryTraits,
unsigned int codim >
223 class MappingProvider< NonHybridMapping< Topology, GeometryTraits >, codim >
225 typedef MappingProvider< NonHybridMapping< Topology, GeometryTraits >, codim > This;
228 static const unsigned int dimension = Topology::dimension;
229 static const unsigned int codimension = codim;
230 static const unsigned int mydimension = dimension - codimension;
232 static const bool hybrid = (mydimension != dimension) && IsHybrid< Topology >::value;
237 :
public VirtualMappingFactory< mydimension, GeometryTraits >
241 struct NonHybridFactory
242 :
public NonHybridMappingFactory
243 < typename SubTopology< Topology, codim, 0 >::type, GeometryTraits >
246 typedef typename conditional< hybrid, HybridFactory<true>, NonHybridFactory<false> >::type Factory;
250 static const unsigned int maxMappingSize = Factory::maxMappingSize;
252 typedef typename Factory::Mapping Mapping;
254 template<
class CoordVector >
256 construct (
const unsigned int topologyId,
const CoordVector &coords,
char *mappingStorage )
258 return Factory::construct( topologyId, coords, mappingStorage );
261 template<
class CoordVector >
262 static Mapping *create (
const unsigned int topologyId,
const CoordVector &coords )
264 Mapping *mapping =
static_cast< Mapping *
>(
operator new( mappingSize( topologyId ) ) );
265 construct( topologyId, coords, mapping );
269 static std::size_t mappingSize (
const unsigned int topologyId )
271 return Factory::mappingSize( topologyId );
#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