| 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 "../../tmop_tools.hpp" |
| 16 |
#include "../../../general/forall.hpp" |
| 17 |
#include "../../../linalg/kernels.hpp" |
| 18 |
|
| 19 |
namespace mfem |
| 20 |
{ |
| 21 |
|
| 22 |
template <int MD1, int MQ1, int T_D1D = 0, int T_Q1D = 0> |
| 23 |
void TMOP_MinDetJpr_3D(const int NE, |
| 24 |
const real_t *b, |
| 25 |
const real_t *g, |
| 26 |
const DeviceTensor<5, const real_t> &X, |
| 27 |
DeviceTensor<4> &DetJ, |
| 28 |
const int d1d, const int q1d) |
| 29 |
{ |
| 30 |
const int D1D = T_D1D ? T_D1D : d1d; |
| 31 |
const int Q1D = T_Q1D ? T_Q1D : q1d; |
| 32 |
|
| 33 |
mfem::forall_2D(NE, Q1D, Q1D, [=] MFEM_HOST_DEVICE(int e) |
| 34 |
{ |
| 35 |
MFEM_SHARED real_t smem[MQ1][MQ1]; |
| 36 |
MFEM_SHARED real_t sB[MD1][MQ1], sG[MD1][MQ1]; |
| 37 |
kernels::internal::vd_regs3d_t<3, 3, MQ1> r0, r1; |
| 38 |
|
| 39 |
kernels::internal::LoadMatrix(D1D, Q1D, b, sB); |
| 40 |
kernels::internal::LoadMatrix(D1D, Q1D, g, sG); |
| 41 |
|
| 42 |
kernels::internal::LoadDofs3d(e, D1D, X, r0); |
| 43 |
kernels::internal::Grad3d(D1D, Q1D, smem, sB, sG, r0, r1); |
| 44 |
|
| 45 |
for (int qz = 0; qz < Q1D; ++qz) |
| 46 |
{ |
| 47 |
MFEM_FOREACH_THREAD_DIRECT(qy, y, Q1D) |
| 48 |
{ |
| 49 |
MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D) |
| 50 |
{ |
| 51 |
const real_t J[9] = |
| 52 |
{ |
| 53 |
r1(0, 0, qz, qy, qx), r1(1, 0, qz, qy, qx), r1(2, 0, qz, qy, qx), |
| 54 |
r1(0, 1, qz, qy, qx), r1(1, 1, qz, qy, qx), r1(2, 1, qz, qy, qx), |
| 55 |
r1(0, 2, qz, qy, qx), r1(1, 2, qz, qy, qx), r1(2, 2, qz, qy, qx) |
| 56 |
}; |
| 57 |
DetJ(qx, qy, qz, e) = kernels::Det<3>(J); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
}); |
| 62 |
} |
| 63 |
|
| 64 |
MFEM_TMOP_MDQ_REGISTER(TMOPMinDetJpr3D, TMOP_MinDetJpr_3D); |
| 65 |
MFEM_TMOP_MDQ_SPECIALIZE(TMOPMinDetJpr3D); |
| 66 |
|
| 67 |
real_t TMOPNewtonSolver::MinDetJpr_3D(const FiniteElementSpace *fes, |
| 68 |
const Vector &D) const |
| 69 |
{ |
| 70 |
const ElementDofOrdering ordering = ElementDofOrdering::LEXICOGRAPHIC; |
| 71 |
|
| 72 |
const Operator *RD = fes->GetElementRestriction(ordering); |
| 73 |
Vector DE(RD->Height(), Device::GetDeviceMemoryType()); |
| 74 |
DE.UseDevice(true); |
| 75 |
RD->Mult(D, DE); |
| 76 |
|
| 77 |
const Operator *RX = x_0.FESpace()->GetElementRestriction(ordering); |
| 78 |
Vector XE(RX->Height(), Device::GetDeviceMemoryType()); |
| 79 |
XE.UseDevice(true); |
| 80 |
RX->Mult(x_0, XE); |
| 81 |
XE += DE; |
| 82 |
|
| 83 |
const auto maps = fes->GetFE(0)->GetDofToQuad(ir, DofToQuad::TENSOR); |
| 84 |
const int NE = fes->GetMesh()->GetNE(); |
| 85 |
const int NQ = ir.GetNPoints(); |
| 86 |
|
| 87 |
const int d = maps.ndof, q = maps.nqpt; |
| 88 |
MFEM_VERIFY(d <= DeviceDofQuadLimits::Get().MAX_D1D, ""); |
| 89 |
MFEM_VERIFY(q <= DeviceDofQuadLimits::Get().MAX_Q1D, ""); |
| 90 |
|
| 91 |
const auto *b = maps.B.Read(), *g = maps.G.Read(); |
| 92 |
const auto xe = Reshape(XE.Read(), d, d, d, 3, NE); |
| 93 |
|
| 94 |
Vector E(NE * NQ); |
| 95 |
E.UseDevice(true); |
| 96 |
|
| 97 |
auto DetJ = Reshape(E.Write(), q, q, q, NE); |
| 98 |
|
| 99 |
TMOPMinDetJpr3D::Run(d, q, NE, b, g, xe, DetJ, d, q); |
| 100 |
|
| 101 |
return E.Min(); |
| 102 |
} |
| 103 |
|
| 104 |
} // namespace mfem |