Flow123d  release_3.0.0-955-g4db4b48
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>
25 class ElementAccessor;
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  /// Returns global indices of the nodes.
59  Point vertex(unsigned int loc_idx) const; ///< Returns coordinates of node @p loc_idx.
60  std::vector<Point> vertex_list() const; ///< Returns vector of nodes coordinates.
61 
62  Point centre() const; ///< Computes the barycenter.
63  //@}
64 
65  /// @name Original Mesh Getters.
66  //@{
67  /// Returns pointer to the computational mesh.
68  Mesh* orig_mesh() const;
69  /// Returns index of the master element in the computational mesh.
70  unsigned int orig_element_idx() const;
71  ///Gets ElementAccessor of this element
73  //@}
74 
75  void inc();
76 
77  bool operator==(const OutputElement& other);
78 private:
79 
80  /// index of the output element
81  unsigned int ele_idx_;
82  /// pointer to the output mesh
83  std::shared_ptr<OutputMeshBase> output_mesh_;
84 };
85 
86 // --------------------------------------------------- OutputElement INLINE implementation -------------------
87 
88 inline OutputElement::OutputElement(unsigned int ele_idx, std::shared_ptr<OutputMeshBase> output_mesh)
89 : ele_idx_(ele_idx), output_mesh_(output_mesh)
90 {}
91 
92 inline void OutputElement::inc()
93 {
94  ele_idx_++;
95 }
96 
97 inline bool OutputElement::operator==(const OutputElement& other)
98 {
99  return ele_idx_ == other.ele_idx_;
100 }
101 
102 
104 {
105  return output_mesh_->orig_mesh_;
106 }
107 
108 inline unsigned int OutputElement::orig_element_idx() const
109 {
110  return (*output_mesh_->orig_element_indices_)[ele_idx_];
111 }
112 
114 {
115  return output_mesh_->orig_mesh_->element_accessor(orig_element_idx());
116 }
117 
118 
119 inline unsigned int OutputElement::idx() const
120 {
121  return ele_idx_;
122 }
123 
124 inline unsigned int OutputElement::n_nodes() const
125 {
126  if(ele_idx_ == 0)
127  return (*output_mesh_->offsets_)[0];
128  else
129  return (*output_mesh_->offsets_)[ele_idx_] - (*output_mesh_->offsets_)[ele_idx_-1];
130 }
131 
132 inline unsigned int OutputElement::dim() const
133 {
134  return n_nodes()-1;
135 }
136 
137 
138 inline unsigned int OutputElement::node_index(unsigned int loc_idx) const
139 {
140  unsigned int n = n_nodes();
141  ASSERT_DBG(loc_idx < n);
142  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_];
143  return (* output_mesh_->connectivity_)[con_off - n + loc_idx];
144 }
145 
146 
147 inline OutputElement::Point OutputElement::vertex(unsigned int loc_idx) const
148 {
149  unsigned int n = n_nodes();
150  ASSERT_DBG(loc_idx < n);
151  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_];
152  unsigned int off = spacedim * (* output_mesh_->connectivity_)[con_off - n + loc_idx];
153  auto &d = *( output_mesh_->nodes_->get_component_data(0).get() );
154  Point point({d[off], d[off+1], d[off+2]});
155  return point;
156 }
157 
158 
160 {
161  const unsigned int n = n_nodes();
162  std::vector<Point> vertices(n);
163 
164  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_];
165  auto &d = *( output_mesh_->nodes_->get_component_data(0).get() );
166  for(unsigned int i=0; i<n; i++) {
167  unsigned int off = spacedim * (* output_mesh_->connectivity_)[con_off - n + i];
168  vertices[i] = {d[off], d[off+1], d[off+2]};
169  off += spacedim;
170  }
171  return vertices;
172 }
173 
174 
176 {
177  unsigned int n = n_nodes();
178  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_];
179  std::vector<unsigned int> indices(n);
180  for(unsigned int i=0; i<n; i++) {
181  indices[i] = (* output_mesh_->connectivity_)[con_off - n + i];
182  }
183  return indices;
184 }
185 
186 
188 {
189  Point res({0,0,0});
190  for(auto& v : vertex_list() ) res += v;
191  return res/n_nodes();
192 }
193 
194 #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:80
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:42
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)
std::vector< unsigned int > node_list() const
Returns global indices of the nodes.
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.