Debian Codegraph @

fem/tmop/metrics/077.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_077 : 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 * I2b + 1. / (I2b * I2b) - 2.);
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 real_t dI2[4], dI2b[4];
35 kernels::InvariantsEvaluator2D ie(Args().J(Jpt).dI2(dI2).dI2b(dI2b));
36 const real_t I2 = ie.Get_I2();
37 kernels::Set(2, 2, 0.5 * (1.0 - 1.0 / (I2 * I2)), ie.Get_dI2(), P);
38 }
39
40 MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy,
41 const int e,
42 const real_t weight,
43 const real_t (&Jpt)[4],
44 const real_t *w,
45 const DeviceTensor<7> &H) const final
46 {
47 MFEM_CONTRACT_VAR(w);
48 real_t dI2[4], dI2b[4], ddI2[4];
49 kernels::InvariantsEvaluator2D ie(
50 Args().J(Jpt).dI2(dI2).dI2b(dI2b).ddI2(ddI2));
51 const real_t I2 = ie.Get_I2(), I2inv_sq = 1.0 / (I2 * I2);
52 ConstDeviceMatrix di2(ie.Get_dI2(), DIM, DIM);
53 for (int i = 0; i < DIM; i++)
54 {
55 for (int j = 0; j < DIM; j++)
56 {
57 ConstDeviceMatrix ddi2(ie.Get_ddI2(i, j), DIM, DIM);
58 for (int r = 0; r < DIM; r++)
59 {
60 for (int c = 0; c < DIM; c++)
61 {
62 H(r, c, i, j, qx, qy, e) =
63 weight * 0.5 * (1.0 - I2inv_sq) * ddi2(r, c) +
64 weight * (I2inv_sq / I2) * di2(r, c) * di2(i, j);
65 }
66 }
67 }
68 }
69 }
70 };
71
72 using metric = TMOP_PA_Metric_077;
73
74 using assemble = TMOPAssembleGradPA2D;
75 using energy = TMOPEnergyPA2D;
76 using mult = TMOPAddMultPA2D;
77
78 MFEM_TMOP_REGISTER_METRIC(metric, assemble, energy, mult, 77);
79
80 } // namespace mfem