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 
39 
41 #include <LibUtilities/Foundations/ManagerAccess.h> // for PointsManager, etc
42 
43 namespace Nektar
44 {
45  namespace LibUtilities
46  {
49  };
50 
52  {
53  // Allocate the storage for points
55 
56  unsigned int npts = m_pointsKey.GetNumPoints();
57  ASSERTL0(!(npts%2), "Fourier points need to be of even order");
58 
59  if(npts==1)
60  {
61  m_points[0][0] = 0.0;
62  }
63  else
64  {
65  NekDouble dx = 2.0/(NekDouble)(npts);
66  for(unsigned int i=0;i<npts;++i)
67  {
68  m_points[0][i] = -1.0 + i*dx;
69  }
70  }
71  }
72 
74  {
75  // Allocate the storage for points
77 
78  unsigned int npts = m_pointsKey.GetNumPoints();
79  if(npts==1)
80  {
81  m_weights[0] = 1.0; //midpoint rule
82  }
83  else
84  {
85  for(unsigned int i=0; i<npts; ++i)
86  {
87  m_weights[i] = 1.0/(NekDouble)npts;
88  }
89  }
90  }
91 
93  {
94  //// Allocate the derivative matrix.
96 
97  unsigned int npts = m_pointsKey.GetNumPoints();
98 
99  for(unsigned int i=1;i<npts;++i)
100  {
101  m_derivmatrix[0]->SetValue(i,i, 0.0);
102  }
103 
104  for(unsigned int i=1;i<npts;++i)
105  {
106  m_derivmatrix[0]->SetValue(0,i, -0.5*M_PI*pow(-1.0,NekDouble(i))*cos(M_PI*i/npts)/sin(M_PI*i/npts));
107  }
108 
109  for(unsigned int i=1;i<npts;++i)
110  {
111  for(unsigned int j=0;j<npts;++j)
112  {
113  m_derivmatrix[0]->SetValue(i,j, (*m_derivmatrix[0])(0,(j-i+npts)%npts));
114  }
115  }
116  }
117 
118  std::shared_ptr<Points<NekDouble> > FourierPoints::Create(const PointsKey &key)
119  {
120  std::shared_ptr<Points<NekDouble> > returnval(MemoryManager<FourierPoints>::AllocateSharedPtr(key));
121 
122  returnval->Initialize();
123 
124  return returnval;
125  }
126 
127 
128  std::shared_ptr< NekMatrix<NekDouble> > FourierPoints::CreateMatrix(const PointsKey &pkey)
129  {
130  int numpoints = pkey.GetNumPoints();
132 
133  PointsManager()[pkey]->GetPoints(xpoints);
134 
135  /// Delegate to function below.
136  return GetI(numpoints, xpoints);
137  }
138 
139  const std::shared_ptr<NekMatrix<NekDouble> > FourierPoints::GetI(const PointsKey& pkey)
140  {
141  ASSERTL0(pkey.GetPointsDim()==1, "Fourier Points can only interp to other 1d point distributions");
142 
143  return m_InterpManager[pkey];
144  }
145 
146  const std::shared_ptr<NekMatrix<NekDouble> > FourierPoints::GetI(const Array<OneD, const NekDouble>& x)
147  {
148  int numpoints = 1;
149 
150  /// Delegate to function below.
151  return GetI(numpoints, x);
152  }
153 
154  const std::shared_ptr<NekMatrix<NekDouble> > FourierPoints::GetI(unsigned int numpoints, const Array<OneD, const NekDouble>& x)
155  {
156  Array<OneD, NekDouble> interp(GetNumPoints()*numpoints);
157 
158  CalculateInterpMatrix(numpoints, x, interp);
159 
160  NekDouble* t = interp.data();
161  unsigned int np = GetNumPoints();
162  std::shared_ptr< NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr(numpoints,np,t));
163 
164  return returnval;
165  }
166 
168  {
169  const NekDouble h = 2.0/m_pointsKey.GetNumPoints();
170  for(unsigned int i=0;i<npts;++i)
171  {
172  for(unsigned int j=0;j<m_pointsKey.GetNumPoints();++j)
173  {
174  interp[i*m_pointsKey.GetNumPoints()+j] = PeriodicSincFunction(M_PI*(xpoints[i]-m_points[0][j]),h);
175  }
176  }
177  }
178 
180  {
181  // This formula is based upon a mapped version of
182  // the periodic sinc presented in Trefethen's "Spectral Methods
183  // in Matlab"
184 
185  NekDouble y = 1.0;
186 
187  if(fabs(x)>1.0e-12)
188  {
189  y = sin(M_PI*x/(M_PI*h))/((2.0/h)*tan(0.5*x));
190  }
191 
192  return y;
193  }
194 
195  } // end of namespace LibUtilities
196 } // end of namespace Nektar
197 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::shared_ptr< NekMatrix< NekDouble > > CreateMatrix(const PointsKey &pkey)
static std::shared_ptr< PointsBaseType > Create(const PointsKey &key)
void CalculateInterpMatrix(unsigned int npts, const Array< OneD, const NekDouble > &xpoints, Array< OneD, NekDouble > &interp)
const MatrixSharedPtrType GetI(const PointsKey &pkey)
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:166
Array< OneD, DataType > m_points[3]
Storage for the point locations, allowing for up to a 3D points storage.
Definition: Points.h:390
MatrixSharedPtrType m_derivmatrix[3]
Derivative matrices.
Definition: Points.h:396
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_InterpManager
Definition: Points.h:397
virtual void CalculateDerivMatrix()
Definition: Points.h:450
PointsKey m_pointsKey
Points type for this points distributions.
Definition: Points.h:387
unsigned int GetNumPoints() const
Definition: Points.h:273
Array< OneD, DataType > m_weights
Quadrature weights for the weights.
Definition: Points.h:392
Defines a specification for a set of points.
Definition: Points.h:60
unsigned int GetPointsDim() const
Definition: Points.h:150
unsigned int GetNumPoints() const
Definition: Points.h:107
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:65
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble