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