Flow123d  release_3.0.0-899-g9314a17
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);
46  double measure() const;
47  arma::vec3 centre() const; // Centre of side
48  arma::vec3 normal() const; // Vector of (generalized) normal
49 
50  /**
51  * Returns number of nodes of the side.
52  */
53  inline unsigned int n_nodes() const;
54 
55  /**
56  * Returns dimension of the side, that is dimension of the element minus one.
57  */
58  inline unsigned int dim() const;
59 
60  // returns true for all sides either on boundary or connected to vb neigboring
61  inline bool is_external() const;
62 
63  /**
64  * Returns node for given local index @p i on the side.
65  */
66  inline NodeAccessor<3> node(unsigned int i) const;
67 
68  /**
69  * Returns iterator to the element of the side.
70  */
71  inline ElementAccessor<3> element() const;
72 
73  /**
74  * Returns pointer to the mesh.
75  */
76  inline const Mesh * mesh() const;
77 
78  /**
79  * Returns global index of the edge connected to the side.
80  */
81  inline unsigned int edge_idx() const;
82 
83  /**
84  * Returns pointer to the edge connected to the side.
85  */
86  inline const Edge * edge() const;
87 
88  inline Boundary * cond() const;
89  inline unsigned int cond_idx() const;
90 
91  /**
92  * Returns local index of the side on the element.
93  */
94  inline unsigned int side_idx() const;
95 
96  /**
97  * Returns index of element in Mesh::element_vec_.
98  */
99  inline unsigned int elem_idx() const;
100 
101  /**
102  * Returns true if the side has assigned element.
103  */
104  inline bool valid() const;
105 
106  /**
107  * Iterate over local sides of the element.
108  */
109  inline void inc();
110 
111  /// This is necessary by current DofHandler, should change this
112  //inline void *make_ptr() const;
113 private:
114 
115  arma::vec3 normal_point() const;
116  arma::vec3 normal_line() const;
117  arma::vec3 normal_triangle() const;
118 
119  // Topology of the mesh
120 
121  const Mesh * mesh_; ///< Pointer to Mesh to which belonged
122  unsigned int elem_idx_; ///< Index of element in Mesh::element_vec_
123  unsigned int side_idx_; ///< Local # of side in element (to remove it, we heve to remove calc_side_rhs)
124 
125 };
126 
127 
128 /*
129  * Iterator to a side.
130  */
131 class SideIter {
132 public:
134  {}
135 
136  inline SideIter(const Side &side)
137  : side_(side)
138  {}
139 
140  inline bool operator==(const SideIter &other) {
141  return (side_.mesh() == other.side_.mesh() ) && ( side_.elem_idx() == other.side_.elem_idx() )
142  && ( side_.side_idx() == other.side_.side_idx() );
143  }
144 
145 
146  inline bool operator!=(const SideIter &other) {
147  return !( *this == other);
148  }
149 
150  /// * dereference operator
151  inline const Side & operator *() const
152  { return side_; }
153 
154  /// -> dereference operator
155  inline const Side * operator ->() const
156  { return &side_; }
157 
158  /// prefix increment iterate only on local element
159  inline SideIter &operator ++ () {
160  side_.inc();
161  return (*this);
162  }
163 
164 private:
166 };
167 #endif
168 //-----------------------------------------------------------------------------
169 // 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
Definition: sides.cc:121
Definition: mesh.h:80
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:165
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:122
unsigned int dim() const
Definition: side_impl.hh:38
arma::vec3 normal_triangle() const
Definition: sides.cc:106
SideIter()
Definition: sides.h:133
bool operator!=(const SideIter &other)
Definition: sides.h:146
Side()
Definition: sides.h:41
NodeAccessor< 3 > node(unsigned int i) const
Definition: side_impl.hh:47
double measure() const
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:123
unsigned int cond_idx() const
Definition: side_impl.hh:76
const Mesh * mesh_
Pointer to Mesh to which belonged.
Definition: sides.h:121
arma::vec3 normal() const
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:140
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:136