MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
tmop_pa_h3s_c0.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 
18 namespace mfem
19 {
20 
21 MFEM_REGISTER_TMOP_KERNELS(void, SetupGradPA_Kernel_C0_3D,
22  const double lim_normal,
23  const Vector &lim_dist,
24  const Vector &c0_,
25  const int NE,
26  const DenseTensor &j_,
27  const Array<double> &w_,
28  const Array<double> &bld_,
29  Vector &h0_,
30  const int d1d,
31  const int q1d)
32 {
33  constexpr int DIM = 3;
34  const int D1D = T_D1D ? T_D1D : d1d;
35  const int Q1D = T_Q1D ? T_Q1D : q1d;
36 
37  const bool const_c0 = c0_.Size() == 1;
38  const auto C0 = const_c0 ?
39  Reshape(c0_.Read(), 1, 1, 1, 1) :
40  Reshape(c0_.Read(), Q1D, Q1D, Q1D, NE);
41  const auto LD = Reshape(lim_dist.Read(), D1D, D1D, D1D, NE);
42  const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, Q1D, NE);
43  const auto W = Reshape(w_.Read(), Q1D, Q1D, Q1D);
44  const auto bld = Reshape(bld_.Read(), Q1D, D1D);
45 
46  auto H0 = Reshape(h0_.Write(), DIM, DIM, Q1D, Q1D, Q1D, NE);
47 
48  MFEM_FORALL_3D(e, NE, Q1D, Q1D, Q1D,
49  {
50  constexpr int DIM = 3;
51  const int D1D = T_D1D ? T_D1D : d1d;
52  const int Q1D = T_Q1D ? T_Q1D : q1d;
53  constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
54  constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
55  constexpr int MDQ = (MQ1 > MD1) ? MQ1 : MD1;
56 
57  MFEM_SHARED double sBLD[MQ1*MD1];
58  kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,bld,sBLD);
59  ConstDeviceMatrix BLD(sBLD, D1D, Q1D);
60 
61  MFEM_SHARED double sm0[MDQ*MDQ*MDQ];
62  MFEM_SHARED double sm1[MDQ*MDQ*MDQ];
63  DeviceCube DDD(sm0, MD1,MD1,MD1);
64  DeviceCube DDQ(sm1, MD1,MD1,MQ1);
65  DeviceCube DQQ(sm0, MD1,MQ1,MQ1);
66  DeviceCube QQQ(sm1, MQ1,MQ1,MQ1);
67 
68  kernels::internal::LoadX(e,D1D,LD,DDD);
69 
70  kernels::internal::EvalX(D1D,Q1D,BLD,DDD,DDQ);
71  kernels::internal::EvalY(D1D,Q1D,BLD,DDQ,DQQ);
72  kernels::internal::EvalZ(D1D,Q1D,BLD,DQQ,QQQ);
73 
74  MFEM_FOREACH_THREAD(qz,z,Q1D)
75  {
76  MFEM_FOREACH_THREAD(qy,y,Q1D)
77  {
78  MFEM_FOREACH_THREAD(qx,x,Q1D)
79  {
80  const double *Jtr = &J(0,0,qx,qy,qz,e);
81  const double detJtr = kernels::Det<3>(Jtr);
82  const double weight = W(qx,qy,qz) * detJtr;
83  const double coeff0 = const_c0 ? C0(0,0,0,0) : C0(qx,qy,qz,e);
84  const double weight_m = weight * lim_normal * coeff0;
85 
86  double D;
87  kernels::internal::PullEval(qx,qy,qz,QQQ,D);
88  const double dist = D; // GetValues, default comp set to 0
89 
90  // lim_func->Eval_d2(p1, p0, d_vals(q), grad_grad);
91  // d2.Diag(1.0 / (dist * dist), x.Size());
92  const double c = 1.0 / (dist * dist);
93  double grad_grad[9];
94  kernels::Diag<3>(c, grad_grad);
95  ConstDeviceMatrix gg(grad_grad,DIM,DIM);
96 
97  for (int i = 0; i < DIM; i++)
98  {
99  for (int j = 0; j < DIM; j++)
100  {
101  H0(i,j,qx,qy,qz,e) = weight_m * gg(i,j);
102  }
103  }
104  }
105  }
106  }
107  });
108 }
109 
111 {
112  const int N = PA.ne;
113  const int D1D = PA.maps_lim->ndof;
114  const int Q1D = PA.maps_lim->nqpt;
115  const int id = (D1D << 4 ) | Q1D;
116  const double ln = lim_normal;
117  const Vector &LD = PA.LD;
118  const DenseTensor &J = PA.Jtr;
119  const Array<double> &W = PA.ir->GetWeights();
120  const Array<double> &BLD = PA.maps_lim->B;
121  const Vector &C0 = PA.C0;
122  Vector &H0 = PA.H0;
123 
124  MFEM_LAUNCH_TMOP_KERNEL(SetupGradPA_Kernel_C0_3D,id,ln,LD,C0,N,J,W,BLD,H0);
125 }
126 
127 } // 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
int Size() const
Returns the size of the vector.
Definition: vector.hpp:200
constexpr int DIM
virtual double * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:457
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
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
void AssembleGradPA_C0_3D(const Vector &) const
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