Nektar++
NodalPrismElec.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: NodalPrismElec.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: 3D Nodal Prism eletrostatic Point Definitions
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include <boost/core/ignore_unused.hpp>
36
38#include <vector>
39
40namespace Nektar
41{
42namespace LibUtilities
43{
44
47
48namespace
49{
50bool isVertex(size_t t, size_t y, size_t npts)
51{
52 return (t == 0 && y == 0) || (t == 1 && y == 0) || (t == 2 && y == 0) ||
53 (t == 0 && y == (npts - 1)) || (t == 1 && y == (npts - 1)) ||
54 (t == 2 && y == (npts - 1));
55}
56
57bool isEdge_01(size_t t, size_t y, size_t npts)
58{
59 return y == 0 && t > 2 && t <= npts;
60}
61
62bool isEdge_12(size_t t, size_t y, size_t npts)
63{
64 boost::ignore_unused(y, npts);
65 return t == 1;
66}
67
68bool isEdge_23(size_t t, size_t y, size_t npts)
69{
70 return y == (npts - 1) && t > 2 && t <= npts;
71}
72
73bool isEdge_30(size_t t, size_t y, size_t npts)
74{
75 boost::ignore_unused(y, npts);
76 return t == 0;
77}
78
79bool isEdge_04(size_t t, size_t y, size_t npts)
80{
81 return y == 0 && t >= 3 + 2 * (npts - 2) && t < 3 + 3 * (npts - 2);
82}
83
84bool isEdge_14(size_t t, size_t y, size_t npts)
85{
86 return y == 0 && t >= 3 + (npts - 2) && t < 3 + 2 * (npts - 2);
87}
88
89bool isEdge_25(size_t t, size_t y, size_t npts)
90{
91 return y == npts - 1 && t >= 3 + (npts - 2) && t < 3 + 2 * (npts - 2);
92}
93
94bool isEdge_35(size_t t, size_t y, size_t npts)
95{
96 return y == npts - 1 && t >= 3 + 2 * (npts - 2) && t < 3 + 3 * (npts - 2);
97}
98
99bool isEdge_45(size_t t, size_t y, size_t npts)
100{
101 boost::ignore_unused(y, npts);
102 return t == 2;
103}
104
105bool isEdge(size_t t, size_t y, size_t npts)
106{
107 return isEdge_01(t, y, npts) || isEdge_12(t, y, npts) ||
108 isEdge_23(t, y, npts) || isEdge_30(t, y, npts) ||
109 isEdge_04(t, y, npts) || isEdge_14(t, y, npts) ||
110 isEdge_25(t, y, npts) || isEdge_35(t, y, npts) ||
111 isEdge_45(t, y, npts);
112}
113
114bool isFace_0123(size_t t, size_t y, size_t npts)
115{
116 boost::ignore_unused(y);
117 return t < 3 + (npts - 2);
118}
119
120bool isFace_014(size_t t, size_t y, size_t npts)
121{
122 boost::ignore_unused(t, npts);
123 return y == 0;
124}
125
126bool isFace_1254(size_t t, size_t y, size_t npts)
127{
128 boost::ignore_unused(y);
129 return t < 3 + 2 * (npts - 2) && t >= 3 + (npts - 2);
130}
131
132bool isFace_325(size_t t, size_t y, size_t npts)
133{
134 boost::ignore_unused(t);
135 return y == (npts - 1);
136}
137
138bool isFace_0354(size_t t, size_t y, size_t npts)
139{
140 boost::ignore_unused(y);
141 return t < 3 + 3 * (npts - 2) && t >= 3 + 2 * (npts - 2);
142}
143
144bool isFace(size_t t, size_t y, size_t npts)
145{
146 return isFace_0123(t, y, npts) || isFace_014(t, y, npts) ||
147 isFace_1254(t, y, npts) || isFace_325(t, y, npts) ||
148 isFace_0354(t, y, npts);
149}
150} // namespace
151
152// Calculate evenly spaced number of points
154{
155 // Allocate the storage for points
157
158 // Populate m_points
159 size_t npts = GetNumPoints();
160
163 LibUtilities::PointsManager()[pkey1]->GetPoints(u1, v1);
166 LibUtilities::PointsManager()[pkey2]->GetPoints(u);
167
168 for (size_t y = 0, index = 0; y < npts; y++)
169 {
170 for (size_t t = 0; t < u1.size(); t++, index++)
171 {
172 m_points[0][index] = u1[t];
173 m_points[1][index] = u[y];
174 m_points[2][index] = v1[t];
175 }
176 }
177
180 npts - 1, m_points[0], m_points[1], m_points[2]);
181}
182
184{
185 size_t npts = GetNumPoints();
186 using std::vector;
187 vector<int> vertex;
188 vector<int> iEdge_01; // interior edge 0
189 vector<int> iEdge_12; // interior edge 1
190 vector<int> iEdge_23; // interior edge 2
191 vector<int> iEdge_30; // interior edge 3
192 vector<int> iEdge_04; // interior edge 4
193 vector<int> iEdge_14; // interior edge 5
194 vector<int> iEdge_25; // interior edge 6
195 vector<int> iEdge_35; // interior edge 7
196 vector<int> iEdge_45; // interior edge 8
197 vector<int> iFace_0123; // interior face 0
198 vector<int> iFace_014; // interior face 1
199 vector<int> iFace_1254; // interior face 2
200 vector<int> iFace_325; // interior face 3
201 vector<int> iFace_0354; // interior face 4
202 vector<int> interiorVolumePoints; // interior volume points
203 vector<int> map;
204
205 // Build the lattice prism left to right - bottom to top
206 for (size_t y = 0, index = 0; y < npts; y++)
207 {
208 for (size_t t = 0; t < npts * (npts + 1) / 2; t++, index++)
209 {
210 if (isVertex(t, y, npts))
211 {
212 vertex.push_back(index);
213 }
214 else if (isEdge(t, y, npts))
215 {
216 if (isEdge_01(t, y, npts))
217 {
218 iEdge_01.push_back(index);
219 }
220 else if (isEdge_12(t, y, npts))
221 {
222 iEdge_12.push_back(index);
223 }
224 else if (isEdge_23(t, y, npts))
225 {
226 iEdge_23.push_back(index);
227 }
228 else if (isEdge_30(t, y, npts))
229 {
230 iEdge_30.push_back(index);
231 }
232 else if (isEdge_04(t, y, npts))
233 {
234 iEdge_04.push_back(index);
235 }
236 else if (isEdge_14(t, y, npts))
237 {
238 iEdge_14.push_back(index);
239 }
240 else if (isEdge_25(t, y, npts))
241 {
242 iEdge_25.push_back(index);
243 }
244 else if (isEdge_35(t, y, npts))
245 {
246 iEdge_35.push_back(index);
247 }
248 else if (isEdge_45(t, y, npts))
249 {
250 iEdge_45.push_back(index);
251 }
252 }
253 else if (isFace(t, y, npts))
254 {
255 if (isFace_0123(t, y, npts))
256 {
257 iFace_0123.push_back(index);
258 }
259 else if (isFace_014(t, y, npts))
260 {
261 iFace_014.push_back(index);
262 }
263 else if (isFace_1254(t, y, npts))
264 {
265 iFace_1254.push_back(index);
266 }
267 else if (isFace_325(t, y, npts))
268 {
269 iFace_325.push_back(index);
270 }
271 else if (isFace_0354(t, y, npts))
272 {
273 iFace_0354.push_back(index);
274 }
275 }
276 else
277 {
278 interiorVolumePoints.push_back(index);
279 }
280 }
281 }
282
283 // sort vertices
284 std::swap(vertex[2], vertex[4]);
285 // sort edges
286 std::reverse(iEdge_23.begin(), iEdge_23.end());
287 std::reverse(iEdge_30.begin(), iEdge_30.end());
288 std::reverse(iEdge_04.begin(), iEdge_04.end());
289 std::reverse(iEdge_35.begin(), iEdge_35.end());
290
291 // faces
292 for (size_t i = 0; i < npts - 2; i++)
293 {
294 for (size_t j = i + 1; j < npts - 2; j++)
295 {
296 std::swap(iFace_1254[i * (npts - 2) + j],
297 iFace_1254[j * (npts - 2) + i]);
298 }
299 }
300 for (size_t i = 0; i < npts - 2; i++)
301 {
302 std::reverse(iFace_0354.begin() + (i * (npts - 2)),
303 iFace_0354.begin() + (i * (npts - 2) + npts - 2));
304 }
305 for (size_t i = 0; i < npts - 2; i++)
306 {
307 for (size_t j = i + 1; j < npts - 2; j++)
308 {
309 std::swap(iFace_0354[i * (npts - 2) + j],
310 iFace_0354[j * (npts - 2) + i]);
311 }
312 }
313
314 for (size_t n = 0; n < vertex.size(); ++n)
315 {
316 map.push_back(vertex[n]);
317 }
318
319 for (size_t n = 0; n < iEdge_01.size(); ++n)
320 {
321 map.push_back(iEdge_01[n]);
322 }
323
324 for (size_t n = 0; n < iEdge_12.size(); ++n)
325 {
326 map.push_back(iEdge_12[n]);
327 }
328
329 for (size_t n = 0; n < iEdge_23.size(); ++n)
330 {
331 map.push_back(iEdge_23[n]);
332 }
333
334 for (size_t n = 0; n < iEdge_30.size(); ++n)
335 {
336 map.push_back(iEdge_30[n]);
337 }
338
339 for (size_t n = 0; n < iEdge_04.size(); ++n)
340 {
341 map.push_back(iEdge_04[n]);
342 }
343
344 for (size_t n = 0; n < iEdge_14.size(); ++n)
345 {
346 map.push_back(iEdge_14[n]);
347 }
348
349 for (size_t n = 0; n < iEdge_25.size(); ++n)
350 {
351 map.push_back(iEdge_25[n]);
352 }
353
354 for (size_t n = 0; n < iEdge_35.size(); ++n)
355 {
356 map.push_back(iEdge_35[n]);
357 }
358
359 for (size_t n = 0; n < iEdge_45.size(); ++n)
360 {
361 map.push_back(iEdge_45[n]);
362 }
363
364 for (size_t n = 0; n < iFace_0123.size(); ++n)
365 {
366 map.push_back(iFace_0123[n]);
367 }
368
369 for (size_t n = 0; n < iFace_014.size(); ++n)
370 {
371 map.push_back(iFace_014[n]);
372 }
373
374 for (size_t n = 0; n < iFace_1254.size(); ++n)
375 {
376 map.push_back(iFace_1254[n]);
377 }
378
379 for (size_t n = 0; n < iFace_325.size(); ++n)
380 {
381 map.push_back(iFace_325[n]);
382 }
383
384 for (size_t n = 0; n < iFace_0354.size(); ++n)
385 {
386 map.push_back(iFace_0354[n]);
387 }
388
389 for (size_t n = 0; n < interiorVolumePoints.size(); ++n)
390 {
391 map.push_back(interiorVolumePoints[n]);
392 }
393
394 Array<OneD, NekDouble> points[3];
398
399 for (size_t index = 0; index < map.size(); ++index)
400 {
401 points[0][index] = m_points[0][index];
402 points[1][index] = m_points[1][index];
403 points[2][index] = m_points[2][index];
404 }
405
406 for (size_t index = 0; index < map.size(); ++index)
407 {
408 m_points[0][index] = points[0][map[index]];
409 m_points[1][index] = points[1][map[index]];
410 m_points[2][index] = points[2][map[index]];
411 }
412}
413
415{
416 // Allocate the storage for points
418
419 typedef DataType T;
420
421 // Solve the Vandermonde system of integrals for the weight vector
422 NekVector<T> w = m_util->GetWeights();
423
424 m_weights = Array<OneD, T>(w.GetRows(), w.GetPtr());
425}
426
427// ////////////////////////////////////////
428// CalculateInterpMatrix()
433{
435 xi[0] = xia;
436 xi[1] = yia;
437 xi[1] = zia;
438
439 std::shared_ptr<NekMatrix<NekDouble>> mat =
440 m_util->GetInterpolationMatrix(xi);
441 Vmath::Vcopy(mat->GetRows() * mat->GetColumns(), mat->GetRawPtr(), 1,
442 &interp[0], 1);
443}
444
445// ////////////////////////////////////////
446// CalculateDerivMatrix()
448{
449 // Allocate the derivative matrix.
450 PointsBaseType::v_CalculateDerivMatrix();
451
452 m_derivmatrix[0] = m_util->GetDerivMatrix(0);
453 m_derivmatrix[1] = m_util->GetDerivMatrix(1);
454 m_derivmatrix[2] = m_util->GetDerivMatrix(2);
455}
456
457std::shared_ptr<PointsBaseType> NodalPrismElec::Create(const PointsKey &key)
458{
459 std::shared_ptr<PointsBaseType> returnval(
461
462 returnval->Initialize();
463
464 return returnval;
465}
466
467} // namespace LibUtilities
468} // namespace Nektar
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
std::shared_ptr< NodalUtilPrism > m_util
virtual void v_CalculateDerivMatrix() override final
void CalculateInterpMatrix(const Array< OneD, const NekDouble > &xi, const Array< OneD, const NekDouble > &yi, const Array< OneD, const NekDouble > &zi, Array< OneD, NekDouble > &interp)
virtual void v_CalculatePoints() override final
virtual void v_CalculateWeights() override final
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
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
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.
PointsManagerT & PointsManager(void)
@ eNodalTriElec
2D Nodal Electrostatic Points on a Triangle
Definition: PointsType.h:83
@ eGaussLobattoLegendre
1D Gauss-Lobatto-Legendre quadrature points
Definition: PointsType.h:53
@ eNodalPrismElec
3D electrostatically spaced points on a Prism
Definition: PointsType.h:89
std::vector< double > w(NPUPPER)
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1191