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