Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NodalTetEvenlySpaced.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File NodalTetEvenlySpaced.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 Tetrahedron Evenly Spaced Point Definitions
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
42 #include <vector>
43 
44 
45 
46 namespace Nektar
47 {
48  namespace LibUtilities
49  {
50  namespace
51  {
52  // construct the geometory and set the coordinate of tetrahedron
53  // edges and vertices are ordered as anticlockwise
54 
55  bool isVertex(int x, int y, int z, int npts){
56  return (x==0 && y==0 && z==0) || (x==(npts-1) && y==0 && z==0) || (x==0 && y==(npts-1) && z==0) || (x==0 && y==0 && z==(npts-1));
57  }
58 
59  bool isEdge_01(int x, int y, int z, int npts){ // edge 0
60  return y==0 && z==0;
61  }
62 
63  bool isEdge_12(int x, int y, int z, int npts){ // edge 1
64  return z==0 && x + y == npts -1;
65  }
66 
67  bool isEdge_20(int x, int y, int z, int npts){ // edge 2
68  return x==0 && z==0;
69  }
70 
71  bool isEdge_03(int x, int y, int z, int npts){ // edge 3
72  return x==0 && y==0;
73  }
74 
75  bool isEdge_13(int x, int y, int z, int npts){ // edge 4
76  return y==0 && x + z == npts -1;
77  }
78 
79  bool isEdge_23(int x, int y, int z, int npts){ // edge 5
80  return x==0 && y + z == npts -1;
81  }
82 
83  bool isEdge(int x, int y, int z, int npts){
84  return isEdge_01(x,y,z,npts)||isEdge_12(x,y,z,npts)||isEdge_20(x,y,z,npts)
85  ||isEdge_03(x,y,z,npts)||isEdge_13(x,y,z,npts)||isEdge_23(x,y,z,npts);
86  }
87 
88  bool isFace_012(int x, int y, int z, int npts){ // bottom face (face 0)
89  return z==0;
90  }
91 
92  bool isFace_013(int x, int y, int z, int npts){ // face 1
93  return y==0;
94  }
95 
96  bool isFace_123(int x, int y, int z, int npts){ // face 2
97  return x+y+z==npts-1;
98  }
99 
100  bool isFace_203(int x, int y, int z, int npts){ // face 3
101  return x==0;
102  }
103 
104  bool isFace(int x, int y, int z, int npts){
105  return isFace_012(x, y, z, npts) || isFace_013(x, y, z, npts)
106  || isFace_123(x, y, z, npts) || isFace_203(x, y, z, npts);
107  }
108  }
109 
110  // Calculate evenly spaced number of points
112  {
113  // Allocate the storage for points
115 
116  // Populate m_points
117  unsigned int npts = GetNumPoints();
118  NekDouble delta = 2.0/(npts - 1.0);
119  for(unsigned int z=0, index=0; z<npts; ++z){
120  for(int y=0; y<npts-z; ++y){
121  for(int x=0; x<npts-z-y; ++x, ++index){
122  NekDouble xi = -1.0 + x*delta;
123  NekDouble yi = -1.0 + y*delta;
124  NekDouble zi = -1.0 + z*delta;
125 
126  m_points[0][index] = xi;
127  m_points[1][index] = yi;
128  m_points[2][index] = zi;
129  }
130  }
131  }
132 
135  npts - 1, m_points[0], m_points[1], m_points[2]);
136  }
137 
139  {
140  unsigned int npts = GetNumPoints();
141  using std::vector;
142  vector<int> vertex;
143  vector<int> iEdge_01; // interior edge 0
144  vector<int> iEdge_12; // interior edge 1
145  vector<int> iEdge_20; // interior edge 2
146  vector<int> iEdge_03; // interior edge 3
147  vector<int> iEdge_13; // interior edge 4
148  vector<int> iEdge_23; // interior edge 5
149  vector<int> iFace_012; // interior face 0
150  vector<int> iFace_013; // interior face 1
151  vector<int> iFace_123; // interior face 2
152  vector<int> iFace_203; // interior face 3
153  vector<int> interiorVolumePoints; // interior volume points
154  vector<int> map;
155 
156  // Build the lattice tetrahedron left to right - bottom to top
157  for(int z=0, index=0; z<npts; ++z){
158  for(int y=0; y<npts-z; ++y){
159  for(int x=0; x<npts-z-y; ++x, ++index){
160 
161  if( isVertex(x,y,z,npts) ){ // vertex
162 
163  vertex.push_back(index);
164 
165  } else if( isEdge(x,y,z,npts) ){ // interior edge
166 
167  if( isEdge_01(x,y,z,npts) ){ // interior edge 0
168 
169  iEdge_01.push_back(index);
170 
171  } else if( isEdge_12(x,y,z,npts) ){ // interior edge 1
172 
173  iEdge_12.push_back(index);
174 
175  } else if( isEdge_20(x,y,z,npts) ){ // interior edge 2
176 
177  iEdge_20.insert(iEdge_20.begin(), index);
178 
179  } else if( isEdge_03(x,y,z,npts) ){ // interior edge 3
180 
181  iEdge_03.push_back(index);
182 
183  } else if( isEdge_13(x,y,z,npts) ){ // interior edge 4
184 
185  iEdge_13.push_back(index);
186 
187  } else if( isEdge_23(x,y,z,npts) ){ // interior edge 5
188 
189  iEdge_23.push_back(index);
190 
191  }
192 
193  } else if( isFace(x,y,z,npts) ) { // interior face
194 
195  if( isFace_012(x,y,z,npts) ){ // interior face 0
196 
197  iFace_012.push_back(index);
198 
199  } else if( isFace_013(x,y,z,npts) ){ // interior face 1
200 
201  iFace_013.push_back(index);
202 
203  } else if( isFace_123(x,y,z,npts) ){ // interior face 2
204 
205  iFace_123.push_back(index);
206 
207  } else if( isFace_203(x,y,z,npts) ){ // interior face 3
208 
209  iFace_203.push_back(index);
210 
211  }
212  } else { // interior volume points
213 
214  interiorVolumePoints.push_back(index);
215  }
216  }
217  }
218  }
219 
220  // Mapping the vertex, edges, faces, interior volume points using the permutation matrix,
221  // so the points are ordered anticlockwise.
222  for(unsigned int n=0; n<vertex.size(); ++n){
223 
224  map.push_back(vertex[n]);
225  }
226 
227  for(unsigned int n=0; n<iEdge_01.size(); ++n){
228 
229  map.push_back(iEdge_01[n]);
230  }
231 
232  for(unsigned int n=0; n<iEdge_12.size(); ++n){
233 
234  map.push_back(iEdge_12[n]);
235  }
236 
237  for(unsigned int n=0; n<iEdge_20.size(); ++n){
238 
239  map.push_back(iEdge_20[n]);
240  }
241 
242  for(unsigned int n=0; n<iEdge_03.size(); ++n){
243 
244  map.push_back(iEdge_03[n]);
245  }
246 
247  for(unsigned int n=0; n<iEdge_13.size(); ++n){
248 
249  map.push_back(iEdge_13[n]);
250  }
251 
252  for(unsigned int n=0; n<iEdge_23.size(); ++n){
253 
254  map.push_back(iEdge_23[n]);
255  }
256 
257  for(unsigned int n=0; n<iFace_012.size(); ++n){
258 
259  map.push_back(iFace_012[n]);
260  }
261 
262  for(unsigned int n=0; n<iFace_013.size(); ++n){
263 
264  map.push_back(iFace_013[n]);
265  }
266 
267  for(unsigned int n=0; n<iFace_123.size(); ++n){
268 
269  map.push_back(iFace_123[n]);
270  }
271 
272  for(unsigned int n=0; n<iFace_203.size(); ++n){
273 
274  map.push_back(iFace_203[n]);
275  }
276 
277  for(unsigned int n=0; n<interiorVolumePoints.size(); ++n){
278 
279  map.push_back(interiorVolumePoints[n]);
280  }
281 
282 
283  Array<OneD, NekDouble> points[3];
287  for(unsigned int index=0; index<map.size(); ++index){
288 
289  points[0][index] = m_points[0][index];
290  points[1][index] = m_points[1][index];
291  points[2][index] = m_points[2][index];
292 
293  }
294 
295  for(unsigned int index=0; index<map.size(); ++index){
296 
297  m_points[0][index] = points[0][map[index]];
298  m_points[1][index] = points[1][map[index]];
299  m_points[2][index] = points[2][map[index]];
300 
301  }
302 
303  }
304 
305 
306 
308  {
309  // Allocate storage for points
311 
312  typedef DataType T;
313 
314  // Solve the Vandermonde system of integrals for the weight vector
315  NekVector<T> w = m_util->GetWeights();
316  m_weights = Array<OneD,T>( w.GetRows(), w.GetPtr() );
317  }
318 
319 
320  // ////////////////////////////////////////
321  // CalculateInterpMatrix()
323  const Array<OneD, const NekDouble>& yia,
324  const Array<OneD, const NekDouble>& zia,
325  Array<OneD, NekDouble>& interp)
326  {
328  xi[0] = xia;
329  xi[1] = yia;
330  xi[2] = zia;
331 
332  boost::shared_ptr<NekMatrix<NekDouble> > mat =
333  m_util->GetInterpolationMatrix(xi);
334  Vmath::Vcopy(mat->GetRows() * mat->GetColumns(), mat->GetRawPtr(),
335  1, &interp[0], 1);
336  }
337 
338  // ////////////////////////////////////////
339  // CalculateDerivMatrix()
341  {
342  // Allocate the derivative matrix.
344 
345  m_derivmatrix[0] = m_util->GetDerivMatrix(0);
346  m_derivmatrix[1] = m_util->GetDerivMatrix(1);
347  m_derivmatrix[2] = m_util->GetDerivMatrix(2);
348  }
349 
350  boost::shared_ptr<PointsBaseType> NodalTetEvenlySpaced::Create(const PointsKey &key)
351  {
352  boost::shared_ptr<PointsBaseType> returnval(MemoryManager<NodalTetEvenlySpaced>::AllocateSharedPtr(key));
353 
354  returnval->Initialize();
355 
356  return returnval;
357  }
358 
359 
360 
361  } // end of namespace
362 } // end of namespace
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...
void CalculateInterpMatrix(const Array< OneD, const NekDouble > &xi, const Array< OneD, const NekDouble > &yi, const Array< OneD, const NekDouble > &zi, Array< OneD, NekDouble > &interp)
MatrixSharedPtrType m_derivmatrix[3]
Definition: Points.h:373
Array< OneD, DataType > m_points[3]
Definition: Points.h:371
static boost::shared_ptr< PointsBaseType > Create(const PointsKey &key)
unsigned int GetNumPoints() const
Definition: Points.h:268
static std::string npts
Definition: InputFld.cpp:43
boost::shared_ptr< NodalUtilTetrahedron > m_util
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
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