Flow123d  release_2.2.0-19-g1279b7e
elements.h
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.h
15  * @brief
16  */
17 
18 #ifndef ELEMENTS_H
19 #define ELEMENTS_H
20 
21 #include "mesh/nodes.hh"
22 #include "mesh/region.hh"
23 #include "mesh/bounding_box.hh"
24 #include "mesh/ref_element.hh"
25 
26 template <int spacedim>
27 class ElementAccessor;
28 
29 class Mesh;
30 class Side;
31 class SideIter;
32 class Neighbour;
33 
34 
35 
36 //=============================================================================
37 // STRUCTURE OF THE ELEMENT OF THE MESH
38 //=============================================================================
39 class Element
40 {
41 public:
42  Element();
43  Element(unsigned int dim, Mesh *mesh_in, RegionIdx reg);
44  void init(unsigned int dim, Mesh *mesh_in, RegionIdx reg);
45  ~Element();
46 
47 
48  inline unsigned int dim() const;
49  inline unsigned int index() const;
50  unsigned int n_sides() const; // Number of sides
51  unsigned int n_nodes() const; // Number of nodes
52 
53  ///Gets ElementAccessor of this element
55 
56  double measure() const;
57  arma::vec3 centre() const;
58  /**
59  * Quality of the element based on the smooth and scale-invariant quality measures proposed in:
60  * J. R. Schewchuk: What is a Good Linear Element?
61  *
62  * We scale the measure so that is gives value 1 for regular elements. Line 1d elements
63  * have always quality 1.
64  */
65  double quality_measure_smooth();
66 
67  unsigned int n_sides_by_dim(unsigned int side_dim);
68  inline SideIter side(const unsigned int loc_index);
69  inline const SideIter side(const unsigned int loc_index) const;
70  Region region() const;
71  inline RegionIdx region_idx() const
72  { return region_idx_; }
73 
74  unsigned int id() const;
75 
76  int pid; // Id # of mesh partition
77 
78  // Type specific data
79  Node** node; // Element's nodes
80 
81 
82  unsigned int *edge_idx_; // Edges on sides
83  unsigned int *boundary_idx_; // Possible boundaries on sides (REMOVE) all bcd assembly should be done through iterating over boundaries
84  // ?? deal.ii has this not only boundary iterators
85  /**
86  * Indices of permutations of nodes on sides.
87  * It determines, in which order to take the nodes of the side so as to obtain
88  * the same order as on the reference side (side 0 on the particular edge).
89  *
90  * Permutations are defined in RefElement::side_permutations.
91  */
92  unsigned int *permutation_idx_;
93 
94  /**
95  * Computes bounding box of element (OBSOLETE)
96  */
98 
99  /**
100  * Return bounding box of the element.
101  */
103  return BoundingBox(this->vertex_list());
104  }
105 
106  /**
107  * Map from reference element to global coord system.
108  * Matrix(3, dim()+1), last column is the translation vector.
109  *
110  * Temporary, this should be provided be a separate finite element mapping class.
111  */
112  inline arma::mat element_map() const
113  {
114  arma::vec3 &v0 = node[0]->point();
115  arma::mat A(3, dim()+1);
116 
117  for(unsigned int i=0; i < dim(); i++ ) {
118  A.col(i) = node[i+1]->point() - v0;
119  }
120  A.col(dim()) = v0;
121  return A;
122  }
123 
124  /**
125  * Project given point to the barycentic coordinates.
126  * Result vector have dimension dim()+1. Local coordinates are the first.
127  * Last is 1-...
128  */
129  arma::vec project_point(const arma::vec3 &point, const arma::mat &map) const;
130 
131 
132  /**
133  * Project a point and create the map as well.
134  */
135  inline arma::vec project_point(const arma::vec3 &point) {
136  return project_point(point, this->element_map() );
137  }
138 
139  /**
140  * Clip a point given by barycentric cocordinates to the element.
141  * If the point is out of the element the closest point
142  * projection to the element surface is used.
143  */
144  inline arma::vec clip_to_element(arma::vec &barycentric) {
145  switch (dim()) {
146  case 1: return RefElement<1>::clip(barycentric);
147  case 2: return RefElement<2>::clip(barycentric);
148  case 3: return RefElement<3>::clip(barycentric);
149  default: ASSERT(false).error("Clipping supported only for dim=1,2,3.");
150  }
151  return barycentric; // should never happen
152  }
153 
154  /**
155  * Return list of element vertices.
156  */
158  vector<arma::vec3> vertices(this->n_nodes());
159  for(unsigned int i=0; i<n_nodes(); i++) vertices[i]=node[i]->point();
160  return vertices;
161  }
162 
163 
164  unsigned int n_neighs_vb; // # of neighbours, V-B type (comp.)
165  // only ngh from this element to higher dimension edge
166  Neighbour **neigh_vb; // List og neighbours, V-B type (comp.)
167 
168 
169  Mesh *mesh_; // should be removed as soon as the element is also an Accessor
170 
171 
172 protected:
173  // Data readed from mesh file
175  unsigned int dim_;
176 
177  friend class Mesh;
178 
179  template<int spacedim, class Value>
180  friend class Field;
181 
182 };
183 
184 
185 
186 
187 #define FOR_ELEMENT_NODES(i,j) for((j)=0;(j)<(i)->n_nodes();(j)++)
188 #define FOR_ELEMENT_SIDES(i,j) for(unsigned int j=0; j < (i)->n_sides(); j++)
189 #define FOR_ELM_NEIGHS_VB(i,j) for((j)=0;(j)<(i)->n_neighs_vb;(j)++)
190 
191 
192 #endif
193 //-----------------------------------------------------------------------------
194 // vim: set cindent:
195 
Definition: sides.h:31
arma::vec project_point(const arma::vec3 &point)
Definition: elements.h:135
arma::vec project_point(const arma::vec3 &point, const arma::mat &map) const
Definition: elements.cc:205
Bounding box in 3d ambient space.
Definition: bounding_box.hh:45
double measure() const
Definition: elements.cc:89
unsigned int n_nodes() const
unsigned int * boundary_idx_
Definition: elements.h:83
Definition: nodes.hh:32
Nodes of a mesh.
int pid
Definition: elements.h:76
unsigned int * permutation_idx_
Definition: elements.h:92
arma::mat element_map() const
Definition: elements.h:112
RegionIdx region_idx() const
Definition: elements.h:71
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:62
unsigned int index() const
Definition: mesh.h:97
Node ** node
Definition: elements.h:79
unsigned int id() const
Definition: elements.cc:160
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:346
Element()
Definition: elements.cc:34
arma::vec clip_to_element(arma::vec &barycentric)
Definition: elements.h:144
unsigned int dim() const
unsigned int * edge_idx_
Definition: elements.h:82
~Element()
Definition: elements.cc:80
Neighbour ** neigh_vb
Definition: elements.h:166
Region region() const
Definition: elements.cc:155
unsigned int n_sides() const
vector< arma::vec3 > vertex_list()
Definition: elements.h:157
void get_bounding_box(BoundingBox &bounding_box) const
Definition: elements.cc:196
SideIter side(const unsigned int loc_index)
unsigned int dim_
Definition: elements.h:175
void init(unsigned int dim, Mesh *mesh_in, RegionIdx reg)
Definition: elements.cc:60
Mesh * mesh_
Definition: elements.h:169
RegionIdx region_idx_
Definition: elements.h:174
arma::vec3 centre() const
Definition: elements.cc:120
unsigned int n_neighs_vb
Definition: elements.h:164
double quality_measure_smooth()
Definition: elements.cc:164
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:148
unsigned int n_sides_by_dim(unsigned int side_dim)
Definition: elements.cc:137
static BaryPoint clip(const BaryPoint &barycentric)
Definition: ref_element.cc:243
arma::vec3 & point()
Definition: nodes.hh:68
BoundingBox bounding_box()
Definition: elements.h:102