MFEM  v4.6.0
Finite element discretization library
tmop_pa_w2_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_2D,
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 = 2;
41  constexpr int NBZ = 1;
42 
43  const int D1D = T_D1D ? T_D1D : d1d;
44  const int Q1D = T_Q1D ? T_Q1D : q1d;
45 
46  const auto C0 = const_c0 ?
47  Reshape(c0_.Read(), 1, 1, 1) :
48  Reshape(c0_.Read(), Q1D, Q1D, NE);
49  const auto LD = Reshape(lim_dist.Read(), D1D, D1D, NE);
50  const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, NE);
51  const auto b = Reshape(b_.Read(), Q1D, D1D);
52  const auto bld = Reshape(bld_.Read(), Q1D, D1D);
53  const auto W = Reshape(w_.Read(), Q1D, Q1D);
54  const auto X0 = Reshape(x0_.Read(), D1D, D1D, DIM, NE);
55  const auto X1 = Reshape(x1_.Read(), D1D, D1D, DIM, NE);
56 
57  auto E = Reshape(energy.Write(), Q1D, Q1D, NE);
58 
59  mfem::forall_2D_batch(NE, Q1D, Q1D, NBZ, [=] MFEM_HOST_DEVICE (int e)
60  {
61  const int D1D = T_D1D ? T_D1D : d1d;
62  const int Q1D = T_Q1D ? T_Q1D : q1d;
63  constexpr int NBZ = 1;
64  constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
65  constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
66 
67  MFEM_SHARED double B[MQ1*MD1];
68  MFEM_SHARED double BLD[MQ1*MD1];
69 
70  MFEM_SHARED double XY[NBZ][MD1*MD1];
71  MFEM_SHARED double DQ[NBZ][MD1*MQ1];
72  MFEM_SHARED double QQ[NBZ][MQ1*MQ1];
73 
74  MFEM_SHARED double XY0[2][NBZ][MD1*MD1];
75  MFEM_SHARED double DQ0[2][NBZ][MD1*MQ1];
76  MFEM_SHARED double QQ0[2][NBZ][MQ1*MQ1];
77 
78  MFEM_SHARED double XY1[2][NBZ][MD1*MD1];
79  MFEM_SHARED double DQ1[2][NBZ][MD1*MQ1];
80  MFEM_SHARED double QQ1[2][NBZ][MQ1*MQ1];
81 
82  kernels::internal::LoadX<MD1,NBZ>(e,D1D,LD,XY);
83  kernels::internal::LoadX<MD1,NBZ>(e,D1D,X0,XY0);
84  kernels::internal::LoadX<MD1,NBZ>(e,D1D,X1,XY1);
85 
86  kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,b,B);
87  kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,bld,BLD);
88 
89  kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,BLD,XY,DQ);
90  kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,BLD,DQ,QQ);
91 
92  kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,B,XY0,DQ0);
93  kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ0,QQ0);
94 
95  kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,B,XY1,DQ1);
96  kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ1,QQ1);
97 
98  MFEM_FOREACH_THREAD(qy,y,Q1D)
99  {
100  MFEM_FOREACH_THREAD(qx,x,Q1D)
101  {
102  double ld, p0[2], p1[2];
103  const double *Jtr = &J(0,0,qx,qy,e);
104  const double detJtr = kernels::Det<2>(Jtr);
105  const double weight = W(qx,qy) * detJtr;
106  const double coeff0 = const_c0 ? C0(0,0,0) : C0(qx,qy,e);
107  kernels::internal::PullEval<MQ1,NBZ>(Q1D,qx,qy,QQ,ld);
108  kernels::internal::PullEval<MQ1,NBZ>(Q1D,qx,qy,QQ0,p0);
109  kernels::internal::PullEval<MQ1,NBZ>(Q1D,qx,qy,QQ1,p1);
110  const double dist = ld; // GetValues, default comp set to 0
111  double id2 = 0.0;
112  double dsq = 0.0;
113  if (!exp_lim)
114  {
115  id2 = 0.5 / (dist*dist);
116  dsq = kernels::DistanceSquared<2>(p1,p0) * id2;
117  E(qx,qy,e) = weight * lim_normal * dsq * coeff0;
118  }
119  else
120  {
121  id2 = 1.0 / (dist*dist);
122  dsq = kernels::DistanceSquared<2>(p1,p0) * id2;
123  E(qx,qy,e) = weight * lim_normal * exp(10.0*(dsq-1.0)) * coeff0;
124  }
125  }
126  }
127  });
128  return energy * ones;
129 }
130 
132 {
133  const int N = PA.ne;
134  const int D1D = PA.maps->ndof;
135  const int Q1D = PA.maps->nqpt;
136  const int id = (D1D << 4 ) | Q1D;
137  const double ln = lim_normal;
138  const Vector &LD = PA.LD;
139  const DenseTensor &J = PA.Jtr;
140  const Array<double> &W = PA.ir->GetWeights();
141  const Array<double> &B = PA.maps->B;
142  const Array<double> &BLD = PA.maps_lim->B;
143  MFEM_VERIFY(PA.maps_lim->ndof == D1D, "");
144  MFEM_VERIFY(PA.maps_lim->nqpt == Q1D, "");
145  const Vector &X0 = PA.X0;
146  const Vector &C0 = PA.C0;
147  const Vector &O = PA.O;
148  Vector &E = PA.E;
149 
150  auto el = dynamic_cast<TMOP_ExponentialLimiter *>(lim_func);
151  const bool exp_lim = (el) ? true : false;
152 
153  MFEM_LAUNCH_TMOP_KERNEL(EnergyPA_C0_2D,id,ln,LD,C0,N,J,W,B,BLD,X0,X,O,E,
154  exp_lim);
155 }
156 
157 } // 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:197
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
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
virtual double * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:461
double b
Definition: lissajous.cpp:42
void forall_2D_batch(int N, int X, int Y, int BZ, lambda &&body)
Definition: forall.hpp:757
double GetLocalStateEnergyPA_C0_2D(const Vector &) const
Exponential limiter function in TMOP_Integrator.
Definition: tmop.hpp:1219
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
TMOP_LimiterFunction * lim_func
Definition: tmop.hpp:1761