Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
quadrature_data.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and
2 // other Serac Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
13 #pragma once
14 
15 #include "mfem.hpp"
16 
17 #include "axom/core.hpp"
18 
19 #include "serac/serac_config.hpp"
20 
22 
23 namespace serac {
24 
38 struct Nothing {};
39 
43 struct Empty {};
44 
45 template <typename T>
46 struct QuadratureData;
47 
48 } // namespace serac
49 
50 // we define these specializations to make it so that materials
51 // without state variables can use the same interface, without
52 // actually storing/accessing any data
53 namespace axom {
54 
56 template <>
57 class Array<serac::Nothing, 2, MemorySpace::Dynamic> {
58 public:
59  Array() {}
60  Array(uint32_t, uint32_t) {}
61 };
62 
63 template <>
64 class ArrayView<serac::Nothing, 2, MemorySpace::Dynamic> {
65 public:
66  ArrayView(Array<serac::Nothing, 2, MemorySpace::Dynamic> /* unused */) {}
67 
69  SERAC_HOST_DEVICE serac::Nothing& operator()(const size_t, const size_t) { return data; }
70 
72  SERAC_HOST_DEVICE const serac::Nothing& operator()(const size_t, const size_t) const { return data; }
73 
74  serac::Nothing data;
75 };
76 
77 template <>
78 class Array<serac::Empty, 2, MemorySpace::Dynamic> {
79 public:
80  Array() {}
81  Array(uint32_t, uint32_t) {}
82 };
83 
84 template <>
85 class ArrayView<serac::Empty, 2, MemorySpace::Dynamic> {
86 public:
87  ArrayView(Array<serac::Empty, 2, MemorySpace::Dynamic> /* unused */) {}
88 
90  SERAC_HOST_DEVICE serac::Empty& operator()(const size_t, const size_t) { return data; }
91 
93  SERAC_HOST_DEVICE const serac::Empty& operator()(const size_t, const size_t) const { return data; }
94 
95  serac::Empty data;
96 };
98 
99 } // namespace axom
100 
101 namespace serac {
102 
111 template <typename T>
114  using geom_array_t = std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES>;
115 
123  QuadratureData(geom_array_t elements, geom_array_t qpts_per_element, T value = T{})
124  {
125  constexpr std::array geometries = {mfem::Geometry::SEGMENT, mfem::Geometry::TRIANGLE, mfem::Geometry::SQUARE,
126  mfem::Geometry::TETRAHEDRON, mfem::Geometry::CUBE};
127 
128  for (auto geom : geometries) {
129  if (elements[uint32_t(geom)] > 0) {
130  data[geom] = axom::Array<T, 2>(elements[uint32_t(geom)], qpts_per_element[uint32_t(geom)]);
131  data[geom].fill(value);
132  }
133  }
134  }
135 
140  axom::ArrayView<T, 2> operator[](mfem::Geometry::Type geom) { return axom::ArrayView<T, 2>(data.at(geom)); }
141 
143  std::map<mfem::Geometry::Type, axom::Array<T, 2> > data;
144 };
145 
147 template <>
148 struct QuadratureData<Nothing> {
149  using geom_array_t = std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES>;
150 
151  QuadratureData() {}
152 
153  axom::ArrayView<Nothing, 2> operator[](mfem::Geometry::Type) { return axom::ArrayView<Nothing, 2>(data); }
154 
155  axom::Array<Nothing, 2, axom::MemorySpace::Dynamic> data;
156 };
157 
158 template <>
159 struct QuadratureData<Empty> {
160  using geom_array_t = std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES>;
161 
162  QuadratureData() {}
163 
164  axom::ArrayView<Empty, 2> operator[](mfem::Geometry::Type) { return axom::ArrayView<Empty, 2>(data); }
165 
166  axom::Array<Empty, 2, axom::MemorySpace::Dynamic> data;
167 };
169 
171 extern std::shared_ptr<QuadratureData<Nothing> > NoQData;
172 extern std::shared_ptr<QuadratureData<Empty> > EmptyQData;
173 
174 } // namespace serac
This file contains the interface used for initializing/terminating any hardware accelerator-related f...
#define SERAC_HOST_DEVICE
Macro that evaluates to __host__ __device__ when compiling with nvcc and does nothing on a host compi...
Definition: accelerator.hpp:38
Accelerator functionality.
Definition: serac.cpp:38
std::shared_ptr< QuadratureData< Empty > > EmptyQData
a single instance of a QuadratureData container of Emptys, since they are all interchangeable
std::shared_ptr< QuadratureData< Nothing > > NoQData
a single instance of a QuadratureData container of Nothings, since they are all interchangeable
see Nothing for a complete description of this class and when to use it
these classes are a little confusing. These two special types represent the similar (but different) c...
A class for storing and access user-defined types at quadrature points.
axom::ArrayView< T, 2 > operator[](mfem::Geometry::Type geom)
return the 2D array of quadrature point values for elements of the specified geometry
std::array< uint32_t, mfem::Geometry::NUM_GEOMETRIES > geom_array_t
a list of integers, one associated with each type of mfem::Geometry
QuadratureData(geom_array_t elements, geom_array_t qpts_per_element, T value=T{})
Initialize a new quadrature data buffer, optionally with some initial value.
std::map< mfem::Geometry::Type, axom::Array< T, 2 > > data
a 3D array indexed by (which geometry, which element, which quadrature point)