MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
tmop_pa_h2m.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_2D,
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 = 2;
32 constexpr int NBZ = 1;
33
34 const int D1D = T_D1D ? T_D1D : d1d;
35 const int Q1D = T_Q1D ? T_Q1D : q1d;
36
37 const auto b = Reshape(b_.Read(), Q1D, D1D);
38 const auto g = Reshape(g_.Read(), Q1D, D1D);
39 const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, NE);
40 const auto X = Reshape(x_.Read(), D1D, D1D, DIM, NE);
41 const auto H = Reshape(h_.Read(), DIM, DIM, DIM, DIM, Q1D, Q1D, NE);
42 auto Y = Reshape(y_.ReadWrite(), D1D, D1D, DIM, NE);
43
44 mfem::forall_2D_batch(NE, Q1D, Q1D, NBZ, [=] MFEM_HOST_DEVICE (int e)
45 {
46 const int D1D = T_D1D ? T_D1D : d1d;
47 const int Q1D = T_Q1D ? T_Q1D : q1d;
48 constexpr int NBZ = 1;
49 constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
50 constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
51
52 MFEM_SHARED real_t BG[2][MQ1*MD1];
53 MFEM_SHARED real_t XY[2][NBZ][MD1*MD1];
54 MFEM_SHARED real_t DQ[4][NBZ][MD1*MQ1];
55 MFEM_SHARED real_t QQ[4][NBZ][MQ1*MQ1];
56
57 kernels::internal::LoadX<MD1,NBZ>(e,D1D,X,XY);
58 kernels::internal::LoadBG<MD1,MQ1>(D1D,Q1D,b,g,BG);
59
60 kernels::internal::GradX<MD1,MQ1,NBZ>(D1D,Q1D,BG,XY,DQ);
61 kernels::internal::GradY<MD1,MQ1,NBZ>(D1D,Q1D,BG,DQ,QQ);
62
63 MFEM_FOREACH_THREAD(qy,y,Q1D)
64 {
65 MFEM_FOREACH_THREAD(qx,x,Q1D)
66 {
67 const real_t *Jtr = &J(0,0,qx,qy,e);
68
69 // Jrt = Jtr^{-1}
70 real_t Jrt[4];
72
73 // Jpr = X^T.DSh
74 real_t Jpr[4];
75 kernels::internal::PullGrad<MQ1,NBZ>(Q1D,qx,qy,QQ,Jpr);
76
77 // Jpt = Jpr . Jrt
78 real_t Jpt[4];
79 kernels::Mult(2,2,2, Jpr, Jrt, Jpt);
80
81 // B = Jpt : H
82 real_t B[4];
83 DeviceMatrix M(B,2,2);
84 ConstDeviceMatrix J(Jpt,2,2);
85 for (int i = 0; i < DIM; i++)
86 {
87 for (int j = 0; j < DIM; j++)
88 {
89 M(i,j) = 0.0;
90 for (int r = 0; r < DIM; r++)
91 {
92 for (int c = 0; c < DIM; c++)
93 {
94 M(i,j) += H(r,c,i,j,qx,qy,e) * J(r,c);
95 }
96 }
97 }
98 }
99 // C = Jrt . B
100 real_t C[4];
101 kernels::MultABt(2,2,2, Jrt, B, C);
102
103 // Overwrite QQ = Jrt . (Jpt : H)^t
104 kernels::internal::PushGrad<MQ1,NBZ>(Q1D,qx,qy, C, QQ);
105 }
106 }
107 MFEM_SYNC_THREAD;
108 kernels::internal::LoadBGt<MD1,MQ1>(D1D,Q1D,b,g,BG);
109 kernels::internal::GradYt<MD1,MQ1,NBZ>(D1D,Q1D,BG,QQ,DQ);
110 kernels::internal::GradXt<MD1,MQ1,NBZ>(D1D,Q1D,BG,DQ,Y,e);
111 });
112}
113
115{
116 const int N = PA.ne;
117 const int D1D = PA.maps->ndof;
118 const int Q1D = PA.maps->nqpt;
119 const int id = (D1D << 4 ) | Q1D;
120 const DenseTensor &J = PA.Jtr;
121 const Array<real_t> &B = PA.maps->B;
122 const Array<real_t> &G = PA.maps->G;
123 const Vector &H = PA.H;
124
125 MFEM_LAUNCH_TMOP_KERNEL(AddMultGradPA_Kernel_2D,id,N,B,G,J,H,R,C);
126}
127
128} // 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_2D(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_2D_batch(int N, int X, int Y, int BZ, lambda &&body)
Definition forall.hpp:769
float real_t
Definition config.hpp:43