shards  Version of the Day
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups
Shards_CellTopologyTraits.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Shards : Shared Discretization Tools
6 // Copyright 2008 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Carter Edwards (hcedwar@sandia.gov),
39 // Pavel Bochev (pbboche@sandia.gov), or
40 // Denis Ridzal (dridzal@sandia.gov).
41 //
42 // ************************************************************************
43 //@HEADER
44 */
45 
46 #ifndef Shards_CellTopologyTraits_hpp
47 #define Shards_CellTopologyTraits_hpp
48 
49 #include <Shards_TypeList.hpp>
50 #include <Shards_IndexList.hpp>
51 #include <Shards_CellTopologyData.h>
52 
53 namespace shards {
54 
62 template< class Traits >
64 
65 template< unsigned Dimension ,
66  unsigned Number_Vertex ,
67  unsigned Number_Node ,
68  class EdgeList = TypeListEnd ,
69  class EdgeMaps = TypeListEnd ,
70  class FaceList = TypeListEnd ,
71  class FaceMaps = TypeListEnd ,
72  class PermutationMaps = TypeListEnd ,
73  class PermutationPolarity = IndexList<> >
75 
76 struct Node ;
77 
78 //----------------------------------------------------------------------
79 //----------------------------------------------------------------------
80 // Implementation details for a much of this file ...
81 
82 #ifndef DOXYGEN_COMPILE
83 
84 template< class CellTop , class CellMap , unsigned Index , bool Good >
85 struct SubcellNodeIndex ;
86 
87 template< class CellTop , class CellMap , unsigned Index >
88 struct SubcellNodeIndex< CellTop , CellMap , Index , false >
89 { enum { value = ~0u }; };
90 
91 template< class CellTop , class CellMap , unsigned Index >
92 struct SubcellNodeIndex< CellTop , CellMap , Index , true >
93 {
94 private:
95  typedef typename CellTop::template subcell<0> subcell_node ;
96 public:
97  enum { value = Index < subcell_node::count
98  ? IndexListAt< CellMap , Index >::value : ~0u };
99 };
100 
101 //----------------------------------------------------------------------
102 
103 template< unsigned SubcellDim , unsigned SubcellOrd , unsigned NodeIndex ,
104  unsigned Dimension , unsigned Number_Vertex , unsigned Number_Node ,
105  class EdgeList , class EdgeMaps ,
106  class FaceList , class FaceMaps ,
107  class PermMaps , class Pol>
108 struct SubcellTopologyTraits ;
109 
110 template< class ListType > struct TypeListHomogeneous ;
111 
112 //----------------------------------------------------------------------
113 // Self-subcell reference
114 
115 template<>
116 struct SubcellTopologyTraits<0,0,0,0,0,0,TypeListEnd,TypeListEnd,
117  TypeListEnd,TypeListEnd,
118  TypeListEnd,IndexList<> >
119 {
120  typedef CellTopologyTraits<0,0,0> topology ;
121  enum { count = 1 };
122  enum { node = ~0u };
123  enum { homogeneity = true };
124 };
125 
126 template< unsigned NodeIndex ,
127  unsigned NV , unsigned NN ,
128  class EList , class EMaps ,
129  class FList , class FMaps ,
130  class PMaps , class Pol>
131 struct SubcellTopologyTraits<1,0,NodeIndex, 1,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
132 {
133  typedef CellTopologyTraits<1,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol> topology ;
134  enum { count = 1 };
135  enum { node = NodeIndex < NN ? NodeIndex : ~0u };
136  enum { homogeneity = true };
137 };
138 
139 template< unsigned NodeIndex ,
140  unsigned NV , unsigned NN ,
141  class EList , class EMaps ,
142  class FList , class FMaps ,
143  class PMaps , class Pol>
144 struct SubcellTopologyTraits<2,0,NodeIndex, 2,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
145 {
146  typedef CellTopologyTraits<2,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol> topology ;
147  enum { count = 1 };
148  enum { node = NodeIndex < NN ? NodeIndex : ~0u };
149  enum { homogeneity = true };
150 };
151 
152 template< unsigned NodeIndex ,
153  unsigned NV , unsigned NN ,
154  class EList , class EMaps ,
155  class FList , class FMaps ,
156  class PMaps , class Pol>
157 struct SubcellTopologyTraits<3,0,NodeIndex, 3,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
158 {
159  typedef CellTopologyTraits<3,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol> topology ;
160  enum { count = 1 };
161  enum { node = NodeIndex < NN ? NodeIndex : ~0u };
162  enum { homogeneity = true };
163 };
164 
165 //----------------------------------------------------------------------
166 // Node-subcell reference:
167 
168 template< unsigned SubcellOrd ,
169  unsigned D , unsigned NV , unsigned NN ,
170  class EList , class EMaps ,
171  class FList , class FMaps ,
172  class PMaps , class Pol>
173 struct SubcellTopologyTraits<0,SubcellOrd,0, D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
174 {
175  typedef CellTopologyTraits<0,0,0> topology ;
176  enum { count = NN };
177  enum { node = SubcellOrd < NN ? SubcellOrd : ~0u };
178  enum { homogeneity = true };
179 };
180 
181 // Edge-subcell reference:
182 
183 template< unsigned SubcellOrd , unsigned NodeIndex ,
184  unsigned D , unsigned NV , unsigned NN ,
185  class EList , class EMaps ,
186  class FList , class FMaps ,
187  class PMaps , class Pol>
188 struct SubcellTopologyTraits<1,SubcellOrd,NodeIndex,
189  D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
190 {
191 private:
192  typedef typename TypeListAt<EMaps,SubcellOrd>::type node_map ;
193 public:
194 
195  typedef typename TypeListAt<EList,SubcellOrd>::type topology ;
196 
197  enum { count = TypeListLength<EList>::value };
198 
199  enum { node = SubcellNodeIndex< topology , node_map , NodeIndex ,
200  SubcellOrd < count >::value };
201 
202  enum { homogeneity = TypeListHomogeneous<EList>::value };
203 };
204 
205 // Face-subcell reference:
206 
207 template< unsigned SubcellOrd , unsigned NodeIndex ,
208  unsigned D , unsigned NV , unsigned NN ,
209  class EList , class EMaps ,
210  class FList , class FMaps ,
211  class PMaps , class Pol>
212 struct SubcellTopologyTraits< 2, SubcellOrd, NodeIndex,
213  D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol >
214 {
215 private:
216  typedef typename TypeListAt<FMaps,SubcellOrd>::type node_map ;
217 public:
218 
219  typedef typename TypeListAt<FList,SubcellOrd>::type topology ;
220 
221  enum { count = TypeListLength<FList>::value };
222 
223  enum { node = SubcellNodeIndex< topology , node_map , NodeIndex ,
224  SubcellOrd < count >::value };
225 
226  enum { homogeneity = TypeListHomogeneous<FList>::value };
227 };
228 
229 //----------------------------------------------------------------------
230 // Only partially specialized subcell references are valid.
231 
232 template< unsigned SubcellDim , unsigned SubcellOrd , unsigned NodeIndex ,
233  unsigned Dimension ,
234  unsigned Number_Vertex , unsigned Number_Node ,
235  class EdgeList , class EdgeMaps ,
236  class FaceList , class FaceMaps ,
237  class PermMaps , class Pol >
238 struct SubcellTopologyTraits
239 {
240  typedef void topology ;
241  enum { count = 0 };
242  enum { node = ~0u };
243  enum { homogeneity = false };
244 };
245 
246 //----------------------------------------------------------------------
247 
248 template<>
249 struct TypeListHomogeneous<TypeListEnd> {
250  enum { value = true };
251 };
252 
253 template< class T >
254 struct TypeListHomogeneous< TypeList<T,TypeListEnd> > {
255  enum { value = true };
256 };
257 
258 template< class T , class Tail >
259 struct TypeListHomogeneous< TypeList< T, TypeList< T , Tail > > > {
260  enum { value = TypeListHomogeneous< TypeList<T,Tail> >::value };
261 };
262 
263 template< class ListType >
264 struct TypeListHomogeneous
265 {
266  enum { value = false };
267 };
268 
269 //----------------------------------------------------------------------
270 
271 template< unsigned I , unsigned J > struct AssertEqual ;
272 
273 template< unsigned I > struct AssertEqual<I,I> { enum { OK = true }; };
274 
275 #endif /* DOXYGEN_COMPILE */
276 
277 //----------------------------------------------------------------------
279 template< unsigned Dimension , unsigned Number_Vertex , unsigned Number_Node ,
280  class EdgeList , class EdgeMaps ,
281  class FaceList , class FaceMaps ,
282  class PermutationMaps ,
283  class PermutationPolarity >
284 struct CellTopologyTraits
285 {
287  typedef CellTopologyTraits< Dimension, Number_Vertex, Number_Node,
288  EdgeList, EdgeMaps, FaceList, FaceMaps,
289  PermutationMaps, PermutationPolarity > Traits ;
290 
291  enum {
293  dimension = Dimension ,
294 
296  vertex_count = Number_Vertex ,
297 
299  node_count = Number_Node ,
300 
303 
304 #ifndef DOXYGEN_COMPILE
305  face_count = TypeListLength<FaceList>::value ,
306 #endif
307 
309  side_count = Dimension == 3 ? face_count : (
310  Dimension == 2 ? edge_count : 0 ),
311 
319  key = ( dimension << 28 /* 4 bits, max 7 */ ) |
320  ( face_count << 22 /* 6 bits, max 63 */ ) |
321  ( edge_count << 16 /* 6 bits, max 63 */ ) |
322  ( vertex_count << 10 /* 6 bits, max 63 */ ) |
323  ( node_count /* 10 bits, max 1023 */ ) };
324 
332  template< unsigned Dim, unsigned Ord = 0, unsigned J = 0 >
333  struct subcell :
334  public SubcellTopologyTraits< Dim , Ord , J ,
335  dimension , vertex_count , node_count ,
336  EdgeList , EdgeMaps ,
337  FaceList , FaceMaps ,
338  PermutationMaps, PermutationPolarity > {};
339 
347  template< unsigned Ord = 0 , unsigned J = 0 >
348  struct side :
349  public SubcellTopologyTraits< ( 1 < dimension ? dimension - 1 : 4 ) ,
350  Ord , J ,
351  dimension , vertex_count , node_count ,
352  EdgeList , EdgeMaps ,
353  FaceList , FaceMaps ,
354  TypeListEnd , IndexList<> > {};
355 
363  template< unsigned Ord = 0 , unsigned J = 0 >
364  struct edge :
365  public SubcellTopologyTraits< ( 1 < dimension ? 1 : 4 ) , Ord , J ,
366  dimension , vertex_count , node_count ,
367  EdgeList , EdgeMaps ,
368  TypeListEnd , TypeListEnd ,
369  TypeListEnd , IndexList<> > {};
370 
371  //--------------------------------------------------------------------
389  template< unsigned Perm , unsigned J = 0 >
390  struct permutation {
391  private:
392  typedef typename TypeListAt< PermutationMaps , Perm >::type node_map ;
393  public:
394  enum { node = J < node_count ? IndexListAt< node_map , J >::value : ~0u };
395  enum { polarity = IndexListAt< PermutationPolarity , Perm >::value };
396  };
397 
398  template< unsigned Perm , unsigned J = 0 >
399  struct permutation_inverse {
400  private:
401  typedef typename TypeListAt< PermutationMaps , Perm >::type forward_map ;
402  typedef typename IndexListInverse< forward_map >::type node_map ;
403  public:
404  enum { node = J < node_count ? IndexListAt< node_map , J >::value : ~0u };
405  enum { polarity = IndexListAt< PermutationPolarity , Perm >::value };
406  };
407 
408  enum { permutation_count = TypeListLength< PermutationMaps >::value };
409 
410  //--------------------------------------------------------------------
411 
412 private:
413 
414 #ifndef DOXYGEN_COMPILE
415 
416  enum { nedge_map = TypeListLength<EdgeMaps>::value ,
417  nface_map = TypeListLength<FaceMaps>::value ,
418  polarity_count = IndexListLength< PermutationPolarity >::value };
419 
420  enum { OK_edge = AssertEqual< edge_count , nedge_map >::OK };
421  enum { OK_face = AssertEqual< face_count , nface_map >::OK };
422  enum { OK_dimen = AssertEqual< 0 , (dimension >> 3) >::OK };
423  enum { OK_faceN = AssertEqual< 0 , (face_count >> 6) >::OK };
424  enum { OK_edgeN = AssertEqual< 0 , (edge_count >> 6) >::OK };
425  enum { OK_vertN = AssertEqual< 0 , (vertex_count >> 6) >::OK };
426  enum { OK_nodeN = AssertEqual< 0 , (node_count >> 10) >::OK };
427  enum { OK_permN = AssertEqual< permutation_count, polarity_count >::OK };
428 
429 #endif
430 
431 };
432 
435 } // namespace shards
436 
437 #endif // Shards_CellTopologyTraits_hpp
438 
Number of edges (a.k.a. Cell^1 subcells).
Number of nodes (a.k.a. Cell^0 subcells).
Member enum { value = ... }; is the length of the type list.
CellTopologyTraits< Dimension, Number_Vertex, Number_Node, EdgeList, EdgeMaps, FaceList, FaceMaps, PermutationMaps, PermutationPolarity > Traits
The self type for the traits.
Compile-time traits for a cell topology.
const CellTopologyData * getCellTopologyData()
Return a CellTopology singleton for the given cell topology traits.
Topological traits: Dimension = 0, Vertices = 0, Nodes = 0.
A simple &#39;C&#39; struct of cell topology attributes.
Number of sides (a.k.a. Cell^(D-1) subcells).