MFEM  v4.5.2
Finite element discretization library
tmop_pa_w3_c0.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 "../linearform.hpp"
15 #include "../../general/forall.hpp"
16 #include "../../linalg/kernels.hpp"
17 
18 namespace mfem
19 {
20 
21 MFEM_REGISTER_TMOP_KERNELS(double, EnergyPA_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> &b_,
29  const Array<double> &bld_,
30  const Vector &x0_,
31  const Vector &x1_,
32  const Vector &ones,
33  Vector &energy,
34  const bool exp_lim,
35  const int d1d,
36  const int q1d)
37 {
38  const bool const_c0 = c0_.Size() == 1;
39 
40  constexpr int DIM = 3;
41  const int D1D = T_D1D ? T_D1D : d1d;
42  const int Q1D = T_Q1D ? T_Q1D : q1d;
43 
44  const auto C0 = const_c0 ?
45  Reshape(c0_.Read(), 1, 1, 1, 1) :
46  Reshape(c0_.Read(), Q1D, Q1D, Q1D, NE);
47  const auto LD = Reshape(lim_dist.Read(), D1D, D1D, D1D, NE);
48  const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, Q1D, NE);
49  const auto b = Reshape(b_.Read(), Q1D, D1D);
50  const auto bld = Reshape(bld_.Read(), Q1D, D1D);
51  const auto W = Reshape(w_.Read(), Q1D, Q1D, Q1D);
52  const auto X0 = Reshape(x0_.Read(), D1D, D1D, D1D, DIM, NE);
53  const auto X1 = Reshape(x1_.Read(), D1D, D1D, D1D, DIM, NE);
54 
55  auto E = Reshape(energy.Write(), Q1D, Q1D, Q1D, NE);
56 
57  MFEM_FORALL_3D(e, NE, Q1D, Q1D, Q1D,
58  {
59  const int D1D = T_D1D ? T_D1D : d1d;
60  const int Q1D = T_Q1D ? T_Q1D : q1d;
61  constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
62  constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
63  constexpr int MDQ = (MQ1 > MD1) ? MQ1 : MD1;
64 
65  MFEM_SHARED double B[MQ1*MD1];
66  MFEM_SHARED double sBLD[MQ1*MD1];
67  kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,bld,sBLD);
68  ConstDeviceMatrix BLD(sBLD, D1D, Q1D);
69 
70  MFEM_SHARED double sm0[MDQ*MDQ*MDQ];
71  MFEM_SHARED double sm1[MDQ*MDQ*MDQ];
72  DeviceCube DDD(sm0, MD1,MD1,MD1);
73  DeviceCube DDQ(sm1, MD1,MD1,MQ1);
74  DeviceCube DQQ(sm0, MD1,MQ1,MQ1);
75  DeviceCube QQQ(sm1, MQ1,MQ1,MQ1);
76 
77  MFEM_SHARED double DDD0[3][MD1*MD1*MD1];
78  MFEM_SHARED double DDQ0[3][MD1*MD1*MQ1];
79  MFEM_SHARED double DQQ0[3][MD1*MQ1*MQ1];
80  MFEM_SHARED double QQQ0[3][MQ1*MQ1*MQ1];
81 
82  MFEM_SHARED double DDD1[3][MD1*MD1*MD1];
83  MFEM_SHARED double DDQ1[3][MD1*MD1*MQ1];
84  MFEM_SHARED double DQQ1[3][MD1*MQ1*MQ1];
85  MFEM_SHARED double QQQ1[3][MQ1*MQ1*MQ1];
86 
87  kernels::internal::LoadX(e,D1D,LD,DDD);
88  kernels::internal::LoadX<MD1>(e,D1D,X0,DDD0);
89  kernels::internal::LoadX<MD1>(e,D1D,X1,DDD1);
90 
91  kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,b,B);
92 
93  kernels::internal::EvalX(D1D,Q1D,BLD,DDD,DDQ);
94  kernels::internal::EvalY(D1D,Q1D,BLD,DDQ,DQQ);
95  kernels::internal::EvalZ(D1D,Q1D,BLD,DQQ,QQQ);
96 
97  kernels::internal::EvalX<MD1,MQ1>(D1D,Q1D,B,DDD0,DDQ0);
98  kernels::internal::EvalY<MD1,MQ1>(D1D,Q1D,B,DDQ0,DQQ0);
99  kernels::internal::EvalZ<MD1,MQ1>(D1D,Q1D,B,DQQ0,QQQ0);
100 
101  kernels::internal::EvalX<MD1,MQ1>(D1D,Q1D,B,DDD1,DDQ1);
102  kernels::internal::EvalY<MD1,MQ1>(D1D,Q1D,B,DDQ1,DQQ1);
103  kernels::internal::EvalZ<MD1,MQ1>(D1D,Q1D,B,DQQ1,QQQ1);
104 
105  MFEM_FOREACH_THREAD(qz,z,Q1D)
106  {
107  MFEM_FOREACH_THREAD(qy,y,Q1D)
108  {
109  MFEM_FOREACH_THREAD(qx,x,Q1D)
110  {
111  double D, p0[3], p1[3];
112  const double *Jtr = &J(0,0,qx,qy,qz,e);
113  const double detJtr = kernels::Det<3>(Jtr);
114  const double weight = W(qx,qy,qz) * detJtr;
115  const double coeff0 = const_c0 ? C0(0,0,0,0) : C0(qx,qy,qz,e);
116 
117  kernels::internal::PullEval(qx,qy,qz,QQQ,D);
118  kernels::internal::PullEval<MQ1>(Q1D,qx,qy,qz,QQQ0,p0);
119  kernels::internal::PullEval<MQ1>(Q1D,qx,qy,qz,QQQ1,p1);
120 
121  const double dist = D; // GetValues, default comp set to 0
122  double id2 = 0.0;
123  double dsq = 0.0;
124  if (!exp_lim)
125  {
126  id2 = 0.5 / (dist*dist);
127  dsq = kernels::DistanceSquared<3>(p1,p0) * id2;
128  E(qx,qy,qz,e) = weight * lim_normal * dsq * coeff0;
129  }
130  else
131  {
132  id2 = 1.0 / (dist*dist);
133  dsq = kernels::DistanceSquared<3>(p1,p0) * id2;
134  E(qx,qy,qz,e) = weight * lim_normal * exp(10.0*(dsq-1.0)) * coeff0;
135  }
136  }
137  }
138  }
139  });
140  return energy * ones;
141 }
142 
144 {
145  const int N = PA.ne;
146  const int D1D = PA.maps->ndof;
147  const int Q1D = PA.maps->nqpt;
148  const int id = (D1D << 4 ) | Q1D;
149  const double ln = lim_normal;
150  const Vector &LD = PA.LD;
151  const DenseTensor &J = PA.Jtr;
152  const Array<double> &W = PA.ir->GetWeights();
153  const Array<double> &B = PA.maps->B;
154  const Array<double> &BLD = PA.maps_lim->B;
155  MFEM_VERIFY(PA.maps_lim->ndof == D1D, "");
156  MFEM_VERIFY(PA.maps_lim->nqpt == Q1D, "");
157  const Vector &X0 = PA.X0;
158  const Vector &C0 = PA.C0;
159  const Vector &O = PA.O;
160  Vector &E = PA.E;
161 
162  auto el = dynamic_cast<TMOP_ExponentialLimiter *>(lim_func);
163  const bool exp_lim = (el) ? true : false;
164 
165  MFEM_LAUNCH_TMOP_KERNEL(EnergyPA_C0_3D,id,ln,LD,C0,N,J,W,B,BLD,X0,X,O,E,
166  exp_lim);
167 }
168 
169 } // 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
int Size() const
Returns the size of the vector.
Definition: vector.hpp:199
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
double GetLocalStateEnergyPA_C0_3D(const Vector &) const
const double * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
Definition: densemat.hpp:1112
virtual double * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:456
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
Exponential limiter function in TMOP_Integrator.
Definition: tmop.hpp:1124
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
TMOP_LimiterFunction * lim_func
Definition: tmop.hpp:1665