MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
tmop_pa_p2_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, AddMultPA_Kernel_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 &y_,
33  const int d1d,
34  const int q1d)
35 {
36  const bool const_c0 = c0_.Size() == 1;
37 
38  constexpr int DIM = 2;
39  constexpr int NBZ = 1;
40 
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) :
46  Reshape(c0_.Read(), Q1D, Q1D, NE);
47  const auto LD = Reshape(lim_dist.Read(), D1D, D1D, NE);
48  const auto J = Reshape(j_.Read(), DIM, DIM, 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);
52  const auto X0 = Reshape(x0_.Read(), D1D, D1D, DIM, NE);
53  const auto X1 = Reshape(x1_.Read(), D1D, D1D, DIM, NE);
54 
55  auto Y = Reshape(y_.ReadWrite(), D1D, D1D, DIM, NE);
56 
57  MFEM_FORALL_2D(e, NE, Q1D, Q1D, NBZ,
58  {
59  const int D1D = T_D1D ? T_D1D : d1d;
60  const int Q1D = T_Q1D ? T_Q1D : q1d;
61  constexpr int NBZ = 1;
62  constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
63  constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
64 
65  MFEM_SHARED double B[MQ1*MD1];
66  MFEM_SHARED double BLD[MQ1*MD1];
67 
68  MFEM_SHARED double XY[NBZ][MD1*MD1];
69  MFEM_SHARED double DQ[NBZ][MD1*MQ1];
70  MFEM_SHARED double QQ[NBZ][MQ1*MQ1];
71 
72  MFEM_SHARED double XY0[2][NBZ][MD1*MD1];
73  MFEM_SHARED double DQ0[2][NBZ][MD1*MQ1];
74  MFEM_SHARED double QQ0[2][NBZ][MQ1*MQ1];
75 
76  MFEM_SHARED double XY1[2][NBZ][MD1*MD1];
77  MFEM_SHARED double DQ1[2][NBZ][MD1*MQ1];
78  MFEM_SHARED double QQ1[2][NBZ][MQ1*MQ1];
79 
80  kernels::internal::LoadX<MD1,NBZ>(e,D1D,LD,XY);
81  kernels::internal::LoadX<MD1,NBZ>(e,D1D,X0,XY0);
82  kernels::internal::LoadX<MD1,NBZ>(e,D1D,X1,XY1);
83 
84  kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,b,B);
85  kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,bld,BLD);
86 
87  kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,BLD,XY,DQ);
88  kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,BLD,DQ,QQ);
89 
90  kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,B,XY0,DQ0);
91  kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ0,QQ0);
92 
93  kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,B,XY1,DQ1);
94  kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ1,QQ1);
95 
96  MFEM_FOREACH_THREAD(qy,y,Q1D)
97  {
98  MFEM_FOREACH_THREAD(qx,x,Q1D)
99  {
100  const double *Jtr = &J(0,0,qx,qy,e);
101  const double detJtr = kernels::Det<2>(Jtr);
102  const double weight = W(qx,qy) * detJtr;
103 
104  double ld, p0[2], p1[2];
105  const double coeff0 = const_c0 ? C0(0,0,0) : C0(qx,qy,e);
106  kernels::internal::PullEval<MQ1,NBZ>(Q1D,qx,qy,QQ,ld);
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 = ld; // GetValues, default comp set to 0
111 
112  double d1[2];
113  // Eval_d1
114  // subtract(1.0 / (dist * dist), x, x0, d1);
115  // z = a * (x - y)
116  // grad = a * (x - x0)
117  const double a = 1.0 / (dist * dist);
118  const double w = weight * lim_normal * coeff0;
119  kernels::Subtract<2>(w*a, p1, p0, d1);
120  kernels::internal::PushEval<MQ1,NBZ>(Q1D,qx,qy,d1,QQ0);
121  }
122  }
123  MFEM_SYNC_THREAD;
124  kernels::internal::LoadBt<MD1,MQ1>(D1D,Q1D,b,B);
125  kernels::internal::EvalXt<MD1,MQ1,NBZ>(D1D,Q1D,B,QQ0,DQ0);
126  kernels::internal::EvalYt<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ0,Y,e);
127  });
128 }
129 
131 {
132  const int N = PA.ne;
133  const int D1D = PA.maps->ndof;
134  const int Q1D = PA.maps->nqpt;
135  const int id = (D1D << 4 ) | Q1D;
136  const double ln = lim_normal;
137  const Vector &LD = PA.LD;
138  const DenseTensor &J = PA.Jtr;
139  const Array<double> &W = PA.ir->GetWeights();
140  const Array<double> &B = PA.maps->B;
141  const Array<double> &BLD = PA.maps_lim->B;
142  MFEM_VERIFY(PA.maps_lim->ndof == D1D, "");
143  MFEM_VERIFY(PA.maps_lim->nqpt == Q1D, "");
144  const Vector &X0 = PA.X0;
145  const Vector &C0 = PA.C0;
146 
147  MFEM_LAUNCH_TMOP_KERNEL(AddMultPA_Kernel_C0_2D,id,ln,LD,C0,N,J,W,B,BLD,X0,X,Y);
148 }
149 
150 } // namespace mfem
void AddMultPA_C0_2D(const Vector &, Vector &) const
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
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
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition: array.hpp:304
double a
Definition: lissajous.cpp:41
virtual double * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:465
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
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