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