MFEM  v4.5.2
Finite element discretization library
tmop_pa_h2d.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 /* // Original i-j assembly (old invariants code).
21  for (int e = 0; e < NE; e++)
22  {
23  for (int q = 0; q < nqp; q++)
24  {
25  el.CalcDShape(ip, DSh);
26  Mult(DSh, Jrt, DS);
27  for (int i = 0; i < dof; i++)
28  {
29  for (int j = 0; j < dof; j++)
30  {
31  for (int r = 0; r < dim; r++)
32  {
33  for (int c = 0; c < dim; c++)
34  {
35  for (int rr = 0; rr < dim; rr++)
36  {
37  for (int cc = 0; cc < dim; cc++)
38  {
39  const double H = h(r, c, rr, cc);
40  A(e, i + r*dof, j + rr*dof) +=
41  weight_q * DS(i, c) * DS(j, cc) * H;
42  }
43  }
44  }
45  }
46  }
47  }
48  }
49  }*/
50 
51 MFEM_REGISTER_TMOP_KERNELS(void, AssembleDiagonalPA_Kernel_2D,
52  const int NE,
53  const Array<double> &b,
54  const Array<double> &g,
55  const DenseTensor &j,
56  const Vector &h,
57  Vector &diagonal,
58  const int d1d,
59  const int q1d)
60 {
61  constexpr int DIM = 2;
62  const int D1D = T_D1D ? T_D1D : d1d;
63  const int Q1D = T_Q1D ? T_Q1D : q1d;
64 
65  const auto B = Reshape(b.Read(), Q1D, D1D);
66  const auto G = Reshape(g.Read(), Q1D, D1D);
67  const auto J = Reshape(j.Read(), DIM, DIM, Q1D, Q1D, NE);
68  const auto H = Reshape(h.Read(), DIM, DIM, DIM, DIM, Q1D, Q1D, NE);
69 
70  auto D = Reshape(diagonal.ReadWrite(), D1D, D1D, DIM, NE);
71 
72  MFEM_FORALL_2D(e, NE, Q1D, Q1D, 1,
73  {
74  constexpr int DIM = 2;
75  const int D1D = T_D1D ? T_D1D : d1d;
76  const int Q1D = T_Q1D ? T_Q1D : q1d;
77  constexpr int MD1 = T_D1D ? T_D1D : MAX_D1D;
78  constexpr int MQ1 = T_Q1D ? T_Q1D : MAX_Q1D;
79 
80  MFEM_SHARED double qd[DIM*DIM*MQ1*MD1];
81  DeviceTensor<4,double> QD(qd, DIM, DIM, MQ1, MD1);
82 
83  for (int v = 0; v < DIM; v++)
84  {
85  MFEM_FOREACH_THREAD(qx,x,Q1D)
86  {
87  MFEM_FOREACH_THREAD(dy,y,D1D)
88  {
89  QD(0,0,qx,dy) = 0.0;
90  QD(0,1,qx,dy) = 0.0;
91  QD(1,0,qx,dy) = 0.0;
92  QD(1,1,qx,dy) = 0.0;
93 
94  MFEM_UNROLL(MQ1)
95  for (int qy = 0; qy < Q1D; ++qy)
96  {
97  const double *Jtr = &J(0,0,qx,qy,e);
98 
99  // Jrt = Jtr^{-1}
100  double jrt_data[4];
101  ConstDeviceMatrix Jrt(jrt_data,2,2);
102  kernels::CalcInverse<2>(Jtr, jrt_data);
103 
104  const double gg = G(qy,dy) * G(qy,dy);
105  const double gb = G(qy,dy) * B(qy,dy);
106  const double bb = B(qy,dy) * B(qy,dy);
107  const double bgb[4] = { bb, gb, gb, gg };
108  ConstDeviceMatrix BG(bgb,2,2);
109 
110  for (int i = 0; i < DIM; i++)
111  {
112  for (int j = 0; j < DIM; j++)
113  {
114  const double Jij = Jrt(i,i) * Jrt(j,j);
115  const double alpha = Jij * BG(i,j);
116  QD(i,j,qx,dy) += alpha * H(v,i,v,j,qx,qy,e);
117  }
118  }
119  }
120  }
121  }
122  MFEM_SYNC_THREAD;
123  MFEM_FOREACH_THREAD(dy,y,D1D)
124  {
125  MFEM_FOREACH_THREAD(dx,x,D1D)
126  {
127  double d = 0.0;
128  MFEM_UNROLL(MQ1)
129  for (int qx = 0; qx < Q1D; ++qx)
130  {
131  const double gg = G(qx,dx) * G(qx,dx);
132  const double gb = G(qx,dx) * B(qx,dx);
133  const double bb = B(qx,dx) * B(qx,dx);
134  d += gg * QD(0,0,qx,dy);
135  d += gb * QD(0,1,qx,dy);
136  d += gb * QD(1,0,qx,dy);
137  d += bb * QD(1,1,qx,dy);
138  }
139  D(dx,dy,v,e) += d;
140  }
141  }
142  MFEM_SYNC_THREAD;
143  }
144  });
145 }
146 
148 {
149  const int N = PA.ne;
150  const int D1D = PA.maps->ndof;
151  const int Q1D = PA.maps->nqpt;
152  const int id = (D1D << 4 ) | Q1D;
153  const DenseTensor &J = PA.Jtr;
154  const Array<double> &B = PA.maps->B;
155  const Array<double> &G = PA.maps->G;
156  const Vector &H = PA.H;
157 
158  MFEM_LAUNCH_TMOP_KERNEL(AssembleDiagonalPA_Kernel_2D,id,N,B,G,J,H,D);
159 }
160 
161 } // namespace mfem
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition: array.hpp:307
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:448
constexpr int DIM
const double * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
Definition: densemat.hpp:1112
const int MAX_Q1D
Definition: forall.hpp:29
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
A basic generic Tensor class, appropriate for use on the GPU.
Definition: dtensor.hpp:81
void AssembleDiagonalPA_2D(Vector &) const
virtual double * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:464
const int MAX_D1D
Definition: forall.hpp:28
const double alpha
Definition: ex15.cpp:369
Vector data type.
Definition: vector.hpp:60
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:978