Flow123d  JS_before_hm-1874-gec44d9749
accessors_impl.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 accessors_impl.hh
15  * @brief Implementation of the inline functions of the mesh accessors.
16  */
17 
18 /*******************************************************************************
19  * ElementAccessor IMPLEMENTATION
20  *******************************************************************************/
21 /**
22  * Default invalid accessor.
23  */
24 template <int spacedim> inline
26 : mesh_(nullptr)
27 {}
28 
29 /**
30  * Regional accessor.
31  */
32 template <int spacedim> inline
34 : mesh_(mesh),
35  element_idx_(undef_idx),
36  r_idx_(r_idx)
37 {}
38 
39 /**
40  * Element accessor.
41  */
42 template <int spacedim> inline
43 ElementAccessor<spacedim>::ElementAccessor(const Mesh *mesh, unsigned int idx)
44 : mesh_(mesh),
45  element_idx_(idx)
46 {}
47 
48 template <int spacedim> inline
50  ASSERT(!is_regional()).error("Do not call inc() for regional accessor!");
51  element_idx_++;
52 }
53 
54 template <int spacedim> inline
55 vector<arma::vec3> ElementAccessor<spacedim>::vertex_list() const {
56  vector<arma::vec3> vertices(element()->n_nodes());
57  for(unsigned int i=0; i<element()->n_nodes(); i++) vertices[i]=*node(i);
58  return vertices;
59 }
60 
61 
62 /**
63  * SET THE "METRICS" FIELD IN STRUCT ELEMENT
64  */
65 
66 template <int spacedim> inline
68  switch (dim()) {
69  case 0:
70  return 1.0;
71  break;
72  case 1:
73  return jacobian_S1();
74  break;
75  case 2:
76  return jacobian_S2() / 2.0;
77  break;
78  case 3:
79  return fabs( jacobian_S3() ) / 6.0;
80  break;
81  }
82  return 1.0;
83 }
84 
85 /**
86  * SET THE "CENTRE[]" FIELD IN STRUCT ELEMENT
87  */
88 template <int spacedim> inline
89 arma::vec::fixed<spacedim> ElementAccessor<spacedim>::centre() const {
90  ASSERT(is_valid()).error("Invalid element accessor.");
91  if (is_regional() ) return arma::vec::fixed<spacedim>();
92 
93  arma::vec::fixed<spacedim> centre;
94  centre.zeros();
95 
96  for (unsigned int li=0; li<element()->n_nodes(); li++) {
97  centre += *node( li );
98  }
99  centre /= (double) element()->n_nodes();
100  return centre;
101 }
102 
103 
104 template <int spacedim> inline
106  switch (dim()) {
107  case 1:
108  return 1.0;
109  case 2:
110  return
111  jacobian_S2() / 2
112  / pow(
113  arma::norm(*node(1) - *node(0), 2)
114  *arma::norm(*node(2) - *node(1), 2)
115  *arma::norm(*node(0) - *node(2), 2)
116  , 2.0/3.0)
117  / ( sqrt(3.0) / 4.0 ); // regular triangle
118  case 3:
119  double sum_faces=0;
120  double face[4];
121  for(unsigned int i=0; i<4; i++) sum_faces+=( face[i]=side(i)->measure());
122 
123  double sum_pairs=0;
124  for(unsigned int i=0;i<3;i++)
125  for(unsigned int j=i+1;j<4;j++) {
126  unsigned int i_line = RefElement<3>::line_between_faces(i,j);
127  arma::vec line = *node(RefElement<3>::interact(Interaction<0,1>(i_line))[1]) - *node(RefElement<3>::interact(Interaction<0,1>(i_line))[0]);
128  sum_pairs += face[i]*face[j]*arma::dot(line, line);
129  }
130  double regular = (2.0*sqrt(2.0/3.0)/9.0); // regular tetrahedron
131  double sign_measure = jacobian_S3() / 6;
132  return sign_measure * pow( sum_faces/sum_pairs, 3.0/4.0) / regular;
133 
134  }
135  return 1.0;
136 }
137 
138 template <int spacedim> inline
139 SideIter ElementAccessor<spacedim>::side(const unsigned int loc_index) {
140  return SideIter( Side(mesh_, element_idx_, loc_index) );
141 }
142 
143 template <int spacedim> inline
144 const SideIter ElementAccessor<spacedim>::side(const unsigned int loc_index) const {
145  return SideIter( Side(mesh_, element_idx_, loc_index) );
146 }
147 
148 
149 
150 /*******************************************************************************
151  * Edge IMPLEMENTATION
152  *******************************************************************************/
153 
154 inline Edge::Edge()
155 : mesh_(nullptr),
156  edge_idx_(undef_idx)
157 {}
158 
159 inline Edge::Edge(const Mesh *mesh, unsigned int edge_idx)
160 : mesh_(mesh),
161  edge_idx_(edge_idx)
162 {}
163 
164 inline const EdgeData* Edge::edge_data() const
165 {
166  ASSERT_DBG(is_valid());
168  return &mesh_->edges[edge_idx_];
169 }
170 
171 inline SideIter Edge::side(const unsigned int i) const {
172  return edge_data()->side_[i];
173 }
174 
175 
176 
177 
178 /*******************************************************************************
179  * Side IMPLEMENTATION
180  *******************************************************************************/
181 
182 inline Side::Side()
183 : mesh_(NULL), elem_idx_(0), side_idx_(0)
184 {}
185 
186 inline Side::Side(const Mesh * mesh, unsigned int elem_idx, unsigned int set_lnum)
187 : mesh_(mesh), elem_idx_(elem_idx), side_idx_(set_lnum)
188 {
190 }
191 
192 inline unsigned int Side::dim() const {
193  return element()->dim()-1;
194  }
195 
196 // returns true for all sides either on boundary or connected to vb neigboring
197 inline bool Side::is_external() const {
198  return edge().n_sides() == 1;
199 }
200 
201 // returns true for all sides either on boundary or connected to vb neigboring
202 inline bool Side::is_boundary() const {
203  return is_external() && cond_idx() != undef_idx;
204 }
205 
206 inline NodeAccessor<3> Side::node(unsigned int i) const {
207  int i_n = mesh_->side_nodes[dim()][side_idx_][i];
208 
209  return element().node( i_n );
210 }
211 
213  ASSERT( is_valid() ).error("Wrong use of uninitialized accessor.\n");
214  return mesh_->element_accessor( elem_idx_ );
215 }
216 
217 inline unsigned int Side::edge_idx() const {
218  return element()->edge_idx(side_idx_);
219 }
220 
221 inline Edge Side::edge() const {
222  return mesh_->edge(edge_idx());
223 }
224 
225 inline Boundary Side::cond() const {
226  return mesh_->boundary(cond_idx());
227 }
228 
229 inline unsigned int Side::cond_idx() const {
230  if (element()->boundary_idx_ == nullptr) return undef_idx;
231  else return element()->boundary_idx_[side_idx_];
232 }
233 
234 
235 
236 /*******************************************************************************
237  * Boundary IMPLEMENTATION
238  *******************************************************************************/
240 : boundary_data_(nullptr)
241 {}
242 
243 inline Boundary::Boundary(BoundaryData* boundary_data)
244 : boundary_data_(boundary_data)
245 {}
246 
248 {
249  ASSERT_DBG(is_valid());
251 }
252 
254 {
255  ASSERT_DBG(is_valid());
257 }
258 
260 {
261  return element_accessor().region();
262 }
263 
265 {
266  ASSERT_DBG(is_valid());
268 }
Side::edge
Edge edge() const
Returns pointer to the edge connected to the side.
Definition: accessors_impl.hh:221
Side::side_idx_
unsigned int side_idx_
Local # of side in element (to remove it, we heve to remove calc_side_rhs)
Definition: accessors.hh:496
Boundary
Definition: accessors.hh:363
Armor::vec
ArmaVec< double, N > vec
Definition: armor.hh:885
Side::elem_idx_
unsigned int elem_idx_
Index of element in Mesh::element_vec_.
Definition: accessors.hh:495
Side::is_external
bool is_external() const
Returns true for all sides either on boundary or connected to vb neigboring.
Definition: accessors_impl.hh:197
Edge::mesh_
const Mesh * mesh_
Pointer to the mesh owning the node.
Definition: accessors.hh:348
RefElement
Definition: ref_element.hh:339
Side::Side
Side()
Default invalid side accessor constructor.
Definition: accessors_impl.hh:182
ASSERT
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:347
Element::dim
unsigned int dim() const
Definition: elements.h:127
Side::mesh_
const Mesh * mesh_
Pointer to Mesh to which belonged.
Definition: accessors.hh:494
Edge::n_sides
unsigned int n_sides() const
Returns number of sides aligned with the edge.
Definition: accessors.hh:343
BoundaryData::edge_idx_
unsigned int edge_idx_
Definition: mesh_data.hh:49
Side::is_boundary
bool is_boundary() const
Returns true for side on the boundary.
Definition: accessors_impl.hh:202
Mesh::element_vec_
vector< Element > element_vec_
Definition: mesh.h:598
ASSERT_DBG
#define ASSERT_DBG(expr)
Definition: include_fadbad.hh:28
Side::dim
unsigned int dim() const
Returns dimension of the side, that is dimension of the element minus one.
Definition: accessors_impl.hh:192
ElementAccessor< 3 >
Side::elem_idx
unsigned int elem_idx() const
Returns index of element in Mesh::element_vec_.
Definition: accessors.hh:462
BoundaryData
Definition: mesh_data.hh:40
Edge::edge_data
const EdgeData * edge_data() const
Getter for edge data from mesh.
Definition: accessors_impl.hh:164
Mesh::boundary
Boundary boundary(uint edge_idx) const
Definition: mesh.cc:268
EdgeData
Definition: mesh_data.hh:25
Side::cond
Boundary cond() const
Definition: accessors_impl.hh:225
Edge::is_valid
bool is_valid() const
Definition: accessors.hh:322
Edge::Edge
Edge()
Default invalid edge accessor constructor.
Definition: accessors_impl.hh:154
BoundaryData::bc_ele_idx_
unsigned int bc_ele_idx_
Definition: mesh_data.hh:53
ElementAccessor::quality_measure_smooth
double quality_measure_smooth() const
Definition: accessors_impl.hh:105
Element
Definition: elements.h:40
EdgeData::side_
SideIter * side_
Definition: mesh_data.hh:32
Region
Definition: region.hh:146
Side::edge_idx
unsigned int edge_idx() const
Returns global index of the edge connected to the side.
Definition: accessors_impl.hh:217
Side::cond_idx
unsigned int cond_idx() const
Returns global index of the prescribed boundary condition.
Definition: accessors_impl.hh:229
Edge::side
SideIter side(const unsigned int i) const
Gets side iterator of the i -th side.
Definition: accessors_impl.hh:171
undef_idx
const unsigned int undef_idx
Definition: index_types.hh:32
ElementAccessor::inc
void inc()
Incremental function of the Element iterator.
Definition: accessors_impl.hh:49
Boundary::is_valid
bool is_valid() const
Definition: accessors.hh:374
Mesh::side_nodes
vector< vector< vector< unsigned int > > > side_nodes
Definition: mesh.h:339
Side
Definition: accessors.hh:404
Side::element
ElementAccessor< 3 > element() const
Returns iterator to the element of the side.
Definition: accessors_impl.hh:212
ElementAccessor::vertex_list
vector< arma::vec3 > vertex_list() const
Return list of element vertices.
Definition: accessors_impl.hh:55
Boundary::element_accessor
ElementAccessor< 3 > element_accessor()
Definition: accessors_impl.hh:253
ElementAccessor::node
NodeAccessor< 3 > node(unsigned int ni) const
Definition: accessors.hh:245
Mesh::check_element_size
void check_element_size(unsigned int elem_idx) const
Check if given index is in element_vec_.
Definition: mesh.cc:1148
Interaction
Definition: ref_element.hh:286
Boundary::element
Element * element()
Definition: accessors_impl.hh:264
Element::edge_idx
unsigned int edge_idx(unsigned int edg_idx) const
Return edge_idx of given index.
Definition: elements.h:142
Mesh
Definition: mesh.h:98
ElementAccessor::ElementAccessor
ElementAccessor()
Default invalid accessor.
Definition: accessors_impl.hh:25
Mesh::edges
std::vector< EdgeData > edges
Vector of MH edges, this should not be part of the geometrical mesh.
Definition: mesh.h:621
Edge
Definition: accessors.hh:308
RefElement::line_between_faces
static unsigned int line_between_faces(unsigned int f1, unsigned int f2)
RegionIdx
Definition: region.hh:67
ElementAccessor::region
Region region() const
Definition: accessors.hh:201
Boundary::boundary_data_
BoundaryData * boundary_data_
Definition: accessors.hh:394
NodeAccessor
Definition: mesh.h:55
ASSERT_LT_DBG
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:300
Boundary::Boundary
Boundary()
Definition: accessors_impl.hh:239
Side::is_valid
bool is_valid() const
Returns true if the side has assigned element.
Definition: accessors.hh:466
Side::node
NodeAccessor< 3 > node(unsigned int i) const
Returns node for given local index i on the side.
Definition: accessors_impl.hh:206
ElementAccessor::side
SideIter side(const unsigned int loc_index)
Definition: accessors_impl.hh:139
Mesh::element_accessor
virtual ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Definition: mesh.cc:817
BoundaryData::mesh_
Mesh * mesh_
Definition: mesh_data.hh:54
Edge::edge_idx_
unsigned int edge_idx_
Index into Mesh::edges vector.
Definition: accessors.hh:350
Boundary::region
Region region()
Definition: accessors_impl.hh:259
SideIter
Definition: accessors.hh:504
Element::boundary_idx_
unsigned int * boundary_idx_
Definition: elements.h:82
Mesh::edge
Edge edge(uint edge_idx) const
Definition: mesh.cc:262
Boundary::edge
Edge edge()
Definition: accessors_impl.hh:247
ElementAccessor::measure
double measure() const
Computes the measure of the element.
Definition: accessors_impl.hh:67
ElementAccessor::centre
arma::vec::fixed< spacedim > centre() const
Computes the barycenter.
Definition: accessors_impl.hh:89