MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
tmop_pa_w3.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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 "../tmop.hpp"
13#include "tmop_pa.hpp"
14#include "../linearform.hpp"
18
19namespace mfem
20{
21
22using Args = kernels::InvariantsEvaluator3D::Buffers;
23
24// mu_302 = I1b * I2b / 9 - 1
25static MFEM_HOST_DEVICE inline
26real_t EvalW_302(const real_t *J)
27{
28 real_t B[9];
29 kernels::InvariantsEvaluator3D ie(Args().J(J).B(B));
30 return ie.Get_I1b()*ie.Get_I2b()/9. - 1.;
31}
32
33// mu_303 = I1b/3 - 1
34static MFEM_HOST_DEVICE inline
35real_t EvalW_303(const real_t *J)
36{
37 real_t B[9];
38 kernels::InvariantsEvaluator3D ie(Args().J(J).B(B));
39 return ie.Get_I1b()/3. - 1.;
40}
41
42// mu_315 = (I3b - 1)^2
43static MFEM_HOST_DEVICE inline
44real_t EvalW_315(const real_t *J)
45{
46 real_t B[9];
47 kernels::InvariantsEvaluator3D ie(Args().J(J).B(B));
48 const real_t a = ie.Get_I3b() - 1.0;
49 return a*a;
50}
51
52// mu_318 = 0.5 * (I3 + 1/I3) - 1.
53static MFEM_HOST_DEVICE inline
54real_t EvalW_318(const real_t *J)
55{
56 real_t B[9];
57 kernels::InvariantsEvaluator3D ie(Args().J(J).B(B));
58 const real_t I3 = ie.Get_I3();
59 return 0.5*(I3 + 1.0/I3) - 1.0;
60}
61
62// mu_321 = I1 + I2/I3 - 6
63static MFEM_HOST_DEVICE inline
64real_t EvalW_321(const real_t *J)
65{
66 real_t B[9];
67 kernels::InvariantsEvaluator3D ie(Args().J(J).B(B));
68 return ie.Get_I1() + ie.Get_I2()/ie.Get_I3() - 6.0;
69}
70
71static MFEM_HOST_DEVICE inline
72real_t EvalW_332(const real_t *J, const real_t *w)
73{
74 return w[0] * EvalW_302(J) + w[1] * EvalW_315(J);
75}
76
77static MFEM_HOST_DEVICE inline
78real_t EvalW_338(const real_t *J, const real_t *w)
79{
80 return w[0] * EvalW_302(J) + w[1] * EvalW_318(J);
81}
82
84 const real_t metric_normal,
85 const Vector &mc_,
86 const Array<real_t> &metric_param,
87 const int mid,
88 const int NE,
89 const DenseTensor &j_,
90 const Array<real_t> &w_,
91 const Array<real_t> &b_,
92 const Array<real_t> &g_,
93 const Vector &ones,
94 const Vector &x_,
95 Vector &energy,
96 const int d1d,
97 const int q1d)
98{
99 MFEM_VERIFY(mid == 302 || mid == 303 || mid == 315 || mid == 318 ||
100 mid == 321 || mid == 332 || mid == 338,
101 "3D metric not yet implemented!");
102
103 const bool const_m0 = mc_.Size() == 1;
104
105 constexpr int DIM = 3;
106 const int D1D = T_D1D ? T_D1D : d1d;
107 const int Q1D = T_Q1D ? T_Q1D : q1d;
108
109 const auto MC = const_m0 ?
110 Reshape(mc_.Read(), 1, 1, 1, 1) :
111 Reshape(mc_.Read(), Q1D, Q1D, Q1D, NE);
112 const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, Q1D, NE);
113 const auto b = Reshape(b_.Read(), Q1D, D1D);
114 const auto g = Reshape(g_.Read(), Q1D, D1D);
115 const auto W = Reshape(w_.Read(), Q1D, Q1D, Q1D);
116 const auto X = Reshape(x_.Read(), D1D, D1D, D1D, DIM, NE);
117
118 auto E = Reshape(energy.Write(), Q1D, Q1D, Q1D, NE);
119
120 const real_t *metric_data = metric_param.Read();
121
122 mfem::forall_3D(NE, Q1D, Q1D, Q1D, [=] MFEM_HOST_DEVICE (int e)
123 {
124 const int D1D = T_D1D ? T_D1D : d1d;
125 const int Q1D = T_Q1D ? T_Q1D : q1d;
126 constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
127 constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
128
129 MFEM_SHARED real_t BG[2][MQ1*MD1];
130 MFEM_SHARED real_t DDD[3][MD1*MD1*MD1];
131 MFEM_SHARED real_t DDQ[6][MD1*MD1*MQ1];
132 MFEM_SHARED real_t DQQ[9][MD1*MQ1*MQ1];
133 MFEM_SHARED real_t QQQ[9][MQ1*MQ1*MQ1];
134
135 kernels::internal::LoadX<MD1>(e,D1D,X,DDD);
136 kernels::internal::LoadBG<MD1,MQ1>(D1D,Q1D,b,g,BG);
137
138 kernels::internal::GradX<MD1,MQ1>(D1D,Q1D,BG,DDD,DDQ);
139 kernels::internal::GradY<MD1,MQ1>(D1D,Q1D,BG,DDQ,DQQ);
140 kernels::internal::GradZ<MD1,MQ1>(D1D,Q1D,BG,DQQ,QQQ);
141
142 MFEM_FOREACH_THREAD(qz,z,Q1D)
143 {
144 MFEM_FOREACH_THREAD(qy,y,Q1D)
145 {
146 MFEM_FOREACH_THREAD(qx,x,Q1D)
147 {
148 const real_t *Jtr = &J(0,0,qx,qy,qz,e);
149 const real_t detJtr = kernels::Det<3>(Jtr);
150 const real_t m_coef = const_m0 ? MC(0,0,0,0) : MC(qx,qy,qz,e);
151 const real_t weight = metric_normal * m_coef *
152 W(qx,qy,qz) * detJtr;
153
154 // Jrt = Jtr^{-1}
155 real_t Jrt[9];
156 kernels::CalcInverse<3>(Jtr, Jrt);
157
158 // Jpr = X^t.DSh
159 real_t Jpr[9];
160 kernels::internal::PullGrad<MQ1>(Q1D,qx,qy,qz, QQQ, Jpr);
161
162 // Jpt = X^t.DS = (X^t.DSh).Jrt = Jpr.Jrt
163 real_t Jpt[9];
164 kernels::Mult(3,3,3, Jpr, Jrt, Jpt);
165
166 // metric->EvalW(Jpt);
167 const real_t EvalW =
168 mid == 302 ? EvalW_302(Jpt) :
169 mid == 303 ? EvalW_303(Jpt) :
170 mid == 315 ? EvalW_315(Jpt) :
171 mid == 318 ? EvalW_318(Jpt) :
172 mid == 321 ? EvalW_321(Jpt) :
173 mid == 332 ? EvalW_332(Jpt, metric_data) :
174 mid == 338 ? EvalW_338(Jpt, metric_data) : 0.0;
175
176 E(qx,qy,qz,e) = weight * EvalW;
177 }
178 }
179 }
180 });
181 return energy * ones;
182}
183
185{
186 const int N = PA.ne;
187 const int M = metric->Id();
188 const int D1D = PA.maps->ndof;
189 const int Q1D = PA.maps->nqpt;
190 const int id = (D1D << 4 ) | Q1D;
191 const real_t mn = metric_normal;
192 const Vector &MC = PA.MC;
193 const DenseTensor &J = PA.Jtr;
194 const Array<real_t> &W = PA.ir->GetWeights();
195 const Array<real_t> &B = PA.maps->B;
196 const Array<real_t> &G = PA.maps->G;
197 const Vector &O = PA.O;
198 Vector &E = PA.E;
199
200 Array<real_t> mp;
201 if (auto m = dynamic_cast<TMOP_Combo_QualityMetric *>(metric))
202 {
203 m->GetWeights(mp);
204 }
205
206 MFEM_LAUNCH_TMOP_KERNEL(EnergyPA_3D,id,mn,MC,mp,M,N,J,W,B,G,O,X,E);
207}
208
209} // namespace mfem
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition array.hpp:317
Rank 3 tensor (array of matrices)
const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
TMOP_QualityMetric * metric
Definition tmop.hpp:1744
struct mfem::TMOP_Integrator::@23 PA
real_t GetLocalStateEnergyPA_3D(const Vector &) const
virtual int Id() const
Return the metric ID.
Definition tmop.hpp:78
Vector data type.
Definition vector.hpp:80
virtual const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:474
int Size() const
Returns the size of the vector.
Definition vector.hpp:218
virtual real_t * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:482
real_t b
Definition lissajous.cpp:42
real_t a
Definition lissajous.cpp:41
constexpr int DIM
MFEM_HOST_DEVICE void CalcInverse(const T *data, T *inv_data)
Return the inverse of a matrix with given size and data into the matrix with data inv_data.
Definition kernels.hpp:246
MFEM_HOST_DEVICE void Mult(const int height, const int width, const TA *data, const TX *x, TY *y)
Matrix vector multiplication: y = A x, where the matrix A is of size height x width with given data,...
Definition kernels.hpp:163
MFEM_HOST_DEVICE T Det(const T *data)
Compute the determinant of a square matrix of size dim with given data.
Definition kernels.hpp:237
MFEM_REGISTER_TMOP_KERNELS(void, DatcSize, const int NE, const int ncomp, const int sizeidx, const real_t input_min_size, const DenseMatrix &w_, const Array< real_t > &b_, const Vector &x_, const Vector &nc_reduce, DenseTensor &j_, const int d1d, const int q1d)
MFEM_HOST_DEVICE DeviceTensor< sizeof...(Dims), T > Reshape(T *ptr, Dims... dims)
Wrap a pointer as a DeviceTensor with automatically deduced template parameters.
Definition dtensor.hpp:131
kernels::InvariantsEvaluator2D::Buffers Args
void forall_3D(int N, int X, int Y, int Z, lambda &&body)
Definition forall.hpp:775
float real_t
Definition config.hpp:43