| 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 "../../../general/forall.hpp" |
| 15 |
#include "../../../linalg/kernels.hpp" |
| 16 |
|
| 17 |
namespace mfem |
| 18 |
{ |
| 19 |
|
| 20 |
/* // Original i-j assembly (old invariants code). |
| 21 |
for (int e = 0; e < NE; e++) |
| 22 |
{ |
| 23 |
for (int q = 0; q < nqp; q++) |
| 24 |
{ |
| 25 |
el.CalcDShape(ip, DSh); |
| 26 |
Mult(DSh, Jrt, DS); |
| 27 |
for (int i = 0; i < dof; i++) |
| 28 |
{ |
| 29 |
for (int j = 0; j < dof; j++) |
| 30 |
{ |
| 31 |
for (int r = 0; r < dim; r++) |
| 32 |
{ |
| 33 |
for (int c = 0; c < dim; c++) |
| 34 |
{ |
| 35 |
for (int rr = 0; rr < dim; rr++) |
| 36 |
{ |
| 37 |
for (int cc = 0; cc < dim; cc++) |
| 38 |
{ |
| 39 |
const real_t H = h(r, c, rr, cc); |
| 40 |
A(e, i + r*dof, j + rr*dof) += |
| 41 |
weight_q * DS(i, c) * DS(j, cc) * H; |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
}*/ |
| 50 |
|
| 51 |
template <int MD1, int MQ1, int T_D1D = 0, int T_Q1D = 0> |
| 52 |
void TMOP_AssembleDiagPA_2D(const int NE, |
| 53 |
const ConstDeviceMatrix &B, |
| 54 |
const ConstDeviceMatrix &G, |
| 55 |
const DeviceTensor<5, const real_t> &J, |
| 56 |
const DeviceTensor<7, const real_t> &H, |
| 57 |
DeviceTensor<4> &D, |
| 58 |
const int d1d = 0, |
| 59 |
const int q1d = 0) |
| 60 |
{ |
| 61 |
const int D1D = T_D1D ? T_D1D : d1d; |
| 62 |
const int Q1D = T_Q1D ? T_Q1D : q1d; |
| 63 |
|
| 64 |
mfem::forall_2D(NE, Q1D, Q1D, [=] MFEM_HOST_DEVICE(int e) |
| 65 |
{ |
| 66 |
// Takes into account Jtr by replacing H with Href at all quad points. |
| 67 |
MFEM_SHARED real_t Href_data[2 * 2 * 2 * MQ1 * MQ1]; |
| 68 |
DeviceTensor<5, real_t> Href(Href_data, 2, 2, 2, MQ1, MQ1); |
| 69 |
for (int v = 0; v < 2; v++) |
| 70 |
{ |
| 71 |
MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D) |
| 72 |
{ |
| 73 |
MFEM_FOREACH_THREAD_DIRECT(qy, y, Q1D) |
| 74 |
{ |
| 75 |
const real_t *Jtr = &J(0, 0, qx, qy, e); |
| 76 |
real_t Jrt_data[4]; |
| 77 |
ConstDeviceMatrix Jrt(Jrt_data, 2, 2); |
| 78 |
kernels::CalcInverse<2>(Jtr, Jrt_data); |
| 79 |
|
| 80 |
for (int m = 0; m < 2; m++) |
| 81 |
{ |
| 82 |
for (int n = 0; n < 2; n++) |
| 83 |
{ |
| 84 |
// Hr_{v,m,n,q} = \sum_{s,t=1}^d |
| 85 |
// Jrt_{m,s,q} H_{v,s,v,t,q} Jrt_{n,t,q} |
| 86 |
Href(v, m, n, qx, qy) = 0.0; |
| 87 |
for (int s = 0; s < 2; s++) |
| 88 |
{ |
| 89 |
for (int t = 0; t < 2; t++) |
| 90 |
{ |
| 91 |
Href(v, m, n, qx, qy) += |
| 92 |
Jrt(m, s) * H(v, s, v, t, qx, qy, e) * Jrt(n, t); |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
MFEM_SHARED real_t qd[2 * 2 * MQ1 * MD1]; |
| 102 |
DeviceTensor<4, real_t> QD(qd, 2, 2, MQ1, MD1); |
| 103 |
|
| 104 |
for (int v = 0; v < 2; v++) |
| 105 |
{ |
| 106 |
// Contract in y. |
| 107 |
MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D) |
| 108 |
{ |
| 109 |
MFEM_FOREACH_THREAD_DIRECT(dy, y, D1D) |
| 110 |
{ |
| 111 |
for (int m = 0; m < 2; m++) |
| 112 |
{ |
| 113 |
for (int n = 0; n < 2; n++) { QD(m, n, qx, dy) = 0.0; } |
| 114 |
} |
| 115 |
for (int qy = 0; qy < Q1D; ++qy) |
| 116 |
{ |
| 117 |
const real_t By = B(qy, dy); |
| 118 |
const real_t Gy = G(qy, dy); |
| 119 |
for (int m = 0; m < 2; m++) |
| 120 |
{ |
| 121 |
for (int n = 0; n < 2; n++) |
| 122 |
{ |
| 123 |
const real_t L = (m == 1 ? Gy : By); |
| 124 |
const real_t R = (n == 1 ? Gy : By); |
| 125 |
QD(m, n, qx, dy) += L * Href(v, m, n, qx, qy) * R; |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
MFEM_SYNC_THREAD; |
| 132 |
|
| 133 |
// Contract in x. |
| 134 |
MFEM_FOREACH_THREAD_DIRECT(dy, y, D1D) |
| 135 |
{ |
| 136 |
MFEM_FOREACH_THREAD_DIRECT(dx, x, D1D) |
| 137 |
{ |
| 138 |
real_t d = 0.0; |
| 139 |
for (int qx = 0; qx < Q1D; ++qx) |
| 140 |
{ |
| 141 |
const real_t Bx = B(qx, dx); |
| 142 |
const real_t Gx = G(qx, dx); |
| 143 |
|
| 144 |
for (int m = 0; m < 2; m++) |
| 145 |
{ |
| 146 |
for (int n = 0; n < 2; n++) |
| 147 |
{ |
| 148 |
const real_t L = (m == 0 ? Gx : Bx); |
| 149 |
const real_t R = (n == 0 ? Gx : Bx); |
| 150 |
d += L * QD(m, n, qx, dy) * R; |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
D(dx, dy, v, e) += d; |
| 155 |
} |
| 156 |
} |
| 157 |
MFEM_SYNC_THREAD; |
| 158 |
} |
| 159 |
}); |
| 160 |
} |
| 161 |
|
| 162 |
MFEM_TMOP_MDQ_REGISTER(TMOPAssembleDiag2D, TMOP_AssembleDiagPA_2D); |
| 163 |
MFEM_TMOP_MDQ_SPECIALIZE(TMOPAssembleDiag2D); |
| 164 |
|
| 165 |
void TMOP_Integrator::AssembleDiagonalPA_2D(Vector &diagonal) const |
| 166 |
{ |
| 167 |
const int NE = PA.ne, d = PA.maps->ndof, q = PA.maps->nqpt; |
| 168 |
MFEM_VERIFY(d <= DeviceDofQuadLimits::Get().MAX_D1D, ""); |
| 169 |
MFEM_VERIFY(q <= DeviceDofQuadLimits::Get().MAX_Q1D, ""); |
| 170 |
|
| 171 |
const auto B = Reshape(PA.maps->B.Read(), q, d); |
| 172 |
const auto G = Reshape(PA.maps->G.Read(), q, d); |
| 173 |
const auto J = Reshape(PA.Jtr.Read(), 2, 2, q, q, NE); |
| 174 |
const auto H = Reshape(PA.H.Read(), 2, 2, 2, 2, q, q, NE); |
| 175 |
auto D = Reshape(diagonal.ReadWrite(), d, d, 2, NE); |
| 176 |
|
| 177 |
TMOPAssembleDiag2D::Run(d, q, NE, B, G, J, H, D, d, q); |
| 178 |
} |
| 179 |
|
| 180 |
} // namespace mfem |