HyperHDG
cubic.hxx
Go to the documentation of this file.
1 #pragma once // Ensure that file is included only once in a single compilation.
2 
3 #include <HyperHDG/hy_assert.hxx>
4 #include <HyperHDG/hypercube.hxx>
6 
7 namespace Topology
8 {
9 /*!*************************************************************************************************
10  * \brief Definition of the topology of a hypergraph --- Cubic HyperGraphs.
11  *
12  * One of the advantages of this software package is the strict discrimination between the topology
13  * and the geometry of the domain \f$\Omega\f$. Thus, one can exemplarily define a single topology
14  * (the one of a cube) to approximate PDEs that live on the cube's boundary and PDEs that live on a
15  * sphere, since their topology is the same. However, different geometries have to be defined, since
16  * these obviously are not equal. Thus, all parts of the code that involve communication and/or
17  * solving systems of equations are reusable in a much more general (than the standard) sense.
18  * Beyond that, absurd (on first sight) domains can be defined easily. This also covers variously
19  * periodic domains, for example.
20  *
21  * \tparam hyEdge_dimT Dimension of a hyperedge, i.e., 1 is for PDEs defined on graphs, 2 is
22  * for PDEs defined on surfaces, and 3 is for PDEs defined on volumes.
23  * \tparam space_dimT The dimension of the space, the object is located in. This number should
24  * be larger than or equal to hyEdge_dimT.
25  * \tparam NodeIncesVecT The vector type of an array containing the node indices of an hyperedge.
26  * \tparam ConstructorVecT The vector type of the constructor.
27  * \tparam hyEdge_index_t The index type of an hyperedge.
28  * \tparam NodeOrientationT The class type that encodes the orientation of the hypernodes with
29  * respect to a given hyperedge.
30  *
31  * \authors Guido Kanschat, Heidelberg University, 2019--2020.
32  * \authors Andreas Rupp, Heidelberg University, 2019--2020.
33  **************************************************************************************************/
34 template <unsigned int hyEdge_dimT,
35  unsigned int space_dimT,
36  typename NodeIndexVecT = SmallVec<2 * hyEdge_dimT, unsigned int>,
37  typename ConstructorVecT = SmallVec<space_dimT, unsigned int>,
38  typename hyEdge_index_t = typename NodeIndexVecT::value_type,
39  typename NodeOrientationT = SmallVec<2 * hyEdge_dimT - 2, unsigned int> >
40 class Cubic
41 {
42  using hyNode_index_t = typename NodeIndexVecT::value_type;
43  /*!***********************************************************************************************
44  * \brief Definition of the topology of a hypergraph's edges --- Cubic HyperGraph's edges.
45  *
46  * \authors Guido Kanschat, Heidelberg University, 2019--2020.
47  * \authors Andreas Rupp, Heidelberg University, 2019--2020.
48  ************************************************************************************************/
49  class hyEdge
50  {
51  private:
52  /*!*********************************************************************************************
53  * \brief Indices of the hypernodes adjacent to the hyperedge.
54  **********************************************************************************************/
55  NodeIndexVecT hyNode_indices_;
56 
57  public:
58  /*!*********************************************************************************************
59  * \brief Construct a cubic hyperedge from its index and a the global topology class.
60  *
61  * \param index The index of the hyperedge to be created.
62  * \param topology A cubic topology.
63  **********************************************************************************************/
64  hyEdge(const hyEdge_index_t index, const Cubic& topology)
65  {
67  Wrapper::get_element(topology.tpcc_elements_, index / topology.n_elem_per_elem);
68  for (unsigned int i = 0; i < hyNode_indices_.size(); ++i)
69  {
70  Wrapper::tpcc_elem_t<hyEdge_dimT - 1, space_dimT> face = Wrapper::get_face(elem, i);
71  hyNode_indices_[i] = Wrapper::get_index(topology.tpcc_faces_, face);
72  }
73 
75  Wrapper::get_element(topology.tpcc_ref_elem_, index % topology.n_elem_per_elem);
76  for (unsigned int i = 0; i < hyNode_indices_.size(); ++i)
77  {
78  Wrapper::tpcc_elem_t<hyEdge_dimT - 1, hyEdge_dimT> face = Wrapper::get_face(ref_elem, i);
79  if (Wrapper::exterior_coordinate(face, 0) == 0 ||
80  Wrapper::exterior_coordinate(face, 0) == topology.n_subintervals_)
81  hyNode_indices_[i] = topology.n_face_per_face * hyNode_indices_[i] +
82  Wrapper::get_index_in_slice(topology.tpcc_ref_faces_, face);
83  else
84  hyNode_indices_[i] = topology.n_coarse_face * topology.n_face_per_face +
85  topology.n_face_per_elem * (index / topology.n_elem_per_elem) +
86  Wrapper::get_index(topology.tpcc_ref_faces_, face);
87  }
88  }
89  /*!*********************************************************************************************
90  * \brief Return indices of hypernodes adjacent to the hyperedge.
91  *
92  * \retval hypernode_indices Topological information on the hyperedge (cf. \c value_type).
93  **********************************************************************************************/
94  const NodeIndexVecT& get_hyNode_indices() const { return hyNode_indices_; }
95  /*!*********************************************************************************************
96  * \brief Return orienation of hypernode.
97  **********************************************************************************************/
98  const NodeOrientationT get_hyNode_oriantation(unsigned int) const { return NodeOrientationT(); }
99  }; // end of class hyEdge
100 
101  public:
102  /*!***********************************************************************************************
103  * \brief Return the template parameter representing the dimension of a hyperedge.
104  *
105  * \retval hyEdge_dimT The dimension of a hyperedge.
106  ************************************************************************************************/
107  static constexpr unsigned int hyEdge_dim() { return hyEdge_dimT; };
108  /*!***********************************************************************************************
109  * \brief Return the template parameter representing the dimension of the space.
110  *
111  * \retval space_dimT The dimension of the space.
112  ************************************************************************************************/
113  static constexpr unsigned int space_dim() { return space_dimT; };
114 
115  private:
116  /*!***********************************************************************************************
117  * \brief Number of elements per spatial dimension.
118  ************************************************************************************************/
119  const ConstructorVecT n_elements_;
120  /*!***********************************************************************************************
121  * \brief Tensor product chain complex for elements.
122  ************************************************************************************************/
125  /*!***********************************************************************************************
126  * \brief Tensor product chain complex for faces.
127  ************************************************************************************************/
128  const Wrapper::tpcc_t<hyEdge_dimT - 1, space_dimT, TPCC::boundaries::both, hyNode_index_t>
130 
131  /*!***********************************************************************************************
132  * \brief Refinment level corresponds to number of subintervals per dimension.
133  ************************************************************************************************/
134  unsigned int n_subintervals_;
135  /*!***********************************************************************************************
136  * \brief Tensor product chain complex for refining a hyperedge into elements.
137  ************************************************************************************************/
139  /*!***********************************************************************************************
140  * \brief Tensor product chain complex for refining a hyperedge into faces.
141  ************************************************************************************************/
142  Wrapper::tpcc_t<hyEdge_dimT - 1, hyEdge_dimT, TPCC::boundaries::none, hyNode_index_t>
144  /*!***********************************************************************************************
145  * \brief Number of refined elements per corase element.
146  ************************************************************************************************/
147  unsigned int n_elem_per_elem;
148  /*!***********************************************************************************************
149  * \brief Number of refined faces per corase face.
150  ************************************************************************************************/
151  unsigned int n_face_per_face;
152  /*!***********************************************************************************************
153  * \brief Number of refined faces per corase element.
154  ************************************************************************************************/
155  unsigned int n_face_per_elem;
156  /*!***********************************************************************************************
157  * \brief Number of refined corase elements.
158  ************************************************************************************************/
159  unsigned int n_coarse_elem;
160  /*!***********************************************************************************************
161  * \brief Number of refined corase faces.
162  ************************************************************************************************/
163  unsigned int n_coarse_face;
164 
165  /*!***********************************************************************************************
166  * \brief Total amount of hyperedges.
167  ************************************************************************************************/
168  hyEdge_index_t n_hyEdges_;
169  /*!***********************************************************************************************
170  * \brief Total amount of hypernodes.
171  ************************************************************************************************/
173 
174  public:
175  /*!***********************************************************************************************
176  * \brief Define the return value of the class.
177  ************************************************************************************************/
179  /*!***********************************************************************************************
180  * \brief Define the value type of input argument for standard constructor.
181  ************************************************************************************************/
182  typedef ConstructorVecT constructor_value_type;
183  /*!***********************************************************************************************
184  * \brief Construct a cubic hypergraph.
185  *
186  * \param n_elements A vector / array containing number of elements per dimension.
187  ************************************************************************************************/
191  Wrapper::create_tpcc<hyEdge_dimT, space_dimT, TPCC::boundaries::both, hyEdge_index_t>(
192  n_elements)),
194  n_subintervals_(1),
196  Wrapper::create_tpcc<hyEdge_dimT, hyEdge_dimT, TPCC::boundaries::both, hyEdge_index_t>(
197  SmallVec<hyEdge_dimT, unsigned int>(n_subintervals_))),
200  n_face_per_face(Hypercube<hyEdge_dimT - 1>::pow(n_subintervals_)),
206  {
207  }
208  /*!***********************************************************************************************
209  * \brief Construct a hypergraph topology from another hypergraph topology.
210  *
211  * Create a (value based) copy of another hypergraph.
212  *
213  * \param other Hypergraph to be copied.
214  ************************************************************************************************/
216  : n_elements_(other.n_elements_),
218  tpcc_faces_(other.tpcc_faces_),
227  n_hyEdges_(other.n_hyEdges_),
228  n_hyNodes_(other.n_hyNodes_)
229  {
230  }
231  /*!***********************************************************************************************
232  * \brief Get topological hyperedge of given index.
233  *
234  * This function returns the hyperedge of the given index, i.e., it returns the topological
235  * hyperedge (\b not the geometrical information). The topological informatiom comprises the
236  * indices of adjacent hypernodes and information about their respective orientations.
237  *
238  * \param index The index of the hyperedge to be returned.
239  * \retval hyperedge Topological information on the hyperedge (cf. \c value_type).
240  ************************************************************************************************/
241  const value_type operator[](const hyEdge_index_t index) const
242  {
243  hy_assert(index >= 0 && index < n_hyEdges_,
244  "The index of an hyperedge must be non-negative and smaller than the total amount "
245  << "of hyperedges, which is " << n_hyEdges_ << ". Nonetheless, the " << index
246  << "-th hyperedge is tried to be accessed.");
247  return hyEdge(index, *this);
248  }
249  /*!***********************************************************************************************
250  * \brief Read the array of elements per dimensions.
251  *
252  * \retval n_elements A vector / arary containing the elements in the repective dimension.
253  ************************************************************************************************/
254  const ConstructorVecT& n_elements() const { return n_elements_; }
255  /*!***********************************************************************************************
256  * \brief Tensor product chain complex for elements.
257  ************************************************************************************************/
259  tpcc_elem() const
260  {
261  return tpcc_elements_;
262  }
263  /*!***********************************************************************************************
264  * \brief Tensor product chain complex for faces.
265  ************************************************************************************************/
266  const Wrapper::tpcc_t<hyEdge_dimT - 1, space_dimT, TPCC::boundaries::both, hyNode_index_t>&
267  tpcc_face() const
268  {
269  return tpcc_faces_;
270  }
271  /*!***********************************************************************************************
272  * \brief Tensor product chain complex of 'local' / refined elements.
273  ************************************************************************************************/
276  {
277  return tpcc_ref_elem_;
278  }
279  /*!***********************************************************************************************
280  * \brief Return the number of hyperedges making up the hypergraph.
281  *
282  * \retval n_hyperedges The total amount of hyperedges of a hypergraph.
283  ************************************************************************************************/
284  const hyEdge_index_t n_hyEdges() const { return n_hyEdges_; }
285  /*!***********************************************************************************************
286  * \brief Return the number of hypernodes making up the hypergraph.
287  *
288  * \retval n_hypernodes The total amount of hypernodes of a hypergraph.
289  ************************************************************************************************/
290  const hyNode_index_t n_hyNodes() const { return n_hyNodes_; }
291  /*!***********************************************************************************************
292  * \brief Return the refinement level (equal to number of subintervals).
293  ************************************************************************************************/
294  unsigned int get_refinement() const { return n_subintervals_; }
295  /*!***********************************************************************************************
296  * \brief Set the refinement level (equal to number of subintervals).
297  ************************************************************************************************/
298  void set_refinement(unsigned int level)
299  {
300  n_subintervals_ = level;
302  Wrapper::create_tpcc<hyEdge_dimT, hyEdge_dimT, TPCC::boundaries::both, hyEdge_index_t>(
304  tpcc_ref_faces_ = Wrapper::tpcc_faces<TPCC::boundaries::none>(tpcc_ref_elem_);
312  }
313 
314 }; // end of class Cubic
315 
316 } // end of namespace Topology
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
Topology::Cubic::n_coarse_elem
unsigned int n_coarse_elem
Number of refined corase elements.
Definition: cubic.hxx:159
Topology::Cubic::tpcc_ref_elem_
Wrapper::tpcc_t< hyEdge_dimT, hyEdge_dimT, TPCC::boundaries::both, hyNode_index_t > tpcc_ref_elem_
Tensor product chain complex for refining a hyperedge into elements.
Definition: cubic.hxx:138
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
Topology
A namespace containing different classes describing hypergraph topologies.
Definition: cubic.hxx:7
Topology::Cubic::n_face_per_face
unsigned int n_face_per_face
Number of refined faces per corase face.
Definition: cubic.hxx:151
Topology::Cubic::n_elem_per_elem
unsigned int n_elem_per_elem
Number of refined elements per corase element.
Definition: cubic.hxx:147
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
Topology::Cubic::operator[]
const value_type operator[](const hyEdge_index_t index) const
Get topological hyperedge of given index.
Definition: cubic.hxx:241
Topology::Cubic::tpcc_ref_elem
const Wrapper::tpcc_t< hyEdge_dimT, hyEdge_dimT, TPCC::boundaries::both, hyNode_index_t > & tpcc_ref_elem() const
Tensor product chain complex of 'local' / refined elements.
Definition: cubic.hxx:275
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
tpcc.hxx
This file provides the functions of the submodule TPCC.
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
TPCC::none
@ none
Definition: lexicographic.h:12
Wrapper::get_element
auto get_element(const auto &tpcc, const auto index)
Return the element of given index the TPCC.
Definition: tpcc.hxx:92
Topology::Cubic::Cubic
Cubic(const Cubic< hyEdge_dimT, space_dimT > &other)
Construct a hypergraph topology from another hypergraph topology.
Definition: cubic.hxx:215
TPCC
Definition: combinations.h:8
Topology::Cubic::n_elements_
const ConstructorVecT n_elements_
Number of elements per spatial dimension.
Definition: cubic.hxx:113
Topology::Cubic::tpcc_ref_faces_
Wrapper::tpcc_t< hyEdge_dimT - 1, hyEdge_dimT, TPCC::boundaries::none, hyNode_index_t > tpcc_ref_faces_
Tensor product chain complex for refining a hyperedge into faces.
Definition: cubic.hxx:143
Topology::Cubic::set_refinement
void set_refinement(unsigned int level)
Set the refinement level (equal to number of subintervals).
Definition: cubic.hxx:298
Topology::Cubic::tpcc_faces_
const Wrapper::tpcc_t< hyEdge_dimT - 1, space_dimT, TPCC::boundaries::both, hyNode_index_t > tpcc_faces_
Tensor product chain complex for faces.
Definition: cubic.hxx:129
Topology::Cubic::n_coarse_face
unsigned int n_coarse_face
Number of refined corase faces.
Definition: cubic.hxx:163
Topology::Cubic::hyEdge_dim
static constexpr unsigned int hyEdge_dim()
Return the template parameter representing the dimension of a hyperedge.
Definition: cubic.hxx:107
Wrapper::n_elements
index_t n_elements(const auto &tpcc)
Return the element of given index the TPCC.
Definition: tpcc.hxx:80
Topology::Cubic::hyEdge::hyNode_indices_
NodeIndexVecT hyNode_indices_
Indices of the hypernodes adjacent to the hyperedge.
Definition: cubic.hxx:55
TPCC::Lexicographic
Lexicographic enumeration of the k-dimensional faces in a tensor product chain complex of dimension n...
Definition: lexicographic.h:44
Topology::Cubic::n_subintervals_
unsigned int n_subintervals_
Refinment level corresponds to number of subintervals per dimension.
Definition: cubic.hxx:134
Topology::Cubic::hyNode_index_t
typename NodeIndexVecT::value_type hyNode_index_t
Definition: cubic.hxx:42
Topology::Cubic::hyEdge
Definition of the topology of a hypergraph's edges — Cubic HyperGraph's edges.
Definition: cubic.hxx:49
Topology::Cubic::n_elements
const ConstructorVecT & n_elements() const
Read the array of elements per dimensions.
Definition: cubic.hxx:254
Topology::Cubic
Definition of the topology of a hypergraph — Cubic HyperGraphs.
Definition: cubic.hxx:40
Topology::Cubic::n_hyEdges_
hyEdge_index_t n_hyEdges_
Total amount of hyperedges.
Definition: cubic.hxx:168
Topology::Cubic::space_dim
static constexpr unsigned int space_dim()
Return the template parameter representing the dimension of the space.
Definition: cubic.hxx:113
Topology::Cubic::constructor_value_type
ConstructorVecT constructor_value_type
Define the value type of input argument for standard constructor.
Definition: cubic.hxx:182
Topology::Cubic::hyEdge::get_hyNode_indices
const NodeIndexVecT & get_hyNode_indices() const
Return indices of hypernodes adjacent to the hyperedge.
Definition: cubic.hxx:94
Topology::Cubic::tpcc_face
const Wrapper::tpcc_t< hyEdge_dimT - 1, space_dimT, TPCC::boundaries::both, hyNode_index_t > & tpcc_face() const
Tensor product chain complex for faces.
Definition: cubic.hxx:267
hypercube.hxx
Topology::Cubic::tpcc_elem
const Wrapper::tpcc_t< hyEdge_dimT, space_dimT, TPCC::boundaries::both, hyNode_index_t > & tpcc_elem() const
Tensor product chain complex for elements.
Definition: cubic.hxx:259
Hypercube::pow
static constexpr unsigned int pow(unsigned int base)
Return n to the power dim.
Definition: hypercube.hxx:25
Topology::Cubic::hyEdge::hyEdge
hyEdge(const hyEdge_index_t index, const Cubic &topology)
Construct a cubic hyperedge from its index and a the global topology class.
Definition: cubic.hxx:64
Topology::Cubic::n_hyNodes
const hyNode_index_t n_hyNodes() const
Return the number of hypernodes making up the hypergraph.
Definition: cubic.hxx:290
Topology::Cubic::n_hyEdges
const hyEdge_index_t n_hyEdges() const
Return the number of hyperedges making up the hypergraph.
Definition: cubic.hxx:284
Topology::Cubic::hyEdge::get_hyNode_oriantation
const NodeOrientationT get_hyNode_oriantation(unsigned int) const
Return orienation of hypernode.
Definition: cubic.hxx:98
Topology::Cubic::n_hyNodes_
hyNode_index_t n_hyNodes_
Total amount of hypernodes.
Definition: cubic.hxx:172
hy_assert
#define hy_assert(Expr, Msg)
The assertion to be used within HyperHDG — deactivate using -DNDEBUG compile flag.
Definition: hy_assert.hxx:38
Topology::Cubic::n_face_per_elem
unsigned int n_face_per_elem
Number of refined faces per corase element.
Definition: cubic.hxx:155
Topology::Cubic::value_type
hyEdge value_type
Define the return value of the class.
Definition: cubic.hxx:178
Topology::Cubic::tpcc_elements_
const Wrapper::tpcc_t< hyEdge_dimT, space_dimT, TPCC::boundaries::both, hyNode_index_t > tpcc_elements_
Tensor product chain complex for elements.
Definition: cubic.hxx:124
Topology::Cubic::get_refinement
unsigned int get_refinement() const
Return the refinement level (equal to number of subintervals).
Definition: cubic.hxx:294
diffusion_uniform.topology
topology
Definition: diffusion_uniform.py:18
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
Topology::Cubic::Cubic
Cubic(const constructor_value_type &n_elements)
Construct a cubic hypergraph.
Definition: cubic.hxx:188
SmallMat
This class implements a small/dense matrix.
Definition: dense_la.hxx:34
Hypercube
Helper class containing numbers and functions related to hypercubes.
Definition: hypercube.hxx:12