Nektar++
FourierPoints.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: FourierPoints.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: 1D Evenly-Spaced Points
32//
33///////////////////////////////////////////////////////////////////////////////
34
37
39{
42
44{
45 // Allocate the storage for points
47
48 size_t npts = m_pointsKey.GetNumPoints();
49 ASSERTL0(!(npts % 2), "Fourier points need to be of even order");
50
51 NekDouble dx = 2.0 / (NekDouble)(npts);
52 for (size_t i = 0; i < npts; ++i)
53 {
54 m_points[0][i] = -1.0 + i * dx;
55 }
56}
57
59{
60 // Allocate the storage for points
62
63 size_t npts = m_pointsKey.GetNumPoints();
64 for (size_t i = 0; i < npts; ++i)
65 {
66 m_weights[i] = 1.0 / (NekDouble)npts;
67 }
68}
69
71{
72 //// Allocate the derivative matrix.
74
75 size_t npts = m_pointsKey.GetNumPoints();
76
77 for (size_t i = 1; i < npts; ++i)
78 {
79 m_derivmatrix[0]->SetValue(i, i, 0.0);
80 }
81
82 for (size_t i = 1; i < npts; ++i)
83 {
84 m_derivmatrix[0]->SetValue(0, i,
85 -0.5 * M_PI * pow(-1.0, NekDouble(i)) *
86 cos(M_PI * i / npts) /
87 sin(M_PI * i / npts));
88 }
89
90 for (size_t i = 1; i < npts; ++i)
91 {
92 for (size_t j = 0; j < npts; ++j)
93 {
94 m_derivmatrix[0]->SetValue(
95 i, j, (*m_derivmatrix[0])(0, (j - i + npts) % npts));
96 }
97 }
98}
99
100std::shared_ptr<Points<NekDouble>> FourierPoints::Create(const PointsKey &key)
101{
102 std::shared_ptr<Points<NekDouble>> returnval(
104
105 returnval->Initialize();
106
107 return returnval;
108}
109
110std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::CreateMatrix(
111 const PointsKey &pkey)
112{
113 size_t numpoints = pkey.GetNumPoints();
115
116 PointsManager()[pkey]->GetPoints(xpoints);
117
118 /// Delegate to function below.
119 return GetI(numpoints, xpoints);
120}
121
122const std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::v_GetI(
123 const PointsKey &pkey)
124{
125 ASSERTL0(pkey.GetPointsDim() == 1,
126 "Fourier Points can only interp to other 1d point distributions");
127
128 return m_InterpManager[pkey];
129}
130
131const std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::v_GetI(
133{
134 size_t numpoints = 1;
135
136 /// Delegate to function below.
137 return GetI(numpoints, x);
138}
139
140const std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::v_GetI(
141 size_t numpoints, const Array<OneD, const NekDouble> &x)
142{
143 Array<OneD, NekDouble> interp(GetNumPoints() * numpoints);
144
145 CalculateInterpMatrix(numpoints, x, interp);
146
147 NekDouble *t = interp.data();
148 size_t np = GetNumPoints();
149 std::shared_ptr<NekMatrix<NekDouble>> returnval(
150 MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr(numpoints, np,
151 t));
152
153 return returnval;
154}
155
157 size_t npts, const Array<OneD, const NekDouble> &xpoints,
159{
160 const NekDouble h = 2.0 / m_pointsKey.GetNumPoints();
161 for (size_t i = 0; i < npts; ++i)
162 {
163 for (size_t j = 0; j < m_pointsKey.GetNumPoints(); ++j)
164 {
165 interp[i * m_pointsKey.GetNumPoints() + j] =
166 PeriodicSincFunction(M_PI * (xpoints[i] - m_points[0][j]), h);
167 }
168 }
169}
170
172 const NekDouble h)
173{
174 // This formula is based upon a mapped version of
175 // the periodic sinc presented in Trefethen's "Spectral Methods
176 // in Matlab"
177
178 NekDouble y = 1.0;
179
180 if (fabs(x) > 1.0e-12)
181 {
182 y = sin(M_PI * x / (M_PI * h)) / ((2.0 / h) * tan(0.5 * x));
183 }
184
185 return y;
186}
187
188} // namespace Nektar::LibUtilities
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
std::shared_ptr< NekMatrix< NekDouble > > CreateMatrix(const PointsKey &pkey)
static std::shared_ptr< PointsBaseType > Create(const PointsKey &key)
void CalculateInterpMatrix(size_t npts, const Array< OneD, const NekDouble > &xpoints, Array< OneD, NekDouble > &interp)
const MatrixSharedPtrType v_GetI(const PointsKey &pkey) final
NekDouble PeriodicSincFunction(const NekDouble x, const NekDouble h)
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
Stores a set of points of datatype DataT, defined by a PointKey.
Definition: Points.h:235
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
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_InterpManager
Definition: Points.h:364
PointsKey m_pointsKey
Points type for this points distributions.
Definition: Points.h:353
Array< OneD, DataType > m_weights
Quadrature weights for the weights.
Definition: Points.h:358
const MatrixSharedPtrType GetI(const PointsKey &key)
Definition: Points.h:317
Defines a specification for a set of points.
Definition: Points.h:50
size_t GetPointsDim() const
Definition: Points.h:128
size_t GetNumPoints() const
Definition: Points.h:85
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
PointsManagerT & PointsManager(void)
@ eFourierEvenlySpaced
1D Evenly-spaced points using Fourier Fit
Definition: PointsType.h:74
double NekDouble