MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
tmop_pa_h3d.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 "../../general/forall.hpp"
15 #include "../../linalg/kernels.hpp"
16 
17 namespace mfem
18 {
19 
20 MFEM_REGISTER_TMOP_KERNELS(void, AssembleDiagonalPA_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  Vector &diagonal,
27  const int d1d,
28  const int q1d)
29 {
30  constexpr int DIM = 3;
31  const int D1D = T_D1D ? T_D1D : d1d;
32  const int Q1D = T_Q1D ? T_Q1D : q1d;
33 
34  const auto B = Reshape(b.Read(), Q1D, D1D);
35  const auto G = Reshape(g.Read(), Q1D, D1D);
36  const auto J = Reshape(j.Read(), DIM, DIM, Q1D, Q1D, Q1D, NE);
37  const auto H = Reshape(h.Read(), DIM, DIM, DIM, DIM, Q1D, Q1D, Q1D, NE);
38 
39  auto D = Reshape(diagonal.ReadWrite(), D1D, D1D, D1D, DIM, NE);
40 
41  MFEM_FORALL_3D(e, NE, Q1D, Q1D, Q1D,
42  {
43  constexpr int DIM = 3;
44  const int D1D = T_D1D ? T_D1D : d1d;
45  const int Q1D = T_Q1D ? T_Q1D : q1d;
46  constexpr int MD1 = T_D1D ? T_D1D : MAX_D1D;
47  constexpr int MQ1 = T_Q1D ? T_Q1D : MAX_Q1D;
48 
49  MFEM_SHARED double qqd[MQ1*MQ1*MD1];
50  MFEM_SHARED double qdd[MQ1*MD1*MD1];
51  DeviceTensor<3,double> QQD(qqd, MQ1, MQ1, MD1);
52  DeviceTensor<3,double> QDD(qdd, MQ1, MD1, MD1);
53 
54  for (int v = 0; v < DIM; ++v)
55  {
56  for (int i = 0; i < DIM; i++)
57  {
58  for (int j = 0; j < DIM; j++)
59  {
60  // first tensor contraction, along z direction
61  MFEM_FOREACH_THREAD(qx,x,Q1D)
62  {
63  MFEM_FOREACH_THREAD(qy,y,Q1D)
64  {
65  MFEM_FOREACH_THREAD(dz,z,D1D)
66  {
67  QQD(qx,qy,dz) = 0.0;
68  MFEM_UNROLL(MQ1)
69  for (int qz = 0; qz < Q1D; ++qz)
70  {
71  const double *Jtr = &J(0,0,qx,qy,qz,e);
72  double jrt[9];
73  ConstDeviceMatrix Jrt(jrt,3,3);
74  kernels::CalcInverse<3>(Jtr, jrt);
75  const double Bz = B(qz,dz);
76  const double Gz = G(qz,dz);
77  const double L = i==2 ? Gz : Bz;
78  const double R = j==2 ? Gz : Bz;
79  const double Jij = Jrt(i,i) * Jrt(j,j);
80  const double h = H(v,i,v,j,qx,qy,qz,e);
81  QQD(qx,qy,dz) += L * Jij * h * R;
82  }
83  }
84  }
85  }
86  MFEM_SYNC_THREAD;
87  // second tensor contraction, along y direction
88  MFEM_FOREACH_THREAD(qx,x,Q1D)
89  {
90  MFEM_FOREACH_THREAD(dz,z,D1D)
91  {
92  MFEM_FOREACH_THREAD(dy,y,D1D)
93  {
94  QDD(qx,dy,dz) = 0.0;
95  MFEM_UNROLL(MQ1)
96  for (int qy = 0; qy < Q1D; ++qy)
97  {
98  const double By = B(qy,dy);
99  const double Gy = G(qy,dy);
100  const double L = i==1 ? Gy : By;
101  const double R = j==1 ? Gy : By;
102  QDD(qx,dy,dz) += L * QQD(qx,qy,dz) * R;
103  }
104  }
105  }
106  }
107  MFEM_SYNC_THREAD;
108  // third tensor contraction, along x direction
109  MFEM_FOREACH_THREAD(dz,z,D1D)
110  {
111  MFEM_FOREACH_THREAD(dy,y,D1D)
112  {
113  MFEM_FOREACH_THREAD(dx,x,D1D)
114  {
115  double d = 0.0;
116  MFEM_UNROLL(MQ1)
117  for (int qx = 0; qx < Q1D; ++qx)
118  {
119  const double Bx = B(qx,dx);
120  const double Gx = G(qx,dx);
121  const double L = i==0 ? Gx : Bx;
122  const double R = j==0 ? Gx : Bx;
123  d += L * QDD(qx,dy,dz) * R;
124  }
125  D(dx,dy,dz,v,e) += d;
126  }
127  }
128  }
129  MFEM_SYNC_THREAD;
130  }
131  }
132  }
133  });
134 }
135 
137 {
138  const int N = PA.ne;
139  const int D1D = PA.maps->ndof;
140  const int Q1D = PA.maps->nqpt;
141  const int id = (D1D << 4 ) | Q1D;
142  const DenseTensor &J = PA.Jtr;
143  const Array<double> &B = PA.maps->B;
144  const Array<double> &G = PA.maps->G;
145  const Vector &H = PA.H;
146 
147  MFEM_LAUNCH_TMOP_KERNEL(AssembleDiagonalPA_Kernel_3D,id,N,B,G,J,H,D);
148 }
149 
150 } // namespace mfem
struct mfem::TMOP_Integrator::@23 PA
const double * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
Definition: densemat.hpp:1087
constexpr int DIM
const int MAX_Q1D
Definition: forall.hpp:29
void AssembleDiagonalPA_3D(Vector &) const
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
A basic generic Tensor class, appropriate for use on the GPU.
Definition: dtensor.hpp:81
virtual double * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:465
const int MAX_D1D
Definition: forall.hpp:28
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