Flow123d  3.9.0-3aaaea010
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  return (*output_mesh_->offsets_)[ele_idx_+1] - (*output_mesh_->offsets_)[ele_idx_];
132 }
133 
134 inline unsigned int OutputElement::dim() const
135 {
136  return n_nodes()-1;
137 }
138 
139 
140 inline unsigned int OutputElement::node_index(unsigned int loc_idx) const
141 {
142  unsigned int n = n_nodes();
143  ASSERT(loc_idx < n);
144  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_+1];
145  return (* output_mesh_->connectivity_)[con_off - n + loc_idx];
146 }
147 
148 
149 inline OutputElement::Point OutputElement::vertex(unsigned int loc_idx) const
150 {
151  unsigned int n = n_nodes();
152  ASSERT(loc_idx < n);
153  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_+1];
154  unsigned int off = spacedim * (* output_mesh_->connectivity_)[con_off - n + loc_idx];
155  auto &d = *( output_mesh_->nodes_->get_data().get() );
156  Point point({d[off], d[off+1], d[off+2]});
157  return point;
158 }
159 
160 
162 {
163  const unsigned int n = n_nodes();
164  std::vector<Point> vertices(n);
165 
166  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_+1];
167  auto &d = *( output_mesh_->nodes_->get_data().get() );
168  for(unsigned int i=0; i<n; i++) {
169  unsigned int off = spacedim * (* output_mesh_->connectivity_)[con_off - n + i];
170  vertices[i] = {d[off], d[off+1], d[off+2]};
171  off += spacedim;
172  }
173  return vertices;
174 }
175 
176 
178 {
179  unsigned int n = n_nodes();
180  unsigned int con_off = (*output_mesh_->offsets_)[ele_idx_+1];
181  std::vector<unsigned int> indices(n);
182  for(unsigned int i=0; i<n; i++) {
183  indices[i] = (* output_mesh_->connectivity_)[con_off - n + i];
184  }
185  return indices;
186 }
187 
188 
190 {
191  Point res({0,0,0});
192  for(auto& v : vertex_list() ) res += v;
193  return res/n_nodes();
194 }
195 
196 #endif // OUTPUT_ELEMENT_HH_
Space::Point
Armor::ArmaVec< double, spacedim > Point
Definition: point.hh:42
element_data_cache.hh
ASSERT
#define ASSERT(expr)
Definition: asserts.hh:351
OutputElement::n_nodes
unsigned int n_nodes() const
Returns number of nodes.
Definition: output_element.hh:129
point.hh
OutputElement::idx
unsigned int idx() const
Returns index of the output element.
Definition: output_element.hh:124
OutputElement
Represents an element of the output mesh. Provides element access on the data of the output mesh (nod...
Definition: output_element.hh:38
std::vector< unsigned int >
ElementAccessor
Definition: dh_cell_accessor.hh:32
OutputElement::ele_idx_
unsigned int ele_idx_
index of the output element
Definition: output_element.hh:84
OutputElement::node_index
unsigned int node_index(unsigned int loc_idx) const
Returns global index of the node.
Definition: output_element.hh:140
accessors.hh
OutputElement::inc
void inc()
Definition: output_element.hh:97
OutputElement::vertex_list
std::vector< Point > vertex_list() const
Returns vector of nodes coordinates.
Definition: output_element.hh:161
OutputElement::OutputElement
OutputElement()
Default constructor.
Definition: output_element.hh:91
OutputElement::orig_element_idx
unsigned int orig_element_idx() const
Returns index of the master element in the computational mesh.
Definition: output_element.hh:113
OutputElement::element_accessor
ElementAccessor< spacedim > element_accessor() const
Gets ElementAccessor of this element.
Definition: output_element.hh:118
mesh.h
OutputElement::operator==
bool operator==(const OutputElement &other)
Definition: output_element.hh:102
OutputElement::Point
Space< spacedim >::Point Point
Definition: output_element.hh:44
OutputElement::dim
unsigned int dim() const
Returns dim of the output element.
Definition: output_element.hh:134
OutputElement::spacedim
static const unsigned int spacedim
Element space dimension = 3.
Definition: output_element.hh:42
Mesh
Definition: mesh.h:361
output_mesh.hh
Classes for auxiliary output mesh.
OutputElement::centre
Point centre() const
Computes the barycenter.
Definition: output_element.hh:189
OutputElement::orig_mesh
Mesh * orig_mesh() const
Returns pointer to the computational mesh.
Definition: output_element.hh:108
OutputElement::vertex
Point vertex(unsigned int loc_idx) const
Returns coordinates of node loc_idx.
Definition: output_element.hh:149
OutputElement::output_mesh_
std::shared_ptr< OutputMeshBase > output_mesh_
pointer to the output mesh
Definition: output_element.hh:86
OutputElement::node_list
std::vector< unsigned int > node_list() const
Returns global indices of the nodes.
Definition: output_element.hh:177