Flow123d  JS_before_hm-1801-ga009cfea3
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 "system/index_types.hh"
29 #include "mesh/region.hh" // for RegionIdx, Region
30 #include "system/asserts.hh" // for Assert, ASSERT
31 
32 class Mesh;
33 class Neighbour;
34 
35 
36 
37 //=============================================================================
38 // STRUCTURE OF THE ELEMENT OF THE MESH
39 //=============================================================================
40 class Element
41 {
42 public:
43  Element();
44  Element(unsigned int dim, RegionIdx reg);
45  void init(unsigned int dim, RegionIdx reg);
46  ~Element();
47 
48 
49  inline unsigned int dim() const;
50  inline unsigned int n_sides() const; // Number of sides
51  inline unsigned int n_nodes() const; // Number of nodes
52 
53  inline RegionIdx region_idx() const
54  { return region_idx_; }
55 
56  /// Return edge_idx of given index
57  inline unsigned int edge_idx(unsigned int edg_idx) const;
58 
59  /// Return permutation_idx of given index
60  inline unsigned int permutation_idx(unsigned int prm_idx) const;
61 
62  /// Return Id of mesh partition
63  inline int pid() const {
64  return pid_;
65  }
66 
67  /// Return number of neighbours
68  inline unsigned int n_neighs_vb() const {
69  return n_neighs_vb_;
70  }
71 
72  /// Return index (in Mesh::node_vec) of ni-th node.
73  inline unsigned int node_idx(unsigned int ni) const {
74  ASSERT_DBG(ni < n_nodes()).error("Node index is out of bound!");
75  ASSERT_DBG(nodes_[ni] != undef_idx);
76  return nodes_[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  * Indices of permutations of nodes on sides.
91  * It determines, in which order to take the nodes of the side so as to obtain
92  * the same order as on the reference side (side 0 on the particular edge).
93  *
94  * Permutations are defined in RefElement::side_permutations.
95  *
96  * TODO fix and remove mutable directive
97  */
99 
100  /// Inverted permutation of element nodes, negative Jacobian.
101  bool inverted;
102 
103 protected:
104  int pid_; ///< Id # of mesh partition
106  mutable unsigned int n_neighs_vb_; ///< # of neighbours, V-B type (comp.)
107  // only ngh from this element to higher dimension edge
108  // TODO fix and remove mutable directive
109 
110 
111 
112  // Data readed from mesh file
114  unsigned int dim_;
115 
116  /// indices to element's nodes
117  std::array<unsigned int, 4> nodes_;
118 
119  friend class Mesh;
120 
121  template<int spacedim, class Value>
122  friend class Field;
123 
124 };
125 
126 
127 inline unsigned int Element::dim() const {
128  return dim_;
129 }
130 
131 
132 inline unsigned int Element::n_nodes() const {
133  return dim()+1;
134 }
135 
136 
137 
138 inline unsigned int Element::n_sides() const {
139  return dim()+1;
140 }
141 
142 inline unsigned int Element::edge_idx(unsigned int edg_idx) const {
143  ASSERT(edg_idx<edge_idx_.size())(edg_idx)(edge_idx_.size()).error("Index of Edge is out of bound!");
144  return edge_idx_[edg_idx];
145 }
146 
147 inline unsigned int Element::permutation_idx(unsigned int prm_idx) const {
148  ASSERT(prm_idx<permutation_idx_.size())(prm_idx)(permutation_idx_.size()).error("Index of permutation is out of bound!");
149  return permutation_idx_[prm_idx];
150 }
151 
152 #endif
153 //-----------------------------------------------------------------------------
154 // vim: set cindent:
Element::n_neighs_vb
unsigned int n_neighs_vb() const
Return number of neighbours.
Definition: elements.h:68
Element::edge_idx_
std::vector< unsigned int > edge_idx_
Edges on sides.
Definition: elements.h:105
Element::inverted
bool inverted
Inverted permutation of element nodes, negative Jacobian.
Definition: elements.h:101
ASSERT
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:347
string.h
Element::dim
unsigned int dim() const
Definition: elements.h:127
asserts.hh
Definitions of ASSERTS.
Element::pid_
int pid_
Id # of mesh partition.
Definition: elements.h:104
ASSERT_DBG
#define ASSERT_DBG(expr)
Definition: include_fadbad.hh:28
std::vector< unsigned int >
Element::permutation_idx_
std::vector< unsigned int > permutation_idx_
Definition: elements.h:98
Neighbour
Definition: neighbours.h:117
index_types.hh
Element
Definition: elements.h:40
Element::~Element
~Element()
Definition: elements.cc:72
Element::dim_
unsigned int dim_
Definition: elements.h:114
undef_idx
const unsigned int undef_idx
Definition: index_types.hh:32
Element::n_neighs_vb_
unsigned int n_neighs_vb_
Definition: elements.h:106
Element::init
void init(unsigned int dim, RegionIdx reg)
Definition: elements.cc:53
Element::region_idx_
RegionIdx region_idx_
Definition: elements.h:113
Element::node_idx
unsigned int node_idx(unsigned int ni) const
Return index (in Mesh::node_vec) of ni-th node.
Definition: elements.h:73
Element::neigh_vb
Neighbour ** neigh_vb
Definition: elements.h:86
Element::nodes_
std::array< unsigned int, 4 > nodes_
indices to element's nodes
Definition: elements.h:117
Element::edge_idx
unsigned int edge_idx(unsigned int edg_idx) const
Return edge_idx of given index.
Definition: elements.h:142
Element::Element
Element()
Definition: elements.cc:35
Mesh
Definition: mesh.h:98
Element::n_sides
unsigned int n_sides() const
Definition: elements.h:138
Element::pid
int pid() const
Return Id of mesh partition.
Definition: elements.h:63
RegionIdx
Definition: region.hh:67
region.hh
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:95
Element::permutation_idx
unsigned int permutation_idx(unsigned int prm_idx) const
Return permutation_idx of given index.
Definition: elements.h:147
Element::region_idx
RegionIdx region_idx() const
Definition: elements.h:53
Element::boundary_idx_
unsigned int * boundary_idx_
Definition: elements.h:82
Element::n_nodes
unsigned int n_nodes() const
Definition: elements.h:132