// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced // at the Lawrence Livermore National Laboratory. All Rights reserved. See files // LICENSE and NOTICE for details. LLNL-CODE-806117. // // This file is part of the MFEM library. For more information and source code // availability visit https://mfem.org. // // MFEM is free software; you can redistribute it and/or modify it under the // terms of the BSD-3 license. We welcome feedback and contributions, see file // CONTRIBUTING.md for details. #pragma once #include "../../tmop.hpp" #include "../../kernels.hpp" #include "../../../general/forall.hpp" #include "../../../linalg/kernels.hpp" namespace mfem { class TMOPAssembleGradPA3D { const TMOP_Integrator *ti; // not owned const Vector &x; public: TMOPAssembleGradPA3D(const TMOP_Integrator *ti, const Vector &x): ti(ti), x(x) {} int Ndof() const { return ti->PA.maps->ndof; } int Nqpt() const { return ti->PA.maps->nqpt; } template static void Mult(TMOPAssembleGradPA3D &ker) { const TMOP_Integrator *ti = ker.ti; const real_t metric_normal = ti->metric_normal; const int NE = ti->PA.ne, d1d = ker.Ndof(), q1d = ti->PA.maps->nqpt; const int D1D = T_D1D ? T_D1D : d1d, Q1D = T_Q1D ? T_Q1D : q1d; MFEM_VERIFY(D1D <= DeviceDofQuadLimits::Get().MAX_D1D, ""); MFEM_VERIFY(Q1D <= DeviceDofQuadLimits::Get().MAX_Q1D, ""); Array mp; if (auto m = dynamic_cast(ti->metric)) { m->GetWeights(mp); } const real_t *w = mp.Read(); const auto *b = ti->PA.maps->B.Read(), *g = ti->PA.maps->G.Read(); const auto X = Reshape(ker.x.Read(), D1D, D1D, D1D, 3, NE); const auto W = Reshape(ti->PA.ir->GetWeights().Read(), Q1D, Q1D, Q1D); const auto J = Reshape(ti->PA.Jtr.Read(), 3, 3, Q1D, Q1D, Q1D, NE); auto H = Reshape(ti->PA.H.Write(), 3, 3, 3, 3, Q1D, Q1D, Q1D, NE); const Vector &mc = ti->PA.MC; const bool const_m0 = mc.Size() == 1; const auto MC = const_m0 ? Reshape(mc.Read(), 1, 1, 1, 1) : Reshape(mc.Read(), Q1D, Q1D, Q1D, NE); mfem::forall_2D(NE, Q1D, Q1D, [=] MFEM_HOST_DEVICE(int e) { MFEM_SHARED real_t smem[MQ1][MQ1]; MFEM_SHARED real_t sB[MD1][MQ1], sG[MD1][MQ1]; kernels::internal::vd_regs3d_t<3, 3, MQ1> r0, r1; kernels::internal::LoadMatrix(D1D, Q1D, b, sB); kernels::internal::LoadMatrix(D1D, Q1D, g, sG); kernels::internal::LoadDofs3d(e, D1D, X, r0); kernels::internal::Grad3d(D1D, Q1D, smem, sB, sG, r0, r1); for (int qz = 0; qz < Q1D; ++qz) { MFEM_FOREACH_THREAD_DIRECT(qy, y, Q1D) { MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D) { const real_t *Jtr = &J(0, 0, qx, qy, qz, e); const real_t detJtr = kernels::Det<3>(Jtr); const real_t m_coef = const_m0 ? MC(0, 0, 0, 0) : MC(qx, qy, qz, e); const real_t weight = metric_normal * m_coef * W(qx, qy, qz) * detJtr; // Jrt = Jtr^{-1} real_t Jrt[9]; kernels::CalcInverse<3>(Jtr, Jrt); // Jpr = X^T.DSh real_t Jpr[9] = { r1(0, 0, qz, qy, qx), r1(1, 0, qz, qy, qx), r1(2, 0, qz, qy, qx), r1(0, 1, qz, qy, qx), r1(1, 1, qz, qy, qx), r1(2, 1, qz, qy, qx), r1(0, 2, qz, qy, qx), r1(1, 2, qz, qy, qx), r1(2, 2, qz, qy, qx) }; // Jpt = X^T . DS = (X^T.DSh) . Jrt = Jpr . Jrt real_t Jpt[9]; kernels::Mult(3, 3, 3, Jpr, Jrt, Jpt); METRIC{}.AssembleH(qx, qy, qz, e, weight, Jrt, Jpr, Jpt, w, H); } } } }); } }; } // namespace mfem