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) 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 <cstddef>
16 #include <array>
17 #include <cstdint>
18 #include <map>
19 #include <memory>
20 #include <string_view>
21 
22 #include "mfem.hpp"
23 #include "axom/core.hpp"
24 #include "serac/serac_config.hpp"
26 
27 namespace serac {
28 
42 struct Nothing {};
43 
47 struct Empty {};
48 
49 template <typename T>
50 struct QuadratureData;
51 
52 } // namespace serac
53 
54 // we define these specializations to make it so that materials
55 // without state variables can use the same interface, without
56 // actually storing/accessing any data
57 namespace axom {
58 
60 template <>
61 class Array<serac::Nothing, 2, MemorySpace::Dynamic> {
62  public:
63  Array() {}
64  Array(uint32_t, uint32_t) {}
65 };
66 
67 template <>
68 class ArrayView<serac::Nothing, 2, MemorySpace::Dynamic> {
69  public:
70  ArrayView(Array<serac::Nothing, 2, MemorySpace::Dynamic> /* unused */) {}
71 
73  SERAC_HOST_DEVICE serac::Nothing& operator()(const size_t, const size_t) { return data; }
74 
76  SERAC_HOST_DEVICE const serac::Nothing& operator()(const size_t, const size_t) const { return data; }
77 
78  serac::Nothing data;
79 };
80 
81 template <>
82 class Array<serac::Empty, 2, MemorySpace::Dynamic> {
83  public:
84  Array() {}
85  Array(uint32_t, uint32_t) {}
86 };
87 
88 template <>
89 class ArrayView<serac::Empty, 2, MemorySpace::Dynamic> {
90  public:
91  ArrayView(Array<serac::Empty, 2, MemorySpace::Dynamic> /* unused */) {}
92 
94  SERAC_HOST_DEVICE serac::Empty& operator()(const size_t, const size_t) { return data; }
95 
97  SERAC_HOST_DEVICE const serac::Empty& operator()(const size_t, const size_t) const { return data; }
98 
99  serac::Empty data;
100 };
102 
103 } // namespace axom
104 
105 namespace serac {
106 namespace detail {
107 
108 // Note: The indexes between these two arrays must match the type in qdata_geometries to the name in
109 // qdata_geometry_names
111 constexpr std::array<mfem::Geometry::Type, 5> qdata_geometries = {mfem::Geometry::SEGMENT, mfem::Geometry::TRIANGLE,
112  mfem::Geometry::SQUARE, mfem::Geometry::TETRAHEDRON,
113  mfem::Geometry::CUBE};
115 constexpr std::array<std::string_view, 5> qdata_geometry_names = {"Segment", "Triangle", "Square", "Tetrahedron",
116  "Cube"};
117 } // namespace detail
118 
127 template <typename T>
130  using geom_array_t = std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES>;
131 
139  QuadratureData(geom_array_t elements, geom_array_t qpts_per_element, T value = T{})
140  {
141  for (auto geom : detail::qdata_geometries) {
142  if (elements[uint32_t(geom)] > 0) {
143  data[geom] = axom::Array<T, 2>(elements[uint32_t(geom)], qpts_per_element[uint32_t(geom)]);
144  data[geom].fill(value);
145  }
146  }
147  }
148 
153  axom::ArrayView<T, 2> operator[](mfem::Geometry::Type geom) { return axom::ArrayView<T, 2>(data.at(geom)); }
154 
156  std::map<mfem::Geometry::Type, axom::Array<T, 2>> data;
157 };
158 
160 template <>
161 struct QuadratureData<Nothing> {
162  using geom_array_t = std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES>;
163 
164  QuadratureData() {}
165 
166  axom::ArrayView<Nothing, 2> operator[](mfem::Geometry::Type) { return axom::ArrayView<Nothing, 2>(data); }
167 
168  axom::Array<Nothing, 2, axom::MemorySpace::Dynamic> data;
169 };
170 
171 template <>
172 struct QuadratureData<Empty> {
173  using geom_array_t = std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES>;
174 
175  QuadratureData() {}
176 
177  axom::ArrayView<Empty, 2> operator[](mfem::Geometry::Type) { return axom::ArrayView<Empty, 2>(data); }
178 
179  axom::Array<Empty, 2, axom::MemorySpace::Dynamic> data;
180 };
182 
184 extern std::shared_ptr<QuadratureData<Nothing>> NoQData;
185 extern std::shared_ptr<QuadratureData<Empty>> EmptyQData;
186 
187 } // 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:36
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
constexpr std::array< std::string_view, 5 > qdata_geometry_names
a list of strings associated with the corresponding mfem::Geometry type supported by QuadratureData
constexpr std::array< mfem::Geometry::Type, 5 > qdata_geometries
a list of mfem::Geometry types supported by QuadratureData
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)