MFEM  v4.6.0
Finite element discretization library
tmop_pa_h2s_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(void, SetupGradPA_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  Vector &h0_,
33  const bool exp_lim,
34  const int d1d,
35  const int q1d)
36 {
37  constexpr int DIM = 2;
38  constexpr int NBZ = 1;
39  const int D1D = T_D1D ? T_D1D : d1d;
40  const int Q1D = T_Q1D ? T_Q1D : q1d;
41 
42  const bool const_c0 = c0_.Size() == 1;
43  const auto C0 = const_c0 ?
44  Reshape(c0_.Read(), 1, 1, 1) :
45  Reshape(c0_.Read(), Q1D, Q1D, NE);
46  const auto LD = Reshape(lim_dist.Read(), D1D, D1D, NE);
47  const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, NE);
48  const auto b = Reshape(b_.Read(), Q1D, D1D);
49  const auto bld = Reshape(bld_.Read(), Q1D, D1D);
50  const auto W = Reshape(w_.Read(), Q1D, Q1D);
51  const auto X0 = Reshape(x0_.Read(), D1D, D1D, DIM, NE);
52  const auto X1 = Reshape(x1_.Read(), D1D, D1D, DIM, NE);
53 
54  auto H0 = Reshape(h0_.Write(), DIM, DIM, Q1D, Q1D, NE);
55 
56  mfem::forall_2D_batch(NE, Q1D, Q1D, NBZ, [=] MFEM_HOST_DEVICE (int e)
57  {
58  const int D1D = T_D1D ? T_D1D : d1d;
59  const int Q1D = T_Q1D ? T_Q1D : q1d;
60  constexpr int NBZ = 1;
61  constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
62  constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
63 
64  MFEM_SHARED double B[MQ1*MD1];
65  MFEM_SHARED double BLD[MQ1*MD1];
66 
67  MFEM_SHARED double XY[NBZ][MD1*MD1];
68  MFEM_SHARED double DQ[NBZ][MD1*MQ1];
69  MFEM_SHARED double QQ[NBZ][MQ1*MQ1];
70 
71  MFEM_SHARED double XY0[2][NBZ][MD1*MD1];
72  MFEM_SHARED double DQ0[2][NBZ][MD1*MQ1];
73  MFEM_SHARED double QQ0[2][NBZ][MQ1*MQ1];
74 
75  MFEM_SHARED double XY1[2][NBZ][MD1*MD1];
76  MFEM_SHARED double DQ1[2][NBZ][MD1*MQ1];
77  MFEM_SHARED double QQ1[2][NBZ][MQ1*MQ1];
78 
79  kernels::internal::LoadX<MD1,NBZ>(e,D1D,LD,XY);
80  kernels::internal::LoadX<MD1,NBZ>(e,D1D,X0,XY0);
81  kernels::internal::LoadX<MD1,NBZ>(e,D1D,X1,XY1);
82 
83  kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,b,B);
84  kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,bld,BLD);
85 
86  kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,BLD,XY,DQ);
87  kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,BLD,DQ,QQ);
88 
89  kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,B,XY0,DQ0);
90  kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ0,QQ0);
91 
92  kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,B,XY1,DQ1);
93  kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ1,QQ1);
94 
95  MFEM_FOREACH_THREAD(qy,y,Q1D)
96  {
97  MFEM_FOREACH_THREAD(qx,x,Q1D)
98  {
99  const double *Jtr = &J(0,0,qx,qy,e);
100  const double detJtr = kernels::Det<2>(Jtr);
101  const double weight = W(qx,qy) * detJtr;
102  const double coeff0 = const_c0 ? C0(0,0,0) : C0(qx,qy,e);
103  const double weight_m = weight * lim_normal * coeff0;
104 
105  double D, p0[2], p1[2];
106  kernels::internal::PullEval<MQ1,NBZ>(Q1D,qx,qy,QQ,D);
107  kernels::internal::PullEval<MQ1,NBZ>(Q1D,qx,qy,QQ0,p0);
108  kernels::internal::PullEval<MQ1,NBZ>(Q1D,qx,qy,QQ1,p1);
109 
110  const double dist = D; // GetValues, default comp set to 0
111 
112  // lim_func->Eval_d2(p1, p0, d_vals(q), grad_grad);
113  double grad_grad[4];
114 
115  if (!exp_lim)
116  {
117  // d2.Diag(1.0 / (dist * dist), x.Size());
118  const double c = 1.0 / (dist * dist);
119  kernels::Diag<2>(c, grad_grad);
120  }
121  else
122  {
123  double tmp[2];
124  kernels::Subtract<2>(1.0, p1, p0, tmp);
125  double dsq = kernels::DistanceSquared<2>(p1,p0);
126  double dist_squared = dist*dist;
127  double dist_squared_squared = dist_squared*dist_squared;
128  double f = exp(10.0*((dsq / dist_squared)-1.0));
129  grad_grad[0] = ((400.0*tmp[0]*tmp[0]*f)/dist_squared_squared)+
130  (20.0*f/dist_squared);
131  grad_grad[1] = (400.0*tmp[0]*tmp[1]*f)/dist_squared_squared;
132  grad_grad[2] = grad_grad[1];
133  grad_grad[3] = ((400.0*tmp[1]*tmp[1]*f)/dist_squared_squared)+
134  (20.0*f/dist_squared);
135  }
136  ConstDeviceMatrix gg(grad_grad,DIM,DIM);
137 
138  for (int i = 0; i < DIM; i++)
139  {
140  for (int j = 0; j < DIM; j++)
141  {
142  H0(i,j,qx,qy,e) = weight_m * gg(i,j);
143  }
144  }
145  }
146  }
147  });
148 }
149 
151 {
152  MFEM_CONTRACT_VAR(X);
153  const int N = PA.ne;
154  const int D1D = PA.maps_lim->ndof;
155  const int Q1D = PA.maps_lim->nqpt;
156  const int id = (D1D << 4 ) | Q1D;
157  const double ln = lim_normal;
158  const Vector &LD = PA.LD;
159  const DenseTensor &J = PA.Jtr;
160  const Array<double> &W = PA.ir->GetWeights();
161  const Array<double> &B = PA.maps->B;
162  const Array<double> &BLD = PA.maps_lim->B;
163  const Vector &C0 = PA.C0;
164  const Vector &X0 = PA.X0;
165  Vector &H0 = PA.H0;
166 
167  auto el = dynamic_cast<TMOP_ExponentialLimiter *>(lim_func);
168  const bool exp_lim = (el) ? true : false;
169 
170  MFEM_LAUNCH_TMOP_KERNEL(SetupGradPA_C0_2D,id,ln,LD,C0,N,J,W,B,BLD,X0,X,H0,
171  exp_lim);
172 }
173 
174 } // 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
std::function< double(const Vector &)> f(double mass_coeff)
Definition: lor_mms.hpp:30
void AssembleGradPA_C0_2D(const Vector &) const
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
A basic generic Tensor class, appropriate for use on the GPU.
Definition: dtensor.hpp:81
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