Nektar++
NodalTriFekete.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File NodalTriFekete.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: 2D Nodal Triangle Fekete Point Definitions
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
44 
45 
46 namespace Nektar
47 {
48  namespace LibUtilities
49  {
52  };
53 
54  // ////////////////////////////////////////////////////////
55  // Coordinate the nodal trianlge Fekete points
57  {
58  // Allocate the storage for points
60 
61  int index=0,isum=0;
62  const int offset = 3; //offset to match Datafile
63  NekDouble b,c;
64  unsigned int numPoints = GetNumPoints();
65 
66  // initialize values
67  for(unsigned int i=0; i < numPoints-2; ++i)
68  {
69  index += NodalTriFeketeNPTS[i];
70  }
71 
72  for(unsigned int i=0; i < NodalTriFeketeNPTS[numPoints-2]; ++i, ++index)
73  {
74  if(int(NodalTriFeketeData[index][0]))
75  {
76  b = NodalTriFeketeData[index][4];
77  c = NodalTriFeketeData[index][5];
78 
79  m_points[0][isum] = 2.0*b - 1.0;
80  m_points[1][isum] = 2.0*c - 1.0;
81  isum++;
82  continue;
83  }//end symmetry1
84 
85 
86  if(int(NodalTriFeketeData[index][1]) == 1)
87  {
88  for(unsigned int j=0; j < 3; ++j)
89  {
90  b = NodalTriFeketeData[index][offset+perm3A_2d[j][1]];
91  c = NodalTriFeketeData[index][offset+perm3A_2d[j][2]];
92  m_points[0][isum] = 2.0*b - 1.0;
93  m_points[1][isum] = 2.0*c - 1.0;
94  isum++;
95  }//end j
96  continue;
97  }//end symmetry3a
98 
99  if(int(NodalTriFeketeData[index][1]) == 2)
100  {
101  for(unsigned int j=0; j < 3; ++j)
102  {
103  b = NodalTriFeketeData[index][offset+perm3B_2d[j][1]];
104  c = NodalTriFeketeData[index][offset+perm3B_2d[j][2]];
105  m_points[0][isum] = 2.0*b - 1.0;
106  m_points[1][isum] = 2.0*c - 1.0;
107  isum++;
108  }//end j
109  continue;
110  }//end symmetry3b
111 
112 
113  if(int(NodalTriFeketeData[index][2]))
114  {
115  for(unsigned int j=0; j < 6; ++j)
116  {
117  b = NodalTriFeketeData[index][offset+perm6_2d[j][1]];
118  c = NodalTriFeketeData[index][offset+perm6_2d[j][2]];
119  m_points[0][isum] = 2.0*b - 1.0;
120  m_points[1][isum] = 2.0*c - 1.0;
121  isum++;
122  }//end j
123  continue;
124  }//end symmetry6
125  }//end npts
126 
128 
129  ASSERTL1((static_cast<unsigned int>(isum)==m_pointsKey.GetTotNumPoints()),"sum not equal to npts");
130 
132  numPoints - 1, m_points[0], m_points[1]);
133  }
134 
136  {
137  // Allocate the storage for points
139 
140  typedef DataType T;
141 
142  // Solve the Vandermonde system of integrals for the weight vector
143  NekVector<T> w = m_util->GetWeights();
144  m_weights = Array<OneD,T>( w.GetRows(), w.GetPtr() );
145 
146  }
147 
148  // ////////////////////////////////////////
149  // CalculateInterpMatrix()
151  Array<OneD, NekDouble>& interp)
152  {
154  xi[0] = xia;
155  xi[1] = yia;
156 
157  std::shared_ptr<NekMatrix<NekDouble> > mat =
158  m_util->GetInterpolationMatrix(xi);
159  Vmath::Vcopy(mat->GetRows() * mat->GetColumns(), mat->GetRawPtr(),
160  1, &interp[0], 1);
161  }
162 
163  // ////////////////////////////////////////
164  // CalculateDerivMatrix()
166  {
167  // Allocate the derivative matrix.
169 
170  m_derivmatrix[0] = m_util->GetDerivMatrix(0);
171  m_derivmatrix[1] = m_util->GetDerivMatrix(1);
172  }
173 
174  std::shared_ptr<PointsBaseType> NodalTriFekete::Create(const PointsKey &key)
175  {
176  std::shared_ptr<PointsBaseType> returnval(MemoryManager<NodalTriFekete>::AllocateSharedPtr(key));
177  returnval->Initialize();
178  return returnval;
179  }
180 
182  {
183  int i,j;
184  int cnt;
185  int istart,iend;
186 
187  const int nVerts = 3;
188  const int nEdgeInteriorPoints = GetNumPoints()-2;
189  const int nBoundaryPoints = 3*nEdgeInteriorPoints + 3;
190 
191  if(nEdgeInteriorPoints==0)
192  {
193  return;
194  }
195 
196  // group the points of edge 1 together;
197  istart = nVerts;
198  for(i = cnt = istart; i < nBoundaryPoints; i++)
199  {
200  if( fabs(m_points[1][i] + 1.0) < NekConstants::kNekZeroTol)
201  {
202  std::swap(m_points[0][cnt], m_points[0][i]);
203  std::swap(m_points[1][cnt], m_points[1][i]);
204  cnt++;
205  }
206  }
207 
208  // bubble sort edge 1 (counterclockwise numbering)
209  iend = istart + nEdgeInteriorPoints;
210  for(i = istart; i < iend; i++)
211  {
212  for(j = istart+1; j < iend; j++)
213  {
214  if(m_points[0][j] < m_points[0][j-1])
215  {
216  std::swap(m_points[0][j], m_points[0][j-1]);
217  std::swap(m_points[1][j], m_points[1][j-1]);
218  }
219  }
220  }
221 
222  // group the points of edge 2 together;
223  istart = iend;
224  for(i = cnt = istart; i < nBoundaryPoints; i++)
225  {
226  if( fabs(m_points[1][i]+m_points[0][i]) < NekConstants::kNekZeroTol)
227  {
228  std::swap(m_points[0][cnt], m_points[0][i]);
229  std::swap(m_points[1][cnt], m_points[1][i]);
230  cnt++;
231  }
232  }
233 
234  // bubble sort edge 2 (counterclockwise numbering)
235  iend = istart + nEdgeInteriorPoints;
236  for(i = istart; i < iend; i++)
237  {
238  for(j = istart+1; j < iend; j++)
239  {
240  if(m_points[1][j] < m_points[1][j-1])
241  {
242  std::swap(m_points[0][j], m_points[0][j-1]);
243  std::swap(m_points[1][j], m_points[1][j-1]);
244  }
245  }
246  }
247 
248  // group the points of edge 3 together;
249  istart = iend;
250  for(i = cnt = istart; i < nBoundaryPoints; i++)
251  {
252  if( fabs(m_points[0][i]+1.0) < NekConstants::kNekZeroTol)
253  {
254  std::swap(m_points[0][cnt], m_points[0][i]);
255  std::swap(m_points[1][cnt], m_points[1][i]);
256  cnt++;
257  }
258  }
259  // bubble sort edge 3 (counterclockwise numbering)
260  iend = istart + nEdgeInteriorPoints;
261  for(i = istart; i < iend; i++)
262  {
263  for(j = istart+1; j < iend; j++)
264  {
265  if(m_points[1][j] > m_points[1][j-1])
266  {
267  std::swap(m_points[0][j], m_points[0][j-1]);
268  std::swap(m_points[1][j], m_points[1][j-1]);
269  }
270  }
271  }
272 
273  if(GetNumPoints() < 5)
274  {
275  //at numpoints = 4 there is only one interior point so doesnt
276  //need sorting
277  return;
278  }
279 
280  //someone forgot to finish this piece of code and tell anyone
281  //that they didnt
282  //face interior nodes needs to be considered
283  //make a copy of the unsorted nodes
284  //bubble sort by smallest y
285  //which will put them into sets of ever decreasing size
286  //which can be bubble sorted by x to obtain the distrobution
287 
288  Array<OneD, NekDouble> xc(m_points[0].size() - iend);
289  Array<OneD, NekDouble> yc(m_points[0].size() - iend);
290  int ct = 0;
291  for(i = iend; i < m_points[0].size(); i++, ct++)
292  {
293  xc[ct] = m_points[0][i];
294  yc[ct] = m_points[1][i];
295  }
296 
297  //sort smallest first
298  bool repeat = true;
299  while(repeat)
300  {
301  repeat = false;
302  for(i = 0; i < xc.size() - 1; i++)
303  {
304  if(yc[i] > yc[i+1])
305  {
306  std::swap(xc[i],xc[i+1]);
307  std::swap(yc[i],yc[i+1]);
308  repeat = true;
309  }
310  }
311  }
312 
313  int offset = 0;
314  int npl = GetNumPoints() - 3;
315  while(npl > 1)
316  {
317  repeat = true;
318  while(repeat)
319  {
320  repeat = false;
321  for(i = offset; i < offset + npl - 1; i++)
322  {
323  if(xc[i] > xc[i+1])
324  {
325  std::swap(xc[i],xc[i+1]);
326  std::swap(yc[i],yc[i+1]);
327  repeat = true;
328  }
329  }
330  }
331  offset += npl;
332  npl--;
333  }
334 
335  //copy back in
336  ct = 0;
337  for(i = iend; i < m_points[0].size(); i++, ct++)
338  {
339  m_points[0][i] = xc[ct];
340  m_points[1][i] = yc[ct];
341  }
342  return;
343  }
344 
345 
346  } // end of namespace stdregion
347 } // end of namespace stdregion
348 
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:250
size_type size() const
Returns the array's size.
bool RegisterCreator(const KeyType &key, const CreateFuncType &createFunc)
Register the given function and associate it with the key. The return value is just to facilitate cal...
Definition: NekManager.hpp:166
void CalculateInterpMatrix(const Array< OneD, const NekDouble > &xi, const Array< OneD, const NekDouble > &yi, Array< OneD, NekDouble > &interp)
std::shared_ptr< NodalUtilTriangle > m_util
static std::shared_ptr< PointsBaseType > Create(const PointsKey &key)
Array< OneD, DataType > m_points[3]
Storage for the point locations, allowing for up to a 3D points storage.
Definition: Points.h:390
MatrixSharedPtrType m_derivmatrix[3]
Derivative matrices.
Definition: Points.h:396
PointsKey m_pointsKey
Points type for this points distributions.
Definition: Points.h:387
unsigned int GetNumPoints() const
Definition: Points.h:273
Array< OneD, DataType > m_weights
Quadrature weights for the weights.
Definition: Points.h:392
Defines a specification for a set of points.
Definition: Points.h:60
unsigned int GetTotNumPoints() const
Definition: Points.h:180
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Array< OneD, DataType > & GetPtr()
Definition: NekVector.cpp:227
unsigned int GetRows() const
Definition: NekVector.cpp:215
static const unsigned int perm3A_2d[3][3]
PointsManagerT & PointsManager(void)
static const NekDouble NodalTriFeketeData[][6]
static const unsigned int perm6_2d[6][3]
static const unsigned int perm3B_2d[3][3]
static const unsigned int NodalTriFeketeNPTS[NodalTriFeketeAvailable]
@ eNodalTriFekete
2D Nodal Fekete Points on a Triangle
Definition: PointsType.h:70
static const NekDouble kNekZeroTol
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199