dune-grid  2.2.0
referencetopologies.hh
Go to the documentation of this file.
1 #ifndef DUNE_GENERICGEOMETRY_REFERENCETOPOLOGIES_HH
2 #define DUNE_GENERICGEOMETRY_REFERENCETOPOLOGIES_HH
3 
4 #warning This file is deprecated, and will be removed \
5  after the release of dune-grid-2.2.
6 
7 #include <dune/geometry/genericgeometry/conversion.hh>
8 #include <dune/geometry/genericgeometry/subtopologies.hh>
9 
10 namespace Dune
11 {
12 
13  namespace GenericGeometry
14  {
15 
16  // ReferenceTopology
17  // -----------------
18 
19  template< unsigned int dim >
21  {
23 
24  class SubEntityInfo;
25  template< class Topology > struct Initialize;
26 
27  public:
28  static const unsigned int dimension = dim;
29 
30  unsigned int size ( unsigned int codim ) const
31  {
32  assert( codim <= dimension );
33  return info_[ codim ].size();
34  }
35 
36  unsigned int
37  size ( unsigned int codim, unsigned int i, unsigned int subcodim ) const
38  {
39  assert( (codim <= dimension) && (i < info_[ codim ].size()) );
40  return info_[ codim ][ i ].size( subcodim );
41  }
42 
43  unsigned int subEntity ( unsigned int codim, unsigned int i,
44  unsigned int subcodim, unsigned int j ) const
45  {
46  assert( (codim <= dimension) && (i < info_[ codim ].size()) );
47  return info_[ codim ][ i ].number( subcodim, j );
48  }
49 
50  unsigned int topologyId ( unsigned int codim, unsigned int i ) const
51  {
52  assert( (codim <= dimension) && (i < info_[ codim ].size()) );
53  return info_[ codim ][ i ].topologyId();
54  }
55 
56  template< class Topology >
57  void initialize ()
58  {
59  typedef Initialize< Topology > Init;
60  ForLoop< Init::template Codim, 0, dimension >::apply( info_ );
61  }
62 
63  private:
64  std::vector< SubEntityInfo > info_[ dimension+1 ];
65  };
66 
67 
68 
69  // ReferenceTopology::SubEntityInfo
70  // --------------------------------
71 
72  template< unsigned int dim >
74  {
75  template< class Topology, unsigned int codim > struct Initialize
76  {
77  template< int subcodim > struct SubCodim;
78  };
79 
80  public:
81  unsigned int size ( unsigned int subcodim ) const
82  {
83  return numbering_[ subcodim ].size();
84  }
85 
86  unsigned int number ( unsigned int subcodim, unsigned int j ) const
87  {
88  return numbering_[ subcodim ][ j ];
89  }
90 
91  unsigned int topologyId () const
92  {
93  return topologyId_;
94  }
95 
96  template< class Topology, unsigned int codim, unsigned int i >
97  void initialize ()
98  {
99  typedef Initialize< Topology, codim > Init;
100  typedef typename GenericGeometry::SubTopology< Topology, codim, i >::type SubTopology;
101 
102  codim_ = codim;
103  topologyId_ = SubTopology::id;
104  numbering_.resize( SubTopology::dimension+1 );
105 
106  const unsigned int iVariable = i;
107  ForLoop< Init::template SubCodim, 0, SubTopology::dimension >::apply( iVariable, numbering_ );
108  }
109 
110  private:
111  int codim_;
112  unsigned int topologyId_;
113  std::vector< std::vector< unsigned int > > numbering_;
114  };
115 
116 
117  template< unsigned int dim >
118  template< class Topology, unsigned int codim >
119  template< int subcodim >
120  struct ReferenceTopology< dim >::SubEntityInfo::Initialize< Topology, codim >::SubCodim
121  {
122  typedef SubTopologySize< Topology, codim, subcodim > Size;
123  typedef SubTopologyNumbering< Topology, codim, subcodim > Numbering;
124 
125  static void
126  apply ( unsigned int i, std::vector< std::vector< unsigned int > > &numbering )
127  {
128  const unsigned int size = Size::size( i );
129  numbering[ subcodim ].resize( size );
130  for( unsigned int j = 0; j < size; ++j )
131  numbering[ subcodim ][ j ] = Numbering::number( i, j );
132  }
133  };
134 
135 
136  // ReferenceTopology::Initialize
137  // -----------------------------
138 
139  template< unsigned int dim >
140  template< class Topology >
142  {
143  template< int codim >
144  struct Codim
145  {
146  template< int i >
147  struct SubTopology
148  {
149  static void apply ( std::vector< SubEntityInfo > &info )
150  {
151  info[ i ].template initialize< Topology, codim, i >();
152  }
153  };
154 
155  static void apply ( std::vector< SubEntityInfo > (&info)[ dim+1 ] )
156  {
157  const unsigned int size = Size< Topology, codim >::value;
158  info[ codim ].resize( size );
159  ForLoop< SubTopology, 0, size-1 >::apply( info[ codim ] );
160  }
161  };
162  };
163 
164 
165  // ReferenceTopologyContainer
166  // --------------------------
167 
168  template< unsigned int dim >
170  {
172 
173  template< int topologyId >
174  struct Init;
175 
176  public:
177  static const unsigned int dimension = dim;
178  static const unsigned int numTopologies = (1 << dimension);
179 
181 
182  static const ReferenceTopology &get ( const unsigned int topologyId )
183  {
184  assert( topologyId < numTopologies );
185  return instance().refTopology_[ topologyId ];
186  }
187 
188  private:
190  {
191  ForLoop< Init, 0, numTopologies-1 >::apply( refTopology_ );
192  }
193 
194  ReferenceTopologies ( const This & );
195  This &operator= ( const This & );
196 
197  static const This &instance ()
198  {
199  static This instance;
200  return instance;
201  }
202 
203  ReferenceTopology refTopology_[ numTopologies ];
204  };
205 
206 
207  template< unsigned int dim >
208  template< int topologyId >
209  struct ReferenceTopologies< dim >::Init
210  {
211  static void apply ( ReferenceTopology (&refTopology)[ numTopologies ] )
212  {
213  typedef typename GenericGeometry::Topology< topologyId, dimension >::type Topology;
214  refTopology[ topologyId ].template initialize< Topology >();
215  }
216  };
217 
218  }
219 
220 }
221 
222 #endif // #ifndef DUNE_GENERICGEOMETRY_REFERENCETOPOLOGIES_HH