Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NodalPrismEvenlySpaced.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File NodalPrismEvenlySpaced.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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: 3D Nodal Prism Evenly Spaced Point Definitions
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 
41 #include <vector>
42 
43 namespace Nektar
44 {
45  namespace LibUtilities
46  {
47  namespace
48  {
49  bool isVertex(int x, int y, int z, int npts)
50  {
51  return (x == 0 && y == 0 && z == 0 ) ||
52  (x == (npts-1) && y == 0 && z == 0 ) ||
53  (x == (npts-1) && y == (npts-1) && z == 0 ) ||
54  (x == 0 && y == (npts-1) && z == 0 ) ||
55  (x == 0 && y == 0 && z == (npts-1)) ||
56  (x == 0 && y == (npts-1) && z == (npts-1));
57  }
58 
59  bool isEdge_01(int x, int y, int z, int npts)
60  {
61  return y == 0 && z == 0;
62  }
63 
64  bool isEdge_12(int x, int y, int z, int npts)
65  {
66  return x == (npts-1) && z == 0;
67  }
68 
69  bool isEdge_23(int x, int y, int z, int npts)
70  {
71  return y == (npts-1) && z == 0;
72  }
73 
74  bool isEdge_30(int x, int y, int z, int npts)
75  {
76  return x == 0 && z == 0;
77  }
78 
79  bool isEdge_04(int x, int y, int z, int npts)
80  {
81  return x == 0 && y == 0;
82  }
83 
84  bool isEdge_14(int x, int y, int z, int npts)
85  {
86  return x + z == (npts-1) && y == 0;
87  }
88 
89  bool isEdge_25(int x, int y, int z, int npts)
90  {
91  return x + z == (npts-1) && y == (npts-1);
92  }
93 
94  bool isEdge_35(int x, int y, int z, int npts)
95  {
96  return x == 0 && y == (npts-1);
97  }
98 
99  bool isEdge_45(int x, int y, int z, int npts)
100  {
101  return x == 0 && z == (npts-1);
102  }
103 
104  bool isEdge(int x, int y, int z, int npts){
105  return isEdge_01(x,y,z,npts) || isEdge_12(x,y,z,npts) ||
106  isEdge_23(x,y,z,npts) || isEdge_30(x,y,z,npts) ||
107  isEdge_04(x,y,z,npts) || isEdge_14(x,y,z,npts) ||
108  isEdge_25(x,y,z,npts) || isEdge_35(x,y,z,npts) ||
109  isEdge_45(x,y,z,npts);
110  }
111 
112  bool isFace_0123(int x, int y, int z, int npts)
113  {
114  return z == 0;
115  }
116 
117  bool isFace_014(int x, int y, int z, int npts)
118  {
119  return y == 0;
120  }
121 
122  bool isFace_1254(int x, int y, int z, int npts)
123  {
124  return x + z == npts-1;
125  }
126 
127  bool isFace_325(int x, int y, int z, int npts)
128  {
129  return y == (npts-1);
130  }
131 
132  bool isFace_0354(int x, int y, int z, int npts)
133  {
134  return x == 0;
135  }
136 
137  bool isFace(int x, int y, int z, int npts){
138  return isFace_0123(x,y,z,npts) || isFace_014(x,y,z,npts) ||
139  isFace_1254(x,y,z,npts) || isFace_325(x,y,z,npts) ||
140  isFace_0354(x,y,z,npts);
141  }
142  }
143 
144  // Calculate evenly spaced number of points
146  {
147  // Allocate the storage for points
149 
150  // Populate m_points
151  unsigned int npts = GetNumPoints();
152  NekDouble delta = 2.0/(npts - 1.0);
153  for(unsigned int z=0, index=0; z<npts; ++z){
154  for(int y=0; y<npts; ++y){
155  for(int x=0; x<npts-z; ++x, ++index){
156  NekDouble xi = -1.0 + x*delta;
157  NekDouble yi = -1.0 + y*delta;
158  NekDouble zi = -1.0 + z*delta;
159 
160  m_points[0][index] = xi;
161  m_points[1][index] = yi;
162  m_points[2][index] = zi;
163  }
164  }
165  }
166 
169  npts - 1, m_points[0], m_points[1], m_points[2]);
170  }
171 
173  {
174  unsigned int npts = GetNumPoints();
175  using std::vector;
176  vector<int> vertex;
177  vector<int> iEdge_01; // interior edge 0
178  vector<int> iEdge_12; // interior edge 1
179  vector<int> iEdge_23; // interior edge 2
180  vector<int> iEdge_30; // interior edge 3
181  vector<int> iEdge_04; // interior edge 4
182  vector<int> iEdge_14; // interior edge 5
183  vector<int> iEdge_25; // interior edge 6
184  vector<int> iEdge_35; // interior edge 7
185  vector<int> iEdge_45; // interior edge 8
186  vector<int> iFace_0123; // interior face 0
187  vector<int> iFace_014; // interior face 1
188  vector<int> iFace_1254; // interior face 2
189  vector<int> iFace_325; // interior face 3
190  vector<int> iFace_0354; // interior face 4
191  vector<int> interiorVolumePoints; // interior volume points
192  vector<int> map;
193 
194  // Build the lattice prism left to right - bottom to top
195  for(int z=0, index=0; z<npts; ++z){
196  for(int y=0; y<npts; ++y){
197  for(int x=0; x<npts-z; ++x, ++index){
198  if (isVertex(x,y,z,npts))
199  {
200  vertex.push_back(index);
201  }
202  else if (isEdge(x,y,z,npts))
203  {
204  if (isEdge_01(x,y,z,npts))
205  {
206  iEdge_01.push_back(index);
207  }
208  else if (isEdge_12(x,y,z,npts))
209  {
210  iEdge_12.push_back(index);
211  }
212  else if (isEdge_23(x,y,z,npts))
213  {
214  iEdge_23.push_back(index);
215  }
216  else if (isEdge_30(x,y,z,npts))
217  {
218  iEdge_30.push_back(index);
219  }
220  else if (isEdge_04(x,y,z,npts))
221  {
222  iEdge_04.push_back(index);
223  }
224  else if (isEdge_14(x,y,z,npts))
225  {
226  iEdge_14.push_back(index);
227  }
228  else if (isEdge_25(x,y,z,npts))
229  {
230  iEdge_25.push_back(index);
231  }
232  else if (isEdge_35(x,y,z,npts))
233  {
234  iEdge_35.push_back(index);
235  }
236  else if (isEdge_45(x,y,z,npts))
237  {
238  iEdge_45.push_back(index);
239  }
240  }
241  else if (isFace(x,y,z,npts))
242  {
243  if (isFace_0123(x,y,z,npts))
244  {
245  iFace_0123.push_back(index);
246  }
247  else if (isFace_014(x,y,z,npts))
248  {
249  iFace_014.push_back(index);
250  }
251  else if (isFace_1254(x,y,z,npts))
252  {
253  iFace_1254.push_back(index);
254  }
255  else if (isFace_325(x,y,z,npts))
256  {
257  iFace_325.push_back(index);
258  }
259  else if (isFace_0354(x,y,z,npts))
260  {
261  iFace_0354.push_back(index);
262  }
263  }
264  else
265  {
266  interiorVolumePoints.push_back(index);
267  }
268  }
269  }
270  }
271 
272  for (unsigned int n=0; n<vertex.size(); ++n)
273  {
274  map.push_back(vertex[n]);
275  }
276 
277  for (unsigned int n=0; n<iEdge_01.size(); ++n)
278  {
279  map.push_back(iEdge_01[n]);
280  }
281 
282  for (unsigned int n=0; n<iEdge_12.size(); ++n)
283  {
284  map.push_back(iEdge_12[n]);
285  }
286 
287  for (unsigned int n=0; n<iEdge_23.size(); ++n)
288  {
289  map.push_back(iEdge_23[n]);
290  }
291 
292  for (unsigned int n=0; n<iEdge_30.size(); ++n)
293  {
294  map.push_back(iEdge_30[n]);
295  }
296 
297  for (unsigned int n=0; n<iEdge_04.size(); ++n)
298  {
299  map.push_back(iEdge_04[n]);
300  }
301 
302  for (unsigned int n=0; n<iEdge_14.size(); ++n)
303  {
304  map.push_back(iEdge_14[n]);
305  }
306 
307  for (unsigned int n=0; n<iEdge_25.size(); ++n)
308  {
309  map.push_back(iEdge_25[n]);
310  }
311 
312  for (unsigned int n=0; n<iEdge_35.size(); ++n)
313  {
314  map.push_back(iEdge_35[n]);
315  }
316 
317  for (unsigned int n=0; n<iEdge_45.size(); ++n)
318  {
319  map.push_back(iEdge_45[n]);
320  }
321 
322  for (unsigned int n=0; n<iFace_0123.size(); ++n)
323  {
324  map.push_back(iFace_0123[n]);
325  }
326 
327  for (unsigned int n=0; n<iFace_014.size(); ++n)
328  {
329  map.push_back(iFace_014[n]);
330  }
331 
332  for(unsigned int n=0; n<iFace_1254.size(); ++n)
333  {
334  map.push_back(iFace_1254[n]);
335  }
336 
337  for(unsigned int n=0; n<iFace_325.size(); ++n)
338  {
339  map.push_back(iFace_325[n]);
340  }
341 
342  for(unsigned int n=0; n<iFace_0354.size(); ++n)
343  {
344  map.push_back(iFace_0354[n]);
345  }
346 
347  for(unsigned int n=0; n<interiorVolumePoints.size(); ++n)
348  {
349  map.push_back(interiorVolumePoints[n]);
350  }
351 
352  Array<OneD, NekDouble> points[3];
356 
357  for(unsigned int index=0; index<map.size(); ++index)
358  {
359  points[0][index] = m_points[0][index];
360  points[1][index] = m_points[1][index];
361  points[2][index] = m_points[2][index];
362  }
363 
364  for(unsigned int index=0; index<map.size(); ++index)
365  {
366  m_points[0][index] = points[0][map[index]];
367  m_points[1][index] = points[1][map[index]];
368  m_points[2][index] = points[2][map[index]];
369  }
370  }
371 
373  {
374  // Allocate the storage for points
376 
377  typedef DataType T;
378 
379  // Solve the Vandermonde system of integrals for the weight vector
380  NekVector<T> w = m_util->GetWeights();
381 
382  m_weights = Array<OneD,T>( w.GetRows(), w.GetPtr() );
383  }
384 
385 
386  // ////////////////////////////////////////
387  // CalculateInterpMatrix()
389  const Array<OneD, const NekDouble>& yia,
390  const Array<OneD, const NekDouble>& zia,
391  Array<OneD, NekDouble>& interp)
392  {
394  xi[0] = xia;
395  xi[1] = yia;
396  xi[2] = zia;
397 
398  boost::shared_ptr<NekMatrix<NekDouble> > mat =
399  m_util->GetInterpolationMatrix(xi);
400  Vmath::Vcopy(mat->GetRows() * mat->GetColumns(), mat->GetRawPtr(),
401  1, &interp[0], 1);
402  }
403 
404  // ////////////////////////////////////////
405  // CalculateDerivMatrix()
407  {
408  // Allocate the derivative matrix.
410 
411  m_derivmatrix[0] = m_util->GetDerivMatrix(0);
412  m_derivmatrix[1] = m_util->GetDerivMatrix(1);
413  m_derivmatrix[2] = m_util->GetDerivMatrix(2);
414  }
415 
416  boost::shared_ptr<PointsBaseType> NodalPrismEvenlySpaced::Create(const PointsKey &key)
417  {
418  boost::shared_ptr<PointsBaseType> returnval(MemoryManager<NodalPrismEvenlySpaced>::AllocateSharedPtr(key));
419 
420  returnval->Initialize();
421 
422  return returnval;
423  }
424  } // end of namespace
425 } // end of namespace
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 boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
MatrixSharedPtrType m_derivmatrix[3]
Definition: Points.h:373
Array< OneD, DataType > m_points[3]
Definition: Points.h:371
boost::shared_ptr< NodalUtilPrism > m_util
unsigned int GetNumPoints() const
Definition: Points.h:268
static std::string npts
Definition: InputFld.cpp:43
Array< OneD, DataType > m_weights
Definition: Points.h:372
Defines a specification for a set of points.
Definition: Points.h:58
double NekDouble
unsigned int GetRows() const
Definition: NekVector.cpp:218
static boost::shared_ptr< PointsBaseType > Create(const PointsKey &key)
unsigned int GetTotNumPoints() const
Definition: Points.h:273
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
Array< OneD, DataType > & GetPtr()
Definition: NekVector.cpp:230