HyperHDG
file.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>
7 
8 #include <string>
9 
10 namespace Topology
11 {
12 /*!*************************************************************************************************
13  * \brief Hypergraph topology based on an input file.
14  *
15  * The topology class File is a set of hyperedges. Each of these tensorial hyperedges is represented
16  * by its hypernodes (given within the file). For consistency, it is assumed that the vertices and
17  * the hypernodes are assumed to be given in lexicographical order to ensure that geometry and
18  * topology of all hyperedges fit.
19  *
20  * \tparam hyEdge_dimT Dimension of a hyperedge, i.e., 1 is for PDEs defined on graphs, 2 is
21  * for PDEs defined on surfaces, and 3 is for PDEs defined on volumes.
22  * \tparam space_dimT The dimension of the space, the object is located in. This number should
23  * be larger than or equal to hyEdge_dimT.
24  * \tparam vectorT The typename of the large vector type. Defaults to std::vector.
25  * \tparam pointT The typename of a Point class. Defaults to \c Point<space_dimT, float>.
26  * \tparam hyEdge_index_t The index type for hyperedges. Default is \c unsigned \c int.
27  * \tparam hyNode_index_t The index type for hypernodes. Default is \c hyNode_index_t.
28  * \tparam pt_index_t The index type of points. Default is \c hyNode_index_t.
29  * \tparam NodeOrientationT The class type that encodes the orientation of the hypernodes with
30  * respect to a given hyperedge.
31  *
32  * \authors Guido Kanschat, Heidelberg University, 2019--2020.
33  * \authors Andreas Rupp, Heidelberg University, 2019--2020.
34  **************************************************************************************************/
35 template <unsigned int hyEdge_dimT,
36  unsigned int space_dimT,
37  template <typename...> typename vectorT = std::vector,
38  typename pointT = Point<space_dimT, float>,
39  typename hyEdge_index_t = unsigned int,
40  typename hyNode_index_t = hyEdge_index_t,
41  typename pt_index_t = hyNode_index_t,
42  typename NodeOrientationT = SmallVec<2 * hyEdge_dimT - 2, unsigned int> >
43 class File
44 {
45  /*!***********************************************************************************************
46  * \brief Definition of the topology of a hypergraph's edges.
47  ************************************************************************************************/
48  class hyEdge
49  {
50  public:
51  /*!*********************************************************************************************
52  * \brief Number of hypernodes per hyperedge.
53  **********************************************************************************************/
54  static constexpr unsigned int n_hyNodes() { return 2 * hyEdge_dimT; }
55 
56  private:
57  /*!*********************************************************************************************
58  * \brief Reference to parent hypergraph.
59  **********************************************************************************************/
61  /*!*********************************************************************************************
62  * \brief Index of the hyperedge within the hypergraph
63  **********************************************************************************************/
64  const hyEdge_index_t index_;
65 
66  /*!*********************************************************************************************
67  * \brief Indices of the hypernodes adjacent to the hyperedge.
68  **********************************************************************************************/
69  std::array<hyNode_index_t, 2 * hyEdge_dimT> hyNode_indices_;
70 
71  public:
72  /*!*********************************************************************************************
73  * \brief Construct hyperedge from hypergraph and index.
74  **********************************************************************************************/
75  hyEdge(const File& topology, const hyEdge_index_t index)
77  {
79  hyGraph_topology_.domain_info_.hyNodes_hyEdge[index / topology.n_elem_per_elem];
80 
82  Wrapper::get_element(topology.tpcc_ref_elem_, index % topology.n_elem_per_elem);
83  for (unsigned int i = 0; i < hyNode_indices_.size(); ++i)
84  {
85  Wrapper::tpcc_elem_t<hyEdge_dimT - 1, hyEdge_dimT> face = Wrapper::get_face(ref_elem, i);
86  if (Wrapper::exterior_coordinate(face, 0) == 0 ||
87  Wrapper::exterior_coordinate(face, 0) == topology.n_subintervals_)
88  hyNode_indices_[i] = topology.n_face_per_face * hyNode_indices_[i] +
89  Wrapper::get_index_in_slice(topology.tpcc_ref_faces_, face);
90  else
91  hyNode_indices_[i] = topology.n_coarse_face * topology.n_face_per_face +
92  topology.n_face_per_elem * (index / topology.n_elem_per_elem) +
93  Wrapper::get_index(topology.tpcc_ref_faces_, face);
94  }
95  }
96  /*!*********************************************************************************************
97  * \brief Return hypernodes of a hyperedge.
98  **********************************************************************************************/
99  const auto& get_hyNode_indices() const { return hyNode_indices_; }
100  /*!*********************************************************************************************
101  * \brief Return orienation of hypernode.
102  **********************************************************************************************/
103  const NodeOrientationT get_hyNode_oriantation(unsigned int) const { return NodeOrientationT(); }
104  }; // end of class hyEdge
105 
106  public:
107  /*!***********************************************************************************************
108  * \brief Return local dimension of the hypergraph's hyperedges.
109  ************************************************************************************************/
110  static constexpr unsigned int hyEdge_dim() { return hyEdge_dimT; }
111  /*!***********************************************************************************************
112  * \brief Return dimension of the surrounding space.
113  ************************************************************************************************/
114  static constexpr unsigned int space_dim() { return space_dimT; }
115 
116  private:
117  /*!***********************************************************************************************
118  * \brief Domain Info containing all the information of the hypergraph (cf. ReadDomain.hxx).
119  ************************************************************************************************/
120  const DomainInfo<hyEdge_dimT,
121  space_dimT,
122  vectorT,
123  pointT,
124  hyEdge_index_t,
125  hyNode_index_t,
126  pt_index_t>
128 
129  /*!***********************************************************************************************
130  * \brief Refinment level corresponds to number of subintervals per dimension.
131  ************************************************************************************************/
132  unsigned int n_subintervals_;
133  /*!***********************************************************************************************
134  * \brief Tensor product chain complex for refining a hyperedge into elements.
135  ************************************************************************************************/
137  /*!***********************************************************************************************
138  * \brief Tensor product chain complex for refining a hyperedge into faces.
139  ************************************************************************************************/
140  Wrapper::tpcc_t<hyEdge_dimT - 1, hyEdge_dimT, TPCC::boundaries::none, hyNode_index_t>
142  /*!***********************************************************************************************
143  * \brief Number of refined elements per corase element.
144  ************************************************************************************************/
145  unsigned int n_elem_per_elem;
146  /*!***********************************************************************************************
147  * \brief Number of refined faces per corase face.
148  ************************************************************************************************/
149  unsigned int n_face_per_face;
150  /*!***********************************************************************************************
151  * \brief Number of refined faces per corase element.
152  ************************************************************************************************/
153  unsigned int n_face_per_elem;
154  /*!***********************************************************************************************
155  * \brief Number of refined corase elements.
156  ************************************************************************************************/
157  unsigned int n_coarse_elem;
158  /*!***********************************************************************************************
159  * \brief Number of refined corase faces.
160  ************************************************************************************************/
161  unsigned int n_coarse_face;
162 
163  /*!***********************************************************************************************
164  * \brief Total amount of hyperedges.
165  ************************************************************************************************/
166  hyEdge_index_t n_hyEdges_;
167  /*!***********************************************************************************************
168  * \brief Total amount of hypernodes.
169  ************************************************************************************************/
170  hyNode_index_t n_hyNodes_;
171 
172  public:
173  /*!***********************************************************************************************
174  * \brief Defines the return value of the class.
175  ************************************************************************************************/
177  /*!***********************************************************************************************
178  * \brief Defines the value type of input argument for standard constructor.
179  ************************************************************************************************/
180  typedef std::string constructor_value_type;
181  /*!***********************************************************************************************
182  * \brief Construct a topology from a given filename.
183  *
184  * \param filename Name of file containing the information.
185  ************************************************************************************************/
186  File(const constructor_value_type& filename)
187  : domain_info_(read_domain<hyEdge_dimT,
188  space_dimT,
189  vectorT,
190  pointT,
191  hyEdge_index_t,
192  hyNode_index_t,
193  pt_index_t>(filename)),
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 Copy constructor.
210  ************************************************************************************************/
212  : domain_info_(other.domain_info()),
221  n_hyEdges_(other.n_hyEdges_),
222  n_hyNodes_(other.n_hyNodes_)
223  {
224  }
225 
226  /*!***********************************************************************************************
227  * \brief Get topological hyperedge of given index.
228  *
229  * This is equivalent to \c get_hyEdge.
230  *
231  * \param index The index of the hyperedge to be returned.
232  * \retval hyperedge Topological information on the hyperedge (cf. \c value_type).
233  ************************************************************************************************/
234  const value_type operator[](const hyEdge_index_t index) const { return get_hyEdge(index); }
235  /*!***********************************************************************************************
236  * \brief Get topological hyperedge of given index.
237  *
238  * This is equivalent to \c operator[].
239  *
240  * \param index The index of the hyperedge to be returned.
241  * \retval hyperedge Topological information on the hyperedge (cf. \c value_type).
242  ************************************************************************************************/
243  const value_type get_hyEdge(const hyEdge_index_t index) const
244  {
245  hy_assert(index < n_hyEdges_ && index >= 0, "Index must be non-negative and smaller than "
246  << domain_info_.n_hyEdges
247  << " (which is the amount of hyperedges). It was "
248  << index << "!");
249  return hyEdge(*this, index);
250  }
251  /*!***********************************************************************************************
252  * \brief Return the number of hyperedges making up the hypergraph.
253  *
254  * \retval n_hyperedges The total amount of hyperedges of a hypergraph.
255  ************************************************************************************************/
256  const hyEdge_index_t n_hyEdges() const { return n_hyEdges_; }
257  /*!***********************************************************************************************
258  * \brief Return the number of hypernodes making up the hypergraph.
259  *
260  * \retval n_hypernodes The total amount of hypernodes of a hypergraph.
261  ************************************************************************************************/
262  const hyNode_index_t n_hyNodes() const { return n_hyNodes_; }
263  /*!***********************************************************************************************
264  * \brief Return the whole domain info related to a hypergraph.
265  *
266  * \retval domain_info Const reference to domain info.
267  ************************************************************************************************/
268  const DomainInfo<hyEdge_dimT,
269  space_dimT,
270  vectorT,
271  pointT,
272  hyEdge_index_t,
273  hyNode_index_t,
274  pt_index_t>&
275  domain_info() const
276  {
277  return domain_info_;
278  }
279  /*!***********************************************************************************************
280  * \brief Tensor product chain complex of 'local' / refined elements.
281  ************************************************************************************************/
284  {
285  return tpcc_ref_elem_;
286  }
287  /*!***********************************************************************************************
288  * \brief Return the refinement level (equal to number of subintervals).
289  ************************************************************************************************/
290  unsigned int get_refinement() const { return n_subintervals_; }
291  /*!***********************************************************************************************
292  * \brief Set the refinement level (equal to number of subintervals).
293  ************************************************************************************************/
294  void set_refinement(unsigned int level)
295  {
296  n_subintervals_ = level;
298  Wrapper::create_tpcc<hyEdge_dimT, hyEdge_dimT, TPCC::boundaries::both, hyEdge_index_t>(
300  tpcc_ref_faces_ = Wrapper::tpcc_faces<TPCC::boundaries::none>(tpcc_ref_elem_);
306  }
307 }; // end of class File
308 
309 } // end of namespace Topology
TPCC::Element
Tensor coordinates for a facet of dimension k in the complex of dimension n.
Definition: element.h:38
Topology::File::operator[]
const value_type operator[](const hyEdge_index_t index) const
Get topological hyperedge of given index.
Definition: file.hxx:234
hy_assert.hxx
This file provides the function hy_assert.
Topology::File::domain_info
const DomainInfo< hyEdge_dimT, space_dimT, vectorT, pointT, hyEdge_index_t, hyNode_index_t, pt_index_t > & domain_info() const
Return the whole domain info related to a hypergraph.
Definition: file.hxx:275
Topology::File::hyEdge::hyNode_indices_
std::array< hyNode_index_t, 2 *hyEdge_dimT > hyNode_indices_
Indices of the hypernodes adjacent to the hyperedge.
Definition: file.hxx:69
Topology::File::n_coarse_face
unsigned int n_coarse_face
Number of refined corase faces.
Definition: file.hxx:161
Topology::File::hyEdge_dim
static constexpr unsigned int hyEdge_dim()
Return local dimension of the hypergraph's hyperedges.
Definition: file.hxx:110
Wrapper
A namespace containing the different wrapper functions.
Definition: lapack.hxx:20
Topology::File::get_hyEdge
const value_type get_hyEdge(const hyEdge_index_t index) const
Get topological hyperedge of given index.
Definition: file.hxx:243
Topology::File::n_hyNodes_
hyNode_index_t n_hyNodes_
Total amount of hypernodes.
Definition: file.hxx:170
check_push_test.index
index
Definition: check_push_test.py:10
Topology::File::n_subintervals_
unsigned int n_subintervals_
Refinment level corresponds to number of subintervals per dimension.
Definition: file.hxx:132
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::File::domain_info_
const DomainInfo< hyEdge_dimT, space_dimT, vectorT, pointT, hyEdge_index_t, hyNode_index_t, pt_index_t > domain_info_
Domain Info containing all the information of the hypergraph (cf. ReadDomain.hxx).
Definition: file.hxx:127
Topology::File::hyEdge::get_hyNode_oriantation
const NodeOrientationT get_hyNode_oriantation(unsigned int) const
Return orienation of hypernode.
Definition: file.hxx:103
Topology::File
Hypergraph topology based on an input file.
Definition: file.hxx:43
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
Topology::File::n_face_per_face
unsigned int n_face_per_face
Number of refined faces per corase face.
Definition: file.hxx:149
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
Topology::File::get_refinement
unsigned int get_refinement() const
Return the refinement level (equal to number of subintervals).
Definition: file.hxx:290
Topology::File::set_refinement
void set_refinement(unsigned int level)
Set the refinement level (equal to number of subintervals).
Definition: file.hxx:294
Topology::File::hyEdge
Definition of the topology of a hypergraph's edges.
Definition: file.hxx:48
Wrapper::tpcc_faces
auto tpcc_faces(const auto &elements)
Create a tensor product chain complex associated to the facets.
Definition: tpcc.hxx:72
Topology::File::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: file.hxx:141
TPCC::none
@ none
Definition: lexicographic.h:12
Topology::File::File
File(const File< hyEdge_dimT, space_dimT > &other)
Copy constructor.
Definition: file.hxx:211
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::File::hyEdge::hyGraph_topology_
const File & hyGraph_topology_
Reference to parent hypergraph.
Definition: file.hxx:60
read_domain.hxx
TPCC
Definition: combinations.h:8
Wrapper::n_elements
index_t n_elements(const auto &tpcc)
Return the element of given index the TPCC.
Definition: tpcc.hxx:80
Topology::File::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: file.hxx:283
Topology::File::File
File(const constructor_value_type &filename)
Construct a topology from a given filename.
Definition: file.hxx:186
Topology::File::hyEdge::hyEdge
hyEdge(const File &topology, const hyEdge_index_t index)
Construct hyperedge from hypergraph and index.
Definition: file.hxx:75
TPCC::Lexicographic
Lexicographic enumeration of the k-dimensional faces in a tensor product chain complex of dimension n...
Definition: lexicographic.h:44
Topology::File::n_hyEdges
const hyEdge_index_t n_hyEdges() const
Return the number of hyperedges making up the hypergraph.
Definition: file.hxx:256
read_domain
DomainInfo< hyEdge_dim, space_dim, vectorT, pointT, hyEdge_index_t, hyNode_index_t, pt_index_t > read_domain(std::string filename)
General Function to read domain from input file.
Definition: read_domain.hxx:362
hypercube.hxx
Topology::File::hyEdge::get_hyNode_indices
const auto & get_hyNode_indices() const
Return hypernodes of a hyperedge.
Definition: file.hxx:99
Topology::File::n_elem_per_elem
unsigned int n_elem_per_elem
Number of refined elements per corase element.
Definition: file.hxx:145
Topology::File::value_type
hyEdge value_type
Defines the return value of the class.
Definition: file.hxx:176
Hypercube::pow
static constexpr unsigned int pow(unsigned int base)
Return n to the power dim.
Definition: hypercube.hxx:25
Topology::File::space_dim
static constexpr unsigned int space_dim()
Return dimension of the surrounding space.
Definition: file.hxx:114
Topology::File::n_hyNodes
const hyNode_index_t n_hyNodes() const
Return the number of hypernodes making up the hypergraph.
Definition: file.hxx:262
Topology::File::n_face_per_elem
unsigned int n_face_per_elem
Number of refined faces per corase element.
Definition: file.hxx:153
Topology::File::n_hyEdges_
hyEdge_index_t n_hyEdges_
Total amount of hyperedges.
Definition: file.hxx:166
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::File::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: file.hxx:136
diffusion_uniform.topology
topology
Definition: diffusion_uniform.py:18
Topology::File::constructor_value_type
std::string constructor_value_type
Defines the value type of input argument for standard constructor.
Definition: file.hxx:180
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::File::hyEdge::index_
const hyEdge_index_t index_
Index of the hyperedge within the hypergraph.
Definition: file.hxx:64
Topology::File::n_coarse_elem
unsigned int n_coarse_elem
Number of refined corase elements.
Definition: file.hxx:157
DomainInfo
Hold all topological and geometrical information of a hypergraph.
Definition: read_domain.hxx:59
Topology::File::hyEdge::n_hyNodes
static constexpr unsigned int n_hyNodes()
Number of hypernodes per hyperedge.
Definition: file.hxx:54
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