Debian Codegraph @

fem/tmop/metrics/321.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_321 : 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 // I1 + I2/I3 - 6
29 return ie.Get_I1() + ie.Get_I2() / ie.Get_I3() - 6.0;
30 }
31
32 MFEM_HOST_DEVICE void EvalP(const real_t (&Jpt)[9],
33 const real_t *w, real_t (&P)[9]) const final
34 {
35 MFEM_CONTRACT_VAR(w);
36 // dI1 + (1/I3)*dI2 - (2*I2/I3b^3)*dI3b
37 real_t B[9];
38 real_t dI1[9], dI2[9], dI3b[9];
39 kernels::InvariantsEvaluator3D ie(
40 Args().J(Jpt).B(B).dI1(dI1).dI2(dI2).dI3b(dI3b));
41 real_t sign_detJ;
42 const real_t I3 = ie.Get_I3();
43 const real_t alpha = 1.0 / I3;
44 const real_t beta = -2. * ie.Get_I2() / (I3 * ie.Get_I3b(sign_detJ));
45 kernels::Add(3, 3, alpha, ie.Get_dI2(), beta, ie.Get_dI3b(sign_detJ), P);
46 kernels::Add(3, 3, ie.Get_dI1(), P);
47 }
48
49 MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy, const int qz,
50 const int e,
51 const real_t weight,
52 real_t *Jrt,
53 real_t *Jpr,
54 const real_t (&Jpt)[9],
55 const real_t *w,
56 const DeviceTensor<8> &H) const final
57 {
58 MFEM_CONTRACT_VAR(w);
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
64 // ddI1 + (-2/I3b^3)*(dI2 x dI3b + dI3b x dI2)
65 // + (1/I3)*ddI2
66 // + (6*I2/I3b^4)*(dI3b x dI3b)
67 // + (-2*I2/I3b^3)*ddI3b
68 kernels::InvariantsEvaluator3D ie(Args()
69 .J(Jpt)
70 .B(B)
71 .dI1b(dI1b)
72 .ddI1(ddI1)
73 .ddI1b(ddI1b)
74 .dI2(dI2)
75 .dI2b(dI2b)
76 .ddI2(ddI2)
77 .ddI2b(ddI2b)
78 .dI3b(dI3b)
79 .ddI3b(ddI3b));
80 real_t sign_detJ;
81 const real_t I2 = ie.Get_I2();
82 const real_t I3b = ie.Get_I3b(sign_detJ);
83 ConstDeviceMatrix di2(ie.Get_dI2(), DIM, DIM);
84 ConstDeviceMatrix di3b(ie.Get_dI3b(sign_detJ), DIM, DIM);
85 const real_t c0 = 1.0 / I3b;
86 const real_t c1 = weight * c0 * c0;
87 const real_t c2 = -2 * c0 * c1;
88 const real_t c3 = c2 * I2;
89 for (int i = 0; i < DIM; i++)
90 {
91 for (int j = 0; j < DIM; j++)
92 {
93 ConstDeviceMatrix ddi1(ie.Get_ddI1(i, j), DIM, DIM);
94 ConstDeviceMatrix ddi2(ie.Get_ddI2(i, j), DIM, DIM);
95 ConstDeviceMatrix ddi3b(ie.Get_ddI3b(i, j), DIM, DIM);
96 for (int r = 0; r < DIM; r++)
97 {
98 for (int c = 0; c < DIM; c++)
99 {
100 const real_t dp =
101 weight * ddi1(r, c) + c1 * ddi2(r, c) + c3 * ddi3b(r, c) +
102 c2 * ((di2(r, c) * di3b(i, j) + di3b(r, c) * di2(i, j))) -
103 3 * c0 * c3 * di3b(r, c) * di3b(i, j);
104 H(r, c, i, j, qx, qy, qz, e) = dp;
105 }
106 }
107 }
108 }
109 }
110 };
111
112 using metric = TMOP_PA_Metric_321;
113
114 using assemble = TMOPAssembleGradPA3D;
115 using energy = TMOPEnergyPA3D;
116 using mult = TMOPAddMultPA3D;
117
118 MFEM_TMOP_REGISTER_METRIC(metric, assemble, energy, mult, 321);
119
120 } // namespace mfem