Flow123d  release_3.0.0-1094-g626f1a1
sides.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 sides.h
15  * @brief
16  */
17 
18 #ifndef SIDES_H
19 #define SIDES_H
20 
21 
22 #include <armadillo>
23 #include <stddef.h> // for NULL
24 //#include "mesh/mesh.h"
25 //#include "mesh/accessors.hh"
26 
27 class Boundary;
28 class Edge;
29 class Element;
30 template <int spacedim> class NodeAccessor;
31 template <int spacedim> class ElementAccessor;
32 
33 //=============================================================================
34 // STRUCTURE OF THE SIDE OF THE MESH
35 //=============================================================================
36 
37 class Mesh;
38 
39 class Side {
40 public:
41  Side()
42  : mesh_(NULL), elem_idx_(0), side_idx_(0)
43  {}
44 
45  inline Side(const Mesh * mesh, unsigned int elem_idx, unsigned int set_lnum); ///< Constructor
46  double measure() const; ///< Calculate metrics of the side
47  arma::vec3 centre() const; ///< Centre of side
48  arma::vec3 normal() const; ///< Vector of (generalized) normal
49  double diameter() const; ///< Calculate the side diameter.
50 
51  /**
52  * Returns number of nodes of the side.
53  */
54  inline unsigned int n_nodes() const;
55 
56  /**
57  * Returns dimension of the side, that is dimension of the element minus one.
58  */
59  inline unsigned int dim() const;
60 
61  // returns true for all sides either on boundary or connected to vb neigboring
62  inline bool is_external() const;
63 
64  /**
65  * Returns node for given local index @p i on the side.
66  */
67  inline NodeAccessor<3> node(unsigned int i) const;
68 
69  /**
70  * Returns iterator to the element of the side.
71  */
72  inline ElementAccessor<3> element() const;
73 
74  /**
75  * Returns pointer to the mesh.
76  */
77  inline const Mesh * mesh() const;
78 
79  /**
80  * Returns global index of the edge connected to the side.
81  */
82  inline unsigned int edge_idx() const;
83 
84  /**
85  * Returns pointer to the edge connected to the side.
86  */
87  inline const Edge * edge() const;
88 
89  inline Boundary * cond() const;
90  inline unsigned int cond_idx() const;
91 
92  /**
93  * Returns local index of the side on the element.
94  */
95  inline unsigned int side_idx() const;
96 
97  /**
98  * Returns index of element in Mesh::element_vec_.
99  */
100  inline unsigned int elem_idx() const;
101 
102  /**
103  * Returns true if the side has assigned element.
104  */
105  inline bool valid() const;
106 
107  /**
108  * Iterate over local sides of the element.
109  */
110  inline void inc();
111 
112  /// This is necessary by current DofHandler, should change this
113  //inline void *make_ptr() const;
114 private:
115 
116  arma::vec3 normal_point() const;
117  arma::vec3 normal_line() const;
118  arma::vec3 normal_triangle() const;
119 
120  // Topology of the mesh
121 
122  const Mesh * mesh_; ///< Pointer to Mesh to which belonged
123  unsigned int elem_idx_; ///< Index of element in Mesh::element_vec_
124  unsigned int side_idx_; ///< Local # of side in element (to remove it, we heve to remove calc_side_rhs)
125 
126 };
127 
128 
129 /*
130  * Iterator to a side.
131  */
132 class SideIter {
133 public:
135  {}
136 
137  inline SideIter(const Side &side)
138  : side_(side)
139  {}
140 
141  inline bool operator==(const SideIter &other) {
142  return (side_.mesh() == other.side_.mesh() ) && ( side_.elem_idx() == other.side_.elem_idx() )
143  && ( side_.side_idx() == other.side_.side_idx() );
144  }
145 
146 
147  inline bool operator!=(const SideIter &other) {
148  return !( *this == other);
149  }
150 
151  /// * dereference operator
152  inline const Side & operator *() const
153  { return side_; }
154 
155  /// -> dereference operator
156  inline const Side * operator ->() const
157  { return &side_; }
158 
159  /// prefix increment iterate only on local element
160  inline SideIter &operator ++ () {
161  side_.inc();
162  return (*this);
163  }
164 
165 private:
167 };
168 #endif
169 //-----------------------------------------------------------------------------
170 // vim: set cindent:
Definition: sides.h:39
const Edge * edge() const
Definition: side_impl.hh:66
unsigned int side_idx() const
Definition: side_impl.hh:82
unsigned int edge_idx() const
Definition: side_impl.hh:62
Boundary * cond() const
Definition: side_impl.hh:71
arma::vec3 normal_line() const
Definition: sides.cc:85
arma::vec3 centre() const
Centre of side.
Definition: sides.cc:121
Definition: mesh.h:76
Definition: edges.h:26
bool valid() const
Definition: side_impl.hh:92
ElementAccessor< 3 > element() const
Definition: side_impl.hh:53
arma::vec3 normal_point() const
This is necessary by current DofHandler, should change this.
Definition: sides.cc:69
Side side_
Definition: sides.h:166
UnitSI operator*(const UnitSI &a, const UnitSI &b)
Product of two units.
Definition: unit_si.cc:235
bool is_external() const
Definition: side_impl.hh:43
unsigned int elem_idx_
Index of element in Mesh::element_vec_.
Definition: sides.h:123
unsigned int dim() const
Definition: side_impl.hh:38
arma::vec3 normal_triangle() const
Definition: sides.cc:106
SideIter()
Definition: sides.h:134
bool operator!=(const SideIter &other)
Definition: sides.h:147
Side()
Definition: sides.h:41
NodeAccessor< 3 > node(unsigned int i) const
Definition: side_impl.hh:47
double measure() const
Calculate metrics of the side.
Definition: sides.cc:30
unsigned int side_idx_
Local # of side in element (to remove it, we heve to remove calc_side_rhs)
Definition: sides.h:124
double diameter() const
Calculate the side diameter.
Definition: sides.cc:137
unsigned int cond_idx() const
Definition: side_impl.hh:76
const Mesh * mesh_
Pointer to Mesh to which belonged.
Definition: sides.h:122
arma::vec3 normal() const
Vector of (generalized) normal.
Definition: sides.cc:53
unsigned int elem_idx() const
Definition: side_impl.hh:87
void inc()
Definition: side_impl.hh:97
bool operator==(const SideIter &other)
Definition: sides.h:141
const Mesh * mesh() const
Definition: side_impl.hh:58
unsigned int n_nodes() const
Definition: side_impl.hh:34
SideIter(const Side &side)
Definition: sides.h:137