MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
pa.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_TMOP_PA_HPP
13#define MFEM_TMOP_PA_HPP
14
17
18namespace mfem
19{
20
21/// Abstract base class for the 2D metric TMOP PA kernels.
23{
24 static constexpr int DIM = 2;
26
27 virtual MFEM_HOST_DEVICE real_t EvalW(const real_t (&Jpt)[DIM * DIM],
28 const real_t *w) const
29 {
30 MFEM_ABORT_KERNEL("TMOP_PA_Metric_2D::EvalW is not implemented");
31 return -0.0_r;
32 }
33
34 virtual MFEM_HOST_DEVICE void EvalP(const real_t (&Jpt)[DIM * DIM],
35 const real_t *w,
36 real_t (&P)[DIM * DIM]) const
37 {
38 MFEM_ABORT_KERNEL("TMOP_PA_Metric_2D::EvalP is not implemented");
39 }
40
41 virtual MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy,
42 const int e, const real_t weight,
43 const real_t (&Jpt)[DIM * DIM],
44 const real_t *w,
45 const DeviceTensor<7> &H) const
46 {
47 MFEM_ABORT_KERNEL("TMOP_PA_Metric_2D::AssembleH is not implemented");
48 }
49};
50
51/// Abstract base class for the 3D metric TMOP PA kernels.
53{
54 static constexpr int DIM = 3;
56
57 virtual MFEM_HOST_DEVICE real_t EvalW(const real_t (&Jpt)[DIM * DIM],
58 const real_t *w) const
59 {
60 MFEM_ABORT_KERNEL("TMOP_PA_Metric_3D::EvalW is not implemented");
61 return -0.0_r;
62 }
63
64 virtual MFEM_HOST_DEVICE void EvalP(const real_t (&Jpt)[DIM * DIM],
65 const real_t *w,
66 real_t (&P)[DIM * DIM]) const
67 {
68 MFEM_ABORT_KERNEL("TMOP_PA_Metric_3D::EvalP is not implemented");
69 }
70
71 virtual MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy,
72 const int qz, const int e, const real_t weight,
73 real_t *Jrt, real_t *Jpr,
74 const real_t (&Jpt)[DIM * DIM],
75 const real_t *w,
76 const DeviceTensor<5 + DIM> &H) const
77 {
78 MFEM_ABORT_KERNEL("TMOP_PA_Metric_3D::AssembleH is not implemented");
79 }
80};
81
82namespace tmop
83{
84
85template <typename T>
86using TMOPFunction = void (*)(T &);
87
88template <int Metric, typename Ker>
89void Kernel(Ker &);
90
91// Register TMOP kernels using max values and two templated parameters (MDQ).
92// MD1, MQ1 = max D1D/Q1D sizes; T_D1D, T_Q1D = the templated D1D/Q1D variants.
93// The Fallback version uses max values.
94// These kernels are independent of the metric id.
95#define MFEM_TMOP_MDQ_REGISTER(Name, Ker) \
96 using Ker##_t = decltype(&Ker<1,1,1,1>); \
97 MFEM_REGISTER_KERNELS(Name, Ker##_t, (int, int)); \
98 template <int D, int Q> \
99 Ker##_t Name::Kernel() { return Ker<D,Q, D,Q>; } \
100 Ker##_t Name::Fallback(int, int) { \
101 return Ker<DofQuadLimits::MAX_D1D, \
102 DofQuadLimits::MAX_Q1D>; }
103// MDQ kernel specializations (fallback versions used otherwise).
104template <typename Kernel>
106{
107 Kernel::template Specialization<2, 2>::Add();
108 Kernel::template Specialization<2, 3>::Add();
109 Kernel::template Specialization<2, 4>::Add();
110 Kernel::template Specialization<2, 5>::Add();
111 Kernel::template Specialization<2, 6>::Add();
112
113 Kernel::template Specialization<3, 3>::Add();
114 Kernel::template Specialization<3, 4>::Add();
115 Kernel::template Specialization<3, 5>::Add();
116 Kernel::template Specialization<3, 6>::Add();
117
118 Kernel::template Specialization<4, 4>::Add();
119 Kernel::template Specialization<4, 5>::Add();
120 Kernel::template Specialization<4, 6>::Add();
121
122 Kernel::template Specialization<5, 5>::Add();
123 Kernel::template Specialization<5, 6>::Add();
124 Kernel::template Specialization<6, 6>::Add();
125 return 0;
126}
127#define MFEM_TMOP_MDQ_SPECIALIZE(Name) \
128 namespace \
129 { \
130 [[maybe_unused]] static bool k##Name{ (tmop::KernelSpecializationsMDQ<Name>(), true) }; \
131 }
132
133// Register TMOP kernels using two templated parameters (D1D, Q1D).
134// The Fallback version uses no arguments (default values).
135// These kernels are independent of the metric id.
136#define MFEM_TMOP_REGISTER_KERNELS(Name, Ker) \
137 using Ker##_t = decltype(&Ker<>); \
138 MFEM_REGISTER_KERNELS(Name, Ker##_t, (int, int)); \
139 template <int D, int Q> \
140 Ker##_t Name::Kernel() { return Ker<D, Q>; } \
141 Ker##_t Name::Fallback(int, int) { return Ker<>; }
142// Kernel specializations for the above (fallback versions used otherwise).
143template <typename Kernel>
145{
146 Kernel::template Specialization<2, 2>::Add();
147 Kernel::template Specialization<2, 3>::Add();
148 Kernel::template Specialization<2, 4>::Add();
149 Kernel::template Specialization<2, 5>::Add();
150 Kernel::template Specialization<2, 6>::Add();
151
152 Kernel::template Specialization<3, 3>::Add();
153 Kernel::template Specialization<3, 4>::Add();
154 Kernel::template Specialization<3, 5>::Add();
155 Kernel::template Specialization<3, 6>::Add();
156
157 Kernel::template Specialization<4, 4>::Add();
158 Kernel::template Specialization<4, 5>::Add();
159 Kernel::template Specialization<4, 6>::Add();
160
161 Kernel::template Specialization<5, 5>::Add();
162 Kernel::template Specialization<5, 6>::Add();
163 Kernel::template Specialization<6, 6>::Add();
164 return 0;
165}
166#define MFEM_TMOP_ADD_SPECIALIZED_KERNELS(Name) \
167 namespace \
168 { \
169 [[maybe_unused]] static bool k##Name{ (tmop::KernelSpecializations<Name>(), true) }; \
170 }
171
172// Register TMOP kernels using a single templated parameter (Q1D).
173// The Fallback version uses no arguments (default values).
174// These kernels are independent of the metric id.
175#define MFEM_TMOP_REGISTER_KERNELS_1(Name, Ker) \
176 using Ker##_t = decltype(&Ker<>); \
177 MFEM_REGISTER_KERNELS(Name, Ker##_t, (int)); \
178 template <int Q> \
179 Ker##_t Name::Kernel() { return Ker<Q>; } \
180 Ker##_t Name::Fallback(int) { return Ker<>; }
181// Kernel specializations for the above (fallback versions used otherwise).
182template <typename Kernel>
184{
185 Kernel::template Specialization<2>::Add();
186 Kernel::template Specialization<3>::Add();
187 Kernel::template Specialization<4>::Add();
188 Kernel::template Specialization<5>::Add();
189 Kernel::template Specialization<6>::Add();
190 return 0;
191}
192#define MFEM_TMOP_ADD_SPECIALIZED_KERNELS_1(Name) \
193 namespace \
194 { \
195 [[maybe_unused]] static bool k##Name{ (tmop::KernelSpecializations1<Name>(), true) }; \
196 }
197
198// Register TMOP kernels for a templated metric id.
199// These are used to call Mult functions of the assemble/energy/mult classes.
200// The kernels use the metric, max values and two templated parameters (MDQ).
201// MD1, MQ1 = max D1D/Q1D sizes; T_D1D, T_Q1D = the templated D1D/Q1D variants.
202// The Fallback version uses max values.
203#define MFEM_TMOP_REGISTER_METRIC_INSTANCE(i, Metric, Name) \
204 using Name##_t = tmop::TMOPFunction<Name>; \
205 MFEM_REGISTER_KERNELS(Name##_##i, Name##_t, (int, int)); \
206 MFEM_TMOP_MDQ_SPECIALIZE(Name##_##i); \
207 template <int D, int Q> \
208 Name##_t Name##_##i::Kernel() \
209 { \
210 return Name::Mult<D, Q, Metric, D, Q>; \
211 } \
212 Name##_t Name##_##i::Fallback(int, int) { \
213 return Name::Mult<DofQuadLimits::MAX_D1D, \
214 DofQuadLimits::MAX_Q1D, Metric>; } \
215 template <> \
216 void tmop::Kernel<i>(Name & ker) \
217 { \
218 Name##_##i::Run(ker.Ndof(), ker.Nqpt(), ker); \
219 }
220// Register all Mult kernels for a templated metric id.
221#define MFEM_TMOP_REGISTER_METRIC(metric, assemble, energy, mult, i) \
222 MFEM_TMOP_REGISTER_METRIC_INSTANCE(i, metric, assemble) \
223 MFEM_TMOP_REGISTER_METRIC_INSTANCE(i, metric, energy) \
224 MFEM_TMOP_REGISTER_METRIC_INSTANCE(i, metric, mult)
225
226} // namespace tmop
227
228} // namespace mfem
229
230#endif // MFEM_TMOP_PA_HPP
A basic generic Tensor class, appropriate for use on the GPU.
Definition dtensor.hpp:84
int KernelSpecializations1()
Definition pa.hpp:183
int KernelSpecializationsMDQ()
Definition pa.hpp:105
void(*)(T &) TMOPFunction
Definition pa.hpp:86
int KernelSpecializations()
Definition pa.hpp:144
void Kernel(Ker &)
float real_t
Definition config.hpp:46
Abstract base class for the 2D metric TMOP PA kernels.
Definition pa.hpp:23
virtual MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy, const int e, const real_t weight, const real_t(&Jpt)[DIM *DIM], const real_t *w, const DeviceTensor< 7 > &H) const
Definition pa.hpp:41
virtual MFEM_HOST_DEVICE void EvalP(const real_t(&Jpt)[DIM *DIM], const real_t *w, real_t(&P)[DIM *DIM]) const
Definition pa.hpp:34
static constexpr int DIM
Definition pa.hpp:24
virtual MFEM_HOST_DEVICE real_t EvalW(const real_t(&Jpt)[DIM *DIM], const real_t *w) const
Definition pa.hpp:27
Abstract base class for the 3D metric TMOP PA kernels.
Definition pa.hpp:53
virtual MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy, const int qz, const int e, const real_t weight, real_t *Jrt, real_t *Jpr, const real_t(&Jpt)[DIM *DIM], const real_t *w, const DeviceTensor< 5+DIM > &H) const
Definition pa.hpp:71
virtual MFEM_HOST_DEVICE real_t EvalW(const real_t(&Jpt)[DIM *DIM], const real_t *w) const
Definition pa.hpp:57
virtual MFEM_HOST_DEVICE void EvalP(const real_t(&Jpt)[DIM *DIM], const real_t *w, real_t(&P)[DIM *DIM]) const
Definition pa.hpp:64
static constexpr int DIM
Definition pa.hpp:54