MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
tmop_pa_h3m.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"
16
17namespace mfem
18{
19
20MFEM_REGISTER_TMOP_KERNELS(void, AddMultGradPA_Kernel_3D,
21 const int NE,
22 const Array<real_t> &b_,
23 const Array<real_t> &g_,
24 const DenseTensor &j_,
25 const Vector &h_,
26 const Vector &x_,
27 Vector &y_,
28 const int d1d,
29 const int q1d)
30{
31 constexpr int DIM = 3;
32 const int D1D = T_D1D ? T_D1D : d1d;
33 const int Q1D = T_Q1D ? T_Q1D : q1d;
34
35 const auto b = Reshape(b_.Read(), Q1D, D1D);
36 const auto g = Reshape(g_.Read(), Q1D, D1D);
37 const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, Q1D, NE);
38 const auto X = Reshape(x_.Read(), D1D, D1D, D1D, DIM, NE);
39 const auto H = Reshape(h_.Read(), DIM, DIM, DIM, DIM, Q1D, Q1D, Q1D, NE);
40 auto Y = Reshape(y_.ReadWrite(), D1D, D1D, D1D, DIM, NE);
41
42 mfem::forall_3D(NE, Q1D, Q1D, Q1D, [=] MFEM_HOST_DEVICE (int e)
43 {
44 constexpr int DIM = 3;
45 const int D1D = T_D1D ? T_D1D : d1d;
46 const int Q1D = T_Q1D ? T_Q1D : q1d;
47 constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
48 constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
49
50 MFEM_SHARED real_t BG[2][MQ1*MD1];
51 MFEM_SHARED real_t DDD[3][MD1*MD1*MD1];
52 MFEM_SHARED real_t DDQ[9][MD1*MD1*MQ1];
53 MFEM_SHARED real_t DQQ[9][MD1*MQ1*MQ1];
54 MFEM_SHARED real_t QQQ[9][MQ1*MQ1*MQ1];
55
56 kernels::internal::LoadX<MD1>(e,D1D,X,DDD);
57 kernels::internal::LoadBG<MD1,MQ1>(D1D,Q1D,b,g,BG);
58
59 kernels::internal::GradX<MD1,MQ1>(D1D,Q1D,BG,DDD,DDQ);
60 kernels::internal::GradY<MD1,MQ1>(D1D,Q1D,BG,DDQ,DQQ);
61 kernels::internal::GradZ<MD1,MQ1>(D1D,Q1D,BG,DQQ,QQQ);
62
63 MFEM_FOREACH_THREAD(qz,z,Q1D)
64 {
65 MFEM_FOREACH_THREAD(qy,y,Q1D)
66 {
67 MFEM_FOREACH_THREAD(qx,x,Q1D)
68 {
69 const real_t *Jtr = &J(0,0,qx,qy,qz,e);
70
71 // Jrt = Jtr^{-1}
72 real_t Jrt[9];
74
75 // Jpr = X^T.DSh
76 real_t Jpr[9];
77 kernels::internal::PullGrad<MQ1>(Q1D, qx,qy,qz, QQQ, Jpr);
78
79 // Jpt = X^T.DS = (X^T.DSh).Jrt = Jpr.Jrt
80 real_t Jpt[9];
81 kernels::Mult(3,3,3, Jpr, Jrt, Jpt);
82
83 // B = Jpt : H
84 real_t B[9];
85 DeviceMatrix M(B,3,3);
86 ConstDeviceMatrix J(Jpt,3,3);
87 for (int i = 0; i < DIM; i++)
88 {
89 for (int j = 0; j < DIM; j++)
90 {
91 M(i,j) = 0.0;
92 for (int r = 0; r < DIM; r++)
93 {
94 for (int c = 0; c < DIM; c++)
95 {
96 M(i,j) += H(r,c,i,j,qx,qy,qz,e) * J(r,c);
97 }
98 }
99 }
100 }
101
102 // Y += DS . M^t += DSh . (Jrt . M^t)
103 real_t A[9];
104 kernels::MultABt(3,3,3, Jrt, B, A);
105 kernels::internal::PushGrad<MQ1>(Q1D, qx,qy,qz, A, QQQ);
106 }
107 }
108 }
109 MFEM_SYNC_THREAD;
110 kernels::internal::LoadBGt<MD1,MQ1>(D1D,Q1D,b,g,BG);
111 kernels::internal::GradZt<MD1,MQ1>(D1D,Q1D,BG,QQQ,DQQ);
112 kernels::internal::GradYt<MD1,MQ1>(D1D,Q1D,BG,DQQ,DDQ);
113 kernels::internal::GradXt<MD1,MQ1>(D1D,Q1D,BG,DDQ,Y,e);
114 });
115}
116
118{
119 const int N = PA.ne;
120 const int D1D = PA.maps->ndof;
121 const int Q1D = PA.maps->nqpt;
122 const int id = (D1D << 4 ) | Q1D;
123 const DenseTensor &J = PA.Jtr;
124 const Array<real_t> &B = PA.maps->B;
125 const Array<real_t> &G = PA.maps->G;
126 const Vector &H = PA.H;
127
128 MFEM_LAUNCH_TMOP_KERNEL(AddMultGradPA_Kernel_3D,id,N,B,G,J,H,R,C);
129}
130
131} // 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
void AddMultGradPA_3D(const Vector &, Vector &) const
struct mfem::TMOP_Integrator::@23 PA
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
real_t b
Definition lissajous.cpp:42
constexpr int DIM
MFEM_HOST_DEVICE void CalcInverse(const T *data, T *inv_data)
Return the inverse of a matrix with given size and data into the matrix with data inv_data.
Definition kernels.hpp:246
MFEM_HOST_DEVICE void Mult(const int height, const int width, const TA *data, const TX *x, TY *y)
Matrix vector multiplication: y = A x, where the matrix A is of size height x width with given data,...
Definition kernels.hpp:163
MFEM_HOST_DEVICE void MultABt(const int Aheight, const int Awidth, const int Bheight, const TA *Adata, const TB *Bdata, TC *ABtdata)
Multiply a matrix of size Aheight x Awidth and data Adata with the transpose of a matrix of size Bhei...
Definition kernels.hpp:363
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