Nektar++
NekFFTW.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File NekFFTW.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: Wrapper around FFTW library
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
38 
39 namespace Nektar
40 {
41  namespace LibUtilities
42  {
43  std::string NekFFTW::className
46 
48  : NektarFFT(N)
49  {
53 
54  plan_forward = fftw_plan_r2r_1d(m_N, &phys[0], &coef[0],
55  FFTW_R2HC, FFTW_ESTIMATE);
56  plan_backward = fftw_plan_r2r_1d(m_N, &coef[0], &phys[0],
57  FFTW_HC2R, FFTW_ESTIMATE);
58 
61 
62  m_FFTW_w[0] = 1.0/(NekDouble)m_N;
63  m_FFTW_w[1] = 0.0;
64 
65  m_FFTW_w_inv[0] = m_N;
66  m_FFTW_w_inv[1] = 0.0;
67 
68  for(int i=2;i<m_N;i++)
69  {
70  m_FFTW_w[i] = m_FFTW_w[0]*2;
71  m_FFTW_w_inv[i] = m_FFTW_w_inv[0]/2;
72  }
73  }
74 
75  // Distructor
77  {
78 
79  }
80 
81  // Forward transformation
83  Array<OneD,NekDouble> &inarray,
84  Array<OneD,NekDouble> &outarray)
85  {
86  Vmath::Vcopy(m_N, inarray, 1, phys, 1);
87 
88  fftw_execute(plan_forward);
89 
91 
92  Vmath::Vcopy(m_N, coef, 1, outarray, 1);
93  }
94 
95  // Backward transformation
97  Array<OneD,NekDouble> &inarray,
98  Array<OneD,NekDouble> &outarray)
99  {
100  Vmath::Vcopy(m_N, inarray, 1, coef, 1);
101 
103 
104  fftw_execute(plan_backward);
105 
106  Vmath::Vcopy(m_N, phys, 1, outarray, 1);
107  }
108 
109  // Reshuffle FFTW2Nek
111  {
112  int halfN = m_N/2;
113 
114  m_wsp[1] = coef[halfN];
115 
116  Vmath::Vcopy(halfN, coef, 1, m_wsp, 2);
117 
118  for(int i = 0; i < (halfN - 1); i++)
119  {
120  m_wsp[(m_N-1)-2*i] = coef[halfN+1+i];
121  }
122 
123  Vmath::Vmul(m_N, m_wsp, 1, m_FFTW_w, 1, coef, 1);
124 
125  return;
126  }
127 
128  // Reshuffle Nek2FFTW
130  {
131  int halfN = m_N/2;
132 
133  Vmath::Vmul(m_N, coef, 1, m_FFTW_w_inv, 1, coef, 1);
134 
135  m_wsp[halfN] = coef[1];
136 
137  Vmath::Vcopy(halfN, coef, 2, m_wsp, 1);
138 
139  for(int i = 0; i < (halfN-1); i++)
140  {
141  m_wsp[halfN+1+i] = coef[(m_N-1)-2*i];
142  }
143 
144  Vmath::Smul(m_N, 1.0/m_N, m_wsp, 1, coef, 1);
145 
146  return;
147  }
148  }
149 }
Array< OneD, NekDouble > m_FFTW_w_inv
Definition: NekFFTW.h:90
Array< OneD, NekDouble > m_FFTW_w
Definition: NekFFTW.h:89
Array< OneD, NekDouble > m_wsp
Definition: NekFFTW.h:95
Array< OneD, NekDouble > coef
Definition: NekFFTW.h:93
static NektarFFTSharedPtr create(int N)
Creates an instance of this class.
Definition: NekFFTW.h:65
virtual void v_FFTBwdTrans(Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray)
Definition: NekFFTW.cpp:96
Array< OneD, NekDouble > phys
Definition: NekFFTW.h:92
static std::string className
Name of class.
Definition: NekFFTW.h:71
void Reshuffle_Nek2FFTW(Array< OneD, NekDouble > &coef)
Definition: NekFFTW.cpp:129
void Reshuffle_FFTW2Nek(Array< OneD, NekDouble > &coef)
Definition: NekFFTW.cpp:110
virtual void v_FFTFwdTrans(Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray)
Definition: NekFFTW.cpp:82
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
NektarFFTFactory & GetNektarFFTFactory()
Definition: NektarFFT.cpp:69
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.cpp:192
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.cpp:225
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199