Nektar++
NodalTriEvenlySpaced.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File NodalTriEvenlySpaced.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: 2D Nodal Triangle Evenly Spaced Point Definitions
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/core/ignore_unused.hpp>
36 
43 #include <vector>
44 
45 
46 
47 namespace Nektar
48 {
49  namespace LibUtilities
50  {
53  };
54 
55  namespace
56  {
57  // construct the geometory and set the coordinate of triangle
58  // edges and vertices are ordered as anticlockwise
59  bool isVertex(int i, int j, int npts){
60  return (i==0 && j==0) || (i==(npts-1) && j==0) || (i==0 && j==(npts-1));
61  }
62 
63  bool isEdge(int i, int j, int npts){
64  return i==0 || j==0 || i+j==npts-1; //i+j=tot num of steps
65  }
66 
67  bool isEdge_1(int i, int j, int npts){
68  boost::ignore_unused(j, npts);
69  return i==0;
70  }
71 
72  bool isEdge_2(int i, int j, int npts){
73  return i+j==npts-1;
74  }
75  }
76 
77 
79  {
80  // Allocate the storage for points
82 
83  // Populate m_points
84  unsigned int npts = GetNumPoints();
85  NekDouble delta = 2.0/(npts - 1.0);
86  for(int i=0, index=0; i<npts; ++i){ // y-direction
87  for(int j=0; j<npts-i; ++j,++index){ // x-direction
88  NekDouble x = -1.0 + j*delta;
89  NekDouble y = -1.0 + i*delta;
90  m_points[0][index] = x;
91  m_points[1][index] = y;
92  }
93  }
94 
96 
98  npts - 1, m_points[0], m_points[1]);
99  }
100 
101 
103  {
104  // Allocate the storage for points
106 
107  typedef DataType T;
108 
109  // Solve the Vandermonde system of integrals for the weight vector
110  NekVector<T> w = m_util->GetWeights();
111 
112  m_weights = Array<OneD,T>( w.GetRows(), w.GetPtr() );
113 
114  }
115 
116 
117  // ////////////////////////////////////////
118  // CalculateInterpMatrix()
120  const Array<OneD, const NekDouble>& yia,
121  Array<OneD, NekDouble>& interp)
122  {
124  xi[0] = xia;
125  xi[1] = yia;
126 
127  std::shared_ptr<NekMatrix<NekDouble> > mat =
128  m_util->GetInterpolationMatrix(xi);
129  Vmath::Vcopy(mat->GetRows() * mat->GetColumns(), mat->GetRawPtr(),
130  1, &interp[0], 1);
131  }
132 
133  // ////////////////////////////////////////
134  // CalculateDerivMatrix()
136  {
137 
138  // Allocate the derivative matrix.
140 
141  m_derivmatrix[0] = m_util->GetDerivMatrix(0);
142  m_derivmatrix[1] = m_util->GetDerivMatrix(1);
143  }
144 
145  std::shared_ptr<PointsBaseType> NodalTriEvenlySpaced::Create(const PointsKey &key)
146  {
147  std::shared_ptr<PointsBaseType> returnval(MemoryManager<NodalTriEvenlySpaced>::AllocateSharedPtr(key));
148 
149  returnval->Initialize();
150 
151  return returnval;
152  }
153 
155  {
156  unsigned int npts = GetNumPoints();
157  using std::vector;
158  vector<int> vertex;
159  vector<int> iEdge_1; // interior edge points on the bottom triangle edge
160  vector<int> iEdge_2; // interior edge points on the right triangle edge
161  vector<int> iEdge_3; // interior edge points on the left triangle edge
162  vector<int> interiorPoints;
163  vector<int> map;
164 
165  // Build the lattice triangle left to right - bottom to top
166  for(int i=0, index=0; i<npts; ++i){ // y-direction
167  for(int j=0; j<npts-i; ++j,++index){ // x-direction
168 
169  if( isVertex(i,j,npts) ) {
170 
171  vertex.push_back(index);
172 
173  } else if( isEdge(i,j,npts) ) { // interior edge
174 
175  if(isEdge_1(i,j,npts)){ // bottom edge
176 
177  iEdge_1.push_back(index);
178 
179  }else if(isEdge_2(i,j,npts)){ // right edge
180 
181  iEdge_2.push_back(index);
182 
183  }else // left edge
184  {
185  // Add backwards. This is because of counter clockwise.
186  iEdge_3.insert(iEdge_3.begin(), index);
187  }
188 
189  } else { // Interior points
190 
191  interiorPoints.push_back(index);
192  }
193  }
194  }
195 
196  // Mapping the vertex, edges, and interior points using the permutation matrix,
197  // so the points are ordered anticlockwise.
198  for(unsigned int k=0; k<vertex.size(); ++k){
199 
200  map.push_back(vertex[k]);
201  }
202 
203  for(unsigned int k=0; k<iEdge_1.size(); ++k){
204 
205  map.push_back(iEdge_1[k]);
206  }
207 
208  for(unsigned int k=0; k<iEdge_2.size(); ++k){
209 
210  map.push_back(iEdge_2[k]);
211  }
212 
213  for(unsigned int k=0; k<iEdge_3.size(); ++k){
214 
215  map.push_back(iEdge_3[k]);
216  }
217 
218  for(unsigned int k=0; k<interiorPoints.size(); ++k){
219 
220  map.push_back(interiorPoints[k]);
221  }
222 
223 
224  Array<OneD,NekDouble> points[2];
225  points[0] = Array<OneD,NekDouble>(GetTotNumPoints());
226  points[1] = Array<OneD,NekDouble>(GetTotNumPoints());
227  for(unsigned int index=0; index<map.size(); ++index){
228  points[0][index] = m_points[0][index];
229  points[1][index] = m_points[1][index];
230  }
231 
232  for(unsigned int index=0; index<map.size(); ++index){
233  m_points[0][index] = points[0][map[index]];
234  m_points[1][index] = points[1][map[index]];
235  }
236 
237  }
238 
239  } // end of namespace
240 } // end of namespace
241 
std::shared_ptr< NodalUtilTriangle > m_util
Array< OneD, DataType > m_weights
Definition: Points.h:382
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, Array< OneD, NekDouble > &interp)
static std::shared_ptr< PointsBaseType > Create(const PointsKey &key)
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
PointsManagerT & PointsManager(void)
Defines a specification for a set of points.
Definition: Points.h:59
double NekDouble
unsigned int GetTotNumPoints() const
Definition: Points.h:277
Array< OneD, DataType > m_points[3]
Definition: Points.h:381
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:166
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:71
unsigned int GetRows() const
Definition: NekVector.cpp:215
MatrixSharedPtrType m_derivmatrix[3]
Definition: Points.h:383
unsigned int GetNumPoints() const
Definition: Points.h:272
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
Array< OneD, DataType > & GetPtr()
Definition: NekVector.cpp:227