Flow123d  JS_before_hm-2-g912b55d
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
35  mesh_(mesh),
36  r_idx_(r_idx)
37 {}
38 
39 /**
40  * Element accessor.
41  */
42 template <int spacedim> inline
44 : mesh_(mesh),
45  boundary_(idx>=mesh->n_elements()),
46  element_idx_(idx),
48 {
49  dim_=element()->dim();
50 }
51 
52 template <int spacedim> inline
54  ASSERT(!is_regional()).error("Do not call inc() for regional accessor!");
55  element_idx_++;
56  r_idx_ = element()->region_idx();
57  dim_=element()->dim();
59 }
60 
61 template <int spacedim> inline
62 vector<arma::vec3> ElementAccessor<spacedim>::vertex_list() const {
63  vector<arma::vec3> vertices(element()->n_nodes());
64  for(unsigned int i=0; i<element()->n_nodes(); i++) vertices[i]=node(i)->point();
65  return vertices;
66 }
67 
68 template <int spacedim> inline
70 {
71  ASSERT(dim() == 3)(dim()).error("Cannot provide Jacobian for dimension other than 3.");
72  return arma::dot( arma::cross(*( node(1) ) - *( node(0) ),
73  *( node(2) ) - *( node(0) )),
74  *( node(3) ) - *( node(0) )
75  );
76 }
77 
78 /**
79  * SET THE "METRICS" FIELD IN STRUCT ELEMENT
80  */
81 template <int spacedim> inline
83  switch (dim()) {
84  case 0:
85  return 1.0;
86  break;
87  case 1:
88  return arma::norm(*( node(1) ) - *( node(0) ) , 2);
89  break;
90  case 2:
91  return
92  arma::norm(
93  arma::cross(*( node(1) ) - *( node(0) ), *( node(2) ) - *( node(0) )),
94  2
95  ) / 2.0 ;
96  break;
97  case 3:
98  return fabs(
99  arma::dot(
100  arma::cross(*( node(1) ) - *( node(0) ), *( node(2) ) - *( node(0) )),
101  *( node(3) ) - *( node(0) ) )
102  ) / 6.0;
103  break;
104  }
105  return 1.0;
106 }
107 
108 /**
109  * SET THE "CENTRE[]" FIELD IN STRUCT ELEMENT
110  */
111 template <int spacedim> inline
112 arma::vec::fixed<spacedim> ElementAccessor<spacedim>::centre() const {
113  ASSERT(is_valid()).error("Invalid element accessor.");
114  if (is_regional() ) return arma::vec::fixed<spacedim>();
115 
116  arma::vec::fixed<spacedim> centre;
117  centre.zeros();
118 
119  for (unsigned int li=0; li<element()->n_nodes(); li++) {
120  centre += node( li )->point();
121  }
122  centre /= (double) element()->n_nodes();
123  return centre;
124 }
125 
126 
127 template <int spacedim> inline
129  if (dim_==3) {
130  double sum_faces=0;
131  double face[4];
132  for(unsigned int i=0; i<4; i++, ++side) sum_faces+=( face[i]=side->measure());
133 
134  double sum_pairs=0;
135  for(unsigned int i=0;i<3;i++)
136  for(unsigned int j=i+1;j<4;j++) {
137  unsigned int i_line = RefElement<3>::line_between_faces(i,j);
139  sum_pairs += face[i]*face[j]*arma::dot(line, line);
140  }
141  double regular = (2.0*sqrt(2.0/3.0)/9.0); // regular tetrahedron
142  return fabs( measure()
143  * pow( sum_faces/sum_pairs, 3.0/4.0))/ regular;
144 
145  }
146  if (dim_==2) {
147  return fabs(
148  measure()/
149  pow(
150  arma::norm(*node(1) - *node(0), 2)
151  *arma::norm(*node(2) - *node(1), 2)
152  *arma::norm(*node(0) - *node(2), 2)
153  , 2.0/3.0)
154  ) / ( sqrt(3.0) / 4.0 ); // regular triangle
155  }
156  return 1.0;
157 }
158 
159 template <int spacedim> inline
160 SideIter ElementAccessor<spacedim>::side(const unsigned int loc_index) {
161  return SideIter( Side(mesh_, element_idx_, loc_index) );
162 }
163 
164 template <int spacedim> inline
165 const SideIter ElementAccessor<spacedim>::side(const unsigned int loc_index) const {
166  return SideIter( Side(mesh_, element_idx_, loc_index) );
167 }
168 
169 
170 
171 /*******************************************************************************
172  * Edge IMPLEMENTATION
173  *******************************************************************************/
174 
175 inline Edge::Edge()
176 : mesh_(nullptr),
177  edge_idx_(Mesh::undef_idx)
178 {}
179 
180 inline Edge::Edge(const Mesh *mesh, unsigned int edge_idx)
181 : mesh_(mesh),
182  edge_idx_(edge_idx)
183 {}
184 
185 inline const EdgeData* Edge::edge_data() const
186 {
187  ASSERT_DBG(is_valid());
189  return &mesh_->edges[edge_idx_];
190 }
191 
192 inline SideIter Edge::side(const unsigned int i) const {
193  return edge_data()->side_[i];
194 }
195 
196 
197 
198 
199 /*******************************************************************************
200  * Side IMPLEMENTATION
201  *******************************************************************************/
202 
203 inline Side::Side()
204 : mesh_(NULL), elem_idx_(0), side_idx_(0)
205 {}
206 
207 inline Side::Side(const Mesh * mesh, unsigned int elem_idx, unsigned int set_lnum)
208 : mesh_(mesh), elem_idx_(elem_idx), side_idx_(set_lnum)
209 {
210  mesh_->check_element_size(elem_idx);
211 }
212 
213 inline unsigned int Side::dim() const {
214  return element()->dim()-1;
215  }
216 
217 // returns true for all sides either on boundary or connected to vb neigboring
218 inline bool Side::is_external() const {
219  return edge().n_sides() == 1;
220 }
221 
222 // returns true for all sides either on boundary or connected to vb neigboring
223 inline bool Side::is_boundary() const {
224  return is_external() && cond_idx() != Mesh::undef_idx;
225 }
226 
227 inline NodeAccessor<3> Side::node(unsigned int i) const {
228  int i_n = mesh_->side_nodes[dim()][side_idx_][i];
229 
230  return element().node_accessor( i_n );
231 }
232 
234  ASSERT( is_valid() ).error("Wrong use of uninitialized accessor.\n");
235  return mesh_->element_accessor( elem_idx_ );
236 }
237 
238 inline unsigned int Side::edge_idx() const {
239  return element()->edge_idx(side_idx_);
240 }
241 
242 inline Edge Side::edge() const {
243  return mesh_->edge(edge_idx());
244 }
245 
246 inline Boundary Side::cond() const {
247  return mesh_->boundary(cond_idx());
248 }
249 
250 inline unsigned int Side::cond_idx() const {
251  if (element()->boundary_idx_ == nullptr) return Mesh::undef_idx;
252  else return element()->boundary_idx_[side_idx_];
253 }
254 
255 
256 
257 /*******************************************************************************
258  * Boundary IMPLEMENTATION
259  *******************************************************************************/
261 : boundary_data_(nullptr)
262 {}
263 
264 inline Boundary::Boundary(BoundaryData* boundary_data)
265 : boundary_data_(boundary_data)
266 {}
267 
269 {
270  ASSERT_DBG(is_valid());
272 }
273 
275 {
276  ASSERT_DBG(is_valid());
278 }
279 
281 {
282  return element_accessor().region();
283 }
284 
286 {
287  ASSERT_DBG(is_valid());
289 }
unsigned int n_sides() const
Returns number of sides aligned with the edge.
Definition: accessors.hh:298
const Element * element() const
Definition: accessors.hh:159
unsigned int n_nodes() const
Definition: elements.h:128
vector< Element > element_vec_
Definition: mesh.h:512
unsigned int * boundary_idx_
Definition: elements.h:82
unsigned int bc_ele_idx_
Definition: mesh_data.hh:53
NodeAccessor< 3 > node_accessor(unsigned int ni) const
Definition: accessors.hh:202
unsigned int dim_
Dimension of reference element.
Definition: accessors.hh:242
Edge edge() const
Returns pointer to the edge connected to the side.
unsigned int edge_idx() const
Returns global index of the edge connected to the side.
RegionIdx region_idx() const
Definition: elements.h:54
static const unsigned int undef_idx
Definition: mesh.h:102
const Mesh * mesh_
Pointer to the mesh owning the node.
Definition: accessors.hh:303
Definition: mesh.h:76
bool is_valid() const
Definition: accessors.hh:152
std::vector< EdgeData > edges
Vector of MH edges, this should not be part of the geometrical mesh.
Definition: mesh.h:535
const Mesh * mesh_
Pointer to the mesh owning the element.
Definition: accessors.hh:245
static unsigned int line_between_faces(unsigned int f1, unsigned int f2)
Mat< double, N, 1 > vec
Definition: armor.hh:211
vector< vector< vector< unsigned int > > > side_nodes
Definition: mesh.h:287
SideIter side(const unsigned int loc_index)
BoundaryData * boundary_data_
Definition: accessors.hh:349
unsigned int element_idx_
Index into Mesh::element_vec_ array.
Definition: accessors.hh:250
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
Region region()
Boundary boundary(uint edge_idx) const
Definition: mesh.cc:256
ElementAccessor< 3 > element() const
Returns iterator to the element of the side.
Edge()
Default invalid edge accessor constructor.
virtual ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Definition: mesh.cc:741
bool is_external() const
Returns true for all sides either on boundary or connected to vb neigboring.
arma::vec::fixed< spacedim > centre() const
Computes the barycenter.
unsigned int dim() const
Definition: elements.h:123
unsigned int elem_idx_
Index of element in Mesh::element_vec_.
Definition: accessors.hh:441
static const unsigned int undefined_dim_
Definition: accessors.hh:239
double quality_measure_smooth(SideIter side) const
const Mesh * mesh() const
Returns pointer to the mesh.
Definition: accessors.hh:409
unsigned int dim() const
Returns dimension of the side, that is dimension of the element minus one.
bool is_boundary() const
Returns true for side on the boundary.
Mesh * mesh_
Definition: mesh_data.hh:54
void check_element_size(unsigned int elem_idx) const
Check if given index is in element_vec_.
Definition: mesh.cc:1073
bool is_valid() const
Definition: accessors.hh:329
unsigned int edge_idx(unsigned int edg_idx) const
Return edge_idx of given index.
Definition: elements.h:138
unsigned int edge_idx_
Definition: mesh_data.hh:49
bool is_valid() const
Returns true if the side has assigned element.
Definition: accessors.hh:421
Type dot(const Mat< Type, nRows, nCols > &a, const Mat< Type, nRows, nCols > &b)
Definition: armor.hh:176
const EdgeData * edge_data() const
Getter for edge data from mesh.
void inc()
Incremental function of the Element iterator.
Element * element()
Side()
Default invalid side accessor constructor.
double measure() const
Computes the measure of the element.
bool boundary_
True if the element is boundary.
Definition: accessors.hh:247
NodeAccessor< 3 > node(unsigned int i) const
Returns node for given local index i on the side.
double measure() const
Calculate metrics of the side.
Definition: accessors.cc:27
ElementAccessor()
Default invalid accessor.
Region region() const
Definition: accessors.hh:164
unsigned int side_idx_
Local # of side in element (to remove it, we heve to remove calc_side_rhs)
Definition: accessors.hh:442
RegionIdx r_idx_
Region index.
Definition: accessors.hh:253
unsigned int edge_idx_
Index into Mesh::edges vector.
Definition: accessors.hh:305
vector< arma::vec3 > vertex_list() const
Return list of element vertices.
virtual unsigned int n_elements(bool boundary=false) const
Returns count of boundary or bulk elements.
Definition: mesh.h:344
unsigned int cond_idx() const
Returns global index of the prescribed boundary condition.
const Mesh * mesh_
Pointer to Mesh to which belonged.
Definition: accessors.hh:440
RegionIdx region_idx() const
Definition: accessors.hh:167
#define ASSERT_DBG(expr)
double tetrahedron_jacobian() const
SideIter * side_
Definition: mesh_data.hh:32
Edge edge(uint edge_idx) const
Definition: mesh.cc:250
unsigned int elem_idx() const
Returns index of element in Mesh::element_vec_.
Definition: accessors.hh:417
unsigned int dim() const
Definition: accessors.hh:156
Boundary cond() const
bool is_valid() const
Definition: accessors.hh:277
arma::vec3 & point()
Definition: nodes.hh:67
unsigned int idx() const
Return local idx of element in boundary / bulk part of element vector.
Definition: accessors.hh:180
SideIter side(const unsigned int i) const
Gets side iterator of the i -th side.
ElementAccessor< 3 > element_accessor()
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:300
const Node * node(unsigned int ni) const
Definition: accessors.hh:198
bool is_regional() const
Definition: accessors.hh:144