HyperHDG
slab.h
Go to the documentation of this file.
1 #ifndef TPCC_SLAB_H
2 #define TPCC_SLAB_H
3 
4 #include <algorithm>
5 #include <cassert>
6 #include <tpcc/lexicographic.h>
7 
8 namespace TPCC
9 {
25 template <int n, int k, typename Bint = unsigned int, typename Sint = unsigned short,
26  typename Tint = unsigned char>
27 class Slab
28 {
31  const std::array<Tint, n - 1> directions;
32  const std::array<bool, n - 1> reverse;
33  const Tint normal_direction;
34  const Sint normal_coordinate;
35  const Lexicographic<n - 1, ((k > 0) ? k - 1 : 0), Bint, Sint, Tint> aux;
36 
38  static constexpr std::array<Sint, n - 1> aux_dimensions(
39  const Lexicographic<n, k, Bint, Sint, Tint>& from, const std::array<Tint, n - 1>& directions)
40  {
41  std::array<Sint, n - 1> result{};
42  for (Tint i = 0; i < n - 1; ++i)
43  result[i] = from.fiber_dimension(directions[i]);
44  return result;
45  }
46 
50  std::array<Bint, binomial(n, k)> block_sizes;
51 
52 public:
54  const std::array<Tint, n - 1> directions, const std::array<bool, n - 1>& reverse,
56  : superset(from)
58  , reverse(reverse)
61  , aux(aux_dimensions(from, directions))
62  {
63  static_assert(k >= 1, "Element dimension of slab must be at least 1");
64  // Assert that normal_direction is not in the array of directions
65  assert(std::find(directions.begin(), directions.end(), normal_direction) == directions.end());
66  }
67 
68  constexpr Bint size() const { return aux.size(); }
69 
73  constexpr Bint block_size(Tint block) const { return aux.block_size(block); }
74 
96  {
97  auto local = aux[index];
98  // `local` contains a cut through the elements of the slab. Thus, copy the along directions.
99  std::array<Sint, n> coordinates{};
100  for (Tint i = 0; i < k - 1; ++i)
101  {
102  const Sint c = local.along_coordinate(i);
103  const Tint d = directions[local.along_direction(i)];
104  coordinates[d] = reverse[i] ? (superset.fiber_dimension(d) - c - 1) : (c);
105  }
106  // By definition of a slab, the normal_direction is an along_direction of its elements
107  coordinates[normal_direction] = normal_coordinate;
108  // The remaining coordinates are just copied
109  for (Tint i = 0; i < n - k; ++i)
110  {
111  const Sint c = local.across_coordinate(i);
112  const Tint d = directions[local.across_direction(i)];
113  coordinates[d] = reverse[i] ? (superset.fiber_dimension(d) - c) : (c);
114  }
115  Tint new_direction = (normal_direction < k) ? k : normal_direction;
116  return Element<n, k, Sint, Tint>{ local.orientation.add_and_expand(new_direction),
117  coordinates };
118  }
119 };
120 } // namespace TPCC
121 
122 #endif // TPCC_SLAB_H
TPCC::Element
Tensor coordinates for a facet of dimension k in the complex of dimension n.
Definition: element.h:38
TPCC::Lexicographic::fiber_dimension
constexpr Sint fiber_dimension(Tint i) const
Dimension of the fiber with given index in the tensor product.
Definition: lexicographic.h:131
TPCC::Slab::aux_dimensions
static constexpr std::array< Sint, n - 1 > aux_dimensions(const Lexicographic< n, k, Bint, Sint, Tint > &from, const std::array< Tint, n - 1 > &directions)
Compute the dimensions of the auxiliary object.
Definition: slab.h:38
TPCC::Slab::Slab
constexpr Slab(const Lexicographic< n, k, Bint, Sint, Tint > &from, const std::array< Tint, n - 1 > directions, const std::array< bool, n - 1 > &reverse, Tint normal_direction, Sint normal_coordinate)
Definition: slab.h:53
check_push_test.index
index
Definition: check_push_test.py:10
lexicographic.h
TPCC::Slab::superset
const Lexicographic< n, k, Bint, Sint, Tint > & superset
Definition: slab.h:30
TPCC::Slab::block_sizes
std::array< Bint, binomial(n, k)> block_sizes
The number of objects facing the same directions.
Definition: slab.h:50
TPCC::Slab::super_class
Lexicographic< n, k, Bint, Sint, Tint > super_class
Definition: slab.h:29
TPCC::Slab::reverse
const std::array< bool, n - 1 > reverse
Definition: slab.h:32
TPCC::Slab::normal_coordinate
const Sint normal_coordinate
Definition: slab.h:34
TPCC
Definition: combinations.h:8
TPCC::Combination::add_and_expand
constexpr std::enable_if<(kk<=n), Combination< n+1, k+1, T > >::type add_and_expand(unsigned int i) const
The combination out of n+1 obtained by adding one element.
Definition: combinations.h:164
TPCC::Slab::operator[]
constexpr Element< n, k, Sint, Tint > operator[](Bint index) const
The element at position index, in the coordinates of the whole chain complex.
Definition: slab.h:95
TPCC::Lexicographic
Lexicographic enumeration of the k-dimensional faces in a tensor product chain complex of dimension n...
Definition: lexicographic.h:44
TPCC::Slab::directions
const std::array< Tint, n - 1 > directions
Definition: slab.h:31
TPCC::Element::orientation
Combination< n, k > orientation
A Combination enumerating the coordinate directions along which the element is aligned.
Definition: element.h:47
TPCC::Slab::block_size
constexpr Bint block_size(Tint block) const
The number of elements in one direction.
Definition: slab.h:73
TPCC::Slab::normal_direction
const Tint normal_direction
Definition: slab.h:33
TPCC::binomial
constexpr T binomial(T n, T k)
Compute the binomial coefficient n over k.
Definition: combinations.h:17
TPCC::Slab::aux
const Lexicographic< n - 1,((k > 0) ? k - 1 :0), Bint, Sint, Tint > aux
Definition: slab.h:35
TPCC::Slab::size
constexpr Bint size() const
Definition: slab.h:68