Flow123d  release_2.2.0-914-gf1a3a4f
elements.cc
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 elements.cc
15  * @ingroup mesh
16  * @brief Various element oriented stuff, should be restricted to purely geometric functions
17  */
18 
19 #include <vector>
20 #include <string>
21 
22 #include "system/system.hh"
23 #include "mesh/mesh.h"
24 #include "mesh/ref_element.hh"
25 #include "element_impls.hh"
26 
27 // following deps. should be removed
28 #include "mesh/boundaries.h"
29 //#include "materials.hh"
30 #include "mesh/accessors.hh"
31 #include "la/distribution.hh"
32 
33 
34 
36 : pid(0),
37 
38  node(NULL),
39 
40 // material(NULL),
41  edge_idx_(NULL),
42  boundary_idx_(NULL),
43  permutation_idx_(NULL),
44 
45  n_neighs_vb(0),
46  neigh_vb(NULL),
47 
48  dim_(0)
49 
50 {
51 }
52 
53 
54 Element::Element(unsigned int dim, Mesh *mesh_in, RegionIdx reg)
55 {
56  init(dim, mesh_in, reg);
57 }
58 
59 
60 
61 void Element::init(unsigned int dim, Mesh *mesh_in, RegionIdx reg) {
62  pid=0;
63  n_neighs_vb=0;
64  neigh_vb=NULL;
65  dim_=dim;
66  mesh_=mesh_in;
67  region_idx_=reg;
68 
69  node = new Node * [ n_nodes()];
70  edge_idx_ = new unsigned int [ n_sides()];
71  boundary_idx_ = NULL;
72  permutation_idx_ = new unsigned int[n_sides()];
73 
74  FOR_ELEMENT_SIDES(this, si) {
77  }
78 }
79 
80 
82  // Can not make deallocation here since then resize of
83  // vectors of elements deallocates what should be keeped.
84 }
85 
86 
87 /**
88  * SET THE "METRICS" FIELD IN STRUCT ELEMENT
89  */
90 double Element::measure() const {
91  switch (dim()) {
92  case 0:
93  return 1.0;
94  break;
95  case 1:
96  return arma::norm(*(node[ 1 ]) - *(node[ 0 ]) , 2);
97  break;
98  case 2:
99  return
100  arma::norm(
101  arma::cross(*(node[1]) - *(node[0]), *(node[2]) - *(node[0])),
102  2
103  ) / 2.0 ;
104  break;
105  case 3:
106  return fabs(
107  arma::dot(
108  arma::cross(*node[1] - *node[0], *node[2] - *node[0]),
109  *node[3] - *node[0] )
110  ) / 6.0;
111  break;
112  }
113  return 1.0;
114 }
115 
117 {
118  OLD_ASSERT(dim_ == 3, "Cannot provide Jacobian for dimension other than 3.");
119  return arma::dot( arma::cross(*node[1] - *node[0],
120  *node[2] - *node[0]),
121  *node[3] - *node[0]
122  );
123 }
124 
125 
126 /**
127  * SET THE "CENTRE[]" FIELD IN STRUCT ELEMENT
128  */
129 
131  unsigned int li;
132 
134  centre.zeros();
135 
136  FOR_ELEMENT_NODES(this, li) {
137  centre += node[ li ]->point();
138  }
139  centre /= (double) n_nodes();
140  return centre;
141 }
142 
143 /**
144  * Count element sides of the space dimension @p side_dim.
145  */
146 
147 unsigned int Element::n_sides_by_dim(unsigned int side_dim)
148 {
149  if (side_dim == dim()) return 1;
150 
151  unsigned int n = 0;
152  for (unsigned int i=0; i<n_sides(); i++)
153  if (side(i)->dim() == side_dim) n++;
154  return n;
155 }
156 
157 
159 {
160  return mesh_->element_accessor( mesh_->element.index(this) );
161 }
162 
163 
164 
166  return Region( region_idx_, mesh_->region_db());
167 }
168 
169 
170 unsigned int Element::id() const {
171  return mesh_->element.get_id(this);
172 }
173 
175  if (dim_==3) {
176  double sum_faces=0;
177  double face[4];
178  for(unsigned int i=0;i<4;i++) sum_faces+=( face[i]=side(i)->measure());
179 
180  double sum_pairs=0;
181  for(unsigned int i=0;i<3;i++)
182  for(unsigned int j=i+1;j<4;j++) {
183  unsigned int i_line = RefElement<3>::line_between_faces(i,j);
185  sum_pairs += face[i]*face[j]*arma::dot(line, line);
186  }
187  double regular = (2.0*sqrt(2.0/3.0)/9.0); // regular tetrahedron
188  return fabs( measure()
189  * pow( sum_faces/sum_pairs, 3.0/4.0))/ regular;
190 
191  }
192  if (dim_==2) {
193  return fabs(
194  measure()/
195  pow(
196  arma::norm(*node[1] - *node[0], 2)
197  *arma::norm(*node[2] - *node[1], 2)
198  *arma::norm(*node[0] - *node[2], 2)
199  , 2.0/3.0)
200  ) / ( sqrt(3.0) / 4.0 ); // regular triangle
201  }
202  return 1.0;
203 }
204 
205 
207 {
208  bounding_box = BoundingBox( this->node[0]->point() );
209 
210  for (unsigned int i=1; i<n_nodes(); i++)
211  bounding_box.expand( this->node[i]->point() );
212 }
213 
215 {
216  ASSERT_GT(mesh_->element_box_.size(), 0);
217  return mesh_->element_box_[mesh_->element.index(this)];
218 }
219 
220 
221 unsigned int Element::get_proc() const
222 {
223  return mesh_->get_el_ds()->get_proc(mesh_->get_row_4_el()[index()]);
224 }
225 
226 
227 //-----------------------------------------------------------------------------
228 // vim: set cindent:
unsigned int get_proc(unsigned int idx) const
get processor of the given index
Bounding box in 3d ambient space.
Definition: bounding_box.hh:45
double measure() const
Computes the measure of the element.
Definition: elements.cc:90
unsigned int n_nodes() const
#define FOR_ELEMENT_NODES(i, j)
Definition: elements.h:156
unsigned int * boundary_idx_
Definition: elements.h:94
int get_id(const T *it) const
Definition: sys_vector.hh:458
Definition: nodes.hh:32
int pid
Definition: elements.h:87
unsigned int * permutation_idx_
Definition: elements.h:103
unsigned int get_proc() const
Definition: elements.cc:221
static const unsigned int undef_idx
Definition: mesh.h:125
#define ASSERT_GT(a, b)
Definition of comparative assert macro (Greater Than)
Definition: asserts.hh:311
unsigned int index() const
void expand(const Point &point)
Definition: mesh.h:99
double tetrahedron_jacobian() const
Definition: elements.cc:116
#define FOR_ELEMENT_SIDES(i, j)
Definition: elements.h:157
static unsigned int line_between_faces(unsigned int f1, unsigned int f2)
Node ** node
Definition: elements.h:90
unsigned int id() const
Definition: elements.cc:170
const RegionDB & region_db() const
Definition: mesh.h:170
ElementAccessor< 3 > element_accessor(unsigned int idx, bool boundary=false)
Definition: mesh.cc:668
Element()
Definition: elements.cc:35
unsigned int dim() const
#define OLD_ASSERT(...)
Definition: global_defs.h:131
BoundingBox & get_bounding_box_fast(BoundingBox &bounding_box) const
Return precomputed bounding box.
Definition: elements.cc:214
unsigned int * edge_idx_
Definition: elements.h:93
unsigned int dim() const
Definition: side_impl.hh:37
~Element()
Definition: elements.cc:81
Neighbour ** neigh_vb
Definition: elements.h:135
Region region() const
Definition: elements.cc:165
unsigned int n_sides() const
static const IdxVector< (InDim >OutDim?InDim+1:dim-InDim) > interact(TInteraction< OutDim, InDim > interaction)
unsigned int index(const T *pointer) const
Definition: sys_vector.hh:373
void get_bounding_box(BoundingBox &bounding_box) const
Definition: elements.cc:206
SideIter side(const unsigned int loc_index)
Distribution * get_el_ds() const
Definition: mesh.h:189
unsigned int dim_
Definition: elements.h:144
void init(unsigned int dim, Mesh *mesh_in, RegionIdx reg)
Definition: elements.cc:61
Mesh * mesh_
Definition: elements.h:138
Support classes for parallel programing.
RegionIdx region_idx_
Definition: elements.h:143
arma::vec3 centre() const
Computes the barycenter.
Definition: elements.cc:130
unsigned int n_neighs_vb
Definition: elements.h:133
double quality_measure_smooth()
Definition: elements.cc:174
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...
ElementAccessor< 3 > element_accessor() const
Gets ElementAccessor of this element.
Definition: elements.cc:158
unsigned int n_sides_by_dim(unsigned int side_dim)
Definition: elements.cc:147
arma::vec3 & point()
Definition: nodes.hh:68
IdxInt * get_row_4_el() const
Definition: mesh.h:192
ElementVector element
Vector of elements of the mesh.
Definition: mesh.h:260
std::vector< BoundingBox > element_box_
Auxiliary vector of mesh elements bounding boxes.
Definition: mesh.h:429
BoundingBox bounding_box()
Definition: elements.h:117