HyperHDG
hypercube.hxx
Go to the documentation of this file.
1 #pragma once // Ensure that file is included only once in a single compilation.
2 
3 /*!*************************************************************************************************
4  * \brief Helper class containing numbers and functions related to hypercubes.
5  *
6  * \tparam dim Unsigned integer indicating the dimension of the considered hypercube.
7  *
8  * \authors Guido Kanschat, Heidelberg University, 2019--2020.
9  * \authors Andreas Rupp, Heidelberg University, 2019--2020.
10  **************************************************************************************************/
11 template <unsigned int dimT>
12 struct Hypercube
13 {
14  /*!***********************************************************************************************
15  * \brief Number of faces of the hypercube.
16  ************************************************************************************************/
17  static constexpr unsigned int n_faces() { return 2 * dimT; }
18  /*!***********************************************************************************************
19  * \brief Number of vertices of the hypercube.
20  ************************************************************************************************/
21  static constexpr unsigned int n_vertices() { return 1 << dimT; }
22  /*!***********************************************************************************************
23  * \brief Return \c n to the power \c dim.
24  ************************************************************************************************/
25  static constexpr unsigned int pow(unsigned int base)
26  {
27  unsigned int result = 1;
28  if constexpr (dimT > 0)
29  for (unsigned int i = 0; i < dimT; ++i)
30  result *= base;
31  return result;
32  }
33  /*!***********************************************************************************************
34  * \brief Decompose global index of tensorial structure with respect to its dimensions.
35  *
36  * \param index Local tensorial index (e.g. of the shape function or point).
37  * \param range Range (maximum, excluded) of the 1D indices.
38  * \retval decomposition Array consisting of respective one-dimensional indices.
39  ************************************************************************************************/
40  static inline std::array<unsigned int, std::max(dimT, 1U)> index_decompose(
41  unsigned int index,
42  const unsigned int range)
43  {
44  std::array<unsigned int, std::max(dimT, 1U)> decomposition;
45  for (unsigned int dim = 0; dim < decomposition.size(); ++dim)
46  {
47  decomposition[dim] = index % range;
48  index /= range;
49  }
50  hy_assert(index == 0, "Index initially exceeded given maximum value range^dimT.");
51  return decomposition;
52  }
53  /*!***********************************************************************************************
54  * \brief Generate tensorial point whose entries are elements of an array.
55  *
56  * \param index Local tensorial index (e.g. of the shape function or point).
57  * \param points Array of possible values of point components.
58  * \retval point Tensorial point of given index.
59  ************************************************************************************************/
60  template <typename point_t, typename array_t>
61  static constexpr point_t tensorial_pt(__attribute__((unused)) const unsigned int index,
62  const array_t& points)
63  {
64  static_assert(point_t::size() == dimT, "Point must have appropriate dimension!");
65  point_t point;
66  if constexpr (dimT > 0)
67  {
68  std::array<unsigned int, std::max(dimT, 1U)> decomp = index_decompose(index, array_t::size());
69  for (unsigned int dim = 0; dim < dimT; ++dim)
70  point[dim] = points[decomp[dim]];
71  }
72  return point;
73  }
74 }; // end of struct Hypercube
check_push_test.index
index
Definition: check_push_test.py:10
Hypercube::index_decompose
static std::array< unsigned int, std::max(dimT, 1U)> index_decompose(unsigned int index, const unsigned int range)
Decompose global index of tensorial structure with respect to its dimensions.
Definition: hypercube.hxx:40
Hypercube::n_vertices
static constexpr unsigned int n_vertices()
Number of vertices of the hypercube.
Definition: hypercube.hxx:21
Hypercube::tensorial_pt
static constexpr point_t tensorial_pt(__attribute__((unused)) const unsigned int index, const array_t &points)
Generate tensorial point whose entries are elements of an array.
Definition: hypercube.hxx:61
Hypercube::pow
static constexpr unsigned int pow(unsigned int base)
Return n to the power dim.
Definition: hypercube.hxx:25
hy_assert
#define hy_assert(Expr, Msg)
The assertion to be used within HyperHDG — deactivate using -DNDEBUG compile flag.
Definition: hy_assert.hxx:38
Hypercube::n_faces
static constexpr unsigned int n_faces()
Number of faces of the hypercube.
Definition: hypercube.hxx:17
Hypercube
Helper class containing numbers and functions related to hypercubes.
Definition: hypercube.hxx:12