Flow123d  JS_before_hm-1754-g1847fd3ed
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 Id of mesh partition
59  inline int pid() const {
60  return pid_;
61  }
62 
63  /// Return number of neighbours
64  inline unsigned int n_neighs_vb() const {
65  return n_neighs_vb_;
66  }
67 
68  /// Return index (in Mesh::node_vec) of ni-th node.
69  inline unsigned int node_idx(unsigned int ni) const {
70  ASSERT_DBG(ni < n_nodes()).error("Node index is out of bound!");
71  return nodes_[ni];
72  }
73 
74 
75  // TODO move data members to protected part, add access trough getters or use direct access of friend class Mesh
76 
77  unsigned int *boundary_idx_; // Possible boundaries on sides (REMOVE) all bcd assembly should be done through iterating over boundaries
78  // ?? deal.ii has this not only boundary iterators
79  // TODO remove direct access in balance, side and transport
80 
81  Neighbour **neigh_vb; // List og neighbours, V-B type (comp.)
82  // TODO remove direct access in DarcyFlow, MhDofHandler, Mesh? Partitioning and Trabsport
83 
84 protected:
85  int pid_; ///< Id # of mesh partition
86  std::vector<unsigned int> edge_idx_; ///< Edges on sides
87  mutable unsigned int n_neighs_vb_; ///< # of neighbours, V-B type (comp.)
88  // only ngh from this element to higher dimension edge
89  // TODO fix and remove mutable directive
90 
91 
92 
93  // Data readed from mesh file
95  unsigned int dim_;
96 
97  /// indices to element's nodes
98  std::array<unsigned int, 4> nodes_;
99 
100  friend class Mesh;
101 
102  template<int spacedim, class Value>
103  friend class Field;
104 
105 };
106 
107 
108 inline unsigned int Element::dim() const {
109  return dim_;
110 }
111 
112 
113 inline unsigned int Element::n_nodes() const {
114  return dim()+1;
115 }
116 
117 
118 
119 inline unsigned int Element::n_sides() const {
120  return dim()+1;
121 }
122 
123 inline unsigned int Element::edge_idx(unsigned int edg_idx) const {
124  ASSERT(edg_idx<edge_idx_.size())(edg_idx)(edge_idx_.size()).error("Index of Edge is out of bound!");
125  return edge_idx_[edg_idx];
126 }
127 
128 
129 #endif
130 //-----------------------------------------------------------------------------
131 // vim: set cindent:
Element::n_neighs_vb
unsigned int n_neighs_vb() const
Return number of neighbours.
Definition: elements.h:64
Element::edge_idx_
std::vector< unsigned int > edge_idx_
Edges on sides.
Definition: elements.h:86
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:108
asserts.hh
Definitions of ASSERTS.
Element::pid_
int pid_
Id # of mesh partition.
Definition: elements.h:85
ASSERT_DBG
#define ASSERT_DBG(expr)
Definition: include_fadbad.hh:28
std::vector< unsigned int >
Neighbour
Definition: neighbours.h:117
Element
Definition: elements.h:39
Element::~Element
~Element()
Definition: elements.cc:68
Element::dim_
unsigned int dim_
Definition: elements.h:95
Element::n_neighs_vb_
unsigned int n_neighs_vb_
Definition: elements.h:87
Element::init
void init(unsigned int dim, RegionIdx reg)
Definition: elements.cc:52
Element::region_idx_
RegionIdx region_idx_
Definition: elements.h:94
Element::node_idx
unsigned int node_idx(unsigned int ni) const
Return index (in Mesh::node_vec) of ni-th node.
Definition: elements.h:69
Element::neigh_vb
Neighbour ** neigh_vb
Definition: elements.h:81
Element::nodes_
std::array< unsigned int, 4 > nodes_
indices to element's nodes
Definition: elements.h:98
Element::edge_idx
unsigned int edge_idx(unsigned int edg_idx) const
Return edge_idx of given index.
Definition: elements.h:123
Element::Element
Element()
Definition: elements.cc:35
Mesh
Definition: mesh.h:77
Element::n_sides
unsigned int n_sides() const
Definition: elements.h:119
Element::pid
int pid() const
Return Id of mesh partition.
Definition: elements.h:59
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::region_idx
RegionIdx region_idx() const
Definition: elements.h:52
Element::boundary_idx_
unsigned int * boundary_idx_
Definition: elements.h:77
Element::n_nodes
unsigned int n_nodes() const
Definition: elements.h:113