dune-geometry  2.2.0
traceprovider.hh
Go to the documentation of this file.
1 #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_TRACEPROVIDER_HH
2 #define DUNE_GEOMETRY_GENERICGEOMETRY_TRACEPROVIDER_HH
3 
4 #include <dune/common/forloop.hh>
5 #include <dune/common/typetraits.hh>
6 
7 #include "mapping.hh"
8 #include "subtopologies.hh"
9 
10 namespace Dune
11 {
12 
13  namespace GenericGeometry
14  {
15 
16  // External Forward Declarations
17  // -----------------------------
18 
19  template< class Topology, class GeometryTraits >
20  class NonHybridMapping;
21 
22  template< unsigned int dim, class GeometryTraits >
23  class HybridMapping;
24 
25  template< class Topology, class GeometryTraits >
26  class VirtualMapping;
27 
28 
29 
30  // TraceProvider
31  // -------------
32 
33  template< class Topology, class GeometryTraits, unsigned int codim, bool forceHybrid >
35  {
37 
38  typedef typename GeometryTraits::template Mapping< Topology >::type MappingImpl;
39 
40  public:
41  static const unsigned int dimension = Topology::dimension;
42  static const unsigned int codimension = codim;
43  static const unsigned int mydimension = dimension - codimension;
44 
45  static const bool hybrid = (forceHybrid || IsCodimHybrid< Topology, codim >::value);
46 
48 
49  private:
50  static const unsigned int numSubTopologies = Mapping::ReferenceElement::template Codim< codimension >::size;
51 
52  template< bool > class HybridFactory;
53  template< bool > class NonHybridFactory;
54 
55  typedef typename SelectType< hybrid, HybridFactory< true >, NonHybridFactory< false > >::Type Factory;
56 
57  template< int i > struct Builder;
58 
59  public:
60  typedef typename Factory::Trace Trace;
61 
62  static Trace *construct ( const Mapping &mapping, unsigned int i, char *traceStorage )
63  {
64  return (*instance().construct_[ i ])( mapping, traceStorage );
65  }
66 
67  private:
68  typedef Trace *(*Construct) ( const Mapping &mapping, char *traceStorage );
69 
70  TraceProvider ()
71  {
72  ForLoop< Builder, 0, numSubTopologies-1 >::apply( construct_ );
73  }
74 
75  static const This &instance ()
76  {
77  static This theInstance;
78  return theInstance;
79  }
80 
81  Construct construct_[ numSubTopologies ];
82  };
83 
84 
85 
86  // TraceProvider::HybridFactory
87  // ----------------------------
88 
89  template< class Topology, class GeometryTraits, unsigned int codim, bool forceHybrid >
90  template< bool >
91  class TraceProvider< Topology, GeometryTraits, codim, forceHybrid >::HybridFactory
92  {
93  template< unsigned int i >
94  struct VirtualTrace
95  {
98  };
99 
100  public:
102 
103  template< int i >
104  static Trace *construct ( const Mapping &mapping, char *traceStorage )
105  {
106  typedef typename VirtualTrace< i >::type TraceImpl;
107  return new( traceStorage ) TraceImpl( mapping.template trace< codim, i >() );
108  }
109  };
110 
111 
112 
113  // TraceProvider::NonHybridFactory
114  // -------------------------------
115 
116  template< class Topology, class GeometryTraits, unsigned int codim, bool forceHybrid >
117  template< bool >
118  class TraceProvider< Topology, GeometryTraits, codim, forceHybrid >::NonHybridFactory
119  {
121 
122  public:
124 
125  template< int i >
126  static Trace *construct ( const Mapping &mapping, char *traceStorage )
127  {
128  return new( traceStorage ) Trace( mapping.template trace< codim, i >() );
129  }
130  };
131 
132 
133 
134  // TraceProvider::Builder
135  // ----------------------
136 
137  template< class Topology, class GeometryTraits, unsigned int codim, bool forceHybrid >
138  template< int i >
139  struct TraceProvider< Topology, GeometryTraits, codim, forceHybrid >::Builder
140  {
141  static void apply ( Construct (&construct)[ numSubTopologies ] )
142  {
143  construct[ i ] = &(Factory::template construct< i >);
144  }
145  };
146 
147  } // namespace GenericGeometry
148 
149 } // namespace Dune
150 
151 #endif // #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_TRACEPROVIDER_HH