| 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_302 : 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 |
// I1b * I2b / 9 - 1 |
| 29 |
return ie.Get_I1b() * ie.Get_I2b() / 9. - 1.; |
| 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 |
// (I1b/9)*dI2b + (I2b/9)*dI1b |
| 37 |
real_t B[9]; |
| 38 |
real_t dI1b[9], dI2[9], dI2b[9], dI3b[9]; |
| 39 |
kernels::InvariantsEvaluator3D ie( |
| 40 |
Args().J(Jpt).B(B).dI1b(dI1b).dI2(dI2).dI2b(dI2b).dI3b(dI3b)); |
| 41 |
const real_t alpha = ie.Get_I1b() / 9.; |
| 42 |
const real_t beta = ie.Get_I2b() / 9.; |
| 43 |
kernels::Add(3, 3, alpha, ie.Get_dI2b(), beta, ie.Get_dI1b(), P); |
| 44 |
} |
| 45 |
|
| 46 |
MFEM_HOST_DEVICE void AssembleH(const int qx, const int qy, const int qz, |
| 47 |
const int e, |
| 48 |
const real_t weight, |
| 49 |
real_t *Jrt, |
| 50 |
real_t *Jpr, |
| 51 |
const real_t (&Jpt)[9], |
| 52 |
const real_t *w, |
| 53 |
const DeviceTensor<8> &H) const final |
| 54 |
{ |
| 55 |
MFEM_CONTRACT_VAR(Jrt); |
| 56 |
MFEM_CONTRACT_VAR(Jpr); |
| 57 |
MFEM_CONTRACT_VAR(w); |
| 58 |
real_t B[9]; |
| 59 |
real_t dI1b[9], ddI1b[9]; |
| 60 |
real_t dI2[9], dI2b[9], ddI2[9], ddI2b[9]; |
| 61 |
real_t dI3b[9]; // = Jrt; |
| 62 |
// (dI2b*dI1b + dI1b*dI2b)/9 + (I1b/9)*ddI2b + (I2b/9)*ddI1b |
| 63 |
kernels::InvariantsEvaluator3D ie(Args() |
| 64 |
.J(Jpt) |
| 65 |
.B(B) |
| 66 |
.dI1b(dI1b) |
| 67 |
.ddI1b(ddI1b) |
| 68 |
.dI2(dI2) |
| 69 |
.dI2b(dI2b) |
| 70 |
.ddI2(ddI2) |
| 71 |
.ddI2b(ddI2b) |
| 72 |
.dI3b(dI3b)); |
| 73 |
|
| 74 |
const real_t c1 = weight / 9.; |
| 75 |
const real_t I1b = ie.Get_I1b(); |
| 76 |
const real_t I2b = ie.Get_I2b(); |
| 77 |
ConstDeviceMatrix di1b(ie.Get_dI1b(), DIM, DIM); |
| 78 |
ConstDeviceMatrix di2b(ie.Get_dI2b(), DIM, DIM); |
| 79 |
for (int i = 0; i < DIM; i++) |
| 80 |
{ |
| 81 |
for (int j = 0; j < DIM; j++) |
| 82 |
{ |
| 83 |
ConstDeviceMatrix ddi1b(ie.Get_ddI1b(i, j), DIM, DIM); |
| 84 |
ConstDeviceMatrix ddi2b(ie.Get_ddI2b(i, j), DIM, DIM); |
| 85 |
for (int r = 0; r < DIM; r++) |
| 86 |
{ |
| 87 |
for (int c = 0; c < DIM; c++) |
| 88 |
{ |
| 89 |
const real_t dp = |
| 90 |
(di2b(r, c) * di1b(i, j) + di1b(r, c) * di2b(i, j)) + |
| 91 |
ddi2b(r, c) * I1b + ddi1b(r, c) * I2b; |
| 92 |
H(r, c, i, j, qx, qy, qz, e) = c1 * dp; |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
}; |
| 99 |
|
| 100 |
using metric = TMOP_PA_Metric_302; |
| 101 |
|
| 102 |
using assemble = TMOPAssembleGradPA3D; |
| 103 |
using energy = TMOPEnergyPA3D; |
| 104 |
using mult = TMOPAddMultPA3D; |
| 105 |
|
| 106 |
MFEM_TMOP_REGISTER_METRIC(metric, assemble, energy, mult, 302); |
| 107 |
|
| 108 |
} // namespace mfem |