| 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 |
#pragma once |
| 12 |
|
| 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 |
class TMOPAssembleGradPA2D |
| 22 |
{ |
| 23 |
const mfem::TMOP_Integrator *ti; // not owned |
| 24 |
const Vector &x; |
| 25 |
|
| 26 |
public: |
| 27 |
TMOPAssembleGradPA2D(const TMOP_Integrator *ti, const Vector &x): ti(ti), |
| 28 |
x(x) {} |
| 29 |
|
| 30 |
int Ndof() const { return ti->PA.maps->ndof; } |
| 31 |
int Nqpt() const { return ti->PA.maps->nqpt; } |
| 32 |
|
| 33 |
template <int MD1, int MQ1, typename METRIC, int T_D1D = 0, int T_Q1D = 0> |
| 34 |
static void Mult(TMOPAssembleGradPA2D &ker) |
| 35 |
{ |
| 36 |
const mfem::TMOP_Integrator *ti = ker.ti; |
| 37 |
const real_t metric_normal = ti->metric_normal; |
| 38 |
const int NE = ti->PA.ne, d1d = ker.Ndof(), q1d = ti->PA.maps->nqpt; |
| 39 |
|
| 40 |
const int D1D = T_D1D ? T_D1D : d1d, Q1D = T_Q1D ? T_Q1D : q1d; |
| 41 |
MFEM_VERIFY(D1D <= DeviceDofQuadLimits::Get().MAX_D1D, ""); |
| 42 |
MFEM_VERIFY(Q1D <= DeviceDofQuadLimits::Get().MAX_Q1D, ""); |
| 43 |
|
| 44 |
Array<real_t> mp; |
| 45 |
if (auto m = dynamic_cast<TMOP_Combo_QualityMetric *>(ti->metric)) |
| 46 |
{ |
| 47 |
m->GetWeights(mp); |
| 48 |
} |
| 49 |
const real_t *w = mp.Read(); |
| 50 |
|
| 51 |
const auto *b = ti->PA.maps->B.Read(), *g = ti->PA.maps->G.Read(); |
| 52 |
const auto X = Reshape(ker.x.Read(), D1D, D1D, 2, NE); |
| 53 |
const auto W = Reshape(ti->PA.ir->GetWeights().Read(), Q1D, Q1D); |
| 54 |
const auto J = Reshape(ti->PA.Jtr.Read(), 2, 2, Q1D, Q1D, NE); |
| 55 |
auto H = Reshape(ti->PA.H.Write(), 2, 2, 2, 2, Q1D, Q1D, NE); |
| 56 |
|
| 57 |
const Vector &mc = ti->PA.MC; |
| 58 |
const bool const_m0 = mc.Size() == 1; |
| 59 |
const auto MC = const_m0 |
| 60 |
? Reshape(mc.Read(), 1, 1, 1) |
| 61 |
: Reshape(mc.Read(), Q1D, Q1D, NE); |
| 62 |
|
| 63 |
mfem::forall_2D(NE, Q1D, Q1D, [=] MFEM_HOST_DEVICE(int e) |
| 64 |
{ |
| 65 |
MFEM_SHARED real_t smem[MQ1][MQ1]; |
| 66 |
MFEM_SHARED real_t sB[MD1][MQ1], sG[MD1][MQ1]; |
| 67 |
kernels::internal::vd_regs2d_t<2, 2, MQ1> r0, r1; |
| 68 |
|
| 69 |
kernels::internal::LoadMatrix(D1D, Q1D, b, sB); |
| 70 |
kernels::internal::LoadMatrix(D1D, Q1D, g, sG); |
| 71 |
|
| 72 |
kernels::internal::LoadDofs2d(e, D1D, X, r0); |
| 73 |
kernels::internal::Grad2d(D1D, Q1D, smem, sB, sG, r0, r1); |
| 74 |
|
| 75 |
MFEM_FOREACH_THREAD_DIRECT(qy, y, Q1D) |
| 76 |
{ |
| 77 |
MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D) |
| 78 |
{ |
| 79 |
const real_t *Jtr = &J(0, 0, qx, qy, e); |
| 80 |
const real_t detJtr = kernels::Det<2>(Jtr); |
| 81 |
const real_t m_coef = const_m0 ? MC(0, 0, 0) : MC(qx, qy, e); |
| 82 |
const real_t weight = metric_normal * m_coef * W(qx, qy) * detJtr; |
| 83 |
|
| 84 |
// Jrt = Jtr^{-1} |
| 85 |
real_t Jrt[4]; |
| 86 |
kernels::CalcInverse<2>(Jtr, Jrt); |
| 87 |
|
| 88 |
// Jpr = X^t.DSh |
| 89 |
const real_t Jpr[4] = |
| 90 |
{ |
| 91 |
r1[0][0][qy][qx], r1[1][0][qy][qx], |
| 92 |
r1[0][1][qy][qx], r1[1][1][qy][qx] |
| 93 |
}; |
| 94 |
|
| 95 |
// Jpt = Jpr.Jrt |
| 96 |
real_t Jpt[4]; |
| 97 |
kernels::Mult(2, 2, 2, Jpr, Jrt, Jpt); |
| 98 |
|
| 99 |
METRIC{}.AssembleH(qx, qy, e, weight, Jpt, w, H); |
| 100 |
} |
| 101 |
} |
| 102 |
}); |
| 103 |
} |
| 104 |
}; |
| 105 |
|
| 106 |
} // namespace mfem |