Flow123d  JS_before_hm-2206-gca2a8366f
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
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 /**
55  * SET THE "METRICS" FIELD IN STRUCT ELEMENT
56  */
57 
58 template <int spacedim> inline
60  switch (dim()) {
61  case 0:
62  return 1.0;
63  break;
64  case 1:
65  return jacobian_S1();
66  break;
67  case 2:
68  return jacobian_S2() / 2.0;
69  break;
70  case 3:
71  return fabs( jacobian_S3() ) / 6.0;
72  break;
73  }
74  return 1.0;
75 }
76 
77 /**
78  * SET THE "CENTRE[]" FIELD IN STRUCT ELEMENT
79  */
80 template <int spacedim> inline
81 arma::vec::fixed<spacedim> ElementAccessor<spacedim>::centre() const {
82  ASSERT(is_valid()).error("Invalid element accessor.");
83  if (is_regional() ) return arma::vec::fixed<spacedim>();
84 
85  arma::vec::fixed<spacedim> centre;
86  centre.zeros();
87 
88  for (unsigned int li=0; li<element()->n_nodes(); li++) {
89  centre += *node( li );
90  }
91  centre /= (double) element()->n_nodes();
92  return centre;
93 }
94 
95 
96 template <int spacedim> inline
98  switch (dim()) {
99  case 1:
100  return 1.0;
101  case 2:
102  return
103  jacobian_S2() / 2
104  / pow(
105  arma::norm(*node(1) - *node(0), 2)
106  *arma::norm(*node(2) - *node(1), 2)
107  *arma::norm(*node(0) - *node(2), 2)
108  , 2.0/3.0)
109  / ( sqrt(3.0) / 4.0 ); // regular triangle
110  case 3:
111  double sum_faces=0;
112  double face[4];
113  for(unsigned int i=0; i<4; i++) sum_faces+=( face[i]=side(i)->measure());
114 
115  double sum_pairs=0;
116  for(unsigned int i=0;i<3;i++)
117  for(unsigned int j=i+1;j<4;j++) {
118  unsigned int i_line = RefElement<3>::line_between_faces(i,j);
119  arma::vec line = *node(RefElement<3>::interact(Interaction<0,1>(i_line))[1]) - *node(RefElement<3>::interact(Interaction<0,1>(i_line))[0]);
120  sum_pairs += face[i]*face[j]*arma::dot(line, line);
121  }
122  double regular = (2.0*sqrt(2.0/3.0)/9.0); // regular tetrahedron
123  double sign_measure = jacobian_S3() / 6;
124  return sign_measure * pow( sum_faces/sum_pairs, 3.0/4.0) / regular;
125 
126  }
127  return 1.0;
128 }
129 
130 template <int spacedim> inline
131 SideIter ElementAccessor<spacedim>::side(const unsigned int loc_index) {
132  return SideIter( Side(mesh_, element_idx_, loc_index) );
133 }
134 
135 template <int spacedim> inline
136 const SideIter ElementAccessor<spacedim>::side(const unsigned int loc_index) const {
137  return SideIter( Side(mesh_, element_idx_, loc_index) );
138 }
139 
140 
141 template <int spacedim> inline
143  arma::vec3 node_vertex = mesh_->nodes_->vec<spacedim>( element()->node_idx(0) );
144  BoundingBox bb(node_vertex);
145 
146  for(unsigned int i=1; i<element()->n_nodes(); i++) {
147  node_vertex = mesh_->nodes_->vec<spacedim>( element()->node_idx(i) );
148  bb.expand(node_vertex);
149  }
150 
151  return bb;
152 }
153 
154 
155 
156 /*******************************************************************************
157  * Edge IMPLEMENTATION
158  *******************************************************************************/
159 
160 inline Edge::Edge()
161 : mesh_(nullptr),
162  edge_idx_(undef_idx)
163 {}
164 
165 inline Edge::Edge(const MeshBase *mesh, unsigned int edge_idx)
166 : mesh_(mesh),
167  edge_idx_(edge_idx)
168 {}
169 
170 inline const EdgeData* Edge::edge_data() const
171 {
172  ASSERT(is_valid());
173  ASSERT_LT(edge_idx_, mesh_->edges.size());
174  return &mesh_->edges[edge_idx_];
175 }
176 
177 inline SideIter Edge::side(const unsigned int i) const {
178  return edge_data()->side_[i];
179 }
180 
181 
182 
183 
184 /*******************************************************************************
185  * Side IMPLEMENTATION
186  *******************************************************************************/
187 
188 inline Side::Side()
189 : mesh_(NULL), elem_idx_(0), side_idx_(0)
190 {}
191 
192 inline Side::Side(const MeshBase * mesh, unsigned int elem_idx, unsigned int set_lnum)
193 : mesh_(mesh), elem_idx_(elem_idx), side_idx_(set_lnum)
194 {
196 }
197 
198 inline unsigned int Side::dim() const {
199  return element()->dim()-1;
200  }
201 
202 // returns true for all sides either on boundary or connected to vb neigboring
203 inline bool Side::is_external() const {
204  return edge().n_sides() == 1;
205 }
206 
207 // returns true for all sides either on boundary or connected to vb neigboring
208 inline bool Side::is_boundary() const {
209  return is_external() && cond_idx() != undef_idx;
210 }
211 
212 inline NodeAccessor<3> Side::node(unsigned int i) const {
213  int i_n = mesh_->get_side_nodes(dim(), side_idx_)[i];
214 
215  return element().node( i_n );
216 }
217 
219  ASSERT( is_valid() ).error("Wrong use of uninitialized accessor.\n");
220  return mesh_->element_accessor( elem_idx_ );
221 }
222 
223 inline unsigned int Side::edge_idx() const {
224  return element()->edge_idx(side_idx_);
225 }
226 
227 inline Edge Side::edge() const {
228  return mesh_->edge(edge_idx());
229 }
230 
231 inline Boundary Side::cond() const {
232  return mesh_->boundary(cond_idx());
233 }
234 
235 inline unsigned int Side::cond_idx() const {
236  if (element()->boundary_idx_ == nullptr) return undef_idx;
237  else return element()->boundary_idx_[side_idx_];
238 }
239 
240 
241 
242 /*******************************************************************************
243  * Boundary IMPLEMENTATION
244  *******************************************************************************/
246 : boundary_data_(nullptr)
247 {}
248 
249 inline Boundary::Boundary(BoundaryData* boundary_data)
250 : boundary_data_(boundary_data)
251 {}
252 
254 {
255  ASSERT(is_valid());
257 }
258 
260 {
261  ASSERT(is_valid());
263 }
264 
266 {
267  return element_accessor().region();
268 }
269 
270 inline const Element * Boundary::element()
271 {
272  ASSERT(is_valid());
274 }
Side::edge
Edge edge() const
Returns pointer to the edge connected to the side.
Definition: accessors_impl.hh:227
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:482
MeshBase::element
const Element & element(unsigned idx) const
Definition: mesh.h:128
Boundary
Definition: accessors.hh:349
Armor::vec
ArmaVec< double, N > vec
Definition: armor.hh:885
Edge::mesh_
const MeshBase * mesh_
Pointer to the mesh owning the node.
Definition: accessors.hh:334
Side::elem_idx_
unsigned int elem_idx_
Index of element in Mesh::element_vec_.
Definition: accessors.hh:481
Side::is_external
bool is_external() const
Returns true for all sides either on boundary or connected to vb neigboring.
Definition: accessors_impl.hh:203
RefElement
Definition: ref_element.hh:339
Side::Side
Side()
Default invalid side accessor constructor.
Definition: accessors_impl.hh:188
ASSERT
#define ASSERT(expr)
Definition: asserts.hh:350
Element::dim
unsigned int dim() const
Definition: elements.h:120
Edge::n_sides
unsigned int n_sides() const
Returns number of sides aligned with the edge.
Definition: accessors.hh:329
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:208
Side::dim
unsigned int dim() const
Returns dimension of the side, that is dimension of the element minus one.
Definition: accessors_impl.hh:198
ElementAccessor< 3 >
Side::elem_idx
unsigned int elem_idx() const
Returns index of element in Mesh::element_vec_.
Definition: accessors.hh:448
arma::vec3
Definition: doxy_dummy_defs.hh:17
BoundaryData
Definition: mesh_data.hh:40
Edge::edge_data
const EdgeData * edge_data() const
Getter for edge data from mesh.
Definition: accessors_impl.hh:170
EdgeData
Definition: mesh_data.hh:25
Side::cond
Boundary cond() const
Definition: accessors_impl.hh:231
Edge::is_valid
bool is_valid() const
Definition: accessors.hh:308
Edge::Edge
Edge()
Default invalid edge accessor constructor.
Definition: accessors_impl.hh:160
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:97
ASSERT_LT
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:300
Element
Definition: elements.h:40
BoundingBox
Bounding box in 3d ambient space.
Definition: bounding_box.hh:54
EdgeData::side_
SideIter * side_
Definition: mesh_data.hh:32
Region
Definition: region.hh:146
MeshBase::check_element_size
void check_element_size(unsigned int elem_idx) const
Check if given index is in element_vec_.
Definition: mesh.h:162
Mesh::bc_mesh
BCMesh * bc_mesh() const override
Implement MeshBase::bc_mesh(), getter of boundary mesh.
Definition: mesh.h:563
MeshBase::edges
std::vector< EdgeData > edges
Vector of MH edges, this should not be part of the geometrical mesh.
Definition: mesh.h:299
ElementAccessor::bounding_box
BoundingBox bounding_box() const
Definition: accessors_impl.hh:142
Side::edge_idx
unsigned int edge_idx() const
Returns global index of the edge connected to the side.
Definition: accessors_impl.hh:223
Side::cond_idx
unsigned int cond_idx() const
Returns global index of the prescribed boundary condition.
Definition: accessors_impl.hh:235
Edge::side
SideIter side(const unsigned int i) const
Gets side iterator of the i -th side.
Definition: accessors_impl.hh:177
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:360
MeshBase::element_accessor
ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Definition: mesh.cc:866
Side
Definition: accessors.hh:390
Side::element
ElementAccessor< 3 > element() const
Returns iterator to the element of the side.
Definition: accessors_impl.hh:218
Boundary::element_accessor
ElementAccessor< 3 > element_accessor()
Definition: accessors_impl.hh:259
ElementAccessor::node
NodeAccessor< 3 > node(unsigned int ni) const
Definition: accessors.hh:230
Boundary::element
const Element * element()
Definition: accessors_impl.hh:270
MeshBase::get_side_nodes
const std::vector< unsigned int > & get_side_nodes(unsigned int dim, unsigned int side) const
Definition: mesh.h:168
Interaction
Definition: ref_element.hh:286
Element::edge_idx
unsigned int edge_idx(unsigned int edg_idx) const
Return edge_idx of given index.
Definition: elements.h:135
MeshBase::edge
Edge edge(uint edge_idx) const
Return edge with given index.
Definition: mesh.cc:131
ElementAccessor::ElementAccessor
ElementAccessor()
Default invalid accessor.
Definition: accessors_impl.hh:25
Edge
Definition: accessors.hh:294
Side::mesh_
const MeshBase * mesh_
Pointer to Mesh to which belonged.
Definition: accessors.hh:480
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:198
MeshBase
Base class for Mesh and BCMesh.
Definition: mesh.h:96
Boundary::boundary_data_
BoundaryData * boundary_data_
Definition: accessors.hh:380
NodeAccessor
Definition: mesh.h:55
Boundary::Boundary
Boundary()
Definition: accessors_impl.hh:245
MeshBase::boundary
virtual Boundary boundary(uint edge_idx) const =0
Side::is_valid
bool is_valid() const
Returns true if the side has assigned element.
Definition: accessors.hh:452
Side::node
NodeAccessor< 3 > node(unsigned int i) const
Returns node for given local index i on the side.
Definition: accessors_impl.hh:212
ElementAccessor::side
SideIter side(const unsigned int loc_index)
Definition: accessors_impl.hh:131
BoundaryData::mesh_
Mesh * mesh_
Definition: mesh_data.hh:54
Edge::edge_idx_
unsigned int edge_idx_
Index into Mesh::edges vector.
Definition: accessors.hh:336
Boundary::region
Region region()
Definition: accessors_impl.hh:265
SideIter
Definition: accessors.hh:490
Element::boundary_idx_
unsigned int * boundary_idx_
Definition: elements.h:79
Boundary::edge
Edge edge()
Definition: accessors_impl.hh:253
ElementAccessor::measure
double measure() const
Computes the measure of the element.
Definition: accessors_impl.hh:59
ElementAccessor::centre
arma::vec::fixed< spacedim > centre() const
Computes the barycenter.
Definition: accessors_impl.hh:81