Debian Codegraph @

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