Debian Codegraph @

fem/tmop/assemble/diag3.cpp

raw
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 #include "../pa.hpp"
13 #include "../../tmop.hpp"
14 #include "../../kernels.hpp"
15 #include "../../../general/forall.hpp"
16 #include "../../../linalg/kernels.hpp"
17
18 namespace mfem
19 {
20
21 template <int MD1, int MQ1, int T_D1D = 0, int T_Q1D = 0>
22 void TMOP_AssembleDiagPA_3D(const int NE,
23 const ConstDeviceMatrix &B,
24 const ConstDeviceMatrix &G,
25 const DeviceTensor<6, const real_t> &J,
26 const DeviceTensor<8, const real_t> &H,
27 DeviceTensor<5> &D,
28 const int d1d = 0,
29 const int q1d = 0)
30 {
31 const int D1D = T_D1D ? T_D1D : d1d;
32 const int Q1D = T_Q1D ? T_Q1D : q1d;
33
34 mfem::forall_2D(NE, Q1D, Q1D, [=] MFEM_HOST_DEVICE(int e)
35 {
36 MFEM_SHARED real_t smem[3][3][MQ1][MQ1];
37 kernels::internal::vd_regs3d_t<3, 3, MQ1> rH, r0, r1;
38
39 for (int v = 0; v < 3; ++v)
40 {
41 // Takes into account Jtr by replacing H with Href at all quad points.
42 for (int qz = 0; qz < Q1D; ++qz)
43 {
44 MFEM_FOREACH_THREAD_DIRECT(qy, y, Q1D)
45 {
46 MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D)
47 {
48 const real_t *Jtr = &J(0, 0, qx, qy, qz, e);
49 real_t Jrt_data[9];
50 ConstDeviceMatrix Jrt(Jrt_data, 3, 3);
51 kernels::CalcInverse<3>(Jtr, Jrt_data);
52
53 real_t h[3][3];
54 for (int s = 0; s < 3; s++)
55 {
56 for (int t = 0; t < 3; t++)
57 {
58 h[s][t] = H(v, s, v, t, qx, qy, qz, e);
59 }
60 }
61
62 for (int m = 0; m < 3; m++)
63 {
64 for (int n = 0; n < 3; n++)
65 {
66 // Hr_{v,m,n,q} = \sum_{s,t=1}^d
67 // Jrt_{m,s,q} H_{v,s,v,t,q} Jrt_{n,t,q}
68 rH(m, n, qz, qy, qx) = 0.0;
69 for (int s = 0; s < 3; s++)
70 {
71 for (int t = 0; t < 3; t++)
72 {
73 rH(m, n, qz, qy, qx) += Jrt(m, s) * h[s][t] * Jrt(n, t);
74 }
75 }
76 }
77 }
78 }
79 }
80 MFEM_SYNC_THREAD;
81 }
82
83 // Contract in z.
84 for (int dz = 0; dz < D1D; ++dz)
85 {
86 MFEM_FOREACH_THREAD_DIRECT(qy, y, Q1D)
87 {
88 MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D)
89 {
90 for (int m = 0; m < 3; m++)
91 {
92 for (int n = 0; n < 3; n++)
93 {
94 r0(m, n, dz, qy, qx) = 0.0;
95 }
96 }
97
98 for (int qz = 0; qz < Q1D; ++qz)
99 {
100 const real_t Bz = B(qz, dz), Gz = G(qz, dz);
101 for (int m = 0; m < 3; m++)
102 {
103 for (int n = 0; n < 3; n++)
104 {
105 const real_t L = (m == 2 ? Gz : Bz);
106 const real_t R = (n == 2 ? Gz : Bz);
107 r0(m, n, dz, qy, qx) += L * rH(m, n, qz, qy, qx) * R;
108 }
109 }
110 }
111 }
112 }
113 MFEM_SYNC_THREAD;
114 }
115
116 // Contract in y.
117 for (int dz = 0; dz < D1D; ++dz)
118 {
119 for (int m = 0; m < 3; m++)
120 {
121 for (int n = 0; n < 3; n++)
122 {
123 MFEM_FOREACH_THREAD_DIRECT(qy, y, Q1D)
124 {
125 MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D)
126 {
127 smem[m][n][qy][qx] = r0(m, n, dz, qy, qx);
128 }
129 }
130 }
131 }
132 MFEM_SYNC_THREAD;
133
134 MFEM_FOREACH_THREAD_DIRECT(dy, y, D1D)
135 {
136 MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D)
137 {
138 for (int m = 0; m < 3; m++)
139 {
140 for (int n = 0; n < 3; n++)
141 {
142 r1(m, n, dz, dy, qx) = 0.0;
143 }
144 }
145
146 for (int qy = 0; qy < Q1D; ++qy)
147 {
148 const real_t By = B(qy, dy);
149 const real_t Gy = G(qy, dy);
150 for (int m = 0; m < 3; m++)
151 {
152 for (int n = 0; n < 3; n++)
153 {
154 const real_t L = (m == 1 ? Gy : By);
155 const real_t R = (n == 1 ? Gy : By);
156 r1(m, n, dz, dy, qx) += L * smem[m][n][qy][qx] * R;
157 }
158 }
159 }
160 }
161 }
162 MFEM_SYNC_THREAD;
163 }
164
165 // Contract in x.
166 for (int dz = 0; dz < D1D; ++dz)
167 {
168 for (int m = 0; m < 3; m++)
169 {
170 for (int n = 0; n < 3; n++)
171 {
172 MFEM_FOREACH_THREAD_DIRECT(dy, y, D1D)
173 {
174 MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D)
175 {
176 smem[m][n][dy][qx] = r1(m, n, dz, dy, qx);
177 }
178 }
179 }
180 }
181 MFEM_SYNC_THREAD;
182
183 MFEM_FOREACH_THREAD_DIRECT(dy, y, D1D)
184 {
185 MFEM_FOREACH_THREAD_DIRECT(dx, x, D1D)
186 {
187 real_t d = 0.0;
188 for (int qx = 0; qx < Q1D; ++qx)
189 {
190 const real_t Bx = B(qx, dx);
191 const real_t Gx = G(qx, dx);
192 for (int m = 0; m < 3; m++)
193 {
194 for (int n = 0; n < 3; n++)
195 {
196 const real_t L = (m == 0 ? Gx : Bx);
197 const real_t R = (n == 0 ? Gx : Bx);
198 d += L * smem[m][n][dy][qx] * R;
199 }
200 }
201 }
202 D(dx, dy, dz, v, e) += d;
203 }
204 }
205 MFEM_SYNC_THREAD;
206 }
207 }
208 });
209 }
210
211 MFEM_TMOP_MDQ_REGISTER(TMOPAssembleDiag3D, TMOP_AssembleDiagPA_3D);
212 MFEM_TMOP_MDQ_SPECIALIZE(TMOPAssembleDiag3D);
213
214 void TMOP_Integrator::AssembleDiagonalPA_3D(Vector &diagonal) const
215 {
216 const int NE = PA.ne, d = PA.maps->ndof, q = PA.maps->nqpt;
217 MFEM_VERIFY(d <= DeviceDofQuadLimits::Get().MAX_D1D, "");
218 MFEM_VERIFY(q <= DeviceDofQuadLimits::Get().MAX_Q1D, "");
219
220 const auto B = Reshape(PA.maps->B.Read(), q, d);
221 const auto G = Reshape(PA.maps->G.Read(), q, d);
222 const auto J = Reshape(PA.Jtr.Read(), 3, 3, q, q, q, NE);
223 const auto H = Reshape(PA.H.Read(), 3, 3, 3, 3, q, q, q, NE);
224 auto D = Reshape(diagonal.ReadWrite(), d, d, d, 3, NE);
225
226 TMOPAssembleDiag3D::Run(d, q, NE, B, G, J, H, D, d, q);
227 }
228
229 } // namespace mfem