Flow123d  master-f44eb46
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 {
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 }
#define ASSERT(expr)
Definition: asserts.hh:351
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:301
unsigned int bc_ele_idx_
Definition: mesh_data.hh:53
Mesh * mesh_
Definition: mesh_data.hh:54
unsigned int edge_idx_
Definition: mesh_data.hh:49
bool is_valid() const
Definition: accessors.hh:360
const Element * element()
Region region()
BoundaryData * boundary_data_
Definition: accessors.hh:380
ElementAccessor< 3 > element_accessor()
Bounding box in 3d ambient space.
Definition: bounding_box.hh:53
SideIter * side_
Definition: mesh_data.hh:32
const MeshBase * mesh_
Pointer to the mesh owning the node.
Definition: accessors.hh:334
Edge()
Default invalid edge accessor constructor.
unsigned int n_sides() const
Returns number of sides aligned with the edge.
Definition: accessors.hh:329
bool is_valid() const
Definition: accessors.hh:308
unsigned int edge_idx_
Index into Mesh::edges vector.
Definition: accessors.hh:336
SideIter side(const unsigned int i) const
Gets side iterator of the i -th side.
const EdgeData * edge_data() const
Getter for edge data from mesh.
NodeAccessor< 3 > node(unsigned int ni) const
Definition: accessors.hh:230
void inc()
Incremental function of the Element iterator.
double measure() const
Computes the measure of the element.
SideIter side(const unsigned int loc_index)
BoundingBox bounding_box() const
Region region() const
Definition: accessors.hh:198
double quality_measure_smooth() const
arma::vec::fixed< spacedim > centre() const
Computes the barycenter.
ElementAccessor()
Default invalid accessor.
unsigned int * boundary_idx_
Definition: elements.h:79
unsigned int edge_idx(unsigned int edg_idx) const
Return edge_idx of given index.
Definition: elements.h:135
unsigned int dim() const
Definition: elements.h:120
Base class for Mesh and BCMesh.
Definition: mesh.h:96
virtual Boundary boundary(uint edge_idx) const =0
const Element & element(unsigned idx) const
Definition: mesh.h:128
void check_element_size(unsigned int elem_idx) const
Check if given index is in element_vec_.
Definition: mesh.h:162
std::vector< EdgeData > edges
Vector of MH edges, this should not be part of the geometrical mesh.
Definition: mesh.h:301
const std::vector< unsigned int > & get_side_nodes(unsigned int dim, unsigned int side) const
Definition: mesh.h:168
Edge edge(uint edge_idx) const
Return edge with given index.
Definition: mesh.cc:131
ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Definition: mesh.cc:866
BCMesh * bc_mesh() const override
Implement MeshBase::bc_mesh(), getter of boundary mesh.
Definition: mesh.h:567
static unsigned int line_between_faces(unsigned int f1, unsigned int f2)
unsigned int elem_idx() const
Returns index of element in Mesh::element_vec_.
Definition: accessors.hh:448
const MeshBase * mesh_
Pointer to Mesh to which belonged.
Definition: accessors.hh:480
bool is_valid() const
Returns true if the side has assigned element.
Definition: accessors.hh:452
Boundary cond() const
ElementAccessor< 3 > element() const
Returns iterator to the element of the side.
unsigned int cond_idx() const
Returns global index of the prescribed boundary condition.
bool is_external() const
Returns true for all sides either on boundary or connected to vb neigboring.
Side()
Default invalid side accessor constructor.
unsigned int side_idx_
Local # of side in element (to remove it, we heve to remove calc_side_rhs)
Definition: accessors.hh:482
bool is_boundary() const
Returns true for side on the boundary.
unsigned int edge_idx() const
Returns global index of the edge connected to the side.
unsigned int dim() const
Returns dimension of the side, that is dimension of the element minus one.
unsigned int elem_idx_
Index of element in Mesh::element_vec_.
Definition: accessors.hh:481
Edge edge() const
Returns pointer to the edge connected to the side.
NodeAccessor< 3 > node(unsigned int i) const
Returns node for given local index i on the side.
const unsigned int undef_idx
Definition: index_types.hh:32
ArmaVec< double, N > vec
Definition: armor.hh:885