MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
tmop_pa_p2_c0.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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"
17
18namespace mfem
19{
20
21MFEM_REGISTER_TMOP_KERNELS(void, AddMultPA_Kernel_C0_2D,
22 const real_t lim_normal,
23 const Vector &lim_dist,
24 const Vector &c0_,
25 const int NE,
26 const DenseTensor &j_,
27 const Array<real_t> &w_,
28 const Array<real_t> &b_,
29 const Array<real_t> &bld_,
30 const Vector &x0_,
31 const Vector &x1_,
32 Vector &y_,
33 const bool exp_lim,
34 const int d1d,
35 const int q1d)
36{
37 const bool const_c0 = c0_.Size() == 1;
38
39 constexpr int DIM = 2;
40 constexpr int NBZ = 1;
41
42 const int D1D = T_D1D ? T_D1D : d1d;
43 const int Q1D = T_Q1D ? T_Q1D : q1d;
44
45 const auto C0 = const_c0 ?
46 Reshape(c0_.Read(), 1, 1, 1) :
47 Reshape(c0_.Read(), Q1D, Q1D, NE);
48 const auto LD = Reshape(lim_dist.Read(), D1D, D1D, NE);
49 const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, NE);
50 const auto b = Reshape(b_.Read(), Q1D, D1D);
51 const auto bld = Reshape(bld_.Read(), Q1D, D1D);
52 const auto W = Reshape(w_.Read(), Q1D, Q1D);
53 const auto X0 = Reshape(x0_.Read(), D1D, D1D, DIM, NE);
54 const auto X1 = Reshape(x1_.Read(), D1D, D1D, DIM, NE);
55
56 auto Y = Reshape(y_.ReadWrite(), D1D, D1D, DIM, NE);
57
58 mfem::forall_2D_batch(NE, Q1D, Q1D, NBZ, [=] MFEM_HOST_DEVICE (int e)
59 {
60 const int D1D = T_D1D ? T_D1D : d1d;
61 const int Q1D = T_Q1D ? T_Q1D : q1d;
62 constexpr int NBZ = 1;
63 constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
64 constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
65
66 MFEM_SHARED real_t B[MQ1*MD1];
67 MFEM_SHARED real_t BLD[MQ1*MD1];
68
69 MFEM_SHARED real_t XY[NBZ][MD1*MD1];
70 MFEM_SHARED real_t DQ[NBZ][MD1*MQ1];
71 MFEM_SHARED real_t QQ[NBZ][MQ1*MQ1];
72
73 MFEM_SHARED real_t XY0[2][NBZ][MD1*MD1];
74 MFEM_SHARED real_t DQ0[2][NBZ][MD1*MQ1];
75 MFEM_SHARED real_t QQ0[2][NBZ][MQ1*MQ1];
76
77 MFEM_SHARED real_t XY1[2][NBZ][MD1*MD1];
78 MFEM_SHARED real_t DQ1[2][NBZ][MD1*MQ1];
79 MFEM_SHARED real_t QQ1[2][NBZ][MQ1*MQ1];
80
81 kernels::internal::LoadX<MD1,NBZ>(e,D1D,LD,XY);
82 kernels::internal::LoadX<MD1,NBZ>(e,D1D,X0,XY0);
83 kernels::internal::LoadX<MD1,NBZ>(e,D1D,X1,XY1);
84
85 kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,b,B);
86 kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,bld,BLD);
87
88 kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,BLD,XY,DQ);
89 kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,BLD,DQ,QQ);
90
91 kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,B,XY0,DQ0);
92 kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ0,QQ0);
93
94 kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,B,XY1,DQ1);
95 kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ1,QQ1);
96
97 MFEM_FOREACH_THREAD(qy,y,Q1D)
98 {
99 MFEM_FOREACH_THREAD(qx,x,Q1D)
100 {
101 const real_t *Jtr = &J(0,0,qx,qy,e);
102 const real_t detJtr = kernels::Det<2>(Jtr);
103 const real_t weight = W(qx,qy) * detJtr;
104
105 real_t ld, p0[2], p1[2];
106 const real_t 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
111 const real_t dist = ld; // GetValues, default comp set to 0
112
113 real_t d1[2];
114 // Eval_d1 (Quadratic Limiter)
115 // subtract(1.0 / (dist * dist), x, x0, d1);
116 // z = a * (x - y)
117 // grad = a * (x - x0)
118
119 // Eval_d1 (Exponential Limiter)
120 // double dist_squared = dist*dist;
121 // subtract(20.0*exp(10.0*((x.DistanceSquaredTo(x0) / dist_squared) - 1.0)) /
122 // dist_squared, x, x0, d1);
123 // z = a * (x - y)
124 // grad = a * (x - x0)
125
126 real_t a = 0.0;
127 const real_t w = weight * lim_normal * coeff0;
128 const real_t dist_squared = dist * dist;
129
130 if (!exp_lim)
131 {
132 a = 1.0 / dist_squared;
133 }
134 else
135 {
136 real_t dsq = kernels::DistanceSquared<2>(p1,p0) / dist_squared;
137 a = 20.0*exp(10.0*(dsq - 1.0))/dist_squared;
138 }
139 kernels::Subtract<2>(w*a, p1, p0, d1);
140 kernels::internal::PushEval<MQ1,NBZ>(Q1D,qx,qy,d1,QQ0);
141
142
143 }
144 }
145 MFEM_SYNC_THREAD;
146 kernels::internal::LoadBt<MD1,MQ1>(D1D,Q1D,b,B);
147 kernels::internal::EvalXt<MD1,MQ1,NBZ>(D1D,Q1D,B,QQ0,DQ0);
148 kernels::internal::EvalYt<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ0,Y,e);
149 });
150}
151
153{
154 const int N = PA.ne;
155 const int D1D = PA.maps->ndof;
156 const int Q1D = PA.maps->nqpt;
157 const int id = (D1D << 4 ) | Q1D;
158 const real_t ln = lim_normal;
159 const Vector &LD = PA.LD;
160 const DenseTensor &J = PA.Jtr;
161 const Array<real_t> &W = PA.ir->GetWeights();
162 const Array<real_t> &B = PA.maps->B;
163 const Array<real_t> &BLD = PA.maps_lim->B;
164 MFEM_VERIFY(PA.maps_lim->ndof == D1D, "");
165 MFEM_VERIFY(PA.maps_lim->nqpt == Q1D, "");
166 const Vector &X0 = PA.X0;
167 const Vector &C0 = PA.C0;
168 auto el = dynamic_cast<TMOP_ExponentialLimiter *>(lim_func);
169 const bool exp_lim = (el) ? true : false;
170
171 MFEM_LAUNCH_TMOP_KERNEL(AddMultPA_Kernel_C0_2D,id,ln,LD,C0,N,J,W,B,BLD,X0,X,Y,
172 exp_lim);
173}
174
175} // namespace mfem
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition array.hpp:317
Rank 3 tensor (array of matrices)
const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
Exponential limiter function in TMOP_Integrator.
Definition tmop.hpp:1224
TMOP_LimiterFunction * lim_func
Definition tmop.hpp:1765
struct mfem::TMOP_Integrator::@23 PA
void AddMultPA_C0_2D(const Vector &, Vector &) const
Vector data type.
Definition vector.hpp:80
virtual const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:474
virtual real_t * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:490
int Size() const
Returns the size of the vector.
Definition vector.hpp:218
real_t b
Definition lissajous.cpp:42
real_t a
Definition lissajous.cpp:41
constexpr int DIM
MFEM_HOST_DEVICE real_t DistanceSquared(const real_t *x, const real_t *y)
Compute the square of the Euclidean distance to another vector.
Definition kernels.hpp:40
MFEM_HOST_DEVICE T Det(const T *data)
Compute the determinant of a square matrix of size dim with given data.
Definition kernels.hpp:237
MFEM_HOST_DEVICE void Subtract(const real_t a, const real_t *x, const real_t *y, real_t *z)
Vector subtraction operation: z = a * (x - y)
Definition kernels.hpp:58
MFEM_REGISTER_TMOP_KERNELS(void, DatcSize, const int NE, const int ncomp, const int sizeidx, const real_t input_min_size, const DenseMatrix &w_, const Array< real_t > &b_, const Vector &x_, const Vector &nc_reduce, DenseTensor &j_, const int d1d, const int q1d)
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
void forall_2D_batch(int N, int X, int Y, int BZ, lambda &&body)
Definition forall.hpp:769
float real_t
Definition config.hpp:43