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 
67  (*this)(0) = x;
68  (*this)(1) = y;
69  (*this)(2) = z;
70  }
71 
72 
73  // copy constructor
75  {
77  m_vid = T.m_vid;
78  m_coordim = T.m_coordim;
79 
80  std::list<CompToElmt>::const_iterator def;
81  for(def = T.m_elmtMap.begin(); def != T.m_elmtMap.end(); def++)
82  {
83  m_elmtMap.push_back(*def);
84  }
85  }
86 
87 
89  {
90  }
91 
92 
93  void PointGeom::AddElmtConnected(int gvo_id, int locid)
94  {
95  CompToElmt ee(gvo_id,locid);
96  m_elmtMap.push_back(ee);
97  }
98 
100  {
101  return int(m_elmtMap.size());
102  }
103 
104  bool PointGeom::IsElmtConnected(int gvo_id, int locid) const
105  {
106 
107  std::list<CompToElmt>::const_iterator def;
108  CompToElmt ee(gvo_id,locid);
109 
110  def = find(m_elmtMap.begin(),m_elmtMap.end(),ee);
111 
112  // Found the element connectivity object in the list
113  if(def != m_elmtMap.end())
114  {
115  return(true);
116  }
117  return(false);
118  }
119 
121  {
122  switch(m_coordim)
123  {
124  case 3:
125  z = (*this)(2);
126  case 2:
127  y = (*this)(1);
128  case 1:
129  x = (*this)(0);
130  break;
131  }
132  }
133 
134  void PointGeom::GetCoords(Array<OneD,NekDouble> &coords)
135  {
136  switch(m_coordim)
137  {
138  case 3:
139  coords[2] = (*this)(2);
140  case 2:
141  coords[1] = (*this)(1);
142  case 1:
143  coords[0] = (*this)(0);
144  break;
145  }
146  }
147 
148 
150  {
151  (*this)(0) = x;
152  (*this)(1) = y;
153  (*this)(2) = z;
154  }
155 
156  // _this = a + b
158  {
159  (*this)(0) = a[0] + b[0];
160  (*this)(1) = a[1] + b[1];
161  (*this)(2) = a[2] + b[2];
162  m_coordim = std::max(a.GetCoordim(),b.GetCoordim());
163  }
164 
165  // _this = a + b
167  {
168  (*this)(0) = a[0] - b[0];
169  (*this)(1) = a[1] - b[1];
170  (*this)(2) = a[2] - b[2];
171  m_coordim = std::max(a.GetCoordim(),b.GetCoordim());
172  }
173 
174  // _this = a x b
176  {
177  (*this)(0) = a[1]*b[2] - a[2]*b[1];
178  (*this)(1) = a[2]*b[0] - a[0]*b[2];
179  (*this)(2) = a[0]*b[1] - a[1]*b[0];
180  m_coordim = 3;
181  }
182 
183  // _output = this.a
185  {
186  return sqrt((x()-a.x())*(x()-a.x()) + (y()-a.y())*(y()-a.y()) + (z()-a.z())*(z()-a.z()));
187  }
188 
189  // _output = this.a
191  {
192  return (x()*a.x() + y()*a.y() + z()*a.z());
193  }
194 
195  /// Determine equivalence by the ids. No matter what the position,
196  /// if the ids are the same, then they are equivalent, and vice versa.
197  bool operator == (const PointGeom &x, const PointGeom &y)
198  {
199  return (x.m_vid == y.m_vid);
200  }
201 
202  bool operator == (const PointGeom &x, const PointGeom *y)
203  {
204  return (x.m_vid == y->m_vid);
205  }
206 
207  bool operator == (const PointGeom *x, const PointGeom &y)
208  {
209  return (x->m_vid == y.m_vid);
210  }
211 
212  bool operator != (const PointGeom &x, const PointGeom &y)
213  {
214  return (x.m_vid != y.m_vid);
215  }
216 
217  bool operator != (const PointGeom &x, const PointGeom *y)
218  {
219  return (x.m_vid != y->m_vid);
220  }
221 
222  bool operator != (const PointGeom *x, const PointGeom &y)
223  {
224  return (x->m_vid != y.m_vid);
225  }
226 
227  bool operator == (const CompToElmt &x, const CompToElmt &y)
228  {
229  return (x.m_id == y.m_id) || (x.m_locId == y.m_locId);
230  }
231 
232  bool operator != (const CompToElmt &x, const CompToElmt &y)
233  {
234  return (x.m_id != y.m_id);
235  }
236 
237  int PointGeom::v_GetVid(int id) const
238  {
239  return m_vid;
240  }
241 
243  {
244  ASSERTL0(i == 0, "Index other than 0 is meaningless.");
245  // shared_this_ptr() returns const PointGeom, which cannot be
246  // returned.
247  return PointGeomSharedPtr(new PointGeom(*this));
248  }
249 
250  /// \brief Get the orientation of point1; to be used later
251  /// for normal convention
252  ///
253  /// If edge1 is connected to edge2 in the same direction as
254  /// the points comprising edge1 then it is forward, otherwise
255  /// it is backward.
256  ///
257  /// For example, assume edge1 is comprised of points 1 and 2,
258  /// and edge2 is comprised of points 2 and 3, then edge1 is
259  /// forward.
260  ///
261  /// If edge1 is comprised of points 2 and 1 and edge2 is
262  /// comprised of points 3 and 2, then edge1 is backward.
263  ///
264  /// Since both edges are passed, it does
265  /// not need any information from the EdgeComponent instance.
266 
268  {
270 
271  /// Backward direction. Vertex 0 is connected to edge 2.
272  if ((*edge1.GetVertex(0) == *edge2.GetVertex(0)) ||
273  (*edge1.GetVertex(0) == *edge2.GetVertex(1)))
274  {
275  returnval = StdRegions::eBwd;
276  }
277 
278  // Not forward either, then we have a problem.
279  else if ((*edge1.GetVertex(1) != *edge2.GetVertex(0)) &&
280  (*edge1.GetVertex(1) != *edge2.GetVertex(1)))
281  {
282  std::ostringstream errstrm;
283  errstrm << "Connected edges do not share a vertex. Edges ";
284  errstrm << edge1.GetEid() << ", " << edge2.GetEid();
285  ASSERTL0(false, errstrm.str());
286  }
287 
288  return returnval;
289  }
290 
292  {
293 
294  }
295 
296  NekDouble PointGeom::v_GetCoord(const int i, const Array<OneD,const NekDouble> &Lcoord)
297  {
298  return GetCoord(i,Lcoord);
299  }
300 
301  NekDouble PointGeom::v_GetLocCoords(const Array<OneD,const NekDouble> &coords, Array<OneD,NekDouble> &Lcoords)
302  {
303  return GetLocCoords(coords,Lcoords);
304  }
305 
306  }; //end of namespace
307 }; //end of namespace