dune-geometry  2.3.1-rc1
mappingprovider.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_MAPPINGPROVIDER_HH
4 #define DUNE_GEOMETRY_GENERICGEOMETRY_MAPPINGPROVIDER_HH
5 
6 #include <dune/common/typetraits.hh>
7 #include <dune/common/visibility.hh>
8 
12 
13 namespace Dune
14 {
15 
16  namespace GenericGeometry
17  {
18 
19  // NonHybridMappingFactory
20  // -----------------------
21 
22  template< class Topology, class GeometryTraits >
24  {
26 
27  public:
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 >
54  {
56 
57  static const unsigned int numTopologies = (1 << dim);
58 
59  template< int topologyId >
60  struct MappingSize
61  {
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:
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  {
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  {
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 >
179 
180 
181  template< unsigned int dim, class GeometryTraits, unsigned int codim >
182  class MappingProvider< HybridMapping< dim, GeometryTraits >, codim >
183  {
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:
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  {
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
static const unsigned int maxMappingSize
Definition: mappingprovider.hh:79
static std::size_t mappingSize(const unsigned int topologyId)
Definition: mappingprovider.hh:269
static Mapping * create(const unsigned int topologyId, const CoordVector &coords)
Definition: mappingprovider.hh:262
Definition: hybridmapping.hh:27
static std::size_t mappingSize(const unsigned int topologyId)
Definition: mappingprovider.hh:215
Definition: mappingprovider.hh:178
conditional< isPrism, Prism< true >, Pyramid< false > >::type::type type
Definition: topologytypes.hh:295
static Mapping * create(const unsigned int topologyId, const CoordVector &coords)
Definition: mappingprovider.hh:209
unsigned int numTopologies(int dim)
obtain the number of topologies of a given dimension
Definition: topologytypes.hh:135
static Mapping * construct(const unsigned int topologyId, const CoordVector &coords, char *mappingStorage)
Definition: mappingprovider.hh:256
abstract base class for generic mapping
Definition: hybridmapping.hh:24
static DUNE_EXPORT Mapping * construct(const unsigned int topologyId, const CoordVector &coords, char *mappingStorage)
Definition: mappingprovider.hh:83
Definition: mappingprovider.hh:23
static void apply(Construct(&construct)[numTopologies])
Definition: mappingprovider.hh:142
static Mapping * construct(const unsigned int topologyId, const CoordVector &coords, char *mappingStorage)
Definition: mappingprovider.hh:203
static std::size_t mappingSize(const unsigned int topologyId)
Definition: mappingprovider.hh:40
HybridMapping< dim, GeometryTraits > Mapping
Definition: mappingprovider.hh:74
non-virtual geometric mapping
Definition: hybridmapping.hh:351
Definition: mappingprovider.hh:53
Definition: maximum.hh:29
static const unsigned int maxMappingSize
Definition: mappingprovider.hh:30
static Mapping * construct(const unsigned int topologyId, const CoordVector &coords, char *mappingStorage)
Definition: mappingprovider.hh:34
NonHybridMapping< Topology, GeometryTraits > Mapping
Definition: mappingprovider.hh:28
Definition: topologytypes.hh:103
Definition: topologytypes.hh:271
static DUNE_EXPORT std::size_t mappingSize(const unsigned int topologyId)
Definition: mappingprovider.hh:89