MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
tmop_pa_h3s_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, SetupGradPA_Kernel_C0_3D,
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 &h0_,
33 const bool exp_lim,
34 const int d1d,
35 const int q1d)
36{
37 constexpr int DIM = 3;
38 const int D1D = T_D1D ? T_D1D : d1d;
39 const int Q1D = T_Q1D ? T_Q1D : q1d;
40
41 const bool const_c0 = c0_.Size() == 1;
42 const auto C0 = const_c0 ?
43 Reshape(c0_.Read(), 1, 1, 1, 1) :
44 Reshape(c0_.Read(), Q1D, Q1D, Q1D, NE);
45 const auto LD = Reshape(lim_dist.Read(), D1D, D1D, D1D, NE);
46 const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, Q1D, NE);
47 const auto b = Reshape(b_.Read(), Q1D, D1D);
48 const auto bld = Reshape(bld_.Read(), Q1D, D1D);
49 const auto W = Reshape(w_.Read(), Q1D, Q1D, Q1D);
50 const auto X0 = Reshape(x0_.Read(), D1D, D1D, D1D, DIM, NE);
51 const auto X1 = Reshape(x1_.Read(), D1D, D1D, D1D, DIM, NE);
52
53 auto H0 = Reshape(h0_.Write(), DIM, DIM, Q1D, Q1D, Q1D, NE);
54
55 mfem::forall_3D(NE, Q1D, Q1D, Q1D, [=] MFEM_HOST_DEVICE (int e)
56 {
57 constexpr int DIM = 3;
58 const int D1D = T_D1D ? T_D1D : d1d;
59 const int Q1D = T_Q1D ? T_Q1D : q1d;
60 constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
61 constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
62 constexpr int MDQ = (MQ1 > MD1) ? MQ1 : MD1;
63
64 MFEM_SHARED real_t B[MQ1*MD1];
65 MFEM_SHARED real_t sBLD[MQ1*MD1];
66 kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,bld,sBLD);
67 ConstDeviceMatrix BLD(sBLD, D1D, Q1D);
68
69 MFEM_SHARED real_t sm0[MDQ*MDQ*MDQ];
70 MFEM_SHARED real_t sm1[MDQ*MDQ*MDQ];
71 DeviceCube DDD(sm0, MD1,MD1,MD1);
72 DeviceCube DDQ(sm1, MD1,MD1,MQ1);
73 DeviceCube DQQ(sm0, MD1,MQ1,MQ1);
74 DeviceCube QQQ(sm1, MQ1,MQ1,MQ1);
75
76 MFEM_SHARED real_t DDD0[3][MD1*MD1*MD1];
77 MFEM_SHARED real_t DDQ0[3][MD1*MD1*MQ1];
78 MFEM_SHARED real_t DQQ0[3][MD1*MQ1*MQ1];
79 MFEM_SHARED real_t QQQ0[3][MQ1*MQ1*MQ1];
80
81 MFEM_SHARED real_t DDD1[3][MD1*MD1*MD1];
82 MFEM_SHARED real_t DDQ1[3][MD1*MD1*MQ1];
83 MFEM_SHARED real_t DQQ1[3][MD1*MQ1*MQ1];
84 MFEM_SHARED real_t QQQ1[3][MQ1*MQ1*MQ1];
85
86 kernels::internal::LoadX(e,D1D,LD,DDD);
87 kernels::internal::LoadX<MD1>(e,D1D,X0,DDD0);
88 kernels::internal::LoadX<MD1>(e,D1D,X1,DDD1);
89
90 kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,b,B);
91
92 kernels::internal::EvalX(D1D,Q1D,BLD,DDD,DDQ);
93 kernels::internal::EvalY(D1D,Q1D,BLD,DDQ,DQQ);
94 kernels::internal::EvalZ(D1D,Q1D,BLD,DQQ,QQQ);
95
96 kernels::internal::EvalX<MD1,MQ1>(D1D,Q1D,B,DDD0,DDQ0);
97 kernels::internal::EvalY<MD1,MQ1>(D1D,Q1D,B,DDQ0,DQQ0);
98 kernels::internal::EvalZ<MD1,MQ1>(D1D,Q1D,B,DQQ0,QQQ0);
99
100 kernels::internal::EvalX<MD1,MQ1>(D1D,Q1D,B,DDD1,DDQ1);
101 kernels::internal::EvalY<MD1,MQ1>(D1D,Q1D,B,DDQ1,DQQ1);
102 kernels::internal::EvalZ<MD1,MQ1>(D1D,Q1D,B,DQQ1,QQQ1);
103
104 MFEM_FOREACH_THREAD(qz,z,Q1D)
105 {
106 MFEM_FOREACH_THREAD(qy,y,Q1D)
107 {
108 MFEM_FOREACH_THREAD(qx,x,Q1D)
109 {
110 const real_t *Jtr = &J(0,0,qx,qy,qz,e);
111 const real_t detJtr = kernels::Det<3>(Jtr);
112 const real_t weight = W(qx,qy,qz) * detJtr;
113 const real_t coeff0 = const_c0 ? C0(0,0,0,0) : C0(qx,qy,qz,e);
114 const real_t weight_m = weight * lim_normal * coeff0;
115
116 real_t D, p0[3], p1[3];
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 real_t dist = D; // GetValues, default comp set to 0
122
123 // lim_func->Eval_d2(p1, p0, d_vals(q), grad_grad);
124
125 real_t grad_grad[9];
126
127 if (!exp_lim)
128 {
129 // d2.Diag(1.0 / (dist * dist), x.Size());
130 const real_t c = 1.0 / (dist * dist);
131 kernels::Diag<3>(c, grad_grad);
132 }
133 else
134 {
135 real_t tmp[3];
136 kernels::Subtract<3>(1.0, p1, p0, tmp);
138 real_t dist_squared = dist*dist;
139 real_t dist_squared_squared = dist_squared*dist_squared;
140 real_t f = exp(10.0*((dsq / dist_squared)-1.0));
141 grad_grad[0] = ((400.0*tmp[0]*tmp[0]*f)/dist_squared_squared)+
142 (20.0*f/dist_squared);
143 grad_grad[1] = (400.0*tmp[0]*tmp[1]*f)/dist_squared_squared;
144 grad_grad[2] = (400.0*tmp[0]*tmp[2]*f)/dist_squared_squared;
145 grad_grad[3] = grad_grad[1];
146 grad_grad[4] = ((400.0*tmp[1]*tmp[1]*f)/dist_squared_squared)+
147 (20.0*f/dist_squared);
148 grad_grad[5] = (400.0*tmp[1]*tmp[2]*f)/dist_squared_squared;
149 grad_grad[6] = grad_grad[2];
150 grad_grad[7] = grad_grad[5];
151 grad_grad[8] = ((400.0*tmp[2]*tmp[2]*f)/dist_squared_squared)+
152 (20.0*f/dist_squared);
153 }
154 ConstDeviceMatrix gg(grad_grad,DIM,DIM);
155
156 for (int i = 0; i < DIM; i++)
157 {
158 for (int j = 0; j < DIM; j++)
159 {
160 H0(i,j,qx,qy,qz,e) = weight_m * gg(i,j);
161 }
162 }
163 }
164 }
165 }
166 });
167}
168
170{
171 const int N = PA.ne;
172 const int D1D = PA.maps_lim->ndof;
173 const int Q1D = PA.maps_lim->nqpt;
174 const int id = (D1D << 4 ) | Q1D;
175 const real_t ln = lim_normal;
176 const Vector &LD = PA.LD;
177 const DenseTensor &J = PA.Jtr;
178 const Array<real_t> &W = PA.ir->GetWeights();
179 const Array<real_t> &B = PA.maps->B;
180 const Array<real_t> &BLD = PA.maps_lim->B;
181 const Vector &C0 = PA.C0;
182 const Vector &X0 = PA.X0;
183 Vector &H0 = PA.H0;
184
185 auto el = dynamic_cast<TMOP_ExponentialLimiter *>(lim_func);
186 const bool exp_lim = (el) ? true : false;
187
188 MFEM_LAUNCH_TMOP_KERNEL(SetupGradPA_Kernel_C0_3D,id,ln,LD,C0,N,J,W,B,BLD,X0,X,
189 H0,exp_lim);
190}
191
192} // 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).
A basic generic Tensor class, appropriate for use on the GPU.
Definition dtensor.hpp:82
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 AssembleGradPA_C0_3D(const 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
int Size() const
Returns the size of the vector.
Definition vector.hpp:218
virtual real_t * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:482
real_t b
Definition lissajous.cpp:42
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 void Diag(const real_t c, real_t *data)
Creates n x n diagonal matrix with diagonal elements c.
Definition kernels.hpp:49
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_3D(int N, int X, int Y, int Z, lambda &&body)
Definition forall.hpp:775
float real_t
Definition config.hpp:43
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30