Flow123d  release_2.1.2-337-g6b7a56b
output_element.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file output_element.hh
15  * @brief Class OutputElement and its iterator OutputElementIterator on the output mesh.
16  */
17 
18 #ifndef OUTPUT_ELEMENT_HH_
19 #define OUTPUT_ELEMENT_HH_
20 
21 #include "element_data_cache.hh"
22 #include "output_mesh.hh"
23 
24 template <int spacedim>
26 
27 
28 #include "mesh/accessors.hh"
29 #include "mesh/mesh.h"
30 #include "mesh/point.hh"
31 #include "output_mesh.hh"
32 
33 /** @brief Represents an element of the output mesh.
34  * Provides element access on the data of the output mesh (nodes, connectivity, offsets etc.).
35  *
36  * Vertex function suppose spacedim = 3 at the moment, hard coded.
37  */
39 {
40 public:
41  /// Element space dimension = 3.
42  static const unsigned int spacedim = 3;
43 
45 
46  /// Constructor.
47  OutputElement(unsigned int ele_idx, std::shared_ptr<OutputMeshBase> output_mesh);
48 
49  /// @name Output Mesh Getters.
50  //@{
51  unsigned int idx() const; ///< Returns index of the output element.
52  unsigned int n_nodes() const; ///< Returns number of nodes.
53  unsigned int dim() const; ///< Returns dim of the output element.
54 
55  /// Returns global index of the node.
56  unsigned int node_index(unsigned int loc_idx) const;
57  Point vertex(unsigned int loc_idx) const; ///< Returns coordinates of node @p loc_idx.
58  std::vector<Point> vertex_list() const; ///< Returns vector of nodes coordinates.
59 
60  Point centre() const; ///< Computes the barycenter.
61  //@}
62 
63  /// @name Original Mesh Getters.
64  //@{
65  /// Returns pointer to the computational mesh.
66  Mesh* orig_mesh() const;
67  /// Returns index of the master element in the computational mesh.
68  unsigned int orig_element_idx() const;
69  ///Gets ElementAccessor of this element
71  //@}
72 
73  void inc();
74  bool operator==(const OutputElement& other);
75 private:
76 
77  /// index of the output element
78  unsigned int ele_idx_;
79  /// pointer to the output mesh
80  std::shared_ptr<OutputMeshBase> output_mesh_;
81 };
82 
83 // --------------------------------------------------- OutputElement INLINE implementation -------------------
84 
85 inline OutputElement::OutputElement(unsigned int ele_idx, std::shared_ptr<OutputMeshBase> output_mesh)
86 : ele_idx_(ele_idx), output_mesh_(output_mesh)
87 {}
88 
89 inline void OutputElement::inc()
90 {
91  ele_idx_++;
92 }
93 
94 inline bool OutputElement::operator==(const OutputElement& other)
95 {
96  return ele_idx_ == other.ele_idx_;
97 }
98 
99 
101 {
102  return output_mesh_->orig_mesh_;
103 }
104 
105 inline unsigned int OutputElement::orig_element_idx() const
106 {
107  return (*output_mesh_->orig_element_indices_)[ele_idx_];
108 }
109 
111 {
112  return output_mesh_->orig_mesh_->element_accessor(orig_element_idx());
113 }
114 
115 
116 inline unsigned int OutputElement::idx() const
117 {
118  return ele_idx_;
119 }
120 
121 inline unsigned int OutputElement::n_nodes() const
122 {
123  if(ele_idx_ == 0)
124  return (*output_mesh_->offsets_)[0];
125  else
126  return (*output_mesh_->offsets_)[ele_idx_] - (*output_mesh_->offsets_)[ele_idx_-1];
127 }
128 
129 inline unsigned int OutputElement::dim() const
130 {
131  return n_nodes()-1;
132 }
133 
134 
135 inline unsigned int OutputElement::node_index(unsigned int loc_idx) const
136 {
137  unsigned int n = n_nodes();
138  ASSERT_DBG(loc_idx < n);
139  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_];
140  return (* output_mesh_->connectivity_)[con_off - n + loc_idx];
141 }
142 
143 
144 inline OutputElement::Point OutputElement::vertex(unsigned int loc_idx) const
145 {
146  unsigned int n = n_nodes();
147  ASSERT_DBG(loc_idx < n);
148  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_];
149  unsigned int off = spacedim * (* output_mesh_->connectivity_)[con_off - n + loc_idx];
150  auto &d = *( output_mesh_->nodes_->get_component_data(0).get() );
151  Point point({d[off], d[off+1], d[off+2]});
152  return point;
153 }
154 
155 
157 {
158  const unsigned int n = n_nodes();
159  std::vector<Point> vertices(n);
160 
161  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_];
162  auto &d = *( output_mesh_->nodes_->get_component_data(0).get() );
163  for(unsigned int i=0; i<n; i++) {
164  unsigned int off = spacedim * (* output_mesh_->connectivity_)[con_off - n + i];
165  vertices[i] = {d[off], d[off+1], d[off+2]};
166  off += spacedim;
167  }
168  return vertices;
169 }
170 
171 
173 {
174  Point res({0,0,0});
175  for(auto& v : vertex_list() ) res += v;
176  return res/n_nodes();
177 }
178 
179 #endif // OUTPUT_ELEMENT_HH_
OutputElement(unsigned int ele_idx, std::shared_ptr< OutputMeshBase > output_mesh)
Constructor.
Classes for auxiliary output mesh.
Point vertex(unsigned int loc_idx) const
Returns coordinates of node loc_idx.
unsigned int n_nodes() const
Returns number of nodes.
Represents an element of the output mesh. Provides element access on the data of the output mesh (nod...
std::vector< Point > vertex_list() const
Returns vector of nodes coordinates.
ElementAccessor< spacedim > element_accessor() const
Gets ElementAccessor of this element.
unsigned int idx() const
Returns index of the output element.
unsigned int orig_element_idx() const
Returns index of the master element in the computational mesh.
Definition: mesh.h:97
unsigned int ele_idx_
index of the output element
Point centre() const
Computes the barycenter.
Space< spacedim >::Point Point
std::shared_ptr< OutputMeshBase > output_mesh_
pointer to the output mesh
arma::vec::fixed< spacedim > Point
Definition: point.hh:33
unsigned int dim() const
Returns dim of the output element.
unsigned int node_index(unsigned int loc_idx) const
Returns global index of the node.
bool operator==(const OutputElement &other)
static const unsigned int spacedim
Element space dimension = 3.
#define ASSERT_DBG(expr)
Definition: asserts.hh:349
Mesh * orig_mesh() const
Returns pointer to the computational mesh.