Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
geometry.hpp
1 #pragma once
2 
3 #include "mfem.hpp"
4 
5 namespace serac {
6 
10 template <int d>
11 struct Dimension {
15  constexpr operator int() { return d; }
16 };
17 
25 constexpr int num_quadrature_points(mfem::Geometry::Type g, int Q)
26 {
27  if (g == mfem::Geometry::SEGMENT) {
28  return Q;
29  }
30  if (g == mfem::Geometry::TRIANGLE) {
31  return (Q * (Q + 1)) / 2;
32  }
33  if (g == mfem::Geometry::SQUARE) {
34  return Q * Q;
35  }
36  if (g == mfem::Geometry::TETRAHEDRON) {
37  return (Q * (Q + 1) * (Q + 2)) / 6;
38  }
39  if (g == mfem::Geometry::CUBE) {
40  return Q * Q * Q;
41  }
42  return -1;
43 }
44 
49 constexpr int dimension_of(mfem::Geometry::Type g)
50 {
51  if (g == mfem::Geometry::SEGMENT) {
52  return 1;
53  }
54 
55  if (g == mfem::Geometry::TRIANGLE || g == mfem::Geometry::SQUARE) {
56  return 2;
57  }
58 
59  if (g == mfem::Geometry::TETRAHEDRON || g == mfem::Geometry::CUBE) {
60  return 3;
61  }
62 
63  return -1;
64 }
65 
70 inline std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES> geometry_counts(const mfem::Mesh& mesh)
71 {
72  std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES> counts{};
73  for (int i = 0; i < mesh.GetNE(); i++) {
74  counts[uint64_t(mesh.GetElementGeometry(i))]++;
75  }
76  return counts;
77 }
78 
83 inline std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES> boundary_geometry_counts(const mfem::Mesh& mesh)
84 {
85  std::array<uint32_t, mfem::Geometry::NUM_GEOMETRIES> counts{};
86  for (int f = 0; f < mesh.GetNumFaces(); f++) {
87  // skip interior faces
88  if (mesh.GetFaceInformation(f).IsInterior()) continue;
89 
90  counts[uint64_t(mesh.GetFaceGeometry(f))]++;
91  }
92  return counts;
93 }
94 
95 } // namespace serac
Accelerator functionality.
Definition: serac.cpp:38
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:25
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:83
constexpr int dimension_of(mfem::Geometry::Type g)
Returns the dimension of an element geometry.
Definition: geometry.hpp:49
std::array< uint32_t, mfem::Geometry::NUM_GEOMETRIES > geometry_counts(const mfem::Mesh &mesh)
count the number of elements of each geometry in a mesh
Definition: geometry.hpp:70
Compile-time alias for a dimension.
Definition: geometry.hpp:11