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