Flow123d  jenkins-Flow123d-windows32-release-multijob-28
elements.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file
26  * @brief Various element oriented stuff, should be restricted to purely geometric functions
27  * @ingroup mesh
28  *
29  */
30 
31 #include <vector>
32 #include <string>
33 
34 #include "system/system.hh"
35 #include "mesh/mesh.h"
36 #include "mesh/ref_element.hh"
37 #include "element_impls.hh"
38 
39 // following deps. should be removed
40 #include "mesh/boundaries.h"
41 //#include "materials.hh"
42 #include "mesh/accessors.hh"
43 
44 
45 
47 : pid(0),
48 
49  node(NULL),
50 
51 // material(NULL),
52  edge_idx_(NULL),
53  boundary_idx_(NULL),
54  permutation_idx_(NULL),
55 
56  n_neighs_vb(0),
57  neigh_vb(NULL),
58 
59  dim_(0)
60 
61 {
62 }
63 
64 
65 Element::Element(unsigned int dim, Mesh *mesh_in, RegionIdx reg)
66 {
67  init(dim, mesh_in, reg);
68 }
69 
70 
71 
72 void Element::init(unsigned int dim, Mesh *mesh_in, RegionIdx reg) {
73  pid=0;
74 // material=NULL;
75  n_neighs_vb=0;
76  neigh_vb=NULL;
77  dim_=dim;
78  mesh_=mesh_in;
79  region_idx_=reg;
80 
81  node = new Node * [ n_nodes()];
82  edge_idx_ = new unsigned int [ n_sides()];
83  boundary_idx_ = NULL;
84  permutation_idx_ = new unsigned int[n_sides()];
85 
86  FOR_ELEMENT_SIDES(this, si) {
89  }
90 }
91 
92 
94 /*
95  if (node) { delete[] node; node=NULL;}
96  if (edge_idx_) { delete[] edge_idx_; edge_idx_=NULL;}
97  if (permutation_idx_) { delete[] permutation_idx_; permutation_idx_=NULL;}
98  if (boundary_idx_) { delete[] boundary_idx_; boundary_idx_ = NULL; }
99  */
100 
101 }
102 
103 
104 /**
105  * SET THE "METRICS" FIELD IN STRUCT ELEMENT
106  */
107 double Element::measure() const {
108  switch (dim()) {
109  case 0:
110  return 1.0;
111  break;
112  case 1:
113  return arma::norm(*(node[ 1 ]) - *(node[ 0 ]) , 2);
114  break;
115  case 2:
116  return
117  arma::norm(
118  arma::cross(*(node[1]) - *(node[0]), *(node[2]) - *(node[0])),
119  2
120  ) / 2.0 ;
121  break;
122  case 3:
123  return fabs(
124  arma::dot(
125  arma::cross(*node[1] - *node[0], *node[2] - *node[0]),
126  *node[3] - *node[0] )
127  ) / 6.0;
128  break;
129  }
130  return 1.0;
131 }
132 
133 
134 /**
135  * SET THE "CENTRE[]" FIELD IN STRUCT ELEMENT
136  */
137 
139  unsigned int li;
140 
142  centre.zeros();
143 
144  FOR_ELEMENT_NODES(this, li) {
145  centre += node[ li ]->point();
146  }
147  centre /= (double) n_nodes();
148  //DBGMSG("%d: %f %f %f\n",ele.id(),ele->centre[0],ele->centre[1],ele->centre[2]);
149  return centre;
150 }
151 
152 /**
153  * Count element sides of the space dimension @p side_dim.
154  */
155 
156 unsigned int Element::n_sides_by_dim(unsigned int side_dim)
157 {
158  if (side_dim == dim()) return 1;
159 
160  unsigned int n = 0;
161  for (unsigned int i=0; i<n_sides(); i++)
162  if (side(i)->dim() == side_dim) n++;
163  return n;
164 }
165 
166 
168 {
169  return mesh_->element_accessor( mesh_->element.index(this) );
170 }
171 
172 
173 
175  return Region( region_idx_, mesh_->region_db());
176 }
177 
178 
179 unsigned int Element::id() const {
180  return mesh_->element.get_id(this);
181 }
182 
184  if (dim_==3) {
185  double sum_faces=0;
186  double face[4];
187  for(unsigned int i=0;i<4;i++) sum_faces+=( face[i]=side(i)->measure());
188 
189  double sum_pairs=0;
190  for(unsigned int i=0;i<3;i++)
191  for(unsigned int j=i+1;j<4;j++) {
192  unsigned int i_line = RefElement<3>::line_between_faces(i,j);
193  arma::vec line = *node[RefElement<3>::line_nodes[i_line][1]] - *node[RefElement<3>::line_nodes[i_line][0]];
194  sum_pairs += face[i]*face[j]*arma::dot(line, line);
195  }
196  double regular = (2.0*sqrt(2.0/3.0)/9.0); // regular tetrahedron
197  return fabs( measure()
198  * pow( sum_faces/sum_pairs, 3.0/4.0))/ regular;
199 
200  }
201  if (dim_==2) {
202  return fabs(
203  measure()/
204  pow(
205  arma::norm(*node[1] - *node[0], 2)
206  *arma::norm(*node[2] - *node[1], 2)
207  *arma::norm(*node[0] - *node[2], 2)
208  , 2.0/3.0)
209  ) / ( sqrt(3.0) / 4.0 ); // regular triangle
210  }
211  return 1.0;
212 }
213 
214 
215 void Element::get_bounding_box(BoundingBox &bounding_box) const
216 {
217  bounding_box = BoundingBox( this->node[0]->point() );
218 
219  for (unsigned int i=1; i<n_nodes(); i++)
220  bounding_box.expand( this->node[i]->point() );
221 }
222 
223 //-----------------------------------------------------------------------------
224 // vim: set cindent:
Bounding box in 3d ambient space.
Definition: bounding_box.hh:55
double measure() const
Definition: elements.cc:107
unsigned int n_nodes() const
#define FOR_ELEMENT_NODES(i, j)
Definition: elements.h:150
unsigned int * boundary_idx_
Definition: elements.h:94
int get_id(const T *it) const
Definition: sys_vector.hh:479
Definition: nodes.hh:44
int pid
Definition: elements.h:87
unsigned int * permutation_idx_
Definition: elements.h:103
static const unsigned int undef_idx
Definition: mesh.h:110
???
void expand(const Point &point)
Definition: mesh.h:108
#define FOR_ELEMENT_SIDES(i, j)
Definition: elements.h:151
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:179
const RegionDB & region_db() const
Definition: mesh.h:148
ElementAccessor< 3 > element_accessor(unsigned int idx, bool boundary=false)
Definition: mesh.cc:733
Element()
Definition: elements.cc:46
unsigned int dim() const
unsigned int * edge_idx_
Definition: elements.h:93
unsigned int dim() const
Definition: side_impl.hh:26
~Element()
Definition: elements.cc:93
Neighbour ** neigh_vb
Definition: elements.h:129
Region region() const
Definition: elements.cc:174
unsigned int n_sides() const
unsigned int index(const T *pointer) const
Definition: sys_vector.hh:394
void get_bounding_box(BoundingBox &bounding_box) const
Definition: elements.cc:215
SideIter side(const unsigned int loc_index)
unsigned int dim_
Definition: elements.h:138
void init(unsigned int dim, Mesh *mesh_in, RegionIdx reg)
Definition: elements.cc:72
Mesh * mesh_
Definition: elements.h:132
RegionIdx region_idx_
Definition: elements.h:137
arma::vec3 centre() const
Definition: elements.cc:138
unsigned int n_neighs_vb
Definition: elements.h:127
double quality_measure_smooth()
Definition: elements.cc:183
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:167
unsigned int n_sides_by_dim(unsigned int side_dim)
Definition: elements.cc:156
arma::vec3 & point()
Definition: nodes.hh:80
ElementVector element
Vector of elements of the mesh.
Definition: mesh.h:198