HyperHDG
tpcc.hxx
Go to the documentation of this file.
1 /*!*************************************************************************************************
2  * \file tpcc.hxx
3  * \brief This file provides the functions of the submodule TPCC.
4  *
5  * This is a wrapper file to provide TPCC (tensor product chain complex) based functions. Since this
6  * is an external submodule utilized by hyperHDG, this file provides appropriate wrapper functions.
7  *
8  * \authors Guido Kanschat, Heidelberg University, 2019--2020.
9  * \authors Andreas Rupp, Heidelberg University, 2019--2020.
10  **************************************************************************************************/
11 
12 #pragma once // Ensure that file is included only once in a single compilation.
13 
14 #include <tpcc/lexicographic.h> // Submodule which is wrapped by this file!
15 #include <HyperHDG/dense_la.hxx>
16 #include <HyperHDG/hy_assert.hxx>
17 
18 namespace Wrapper
19 {
20 // -------------------------------------------------------------------------------------------------
21 // Wrapper classes for mathematical helper functions.
22 // -------------------------------------------------------------------------------------------------
23 
24 /*!*************************************************************************************************
25  * \brief Binomial coefficient of unsigned integers.
26  **************************************************************************************************/
27 unsigned int binomial(unsigned int n, unsigned int k)
28 {
29  return TPCC::binomial<unsigned int>(n, k);
30 }
31 
32 // -------------------------------------------------------------------------------------------------
33 // Wrapper classes for tensor product chain complex and its elements.
34 // -------------------------------------------------------------------------------------------------
35 
36 /*!*************************************************************************************************
37  * \brief Type of a tensor product chain complex.
38  **************************************************************************************************/
39 template <unsigned int hyEdge_dim,
40  unsigned int space_dim,
42  typename index_t = unsigned int>
43 using tpcc_t =
45 /*!*************************************************************************************************
46  * \brief Type of an element of a tensor product chain complex.
47  **************************************************************************************************/
48 template <unsigned int hyEdge_dim, unsigned int space_dim>
50 
51 // -------------------------------------------------------------------------------------------------
52 // Functions considering full tensor product chain complexes.
53 // -------------------------------------------------------------------------------------------------
54 
55 /*!*************************************************************************************************
56  * \brief Create a tensor product chain complex.
57  **************************************************************************************************/
58 template <unsigned int hyEdge_dim,
59  unsigned int space_dim,
61  typename index_t = unsigned int>
63 {
64  static_assert(space_dim >= hyEdge_dim, "Hypercube dim must not be bigger than spatial dim!");
66  vec.data());
67 }
68 /*!*************************************************************************************************
69  * \brief Create a tensor product chain complex associated to the facets.
70  **************************************************************************************************/
71 template <typename TPCC::boundaries bndT>
72 auto tpcc_faces(const auto& elements)
73 {
74  return elements.template boundary<bndT>();
75 }
76 /*!*************************************************************************************************
77  * \brief Return the element of given index the TPCC.
78  **************************************************************************************************/
79 template <typename index_t = unsigned int>
80 index_t n_elements(const auto& tpcc)
81 {
82  return tpcc.size();
83 }
84 
85 // -------------------------------------------------------------------------------------------------
86 // Functions related to single elements.
87 // -------------------------------------------------------------------------------------------------
88 
89 /*!*************************************************************************************************
90  * \brief Return the element of given index the TPCC.
91  **************************************************************************************************/
92 auto get_element(const auto& tpcc, const auto index)
93 {
94  hy_assert(index < tpcc.size(), "Index " << index << " must not be bigger than the TPCC "
95  << "size, which is " << tpcc.size() << ".");
96  return tpcc.operator[](index);
97 }
98 /*!*************************************************************************************************
99  * \brief Return index of given element within TPCC.
100  **************************************************************************************************/
101 template <typename index_t = unsigned int>
102 index_t get_index(const auto& tpcc, const auto& elem)
103 {
104  index_t index = tpcc.index(elem);
105  hy_assert(index < tpcc.size(), "Returned index is larger than number of elements!");
106  return index;
107 }
108 /*!*************************************************************************************************
109  * \brief Return index of given element within TPCC.
110  **************************************************************************************************/
111 template <typename index_t = unsigned int>
112 index_t get_index_in_slice(const auto& tpcc, const auto& elem)
113 {
114  index_t index = tpcc.index_in_slice(elem);
115  // hy_assert(index < tpcc.size(), "Returned index is larger than number of elements!");
116  return index;
117 }
118 /*!*************************************************************************************************
119  * \brief Return i-th element facet.
120  **************************************************************************************************/
121 auto get_face(const auto& elem, const unsigned int index)
122 {
123  hy_assert(index < elem.n_facets(), "An element hast only " << elem.n_facets() << "facets. "
124  << "You requested number " << index
125  << ".");
126  return elem.facet(index);
127 }
128 /*!*************************************************************************************************
129  * \brief Determine the orientation of an element.
130  **************************************************************************************************/
131 unsigned int elem_orientation(const auto& elem)
132 {
133  return elem.direction_index();
134 }
135 /*!*************************************************************************************************
136  * \brief Return the index-th orthonormal direction to element.
137  **************************************************************************************************/
138 unsigned int exterior_direction(const auto& elem, const unsigned int index)
139 {
140  hy_assert(index < elem.n_val - elem.k_val,
141  "There are only " << elem.n_val - elem.k_val << " exterior directions.");
142  unsigned int acr_dir = elem.across_direction(index);
143  hy_assert(acr_dir < elem.n_val,
144  "Exterior direction must be smaller than amount of spatial dimensions!");
145  return acr_dir;
146 }
147 /*!*************************************************************************************************
148  * \brief Return coordinate value with respect to index-th orthonormal direction on element.
149  **************************************************************************************************/
150 unsigned int exterior_coordinate(const auto& elem, const unsigned int index)
151 {
152  hy_assert(index < elem.n_val - elem.k_val,
153  "There are only " << elem.n_val - elem.k_val << " exterior directions.");
154  return elem.across_coordinate(index);
155 }
156 /*!*************************************************************************************************
157  * \brief Return coordinate value with respect to index-th orthonormal direction of element.
158  **************************************************************************************************/
159 unsigned int interior_coordinate(const auto& elem, const unsigned int index)
160 {
161  hy_assert(index < elem.k_val,
162  "There are only " << elem.n_val - elem.k_val << " exterior directions.");
163  return elem.along_coordinate(index);
164 }
165 
166 } // end of namespace Wrapper
TPCC::Element
Tensor coordinates for a facet of dimension k in the complex of dimension n.
Definition: element.h:38
hy_assert.hxx
This file provides the function hy_assert.
Wrapper
A namespace containing the different wrapper functions.
Definition: lapack.hxx:20
check_push_test.index
index
Definition: check_push_test.py:10
Wrapper::get_index
index_t get_index(const auto &tpcc, const auto &elem)
Return index of given element within TPCC.
Definition: tpcc.hxx:102
TPCC::both
@ both
Definition: lexicographic.h:11
lexicographic.h
Wrapper::get_index_in_slice
index_t get_index_in_slice(const auto &tpcc, const auto &elem)
Return index of given element within TPCC.
Definition: tpcc.hxx:112
TPCC::boundaries
boundaries
Definition: lexicographic.h:9
Wrapper::exterior_coordinate
unsigned int exterior_coordinate(const auto &elem, const unsigned int index)
Return coordinate value with respect to index-th orthonormal direction on element.
Definition: tpcc.hxx:150
Wrapper::get_face
auto get_face(const auto &elem, const unsigned int index)
Return i-th element facet.
Definition: tpcc.hxx:121
Wrapper::tpcc_faces
auto tpcc_faces(const auto &elements)
Create a tensor product chain complex associated to the facets.
Definition: tpcc.hxx:72
Wrapper::interior_coordinate
unsigned int interior_coordinate(const auto &elem, const unsigned int index)
Return coordinate value with respect to index-th orthonormal direction of element.
Definition: tpcc.hxx:159
Wrapper::get_element
auto get_element(const auto &tpcc, const auto index)
Return the element of given index the TPCC.
Definition: tpcc.hxx:92
Wrapper::n_elements
index_t n_elements(const auto &tpcc)
Return the element of given index the TPCC.
Definition: tpcc.hxx:80
Wrapper::binomial
unsigned int binomial(unsigned int n, unsigned int k)
Binomial coefficient of unsigned integers.
Definition: tpcc.hxx:27
TPCC::Lexicographic
Lexicographic enumeration of the k-dimensional faces in a tensor product chain complex of dimension n...
Definition: lexicographic.h:44
SmallMat::data
std::array< mat_entry_t, size()> & data()
Return data array that allows to manipulate the SmallMat.
Definition: dense_la.hxx:190
hy_assert
#define hy_assert(Expr, Msg)
The assertion to be used within HyperHDG — deactivate using -DNDEBUG compile flag.
Definition: hy_assert.hxx:38
dense_la.hxx
Wrapper::tpcc_t
TPCC::Lexicographic< space_dim, hyEdge_dim, bndT, index_t, unsigned int, unsigned int > tpcc_t
Type of a tensor product chain complex.
Definition: tpcc.hxx:44
Wrapper::elem_orientation
unsigned int elem_orientation(const auto &elem)
Determine the orientation of an element.
Definition: tpcc.hxx:131
Wrapper::create_tpcc
tpcc_t< hyEdge_dim, space_dim, bndT, index_t > create_tpcc(const SmallVec< space_dim, index_t > &vec)
Create a tensor product chain complex.
Definition: tpcc.hxx:62
SmallMat
This class implements a small/dense matrix.
Definition: dense_la.hxx:34
Wrapper::exterior_direction
unsigned int exterior_direction(const auto &elem, const unsigned int index)
Return the index-th orthonormal direction to element.
Definition: tpcc.hxx:138