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
38namespace Nektar
39{
40namespace LibUtilities
41{
44
46{
47 // Allocate the storage for points
49
50 size_t npts = m_pointsKey.GetNumPoints();
51 ASSERTL0(!(npts % 2), "Fourier points need to be of even order");
52
53 NekDouble dx = 2.0 / (NekDouble)(npts);
54 for (size_t i = 0; i < npts; ++i)
55 {
56 m_points[0][i] = -1.0 + i * dx;
57 }
58}
59
61{
62 // Allocate the storage for points
64
65 size_t npts = m_pointsKey.GetNumPoints();
66 for (size_t i = 0; i < npts; ++i)
67 {
68 m_weights[i] = 1.0 / (NekDouble)npts;
69 }
70}
71
73{
74 //// Allocate the derivative matrix.
76
77 size_t npts = m_pointsKey.GetNumPoints();
78
79 for (size_t i = 1; i < npts; ++i)
80 {
81 m_derivmatrix[0]->SetValue(i, i, 0.0);
82 }
83
84 for (size_t i = 1; i < npts; ++i)
85 {
86 m_derivmatrix[0]->SetValue(0, i,
87 -0.5 * M_PI * pow(-1.0, NekDouble(i)) *
88 cos(M_PI * i / npts) /
89 sin(M_PI * i / npts));
90 }
91
92 for (size_t i = 1; i < npts; ++i)
93 {
94 for (size_t j = 0; j < npts; ++j)
95 {
96 m_derivmatrix[0]->SetValue(
97 i, j, (*m_derivmatrix[0])(0, (j - i + npts) % npts));
98 }
99 }
100}
101
102std::shared_ptr<Points<NekDouble>> FourierPoints::Create(const PointsKey &key)
103{
104 std::shared_ptr<Points<NekDouble>> returnval(
106
107 returnval->Initialize();
108
109 return returnval;
110}
111
112std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::CreateMatrix(
113 const PointsKey &pkey)
114{
115 size_t numpoints = pkey.GetNumPoints();
117
118 PointsManager()[pkey]->GetPoints(xpoints);
119
120 /// Delegate to function below.
121 return GetI(numpoints, xpoints);
122}
123
124const std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::v_GetI(
125 const PointsKey &pkey)
126{
127 ASSERTL0(pkey.GetPointsDim() == 1,
128 "Fourier Points can only interp to other 1d point distributions");
129
130 return m_InterpManager[pkey];
131}
132
133const std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::v_GetI(
135{
136 size_t numpoints = 1;
137
138 /// Delegate to function below.
139 return GetI(numpoints, x);
140}
141
142const std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::v_GetI(
143 size_t numpoints, const Array<OneD, const NekDouble> &x)
144{
145 Array<OneD, NekDouble> interp(GetNumPoints() * numpoints);
146
147 CalculateInterpMatrix(numpoints, x, interp);
148
149 NekDouble *t = interp.data();
150 size_t np = GetNumPoints();
151 std::shared_ptr<NekMatrix<NekDouble>> returnval(
152 MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr(numpoints, np,
153 t));
154
155 return returnval;
156}
157
159 size_t npts, const Array<OneD, const NekDouble> &xpoints,
161{
162 const NekDouble h = 2.0 / m_pointsKey.GetNumPoints();
163 for (size_t i = 0; i < npts; ++i)
164 {
165 for (size_t j = 0; j < m_pointsKey.GetNumPoints(); ++j)
166 {
167 interp[i * m_pointsKey.GetNumPoints() + j] =
168 PeriodicSincFunction(M_PI * (xpoints[i] - m_points[0][j]), h);
169 }
170 }
171}
172
174 const NekDouble h)
175{
176 // This formula is based upon a mapped version of
177 // the periodic sinc presented in Trefethen's "Spectral Methods
178 // in Matlab"
179
180 NekDouble y = 1.0;
181
182 if (fabs(x) > 1.0e-12)
183 {
184 y = sin(M_PI * x / (M_PI * h)) / ((2.0 / h) * tan(0.5 * x));
185 }
186
187 return y;
188}
189
190} // end of namespace LibUtilities
191} // end of namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
virtual void v_CalculatePoints() override
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)
virtual void v_CalculateWeights() override
virtual const MatrixSharedPtrType v_GetI(const PointsKey &pkey) override final
NekDouble PeriodicSincFunction(const NekDouble x, const NekDouble h)
virtual void v_CalculateDerivMatrix() override
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
Stores a set of points of datatype DataT, defined by a PointKey.
Definition: Points.h:240
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
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_InterpManager
Definition: Points.h:369
PointsKey m_pointsKey
Points type for this points distributions.
Definition: Points.h:358
Array< OneD, DataType > m_weights
Quadrature weights for the weights.
Definition: Points.h:363
const MatrixSharedPtrType GetI(const PointsKey &key)
Definition: Points.h:322
Defines a specification for a set of points.
Definition: Points.h:55
size_t GetPointsDim() const
Definition: Points.h:133
size_t GetNumPoints() const
Definition: Points.h:90
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:76
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble