Flow123d  JS_before_hm-62-ge56f9d5
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 <ext/alloc_traits.h> // for __alloc_traits<>::valu...
22 #include <string.h> // for memcpy
23 #include <new> // for operator new[]
24 #include <ostream> // for operator<<
25 #include <string> // for operator<<
26 #include <vector> // for vector
27 #include <armadillo>
28 #include "mesh/nodes.hh" // for Node
29 #include "mesh/ref_element.hh" // for RefElement
30 #include "mesh/region.hh" // for RegionIdx, Region
31 #include "system/asserts.hh" // for Assert, ASSERT
32 
33 class Mesh;
34 class Neighbour;
35 
36 
37 
38 //=============================================================================
39 // STRUCTURE OF THE ELEMENT OF THE MESH
40 //=============================================================================
41 class Element
42 {
43 public:
44  Element();
45  Element(unsigned int dim, RegionIdx reg);
46  void init(unsigned int dim, RegionIdx reg);
47  ~Element();
48 
49 
50  inline unsigned int dim() const;
51  inline unsigned int n_sides() const; // Number of sides
52  inline unsigned int n_nodes() const; // Number of nodes
53 
54  inline RegionIdx region_idx() const
55  { return region_idx_; }
56 
57  /// Return edge_idx of given index
58  inline unsigned int edge_idx(unsigned int edg_idx) const;
59 
60  /// Return permutation_idx of given index
61  inline unsigned int permutation_idx(unsigned int prm_idx) const;
62 
63  /// Return Id of mesh partition
64  inline int pid() const {
65  return pid_;
66  }
67 
68  /// Return number of neighbours
69  inline unsigned int n_neighs_vb() const {
70  return n_neighs_vb_;
71  }
72 
73  /// Return index (in Mesh::node_vec) of ni-th node.
74  inline unsigned int node_idx(unsigned int ni) const {
75  ASSERT(ni < n_nodes()).error("Node index is out of bound!");
76  return nodes_.at(ni);
77  }
78 
79 
80  // TODO move data members to protected part, add access trough getters or use direct access of friend class Mesh
81 
82  unsigned int *boundary_idx_; // Possible boundaries on sides (REMOVE) all bcd assembly should be done through iterating over boundaries
83  // ?? deal.ii has this not only boundary iterators
84  // TODO remove direct access in balance, side and transport
85 
86  Neighbour **neigh_vb; // List og neighbours, V-B type (comp.)
87  // TODO remove direct access in DarcyFlow, MhDofHandler, Mesh? Partitioning and Trabsport
88 
89 
90 protected:
91  int pid_; ///< Id # of mesh partition
92  std::vector<unsigned int> edge_idx_; ///< Edges on sides
93  mutable unsigned int n_neighs_vb_; ///< # of neighbours, V-B type (comp.)
94  // only ngh from this element to higher dimension edge
95  // TODO fix and remove mutable directive
96 
97  /**
98  * Indices of permutations of nodes on sides.
99  * It determines, in which order to take the nodes of the side so as to obtain
100  * the same order as on the reference side (side 0 on the particular edge).
101  *
102  * Permutations are defined in RefElement::side_permutations.
103  *
104  * TODO fix and remove mutable directive
105  */
107 
108  // Data readed from mesh file
110  unsigned int dim_;
111 
112  /// indices to element's nodes
113  std::array<unsigned int, 4> nodes_;
114 
115  friend class Mesh;
116 
117  template<int spacedim, class Value>
118  friend class Field;
119 
120 };
121 
122 
123 inline unsigned int Element::dim() const {
124  return dim_;
125 }
126 
127 
128 inline unsigned int Element::n_nodes() const {
129  return dim()+1;
130 }
131 
132 
133 
134 inline unsigned int Element::n_sides() const {
135  return dim()+1;
136 }
137 
138 inline unsigned int Element::edge_idx(unsigned int edg_idx) const {
139  ASSERT(edg_idx<edge_idx_.size())(edg_idx)(edge_idx_.size()).error("Index of Edge is out of bound!");
140  return edge_idx_[edg_idx];
141 }
142 
143 inline unsigned int Element::permutation_idx(unsigned int prm_idx) const {
144  ASSERT(prm_idx<permutation_idx_.size())(prm_idx)(permutation_idx_.size()).error("Index of permutation is out of bound!");
145  return permutation_idx_[prm_idx];
146 }
147 
148 #endif
149 //-----------------------------------------------------------------------------
150 // vim: set cindent:
unsigned int n_nodes() const
Definition: elements.h:128
std::array< unsigned int, 4 > nodes_
indices to element&#39;s nodes
Definition: elements.h:113
unsigned int * boundary_idx_
Definition: elements.h:82
Nodes of a mesh.
RegionIdx region_idx() const
Definition: elements.h:54
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:83
Definitions of ASSERTS.
Definition: mesh.h:76
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
Element()
Definition: elements.cc:35
void init(unsigned int dim, RegionIdx reg)
Definition: elements.cc:52
unsigned int dim() const
Definition: elements.h:123
unsigned int node_idx(unsigned int ni) const
Return index (in Mesh::node_vec) of ni-th node.
Definition: elements.h:74
~Element()
Definition: elements.cc:70
Neighbour ** neigh_vb
Definition: elements.h:86
unsigned int edge_idx(unsigned int edg_idx) const
Return edge_idx of given index.
Definition: elements.h:138
unsigned int n_sides() const
Definition: elements.h:134
std::vector< unsigned int > edge_idx_
Edges on sides.
Definition: elements.h:92
int pid() const
Return Id of mesh partition.
Definition: elements.h:64
std::vector< unsigned int > permutation_idx_
Definition: elements.h:106
unsigned int dim_
Definition: elements.h:110
RegionIdx region_idx_
Definition: elements.h:109
int pid_
Id # of mesh partition.
Definition: elements.h:91
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...
unsigned int n_neighs_vb() const
Return number of neighbours.
Definition: elements.h:69
unsigned int n_neighs_vb_
of neighbours, V-B type (comp.)
Definition: elements.h:93
unsigned int permutation_idx(unsigned int prm_idx) const
Return permutation_idx of given index.
Definition: elements.h:143