Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Points.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Points.hpp
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: Header file of Points definition
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_UTILITIES_FOUNDATIONS_POINTS_H
37 #define NEKTAR_LIB_UTILITIES_FOUNDATIONS_POINTS_H
38 
43 
44 //#include <LibUtilities/BasicUtils/BasicUtilsFwd.hpp> // for NekManager
47 
48 
49 namespace Nektar
50 {
51 
52  namespace LibUtilities
53  {
54  // Need to add method to compute total number of points given dimension
55  // and number of points.
56 
57  /// Defines a specification for a set of points.
58  class PointsKey
59  {
60  public:
61  // Used for looking up the creator. The creator for number of points
62  // can generate for any number, so we want the same creator called
63  // for all number.
64  struct opLess
65  {
66  LIB_UTILITIES_EXPORT bool operator()(const PointsKey &lhs, const PointsKey &rhs) const;
67  };
68 
69  /// Default constructor.
70  PointsKey(void):
71  m_numpoints(0),
73  m_factor(NekConstants::kNekUnsetDouble)
74  {
75  }
76 
77  /// Constructor defining the number and distribution of points.
78  PointsKey(const int &numpoints, const PointsType &pointstype,
80  m_numpoints(numpoints),
81  m_pointstype(pointstype),
82  m_factor(factor)
83  {
84  }
85 
86  /// Destructor.
87  virtual ~PointsKey()
88  {
89  }
90 
91  /// Copy constructor.
92  PointsKey(const PointsKey &key)
93  {
94  *this = key; // defer to assignment operator
95  }
96 
98  {
101  m_factor = key.m_factor;
102 
103  return *this;
104  }
105 
106  inline unsigned int GetNumPoints() const
107  {
108  return m_numpoints;
109  }
110 
111  inline PointsType GetPointsType() const
112  {
113  return m_pointstype;
114  }
115 
116  inline NekDouble GetFactor() const
117  {
118  return m_factor;
119  }
120 
121  inline bool operator==(const PointsKey &key)
122  {
123 
125  {
126  return (m_numpoints == key.m_numpoints &&
127  m_pointstype == key.m_pointstype);
128  }
129 
130  return false;
131  }
132 
133  inline bool operator== (const PointsKey *y)
134  {
135  return (*this == *y);
136  }
137 
138  inline bool operator != (const PointsKey& y)
139  {
140  return (!(*this == y));
141  }
142 
143  inline bool operator != (const PointsKey *y)
144  {
145  return (!(*this == *y));
146  }
147 
148  // If new points are added, this function must be modified
149  inline unsigned int GetPointsDim() const
150  {
151  int dimpoints = 1;
152 
153  switch(m_pointstype)
154  {
155  case eNodalTriElec:
156  case eNodalTriFekete:
158  dimpoints = 2;
159  break;
160 
161  case eNodalTetElec:
164  dimpoints = 3;
165  break;
166 
167  default:
168  break;
169  }
170 
171  return dimpoints;
172  }
173 
174  // If new points are added, this function must be modified
175  inline unsigned int GetTotNumPoints() const
176  {
177  int totpoints = m_numpoints;
178 
179  switch(m_pointstype)
180  {
181  case eNodalTriElec:
182  case eNodalTriFekete:
184  totpoints = m_numpoints*(m_numpoints+1)/2;
185  break;
186 
187  case eNodalTetElec:
189  totpoints = m_numpoints*(m_numpoints+1)*(m_numpoints+2)/6;
190  break;
191 
193  totpoints = m_numpoints*m_numpoints*(m_numpoints+1)/2;
194  break;
195 
196  default:
197  break;
198  }
199 
200  return totpoints;
201  }
202 
203  LIB_UTILITIES_EXPORT friend bool operator==(const PointsKey &lhs, const PointsKey &rhs);
204  LIB_UTILITIES_EXPORT friend bool operator<(const PointsKey &lhs, const PointsKey &rhs);
205  LIB_UTILITIES_EXPORT friend bool opLess::operator()(const PointsKey &lhs, const PointsKey &rhs) const;
206 
207  protected:
208  unsigned int m_numpoints; //!< number of the points (as appropriately defined for PointsType)
209  PointsType m_pointstype; //!< Type of Points
210  NekDouble m_factor; //!< optional factor
211  private:
212  };
213 
214  static const PointsKey NullPointsKey(0, eNoPointsType);
215 
216  LIB_UTILITIES_EXPORT bool operator==(const PointsKey &lhs, const PointsKey &rhs);
217  LIB_UTILITIES_EXPORT bool operator<(const PointsKey &lhs, const PointsKey &rhs);
218  LIB_UTILITIES_EXPORT std::ostream& operator<<(std::ostream& os, const PointsKey& rhs);
219 
220  typedef std::vector<PointsKey> PointsKeyVector;
221 
222  /// Stores a set of points of datatype DataT, defined by a PointKey.
223  template<typename DataT>
224  class Points
225  {
226  public:
227  typedef DataT DataType;
228  typedef boost::shared_ptr<NekMatrix<DataType> > MatrixSharedPtrType;
229 
230  virtual ~Points()
231  {
232  }
233 
234  virtual void Initialize(void)
235  {
236  CalculatePoints();
239  }
240 
241  inline unsigned int GetPointsDim() const
242  {
243  return m_pointsKey.GetPointsDim();
244  }
245 
246  inline unsigned int GetNumPoints() const
247  {
248  return m_pointsKey.GetNumPoints();
249  }
250 
251  inline unsigned int GetTotNumPoints() const
252  {
253  return m_pointsKey.GetTotNumPoints();
254  }
255 
256  inline PointsType GetPointsType() const
257  {
258  return m_pointsKey.GetPointsType();
259  }
260 
261  inline const Array<OneD, const DataType>& GetZ() const
262  {
263  return m_points[0];
264  }
265 
266  inline const Array<OneD, const DataType>& GetW() const
267  {
268  return m_weights;
269  }
270 
272  Array<OneD, const DataType> &w) const
273  {
274  z = m_points[0];
275  w = m_weights;
276  }
277 
279  {
280  x = m_points[0];
281  }
282 
285  {
286  x = m_points[0];
287  y = m_points[1];
288  }
289 
293  {
294  x = m_points[0];
295  y = m_points[1];
296  z = m_points[2];
297  }
298 
299  inline const MatrixSharedPtrType& GetD(Direction dir = xDir) const
300  {
301  return m_derivmatrix[(int)dir];
302  }
303 
304  virtual const MatrixSharedPtrType GetI(const PointsKey &pkey)
305  {
306  ASSERTL0(false, "Method not implemented ");
307  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
308  return returnval;
309  }
310 
312  {
313  ASSERTL0(false, "Method not implemented");
314  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
315  return returnval;
316  }
317 
318  virtual const MatrixSharedPtrType GetI(unsigned int numpoints, const Array<OneD, const DataType>& x)
319  {
320  ASSERTL0(false, "Method not implemented");
321  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
322  return returnval;
323  }
324 
326  {
327  ASSERTL0(false, "Method not implemented");
328  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
329  return returnval;
330  }
331 
334  {
335  ASSERTL0(false, "Method not implemented");
336  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
337  return returnval;
338  }
339 
341  {
342  ASSERTL0(false, "Method not implemented ");
343  boost::shared_ptr<NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr());
344  return returnval;
345  }
346 
347  protected:
354 
355  virtual void CalculatePoints()
356  {
357  unsigned int pointsDim = GetPointsDim();
358  unsigned int totNumPoints = GetTotNumPoints();
359 
360  for (unsigned int i=0; i<pointsDim; ++i)
361  {
362  m_points[i] = Array<OneD, DataType>(totNumPoints);
363  }
364  }
365 
366  virtual void CalculateWeights()
367  {
369  }
370 
371  virtual void CalculateDerivMatrix()
372  {
373  int totNumPoints = GetTotNumPoints();
374  for(unsigned int i = 0; i < m_pointsKey.GetPointsDim(); ++i)
375  {
376  m_derivmatrix[i] = MemoryManager<NekMatrix<DataType> >::AllocateSharedPtr(totNumPoints,totNumPoints);
377  }
378  }
379  Points(const PointsKey &key):m_pointsKey(key)
380  {
381  }
382 
383  private:
384  // These should never be called
385  Points(const Points &pts)
386  {
387  NEKERROR(ErrorUtil::efatal,"Copy Constructor for Points should not be called");
388  }
390  {
391  NEKERROR(ErrorUtil::efatal,"Default Constructor for Points should not be called");
392  }
393  };
394 
395  }; // end of namespace
396 } // end of namespace
397 
398 #endif //NEKTAR_LIB_UTILITIES_FOUNDATIONS_POINTS_H