Debian Codegraph @

fem/tmop/metrics/056.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_056 : 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 const real_t I2b = ie.Get_I2b();
27 return 0.5 * (I2b + 1.0 / I2b) - 1.0;
28 };
29
30 MFEM_HOST_DEVICE void EvalP(const real_t (&Jpt)[4],
31 const real_t *w, real_t (&P)[4]) const final
32 {
33 MFEM_CONTRACT_VAR(w);
34 // 0.5*(1 - 1/I2b^2)*dI2b
35 real_t dI2b[4];
36 kernels::InvariantsEvaluator2D ie(Args().J(Jpt).dI2b(dI2b));
37 const real_t I2b = ie.Get_I2b();
38 kernels::Set(2, 2, 0.5 * (1.0 - 1.0 / (I2b * I2b)), ie.Get_dI2b(), P);
39 }
40
41 MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy,
42 const int e,
43 const real_t weight,
44 const real_t (&Jpt)[4],
45 const real_t *w,
46 const DeviceTensor<7> &H) const final
47 {
48 MFEM_CONTRACT_VAR(w);
49 // (0.5 - 0.5/I2b^2)*ddI2b + (1/I2b^3)*(dI2b x dI2b)
50 real_t dI2b[4], ddI2b[4];
51 kernels::InvariantsEvaluator2D ie(Args().J(Jpt).dI2b(dI2b).ddI2b(ddI2b));
52 const real_t I2b = ie.Get_I2b();
53 ConstDeviceMatrix di2b(ie.Get_dI2b(), DIM, DIM);
54 for (int i = 0; i < DIM; i++)
55 {
56 for (int j = 0; j < DIM; j++)
57 {
58 ConstDeviceMatrix ddi2b(ie.Get_ddI2b(i, j), DIM, DIM);
59 for (int r = 0; r < DIM; r++)
60 {
61 for (int c = 0; c < DIM; c++)
62 {
63 H(r, c, i, j, qx, qy, e) =
64 weight * (0.5 - 0.5 / (I2b * I2b)) * ddi2b(r, c) +
65 weight / (I2b * I2b * I2b) * di2b(r, c) * di2b(i, j);
66 }
67 }
68 }
69 }
70 }
71 };
72
73 using metric = TMOP_PA_Metric_056;
74
75 using assemble = TMOPAssembleGradPA2D;
76 using energy = TMOPEnergyPA2D;
77 using mult = TMOPAddMultPA2D;
78
79 MFEM_TMOP_REGISTER_METRIC(metric, assemble, energy, mult, 56);
80
81 } // namespace mfem