Debian Codegraph @

fem/tmop/metrics/338.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_338 : 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 const real_t eval_w_302 = ie.Get_I1b() * ie.Get_I2b() / 9. - 1.;
29 const real_t I3 = ie.Get_I3();
30 const real_t eval_w_318 = 0.5 * (I3 + 1.0 / I3) - 1.0;
31 return w[0] * eval_w_302 + w[1] * eval_w_318;
32 }
33
34 MFEM_HOST_DEVICE void EvalP(const real_t (&Jpt)[9], const real_t *w,
35 real_t (&P)[9]) const final
36 {
37 // w0 P_302 + w1 P_318
38 real_t B[9];
39 real_t dI1b[9], dI2[9], dI2b[9], dI3b[9];
40 kernels::InvariantsEvaluator3D ie(
41 Args().J(Jpt).B(B).dI1b(dI1b).dI2(dI2).dI2b(dI2b).dI3b(dI3b));
42 const real_t alpha = w[0] * ie.Get_I1b() / 9.;
43 const real_t beta = w[0] * ie.Get_I2b() / 9.;
44 kernels::Add(3, 3, alpha, ie.Get_dI2b(), beta, ie.Get_dI1b(), P);
45 real_t sign_detJ;
46 const real_t I3b = ie.Get_I3b(sign_detJ);
47 kernels::Add(3, 3, w[1] * (I3b - 1.0 / (I3b * I3b * I3b)),
48 ie.Get_dI3b(sign_detJ), P);
49 }
50
51 MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy, const int qz,
52 const int e,
53 const real_t weight,
54 real_t *Jrt,
55 real_t *Jpr,
56 const real_t (&Jpt)[9],
57 const real_t *w,
58 const DeviceTensor<8> &H) const final
59 {
60 real_t B[9];
61 real_t dI1b[9], ddI1b[9];
62 real_t dI2[9], dI2b[9], ddI2[9], ddI2b[9];
63 real_t *dI3b = Jrt, *ddI3b = Jpr;
64 // w0 H_302 + w1 H_318
65 kernels::InvariantsEvaluator3D ie(Args()
66 .J(Jpt)
67 .B(B)
68 .dI1b(dI1b)
69 .ddI1b(ddI1b)
70 .dI2(dI2)
71 .dI2b(dI2b)
72 .ddI2(ddI2)
73 .ddI2b(ddI2b)
74 .dI3b(dI3b)
75 .ddI3b(ddI3b));
76 real_t sign_detJ;
77 const real_t c1 = weight / 9.;
78 const real_t I1b = ie.Get_I1b();
79 const real_t I2b = ie.Get_I2b();
80 const real_t I3b = ie.Get_I3b(sign_detJ);
81 ConstDeviceMatrix di1b(ie.Get_dI1b(), DIM, DIM);
82 ConstDeviceMatrix di2b(ie.Get_dI2b(), DIM, DIM);
83 ConstDeviceMatrix di3b(ie.Get_dI3b(sign_detJ), DIM, DIM);
84 for (int i = 0; i < DIM; i++)
85 {
86 for (int j = 0; j < DIM; j++)
87 {
88 ConstDeviceMatrix ddi1b(ie.Get_ddI1b(i, j), DIM, DIM);
89 ConstDeviceMatrix ddi2b(ie.Get_ddI2b(i, j), DIM, DIM);
90 ConstDeviceMatrix ddi3b(ie.Get_ddI3b(i, j), DIM, DIM);
91 for (int r = 0; r < DIM; r++)
92 {
93 for (int c = 0; c < DIM; c++)
94 {
95 const real_t dp_302 =
96 (di2b(r, c) * di1b(i, j) + di1b(r, c) * di2b(i, j)) +
97 ddi2b(r, c) * I1b + ddi1b(r, c) * I2b;
98 const real_t dp_318 =
99 weight * (I3b - 1.0 / (I3b * I3b * I3b)) * ddi3b(r, c) +
100 weight * (1.0 + 3.0 / (I3b * I3b * I3b * I3b)) *
101 di3b(r, c) * di3b(i, j);
102 H(r, c, i, j, qx, qy, qz, e) =
103 w[0] * c1 * dp_302 + w[1] * dp_318;
104 }
105 }
106 }
107 }
108 }
109 };
110
111 using metric = TMOP_PA_Metric_338;
112
113 using assemble = TMOPAssembleGradPA3D;
114 using energy = TMOPEnergyPA3D;
115 using mult = TMOPAddMultPA3D;
116
117 MFEM_TMOP_REGISTER_METRIC(metric, assemble, energy, mult, 338);
118
119 } // namespace mfem