DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ElementTraits.hpp
Go to the documentation of this file.
1#pragma once
2// ElementTraits.hpp -- Per-element-type trait structs with static dispatch.
3//
4// This is the HUB header that includes all element trait definitions.
5// Each element type's traits are defined in a separate file under Elements/:
6// - Line2, Line3 -> Elements/Line2.hpp, Elements/Line3.hpp
7// - Tri3, Tri6 -> Elements/Tri3.hpp, Elements/Tri6.hpp
8// - Quad4, Quad9 -> Elements/Quad4.hpp, Elements/Quad9.hpp
9// - Tet4, Tet10 -> Elements/Tet4.hpp, Elements/Tet10.hpp
10// - Hex8, Hex27 -> Elements/Hex8.hpp, Elements/Hex27.hpp
11// - Prism6, Prism18 -> Elements/Prism6.hpp, Elements/Prism18.hpp
12// - Pyramid5, Pyramid14 -> Elements/Pyramid5.hpp, Elements/Pyramid14.hpp
13//
14// To add a new element type:
15// 1. Add its enum value to ElemType in ElemEnum.hpp
16// 2. Create an ElementTraits specialization in Elements/<Elem>.hpp
17// 3. Add its case to DispatchElementType() below
18// 4. Add its shape function definition in tools/gen_shape_functions/
19
20#include "ElementTraitsBase.hpp"
21
22// Include all element trait specializations
23// Note: These files contain both ShapeFuncImpl (generated) and ElementTraits (manual)
24#include "Elements/Line2.hpp"
25#include "Elements/Line3.hpp"
26#include "Elements/Tri3.hpp"
27#include "Elements/Tri6.hpp"
28#include "Elements/Quad4.hpp"
29#include "Elements/Quad9.hpp"
30#include "Elements/Tet4.hpp"
31#include "Elements/Tet10.hpp"
32#include "Elements/Hex8.hpp"
33#include "Elements/Hex27.hpp"
34#include "Elements/Prism6.hpp"
35#include "Elements/Prism18.hpp"
36#include "Elements/Pyramid5.hpp"
38
39namespace DNDS::Geom::Elem
40{
41
42 // ----------------------------------------------------------------
43 // ParamSpace-level information (not per-element, per-space)
44 // ----------------------------------------------------------------
45
46 /**
47 * @brief Get the volume of a parametric space
48 * @param ps Parametric space type
49 * @return Volume (length for 1D, area for 2D, volume for 3D)
50 *
51 * Returns the "size" of the reference element in parametric coordinates:
52 * - LineSpace: 2.0 (length from -1 to +1)
53 * - TriSpace: 0.5 (area of reference triangle)
54 * - QuadSpace: 4.0 (area of [-1,1] x [-1,1])
55 * - TetSpace: 1/6 (volume of reference tet)
56 * - HexSpace: 8.0 (volume of [-1,1]^3)
57 * - PrismSpace: 1.0 (volume of reference prism)
58 * - PyramidSpace: 4/3 (volume of reference pyramid)
59 */
61 {
62 switch (ps)
63 {
64 case LineSpace: return 2.0;
65 case TriSpace: return 0.5;
66 case QuadSpace: return 4.0;
67 case TetSpace: return 1.0 / 6.0;
68 case HexSpace: return 8.0;
69 case PrismSpace: return 1.0;
70 case PyramidSpace: return 4.0 / 3.0;
71 default: return 0.0;
72 }
73 }
74
75 /**
76 * @brief Get the order-1 (linear) element type for a parametric space
77 * @param ps Parametric space type
78 * @return Element type enum (Line2, Tri3, Quad4, etc.)
79 *
80 * Maps each parametric space to its corresponding linear element:
81 * - LineSpace -> Line2
82 * - TriSpace -> Tri3
83 * - QuadSpace -> Quad4
84 * - TetSpace -> Tet4
85 * - HexSpace -> Hex8
86 * - PrismSpace -> Prism6
87 * - PyramidSpace -> Pyramid5
88 */
90 {
91 switch (ps)
92 {
93 case LineSpace: return Line2;
94 case TriSpace: return Tri3;
95 case QuadSpace: return Quad4;
96 case TetSpace: return Tet4;
97 case HexSpace: return Hex8;
98 case PrismSpace: return Prism6;
99 case PyramidSpace: return Pyramid5;
100 default: return UnknownElem;
101 }
102 }
103
104 // ----------------------------------------------------------------
105 // Compile-time dispatch: invoke a callable with ElementTraits<t>
106 // ----------------------------------------------------------------
107
108 /**
109 * @brief Static dispatch over element types at compile time
110 * @tparam Func Callable type
111 * @param t Element type enum
112 * @param func Callable to invoke with ElementTraits<t>
113 * @return Return value of func(ElementTraits<t>{})
114 *
115 * Usage:
116 * auto numNodes = DispatchElementType(elemType, [](auto traits) {
117 * return traits.numNodes;
118 * });
119 */
120 template <typename Func>
121 DNDS_DEVICE_CALLABLE constexpr decltype(auto) DispatchElementType(ElemType t, Func &&func)
122 {
123 switch (t)
124 {
125 case Line2:
126 return func(ElementTraits<Line2>{});
127 case Line3:
128 return func(ElementTraits<Line3>{});
129 case Tri3:
130 return func(ElementTraits<Tri3>{});
131 case Tri6:
132 return func(ElementTraits<Tri6>{});
133 case Quad4:
134 return func(ElementTraits<Quad4>{});
135 case Quad9:
136 return func(ElementTraits<Quad9>{});
137 case Tet4:
138 return func(ElementTraits<Tet4>{});
139 case Tet10:
140 return func(ElementTraits<Tet10>{});
141 case Hex8:
142 return func(ElementTraits<Hex8>{});
143 case Hex27:
144 return func(ElementTraits<Hex27>{});
145 case Prism6:
146 return func(ElementTraits<Prism6>{});
147 case Prism18:
148 return func(ElementTraits<Prism18>{});
149 case Pyramid5:
150 return func(ElementTraits<Pyramid5>{});
151 case Pyramid14:
152 return func(ElementTraits<Pyramid14>{});
153 default:
154 DNDS_assert(false);
155 return func(ElementTraits<Line2>{}); // unreachable, satisfies return type
156 }
157 }
158
159} // namespace DNDS::Geom::Elem
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Definition Errors.hpp:108
DNDS_DEVICE_CALLABLE constexpr decltype(auto) DispatchElementType(ElemType t, Func &&func)
Static dispatch over element types at compile time.
DNDS_DEVICE_CALLABLE constexpr t_real ParamSpaceVolume(ParamSpace ps)
Get the volume of a parametric space.
DNDS_DEVICE_CALLABLE constexpr ElemType ParamSpaceO1Elem(ParamSpace ps)
Get the order-1 (linear) element type for a parametric space.
double t_real
Definition Geometric.hpp:8