Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
geometry.hpp
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Smith Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
7 #pragma once
8 
9 #include "mfem.hpp"
10 
11 namespace smith {
12 
16 template <int d>
17 struct Dimension {
21  constexpr operator int() { return d; }
22 };
23 
31 constexpr int num_quadrature_points(mfem::Geometry::Type g, int Q)
32 {
33  if (g == mfem::Geometry::SEGMENT) {
34  return Q;
35  }
36  if (g == mfem::Geometry::TRIANGLE) {
37  return (Q * (Q + 1)) / 2;
38  }
39  if (g == mfem::Geometry::SQUARE) {
40  return Q * Q;
41  }
42  if (g == mfem::Geometry::TETRAHEDRON) {
43  return (Q * (Q + 1) * (Q + 2)) / 6;
44  }
45  if (g == mfem::Geometry::CUBE) {
46  return Q * Q * Q;
47  }
48  return -1;
49 }
50 
55 constexpr int dimension_of(mfem::Geometry::Type g)
56 {
57  if (g == mfem::Geometry::SEGMENT) {
58  return 1;
59  }
60 
61  if (g == mfem::Geometry::TRIANGLE || g == mfem::Geometry::SQUARE) {
62  return 2;
63  }
64 
65  if (g == mfem::Geometry::TETRAHEDRON || g == mfem::Geometry::CUBE) {
66  return 3;
67  }
68 
69  return -1;
70 }
71 
76 inline std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES> geometry_counts(const mfem::Mesh& mesh)
77 {
78  std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES> counts{};
79  for (int i = 0; i < mesh.GetNE(); i++) {
80  counts[uint64_t(mesh.GetElementGeometry(i))]++;
81  }
82  return counts;
83 }
84 
89 inline std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES> boundary_geometry_counts(const mfem::Mesh& mesh)
90 {
91  std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES> counts{};
92  for (int f = 0; f < mesh.GetNumFaces(); f++) {
93  // skip interior faces
94  if (mesh.GetFaceInformation(f).IsInterior()) continue;
95 
96  counts[uint64_t(mesh.GetFaceGeometry(f))]++;
97  }
98  return counts;
99 }
100 
101 } // namespace smith
Accelerator functionality.
Definition: smith.cpp:36
std::array< uint32_t, mfem::Geometry::NUM_GEOMETRIES > geometry_counts(const Domain &domain)
count the number of elements of each geometry in a domain
Definition: domain.hpp:300
constexpr int num_quadrature_points(mfem::Geometry::Type g, int Q)
return the number of quadrature points in a Gauss-Legendre rule with parameter "Q"
Definition: geometry.hpp:31
std::array< uint32_t, mfem::Geometry::NUM_GEOMETRIES > boundary_geometry_counts(const mfem::Mesh &mesh)
count the number of boundary elements of each geometry in a mesh
Definition: geometry.hpp:89
constexpr int dimension_of(mfem::Geometry::Type g)
Returns the dimension of an element geometry.
Definition: geometry.hpp:55
Compile-time alias for a dimension.
Definition: geometry.hpp:17