MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
tmop_pa_h2d.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
20/* // Original i-j assembly (old invariants code).
21 for (int e = 0; e < NE; e++)
22 {
23 for (int q = 0; q < nqp; q++)
24 {
25 el.CalcDShape(ip, DSh);
26 Mult(DSh, Jrt, DS);
27 for (int i = 0; i < dof; i++)
28 {
29 for (int j = 0; j < dof; j++)
30 {
31 for (int r = 0; r < dim; r++)
32 {
33 for (int c = 0; c < dim; c++)
34 {
35 for (int rr = 0; rr < dim; rr++)
36 {
37 for (int cc = 0; cc < dim; cc++)
38 {
39 const double H = h(r, c, rr, cc);
40 A(e, i + r*dof, j + rr*dof) +=
41 weight_q * DS(i, c) * DS(j, cc) * H;
42 }
43 }
44 }
45 }
46 }
47 }
48 }
49 }*/
50
51MFEM_REGISTER_TMOP_KERNELS(void, AssembleDiagonalPA_Kernel_2D,
52 const int NE,
53 const Array<real_t> &b,
54 const Array<real_t> &g,
55 const DenseTensor &j,
56 const Vector &h,
57 Vector &diagonal,
58 const int d1d,
59 const int q1d)
60{
61 constexpr int DIM = 2;
62 const int D1D = T_D1D ? T_D1D : d1d;
63 const int Q1D = T_Q1D ? T_Q1D : q1d;
64
65 const auto B = Reshape(b.Read(), Q1D, D1D);
66 const auto G = Reshape(g.Read(), Q1D, D1D);
67 const auto J = Reshape(j.Read(), DIM, DIM, Q1D, Q1D, NE);
68 const auto H = Reshape(h.Read(), DIM, DIM, DIM, DIM, Q1D, Q1D, NE);
69
70 auto D = Reshape(diagonal.ReadWrite(), D1D, D1D, DIM, NE);
71
72 mfem::forall_2D(NE, Q1D, Q1D, [=] MFEM_HOST_DEVICE (int e)
73 {
74 constexpr int DIM = 2;
75 const int D1D = T_D1D ? T_D1D : d1d;
76 const int Q1D = T_Q1D ? T_Q1D : q1d;
77 constexpr int MD1 = T_D1D ? T_D1D : DofQuadLimits::MAX_D1D;
78 constexpr int MQ1 = T_Q1D ? T_Q1D : DofQuadLimits::MAX_Q1D;
79
80 // Takes into account Jtr by replacing H with Href at all quad points.
81 MFEM_SHARED real_t Href_data[DIM*DIM*DIM*MQ1*MQ1];
82 DeviceTensor<5, real_t> Href(Href_data, DIM, DIM, DIM, MQ1, MQ1);
83 for (int v = 0; v < DIM; v++)
84 {
85 MFEM_FOREACH_THREAD(qx,x,Q1D)
86 {
87 MFEM_FOREACH_THREAD(qy,y,Q1D)
88 {
89 const real_t *Jtr = &J(0,0,qx,qy,e);
90 real_t Jrt_data[4];
91 ConstDeviceMatrix Jrt(Jrt_data,2,2);
92 kernels::CalcInverse<2>(Jtr, Jrt_data);
93
94 for (int m = 0; m < DIM; m++)
95 {
96 for (int n = 0; n < DIM; n++)
97 {
98 // Hr_{v,m,n,q} = \sum_{s,t=1}^d
99 // Jrt_{m,s,q} H_{v,s,v,t,q} Jrt_{n,t,q}
100 Href(v,m,n,qx,qy) = 0.0;
101 for (int s = 0; s < DIM; s++)
102 {
103 for (int t = 0; t < DIM; t++)
104 {
105 Href(v,m,n,qx,qy) +=
106 Jrt(m,s) * H(v,s,v,t,qx,qy,e) * Jrt(n,t);
107 }
108 }
109 }
110 }
111 }
112 }
113 }
114
115 MFEM_SHARED real_t qd[DIM*DIM*MQ1*MD1];
116 DeviceTensor<4,real_t> QD(qd, DIM, DIM, MQ1, MD1);
117
118 for (int v = 0; v < DIM; v++)
119 {
120 // Contract in y.
121 MFEM_FOREACH_THREAD(qx,x,Q1D)
122 {
123 MFEM_FOREACH_THREAD(dy,y,D1D)
124 {
125 for (int m = 0; m < DIM; m++)
126 {
127 for (int n = 0; n < DIM; n++)
128 {
129 QD(m,n,qx,dy) = 0.0;
130 }
131 }
132
133 MFEM_UNROLL(MQ1)
134 for (int qy = 0; qy < Q1D; ++qy)
135 {
136 const real_t By = B(qy,dy);
137 const real_t Gy = G(qy,dy);
138 for (int m = 0; m < DIM; m++)
139 {
140 for (int n = 0; n < DIM; n++)
141 {
142 const real_t L = (m == 1 ? Gy : By);
143 const real_t R = (n == 1 ? Gy : By);
144 QD(m,n,qx,dy) += L * Href(v,m,n,qx,qy) * R;
145 }
146 }
147 }
148 }
149 }
150 MFEM_SYNC_THREAD;
151
152 // Contract in x.
153 MFEM_FOREACH_THREAD(dy,y,D1D)
154 {
155 MFEM_FOREACH_THREAD(dx,x,D1D)
156 {
157 real_t d = 0.0;
158 MFEM_UNROLL(MQ1)
159 for (int qx = 0; qx < Q1D; ++qx)
160 {
161 const real_t Bx = B(qx,dx);
162 const real_t Gx = G(qx,dx);
163
164 for (int m = 0; m < DIM; m++)
165 {
166 for (int n = 0; n < DIM; n++)
167 {
168 const real_t L = (m == 0 ? Gx : Bx);
169 const real_t R = (n == 0 ? Gx : Bx);
170 d += L * QD(m,n,qx,dy) * R;
171 }
172 }
173 }
174 D(dx,dy,v,e) += d;
175 }
176 }
177 MFEM_SYNC_THREAD;
178 }
179 });
180}
181
183{
184 const int N = PA.ne;
185 const int D1D = PA.maps->ndof;
186 const int Q1D = PA.maps->nqpt;
187 const int id = (D1D << 4 ) | Q1D;
188 const DenseTensor &J = PA.Jtr;
189 const Array<real_t> &B = PA.maps->B;
190 const Array<real_t> &G = PA.maps->G;
191 const Vector &H = PA.H;
192
193 MFEM_LAUNCH_TMOP_KERNEL(AssembleDiagonalPA_Kernel_2D,id,N,B,G,J,H,D);
194}
195
196} // 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 AssembleDiagonalPA_2D(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_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(int N, int X, int Y, lambda &&body)
Definition forall.hpp:763
float real_t
Definition config.hpp:43
RefCoord t[3]
RefCoord s[3]