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