MFEM  v4.6.0
Finite element discretization library
tmop_pa_h3m.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, 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 "../../general/forall.hpp"
15 #include "../../linalg/kernels.hpp"
16 
17 namespace mfem
18 {
19 
20 MFEM_REGISTER_TMOP_KERNELS(void, AddMultGradPA_Kernel_3D,
21  const int NE,
22  const Array<double> &b_,
23  const Array<double> &g_,
24  const DenseTensor &j_,
25  const Vector &h_,
26  const Vector &x_,
27  Vector &y_,
28  const int d1d,
29  const int q1d)
30 {
31  constexpr int DIM = 3;
32  const int D1D = T_D1D ? T_D1D : d1d;
33  const int Q1D = T_Q1D ? T_Q1D : q1d;
34 
35  const auto b = Reshape(b_.Read(), Q1D, D1D);
36  const auto g = Reshape(g_.Read(), Q1D, D1D);
37  const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, Q1D, NE);
38  const auto X = Reshape(x_.Read(), D1D, D1D, D1D, DIM, NE);
39  const auto H = Reshape(h_.Read(), DIM, DIM, DIM, DIM, Q1D, Q1D, Q1D, NE);
40  auto Y = Reshape(y_.ReadWrite(), D1D, D1D, D1D, DIM, NE);
41 
42  mfem::forall_3D(NE, Q1D, Q1D, Q1D, [=] MFEM_HOST_DEVICE (int e)
43  {
44  constexpr int DIM = 3;
45  const int D1D = T_D1D ? T_D1D : d1d;
46  const int Q1D = T_Q1D ? T_Q1D : q1d;
47  constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
48  constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
49 
50  MFEM_SHARED double BG[2][MQ1*MD1];
51  MFEM_SHARED double DDD[3][MD1*MD1*MD1];
52  MFEM_SHARED double DDQ[9][MD1*MD1*MQ1];
53  MFEM_SHARED double DQQ[9][MD1*MQ1*MQ1];
54  MFEM_SHARED double QQQ[9][MQ1*MQ1*MQ1];
55 
56  kernels::internal::LoadX<MD1>(e,D1D,X,DDD);
57  kernels::internal::LoadBG<MD1,MQ1>(D1D,Q1D,b,g,BG);
58 
59  kernels::internal::GradX<MD1,MQ1>(D1D,Q1D,BG,DDD,DDQ);
60  kernels::internal::GradY<MD1,MQ1>(D1D,Q1D,BG,DDQ,DQQ);
61  kernels::internal::GradZ<MD1,MQ1>(D1D,Q1D,BG,DQQ,QQQ);
62 
63  MFEM_FOREACH_THREAD(qz,z,Q1D)
64  {
65  MFEM_FOREACH_THREAD(qy,y,Q1D)
66  {
67  MFEM_FOREACH_THREAD(qx,x,Q1D)
68  {
69  const double *Jtr = &J(0,0,qx,qy,qz,e);
70 
71  // Jrt = Jtr^{-1}
72  double Jrt[9];
73  kernels::CalcInverse<3>(Jtr, Jrt);
74 
75  // Jpr = X^T.DSh
76  double Jpr[9];
77  kernels::internal::PullGrad<MQ1>(Q1D, qx,qy,qz, QQQ, Jpr);
78 
79  // Jpt = X^T.DS = (X^T.DSh).Jrt = Jpr.Jrt
80  double Jpt[9];
81  kernels::Mult(3,3,3, Jpr, Jrt, Jpt);
82 
83  // B = Jpt : H
84  double B[9];
85  DeviceMatrix M(B,3,3);
86  ConstDeviceMatrix J(Jpt,3,3);
87  for (int i = 0; i < DIM; i++)
88  {
89  for (int j = 0; j < DIM; j++)
90  {
91  M(i,j) = 0.0;
92  for (int r = 0; r < DIM; r++)
93  {
94  for (int c = 0; c < DIM; c++)
95  {
96  M(i,j) += H(r,c,i,j,qx,qy,qz,e) * J(r,c);
97  }
98  }
99  }
100  }
101 
102  // Y += DS . M^t += DSh . (Jrt . M^t)
103  double A[9];
104  kernels::MultABt(3,3,3, Jrt, B, A);
105  kernels::internal::PushGrad<MQ1>(Q1D, qx,qy,qz, A, QQQ);
106  }
107  }
108  }
109  MFEM_SYNC_THREAD;
110  kernels::internal::LoadBGt<MD1,MQ1>(D1D,Q1D,b,g,BG);
111  kernels::internal::GradZt<MD1,MQ1>(D1D,Q1D,BG,QQQ,DQQ);
112  kernels::internal::GradYt<MD1,MQ1>(D1D,Q1D,BG,DQQ,DDQ);
113  kernels::internal::GradXt<MD1,MQ1>(D1D,Q1D,BG,DDQ,Y,e);
114  });
115 }
116 
118 {
119  const int N = PA.ne;
120  const int D1D = PA.maps->ndof;
121  const int Q1D = PA.maps->nqpt;
122  const int id = (D1D << 4 ) | Q1D;
123  const DenseTensor &J = PA.Jtr;
124  const Array<double> &B = PA.maps->B;
125  const Array<double> &G = PA.maps->G;
126  const Vector &H = PA.H;
127 
128  MFEM_LAUNCH_TMOP_KERNEL(AddMultGradPA_Kernel_3D,id,N,B,G,J,H,R,C);
129 }
130 
131 } // namespace mfem
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition: array.hpp:307
void forall_3D(int N, int X, int Y, int Z, lambda &&body)
Definition: forall.hpp:763
MFEM_HOST_DEVICE void MultABt(const int Aheight, const int Awidth, const int Bheight, const TA *Adata, const TB *Bdata, TC *ABtdata)
Multiply a matrix of size Aheight x Awidth and data Adata with the transpose of a matrix of size Bhei...
Definition: kernels.hpp:363
struct mfem::TMOP_Integrator::@23 PA
virtual const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:453
constexpr int DIM
const double * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
Definition: densemat.hpp:1230
void AddMultGradPA_3D(const Vector &, Vector &) const
MFEM_REGISTER_TMOP_KERNELS(void, DatcSize, const int NE, const int ncomp, const int sizeidx, const double input_min_size, const DenseMatrix &w_, const Array< double > &b_, const Vector &x_, const Vector &nc_reduce, DenseTensor &j_, const int d1d, const int q1d)
Definition: tmop_pa_da3.cpp:20
double b
Definition: lissajous.cpp:42
A basic generic Tensor class, appropriate for use on the GPU.
Definition: dtensor.hpp:81
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
virtual double * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:469
Vector data type.
Definition: vector.hpp:58
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
Rank 3 tensor (array of matrices)
Definition: densemat.hpp:1096