shards Version of the Day
Loading...
Searching...
No Matches
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
53namespace shards {
54
62template< class Traits >
64
65template< 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<> >
74struct CellTopologyTraits ;
75
76struct Node ;
77
78//----------------------------------------------------------------------
79//----------------------------------------------------------------------
80// Implementation details for a much of this file ...
81
82#ifndef DOXYGEN_COMPILE
83
84template< class CellTop , class CellMap , unsigned Index , bool Good >
85struct SubcellNodeIndex ;
86
87template< class CellTop , class CellMap , unsigned Index >
88struct SubcellNodeIndex< CellTop , CellMap , Index , false >
89{ enum { value = ~0u }; };
90
91template< class CellTop , class CellMap , unsigned Index >
92struct SubcellNodeIndex< CellTop , CellMap , Index , true >
93{
94private:
95 typedef typename CellTop::template subcell<0> subcell_node ;
96public:
97 enum { value = Index < subcell_node::count
98 ? IndexListAt< CellMap , Index >::value : ~0u };
99};
100
101//----------------------------------------------------------------------
102
103template< 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>
108struct SubcellTopologyTraits ;
109
110template< class ListType > struct TypeListHomogeneous ;
111
112//----------------------------------------------------------------------
113// Self-subcell reference
114
115// Node
116template<>
117struct SubcellTopologyTraits<0,0,0,0,0,0,TypeListEnd,TypeListEnd,
118 TypeListEnd,TypeListEnd,
119 TypeListEnd,IndexList<> >
120{
121 typedef CellTopologyTraits<0,0,0> topology ;
122 enum { count = 1 };
123 enum { node = ~0u };
124 enum { homogeneity = true };
125};
126
127// Particle
128template<>
129struct SubcellTopologyTraits<0,0,0,0,1,1,TypeListEnd,TypeListEnd,
130 TypeListEnd,TypeListEnd,
131 TypeListEnd,IndexList<> >
132{
133 typedef CellTopologyTraits<0,1,1> topology ;
134 enum { count = 1 };
135 enum { node = 0 }; // A Particle has 1 node, and NodeIndex (3rd tmpl arg) is 0, so it's valid
136 enum { homogeneity = true };
137};
138
139// Line
140template< unsigned NodeIndex ,
141 unsigned NV , unsigned NN ,
142 class EList , class EMaps ,
143 class FList , class FMaps ,
144 class PMaps , class Pol>
145struct SubcellTopologyTraits<1,0,NodeIndex, 1,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
146{
147 typedef CellTopologyTraits<1,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol> topology ;
148 enum { count = 1 };
149 enum { node = NodeIndex < NN ? NodeIndex : ~0u };
150 enum { homogeneity = true };
151};
152
153// Face
154template< unsigned NodeIndex ,
155 unsigned NV , unsigned NN ,
156 class EList , class EMaps ,
157 class FList , class FMaps ,
158 class PMaps , class Pol>
159struct SubcellTopologyTraits<2,0,NodeIndex, 2,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
160{
161 typedef CellTopologyTraits<2,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol> topology ;
162 enum { count = 1 };
163 enum { node = NodeIndex < NN ? NodeIndex : ~0u };
164 enum { homogeneity = true };
165};
166
167// Volume
168template< unsigned NodeIndex ,
169 unsigned NV , unsigned NN ,
170 class EList , class EMaps ,
171 class FList , class FMaps ,
172 class PMaps , class Pol>
173struct SubcellTopologyTraits<3,0,NodeIndex, 3,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
174{
175 typedef CellTopologyTraits<3,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol> topology ;
176 enum { count = 1 };
177 enum { node = NodeIndex < NN ? NodeIndex : ~0u };
178 enum { homogeneity = true };
179};
180
181//----------------------------------------------------------------------
182// Node-subcell reference:
183
184template< unsigned SubcellOrd ,
185 unsigned D , unsigned NV , unsigned NN ,
186 class EList , class EMaps ,
187 class FList , class FMaps ,
188 class PMaps , class Pol>
189struct SubcellTopologyTraits<0,SubcellOrd,0, D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
190{
191 typedef CellTopologyTraits<0,0,0> topology ;
192 enum { count = NN };
193 enum { node = SubcellOrd < NN ? SubcellOrd : ~0u };
194 enum { homogeneity = true };
195};
196
197// Edge-subcell reference:
198
199template< unsigned SubcellOrd , unsigned NodeIndex ,
200 unsigned D , unsigned NV , unsigned NN ,
201 class EList , class EMaps ,
202 class FList , class FMaps ,
203 class PMaps , class Pol>
204struct SubcellTopologyTraits<1,SubcellOrd,NodeIndex,
205 D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol>
206{
207private:
208 typedef typename TypeListAt<EMaps,SubcellOrd>::type node_map ;
209public:
210
211 typedef typename TypeListAt<EList,SubcellOrd>::type topology ;
212
213 enum { count = TypeListLength<EList>::value };
214
215 enum { node = SubcellNodeIndex< topology , node_map , NodeIndex ,
216 SubcellOrd < count >::value };
217
218 enum { homogeneity = TypeListHomogeneous<EList>::value };
219};
220
221// Face-subcell reference:
222
223template< unsigned SubcellOrd , unsigned NodeIndex ,
224 unsigned D , unsigned NV , unsigned NN ,
225 class EList , class EMaps ,
226 class FList , class FMaps ,
227 class PMaps , class Pol>
228struct SubcellTopologyTraits< 2, SubcellOrd, NodeIndex,
229 D,NV,NN,EList,EMaps,FList,FMaps,PMaps,Pol >
230{
231private:
232 typedef typename TypeListAt<FMaps,SubcellOrd>::type node_map ;
233public:
234
235 typedef typename TypeListAt<FList,SubcellOrd>::type topology ;
236
237 enum { count = TypeListLength<FList>::value };
238
239 enum { node = SubcellNodeIndex< topology , node_map , NodeIndex ,
240 SubcellOrd < count >::value };
241
242 enum { homogeneity = TypeListHomogeneous<FList>::value };
243};
244
245//----------------------------------------------------------------------
246// Only partially specialized subcell references are valid.
247
248template< unsigned SubcellDim , unsigned SubcellOrd , unsigned NodeIndex ,
249 unsigned Dimension ,
250 unsigned Number_Vertex , unsigned Number_Node ,
251 class EdgeList , class EdgeMaps ,
252 class FaceList , class FaceMaps ,
253 class PermMaps , class Pol >
254struct SubcellTopologyTraits
255{
256 typedef void topology ;
257 enum { count = 0 };
258 enum { node = ~0u };
259 enum { homogeneity = false };
260};
261
262//----------------------------------------------------------------------
263
264template<>
265struct TypeListHomogeneous<TypeListEnd> {
266 enum { value = true };
267};
268
269template< class T >
270struct TypeListHomogeneous< TypeList<T,TypeListEnd> > {
271 enum { value = true };
272};
273
274template< class T , class Tail >
275struct TypeListHomogeneous< TypeList< T, TypeList< T , Tail > > > {
276 enum { value = TypeListHomogeneous< TypeList<T,Tail> >::value };
277};
278
279template< class ListType >
280struct TypeListHomogeneous
281{
282 enum { value = false };
283};
284
285//----------------------------------------------------------------------
286
287template< unsigned I , unsigned J > struct AssertEqual ;
288
289template< unsigned I > struct AssertEqual<I,I> { enum { OK = true }; };
290
291#endif /* DOXYGEN_COMPILE */
292
293//----------------------------------------------------------------------
295template< unsigned Dimension , unsigned Number_Vertex , unsigned Number_Node ,
296 class EdgeList , class EdgeMaps ,
297 class FaceList , class FaceMaps ,
298 class PermutationMaps ,
299 class PermutationPolarity >
301{
303 typedef CellTopologyTraits< Dimension, Number_Vertex, Number_Node,
304 EdgeList, EdgeMaps, FaceList, FaceMaps,
305 PermutationMaps, PermutationPolarity > Traits ;
306
307 enum {
309 dimension = Dimension ,
310
312 vertex_count = Number_Vertex ,
313
315 node_count = Number_Node ,
316
319
320#ifndef DOXYGEN_COMPILE
322#endif
323
325 side_count = Dimension == 3 ? face_count : (
326 Dimension == 2 ? edge_count : 0 ),
327
335 key = ( dimension << 28 /* 4 bits, max 7 */ ) |
336 ( face_count << 22 /* 6 bits, max 63 */ ) |
337 ( edge_count << 16 /* 6 bits, max 63 */ ) |
338 ( vertex_count << 10 /* 6 bits, max 63 */ ) |
339 ( node_count /* 10 bits, max 1023 */ ) };
340
348 template< unsigned Dim, unsigned Ord = 0, unsigned J = 0 >
349 struct subcell :
350 public SubcellTopologyTraits< Dim , Ord , J ,
351 dimension , vertex_count , node_count ,
352 EdgeList , EdgeMaps ,
353 FaceList , FaceMaps ,
354 PermutationMaps, PermutationPolarity > {};
355
363 template< unsigned Ord = 0 , unsigned J = 0 >
364 struct side :
365 public SubcellTopologyTraits< ( 1 < dimension ? dimension - 1 : 4 ) ,
366 Ord , J ,
367 dimension , vertex_count , node_count ,
368 EdgeList , EdgeMaps ,
369 FaceList , FaceMaps ,
370 TypeListEnd , IndexList<> > {};
371
379 template< unsigned Ord = 0 , unsigned J = 0 >
380 struct edge :
381 public SubcellTopologyTraits< ( 1 < dimension ? 1 : 4 ) , Ord , J ,
382 dimension , vertex_count , node_count ,
383 EdgeList , EdgeMaps ,
384 TypeListEnd , TypeListEnd ,
385 TypeListEnd , IndexList<> > {};
386
387 //--------------------------------------------------------------------
405 template< unsigned Perm , unsigned J = 0 >
406 struct permutation {
407 private:
408 typedef typename TypeListAt< PermutationMaps , Perm >::type node_map ;
409 public:
410 enum { node = J < node_count ? IndexListAt< node_map , J >::value : ~0u };
411 enum { polarity = IndexListAt< PermutationPolarity , Perm >::value };
412 };
413
414 template< unsigned Perm , unsigned J = 0 >
415 struct permutation_inverse {
416 private:
417 typedef typename TypeListAt< PermutationMaps , Perm >::type forward_map ;
418 typedef typename IndexListInverse< forward_map >::type node_map ;
419 public:
420 enum { node = J < node_count ? IndexListAt< node_map , J >::value : ~0u };
421 enum { polarity = IndexListAt< PermutationPolarity , Perm >::value };
422 };
423
424 enum { permutation_count = TypeListLength< PermutationMaps >::value };
425
426 //--------------------------------------------------------------------
427
428private:
429
430#ifndef DOXYGEN_COMPILE
431
432 enum { nedge_map = TypeListLength<EdgeMaps>::value ,
433 nface_map = TypeListLength<FaceMaps>::value ,
434 polarity_count = IndexListLength< PermutationPolarity >::value };
435
436 enum { OK_edge = AssertEqual< edge_count , nedge_map >::OK };
437 enum { OK_face = AssertEqual< face_count , nface_map >::OK };
438 enum { OK_dimen = AssertEqual< 0 , (dimension >> 3) >::OK };
439 enum { OK_faceN = AssertEqual< 0 , (face_count >> 6) >::OK };
440 enum { OK_edgeN = AssertEqual< 0 , (edge_count >> 6) >::OK };
441 enum { OK_vertN = AssertEqual< 0 , (vertex_count >> 6) >::OK };
442 enum { OK_nodeN = AssertEqual< 0 , (node_count >> 10) >::OK };
443 enum { OK_permN = AssertEqual< permutation_count, polarity_count >::OK };
444
445#endif
446
447};
448
451} // namespace shards
452
453#endif // Shards_CellTopologyTraits_hpp
454
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.
CellTopologyTraits< Dimension, Number_Vertex, Number_Node, EdgeList, EdgeMaps, FaceList, FaceMaps, PermutationMaps, PermutationPolarity > Traits
The self type for the traits.
@ 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.
Compile-time list of indices.
Topological traits: Dimension = 0, Vertices = 0, Nodes = 0.
Member enum { value = ... }; is the length of the type list.