shards Version of the Day
Loading...
Searching...
No Matches
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
17namespace shards {
18
22
26template< class Traits >
28
29template< 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<> >
38struct CellTopologyTraits ;
39
40struct Node ;
41
42//----------------------------------------------------------------------
43//----------------------------------------------------------------------
44// Implementation details for a much of this file ...
45
46#ifndef DOXYGEN_COMPILE
47
48template< class CellTop , class CellMap , unsigned Index , bool Good >
49struct SubcellNodeIndex ;
50
51template< class CellTop , class CellMap , unsigned Index >
52struct SubcellNodeIndex< CellTop , CellMap , Index , false >
53{ enum { value = ~0u }; };
54
55template< class CellTop , class CellMap , unsigned Index >
56struct SubcellNodeIndex< CellTop , CellMap , Index , true >
57{
58private:
59 typedef typename CellTop::template subcell<0> subcell_node ;
60public:
61 enum { value = Index < subcell_node::count
62 ? IndexListAt< CellMap , Index >::value : ~0u };
63};
64
65//----------------------------------------------------------------------
66
67template< 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>
72struct SubcellTopologyTraits ;
73
74template< class ListType > struct TypeListHomogeneous ;
75
76//----------------------------------------------------------------------
77// Self-subcell reference
78
79// Node
80template<>
81struct 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
92template<>
93struct 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
104template< unsigned NodeIndex ,
105 unsigned NV , unsigned NN ,
106 class EList , class EMaps ,
107 class FList , class FMaps ,
108 class PMaps , class Pol>
109struct 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
118template< unsigned NodeIndex ,
119 unsigned NV , unsigned NN ,
120 class EList , class EMaps ,
121 class FList , class FMaps ,
122 class PMaps , class Pol>
123struct 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
132template< unsigned NodeIndex ,
133 unsigned NV , unsigned NN ,
134 class EList , class EMaps ,
135 class FList , class FMaps ,
136 class PMaps , class Pol>
137struct 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
148template< unsigned SubcellOrd ,
149 unsigned D , unsigned NV , unsigned NN ,
150 class EList , class EMaps ,
151 class FList , class FMaps ,
152 class PMaps , class Pol>
153struct 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
163template< 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>
168struct SubcellTopologyTraits<1,SubcellOrd,NodeIndex,
169 D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
170{
171private:
172 typedef typename TypeListAt<EMaps,SubcellOrd>::type node_map ;
173public:
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
187template< 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>
192struct SubcellTopologyTraits< 2, SubcellOrd, NodeIndex,
193 D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol >
194{
195private:
196 typedef typename TypeListAt<FMaps,SubcellOrd>::type node_map ;
197public:
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
212template< 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 >
218struct SubcellTopologyTraits
219{
220 typedef void topology ;
221 enum { count = 0 };
222 enum { node = ~0u };
223 enum { homogeneity = false };
224};
225
226//----------------------------------------------------------------------
227
228template<>
229struct TypeListHomogeneous<TypeListEnd> {
230 enum { value = true };
231};
232
233template< class T >
234struct TypeListHomogeneous< TypeList<T,TypeListEnd> > {
235 enum { value = true };
236};
237
238template< class T , class Tail >
239struct TypeListHomogeneous< TypeList< T, TypeList< T , Tail > > > {
240 enum { value = TypeListHomogeneous< TypeList<T,Tail> >::value };
241};
242
243template< class ListType >
244struct TypeListHomogeneous
245{
246 enum { value = false };
247};
248
249//----------------------------------------------------------------------
250
251template< unsigned I , unsigned J > struct AssertEqual ;
252
253template< unsigned I > struct AssertEqual<I,I> { enum { OK = true }; };
254
255#endif /* DOXYGEN_COMPILE */
256
257//----------------------------------------------------------------------
259template< unsigned Dimension , unsigned Number_Vertex , unsigned Number_Node ,
260 class EdgeList , class EdgeMaps ,
261 class FaceList , class FaceMaps ,
262 class PermutationMaps ,
263 class PermutationPolarity >
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
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
392private:
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
414
415} // namespace shards
416
417#endif // Shards_CellTopologyTraits_hpp
418
const CellTopologyData * getCellTopologyData()
Return a CellTopology singleton for the given cell topology traits.
A simple 'C' struct of cell topology attributes.
Compile-time traits for a cell topology.
@ node_count
Number of nodes (a.k.a. Cell^0 subcells).
@ edge_count
Number of edges (a.k.a. Cell^1 subcells).
@ side_count
Number of sides (a.k.a. Cell^(D-1) subcells).
@ key
Unique key for this topology.
CellTopologyTraits< Dimension, Number_Vertex, Number_Node, EdgeList, EdgeMaps, FaceList, FaceMaps, PermutationMaps, PermutationPolarity > Traits
The self type for the traits.
Compile-time list of indices.
Topological traits: Dimension = 0, Vertices = 0, Nodes = 0.
Member enum { value = ... }; is the length of the type list.
A link within a linked list of types.