Nektar++
Loading...
Searching...
No Matches
NodalPyrEvenlySpaced.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: NodalPyrEvenlySpaced.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 Pyramid Evenly Spaced Point Definitions
32//
33///////////////////////////////////////////////////////////////////////////////
34
36#include <vector>
37
39{
41 PointsManager().RegisterCreator(PointsKey(0, eNodalPyrEvenlySpaced),
43
44// Local vertex/edge/face numbering for the standard pyramid:
45//
46// Base square (z == 0): v0 = (0,0,0), v1 = (npts-1,0,0),
47// v2 = (npts-1,npts-1,0), v3 = (0,npts-1,0)
48// Apex: v4 = (0,0,npts-1)
49//
50// Edges: e01, e12, e23, e30 (base), e04, e14, e24, e34 (to apex)
51// Faces: f0123 (base quad), f014, f124, f234, f034 (triangles)
52//
53// Unlike the prism -- whose cross-section only collapses in one direction as
54// z increases, since it is a uniform extrusion in y -- the pyramid collapses
55// in *both* x and y simultaneously as z increases, tapering to the single
56// apex point at z == npts-1. This is why the loop bounds and edge/face
57// predicates below involve both (x+z) and (y+z), rather than just x as in
58// the prism case.
59namespace
60{
61bool isVertex(size_t x, size_t y, size_t z, size_t npts)
62{
63 return (x == 0 && y == 0 && z == 0) ||
64 (x == (npts - 1) && y == 0 && z == 0) ||
65 (x == (npts - 1) && y == (npts - 1) && z == 0) ||
66 (x == 0 && y == (npts - 1) && z == 0) ||
67 (x == 0 && y == 0 && z == (npts - 1));
68}
69
70bool isEdge_01([[maybe_unused]] size_t x, size_t y, size_t z,
71 [[maybe_unused]] size_t npts)
72{
73 return y == 0 && z == 0;
74}
75
76bool isEdge_12(size_t x, [[maybe_unused]] size_t y, size_t z, size_t npts)
77{
78 return x == (npts - 1) && z == 0;
79}
80
81bool isEdge_23([[maybe_unused]] size_t x, size_t y, size_t z, size_t npts)
82{
83 return y == (npts - 1) && z == 0;
84}
85
86bool isEdge_30(size_t x, [[maybe_unused]] size_t y, size_t z,
87 [[maybe_unused]] size_t npts)
88{
89 return x == 0 && z == 0;
90}
91
92bool isEdge_04(size_t x, size_t y, [[maybe_unused]] size_t z,
93 [[maybe_unused]] size_t npts)
94{
95 return x == 0 && y == 0;
96}
97
98bool isEdge_14(size_t x, size_t y, size_t z, size_t npts)
99{
100 return y == 0 && (x + z) == (npts - 1);
101}
102
103bool isEdge_24(size_t x, size_t y, size_t z, size_t npts)
104{
105 return (x + z) == (npts - 1) && (y + z) == (npts - 1);
106}
107
108bool isEdge_34(size_t x, size_t y, size_t z, size_t npts)
109{
110 return x == 0 && (y + z) == (npts - 1);
111}
112
113bool isEdge(size_t x, size_t y, size_t z, size_t npts)
114{
115 return isEdge_01(x, y, z, npts) || isEdge_12(x, y, z, npts) ||
116 isEdge_23(x, y, z, npts) || isEdge_30(x, y, z, npts) ||
117 isEdge_04(x, y, z, npts) || isEdge_14(x, y, z, npts) ||
118 isEdge_24(x, y, z, npts) || isEdge_34(x, y, z, npts);
119}
120
121bool isFace_0123([[maybe_unused]] size_t x, [[maybe_unused]] size_t y, size_t z,
122 [[maybe_unused]] size_t npts)
123{
124 return z == 0;
125}
126
127bool isFace_014([[maybe_unused]] size_t x, size_t y, [[maybe_unused]] size_t z,
128 [[maybe_unused]] size_t npts)
129{
130 return y == 0;
131}
132
133bool isFace_124(size_t x, [[maybe_unused]] size_t y, size_t z, size_t npts)
134{
135 return (x + z) == (npts - 1);
136}
137
138bool isFace_234([[maybe_unused]] size_t x, size_t y, size_t z, size_t npts)
139{
140 return (y + z) == (npts - 1);
141}
142
143bool isFace_034(size_t x, [[maybe_unused]] size_t y, [[maybe_unused]] size_t z,
144 [[maybe_unused]] size_t npts)
145{
146 return x == 0;
147}
148
149bool isFace(size_t x, size_t y, size_t z, size_t npts)
150{
151 return isFace_0123(x, y, z, npts) || isFace_014(x, y, z, npts) ||
152 isFace_124(x, y, z, npts) || isFace_234(x, y, z, npts) ||
153 isFace_034(x, y, z, npts);
154}
155} // namespace
156
157// Calculate evenly spaced number of points
159{
160 // Allocate the storage for points
162
163 // Populate m_points
164 size_t npts = GetNumPoints();
165 NekDouble delta = 2.0 / (npts - 1.0);
166 for (size_t z = 0, index = 0; z < npts; ++z)
167 {
168 for (size_t y = 0; y < npts - z; ++y)
169 {
170 for (size_t x = 0; x < npts - z; ++x, ++index)
171 {
172 NekDouble xi = -1.0 + x * delta;
173 NekDouble yi = -1.0 + y * delta;
174 NekDouble zi = -1.0 + z * delta;
175
176 m_points[0][index] = xi;
177 m_points[1][index] = yi;
178 m_points[2][index] = zi;
179 }
180 }
181 }
182
185 npts - 1, m_points[0], m_points[1], m_points[2]);
186}
187
189{
190 size_t npts = GetNumPoints();
191 using std::vector;
192 vector<int> vertex;
193 vector<int> iEdge_01; // interior edge 0
194 vector<int> iEdge_12; // interior edge 1
195 vector<int> iEdge_23; // interior edge 2
196 vector<int> iEdge_30; // interior edge 3
197 vector<int> iEdge_04; // interior edge 4
198 vector<int> iEdge_14; // interior edge 5
199 vector<int> iEdge_24; // interior edge 6
200 vector<int> iEdge_34; // interior edge 7
201 vector<int> iFace_0123; // interior face 0 (base quad)
202 vector<int> iFace_014; // interior face 1
203 vector<int> iFace_124; // interior face 2
204 vector<int> iFace_234; // interior face 3
205 vector<int> iFace_034; // interior face 4
206 vector<int> interiorVolumePoints; // interior volume points
207 vector<int> map;
208
209 // Build the lattice pyramid left to right - bottom to top. Note that,
210 // unlike the prism, both the x and y extents shrink together as z
211 // increases, since the pyramid tapers to a single apex point rather than
212 // an edge.
213 for (size_t z = 0, index = 0; z < npts; ++z)
214 {
215 for (size_t y = 0; y < npts - z; ++y)
216 {
217 for (size_t x = 0; x < npts - z; ++x, ++index)
218 {
219 if (isVertex(x, y, z, npts))
220 {
221 vertex.push_back(index);
222 }
223 else if (isEdge(x, y, z, npts))
224 {
225 if (isEdge_01(x, y, z, npts))
226 {
227 iEdge_01.push_back(index);
228 }
229 else if (isEdge_12(x, y, z, npts))
230 {
231 iEdge_12.push_back(index);
232 }
233 else if (isEdge_23(x, y, z, npts))
234 {
235 iEdge_23.push_back(index);
236 }
237 else if (isEdge_30(x, y, z, npts))
238 {
239 iEdge_30.push_back(index);
240 }
241 else if (isEdge_04(x, y, z, npts))
242 {
243 iEdge_04.push_back(index);
244 }
245 else if (isEdge_14(x, y, z, npts))
246 {
247 iEdge_14.push_back(index);
248 }
249 else if (isEdge_24(x, y, z, npts))
250 {
251 iEdge_24.push_back(index);
252 }
253 else if (isEdge_34(x, y, z, npts))
254 {
255 iEdge_34.push_back(index);
256 }
257 }
258 else if (isFace(x, y, z, npts))
259 {
260 if (isFace_0123(x, y, z, npts))
261 {
262 iFace_0123.push_back(index);
263 }
264 else if (isFace_014(x, y, z, npts))
265 {
266 iFace_014.push_back(index);
267 }
268 else if (isFace_124(x, y, z, npts))
269 {
270 iFace_124.push_back(index);
271 }
272 else if (isFace_234(x, y, z, npts))
273 {
274 iFace_234.push_back(index);
275 }
276 else if (isFace_034(x, y, z, npts))
277 {
278 iFace_034.push_back(index);
279 }
280 }
281 else
282 {
283 interiorVolumePoints.push_back(index);
284 }
285 }
286 }
287 }
288
289 // The lattice walks the base in raster order, which puts the corner at
290 // (-1, 1, -1) third; the standard pyramid numbers that corner 3, so the
291 // two middle slots are the wrong way round.
292 std::swap(vertex[2], vertex[3]);
293
294 for (size_t n = 0; n < vertex.size(); ++n)
295 {
296 map.push_back(vertex[n]);
297 }
298
299 for (size_t n = 0; n < iEdge_01.size(); ++n)
300 {
301 map.push_back(iEdge_01[n]);
302 }
303
304 for (size_t n = 0; n < iEdge_12.size(); ++n)
305 {
306 map.push_back(iEdge_12[n]);
307 }
308
309 for (size_t n = 0; n < iEdge_23.size(); ++n)
310 {
311 map.push_back(iEdge_23[n]);
312 }
313
314 for (size_t n = 0; n < iEdge_30.size(); ++n)
315 {
316 map.push_back(iEdge_30[n]);
317 }
318
319 for (size_t n = 0; n < iEdge_04.size(); ++n)
320 {
321 map.push_back(iEdge_04[n]);
322 }
323
324 for (size_t n = 0; n < iEdge_14.size(); ++n)
325 {
326 map.push_back(iEdge_14[n]);
327 }
328
329 for (size_t n = 0; n < iEdge_24.size(); ++n)
330 {
331 map.push_back(iEdge_24[n]);
332 }
333
334 for (size_t n = 0; n < iEdge_34.size(); ++n)
335 {
336 map.push_back(iEdge_34[n]);
337 }
338
339 for (size_t n = 0; n < iFace_0123.size(); ++n)
340 {
341 map.push_back(iFace_0123[n]);
342 }
343
344 for (size_t n = 0; n < iFace_014.size(); ++n)
345 {
346 map.push_back(iFace_014[n]);
347 }
348
349 for (size_t n = 0; n < iFace_124.size(); ++n)
350 {
351 map.push_back(iFace_124[n]);
352 }
353
354 for (size_t n = 0; n < iFace_234.size(); ++n)
355 {
356 map.push_back(iFace_234[n]);
357 }
358
359 for (size_t n = 0; n < iFace_034.size(); ++n)
360 {
361 map.push_back(iFace_034[n]);
362 }
363
364 for (size_t n = 0; n < interiorVolumePoints.size(); ++n)
365 {
366 map.push_back(interiorVolumePoints[n]);
367 }
368
369 Array<OneD, NekDouble> points[3];
373
374 for (size_t index = 0; index < map.size(); ++index)
375 {
376 points[0][index] = m_points[0][index];
377 points[1][index] = m_points[1][index];
378 points[2][index] = m_points[2][index];
379 }
380
381 for (size_t index = 0; index < map.size(); ++index)
382 {
383 m_points[0][index] = points[0][map[index]];
384 m_points[1][index] = points[1][map[index]];
385 m_points[2][index] = points[2][map[index]];
386 }
387}
388
390{
391 // Allocate the storage for points
393
394 typedef DataType T;
395
396 // Solve the Vandermonde system of integrals for the weight vector
397 NekVector<T> w = m_util->GetWeights();
398
399 m_weights = Array<OneD, T>(w.GetRows(), w.GetPtr());
400}
401
402// ////////////////////////////////////////
403// CalculateInterpMatrix()
408{
410 xi[0] = xia;
411 xi[1] = yia;
412 xi[2] = zia;
413
414 std::shared_ptr<NekMatrix<NekDouble>> mat =
415 m_util->GetInterpolationMatrix(xi);
416 Vmath::Vcopy(mat->GetRows() * mat->GetColumns(), mat->GetRawPtr(), 1,
417 &interp[0], 1);
418}
419
420// ////////////////////////////////////////
421// CalculateDerivMatrix()
423{
424 // Allocate the derivative matrix.
425 PointsBaseType::v_CalculateDerivMatrix();
426
427 m_derivmatrix[0] = m_util->GetDerivMatrix(0);
428 m_derivmatrix[1] = m_util->GetDerivMatrix(1);
429 m_derivmatrix[2] = m_util->GetDerivMatrix(2);
430}
431
432std::shared_ptr<PointsBaseType> NodalPyrEvenlySpaced::Create(
433 const PointsKey &key)
434{
435 std::shared_ptr<PointsBaseType> returnval(
437
438 returnval->Initialize();
439
440 return returnval;
441}
442} // namespace Nektar::LibUtilities
void CalculateInterpMatrix(const Array< OneD, const NekDouble > &xi, const Array< OneD, const NekDouble > &yi, const Array< OneD, const NekDouble > &zi, Array< OneD, NekDouble > &interp)
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:434
MatrixSharedPtrType m_derivmatrix[3]
Derivative matrices.
Definition Points.h:440
Array< OneD, DataType > m_weights
Quadrature weights for the weights.
Definition Points.h:436
Defines a specification for a set of points.
Definition Points.h:50
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)
@ eNodalPyrEvenlySpaced
3D Nodal Pyramid evenly spaced points
Definition PointsType.h:99
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:828