Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 node object.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKMESHUTILS_MESHELEMENTS_NODE
37 #define NEKMESHUTILS_MESHELEMENTS_NODE
38 
40 
41 #include <iomanip>
42 
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  /// create an empty node
73  NEKMESHUTILS_EXPORT Node() : m_id(0), m_x(0.0), m_y(0.0), m_z(0.0), m_geom()
74  {
75  }
77  {
78  }
79 
80  /// Reset the local id;
81  NEKMESHUTILS_EXPORT void SetID(int pId)
82  {
83  m_id = pId;
84  }
85 
86  /// Get the local id;
88  {
89  return m_id;
90  }
91 
92  /// Define node ordering based on ID.
94  {
95  return (m_id < pSrc.m_id);
96  }
97  /// Define node equality based on coordinate.
99  {
100  return m_x == pSrc.m_x && m_y == pSrc.m_y && m_z == pSrc.m_z;
101  }
102 
104  {
105  return Node(m_id, m_x + pSrc.m_x, m_y + pSrc.m_y, m_z + pSrc.m_z);
106  }
107 
109  {
110  return Node(m_id, m_x - pSrc.m_x, m_y - pSrc.m_y, m_z - pSrc.m_z);
111  }
112 
114  {
115  return Node(m_id, m_x * pSrc.m_x, m_y * pSrc.m_y, m_z * pSrc.m_z);
116  }
117 
119  {
120  return Node(m_id, alpha * m_x, alpha * m_y, alpha * m_z);
121  }
122 
124  {
125  return Node(m_id, m_x / alpha, m_y / alpha, m_z / alpha);
126  }
127 
129  {
130  m_x += pSrc.m_x;
131  m_y += pSrc.m_y;
132  m_z += pSrc.m_z;
133  }
134 
136  {
137  m_x *= alpha;
138  m_y *= alpha;
139  m_z *= alpha;
140  }
141 
143  {
144  m_x /= alpha;
145  m_y /= alpha;
146  m_z /= alpha;
147  }
148 
149  NEKMESHUTILS_EXPORT NodeSharedPtr copy()
150  {
151  return boost::shared_ptr<Node>(new Node(m_id, m_x, m_y, m_z));
152  }
153 
155  {
156  return m_x * m_x + m_y * m_y + m_z * m_z;
157  }
158 
160  {
161  return m_x * pSrc.m_x + m_y * pSrc.m_y + m_z * pSrc.m_z;
162  }
163 
164  NEKMESHUTILS_EXPORT Node curl(const Node &pSrc) const
165  {
166  return Node(m_id, m_y * pSrc.m_z - m_z * pSrc.m_y,
167  m_z * pSrc.m_x - m_x * pSrc.m_z,
168  m_x * pSrc.m_y - m_y * pSrc.m_x);
169  }
170 
172  {
173  Array<OneD, NekDouble> out(3);
174  out[0] = m_x;
175  out[1] = m_y;
176  out[2] = m_z;
177  return out;
178  }
179 
180  /// Generate a %SpatialDomains::PointGeom for this node.
182  {
185  coordDim, m_id, m_x, m_y, m_z);
186 
187  return ret;
188  }
189 
191  {
192  return sqrt((m_x - p->m_x) * (m_x - p->m_x) +
193  (m_y - p->m_y) * (m_y - p->m_y) +
194  (m_z - p->m_z) * (m_z - p->m_z));
195  }
196 
197  NEKMESHUTILS_EXPORT NekDouble Angle(NodeSharedPtr &a, NodeSharedPtr &b)
198  {
199  Array<OneD, NekDouble> va(3), vb(3), cn(3);
200  va[0] = a->m_x - m_x;
201  va[1] = a->m_y - m_y;
202  va[2] = a->m_z - m_z;
203  vb[0] = b->m_x - m_x;
204  vb[1] = b->m_y - m_y;
205  vb[2] = b->m_z - m_z;
206 
207  NekDouble lva = sqrt(va[0] * va[0] + va[1] * va[1] + va[2] * va[2]);
208  NekDouble lvb = sqrt(vb[0] * vb[0] + vb[1] * vb[1] + vb[2] * vb[2]);
209 
210  NekDouble aw = 1.0 / (lva * lvb);
211 
212  NekDouble cosw = (va[0] * vb[0] + va[1] * vb[1] + va[2] * vb[2]) * aw;
213 
214  cn[0] = vb[1] * va[2] - vb[2] * va[1];
215  cn[1] = vb[2] * va[0] - vb[0] * va[2];
216  cn[2] = vb[0] * va[1] - vb[1] * va[0];
217 
218  NekDouble lcn = sqrt(cn[0] * cn[0] + cn[1] * cn[1] + cn[2] * cn[2]);
219 
220  NekDouble sinw = aw * lcn;
221 
222  NekDouble an = atan2(sinw, cosw);
223 
224  if (an < 0)
225  an += 6.2831853071796;
226 
227  return an;
228  }
229 
230  // functions for cad information
231 
233  {
234  CADCurveList[i] = std::pair<CADCurveSharedPtr, NekDouble>(c, t);
235  }
236 
238  {
239  CADSurfList[i] =
240  std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> >(s, uv);
241  }
242 
244  {
245  std::map<int, std::pair<CADCurveSharedPtr, NekDouble> >::iterator
246  search = CADCurveList.find(i);
247  ASSERTL0(search->first == i, "node not on this curve");
248 
249  return search->second.first;
250  }
251 
253  {
254  std::map<int, std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> > >::
255  iterator search = CADSurfList.find(i);
256  ASSERTL0(search->first == i, "surface not found");
257 
258  return search->second.first;
259  }
260 
262  {
263  std::map<int, std::pair<CADCurveSharedPtr, NekDouble> >::iterator
264  search = CADCurveList.find(i);
265  ASSERTL0(search->first == i, "node not on this curve");
266 
267  return search->second.second;
268  }
269 
271  {
272  std::map<int, std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> > >::
273  iterator search = CADSurfList.find(i);
274  ASSERTL0(search->first == i, "surface not found");
275 
276  return search->second.second;
277  }
278 
279  std::vector<std::pair<int, CADCurveSharedPtr> > GetCADCurves()
280  {
281  std::vector<std::pair<int, CADCurveSharedPtr> > lst;
282  std::map<int, std::pair<CADCurveSharedPtr, NekDouble> >::iterator c;
283  for (c = CADCurveList.begin(); c != CADCurveList.end(); c++)
284  {
285  lst.push_back(
286  std::pair<int, CADCurveSharedPtr>(c->first, c->second.first));
287  }
288  return lst;
289  }
290 
291  std::vector<std::pair<int, CADSurfSharedPtr> > GetCADSurfs()
292  {
293  std::vector<std::pair<int, CADSurfSharedPtr> > lst;
294  std::map<int, std::pair<CADSurfSharedPtr,
296  for (s = CADSurfList.begin(); s != CADSurfList.end(); s++)
297  {
298  lst.push_back(
299  std::pair<int, CADSurfSharedPtr>(s->first, s->second.first));
300  }
301  return lst;
302  }
303 
305  {
306  return CADCurveList.size();
307  }
308 
310  {
311  return CADSurfList.size();
312  }
313 
315  {
316  m_x = l[0];
317  m_y = l[1];
318  m_z = l[2];
319  CADSurfSharedPtr su = CADSurfList[s].first;
320  CADSurfList[s] =
321  std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> >(su, uv);
322  }
323 
325  {
326  m_x = l[0];
327  m_y = l[1];
328  m_z = l[2];
329  CADCurveSharedPtr cu = CADCurveList[s].first;
330  CADCurveList[s] = std::pair<CADCurveSharedPtr, NekDouble>(cu, t);
331  }
332 
333  std::vector<std::pair<int, std::string> > GetCADCurveInfoVector()
334  {
335  std::vector<std::pair<int, std::string> > ret;
336  std::map<int, std::pair<CADCurveSharedPtr, NekDouble> >::iterator c;
337  for (c = CADCurveList.begin(); c != CADCurveList.end(); c++)
338  {
339  std::stringstream ss;
340  ss << std::scientific << std::setprecision(8);
341  ss << c->second.second;
342  ret.push_back(std::pair<int, std::string>(c->first, ss.str()));
343  }
344  return ret;
345  }
346 
347  std::vector<std::pair<int, std::string> > GetCADSurfInfoVector()
348  {
349  std::vector<std::pair<int, std::string> > ret;
350  std::map<int, std::pair<CADSurfSharedPtr,
352  for (s = CADSurfList.begin(); s != CADSurfList.end(); s++)
353  {
354  std::stringstream ss;
355  ss << std::scientific << std::setprecision(8);
356  ss << s->second.second[0] << " " << s->second.second[1];
357  ret.push_back(std::pair<int, std::string>(s->first, ss.str()));
358  }
359  return ret;
360  }
361 
364  {
365  // calculates the angle between this node to a to this node to b
366  // Uses the CAD surface to orientate the angle
367  Array<OneD, NekDouble> A(3), B(3), CP(3);
368  A[0] = locA[0] - m_x;
369  A[1] = locA[1] - m_y;
370  A[2] = locA[2] - m_z;
371  B[0] = locB[0] - m_x;
372  B[1] = locB[1] - m_y;
373  B[2] = locB[2] - m_z;
374 
375  CP[0] = A[1] * B[2] - A[2] * B[1];
376  CP[1] = -1.0 * (A[0] * B[2] - A[2] * B[0]);
377  CP[2] = A[0] * B[1] - A[1] * B[0];
378 
379  NekDouble ang = sqrt(CP[0] * CP[0] + CP[1] * CP[1] + CP[2] * CP[2]);
380 
381  ang /= sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
382  ang /= sqrt(B[0] * B[0] + B[1] * B[1] + B[2] * B[2]);
383 
384  NekDouble dot = N[0] * CP[0] + N[1] * CP[1] + N[2] * CP[2];
385 
386  ang = asin(ang);
387 
388  if (dot < 0.0)
389  {
390  ang = 2.0 * M_PI - ang;
391  }
392 
393  return ang;
394  }
395 
396  /// ID of node.
397  int m_id;
398  /// X-coordinate.
400  /// Y-coordinate.
402  /// Z-coordinate.
404 
405  /// list of cadcurves the node lies on
406  std::map<int, std::pair<CADCurveSharedPtr, NekDouble> > CADCurveList;
407  /// list of cadsurfs the node lies on
408  std::map<int, std::pair<CADSurfSharedPtr, Array<OneD, NekDouble> > >
410 
411 private:
413 };
414 /// Shared pointer to a Node.
415 
416 NEKMESHUTILS_EXPORT bool operator==(NodeSharedPtr const &p1,
417  NodeSharedPtr const &p2);
418 NEKMESHUTILS_EXPORT bool operator<(NodeSharedPtr const &p1,
419  NodeSharedPtr const &p2);
420 NEKMESHUTILS_EXPORT bool operator!=(NodeSharedPtr const &p1,
421  NodeSharedPtr const &p2);
422 std::ostream &operator<<(std::ostream &os, const NodeSharedPtr &n);
423 
424 /**
425  * @brief Defines a hash function for nodes.
426  *
427  * The hash of a node is straight-forward; a combination of the x, y,
428  * and z co-ordinates in this order.
429  */
430 struct NodeHash : std::unary_function<NodeSharedPtr, std::size_t>
431 {
432  std::size_t operator()(NodeSharedPtr const &p) const
433  {
434  std::size_t seed = 0;
435  boost::hash_combine(seed, p->m_x);
436  boost::hash_combine(seed, p->m_y);
437  boost::hash_combine(seed, p->m_z);
438  return seed;
439  }
440 };
441 typedef boost::unordered_set<NodeSharedPtr, NodeHash> NodeSet;
442 }
443 }
444 
445 #endif
static NekDouble ang(NekDouble x, NekDouble y)
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:181
NEKMESHUTILS_EXPORT NekDouble dot(const Node &pSrc) const
Definition: Node.h:159
NEKMESHUTILS_EXPORT NekDouble Angle(NodeSharedPtr &a, NodeSharedPtr &b)
Definition: Node.h:197
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
void MoveCurve(Array< OneD, NekDouble > l, int s, NekDouble t)
Definition: Node.h:324
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
std::vector< std::pair< int, std::string > > GetCADSurfInfoVector()
Definition: Node.h:347
std::size_t operator()(NodeSharedPtr const &p) const
Definition: Node.h:432
NEKMESHUTILS_EXPORT bool operator<(const Node &pSrc)
Define node ordering based on ID.
Definition: Node.h:93
NEKMESHUTILS_EXPORT int GetID(void)
Get the local id;.
Definition: Node.h:87
NEKMESHUTILS_EXPORT ~Node()
Definition: Node.h:76
NEKMESHUTILS_EXPORT Node operator/(const NekDouble &alpha) const
Definition: Node.h:123
NekDouble m_y
Y-coordinate.
Definition: Node.h:401
NEKMESHUTILS_EXPORT void operator*=(const NekDouble &alpha)
Definition: Node.h:135
std::vector< std::pair< int, std::string > > GetCADCurveInfoVector()
Definition: Node.h:333
Defines a hash function for nodes.
Definition: Node.h:430
void Move(Array< OneD, NekDouble > l, int s, Array< OneD, NekDouble > uv)
Definition: Node.h:314
boost::unordered_set< NodeSharedPtr, NodeHash > NodeSet
Definition: Node.h:441
Represents a point in the domain.
Definition: Node.h:60
bool operator==(ElmtConfig const &c1, ElmtConfig const &c2)
Compares two element config structs.
NEKMESHUTILS_EXPORT Node operator*(const NekDouble &alpha) const
Definition: Node.h:118
NEKMESHUTILS_EXPORT NekDouble abs2() const
Definition: Node.h:154
void SetCADSurf(int i, CADSurfSharedPtr s, Array< OneD, NekDouble > uv)
Definition: Node.h:237
bool operator!=(NodeSharedPtr const &p1, NodeSharedPtr const &p2)
Compares two nodes for inequality based on IDs.
int m_id
ID of node.
Definition: Node.h:397
NEKMESHUTILS_EXPORT void operator/=(const NekDouble &alpha)
Definition: Node.h:142
NEKMESHUTILS_EXPORT void SetID(int pId)
Reset the local id;.
Definition: Node.h:81
CADCurveSharedPtr GetCADCurve(int i)
Definition: Node.h:243
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
NEKMESHUTILS_EXPORT Node curl(const Node &pSrc) const
Definition: Node.h:164
double NekDouble
NEKMESHUTILS_EXPORT NodeSharedPtr copy()
Definition: Node.h:149
NEKMESHUTILS_EXPORT Node operator+(const Node &pSrc) const
Definition: Node.h:103
NEKMESHUTILS_EXPORT bool operator==(const Node &pSrc)
Define node equality based on coordinate.
Definition: Node.h:98
NEKMESHUTILS_EXPORT Node()
Copy an existing node.
Definition: Node.h:73
NekDouble Angle(Array< OneD, NekDouble > locA, Array< OneD, NekDouble > locB, Array< OneD, NekDouble > N)
Definition: Node.h:362
std::map< int, std::pair< CADSurfSharedPtr, Array< OneD, NekDouble > > > CADSurfList
list of cadsurfs the node lies on
Definition: Node.h:409
std::ostream & operator<<(std::ostream &os, const NodeSharedPtr &n)
Print description of node to given ostream.
boost::shared_ptr< CADSurf > CADSurfSharedPtr
Definition: CADSurf.h:172
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
NEKMESHUTILS_EXPORT NekDouble Distance(NodeSharedPtr &p)
Definition: Node.h:190
NekDouble m_x
X-coordinate.
Definition: Node.h:399
std::map< int, std::pair< CADCurveSharedPtr, NekDouble > > CADCurveList
list of cadcurves the node lies on
Definition: Node.h:406
NEKMESHUTILS_EXPORT void operator+=(const Node &pSrc)
Definition: Node.h:128
#define NEKMESHUTILS_EXPORT
CADSurfSharedPtr GetCADSurf(int i)
Definition: Node.h:252
NekDouble GetCADCurveInfo(int i)
Definition: Node.h:261
std::vector< std::pair< int, CADCurveSharedPtr > > GetCADCurves()
Definition: Node.h:279
Array< OneD, NekDouble > GetCADSurfInfo(int i)
Definition: Node.h:270
NEKMESHUTILS_EXPORT Node operator*(const Node &pSrc) const
Definition: Node.h:113
NekDouble m_z
Z-coordinate.
Definition: Node.h:403
void SetCADCurve(int i, CADCurveSharedPtr c, NekDouble t)
Definition: Node.h:232
NEKMESHUTILS_EXPORT Node operator-(const Node &pSrc) const
Definition: Node.h:108
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:412
std::vector< std::pair< int, CADSurfSharedPtr > > GetCADSurfs()
Definition: Node.h:291
boost::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:60
NEKMESHUTILS_EXPORT Array< OneD, NekDouble > GetLoc()
Definition: Node.h:171
boost::shared_ptr< CADCurve > CADCurveSharedPtr
Definition: CADCurve.h:194