PRAgMaTIc  master
Edge.h
Go to the documentation of this file.
1 /* Copyright (C) 2010 Imperial College London and others.
2  *
3  * Please see the AUTHORS file in the main source directory for a
4  * full list of copyright holders.
5  *
6  * Gerard Gorman
7  * Applied Modelling and Computation Group
8  * Department of Earth Science and Engineering
9  * Imperial College London
10  *
11  * g.gorman@imperial.ac.uk
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above
19  * copyright notice, this list of conditions and the following
20  * disclaimer in the documentation and/or other materials provided
21  * with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
30  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
32  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
34  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  */
37 
38 #ifndef H_EDGE
39 #define H_EDGE
40 
43 template<typename index_t> class Edge{
44  public:
49  Edge(index_t nid0, index_t nid1){
50  edge.first = std::min(nid0, nid1);
51  edge.second = std::max(nid0, nid1);
52  }
53 
57  Edge(const Edge& in){
58  *this = in;
59  }
60 
62  ~Edge(){}
63 
65  Edge& operator=(const Edge &in){
66  edge = in.edge;
67 
68  return *this;
69  }
70 
72  bool operator==(const Edge& in) const{
73  return this->edge == in.edge;
74  }
75 
77  bool operator!=(const Edge& in) const{
78  return this->edge != in.edge;
79  }
80 
82  bool operator<(const Edge& in) const{
83  return this->edge < in.edge;
84  }
85 
86  index_t connected(const Edge& in) const{
87  if((edge.first==in.edge.first)||(edge.first==in.edge.second))
88  return edge.first;
89  else if((edge.second==in.edge.first)||(edge.second==in.edge.second))
90  return edge.second;
91  return -1;
92  }
93 
94  bool contains(index_t nid) const{
95  return (nid==edge.first)||(nid==edge.second);
96  }
97 
98  template<typename _real_t> friend class Mesh;
99  template<typename _real_t, int _dim> friend class Coarsen;
100  template<typename _real_t, int _dim> friend class Swapping;
101  template<typename _real_t, int _dim> friend class Refine;
102 
103  private:
104 
105  std::pair<index_t, index_t> edge;
106 };
107 
108 template<typename index_t> class DirectedEdge{
109  public:
115  edge.first = nid0;
116  edge.second = nid1;
117  }
118 
120  edge.first = nid0;
121  edge.second = nid1;
122  id = nid;
123  }
124 
129  *this = in;
130  }
131 
132  // Default constructor.
134 
137 
140  edge = in.edge;
141  id = in.id;
142 
143  return *this;
144  }
145 
147  bool operator==(const DirectedEdge& in) const{
148  return this->edge == in.edge;
149  }
150 
152  bool operator!=(const DirectedEdge& in) const{
153  return this->edge != in.edge;
154  }
155 
157  bool operator<(const DirectedEdge& in) const{
158  return this->edge < in.edge;
159  }
160 
161  index_t connected(const DirectedEdge& in) const{
162  if((edge.first==in.edge.first)||(edge.first==in.edge.second))
163  return edge.first;
164  else if((edge.second==in.edge.first)||(edge.second==in.edge.second))
165  return edge.second;
166  return -1;
167  }
168 
169  bool contains(index_t nid) const{
170  return (nid==edge.first)||(nid==edge.second);
171  }
172 
173  template<typename _real_t> friend class Mesh;
174  template<typename _real_t, int _dim> friend class Coarsen;
175  template<typename _real_t, int _dim> friend class Swapping;
176  template<typename _real_t, int _dim> friend class Refine;
177 
178  private:
179  index_t id;
180  std::pair<index_t, index_t> edge;
181 };
182 
183 #endif
184 
DirectedEdge(const DirectedEdge &in)
Definition: Edge.h:128
DirectedEdge(index_t nid0, index_t nid1)
Definition: Edge.h:114
bool operator==(const Edge &in) const
Equality operator.
Definition: Edge.h:72
bool operator!=(const Edge &in) const
Inequality operator.
Definition: Edge.h:77
bool contains(index_t nid) const
Definition: Edge.h:169
Edge(const Edge &in)
Definition: Edge.h:57
Performs 2D mesh coarsening.
Definition: Coarsen.h:59
int index_t
~Edge()
Destructor.
Definition: Edge.h:62
Performs edge/face swapping.
Definition: Swapping.h:56
Manages mesh data.
Definition: Mesh.h:70
DirectedEdge()
Definition: Edge.h:133
bool operator!=(const DirectedEdge &in) const
Inequality operator.
Definition: Edge.h:152
Mesh edge object.
Definition: Edge.h:43
DirectedEdge(index_t nid0, index_t nid1, index_t nid)
Definition: Edge.h:119
bool contains(index_t nid) const
Definition: Edge.h:94
index_t connected(const Edge &in) const
Definition: Edge.h:86
index_t connected(const DirectedEdge &in) const
Definition: Edge.h:161
DirectedEdge & operator=(const DirectedEdge &in)
Assignment operator.
Definition: Edge.h:139
bool operator<(const DirectedEdge &in) const
Less-than operator.
Definition: Edge.h:157
bool operator==(const DirectedEdge &in) const
Equality operator.
Definition: Edge.h:147
bool operator<(const Edge &in) const
Less-than operator.
Definition: Edge.h:82
Edge & operator=(const Edge &in)
Assignment operator.
Definition: Edge.h:65
~DirectedEdge()
Destructor.
Definition: Edge.h:136
Edge(index_t nid0, index_t nid1)
Definition: Edge.h:49
Performs 2D mesh refinement.
Definition: Refine.h:56