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