Debian Codegraph @

fem/tmop/metrics/080.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_080 : 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_77 = 0.5 * (I2b * I2b + 1. / (I2b * I2b) - 2.);
29 return w[0] * eval_w_02 + w[1] * eval_w_77;
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 MFEM_CONTRACT_VAR(w);
36 // w0 P_2 + w1 P_77
37 real_t dI1b[4], dI2[4], dI2b[4];
38 kernels::InvariantsEvaluator2D ie(
39 Args().J(Jpt).dI1b(dI1b).dI2(dI2).dI2b(dI2b));
40 kernels::Set(2, 2, w[0] * 0.5, ie.Get_dI1b(), P);
41 const real_t I2 = ie.Get_I2();
42 kernels::Add(2, 2, w[1] * 0.5 * (1.0 - 1.0 / (I2 * I2)), ie.Get_dI2(), P);
43 }
44
45 MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy,
46 const int e,
47 const real_t weight,
48 const real_t (&Jpt)[4],
49 const real_t *w,
50 const DeviceTensor<7> &H) const final
51 {
52 // w0 H_2 + w1 H_77
53 real_t ddI1[4], ddI1b[4], dI2[4], dI2b[4], ddI2[4];
54 kernels::InvariantsEvaluator2D ie(
55 Args().J(Jpt).dI2(dI2).ddI1(ddI1).ddI1b(ddI1b).dI2b(dI2b).ddI2(ddI2));
56
57 const real_t I2 = ie.Get_I2(), I2inv_sq = 1.0 / (I2 * I2);
58 ConstDeviceMatrix di2(ie.Get_dI2(), DIM, DIM);
59 for (int i = 0; i < DIM; i++)
60 {
61 for (int j = 0; j < DIM; j++)
62 {
63 ConstDeviceMatrix ddi1b(ie.Get_ddI1b(i, j), DIM, DIM);
64 ConstDeviceMatrix ddi2(ie.Get_ddI2(i, j), DIM, DIM);
65 for (int r = 0; r < DIM; r++)
66 {
67 for (int c = 0; c < DIM; c++)
68 {
69 H(r, c, i, j, qx, qy, e) =
70 w[0] * 0.5 * weight * ddi1b(r, c) +
71 w[1] * (weight * 0.5 * (1.0 - I2inv_sq) * ddi2(r, c) +
72 weight * (I2inv_sq / I2) * di2(r, c) * di2(i, j));
73 }
74 }
75 }
76 }
77 }
78 };
79
80 using metric = TMOP_PA_Metric_080;
81
82 using assemble = TMOPAssembleGradPA2D;
83 using energy = TMOPEnergyPA2D;
84 using mult = TMOPAddMultPA2D;
85
86 MFEM_TMOP_REGISTER_METRIC(metric, assemble, energy, mult, 80);
87
88 } // namespace mfem