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
38#include <vector>
39
40namespace Nektar
41{
42namespace LibUtilities
43{
47
48namespace
49{
50// construct the geometory and set the coordinate of triangle
51// edges and vertices are ordered as anticlockwise
52bool isVertex(size_t i, size_t j, size_t npts)
53{
54 return (i == 0 && j == 0) || (i == (npts - 1) && j == 0) ||
55 (i == 0 && j == (npts - 1));
56}
57
58bool isEdge(size_t i, size_t j, size_t npts)
59{
60 return i == 0 || j == 0 || i + j == npts - 1; // i+j=tot num of steps
61}
62
63bool isEdge_1(size_t i, size_t j, size_t npts)
64{
65 boost::ignore_unused(j, npts);
66 return i == 0;
67}
68
69bool isEdge_2(size_t i, size_t j, size_t npts)
70{
71 return i + j == npts - 1;
72}
73} // namespace
74
76{
77 // Allocate the storage for points
79
80 // Populate m_points
81 size_t npts = GetNumPoints();
82 NekDouble delta = 2.0 / (npts - 1.0);
83 for (size_t i = 0, index = 0; i < npts; ++i)
84 { // y-direction
85 for (size_t j = 0; j < npts - i; ++j, ++index)
86 { // x-direction
87 NekDouble x = -1.0 + j * delta;
88 NekDouble y = -1.0 + i * delta;
89 m_points[0][index] = x;
90 m_points[1][index] = y;
91 }
92 }
93
95
97 npts - 1, m_points[0], m_points[1]);
98}
99
101{
102 // Allocate the storage for points
104
105 typedef DataType T;
106
107 // Solve the Vandermonde system of integrals for the weight vector
108 NekVector<T> w = m_util->GetWeights();
109
110 m_weights = Array<OneD, T>(w.GetRows(), w.GetPtr());
111}
112
113// ////////////////////////////////////////
114// CalculateInterpMatrix()
118{
120 xi[0] = xia;
121 xi[1] = yia;
122
123 std::shared_ptr<NekMatrix<NekDouble>> mat =
124 m_util->GetInterpolationMatrix(xi);
125 Vmath::Vcopy(mat->GetRows() * mat->GetColumns(), mat->GetRawPtr(), 1,
126 &interp[0], 1);
127}
128
129// ////////////////////////////////////////
130// CalculateDerivMatrix()
132{
133
134 // Allocate the derivative matrix.
135 PointsBaseType::v_CalculateDerivMatrix();
136
137 m_derivmatrix[0] = m_util->GetDerivMatrix(0);
138 m_derivmatrix[1] = m_util->GetDerivMatrix(1);
139}
140
141std::shared_ptr<PointsBaseType> NodalTriEvenlySpaced::Create(
142 const PointsKey &key)
143{
144 std::shared_ptr<PointsBaseType> returnval(
146
147 returnval->Initialize();
148
149 return returnval;
150}
151
153{
154 size_t npts = GetNumPoints();
155 using std::vector;
156 vector<int> vertex;
157 vector<int> iEdge_1; // interior edge points on the bottom triangle edge
158 vector<int> iEdge_2; // interior edge points on the right triangle edge
159 vector<int> iEdge_3; // interior edge points on the left triangle edge
160 vector<int> interiorPoints;
161 vector<int> map;
162
163 // Build the lattice triangle left to right - bottom to top
164 for (size_t i = 0, index = 0; i < npts; ++i)
165 { // y-direction
166 for (size_t j = 0; j < npts - i; ++j, ++index)
167 { // x-direction
168
169 if (isVertex(i, j, npts))
170 {
171
172 vertex.push_back(index);
173 }
174 else if (isEdge(i, j, npts))
175 { // interior edge
176
177 if (isEdge_1(i, j, npts))
178 { // bottom edge
179
180 iEdge_1.push_back(index);
181 }
182 else if (isEdge_2(i, j, npts))
183 { // right edge
184
185 iEdge_2.push_back(index);
186 }
187 else // left edge
188 {
189 // Add backwards. This is because of counter clockwise.
190 iEdge_3.insert(iEdge_3.begin(), index);
191 }
192 }
193 else
194 { // Interior points
195
196 interiorPoints.push_back(index);
197 }
198 }
199 }
200
201 // Mapping the vertex, edges, and interior points using the permutation
202 // matrix, so the points are ordered anticlockwise.
203 for (size_t k = 0; k < vertex.size(); ++k)
204 {
205
206 map.push_back(vertex[k]);
207 }
208
209 for (size_t k = 0; k < iEdge_1.size(); ++k)
210 {
211
212 map.push_back(iEdge_1[k]);
213 }
214
215 for (size_t k = 0; k < iEdge_2.size(); ++k)
216 {
217
218 map.push_back(iEdge_2[k]);
219 }
220
221 for (size_t k = 0; k < iEdge_3.size(); ++k)
222 {
223
224 map.push_back(iEdge_3[k]);
225 }
226
227 for (size_t k = 0; k < interiorPoints.size(); ++k)
228 {
229
230 map.push_back(interiorPoints[k]);
231 }
232
233 Array<OneD, NekDouble> points[2];
236 for (size_t index = 0; index < map.size(); ++index)
237 {
238 points[0][index] = m_points[0][index];
239 points[1][index] = m_points[1][index];
240 }
241
242 for (size_t index = 0; index < map.size(); ++index)
243 {
244 m_points[0][index] = points[0][map[index]];
245 m_points[1][index] = points[1][map[index]];
246 }
247}
248
249} // namespace LibUtilities
250} // 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:169
virtual void v_CalculateDerivMatrix() override final
std::shared_ptr< NodalUtilTriangle > m_util
virtual void v_CalculateWeights() override final
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)
virtual void v_CalculatePoints() override final
Array< OneD, DataType > m_points[3]
Storage for the point locations, allowing for up to a 3D points storage.
Definition: Points.h:361
MatrixSharedPtrType m_derivmatrix[3]
Derivative matrices.
Definition: Points.h:367
Array< OneD, DataType > m_weights
Quadrature weights for the weights.
Definition: Points.h:363
Defines a specification for a set of points.
Definition: Points.h:55
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.
PointsManagerT & PointsManager(void)
@ eNodalTriEvenlySpaced
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:85
std::vector< double > w(NPUPPER)
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:1191