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