MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
tmop_pa_w3.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, 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"
15 #include "../../general/forall.hpp"
16 #include "../../linalg/kernels.hpp"
17 #include "../../linalg/dinvariants.hpp"
18 
19 namespace mfem
20 {
21 
22 using Args = kernels::InvariantsEvaluator3D::Buffers;
23 
24 // mu_302 = I1b * I2b / 9 - 1
25 static MFEM_HOST_DEVICE inline
26 double EvalW_302(const double *J)
27 {
28  double 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
34 static MFEM_HOST_DEVICE inline
35 double EvalW_303(const double *J)
36 {
37  double 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
43 static MFEM_HOST_DEVICE inline
44 double EvalW_315(const double *J)
45 {
46  double B[9];
47  kernels::InvariantsEvaluator3D ie(Args().J(J).B(B));
48  const double a = ie.Get_I3b() - 1.0;
49  return a*a;
50 }
51 
52 // mu_321 = I1 + I2/I3 - 6
53 static MFEM_HOST_DEVICE inline
54 double EvalW_321(const double *J)
55 {
56  double B[9];
57  kernels::InvariantsEvaluator3D ie(Args().J(J).B(B));
58  return ie.Get_I1() + ie.Get_I2()/ie.Get_I3() - 6.0;
59 }
60 
61 static MFEM_HOST_DEVICE inline
62 double EvalW_332(const double *J, double gamma)
63 {
64  return (1.0 - gamma) * EvalW_302(J) + gamma * EvalW_315(J);
65 }
66 
67 MFEM_REGISTER_TMOP_KERNELS(double, EnergyPA_3D,
68  const double metric_normal,
69  const double metric_param,
70  const int mid,
71  const int NE,
72  const DenseTensor &j_,
73  const Array<double> &w_,
74  const Array<double> &b_,
75  const Array<double> &g_,
76  const Vector &ones,
77  const Vector &x_,
78  Vector &energy,
79  const int d1d,
80  const int q1d)
81 {
82  MFEM_VERIFY(mid == 302 || mid == 303 || mid == 315 ||
83  mid == 321 || mid == 332, "3D metric not yet implemented!");
84 
85  constexpr int DIM = 3;
86  const int D1D = T_D1D ? T_D1D : d1d;
87  const int Q1D = T_Q1D ? T_Q1D : q1d;
88 
89  const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, Q1D, NE);
90  const auto b = Reshape(b_.Read(), Q1D, D1D);
91  const auto g = Reshape(g_.Read(), Q1D, D1D);
92  const auto W = Reshape(w_.Read(), Q1D, Q1D, Q1D);
93  const auto X = Reshape(x_.Read(), D1D, D1D, D1D, DIM, NE);
94 
95  auto E = Reshape(energy.Write(), Q1D, Q1D, Q1D, NE);
96 
97  MFEM_FORALL_3D(e, NE, Q1D, Q1D, Q1D,
98  {
99  const int D1D = T_D1D ? T_D1D : d1d;
100  const int Q1D = T_Q1D ? T_Q1D : q1d;
101  constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
102  constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
103 
104  MFEM_SHARED double BG[2][MQ1*MD1];
105  MFEM_SHARED double DDD[3][MD1*MD1*MD1];
106  MFEM_SHARED double DDQ[6][MD1*MD1*MQ1];
107  MFEM_SHARED double DQQ[9][MD1*MQ1*MQ1];
108  MFEM_SHARED double QQQ[9][MQ1*MQ1*MQ1];
109 
110  kernels::internal::LoadX<MD1>(e,D1D,X,DDD);
111  kernels::internal::LoadBG<MD1,MQ1>(D1D,Q1D,b,g,BG);
112 
113  kernels::internal::GradX<MD1,MQ1>(D1D,Q1D,BG,DDD,DDQ);
114  kernels::internal::GradY<MD1,MQ1>(D1D,Q1D,BG,DDQ,DQQ);
115  kernels::internal::GradZ<MD1,MQ1>(D1D,Q1D,BG,DQQ,QQQ);
116 
117  MFEM_FOREACH_THREAD(qz,z,Q1D)
118  {
119  MFEM_FOREACH_THREAD(qy,y,Q1D)
120  {
121  MFEM_FOREACH_THREAD(qx,x,Q1D)
122  {
123  const double *Jtr = &J(0,0,qx,qy,qz,e);
124  const double detJtr = kernels::Det<3>(Jtr);
125  const double weight = metric_normal * W(qx,qy,qz) * detJtr;
126 
127  // Jrt = Jtr^{-1}
128  double Jrt[9];
129  kernels::CalcInverse<3>(Jtr, Jrt);
130 
131  // Jpr = X^t.DSh
132  double Jpr[9];
133  kernels::internal::PullGrad<MQ1>(Q1D,qx,qy,qz, QQQ, Jpr);
134 
135  // Jpt = X^t.DS = (X^t.DSh).Jrt = Jpr.Jrt
136  double Jpt[9];
137  kernels::Mult(3,3,3, Jpr, Jrt, Jpt);
138 
139  // metric->EvalW(Jpt);
140  const double EvalW =
141  mid == 302 ? EvalW_302(Jpt) :
142  mid == 303 ? EvalW_303(Jpt) :
143  mid == 315 ? EvalW_315(Jpt) :
144  mid == 321 ? EvalW_321(Jpt) :
145  mid == 332 ? EvalW_332(Jpt, metric_param) : 0.0;
146 
147  E(qx,qy,qz,e) = weight * EvalW;
148  }
149  }
150  }
151  });
152  return energy * ones;
153 }
154 
156 {
157  const int N = PA.ne;
158  const int M = metric->Id();
159  const int D1D = PA.maps->ndof;
160  const int Q1D = PA.maps->nqpt;
161  const int id = (D1D << 4 ) | Q1D;
162  const double mn = metric_normal;
163  const DenseTensor &J = PA.Jtr;
164  const Array<double> &W = PA.ir->GetWeights();
165  const Array<double> &B = PA.maps->B;
166  const Array<double> &G = PA.maps->G;
167  const Vector &O = PA.O;
168  Vector &E = PA.E;
169 
170  double mp = 0.0;
171  if (auto m = dynamic_cast<TMOP_Metric_332 *>(metric)) { mp = m->GetGamma(); }
172 
173  MFEM_LAUNCH_TMOP_KERNEL(EnergyPA_3D,id,mn,mp,M,N,J,W,B,G,O,X,E);
174 }
175 
176 } // namespace mfem
virtual int Id() const
Return the metric ID.
Definition: tmop.hpp:78
double GetLocalStateEnergyPA_3D(const Vector &) const
Definition: tmop_pa_w3.cpp:155
struct mfem::TMOP_Integrator::@23 PA
TMOP_QualityMetric * metric
Definition: tmop.hpp:1572
const double * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
Definition: densemat.hpp:1087
constexpr int DIM
virtual double * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:457
double b
Definition: lissajous.cpp:42
MFEM_REGISTER_TMOP_KERNELS(void, DatcSize, const int NE, const int ncomp, const int sizeidx, const DenseMatrix &w_, const Array< double > &b_, const Vector &x_, DenseTensor &j_, const int d1d, const int q1d)
Definition: tmop_pa_da3.cpp:20
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition: array.hpp:304
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
double a
Definition: lissajous.cpp:41
kernels::InvariantsEvaluator2D::Buffers Args
Definition: tmop_pa_h2s.cpp:21
Vector data type.
Definition: vector.hpp:60
Rank 3 tensor (array of matrices)
Definition: densemat.hpp:953
virtual const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:449
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