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 
38 
40 #include <LibUtilities/Foundations/ManagerAccess.h> // for PointsManager, etc
41 
42 namespace Nektar
43 {
44 namespace LibUtilities
45 {
48 
50 {
51  // Allocate the storage for points
53 
54  unsigned int npts = m_pointsKey.GetNumPoints();
55  ASSERTL0(!(npts % 2), "Fourier points need to be of even order");
56 
57  if (npts == 1)
58  {
59  m_points[0][0] = 0.0;
60  }
61  else
62  {
63  NekDouble dx = 2.0 / (NekDouble)(npts);
64  for (unsigned int i = 0; i < npts; ++i)
65  {
66  m_points[0][i] = -1.0 + i * dx;
67  }
68  }
69 }
70 
72 {
73  // Allocate the storage for points
75 
76  unsigned int npts = m_pointsKey.GetNumPoints();
77  if (npts == 1)
78  {
79  m_weights[0] = 1.0; // midpoint rule
80  }
81  else
82  {
83  for (unsigned int i = 0; i < npts; ++i)
84  {
85  m_weights[i] = 1.0 / (NekDouble)npts;
86  }
87  }
88 }
89 
91 {
92  //// Allocate the derivative matrix.
94 
95  unsigned int npts = m_pointsKey.GetNumPoints();
96 
97  for (unsigned int i = 1; i < npts; ++i)
98  {
99  m_derivmatrix[0]->SetValue(i, i, 0.0);
100  }
101 
102  for (unsigned int i = 1; i < npts; ++i)
103  {
104  m_derivmatrix[0]->SetValue(0, i,
105  -0.5 * M_PI * pow(-1.0, NekDouble(i)) *
106  cos(M_PI * i / npts) /
107  sin(M_PI * i / npts));
108  }
109 
110  for (unsigned int i = 1; i < npts; ++i)
111  {
112  for (unsigned int j = 0; j < npts; ++j)
113  {
114  m_derivmatrix[0]->SetValue(
115  i, j, (*m_derivmatrix[0])(0, (j - i + npts) % npts));
116  }
117  }
118 }
119 
120 std::shared_ptr<Points<NekDouble>> FourierPoints::Create(const PointsKey &key)
121 {
122  std::shared_ptr<Points<NekDouble>> returnval(
124 
125  returnval->Initialize();
126 
127  return returnval;
128 }
129 
130 std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::CreateMatrix(
131  const PointsKey &pkey)
132 {
133  int numpoints = pkey.GetNumPoints();
135 
136  PointsManager()[pkey]->GetPoints(xpoints);
137 
138  /// Delegate to function below.
139  return GetI(numpoints, xpoints);
140 }
141 
142 const std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::v_GetI(
143  const PointsKey &pkey)
144 {
145  ASSERTL0(pkey.GetPointsDim() == 1,
146  "Fourier Points can only interp to other 1d point distributions");
147 
148  return m_InterpManager[pkey];
149 }
150 
151 const std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::v_GetI(
153 {
154  int numpoints = 1;
155 
156  /// Delegate to function below.
157  return GetI(numpoints, x);
158 }
159 
160 const std::shared_ptr<NekMatrix<NekDouble>> FourierPoints::v_GetI(
161  unsigned int numpoints, const Array<OneD, const NekDouble> &x)
162 {
163  Array<OneD, NekDouble> interp(GetNumPoints() * numpoints);
164 
165  CalculateInterpMatrix(numpoints, x, interp);
166 
167  NekDouble *t = interp.data();
168  unsigned int np = GetNumPoints();
169  std::shared_ptr<NekMatrix<NekDouble>> returnval(
170  MemoryManager<NekMatrix<NekDouble>>::AllocateSharedPtr(numpoints, np,
171  t));
172 
173  return returnval;
174 }
175 
177  unsigned int npts, const Array<OneD, const NekDouble> &xpoints,
178  Array<OneD, NekDouble> &interp)
179 {
180  const NekDouble h = 2.0 / m_pointsKey.GetNumPoints();
181  for (unsigned int i = 0; i < npts; ++i)
182  {
183  for (unsigned int j = 0; j < m_pointsKey.GetNumPoints(); ++j)
184  {
185  interp[i * m_pointsKey.GetNumPoints() + j] =
186  PeriodicSincFunction(M_PI * (xpoints[i] - m_points[0][j]), h);
187  }
188  }
189 }
190 
192  const NekDouble h)
193 {
194  // This formula is based upon a mapped version of
195  // the periodic sinc presented in Trefethen's "Spectral Methods
196  // in Matlab"
197 
198  NekDouble y = 1.0;
199 
200  if (fabs(x) > 1.0e-12)
201  {
202  y = sin(M_PI * x / (M_PI * h)) / ((2.0 / h) * tan(0.5 * x));
203  }
204 
205  return y;
206 }
207 
208 } // end of namespace LibUtilities
209 } // 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)
virtual const MatrixSharedPtrType v_GetI(const PointsKey &pkey) override
static std::shared_ptr< PointsBaseType > Create(const PointsKey &key)
void CalculateInterpMatrix(unsigned int npts, const Array< OneD, const NekDouble > &xpoints, Array< OneD, NekDouble > &interp)
virtual void v_CalculateWeights() override
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:170
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
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_InterpManager
Definition: Points.h:383
PointsKey m_pointsKey
Points type for this points distributions.
Definition: Points.h:372
unsigned int GetNumPoints() const
Definition: Points.h:273
Array< OneD, DataType > m_weights
Quadrature weights for the weights.
Definition: Points.h:377
virtual void v_CalculateDerivMatrix()
Definition: Points.h:445
const MatrixSharedPtrType GetI(const PointsKey &key)
Definition: Points.h:336
Defines a specification for a set of points.
Definition: Points.h:59
unsigned int GetPointsDim() const
Definition: Points.h:147
unsigned int GetNumPoints() const
Definition: Points.h:104
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