shards  Version of the Day
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups
Shards_CellTopologyTraits.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Shards : Shared Discretization Tools
4 //
5 // Copyright 2008-2011 NTESS and the Shards contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef Shards_CellTopologyTraits_hpp
11 #define Shards_CellTopologyTraits_hpp
12 
13 #include <Shards_TypeList.hpp>
14 #include <Shards_IndexList.hpp>
15 #include <Shards_CellTopologyData.h>
16 
17 namespace shards {
18 
26 template< class Traits >
28 
29 template< unsigned Dimension ,
30  unsigned Number_Vertex ,
31  unsigned Number_Node ,
32  class EdgeList = TypeListEnd ,
33  class EdgeMaps = TypeListEnd ,
34  class FaceList = TypeListEnd ,
35  class FaceMaps = TypeListEnd ,
36  class PermutationMaps = TypeListEnd ,
37  class PermutationPolarity = IndexList<> >
39 
40 struct Node ;
41 
42 //----------------------------------------------------------------------
43 //----------------------------------------------------------------------
44 // Implementation details for a much of this file ...
45 
46 #ifndef DOXYGEN_COMPILE
47 
48 template< class CellTop , class CellMap , unsigned Index , bool Good >
49 struct SubcellNodeIndex ;
50 
51 template< class CellTop , class CellMap , unsigned Index >
52 struct SubcellNodeIndex< CellTop , CellMap , Index , false >
53 { enum { value = ~0u }; };
54 
55 template< class CellTop , class CellMap , unsigned Index >
56 struct SubcellNodeIndex< CellTop , CellMap , Index , true >
57 {
58 private:
59  typedef typename CellTop::template subcell<0> subcell_node ;
60 public:
61  enum { value = Index < subcell_node::count
62  ? IndexListAt< CellMap , Index >::value : ~0u };
63 };
64 
65 //----------------------------------------------------------------------
66 
67 template< unsigned SubcellDim , unsigned SubcellOrd , unsigned NodeIndex ,
68  unsigned Dimension , unsigned Number_Vertex , unsigned Number_Node ,
69  class EdgeList , class EdgeMaps ,
70  class FaceList , class FaceMaps ,
71  class PermMaps , class Pol>
72 struct SubcellTopologyTraits ;
73 
74 template< class ListType > struct TypeListHomogeneous ;
75 
76 //----------------------------------------------------------------------
77 // Self-subcell reference
78 
79 // Node
80 template<>
81 struct SubcellTopologyTraits<0,0,0,0,0,0,TypeListEnd,TypeListEnd,
82  TypeListEnd,TypeListEnd,
83  TypeListEnd,IndexList<> >
84 {
85  typedef CellTopologyTraits<0,0,0> topology ;
86  enum { count = 1 };
87  enum { node = ~0u };
88  enum { homogeneity = true };
89 };
90 
91 // Particle
92 template<>
93 struct SubcellTopologyTraits<0,0,0,0,1,1,TypeListEnd,TypeListEnd,
94  TypeListEnd,TypeListEnd,
95  TypeListEnd,IndexList<> >
96 {
97  typedef CellTopologyTraits<0,1,1> topology ;
98  enum { count = 1 };
99  enum { node = 0 }; // A Particle has 1 node, and NodeIndex (3rd tmpl arg) is 0, so it's valid
100  enum { homogeneity = true };
101 };
102 
103 // Line
104 template< unsigned NodeIndex ,
105  unsigned NV , unsigned NN ,
106  class EList , class EMaps ,
107  class FList , class FMaps ,
108  class PMaps , class Pol>
109 struct SubcellTopologyTraits<1,0,NodeIndex, 1,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
110 {
111  typedef CellTopologyTraits<1,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol> topology ;
112  enum { count = 1 };
113  enum { node = NodeIndex < NN ? NodeIndex : ~0u };
114  enum { homogeneity = true };
115 };
116 
117 // Face
118 template< unsigned NodeIndex ,
119  unsigned NV , unsigned NN ,
120  class EList , class EMaps ,
121  class FList , class FMaps ,
122  class PMaps , class Pol>
123 struct SubcellTopologyTraits<2,0,NodeIndex, 2,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
124 {
125  typedef CellTopologyTraits<2,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol> topology ;
126  enum { count = 1 };
127  enum { node = NodeIndex < NN ? NodeIndex : ~0u };
128  enum { homogeneity = true };
129 };
130 
131 // Volume
132 template< unsigned NodeIndex ,
133  unsigned NV , unsigned NN ,
134  class EList , class EMaps ,
135  class FList , class FMaps ,
136  class PMaps , class Pol>
137 struct SubcellTopologyTraits<3,0,NodeIndex, 3,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
138 {
139  typedef CellTopologyTraits<3,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol> topology ;
140  enum { count = 1 };
141  enum { node = NodeIndex < NN ? NodeIndex : ~0u };
142  enum { homogeneity = true };
143 };
144 
145 //----------------------------------------------------------------------
146 // Node-subcell reference:
147 
148 template< unsigned SubcellOrd ,
149  unsigned D , unsigned NV , unsigned NN ,
150  class EList , class EMaps ,
151  class FList , class FMaps ,
152  class PMaps , class Pol>
153 struct SubcellTopologyTraits<0,SubcellOrd,0, D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
154 {
155  typedef CellTopologyTraits<0,0,0> topology ;
156  enum { count = NN };
157  enum { node = SubcellOrd < NN ? SubcellOrd : ~0u };
158  enum { homogeneity = true };
159 };
160 
161 // Edge-subcell reference:
162 
163 template< unsigned SubcellOrd , unsigned NodeIndex ,
164  unsigned D , unsigned NV , unsigned NN ,
165  class EList , class EMaps ,
166  class FList , class FMaps ,
167  class PMaps , class Pol>
168 struct SubcellTopologyTraits<1,SubcellOrd,NodeIndex,
169  D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
170 {
171 private:
172  typedef typename TypeListAt<EMaps,SubcellOrd>::type node_map ;
173 public:
174 
175  typedef typename TypeListAt<EList,SubcellOrd>::type topology ;
176 
177  enum { count = TypeListLength<EList>::value };
178 
179  enum { node = SubcellNodeIndex< topology , node_map , NodeIndex ,
180  SubcellOrd < count >::value };
181 
182  enum { homogeneity = TypeListHomogeneous<EList>::value };
183 };
184 
185 // Face-subcell reference:
186 
187 template< unsigned SubcellOrd , unsigned NodeIndex ,
188  unsigned D , unsigned NV , unsigned NN ,
189  class EList , class EMaps ,
190  class FList , class FMaps ,
191  class PMaps , class Pol>
192 struct SubcellTopologyTraits< 2, SubcellOrd, NodeIndex,
193  D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol >
194 {
195 private:
196  typedef typename TypeListAt<FMaps,SubcellOrd>::type node_map ;
197 public:
198 
199  typedef typename TypeListAt<FList,SubcellOrd>::type topology ;
200 
201  enum { count = TypeListLength<FList>::value };
202 
203  enum { node = SubcellNodeIndex< topology , node_map , NodeIndex ,
204  SubcellOrd < count >::value };
205 
206  enum { homogeneity = TypeListHomogeneous<FList>::value };
207 };
208 
209 //----------------------------------------------------------------------
210 // Only partially specialized subcell references are valid.
211 
212 template< unsigned SubcellDim , unsigned SubcellOrd , unsigned NodeIndex ,
213  unsigned Dimension ,
214  unsigned Number_Vertex , unsigned Number_Node ,
215  class EdgeList , class EdgeMaps ,
216  class FaceList , class FaceMaps ,
217  class PermMaps , class Pol >
218 struct SubcellTopologyTraits
219 {
220  typedef void topology ;
221  enum { count = 0 };
222  enum { node = ~0u };
223  enum { homogeneity = false };
224 };
225 
226 //----------------------------------------------------------------------
227 
228 template<>
229 struct TypeListHomogeneous<TypeListEnd> {
230  enum { value = true };
231 };
232 
233 template< class T >
234 struct TypeListHomogeneous< TypeList<T,TypeListEnd> > {
235  enum { value = true };
236 };
237 
238 template< class T , class Tail >
239 struct TypeListHomogeneous< TypeList< T, TypeList< T , Tail > > > {
240  enum { value = TypeListHomogeneous< TypeList<T,Tail> >::value };
241 };
242 
243 template< class ListType >
244 struct TypeListHomogeneous
245 {
246  enum { value = false };
247 };
248 
249 //----------------------------------------------------------------------
250 
251 template< unsigned I , unsigned J > struct AssertEqual ;
252 
253 template< unsigned I > struct AssertEqual<I,I> { enum { OK = true }; };
254 
255 #endif /* DOXYGEN_COMPILE */
256 
257 //----------------------------------------------------------------------
259 template< unsigned Dimension , unsigned Number_Vertex , unsigned Number_Node ,
260  class EdgeList , class EdgeMaps ,
261  class FaceList , class FaceMaps ,
262  class PermutationMaps ,
263  class PermutationPolarity >
264 struct CellTopologyTraits
265 {
267  typedef CellTopologyTraits< Dimension, Number_Vertex, Number_Node,
268  EdgeList, EdgeMaps, FaceList, FaceMaps,
269  PermutationMaps, PermutationPolarity > Traits ;
270 
271  enum {
273  dimension = Dimension ,
274 
276  vertex_count = Number_Vertex ,
277 
279  node_count = Number_Node ,
280 
283 
284 #ifndef DOXYGEN_COMPILE
285  face_count = TypeListLength<FaceList>::value ,
286 #endif
287 
289  side_count = Dimension == 3 ? face_count : (
290  Dimension == 2 ? edge_count : 0 ),
291 
299  key = ( dimension << 28 /* 4 bits, max 7 */ ) |
300  ( face_count << 22 /* 6 bits, max 63 */ ) |
301  ( edge_count << 16 /* 6 bits, max 63 */ ) |
302  ( vertex_count << 10 /* 6 bits, max 63 */ ) |
303  ( node_count /* 10 bits, max 1023 */ ) };
304 
312  template< unsigned Dim, unsigned Ord = 0, unsigned J = 0 >
313  struct subcell :
314  public SubcellTopologyTraits< Dim , Ord , J ,
315  dimension , vertex_count , node_count ,
316  EdgeList , EdgeMaps ,
317  FaceList , FaceMaps ,
318  PermutationMaps, PermutationPolarity > {};
319 
327  template< unsigned Ord = 0 , unsigned J = 0 >
328  struct side :
329  public SubcellTopologyTraits< ( 1 < dimension ? dimension - 1 : 4 ) ,
330  Ord , J ,
331  dimension , vertex_count , node_count ,
332  EdgeList , EdgeMaps ,
333  FaceList , FaceMaps ,
334  TypeListEnd , IndexList<> > {};
335 
343  template< unsigned Ord = 0 , unsigned J = 0 >
344  struct edge :
345  public SubcellTopologyTraits< ( 1 < dimension ? 1 : 4 ) , Ord , J ,
346  dimension , vertex_count , node_count ,
347  EdgeList , EdgeMaps ,
348  TypeListEnd , TypeListEnd ,
349  TypeListEnd , IndexList<> > {};
350 
351  //--------------------------------------------------------------------
369  template< unsigned Perm , unsigned J = 0 >
370  struct permutation {
371  private:
372  typedef typename TypeListAt< PermutationMaps , Perm >::type node_map ;
373  public:
374  enum { node = J < node_count ? IndexListAt< node_map , J >::value : ~0u };
375  enum { polarity = IndexListAt< PermutationPolarity , Perm >::value };
376  };
377 
378  template< unsigned Perm , unsigned J = 0 >
379  struct permutation_inverse {
380  private:
381  typedef typename TypeListAt< PermutationMaps , Perm >::type forward_map ;
382  typedef typename IndexListInverse< forward_map >::type node_map ;
383  public:
384  enum { node = J < node_count ? IndexListAt< node_map , J >::value : ~0u };
385  enum { polarity = IndexListAt< PermutationPolarity , Perm >::value };
386  };
387 
388  enum { permutation_count = TypeListLength< PermutationMaps >::value };
389 
390  //--------------------------------------------------------------------
391 
392 private:
393 
394 #ifndef DOXYGEN_COMPILE
395 
396  enum { nedge_map = TypeListLength<EdgeMaps>::value ,
397  nface_map = TypeListLength<FaceMaps>::value ,
398  polarity_count = IndexListLength< PermutationPolarity >::value };
399 
400  enum { OK_edge = AssertEqual< edge_count , nedge_map >::OK };
401  enum { OK_face = AssertEqual< face_count , nface_map >::OK };
402  enum { OK_dimen = AssertEqual< 0 , (dimension >> 3) >::OK };
403  enum { OK_faceN = AssertEqual< 0 , (face_count >> 6) >::OK };
404  enum { OK_edgeN = AssertEqual< 0 , (edge_count >> 6) >::OK };
405  enum { OK_vertN = AssertEqual< 0 , (vertex_count >> 6) >::OK };
406  enum { OK_nodeN = AssertEqual< 0 , (node_count >> 10) >::OK };
407  enum { OK_permN = AssertEqual< permutation_count, polarity_count >::OK };
408 
409 #endif
410 
411 };
412 
415 } // namespace shards
416 
417 #endif // Shards_CellTopologyTraits_hpp
418 
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).