Hermes2D  3.0
element.h
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef __H2D_ELEMENT_H
17 #define __H2D_ELEMENT_H
18 
19 #include "../global.h"
20 #include "curved.h"
21 #include "hash.h"
22 
23 namespace Hermes
24 {
25  namespace Hermes2D
26  {
27  class HashTable;
28 
29  enum
30  {
31  HERMES_TYPE_VERTEX = 0,
32  HERMES_TYPE_EDGE = 1
33  };
34 
35  class Element;
36 
45  struct HERMES_API Node
46  {
48  int id;
50  unsigned ref : 29;
52  unsigned type : 1;
54  unsigned bnd : 1;
56  unsigned used : 1;
57 
58  union
59  {
60  struct
61  {
63  double x, y;
64  };
65  struct
66  {
68  int marker;
70  Element* elem[2];
71  };
72  };
73 
75  int p1, p2;
78 
80  bool is_constrained_vertex() const;
81 
82  void ref_element(Element* e = nullptr);
83  void unref_element(HashTable* ht, Element* e = nullptr);
84  };
85 
107  class HERMES_API Element
108  {
109  public:
110  Element();
112  int id;
114  bool active;
116  bool used;
120  bool visited;
121 
125  void calc_area(bool precise_for_curvature = false);
126 
128  void calc_diameter();
129 
131  void get_center(double& x, double& y);
132 
135  union
136  {
141  };
142 
144  int marker;
145 
146  // returns the edge orientation. This works for the unconstrained edges.
147  bool get_edge_orientation(int ie) const;
148 
149  ElementMode2D get_mode() const {
150  return (nvert == 3) ? HERMES_MODE_TRIANGLE : HERMES_MODE_QUAD;
151  }
152 
153  inline bool is_triangle() const {
154  return nvert == 3;
155  }
156  inline bool is_quad() const {
157  return nvert == 4;
158  }
159  inline bool is_curved() const {
160  return cm != nullptr;
161  }
162  inline unsigned char get_nvert() const {
163  return this->nvert;
164  }
165 
166  inline bool is_parallelogram() const
167  {
168  if (this->nvert == 3)
169  return false;
170  else if (this->id == -1)
171  return true;
172 
173  const double eps = 1e-14;
174  return fabs(this->vn[2]->x - (this->vn[1]->x + this->vn[3]->x - this->vn[0]->x)) < eps &&
175  fabs(this->vn[2]->y - (this->vn[1]->y + this->vn[3]->y - this->vn[0]->y)) < eps;
176  }
177 
178  inline bool has_const_ref_map() const
179  {
180  return (this->nvert == 3 || is_parallelogram()) && (!this->cm);
181  }
182 
183  bool hsplit() const;
184  bool vsplit() const;
185  bool bsplit() const;
186 
190  double area;
191 
192  bool center_set;
193  double x_center, y_center;
194 
196  double diameter;
197 
199  unsigned short iro_cache;
200 
202  inline unsigned char next_vert(unsigned char i) const
203  {
204  return ((i + 1) % nvert);
205  }
206 
207  inline unsigned char prev_vert(unsigned char i) const
208  {
209  return ((i + nvert - 1) % nvert);
210  }
211 
214  Element* get_neighbor(int ie) const;
215 
217  void ref_all_nodes();
219  void unref_all_nodes(HashTable* ht);
220 
222  unsigned char nvert;
223  };
224 
225  static Node* get_edge_node();
226  static Node* get_vertex_node(Node* v1, Node* v2);
227 
228  const int TOP_LEVEL_REF = 123456;
229  }
230 }
231 #endif
double x
vertex node coordinates
Definition: element.h:63
int id
node id number
Definition: element.h:48
Definition: adapt.h:24
unsigned char next_vert(unsigned char i) const
Helper functions to obtain the index of the next or previous vertex/edge.
Definition: element.h:202
int marker
element marker
Definition: element.h:144
int id
element id number
Definition: element.h:112
Node * next_hash
next node in hash synonym list
Definition: element.h:77
Stores one element of a mesh.
Definition: element.h:107
bool visited
true if the element has been visited during assembling
Definition: element.h:120
CurvMap * cm
curved mapping, nullptr if not curvilinear
Definition: element.h:188
Stores one node of a mesh.
Definition: element.h:45
bool used
array item usage flag
Definition: element.h:116
unsigned char nvert
number of vertices (3 or 4)
Definition: element.h:222
::xsd::cxx::tree::type type
C++ type corresponding to the anyType XML Schema built-in type.
double area
Serves for saving the once calculated area of this element.
Definition: element.h:190
#define H2D_MAX_NUMBER_EDGES
A maximum number of edges of an element.
Definition: global.h:31
unsigned short iro_cache
Increase in integration order, see RefMap::calc_inv_ref_order()
Definition: element.h:199
#define H2D_MAX_NUMBER_VERTICES
A maximum number of vertices of an element.
Definition: global.h:32
int p1
parent id numbers
Definition: element.h:75
#define H2D_MAX_ELEMENT_SONS
Macros.
Definition: global.h:30
bool active
0 = active, no sons; 1 = inactive (refined), has sons
Definition: element.h:114
int marker
edge marker
Definition: element.h:68
double diameter
Serves for saving the once calculated diameter of this element.
Definition: element.h:196
Element * parent
pointer to the parent element for the current son
Definition: element.h:118
Stores and searches node tables.
Definition: hash.h:39