Nektar++
PointGeom.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: PointGeom.cpp
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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Point geometry information
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <fstream>
36 
39 #include <SpatialDomains/SegGeom.h>
40 
41 namespace Nektar
42 {
43 namespace SpatialDomains
44 {
46 {
48  m_coordim = 0;
49  m_globalID = 0;
50 }
51 
53  const int coordim, const int vid, NekDouble x, NekDouble y, NekDouble z)
54  : NekPoint<NekDouble>(x, y, z)
55 {
57  m_coordim = coordim;
58  m_globalID = vid;
59 }
60 
61 // copy constructor
63  : Geometry0D(T),
64  NekPoint<NekDouble>(T),
65  std::enable_shared_from_this<PointGeom>(T)
66 {
69  m_coordim = T.m_coordim;
70 }
71 
73 {
74 }
75 
77 {
78  switch (m_coordim)
79  {
80  case 3:
81  z = (*this)(2);
82  /* Falls through. */
83  case 2:
84  y = (*this)(1);
85  /* Falls through. */
86  case 1:
87  x = (*this)(0);
88  break;
89  }
90 }
91 
93 {
94  switch (m_coordim)
95  {
96  case 3:
97  coords[2] = (*this)(2);
98  /* Falls through. */
99  case 2:
100  coords[1] = (*this)(1);
101  /* Falls through. */
102  case 1:
103  coords[0] = (*this)(0);
104  break;
105  }
106 }
107 
109 {
110  (*this)(0) = x;
111  (*this)(1) = y;
112  (*this)(2) = z;
113 }
114 
115 // _this = a + b
117 {
118  (*this)(0) = a[0] + b[0];
119  (*this)(1) = a[1] + b[1];
120  (*this)(2) = a[2] + b[2];
121  m_coordim = std::max(a.GetCoordim(), b.GetCoordim());
122 }
123 
124 // _this = a + b
126 {
127  (*this)(0) = a[0] - b[0];
128  (*this)(1) = a[1] - b[1];
129  (*this)(2) = a[2] - b[2];
130  m_coordim = std::max(a.GetCoordim(), b.GetCoordim());
131 }
132 
133 /// \brief _this = a x b
135 {
136  (*this)(0) = a[1] * b[2] - a[2] * b[1];
137  (*this)(1) = a[2] * b[0] - a[0] * b[2];
138  (*this)(2) = a[0] * b[1] - a[1] * b[0];
139  m_coordim = 3;
140 }
141 
142 /// \brief _this = rotation of a by angle 'angle' around axis dir
143 void PointGeom::Rotate(PointGeom& a, int dir, NekDouble angle)
144 {
145  switch(dir)
146  {
147  case 0:
148  {
149  NekDouble yrot = cos(angle)*a.y() - sin(angle)*a.z();
150  NekDouble zrot = sin(angle)*a.y() + cos(angle)*a.z();
151 
152  (*this)(0) = a.x();
153  (*this)(1) = yrot;
154  (*this)(2) = zrot;
155  }
156  break;
157  case 1:
158  {
159  NekDouble zrot = cos(angle)*a.z() - sin(angle)*a.x();
160  NekDouble xrot = sin(angle)*a.z() + cos(angle)*a.x();
161 
162  (*this)(0) = xrot;
163  (*this)(1) = a.y();
164  (*this)(2) = zrot;
165  }
166  break;
167  case 2:
168  {
169  NekDouble xrot = cos(angle)*a.x() - sin(angle)*a.y();
170  NekDouble yrot = sin(angle)*a.x() + cos(angle)*a.y();
171 
172  (*this)(0) = xrot;
173  (*this)(1) = yrot;
174  (*this)(2) = a.z();
175  }
176  break;
177  }
178 }
179 
180 /// \brief return distance between this and input a
182 {
183  return sqrt((x() - a.x()) * (x() - a.x()) + (y() - a.y()) * (y() - a.y()) +
184  (z() - a.z()) * (z() - a.z()));
185 }
186 
187 /// \brief retun the dot product between this and input a
189 {
190  return (x() * a.x() + y() * a.y() + z() * a.z());
191 }
192 
193 /// Determine equivalence by the ids. No matter what the position,
194 /// if the ids are the same, then they are equivalent, and vice versa.
195 bool operator==(const PointGeom &x, const PointGeom &y)
196 {
197  return (x.m_globalID == y.m_globalID);
198 }
199 
200 bool operator==(const PointGeom &x, const PointGeom *y)
201 {
202  return (x.m_globalID == y->m_globalID);
203 }
204 
205 bool operator==(const PointGeom *x, const PointGeom &y)
206 {
207  return (x->m_globalID == y.m_globalID);
208 }
209 
210 bool operator!=(const PointGeom &x, const PointGeom &y)
211 {
212  return (x.m_globalID != y.m_globalID);
213 }
214 
215 bool operator!=(const PointGeom &x, const PointGeom *y)
216 {
217  return (x.m_globalID != y->m_globalID);
218 }
219 
220 bool operator!=(const PointGeom *x, const PointGeom &y)
221 {
222  return (x->m_globalID != y.m_globalID);
223 }
224 
226 {
227  ASSERTL0(i == 0, "Index other than 0 is meaningless.");
228  // shared_this_ptr() returns const PointGeom, which cannot be
229  // returned.
230  return PointGeomSharedPtr(new PointGeom(*this));
231 }
232 
234 {
235 }
236 
237 }
238 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
boost::call_traits< DataType >::const_reference a() const
Definition: NekPoint.hpp:176
void Add(PointGeom &a, PointGeom &b)
Definition: PointGeom.cpp:116
void GetCoords(NekDouble &x, NekDouble &y, NekDouble &z)
Definition: PointGeom.cpp:76
boost::call_traits< DataType >::const_reference y() const
Definition: NekPoint.hpp:164
NekDouble dot(PointGeom &a)
retun the dot product between this and input a
Definition: PointGeom.cpp:188
boost::call_traits< DataType >::const_reference z() const
Definition: NekPoint.hpp:170
void UpdatePosition(NekDouble x, NekDouble y, NekDouble z)
Definition: PointGeom.cpp:108
void Sub(PointGeom &a, PointGeom &b)
Definition: PointGeom.cpp:125
STL namespace.
void Rotate(PointGeom &a, int dir, NekDouble angle)
_this = rotation of a by angle &#39;angle&#39; around axis dir
Definition: PointGeom.cpp:143
friend bool operator==(const PointGeom &x, const PointGeom &y)
Determine equivalence by the ids. No matter what the position, if the ids are the same...
Definition: PointGeom.cpp:195
virtual PointGeomSharedPtr v_GetVertex(int i) const
Definition: PointGeom.cpp:225
int GetCoordim() const
Return the coordinate dimension of this object (i.e. the dimension of the space in which this object ...
Definition: Geometry.h:271
double NekDouble
friend bool operator!=(const PointGeom &x, const PointGeom &y)
Definition: PointGeom.cpp:210
std::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:59
void Mult(PointGeom &a, PointGeom &b)
_this = a x b
Definition: PointGeom.cpp:134
1D geometry information
Definition: Geometry0D.h:53
boost::call_traits< DataType >::const_reference b() const
Definition: NekPoint.hpp:182
LibUtilities::ShapeType m_shapeType
Type of shape.
Definition: Geometry.h:197
NekDouble dist(PointGeom &a)
return distance between this and input a
Definition: PointGeom.cpp:181
boost::call_traits< DataType >::const_reference x() const
Definition: NekPoint.hpp:158
int m_coordim
Coordinate dimension of this geometry object.
Definition: Geometry.h:183