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