Debian Codegraph @

fem/tmop/tools/det2_jpr.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 "../../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_2D(const int NE,
24 const real_t *b,
25 const real_t *g,
26 const DeviceTensor<4, const real_t> &X,
27 const DeviceTensor<3, real_t> &DetJ,
28 const int d1d,
29 const int q1d)
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[MQ1][MQ1];
37 MFEM_SHARED real_t sB[MD1][MQ1], sG[MD1][MQ1];
38 kernels::internal::vd_regs2d_t<2, 2, MQ1> r0, r1;
39
40 kernels::internal::LoadMatrix(D1D, Q1D, b, sB);
41 kernels::internal::LoadMatrix(D1D, Q1D, g, sG);
42
43 kernels::internal::LoadDofs2d(e, D1D, X, r0);
44 kernels::internal::Grad2d(D1D, Q1D, smem, sB, sG, r0, r1);
45
46 MFEM_FOREACH_THREAD_DIRECT(qy, y, Q1D)
47 {
48 MFEM_FOREACH_THREAD_DIRECT(qx, x, Q1D)
49 {
50 const real_t J[4] =
51 {
52 r1[0][0][qy][qx], r1[1][0][qy][qx],
53 r1[0][1][qy][qx], r1[1][1][qy][qx]
54 };
55 DetJ(qx, qy, e) = kernels::Det<2>(J);
56 }
57 }
58 });
59 }
60
61 MFEM_TMOP_MDQ_REGISTER(TMOPMinDetJpr2D, TMOP_MinDetJpr_2D);
62 MFEM_TMOP_MDQ_SPECIALIZE(TMOPMinDetJpr2D);
63
64 real_t TMOPNewtonSolver::MinDetJpr_2D(const FiniteElementSpace *fes,
65 const Vector &D) const
66 {
67 const ElementDofOrdering ordering = ElementDofOrdering::LEXICOGRAPHIC;
68
69 const Operator *RD = fes->GetElementRestriction(ordering);
70 Vector DE(RD->Height(), Device::GetDeviceMemoryType());
71 DE.UseDevice(true);
72 RD->Mult(D, DE);
73
74 const Operator *RX = x_0.FESpace()->GetElementRestriction(ordering);
75 Vector XE(RX->Height(), Device::GetDeviceMemoryType());
76 XE.UseDevice(true);
77 RX->Mult(x_0, XE);
78 XE += DE;
79
80 auto maps = fes->GetFE(0)->GetDofToQuad(ir, DofToQuad::TENSOR);
81 const int NE = fes->GetMesh()->GetNE();
82 const int NQ = ir.GetNPoints();
83
84 const int d = maps.ndof, q = maps.nqpt;
85 MFEM_VERIFY(d <= DeviceDofQuadLimits::Get().MAX_D1D, "");
86 MFEM_VERIFY(q <= DeviceDofQuadLimits::Get().MAX_Q1D, "");
87
88 Vector E(NE*NQ);
89 E.UseDevice(true);
90
91 const auto *b = maps.B.Read(), *g = maps.G.Read();
92 const auto xe = Reshape(XE.Read(), d, d, 2, NE);
93 auto e = Reshape(E.Write(), q, q, NE);
94
95 TMOPMinDetJpr2D::Run(d, q, NE, b, g, xe, e, d, q);
96
97 return E.Min();
98 }
99
100 } // namespace mfem