Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // 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: Point geometry information
33 //
34 //
35 ////////////////////////////////////////////////////////////////////////////////
36 //#include "pchSpatialDomains.h"
37 
39 #include <SpatialDomains/SegGeom.h>
40 
41 
43 
44 
45 #include <fstream>
46 
47 namespace Nektar
48 {
49  namespace SpatialDomains
50  {
52  : NekPoint<NekDouble>(0.0, 0.0, 0.0)
53  {
55  m_coordim = 0;
56  m_vid = 0;
57  }
58 
59  PointGeom::PointGeom(const int coordim, const int vid,
61  : NekPoint<NekDouble>(x,y,z)
62  {
64  m_coordim = coordim;
65  m_vid = vid;
66  m_globalID = vid;
67 
68  (*this)(0) = x;
69  (*this)(1) = y;
70  (*this)(2) = z;
71  }
72 
73 
74  // copy constructor
76  {
78  m_vid = T.m_vid;
79  m_coordim = T.m_coordim;
81 
82  std::list<CompToElmt>::const_iterator def;
83  for(def = T.m_elmtMap.begin(); def != T.m_elmtMap.end(); def++)
84  {
85  m_elmtMap.push_back(*def);
86  }
87  }
88 
89 
91  {
92  }
93 
94 
95  void PointGeom::AddElmtConnected(int gvo_id, int locid)
96  {
97  CompToElmt ee(gvo_id,locid);
98  m_elmtMap.push_back(ee);
99  }
100 
102  {
103  return int(m_elmtMap.size());
104  }
105 
106  bool PointGeom::IsElmtConnected(int gvo_id, int locid) const
107  {
108 
109  std::list<CompToElmt>::const_iterator def;
110  CompToElmt ee(gvo_id,locid);
111 
112  def = find(m_elmtMap.begin(),m_elmtMap.end(),ee);
113 
114  // Found the element connectivity object in the list
115  if(def != m_elmtMap.end())
116  {
117  return(true);
118  }
119  return(false);
120  }
121 
123  {
124  switch(m_coordim)
125  {
126  case 3:
127  z = (*this)(2);
128  case 2:
129  y = (*this)(1);
130  case 1:
131  x = (*this)(0);
132  break;
133  }
134  }
135 
137  {
138  switch(m_coordim)
139  {
140  case 3:
141  coords[2] = (*this)(2);
142  case 2:
143  coords[1] = (*this)(1);
144  case 1:
145  coords[0] = (*this)(0);
146  break;
147  }
148  }
149 
150 
152  {
153  (*this)(0) = x;
154  (*this)(1) = y;
155  (*this)(2) = z;
156  }
157 
158  // _this = a + b
160  {
161  (*this)(0) = a[0] + b[0];
162  (*this)(1) = a[1] + b[1];
163  (*this)(2) = a[2] + b[2];
164  m_coordim = std::max(a.GetCoordim(),b.GetCoordim());
165  }
166 
167  // _this = a + b
169  {
170  (*this)(0) = a[0] - b[0];
171  (*this)(1) = a[1] - b[1];
172  (*this)(2) = a[2] - b[2];
173  m_coordim = std::max(a.GetCoordim(),b.GetCoordim());
174  }
175 
176  // _this = a x b
178  {
179  (*this)(0) = a[1]*b[2] - a[2]*b[1];
180  (*this)(1) = a[2]*b[0] - a[0]*b[2];
181  (*this)(2) = a[0]*b[1] - a[1]*b[0];
182  m_coordim = 3;
183  }
184 
185  // _output = this.a
187  {
188  return sqrt((x()-a.x())*(x()-a.x()) + (y()-a.y())*(y()-a.y()) + (z()-a.z())*(z()-a.z()));
189  }
190 
191  // _output = this.a
193  {
194  return (x()*a.x() + y()*a.y() + z()*a.z());
195  }
196 
197  /// Determine equivalence by the ids. No matter what the position,
198  /// if the ids are the same, then they are equivalent, and vice versa.
199  bool operator == (const PointGeom &x, const PointGeom &y)
200  {
201  return (x.m_vid == y.m_vid);
202  }
203 
204  bool operator == (const PointGeom &x, const PointGeom *y)
205  {
206  return (x.m_vid == y->m_vid);
207  }
208 
209  bool operator == (const PointGeom *x, const PointGeom &y)
210  {
211  return (x->m_vid == y.m_vid);
212  }
213 
214  bool operator != (const PointGeom &x, const PointGeom &y)
215  {
216  return (x.m_vid != y.m_vid);
217  }
218 
219  bool operator != (const PointGeom &x, const PointGeom *y)
220  {
221  return (x.m_vid != y->m_vid);
222  }
223 
224  bool operator != (const PointGeom *x, const PointGeom &y)
225  {
226  return (x->m_vid != y.m_vid);
227  }
228 
229  bool operator == (const CompToElmt &x, const CompToElmt &y)
230  {
231  return (x.m_id == y.m_id) || (x.m_locId == y.m_locId);
232  }
233 
234  bool operator != (const CompToElmt &x, const CompToElmt &y)
235  {
236  return (x.m_id != y.m_id);
237  }
238 
239  int PointGeom::v_GetVid(int id) const
240  {
241  return m_vid;
242  }
243 
245  {
246  ASSERTL0(i == 0, "Index other than 0 is meaningless.");
247  // shared_this_ptr() returns const PointGeom, which cannot be
248  // returned.
249  return PointGeomSharedPtr(new PointGeom(*this));
250  }
251 
252  /// \brief Get the orientation of point1; to be used later
253  /// for normal convention
254  ///
255  /// If edge1 is connected to edge2 in the same direction as
256  /// the points comprising edge1 then it is forward, otherwise
257  /// it is backward.
258  ///
259  /// For example, assume edge1 is comprised of points 1 and 2,
260  /// and edge2 is comprised of points 2 and 3, then edge1 is
261  /// forward.
262  ///
263  /// If edge1 is comprised of points 2 and 1 and edge2 is
264  /// comprised of points 3 and 2, then edge1 is backward.
265  ///
266  /// Since both edges are passed, it does
267  /// not need any information from the EdgeComponent instance.
268 
270  {
272 
273  /// Backward direction. Vertex 0 is connected to edge 2.
274  if ((*edge1.GetVertex(0) == *edge2.GetVertex(0)) ||
275  (*edge1.GetVertex(0) == *edge2.GetVertex(1)))
276  {
277  returnval = StdRegions::eBwd;
278  }
279 
280  // Not forward either, then we have a problem.
281  else if ((*edge1.GetVertex(1) != *edge2.GetVertex(0)) &&
282  (*edge1.GetVertex(1) != *edge2.GetVertex(1)))
283  {
284  std::ostringstream errstrm;
285  errstrm << "Connected edges do not share a vertex. Edges ";
286  errstrm << edge1.GetEid() << ", " << edge2.GetEid();
287  ASSERTL0(false, errstrm.str());
288  }
289 
290  return returnval;
291  }
292 
294  {
295 
296  }
297 
299  {
300  return GetCoord(i,Lcoord);
301  }
302 
304  {
305  return GetLocCoords(coords,Lcoords);
306  }
307 
308  }; //end of namespace
309 }; //end of namespace
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
virtual NekDouble v_GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
Definition: PointGeom.cpp:303
boost::call_traits< DataType >::const_reference y() const
Definition: NekPoint.hpp:170
void Add(PointGeom &a, PointGeom &b)
Definition: PointGeom.cpp:159
virtual int v_GetVid(int id) const
Definition: PointGeom.cpp:239
void GetCoords(NekDouble &x, NekDouble &y, NekDouble &z)
Definition: PointGeom.cpp:122
Structure holding graphvertexobject id and local element facet id.
NekDouble dot(PointGeom &a)
Definition: PointGeom.cpp:192
bool operator!=(const PointGeom &x, const PointGeom &y)
Definition: PointGeom.cpp:214
void UpdatePosition(NekDouble x, NekDouble y, NekDouble z)
Definition: PointGeom.cpp:151
void Sub(PointGeom &a, PointGeom &b)
Definition: PointGeom.cpp:168
virtual NekDouble v_GetCoord(const int i, const Array< OneD, const NekDouble > &Lcoord)
Definition: PointGeom.cpp:298
boost::call_traits< DataType >::const_reference z() const
Definition: NekPoint.hpp:176
boost::call_traits< DataType >::const_reference x() const
Definition: NekPoint.hpp:164
PointGeomSharedPtr GetVertex(const int i) const
Definition: Geometry1D.cpp:56
double NekDouble
std::list< CompToElmt > m_elmtMap
Definition: PointGeom.h:108
void Mult(PointGeom &a, PointGeom &b)
Definition: PointGeom.cpp:177
bool IsElmtConnected(int gvo_id, int locid) const
Definition: PointGeom.cpp:106
bool operator==(const GeomFactors &lhs, const GeomFactors &rhs)
Equivalence test for GeomFactors objects.
NekDouble GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
Definition: Geometry.h:450
LibUtilities::ShapeType m_shapeType
Definition: Geometry.h:177
static StdRegions::Orientation GetPointOrientation(const SegGeom &edge1, const SegGeom &edge2)
Get the orientation of point1; to be used later for normal convention.
Definition: PointGeom.cpp:269
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:315
NekDouble dist(PointGeom &a)
Definition: PointGeom.cpp:186
NekDouble GetCoord(const int i, const Array< OneD, const NekDouble > &Lcoord)
Given local collapsed coordinate Lcoord return the value of physical coordinate in direction i...
Definition: Geometry.h:461
void AddElmtConnected(int gvo_id, int locid)
Definition: PointGeom.cpp:95
int m_coordim
coordinate dimension
Definition: Geometry.h:169
virtual PointGeomSharedPtr v_GetVertex(int i) const
Definition: PointGeom.cpp:244
boost::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:60