HyperHDG
element.h
Go to the documentation of this file.
1 #ifndef TPCC_ELEMENT_H
2 #define TPCC_ELEMENT_H
3 
4 #include <tpcc/combinations.h>
5 
6 namespace TPCC
7 {
8 template <int n, int k, typename Bint, typename Sint, typename Tint>
9 class Slab;
37 template <int n, int k, typename Sint = unsigned short, typename Tint = unsigned char>
38 class Element
39 {
49  std::array<Sint, n> positions;
50 
51 public:
53  template <typename T>
54  Element(const Combination<n, k>& combi, const std::array<T, n>& pos)
55  : orientation(combi)
56  , positions(pos)
57  {
58  }
59 
60  static constexpr unsigned int n_val = n;
61  static constexpr unsigned int k_val = k;
62 
64  static constexpr Tint n_facets() { return 2 * k; }
65 
67  constexpr Tint direction_index() const { return Combinations<n, k>::index(orientation); }
68 
74  constexpr Sint operator[](Tint index) const { return positions[index]; }
75 
84  constexpr Tint along_direction(Tint index) const { return n - 1 - orientation.in(index); }
85 
87  constexpr Sint along_coordinate(Tint index) const { return positions[along_direction(index)]; }
88 
92  constexpr Tint across_direction(Tint index) const { return n - 1 - orientation.out(index); }
93 
95  constexpr Sint across_coordinate(Tint index) const { return positions[across_direction(index)]; }
96 
112  void print_debug(std::ostream& os) const
113  {
114  os << " (";
115  for (Tint i = 0; i < k; ++i)
116  os << (unsigned int)along_direction(i);
117  os << ':';
118  for (Tint i = 0; i < n - k; ++i)
119  os << (unsigned int)across_direction(i);
120  os << ' ';
121  for (unsigned int i = 0; i < n - 1; ++i)
122  os << positions[i] << ',';
123  os << positions[n - 1] << ")";
124  }
125 
136  constexpr Element<n, k - 1, Sint, Tint> facet(Tint index) const
137  {
138  Tint i2 = index / 2; // The direction index out of k
139  Tint im = index % 2; // Lower or upper boundary in this direction?
140  Tint gi = along_direction(i2); // The global direction out of n belonging to index
141  Combination<n, k - 1> combi = orientation.eliminate(i2);
142  std::array<Sint, n> new_positions = positions;
143  if (im == 1)
144  ++new_positions[gi];
145 
146  return Element<n, k - 1, Sint, Tint>{ combi, new_positions };
147  }
148 
149  template <int, int, typename, typename, typename>
150  friend class Slab;
151 };
152 } // namespace TPCC
153 
154 #endif
TPCC::Element
Tensor coordinates for a facet of dimension k in the complex of dimension n.
Definition: element.h:38
TPCC::Combination::eliminate
constexpr std::enable_if<(kk > 0), Combination< n, k - 1, T > >::type eliminate(unsigned int i) const
The combination obtained by eliminating the ith element.
Definition: combinations.h:98
TPCC::Element::along_direction
constexpr Tint along_direction(Tint index) const
Mapping from local to global coordinate directions.
Definition: element.h:84
check_push_test.index
index
Definition: check_push_test.py:10
combinations.h
TPCC::Element::n_facets
static constexpr Tint n_facets()
The number of facets in the boundary of this object.
Definition: element.h:64
TPCC::Combinations::index
static constexpr unsigned int index(const Combination< n, k, T > &combi)
The index of a combination within the lexicographic enumeration.
Definition: combinations.h:272
TPCC::Element::across_coordinate
constexpr Sint across_coordinate(Tint index) const
The position of the element orthogonal to its extension.
Definition: element.h:95
TPCC::Element::n_val
static constexpr unsigned int n_val
Definition: element.h:60
TPCC::Element::Element
Element(const Combination< n, k > &combi, const std::array< T, n > &pos)
Constructor with both data elements.
Definition: element.h:54
TPCC::Element::across_direction
constexpr Tint across_direction(Tint index) const
Mapping of orthogonal coordinate directions to global.
Definition: element.h:92
TPCC
Definition: combinations.h:8
TPCC::Element::k_val
static constexpr unsigned int k_val
Definition: element.h:61
TPCC::Combination::in
T in(unsigned int i) const
The ith element which is part of the combination in descending order.
Definition: combinations.h:79
TPCC::Element::orientation
Combination< n, k > orientation
A Combination enumerating the coordinate directions along which the element is aligned.
Definition: element.h:47
TPCC::Element::along_coordinate
constexpr Sint along_coordinate(Tint index) const
The coordinates in the k-dimensional element.
Definition: element.h:87
TPCC::Combination< n, k >
TPCC::Combination::out
T out(unsigned int i) const
The ith element which is not part of the combination in descending order.
Definition: combinations.h:84
TPCC::Element::print_debug
void print_debug(std::ostream &os) const
Function for printing the data stored in the element.
Definition: element.h:112
TPCC::Element::operator[]
constexpr Sint operator[](Tint index) const
The coordinates in the n-dimensional chain complex.
Definition: element.h:74
TPCC::Element::facet
constexpr Element< n, k - 1, Sint, Tint > facet(Tint index) const
Enumeration of the boundary facets of the element.
Definition: element.h:136
TPCC::Element::direction_index
constexpr Tint direction_index() const
The index of the combination enumerating directions.
Definition: element.h:67
TPCC::Element::positions
std::array< Sint, n > positions
The integer coordinates within the n-dimensional complex.
Definition: element.h:49
TPCC::Slab
A slab of thickness one cell cut out of a tensor product chain complex.
Definition: element.h:9