Debian Codegraph @

fem/tmop/metrics/002.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 "../mult/mult2.hpp"
14 #include "../tools/energy2.hpp"
15 #include "../assemble/grad2.hpp"
16
17 namespace mfem
18 {
19
20 struct TMOP_PA_Metric_002 : TMOP_PA_Metric_2D
21 {
22 MFEM_HOST_DEVICE real_t EvalW(const real_t (&Jpt)[4],
23 const real_t *) const final
24 {
25 kernels::InvariantsEvaluator2D ie(Args().J(Jpt));
26 return 0.5 * ie.Get_I1b() - 1.0;
27 };
28
29 MFEM_HOST_DEVICE void EvalP(const real_t (&Jpt)[4],
30 const real_t *w, real_t (&P)[4]) const final
31 {
32 MFEM_CONTRACT_VAR(w);
33 real_t dI1b[4], dI2b[4];
34 kernels::InvariantsEvaluator2D ie(Args().J(Jpt).dI1b(dI1b).dI2b(dI2b));
35 kernels::Set(2, 2, 1. / 2., ie.Get_dI1b(), P);
36 }
37
38 MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy,
39 const int e, const real_t weight,
40 const real_t (&Jpt)[4], const real_t *w,
41 const DeviceTensor<7> &H) const final
42 {
43 MFEM_CONTRACT_VAR(w);
44 // 0.5 * weight * dI1b
45 real_t ddI1[4], ddI1b[4], dI2b[4];
46 kernels::InvariantsEvaluator2D ie(
47 Args().J(Jpt).ddI1(ddI1).ddI1b(ddI1b).dI2b(dI2b));
48 const real_t half_weight = 0.5 * weight;
49 for (int i = 0; i < DIM; i++)
50 {
51 for (int j = 0; j < DIM; j++)
52 {
53 ConstDeviceMatrix ddi1b(ie.Get_ddI1b(i, j), DIM, DIM);
54 for (int r = 0; r < DIM; r++)
55 {
56 for (int c = 0; c < DIM; c++)
57 {
58 const real_t h = ddi1b(r, c);
59 H(r, c, i, j, qx, qy, e) = half_weight * h;
60 }
61 }
62 }
63 }
64 }
65 };
66
67 using metric = TMOP_PA_Metric_002;
68
69 using assemble = TMOPAssembleGradPA2D;
70 using energy = TMOPEnergyPA2D;
71 using mult = TMOPAddMultPA2D;
72
73 MFEM_TMOP_REGISTER_METRIC(metric, assemble, energy, mult, 2);
74
75 } // namespace mfem