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 namespace Nektar
46 {
47 namespace LibUtilities
48 {
52 
53 namespace
54 {
55 // construct the geometory and set the coordinate of triangle
56 // edges and vertices are ordered as anticlockwise
57 bool isVertex(int i, int j, int npts)
58 {
59  return (i == 0 && j == 0) || (i == (npts - 1) && j == 0) ||
60  (i == 0 && j == (npts - 1));
61 }
62 
63 bool isEdge(int i, int j, int npts)
64 {
65  return i == 0 || j == 0 || i + j == npts - 1; // i+j=tot num of steps
66 }
67 
68 bool isEdge_1(int i, int j, int npts)
69 {
70  boost::ignore_unused(j, npts);
71  return i == 0;
72 }
73 
74 bool isEdge_2(int i, int j, int npts)
75 {
76  return i + j == npts - 1;
77 }
78 } // namespace
79 
81 {
82  // Allocate the storage for points
84 
85  // Populate m_points
86  unsigned int npts = GetNumPoints();
87  NekDouble delta = 2.0 / (npts - 1.0);
88  for (int i = 0, index = 0; i < npts; ++i)
89  { // y-direction
90  for (int j = 0; j < npts - i; ++j, ++index)
91  { // x-direction
92  NekDouble x = -1.0 + j * delta;
93  NekDouble y = -1.0 + i * delta;
94  m_points[0][index] = x;
95  m_points[1][index] = y;
96  }
97  }
98 
100 
102  npts - 1, m_points[0], m_points[1]);
103 }
104 
106 {
107  // Allocate the storage for points
109 
110  typedef DataType T;
111 
112  // Solve the Vandermonde system of integrals for the weight vector
113  NekVector<T> w = m_util->GetWeights();
114 
116 }
117 
118 // ////////////////////////////////////////
119 // CalculateInterpMatrix()
121  const Array<OneD, const NekDouble> &xia,
123 {
125  xi[0] = xia;
126  xi[1] = yia;
127 
128  std::shared_ptr<NekMatrix<NekDouble>> mat =
129  m_util->GetInterpolationMatrix(xi);
130  Vmath::Vcopy(mat->GetRows() * mat->GetColumns(), mat->GetRawPtr(), 1,
131  &interp[0], 1);
132 }
133 
134 // ////////////////////////////////////////
135 // CalculateDerivMatrix()
137 {
138 
139  // Allocate the derivative matrix.
141 
142  m_derivmatrix[0] = m_util->GetDerivMatrix(0);
143  m_derivmatrix[1] = m_util->GetDerivMatrix(1);
144 }
145 
146 std::shared_ptr<PointsBaseType> NodalTriEvenlySpaced::Create(
147  const PointsKey &key)
148 {
149  std::shared_ptr<PointsBaseType> returnval(
151 
152  returnval->Initialize();
153 
154  return returnval;
155 }
156 
158 {
159  unsigned int npts = GetNumPoints();
160  using std::vector;
161  vector<int> vertex;
162  vector<int> iEdge_1; // interior edge points on the bottom triangle edge
163  vector<int> iEdge_2; // interior edge points on the right triangle edge
164  vector<int> iEdge_3; // interior edge points on the left triangle edge
165  vector<int> interiorPoints;
166  vector<int> map;
167 
168  // Build the lattice triangle left to right - bottom to top
169  for (int i = 0, index = 0; i < npts; ++i)
170  { // y-direction
171  for (int j = 0; j < npts - i; ++j, ++index)
172  { // x-direction
173 
174  if (isVertex(i, j, npts))
175  {
176 
177  vertex.push_back(index);
178  }
179  else if (isEdge(i, j, npts))
180  { // interior edge
181 
182  if (isEdge_1(i, j, npts))
183  { // bottom edge
184 
185  iEdge_1.push_back(index);
186  }
187  else if (isEdge_2(i, j, npts))
188  { // right edge
189 
190  iEdge_2.push_back(index);
191  }
192  else // left edge
193  {
194  // Add backwards. This is because of counter clockwise.
195  iEdge_3.insert(iEdge_3.begin(), index);
196  }
197  }
198  else
199  { // Interior points
200 
201  interiorPoints.push_back(index);
202  }
203  }
204  }
205 
206  // Mapping the vertex, edges, and interior points using the permutation
207  // matrix, so the points are ordered anticlockwise.
208  for (unsigned int k = 0; k < vertex.size(); ++k)
209  {
210 
211  map.push_back(vertex[k]);
212  }
213 
214  for (unsigned int k = 0; k < iEdge_1.size(); ++k)
215  {
216 
217  map.push_back(iEdge_1[k]);
218  }
219 
220  for (unsigned int k = 0; k < iEdge_2.size(); ++k)
221  {
222 
223  map.push_back(iEdge_2[k]);
224  }
225 
226  for (unsigned int k = 0; k < iEdge_3.size(); ++k)
227  {
228 
229  map.push_back(iEdge_3[k]);
230  }
231 
232  for (unsigned int k = 0; k < interiorPoints.size(); ++k)
233  {
234 
235  map.push_back(interiorPoints[k]);
236  }
237 
238  Array<OneD, NekDouble> points[2];
241  for (unsigned int index = 0; index < map.size(); ++index)
242  {
243  points[0][index] = m_points[0][index];
244  points[1][index] = m_points[1][index];
245  }
246 
247  for (unsigned int index = 0; index < map.size(); ++index)
248  {
249  m_points[0][index] = points[0][map[index]];
250  m_points[1][index] = points[1][map[index]];
251  }
252 }
253 
254 } // namespace LibUtilities
255 } // 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< NodalUtilTriangle > m_util
static std::shared_ptr< PointsBaseType > Create(const PointsKey &key)
void CalculateInterpMatrix(const Array< OneD, const NekDouble > &xi, const Array< OneD, const NekDouble > &yi, Array< OneD, NekDouble > &interp)
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)
@ eNodalTriEvenlySpaced
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:85
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255