Debian Codegraph @

fem/tmop/metrics/094.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_094 : TMOP_PA_Metric_2D
21 {
22 MFEM_HOST_DEVICE real_t EvalW(const real_t (&Jpt)[4],
23 const real_t *w) const final
24 {
25 kernels::InvariantsEvaluator2D ie(Args().J(Jpt));
26 const real_t eval_w_02 = 0.5 * ie.Get_I1b() - 1.0;
27 const real_t I2b = ie.Get_I2b();
28 const real_t eval_w_56 = 0.5 * (I2b + 1.0 / I2b) - 1.0;
29 return w[0] * eval_w_02 + w[1] * eval_w_56;
30 };
31
32 MFEM_HOST_DEVICE void EvalP(const real_t (&Jpt)[4],
33 const real_t *w, real_t (&P)[4]) const final
34 {
35 // w0 P_2 + w1 P_56
36 real_t dI1b[4], dI2b[4];
37 kernels::InvariantsEvaluator2D ie(Args().J(Jpt).dI1b(dI1b).dI2b(dI2b));
38 kernels::Set(2, 2, w[0] * 0.5, ie.Get_dI1b(), P);
39 const real_t I2b = ie.Get_I2b();
40 kernels::Add(2, 2, w[1] * 0.5 * (1.0 - 1.0 / (I2b * I2b)), ie.Get_dI2b(),
41 P);
42 }
43
44 MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy,
45 const int e,
46 const real_t weight,
47 const real_t (&Jpt)[4],
48 const real_t *w,
49 const DeviceTensor<7> &H) const final
50 {
51 // w0 H_2 + w1 H_56
52 real_t ddI1[4], ddI1b[4], dI2b[4], ddI2b[4];
53 kernels::InvariantsEvaluator2D ie(
54 Args().J(Jpt).ddI1(ddI1).ddI1b(ddI1b).dI2b(dI2b).ddI2b(ddI2b));
55 const real_t I2b = ie.Get_I2b();
56 ConstDeviceMatrix di2b(ie.Get_dI2b(), DIM, DIM);
57 for (int i = 0; i < DIM; i++)
58 {
59 for (int j = 0; j < DIM; j++)
60 {
61 ConstDeviceMatrix ddi1b(ie.Get_ddI1b(i, j), DIM, DIM);
62 ConstDeviceMatrix ddi2b(ie.Get_ddI2b(i, j), DIM, DIM);
63 for (int r = 0; r < DIM; r++)
64 {
65 for (int c = 0; c < DIM; c++)
66 {
67 H(r, c, i, j, qx, qy, e) =
68 w[0] * 0.5 * weight * ddi1b(r, c) +
69 w[1] *
70 (weight * (0.5 - 0.5 / (I2b * I2b)) * ddi2b(r, c) +
71 weight / (I2b * I2b * I2b) * di2b(r, c) * di2b(i, j));
72 }
73 }
74 }
75 }
76 }
77 };
78
79 using metric = TMOP_PA_Metric_094;
80
81 using assemble = TMOPAssembleGradPA2D;
82 using energy = TMOPEnergyPA2D;
83 using mult = TMOPAddMultPA2D;
84
85 MFEM_TMOP_REGISTER_METRIC(metric, assemble, energy, mult, 94);
86
87 } // namespace mfem