MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
tmop_pa_tc2.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, 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 "../gridfunc.hpp"
15 #include "../kernels.hpp"
16 #include "../../general/forall.hpp"
17 #include "../../linalg/kernels.hpp"
18 
19 using namespace mfem;
20 
21 namespace mfem
22 {
23 
24 MFEM_REGISTER_TMOP_KERNELS(bool, TC_IDEAL_SHAPE_UNIT_SIZE_2D_KERNEL,
25  const int NE,
26  const DenseMatrix &w_,
27  DenseTensor &j_,
28  const int d1d,
29  const int q1d)
30 {
31  constexpr int DIM = 2;
32  constexpr int NBZ = 1;
33 
34  const int Q1D = T_Q1D ? T_Q1D : q1d;
35 
36  const auto W = Reshape(w_.Read(), DIM,DIM);
37  auto J = Reshape(j_.Write(), DIM,DIM, Q1D,Q1D, NE);
38 
39  MFEM_FORALL_2D(e, NE, Q1D, Q1D, NBZ,
40  {
41  const int Q1D = T_Q1D ? T_Q1D : q1d;
42  MFEM_FOREACH_THREAD(qy,y,Q1D)
43  {
44  MFEM_FOREACH_THREAD(qx,x,Q1D)
45  {
46  kernels::Set(DIM,DIM, 1.0, &W(0,0), &J(0,0,qx,qy,e));
47  }
48  }
49  });
50  return true;
51 }
52 
53 MFEM_REGISTER_TMOP_KERNELS(bool, TC_IDEAL_SHAPE_GIVEN_SIZE_2D_KERNEL,
54  const int NE,
55  const Array<double> &b_,
56  const Array<double> &g_,
57  const DenseMatrix &w_,
58  const Vector &x_,
59  DenseTensor &j_,
60  const int d1d,
61  const int q1d)
62 {
63  constexpr int DIM = 2;
64  constexpr int NBZ = 1;
65 
66  const double detW = w_.Det();
67  const int D1D = T_D1D ? T_D1D : d1d;
68  const int Q1D = T_Q1D ? T_Q1D : q1d;
69 
70  const auto b = Reshape(b_.Read(), Q1D, D1D);
71  const auto g = Reshape(g_.Read(), Q1D, D1D);
72  const auto W = Reshape(w_.Read(), DIM,DIM);
73  const auto X = Reshape(x_.Read(), D1D, D1D, DIM, NE);
74  auto J = Reshape(j_.Write(), DIM,DIM, Q1D,Q1D, NE);
75 
76  MFEM_FORALL_2D(e, NE, Q1D, Q1D, NBZ,
77  {
78  const int D1D = T_D1D ? T_D1D : d1d;
79  const int Q1D = T_Q1D ? T_Q1D : q1d;
80 
81  constexpr int NBZ = 1;
82  constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
83  constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
84 
85  MFEM_SHARED double BG[2][MQ1*MD1];
86  MFEM_SHARED double XY[2][NBZ][MD1*MD1];
87  MFEM_SHARED double DQ[4][NBZ][MD1*MQ1];
88  MFEM_SHARED double QQ[4][NBZ][MQ1*MQ1];
89 
90  kernels::internal::LoadX<MD1,NBZ>(e,D1D,X,XY);
91  kernels::internal::LoadBG<MD1,MQ1>(D1D,Q1D,b,g,BG);
92 
93  kernels::internal::GradX<MD1,MQ1,NBZ>(D1D,Q1D,BG,XY,DQ);
94  kernels::internal::GradY<MD1,MQ1,NBZ>(D1D,Q1D,BG,DQ,QQ);
95 
96  MFEM_FOREACH_THREAD(qy,y,Q1D)
97  {
98  MFEM_FOREACH_THREAD(qx,x,Q1D)
99  {
100  double Jtr[4];
101  const double *Wid = &W(0,0);
102  kernels::internal::PullGrad<MQ1,NBZ>(Q1D,qx,qy,QQ,Jtr);
103  const double detJ = kernels::Det<2>(Jtr);
104  const double alpha = std::pow(detJ/detW,1./2);
105  kernels::Set(DIM,DIM,alpha,Wid,&J(0,0,qx,qy,e));
106  }
107  }
108  });
109  return true;
110 }
111 
112 template<> bool
113 TargetConstructor::ComputeAllElementTargets<2>(const FiniteElementSpace &fes,
114  const IntegrationRule &ir,
115  const Vector &,
116  DenseTensor &Jtr) const
117 {
118  MFEM_ASSERT(target_type == IDEAL_SHAPE_UNIT_SIZE || nodes != nullptr, "");
119  const Mesh *mesh = fes.GetMesh();
120  const int NE = mesh->GetNE();
121  // Quick return for empty processors:
122  if (NE == 0) { return true; }
123  const int dim = mesh->Dimension();
124  MFEM_VERIFY(mesh->GetNumGeometries(dim) <= 1,
125  "mixed meshes are not supported");
126  MFEM_VERIFY(!fes.IsVariableOrder(), "variable orders are not supported");
127  const FiniteElement &fe = *fes.GetFE(0);
128  MFEM_VERIFY(fe.GetGeomType() == Geometry::SQUARE, "");
130  const DofToQuad::Mode mode = DofToQuad::TENSOR;
131  const DofToQuad &maps = fe.GetDofToQuad(ir, mode);
132  const int D1D = maps.ndof;
133  const int Q1D = maps.nqpt;
134  const int id = (D1D << 4 ) | Q1D;
135 
136  const Array<double> &B = maps.B;
137  const Array<double> &G = maps.G;
138 
139  switch (target_type)
140  {
141  case IDEAL_SHAPE_UNIT_SIZE: // Jtr(i) = Wideal;
142  {
143  MFEM_LAUNCH_TMOP_KERNEL(TC_IDEAL_SHAPE_UNIT_SIZE_2D_KERNEL,
144  id,NE,W,Jtr);
145  }
146  case IDEAL_SHAPE_EQUAL_SIZE: return false;
147  case IDEAL_SHAPE_GIVEN_SIZE:
148  {
149  MFEM_VERIFY(nodes, "");
151  const Operator *R = fes.GetElementRestriction(ordering);
153  X.UseDevice(true);
154  R->Mult(*nodes, X);
155  MFEM_ASSERT(nodes->FESpace()->GetVDim() == 2, "");
156  MFEM_LAUNCH_TMOP_KERNEL(TC_IDEAL_SHAPE_GIVEN_SIZE_2D_KERNEL,
157  id,NE,B,G,W,X,Jtr);
158  }
159  case GIVEN_SHAPE_AND_SIZE: return false;
160  default: return false;
161  }
162  return false;
163 }
164 
165 } // namespace mfem
Abstract class for all finite elements.
Definition: fe_base.hpp:235
Class for an integration rule - an Array of IntegrationPoint.
Definition: intrules.hpp:90
Tensor product representation using 1D matrices/tensors with dimensions using 1D number of quadrature...
Definition: fe_base.hpp:162
int GetNumGeometries(int dim) const
Return the number of geometries of the given dimension present in the mesh.
Definition: mesh.cpp:5908
double Det() const
Definition: densemat.cpp:449
int nqpt
Number of quadrature points. When mode is TENSOR, this is the 1D number.
Definition: fe_base.hpp:174
Data type dense matrix using column-major storage.
Definition: densemat.hpp:23
int ndof
Number of degrees of freedom = number of basis functions. When mode is TENSOR, this is the 1D number...
Definition: fe_base.hpp:170
int GetNE() const
Returns number of elements.
Definition: mesh.hpp:923
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
constexpr int DIM
virtual void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
Definition: vector.hpp:118
const DenseMatrix & GetGeomToPerfGeomJac(int GeomType) const
Definition: geom.hpp:98
Geometry Geometries
Definition: fe.cpp:49
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition: operator.hpp:67
double b
Definition: lissajous.cpp:42
static MemoryType GetDeviceMemoryType()
Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating m...
Definition: device.hpp:273
MFEM_REGISTER_TMOP_KERNELS(void, DatcSize, const int NE, const int ncomp, const int sizeidx, const DenseMatrix &w_, const Array< double > &b_, const Vector &x_, DenseTensor &j_, const int d1d, const int q1d)
Definition: tmop_pa_da3.cpp:20
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition: array.hpp:304
int Dimension() const
Definition: mesh.hpp:1006
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:96
Structure representing the matrices/tensors needed to evaluate (in reference space) the values...
Definition: fe_base.hpp:136
Array< double > B
Basis functions evaluated at quadrature points.
Definition: fe_base.hpp:185
Mode
Type of data stored in the arrays B, Bt, G, and Gt.
Definition: fe_base.hpp:149
ElementDofOrdering
Constants describing the possible orderings of the DOFs in one element.
Definition: fespace.hpp:74
int dim
Definition: ex24.cpp:53
Array< double > G
Gradients/divergences/curls of basis functions evaluated at quadrature points.
Definition: fe_base.hpp:206
Lexicographic ordering for tensor-product FiniteElements.
MFEM_HOST_DEVICE void Set(const int height, const int width, const double alpha, const TA *Adata, TB *Bdata)
Compute B = alpha*A, where the matrices A and B are of size height x width with data Adata and Bdata...
Definition: kernels.hpp:326
const double alpha
Definition: ex15.cpp:369
Vector data type.
Definition: vector.hpp:60
double * Write(bool on_dev=true)
Shortcut for mfem::Write(GetMemory(), TotalSize(), on_dev).
Definition: densemat.hpp:1095
Abstract operator.
Definition: operator.hpp:24
Rank 3 tensor (array of matrices)
Definition: densemat.hpp:953
virtual const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:449
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
const double * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
Definition: densemat.hpp:443