Debian Codegraph @

fem/tmop/metrics/318.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/mult3.hpp"
14 #include "../tools/energy3.hpp"
15 #include "../assemble/grad3.hpp"
16
17 namespace mfem
18 {
19
20 struct TMOP_PA_Metric_318 : TMOP_PA_Metric_3D
21 {
22 MFEM_HOST_DEVICE real_t EvalW(const real_t (&Jpt)[DIM * DIM],
23 const real_t *w) const final
24 {
25 real_t B[9];
26 MFEM_CONTRACT_VAR(w);
27 kernels::InvariantsEvaluator3D ie(Args().J(Jpt).B(B));
28 // 0.5 * (I3 + 1/I3) - 1.
29 const real_t I3 = ie.Get_I3();
30 return 0.5 * (I3 + 1.0 / I3) - 1.0;
31 }
32
33 // P_318 = (I3b - 1/I3b^3)*dI3b.
34 // Uses the I3b form, as dI3 and ddI3 were not implemented at the time
35 MFEM_HOST_DEVICE void EvalP(const real_t (&Jpt)[9],
36 const real_t *w, real_t (&P)[9]) const final
37 {
38 MFEM_CONTRACT_VAR(w);
39 real_t dI3b[9];
40 kernels::InvariantsEvaluator3D ie(Args().J(Jpt).dI3b(dI3b));
41
42 real_t sign_detJ;
43 const real_t I3b = ie.Get_I3b(sign_detJ);
44 kernels::Set(3, 3, I3b - 1.0 / (I3b * I3b * I3b), ie.Get_dI3b(sign_detJ),
45 P);
46 }
47
48 MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy, const int qz,
49 const int e,
50 const real_t weight,
51 real_t *Jrt,
52 real_t *Jpr,
53 const real_t (&Jpt)[9],
54 const real_t *w,
55 const DeviceTensor<8> &H) const final
56 {
57 MFEM_CONTRACT_VAR(w);
58 real_t *dI3b = Jrt, *ddI3b = Jpr;
59 // dP_318 = (I3b - 1/I3b^3)*ddI3b + (1 + 3/I3b^4)*(dI3b x dI3b)
60 // Uses the I3b form, as dI3 and ddI3 were not implemented at the time
61 kernels::InvariantsEvaluator3D ie(Args().J(Jpt).dI3b(dI3b).ddI3b(ddI3b));
62 real_t sign_detJ;
63 const real_t I3b = ie.Get_I3b(sign_detJ);
64 ConstDeviceMatrix di3b(ie.Get_dI3b(sign_detJ), DIM, DIM);
65 for (int i = 0; i < DIM; i++)
66 {
67 for (int j = 0; j < DIM; j++)
68 {
69 ConstDeviceMatrix ddi3b(ie.Get_ddI3b(i, j), DIM, DIM);
70 for (int r = 0; r < DIM; r++)
71 {
72 for (int c = 0; c < DIM; c++)
73 {
74 const real_t dp =
75 weight * (I3b - 1.0 / (I3b * I3b * I3b)) * ddi3b(r, c) +
76 weight * (1.0 + 3.0 / (I3b * I3b * I3b * I3b)) *
77 di3b(r, c) * di3b(i, j);
78 H(r, c, i, j, qx, qy, qz, e) = dp;
79 }
80 }
81 }
82 }
83 }
84 };
85
86 using metric = TMOP_PA_Metric_318;
87
88 using assemble = TMOPAssembleGradPA3D;
89 using energy = TMOPEnergyPA3D;
90 using mult = TMOPAddMultPA3D;
91
92 MFEM_TMOP_REGISTER_METRIC(metric, assemble, energy, mult, 318);
93
94 } // namespace mfem