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>
5 #include <cmath>
6 
7 namespace NodeDescriptor
8 {
9 /*!*************************************************************************************************
10  * \brief Definition of the node types of a cubic hypergraph.
11  *
12  * In a cubic hypergraph \f$\mathcal G\f$, the nodes receive their indices according to their
13  * positions. Thus, the node type \f$t\f$ of node \f$\mathcal N\f$ is defined as
14  * \f[
15  * t = \sum_{n=1}^\text{space_dim} 3^n \left[ ( \Pi_n \mathcal N == \{ \min \Pi_n \mathcal G \} )
16  * + 2 ( \Pi_n \mathcal N == \{ \max \Pi_n \mathcal G \} ) \right],
17  * \f]
18  * where \f$\Pi_n\f$ is the orthonormal projection onto the \f$n\f$-th axis of the canonical basis.
19  *
20  * \authors Guido Kanschat, Heidelberg University, 2019--2020.
21  * \authors Andreas Rupp, Heidelberg University, 2019--2020.
22  **************************************************************************************************/
23 template <unsigned int hyEdge_dimT,
24  unsigned int space_dimT,
25  typename NodeTypeVecT = SmallVec<2 * hyEdge_dimT, unsigned int>,
26  typename ConstructorVecT = SmallVec<space_dimT, unsigned int>,
27  typename hyEdge_index_t = unsigned int,
28  typename hyNode_index_t = hyEdge_index_t>
29 class Cubic
30 {
31  /*!***********************************************************************************************
32  * \brief Definition of the node types of a hypergraph's edges.
33  *
34  * \authors Guido Kanschat, Heidelberg University, 2019--2020.
35  * \authors Andreas Rupp, Heidelberg University, 2019--2020.
36  ************************************************************************************************/
37  class hyEdge
38  {
39  private:
40  /*!*********************************************************************************************
41  * \brief Types of the hypernodes adjacent to the hyperedge.
42  **********************************************************************************************/
43  NodeTypeVecT hyFace_types_;
44 
45  public:
46  /*!*********************************************************************************************
47  * \brief Construct a \c hyperEdge, i.e. determine its node indices.
48  *
49  * \param index The index of the hyperedge to be created.
50  * \param node_desc Cubic node descriptor.
51  **********************************************************************************************/
52  hyEdge(const hyEdge_index_t index, const Cubic& node_desc)
53  {
55  node_desc.tpcc_elements_, index / Wrapper::n_elements(node_desc.tpcc_ref_elem_));
56  for (unsigned int i = 0; i < hyFace_types_.size(); ++i)
57  {
58  Wrapper::tpcc_elem_t<hyEdge_dimT - 1, space_dimT> face = Wrapper::get_face(elem, i);
59  hyFace_types_[i] = 0;
60  for (unsigned int dim = 0; dim < space_dimT - hyEdge_dimT + 1; ++dim)
61  {
62  unsigned int coordinate = Wrapper::exterior_coordinate(face, dim);
63  unsigned int direction = Wrapper::exterior_direction(face, dim);
64  if (coordinate == 0 || coordinate == node_desc.n_elements().operator[](direction))
65  hyFace_types_[i] += (1 + (coordinate != 0)) * std::pow(3, direction);
66  }
67  }
68 
70  node_desc.tpcc_ref_elem_, index % Wrapper::n_elements(node_desc.tpcc_ref_elem_));
71  for (unsigned int i = 0; i < hyFace_types_.size(); ++i)
72  {
73  Wrapper::tpcc_elem_t<hyEdge_dimT - 1, hyEdge_dimT> face = Wrapper::get_face(ref_elem, i);
74  if (Wrapper::exterior_coordinate(face, 0) != 0 &&
75  Wrapper::exterior_coordinate(face, 0) != node_desc.n_subintervals_)
76  hyFace_types_[i] = 0;
77  }
78  }
79  /*!*********************************************************************************************
80  * \brief Return types of hypernodes adjacent to the hyperedge.
81  **********************************************************************************************/
82  const NodeTypeVecT& get_hyFace_types() const { return hyFace_types_; }
83  /*!*********************************************************************************************
84  * \brief Return types of hypernode of given index.
85  **********************************************************************************************/
86  unsigned int operator[](const unsigned int index) const { return hyFace_types_[index]; }
87  }; // end of class hyEdge
88 
89  public:
90  /*!***********************************************************************************************
91  * \brief Return the template parameter representing the dimension of a hyperedge.
92  *
93  * \retval hyEdge_dimT The dimension of a hyperedge.
94  ************************************************************************************************/
95  static constexpr unsigned int hyEdge_dim() { return hyEdge_dimT; };
96  /*!***********************************************************************************************
97  * \brief Return the template parameter representing the dimension of the space.
98  *
99  * \retval space_dimT The dimension of the space.
100  ************************************************************************************************/
101  static constexpr unsigned int space_dim() { return space_dimT; };
102 
103  private:
104  /*!***********************************************************************************************
105  * \brief Number of elements per spatial dimension.
106  ************************************************************************************************/
107  const ConstructorVecT n_elements_;
108  /*!***********************************************************************************************
109  * \brief Tensor product chain complex for elements.
110  ************************************************************************************************/
113  /*!***********************************************************************************************
114  * \brief Refinment level corresponds to number of subintervals per dimension.
115  ************************************************************************************************/
116  unsigned int n_subintervals_;
117  /*!***********************************************************************************************
118  * \brief Tensor product chain complex for refined elements of hypergedge.
119  ************************************************************************************************/
121  /*!***********************************************************************************************
122  * \brief Total amount of hyperedges in hypergraph.
123  ************************************************************************************************/
124  hyEdge_index_t n_hyEdges_;
125 
126  public:
127  /*!***********************************************************************************************
128  * \brief Defines the return value of the class to be a \c hyEdge.
129  ************************************************************************************************/
131  /*!***********************************************************************************************
132  * \brief Defines the value type of input argument for standard constructor.
133  ************************************************************************************************/
134  typedef ConstructorVecT constructor_value_type;
135  /*!***********************************************************************************************
136  * \brief Construct a node descriptor of a cubic hypergraph.
137  *
138  * \param n_elements A vector/array containing number of elements per spatial dimension.
139  ************************************************************************************************/
140  Cubic(const ConstructorVecT& n_elements)
143  Wrapper::create_tpcc<hyEdge_dimT, space_dimT, TPCC::boundaries::both, hyEdge_index_t>(
144  n_elements)),
145  n_subintervals_(1),
147  Wrapper::create_tpcc<hyEdge_dimT, hyEdge_dimT, TPCC::boundaries::both, hyEdge_index_t>(
148  SmallVec<hyEdge_dimT, unsigned int>(n_subintervals_))),
150  {
151  }
152  /*!***********************************************************************************************
153  * \brief Construct a cubic node descruiptor from a cubic topology.
154  *
155  * \param other Topology to which the node descriptor will fit.
156  ************************************************************************************************/
158  : n_elements_(other.n_elements()),
159  tpcc_elements_(other.tpcc_elem()),
161  tpcc_ref_elem_(other.tpcc_ref_elem()),
162  n_hyEdges_(other.n_hyEdges())
163  {
164  }
165  /*!***********************************************************************************************
166  * \brief Get topological hyperedge of given index.
167  *
168  * This function returns the hyperedge of the given index, i.e., it returns the hyperedge 's node
169  * description info.
170  *
171  * \param index The index of the hyperedge to be returned.
172  * \retval hyperedge Information on the hyperedge's nodes (cf. \c value_type).
173  ************************************************************************************************/
174  const value_type operator[](const hyEdge_index_t index) const
175  {
176  hy_assert(index >= 0 && index < n_hyEdges_,
177  "The index of an hyperedge must be non-negative and smaller than the total amount "
178  << "of hyperedges, which is " << n_hyEdges_ << ". Nonetheless, the " << index
179  << "-th hyperedge is tried to be accessed.");
180  return hyEdge(index, *this);
181  }
182  /*!***********************************************************************************************
183  * \brief Return the array / vector of elements per dimensions.
184  *
185  * \retval n_elements A vector / array containing the elements in the repective dimension.
186  ************************************************************************************************/
187  const ConstructorVecT& n_elements() const { return n_elements_; }
188  /*!***********************************************************************************************
189  * \brief Returns the number of hyperedges making up the hypergraph.
190  *
191  * \retval n_hyperedges The total amount of hyperedges of a hypergraph.
192  ************************************************************************************************/
193  const hyEdge_index_t n_hyEdges() const { return n_hyEdges_; }
194  /*!***********************************************************************************************
195  * \brief Return the refinement level (equal to number of subintervals).
196  ************************************************************************************************/
197  unsigned int get_refinement() const { return n_subintervals_; }
198  /*!***********************************************************************************************
199  * \brief Set the refinement level (equal to number of subintervals).
200  ************************************************************************************************/
201  void set_refinement(unsigned int level)
202  {
203  n_subintervals_ = level;
205  Wrapper::create_tpcc<hyEdge_dimT, hyEdge_dimT, TPCC::boundaries::both, hyEdge_index_t>(
208  }
209 
210 }; // end of class Cubic
211 
212 } // end of namespace NodeDescriptor
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
NodeDescriptor::Cubic::hyEdge_dim
static constexpr unsigned int hyEdge_dim()
Return the template parameter representing the dimension of a hyperedge.
Definition: cubic.hxx:95
NodeDescriptor::Cubic::hyEdge::get_hyFace_types
const NodeTypeVecT & get_hyFace_types() const
Return types of hypernodes adjacent to the hyperedge.
Definition: cubic.hxx:82
check_push_test.index
index
Definition: check_push_test.py:10
cubic.hxx
TPCC::both
@ both
Definition: lexicographic.h:11
NodeDescriptor::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:112
NodeDescriptor::Cubic::n_hyEdges
const hyEdge_index_t n_hyEdges() const
Returns the number of hyperedges making up the hypergraph.
Definition: cubic.hxx:193
TPCC::boundaries
boundaries
Definition: lexicographic.h:9
NodeDescriptor::Cubic::n_elements_
const ConstructorVecT n_elements_
Number of elements per spatial dimension.
Definition: cubic.hxx:101
NodeDescriptor::Cubic::hyEdge::operator[]
unsigned int operator[](const unsigned int index) const
Return types of hypernode of given index.
Definition: cubic.hxx:86
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
NodeDescriptor::Cubic::n_elements
const ConstructorVecT & n_elements() const
Return the array / vector of elements per dimensions.
Definition: cubic.hxx:187
Wrapper::get_element
auto get_element(const auto &tpcc, const auto index)
Return the element of given index the TPCC.
Definition: tpcc.hxx:92
NodeDescriptor::Cubic
Definition of the node types of a cubic hypergraph.
Definition: cubic.hxx:29
TPCC
Definition: combinations.h:8
NodeDescriptor::Cubic::get_refinement
unsigned int get_refinement() const
Return the refinement level (equal to number of subintervals).
Definition: cubic.hxx:197
NodeDescriptor::Cubic::n_hyEdges_
hyEdge_index_t n_hyEdges_
Total amount of hyperedges in hypergraph.
Definition: cubic.hxx:124
NodeDescriptor::Cubic::hyEdge
Definition of the node types of a hypergraph's edges.
Definition: cubic.hxx:37
Wrapper::n_elements
index_t n_elements(const auto &tpcc)
Return the element of given index the TPCC.
Definition: tpcc.hxx:80
NodeDescriptor::Cubic::constructor_value_type
ConstructorVecT constructor_value_type
Defines the value type of input argument for standard constructor.
Definition: cubic.hxx:134
NodeDescriptor::Cubic::Cubic
Cubic(const Topology::Cubic< hyEdge_dimT, space_dimT > &other)
Construct a cubic node descruiptor from a cubic topology.
Definition: cubic.hxx:157
TPCC::Lexicographic
Lexicographic enumeration of the k-dimensional faces in a tensor product chain complex of dimension n...
Definition: lexicographic.h:44
Topology::Cubic
Definition of the topology of a hypergraph — Cubic HyperGraphs.
Definition: cubic.hxx:40
NodeDescriptor::Cubic::space_dim
static constexpr unsigned int space_dim()
Return the template parameter representing the dimension of the space.
Definition: cubic.hxx:101
NodeDescriptor::Cubic::Cubic
Cubic(const ConstructorVecT &n_elements)
Construct a node descriptor of a cubic hypergraph.
Definition: cubic.hxx:140
NodeDescriptor::Cubic::n_subintervals_
unsigned int n_subintervals_
Refinment level corresponds to number of subintervals per dimension.
Definition: cubic.hxx:116
NodeDescriptor::Cubic::value_type
hyEdge value_type
Defines the return value of the class to be a hyEdge.
Definition: cubic.hxx:130
hy_assert
#define hy_assert(Expr, Msg)
The assertion to be used within HyperHDG — deactivate using -DNDEBUG compile flag.
Definition: hy_assert.hxx:38
NodeDescriptor
A namespace containing different classes describing the types of hypernodes.
Definition: cubic.hxx:7
NodeDescriptor::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 refined elements of hypergedge.
Definition: cubic.hxx:120
NodeDescriptor::Cubic::operator[]
const value_type operator[](const hyEdge_index_t index) const
Get topological hyperedge of given index.
Definition: cubic.hxx:174
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
NodeDescriptor::Cubic::hyEdge::hyEdge
hyEdge(const hyEdge_index_t index, const Cubic &node_desc)
Construct a hyperEdge, i.e. determine its node indices.
Definition: cubic.hxx:52
NodeDescriptor::Cubic::hyEdge::hyFace_types_
NodeTypeVecT hyFace_types_
Types of the hypernodes adjacent to the hyperedge.
Definition: cubic.hxx:43
NodeDescriptor::Cubic::set_refinement
void set_refinement(unsigned int level)
Set the refinement level (equal to number of subintervals).
Definition: cubic.hxx:201
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