Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Edge.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Edge.h
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Mesh manipulation objects.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NekMeshUtils_MESHELEMENTS_EDGE
37 #define NekMeshUtils_MESHELEMENTS_EDGE
38 
39 #include <iomanip>
40 
41 #include <SpatialDomains/SegGeom.h>
42 
46 
47 namespace Nektar
48 {
49 namespace NekMeshUtils
50 {
51 
52 class Element;
53 typedef boost::shared_ptr<Element> ElementSharedPtr;
54 
55 /**
56  * @brief Represents an edge which joins two points.
57  *
58  * An edge is defined by two nodes (vertices) and, for high-order edges,
59  * a set of control nodes defining the shape of the edge.
60  */
61 class Edge
62 {
63 public:
64  /// Creates a new edge.
66  NodeSharedPtr pVertex2,
67  std::vector<NodeSharedPtr> pEdgeNodes,
68  LibUtilities::PointsType pCurveType)
69  : m_n1(pVertex1), m_n2(pVertex2), m_edgeNodes(pEdgeNodes),
70  m_curveType(pCurveType), m_geom()
71  {
72 #ifdef NEKTAR_USE_MESHGEN
73  onCurve = false;
74 #endif
75  }
76 
77  /// Creates a new linear edge.
79  : m_n1(pVertex1), m_n2(pVertex2), m_edgeNodes(), m_curveType(), m_geom()
80  {
81 #ifdef NEKTAR_USE_MESHGEN
82  onCurve = false;
83 #endif
84  }
85 
86  /// Copies an existing edge.
88  : m_n1(pSrc.m_n1), m_n2(pSrc.m_n2), m_edgeNodes(pSrc.m_edgeNodes),
90  {
91  }
92 
94  {
95  }
96 
97  /// Returns the total number of nodes defining the edge.
98  NEKMESHUTILS_EXPORT unsigned int GetNodeCount() const
99  {
100  return m_edgeNodes.size() + 2;
101  }
102 
104  std::vector<NodeSharedPtr> &nodeList) const
105  {
106  nodeList.push_back(m_n1);
107  for (int k = 0; k < m_edgeNodes.size(); ++k)
108  {
109  nodeList.push_back(m_edgeNodes[k]);
110  }
111  nodeList.push_back(m_n2);
112  }
113 
114  /// Creates a Nektar++ string listing the coordinates of all the
115  /// nodes.
117  {
118  std::vector<NodeSharedPtr> nodeList;
119 
120  GetCurvedNodes(nodeList);
121 
122  std::stringstream s;
123  std::string str;
124 
125  // put them into a string and return
126  for (int k = 0; k < nodeList.size(); ++k)
127  {
128  s << std::scientific << std::setprecision(8) << " "
129  << nodeList[k]->m_x << " " << nodeList[k]->m_y << " "
130  << nodeList[k]->m_z << " ";
131  }
132 
133  return s.str();
134  }
135 
136  /// Generate a SpatialDomains::SegGeom object for this edge.
138  {
139  // Create edge vertices.
142 
143  p[0] = m_n1->GetGeom(coordDim);
144  p[1] = m_n2->GetGeom(coordDim);
145 
146  // Create a curve if high-order information exists.
147  if (m_edgeNodes.size() > 0)
148  {
151  m_id, m_curveType);
152 
153  c->m_points.push_back(p[0]);
154  for (int i = 0; i < m_edgeNodes.size(); ++i)
155  {
156  c->m_points.push_back(m_edgeNodes[i]->GetGeom(coordDim));
157  }
158  c->m_points.push_back(p[1]);
159 
161  m_id, coordDim, p, c);
162  }
163  else
164  {
166  m_id, coordDim, p);
167  }
168 
169  return ret;
170  }
171 
172  /// ID of edge.
173  unsigned int m_id;
174  /// First vertex node.
176  /// Second vertex node.
178  /// List of control nodes between the first and second vertices.
179  std::vector<NodeSharedPtr> m_edgeNodes;
180  /// Distributions of points along edge.
182  /// Element(s) which are linked to this edge.
183  vector<pair<ElementSharedPtr, int> > m_elLink;
184 
185 #ifdef NEKTAR_USE_MESHGEN
186  bool onCurve;
187  /// id of cad curve which edge lies on
188  int CADCurveId;
190 #endif
191 
192 private:
194 };
195 /// Shared pointer to an edge.
196 typedef boost::shared_ptr<Edge> EdgeSharedPtr;
197 
198 NEKMESHUTILS_EXPORT bool operator==(EdgeSharedPtr const &p1,
199  EdgeSharedPtr const &p2);
200 NEKMESHUTILS_EXPORT bool operator<(EdgeSharedPtr const &p1,
201  EdgeSharedPtr const &p2);
202 
203 /**
204  * @brief Defines a hash function for edges.
205  *
206  * The hash of an edge is defined using the IDs of the two nodes which
207  * define it. First the minimum ID is hashed, then the maximum
208  * ID, which takes the two possible orientations into account.
209  */
210 struct EdgeHash : std::unary_function<EdgeSharedPtr, std::size_t>
211 {
212  std::size_t operator()(EdgeSharedPtr const &p) const
213  {
214  std::size_t seed = 0;
215  unsigned int id1 = p->m_n1->m_id;
216  unsigned int id2 = p->m_n2->m_id;
217  boost::hash_combine(seed, id1 < id2 ? id1 : id2);
218  boost::hash_combine(seed, id2 < id1 ? id1 : id2);
219  return seed;
220  }
221 };
222 typedef boost::unordered_set<EdgeSharedPtr, EdgeHash> EdgeSet;
223 }
224 }
225 
226 #endif
bool operator<(NodeSharedPtr const &p1, NodeSharedPtr const &p2)
Defines ordering between two NodeSharedPtr objects.
NEKMESHUTILS_EXPORT Edge(NodeSharedPtr pVertex1, NodeSharedPtr pVertex2, std::vector< NodeSharedPtr > pEdgeNodes, LibUtilities::PointsType pCurveType)
Creates a new edge.
Definition: Edge.h:65
NEKMESHUTILS_EXPORT std::string GetXmlCurveString() const
Creates a Nektar++ string listing the coordinates of all the nodes.
Definition: Edge.h:116
class for CAD curves.
Definition: CADCurve.h:61
NodeSharedPtr m_n1
First vertex node.
Definition: Edge.h:175
Represents an edge which joins two points.
Definition: Edge.h:61
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
Defines a hash function for edges.
Definition: Edge.h:210
bool operator==(ElmtConfig const &c1, ElmtConfig const &c2)
boost::shared_ptr< Curve > CurveSharedPtr
Definition: Curve.hpp:62
std::vector< NodeSharedPtr > m_edgeNodes
List of control nodes between the first and second vertices.
Definition: Edge.h:179
NEKMESHUTILS_EXPORT unsigned int GetNodeCount() const
Returns the total number of nodes defining the edge.
Definition: Edge.h:98
unsigned int m_id
ID of edge.
Definition: Edge.h:173
std::size_t operator()(EdgeSharedPtr const &p) const
Definition: Edge.h:212
NEKMESHUTILS_EXPORT Edge(NodeSharedPtr pVertex1, NodeSharedPtr pVertex2)
Creates a new linear edge.
Definition: Edge.h:78
boost::shared_ptr< SegGeom > SegGeomSharedPtr
Definition: Geometry2D.h:60
NEKMESHUTILS_EXPORT SpatialDomains::SegGeomSharedPtr GetGeom(int coordDim)
Generate a SpatialDomains::SegGeom object for this edge.
Definition: Edge.h:137
NEKMESHUTILS_EXPORT void GetCurvedNodes(std::vector< NodeSharedPtr > &nodeList) const
Definition: Edge.h:103
LibUtilities::PointsType m_curveType
Distributions of points along edge.
Definition: Edge.h:181
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
NEKMESHUTILS_EXPORT ~Edge()
Definition: Edge.h:93
NodeSharedPtr m_n2
Second vertex node.
Definition: Edge.h:177
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:196
vector< pair< ElementSharedPtr, int > > m_elLink
Element(s) which are linked to this edge.
Definition: Edge.h:183
NEKMESHUTILS_EXPORT Edge(const Edge &pSrc)
Copies an existing edge.
Definition: Edge.h:87
#define NEKMESHUTILS_EXPORT
boost::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:52
boost::unordered_set< EdgeSharedPtr, EdgeHash > EdgeSet
Definition: Edge.h:222
SpatialDomains::SegGeomSharedPtr m_geom
Definition: Edge.h:193
boost::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:60
boost::shared_ptr< CADCurve > CADCurveSharedPtr
Definition: CADCurve.h:168
Base class for element definitions.
Definition: Element.h:115