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
40
42{
43
45{
47 m_coordim = 0;
48 m_globalID = 0;
49}
50
51PointGeom::PointGeom(const int coordim, const int vid, NekDouble x, NekDouble y,
53 : NekPoint<NekDouble>(x, y, z)
54{
56 m_coordim = coordim;
57 m_globalID = vid;
58}
59
60// copy constructor
63 std::enable_shared_from_this<PointGeom>(T)
64{
68}
69
71{
72 switch (m_coordim)
73 {
74 case 3:
75 z = (*this)(2);
76 /* Falls through. */
77 case 2:
78 y = (*this)(1);
79 /* Falls through. */
80 case 1:
81 x = (*this)(0);
82 break;
83 }
84}
85
87{
88 switch (m_coordim)
89 {
90 case 3:
91 coords[2] = (*this)(2);
92 /* Falls through. */
93 case 2:
94 coords[1] = (*this)(1);
95 /* Falls through. */
96 case 1:
97 coords[0] = (*this)(0);
98 break;
99 }
100}
101
103{
104 (*this)(0) = x;
105 (*this)(1) = y;
106 (*this)(2) = z;
107}
108
109// _this = a + b
111{
112 (*this)(0) = a[0] + b[0];
113 (*this)(1) = a[1] + b[1];
114 (*this)(2) = a[2] + b[2];
115 m_coordim = std::max(a.GetCoordim(), b.GetCoordim());
116}
117
118// _this = a + b
120{
121 (*this)(0) = a[0] - b[0];
122 (*this)(1) = a[1] - b[1];
123 (*this)(2) = a[2] - b[2];
124 m_coordim = std::max(a.GetCoordim(), b.GetCoordim());
125}
126
127/// \brief _this = a x b
129{
130 (*this)(0) = a[1] * b[2] - a[2] * b[1];
131 (*this)(1) = a[2] * b[0] - a[0] * b[2];
132 (*this)(2) = a[0] * b[1] - a[1] * b[0];
133 m_coordim = 3;
134}
135
136/// \brief _this = rotation of a by angle 'angle' around axis dir
137void PointGeom::Rotate(PointGeom &a, int dir, NekDouble angle)
138{
139 switch (dir)
140 {
141 case 0:
142 {
143 NekDouble yrot = cos(angle) * a.y() - sin(angle) * a.z();
144 NekDouble zrot = sin(angle) * a.y() + cos(angle) * a.z();
145
146 (*this)(0) = a.x();
147 (*this)(1) = yrot;
148 (*this)(2) = zrot;
149 }
150 break;
151 case 1:
152 {
153 NekDouble zrot = cos(angle) * a.z() - sin(angle) * a.x();
154 NekDouble xrot = sin(angle) * a.z() + cos(angle) * a.x();
155
156 (*this)(0) = xrot;
157 (*this)(1) = a.y();
158 (*this)(2) = zrot;
159 }
160 break;
161 case 2:
162 {
163 NekDouble xrot = cos(angle) * a.x() - sin(angle) * a.y();
164 NekDouble yrot = sin(angle) * a.x() + cos(angle) * a.y();
165
166 (*this)(0) = xrot;
167 (*this)(1) = yrot;
168 (*this)(2) = a.z();
169 }
170 break;
171 }
172}
173
174/// \brief return distance between this and input a
176{
177 return sqrt((x() - a.x()) * (x() - a.x()) + (y() - a.y()) * (y() - a.y()) +
178 (z() - a.z()) * (z() - a.z()));
179}
180
181/// \brief retun the dot product between this and input a
183{
184 return (x() * a.x() + y() * a.y() + z() * a.z());
185}
186
187/// Determine equivalence by the ids. No matter what the position,
188/// if the ids are the same, then they are equivalent, and vice versa.
189bool operator==(const PointGeom &x, const PointGeom &y)
190{
191 return (x.m_globalID == y.m_globalID);
192}
193
194bool operator==(const PointGeom &x, const PointGeom *y)
195{
196 return (x.m_globalID == y->m_globalID);
197}
198
199bool operator==(const PointGeom *x, const PointGeom &y)
200{
201 return (x->m_globalID == y.m_globalID);
202}
203
204bool operator!=(const PointGeom &x, const PointGeom &y)
205{
206 return (x.m_globalID != y.m_globalID);
207}
208
209bool operator!=(const PointGeom &x, const PointGeom *y)
210{
211 return (x.m_globalID != y->m_globalID);
212}
213
214bool operator!=(const PointGeom *x, const PointGeom &y)
215{
216 return (x->m_globalID != y.m_globalID);
217}
218
220{
221 ASSERTL0(i == 0, "Index other than 0 is meaningless.");
222 // shared_this_ptr() returns const PointGeom, which cannot be
223 // returned.
224 return PointGeomSharedPtr(new PointGeom(*this));
225}
226
228{
229}
230
231} // namespace Nektar::SpatialDomains
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
boost::call_traits< DataType >::const_reference x() const
Definition: NekPoint.hpp:160
boost::call_traits< DataType >::const_reference a() const
Definition: NekPoint.hpp:178
boost::call_traits< DataType >::const_reference z() const
Definition: NekPoint.hpp:172
boost::call_traits< DataType >::const_reference b() const
Definition: NekPoint.hpp:184
boost::call_traits< DataType >::const_reference y() const
Definition: NekPoint.hpp:166
1D geometry information
Definition: Geometry0D.h:52
LibUtilities::ShapeType m_shapeType
Type of shape.
Definition: Geometry.h:202
int m_coordim
Coordinate dimension of this geometry object.
Definition: Geometry.h:188
void Sub(PointGeom &a, PointGeom &b)
Definition: PointGeom.cpp:119
void GetCoords(NekDouble &x, NekDouble &y, NekDouble &z)
Definition: PointGeom.cpp:70
void Mult(PointGeom &a, PointGeom &b)
_this = a x b
Definition: PointGeom.cpp:128
void Rotate(PointGeom &a, int dir, NekDouble angle)
_this = rotation of a by angle 'angle' around axis dir
Definition: PointGeom.cpp:137
NekDouble dot(PointGeom &a)
retun the dot product between this and input a
Definition: PointGeom.cpp:182
void Add(PointGeom &a, PointGeom &b)
Definition: PointGeom.cpp:110
PointGeomSharedPtr v_GetVertex(int i) const override
Definition: PointGeom.cpp:219
void UpdatePosition(NekDouble x, NekDouble y, NekDouble z)
Definition: PointGeom.cpp:102
NekDouble dist(PointGeom &a)
return distance between this and input a
Definition: PointGeom.cpp:175
bool operator==(const GeomFactors &lhs, const GeomFactors &rhs)
Equivalence test for GeomFactors objects.
bool operator!=(const PointGeom &x, const PointGeom &y)
Definition: PointGeom.cpp:204
std::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:57
std::vector< double > z(NPUPPER)
double NekDouble
STL namespace.
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:285