Flow123d  release_3.0.0-904-gff06a57
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 #include "sides.h"
33 
34 class Mesh;
35 class Neighbour;
36 
37 
38 
39 //=============================================================================
40 // STRUCTURE OF THE ELEMENT OF THE MESH
41 //=============================================================================
42 class Element
43 {
44 public:
45  Element();
46  Element(unsigned int dim, RegionIdx reg);
47  void init(unsigned int dim, RegionIdx reg);
48  ~Element();
49 
50 
51  inline unsigned int dim() const;
52  inline unsigned int n_sides() const; // Number of sides
53  inline unsigned int n_nodes() const; // Number of nodes
54 
55  inline RegionIdx region_idx() const
56  { return region_idx_; }
57 
58  /// Return edge_idx of given index
59  inline unsigned int edge_idx(unsigned int edg_idx) const;
60 
61  /// Return permutation_idx of given index
62  inline unsigned int permutation_idx(unsigned int prm_idx) const;
63 
64  /// Return Id of mesh partition
65  inline int pid() const {
66  return pid_;
67  }
68 
69  /// Return number of neighbours
70  inline unsigned int n_neighs_vb() const {
71  return n_neighs_vb_;
72  }
73 
74  /// Return index (in Mesh::node_vec) of ni-th node.
75  inline unsigned int node_idx(unsigned int ni) const {
76  ASSERT(ni < n_nodes()).error("Node index is out of bound!");
77  return nodes_.at(ni);
78  }
79 
80 
81  // TODO move data members to protected part, add access trough getters or use direct access of friend class Mesh
82 
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  // TODO remove direct access in balance, side and transport
86 
87  Neighbour **neigh_vb; // List og neighbours, V-B type (comp.)
88  // TODO remove direct access in DarcyFlow, MhDofHandler, Mesh? Partitioning and Trabsport
89 
90 
91 protected:
92  int pid_; ///< Id # of mesh partition
93  std::vector<unsigned int> edge_idx_; ///< Edges on sides
94  mutable unsigned int n_neighs_vb_; ///< # of neighbours, V-B type (comp.)
95  // only ngh from this element to higher dimension edge
96  // TODO fix and remove mutable directive
97 
98  /**
99  * Indices of permutations of nodes on sides.
100  * It determines, in which order to take the nodes of the side so as to obtain
101  * the same order as on the reference side (side 0 on the particular edge).
102  *
103  * Permutations are defined in RefElement::side_permutations.
104  *
105  * TODO fix and remove mutable directive
106  */
108 
109  // Data readed from mesh file
111  unsigned int dim_;
112 
113  /// indices to element's nodes
114  std::array<unsigned int, 4> nodes_;
115 
116  friend class Mesh;
117 
118  template<int spacedim, class Value>
119  friend class Field;
120 
121 };
122 
123 
124 inline unsigned int Element::dim() const {
125  return dim_;
126 }
127 
128 
129 inline unsigned int Element::n_nodes() const {
130  return dim()+1;
131 }
132 
133 
134 
135 inline unsigned int Element::n_sides() const {
136  return dim()+1;
137 }
138 
139 inline unsigned int Element::edge_idx(unsigned int edg_idx) const {
140  ASSERT(edg_idx<edge_idx_.size())(edg_idx)(edge_idx_.size()).error("Index of Edge is out of bound!");
141  return edge_idx_[edg_idx];
142 }
143 
144 inline unsigned int Element::permutation_idx(unsigned int prm_idx) const {
145  ASSERT(prm_idx<permutation_idx_.size())(prm_idx)(permutation_idx_.size()).error("Index of permutation is out of bound!");
146  return permutation_idx_[prm_idx];
147 }
148 
149 #endif
150 //-----------------------------------------------------------------------------
151 // vim: set cindent:
unsigned int n_nodes() const
Definition: elements.h:129
std::array< unsigned int, 4 > nodes_
indices to element&#39;s nodes
Definition: elements.h:114
unsigned int * boundary_idx_
Definition: elements.h:83
Nodes of a mesh.
RegionIdx region_idx() const
Definition: elements.h:55
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:346
Element()
Definition: elements.cc:36
void init(unsigned int dim, RegionIdx reg)
Definition: elements.cc:53
unsigned int dim() const
Definition: elements.h:124
unsigned int node_idx(unsigned int ni) const
Return index (in Mesh::node_vec) of ni-th node.
Definition: elements.h:75
~Element()
Definition: elements.cc:71
Neighbour ** neigh_vb
Definition: elements.h:87
unsigned int edge_idx(unsigned int edg_idx) const
Return edge_idx of given index.
Definition: elements.h:139
unsigned int n_sides() const
Definition: elements.h:135
std::vector< unsigned int > edge_idx_
Edges on sides.
Definition: elements.h:93
int pid() const
Return Id of mesh partition.
Definition: elements.h:65
std::vector< unsigned int > permutation_idx_
Definition: elements.h:107
unsigned int dim_
Definition: elements.h:111
RegionIdx region_idx_
Definition: elements.h:110
int pid_
Id # of mesh partition.
Definition: elements.h:92
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:70
unsigned int n_neighs_vb_
of neighbours, V-B type (comp.)
Definition: elements.h:94
unsigned int permutation_idx(unsigned int prm_idx) const
Return permutation_idx of given index.
Definition: elements.h:144