Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Node.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Node.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_NODE
37 #define NEKMESHUTILS_MESHELEMENTS_NODE
38 
40 
41 #ifdef NEKTAR_USE_MESHGEN
44 #endif
45 
46 namespace Nektar
47 {
48 namespace NekMeshUtils
49 {
50 class Node;
51 typedef boost::shared_ptr<Node> NodeSharedPtr;
52 
53 /**
54  * @brief Represents a point in the domain.
55  *
56  * Such points may either be element vertices, or simply control
57  * points on high-order edges/faces, although this information is not
58  * contained within this class.
59  */
60 class Node
61 {
62 public:
63  /// Create a new node at a specified coordinate.
65  : m_id(pId), m_x(pX), m_y(pY), m_z(pZ), m_geom()
66  {
67  }
68  /// Copy an existing node.
69  // Node(const Node& pSrc)
70  // : m_id(pSrc.m_id), m_x(pSrc.m_x), m_y(pSrc.m_y),
71  // m_z(pSrc.m_z), m_geom() {}
72  NEKMESHUTILS_EXPORT Node() : m_id(0), m_x(0.0), m_y(0.0), m_z(0.0), m_geom()
73  {
74  }
76  {
77  }
78 
79  /// Reset the local id;
80  NEKMESHUTILS_EXPORT void SetID(int pId)
81  {
82  m_id = pId;
83  }
84 
85  /// Get the local id;
87  {
88  return m_id;
89  }
90 
91  /// Define node ordering based on ID.
93  {
94  return (m_id < pSrc.m_id);
95  }
96  /// Define node equality based on coordinate.
98  {
99  return m_x == pSrc.m_x && m_y == pSrc.m_y && m_z == pSrc.m_z;
100  }
101 
103  {
104  return Node(m_id, m_x + pSrc.m_x, m_y + pSrc.m_y, m_z + pSrc.m_z);
105  }
106 
108  {
109  return Node(m_id, m_x - pSrc.m_x, m_y - pSrc.m_y, m_z - pSrc.m_z);
110  }
111 
113  {
114  return Node(m_id, m_x * pSrc.m_x, m_y * pSrc.m_y, m_z * pSrc.m_z);
115  }
116 
118  {
119  return Node(m_id, alpha * m_x, alpha * m_y, alpha * m_z);
120  }
121 
123  {
124  return Node(m_id, m_x / alpha, m_y / alpha, m_z / alpha);
125  }
126 
128  {
129  m_x += pSrc.m_x;
130  m_y += pSrc.m_y;
131  m_z += pSrc.m_z;
132  }
133 
135  {
136  m_x *= alpha;
137  m_y *= alpha;
138  m_z *= alpha;
139  }
140 
142  {
143  m_x /= alpha;
144  m_y /= alpha;
145  m_z /= alpha;
146  }
147 
149  {
150  return m_x * m_x + m_y * m_y + m_z * m_z;
151  }
152 
154  {
155  return m_x * pSrc.m_x + m_y * pSrc.m_y + m_z * pSrc.m_z;
156  }
157 
158  NEKMESHUTILS_EXPORT Node curl(const Node &pSrc) const
159  {
160  return Node(m_id,
161  m_y * pSrc.m_z - m_z * pSrc.m_y,
162  m_z * pSrc.m_x - m_x * pSrc.m_z,
163  m_x * pSrc.m_y - m_y * pSrc.m_x);
164  }
165 
167  {
168  Array<OneD, NekDouble> out(3);
169  out[0] = m_x;
170  out[1] = m_y;
171  out[2] = m_z;
172  return out;
173  }
174 
175  /// Generate a %SpatialDomains::PointGeom for this node.
177  {
180  coordDim, m_id, m_x, m_y, m_z);
181 
182  return ret;
183  }
184 
186  {
187  return sqrt((m_x - p->m_x) * (m_x - p->m_x) +
188  (m_y - p->m_y) * (m_y - p->m_y) +
189  (m_z - p->m_z) * (m_z - p->m_z));
190  }
191 
192  NEKMESHUTILS_EXPORT NekDouble Angle(NodeSharedPtr &a, NodeSharedPtr &b)
193  {
194  Array<OneD, NekDouble> va(3), vb(3), cn(3);
195  va[0] = a->m_x - m_x;
196  va[1] = a->m_y - m_y;
197  va[2] = a->m_z - m_z;
198  vb[0] = b->m_x - m_x;
199  vb[1] = b->m_y - m_y;
200  vb[2] = b->m_z - m_z;
201 
202  NekDouble lva = sqrt(va[0] * va[0] + va[1] * va[1] + va[2] * va[2]);
203  NekDouble lvb = sqrt(vb[0] * vb[0] + vb[1] * vb[1] + vb[2] * vb[2]);
204 
205  NekDouble aw = 1.0 / (lva * lvb);
206 
207  NekDouble cosw = (va[0] * vb[0] + va[1] * vb[1] + va[2] * vb[2]) * aw;
208 
209  cn[0] = vb[1] * va[2] - vb[2] * va[1];
210  cn[1] = vb[2] * va[0] - vb[0] * va[2];
211  cn[2] = vb[0] * va[1] - vb[1] * va[0];
212 
213  NekDouble lcn = sqrt(cn[0] * cn[0] + cn[1] * cn[1] + cn[2] * cn[2]);
214 
215  NekDouble sinw = aw * lcn;
216 
217  NekDouble an = atan2(sinw, cosw);
218 
219  if (an < 0)
220  an += 6.2831853071796;
221 
222  return an;
223  }
224 
225 #ifdef NEKTAR_USE_MESHGEN // fucntions for cad information
226 
227  void SetCADCurve(int i, CADCurveSharedPtr c, NekDouble t)
228  {
229  CADCurveList[i] = std::pair<CADCurveSharedPtr, NekDouble>(c, t);
230  }
231 
232  void SetCADSurf(int i, CADSurfSharedPtr s, Array<OneD, NekDouble> uv)
233  {
234  CADSurfList[i] =
235  std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> >(s, uv);
236  }
237 
238  CADCurveSharedPtr GetCADCurve(int i)
239  {
240  std::map<int, std::pair<CADCurveSharedPtr, NekDouble> >::iterator
241  search = CADCurveList.find(i);
242  ASSERTL0(search->first == i, "node not on this curve");
243 
244  return search->second.first;
245  }
246 
247  CADSurfSharedPtr GetCADSurf(int i)
248  {
249  std::map<int, std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> > >::
250  iterator search = CADSurfList.find(i);
251  ASSERTL0(search->first == i, "surface not found");
252 
253  return search->second.first;
254  }
255 
256  NekDouble GetCADCurveInfo(int i)
257  {
258  std::map<int, std::pair<CADCurveSharedPtr, NekDouble> >::iterator
259  search = CADCurveList.find(i);
260  ASSERTL0(search->first == i, "node not on this curve");
261 
262  return search->second.second;
263  }
264 
265  Array<OneD, NekDouble> GetCADSurfInfo(int i)
266  {
267  std::map<int, std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> > >::
268  iterator search = CADSurfList.find(i);
269  ASSERTL0(search->first == i, "surface not found");
270 
271  return search->second.second;
272  }
273 
274  std::vector<std::pair<int, CADSurfSharedPtr> > GetCADSurfs()
275  {
276  std::vector<std::pair<int, CADSurfSharedPtr> > lst;
277  std::map<int, std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> > >::
278  iterator s;
279  for (s = CADSurfList.begin(); s != CADSurfList.end(); s++)
280  {
281  lst.push_back(
282  std::pair<int, CADSurfSharedPtr>(s->first, s->second.first));
283  }
284  return lst;
285  }
286 
287  int GetNumCadCurve()
288  {
289  return CADCurveList.size();
290  }
291 
292  int GetNumCADSurf()
293  {
294  return CADSurfList.size();
295  }
296 
297  void Move(Array<OneD, NekDouble> l, int s, Array<OneD, NekDouble> uv)
298  {
299  m_x = l[0];
300  m_y = l[1];
301  m_z = l[2];
302  CADSurfSharedPtr su = CADSurfList[s].first;
303  CADSurfList[s] =
304  std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> >(su, uv);
305  }
306 
307 #endif
308 
309  /// ID of node.
310  int m_id;
311  /// X-coordinate.
313  /// Y-coordinate.
315  /// Z-coordinate.
317 
318 #ifdef NEKTAR_USE_MESHGEN // tag to tell the meshelemnets to include cad
319  // information
320  /// list of cadcurves the node lies on
321  std::map<int, std::pair<CADCurveSharedPtr, NekDouble> > CADCurveList;
322  /// list of cadsurfs the node lies on
323  std::map<int, std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> > >
324  CADSurfList;
325 #endif
326 
327 private:
329 };
330 /// Shared pointer to a Node.
331 
332 NEKMESHUTILS_EXPORT bool operator==(NodeSharedPtr const &p1,
333  NodeSharedPtr const &p2);
334 NEKMESHUTILS_EXPORT bool operator<(NodeSharedPtr const &p1,
335  NodeSharedPtr const &p2);
336 NEKMESHUTILS_EXPORT bool operator!=(NodeSharedPtr const &p1,
337  NodeSharedPtr const &p2);
338 std::ostream &operator<<(std::ostream &os, const NodeSharedPtr &n);
339 
340 /**
341  * @brief Defines a hash function for nodes.
342  *
343  * The hash of a node is straight-forward; a combination of the x, y,
344  * and z co-ordinates in this order.
345  */
346 struct NodeHash : std::unary_function<NodeSharedPtr, std::size_t>
347 {
348  std::size_t operator()(NodeSharedPtr const &p) const
349  {
350  std::size_t seed = 0;
351  boost::hash_combine(seed, p->m_x);
352  boost::hash_combine(seed, p->m_y);
353  boost::hash_combine(seed, p->m_z);
354  return seed;
355  }
356 };
357 typedef boost::unordered_set<NodeSharedPtr, NodeHash> NodeSet;
358 }
359 }
360 
361 #endif
bool operator<(NodeSharedPtr const &p1, NodeSharedPtr const &p2)
Defines ordering between two NodeSharedPtr objects.
NEKMESHUTILS_EXPORT SpatialDomains::PointGeomSharedPtr GetGeom(int coordDim)
Generate a SpatialDomains::PointGeom for this node.
Definition: Node.h:176
NEKMESHUTILS_EXPORT NekDouble dot(const Node &pSrc) const
Definition: Node.h:153
NEKMESHUTILS_EXPORT NekDouble Angle(NodeSharedPtr &a, NodeSharedPtr &b)
Definition: Node.h:192
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
std::size_t operator()(NodeSharedPtr const &p) const
Definition: Node.h:348
NEKMESHUTILS_EXPORT bool operator<(const Node &pSrc)
Define node ordering based on ID.
Definition: Node.h:92
NEKMESHUTILS_EXPORT int GetID(void)
Get the local id;.
Definition: Node.h:86
NEKMESHUTILS_EXPORT ~Node()
Definition: Node.h:75
NEKMESHUTILS_EXPORT Node operator/(const NekDouble &alpha) const
Definition: Node.h:122
NekDouble m_y
Y-coordinate.
Definition: Node.h:314
NEKMESHUTILS_EXPORT void operator*=(const NekDouble &alpha)
Definition: Node.h:134
Defines a hash function for nodes.
Definition: Node.h:346
boost::unordered_set< NodeSharedPtr, NodeHash > NodeSet
Definition: Node.h:357
Represents a point in the domain.
Definition: Node.h:60
bool operator==(ElmtConfig const &c1, ElmtConfig const &c2)
NEKMESHUTILS_EXPORT Node operator*(const NekDouble &alpha) const
Definition: Node.h:117
NEKMESHUTILS_EXPORT NekDouble abs2() const
Definition: Node.h:148
bool operator!=(NodeSharedPtr const &p1, NodeSharedPtr const &p2)
int m_id
ID of node.
Definition: Node.h:310
NEKMESHUTILS_EXPORT void operator/=(const NekDouble &alpha)
Definition: Node.h:141
NEKMESHUTILS_EXPORT void SetID(int pId)
Reset the local id;.
Definition: Node.h:80
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
NEKMESHUTILS_EXPORT Node curl(const Node &pSrc) const
Definition: Node.h:158
double NekDouble
NEKMESHUTILS_EXPORT Node operator+(const Node &pSrc) const
Definition: Node.h:102
NEKMESHUTILS_EXPORT bool operator==(const Node &pSrc)
Define node equality based on coordinate.
Definition: Node.h:97
NEKMESHUTILS_EXPORT Node()
Copy an existing node.
Definition: Node.h:72
std::ostream & operator<<(std::ostream &os, const NodeSharedPtr &n)
boost::shared_ptr< CADSurf > CADSurfSharedPtr
Definition: CADSurf.h:217
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
NEKMESHUTILS_EXPORT NekDouble Distance(NodeSharedPtr &p)
Definition: Node.h:185
NekDouble m_x
X-coordinate.
Definition: Node.h:312
NEKMESHUTILS_EXPORT void operator+=(const Node &pSrc)
Definition: Node.h:127
#define NEKMESHUTILS_EXPORT
NEKMESHUTILS_EXPORT Node operator*(const Node &pSrc) const
Definition: Node.h:112
NekDouble m_z
Z-coordinate.
Definition: Node.h:316
NEKMESHUTILS_EXPORT Node operator-(const Node &pSrc) const
Definition: Node.h:107
NEKMESHUTILS_EXPORT Node(int pId, NekDouble pX, NekDouble pY, NekDouble pZ)
Create a new node at a specified coordinate.
Definition: Node.h:64
SpatialDomains::PointGeomSharedPtr m_geom
Definition: Node.h:328
boost::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:60
NEKMESHUTILS_EXPORT Array< OneD, NekDouble > GetLoc()
Definition: Node.h:166
boost::shared_ptr< CADCurve > CADCurveSharedPtr
Definition: CADCurve.h:168