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
39namespace Nektar
40{
41namespace LibUtilities
42{
43std::string NekFFTW::className =
45
47{
51
53 fftw_plan_r2r_1d(m_N, &m_phys[0], &m_coef[0], FFTW_R2HC, FFTW_ESTIMATE);
55 fftw_plan_r2r_1d(m_N, &m_coef[0], &m_phys[0], FFTW_HC2R, FFTW_ESTIMATE);
56
59
60 m_FFTW_w[0] = 1.0 / (NekDouble)m_N;
61 m_FFTW_w[1] = 0.0;
62
63 m_FFTW_w_inv[0] = m_N;
64 m_FFTW_w_inv[1] = 0.0;
65
66 for (int i = 2; i < m_N; i++)
67 {
68 m_FFTW_w[i] = m_FFTW_w[0] * 2;
69 m_FFTW_w_inv[i] = m_FFTW_w_inv[0] / 2;
70 }
71}
72
73// Distructor
75{
76}
77
78// Forward transformation
80 Array<OneD, NekDouble> &outarray)
81{
82 Vmath::Vcopy(m_N, inarray, 1, m_phys, 1);
83
84 fftw_execute(m_plan_forward);
85
87
88 Vmath::Vcopy(m_N, m_coef, 1, outarray, 1);
89}
90
91// Backward transformation
93 Array<OneD, NekDouble> &outarray)
94{
95 Vmath::Vcopy(m_N, inarray, 1, m_coef, 1);
96
98
99 fftw_execute(m_plan_backward);
100
101 Vmath::Vcopy(m_N, m_phys, 1, outarray, 1);
102}
103
104// Reshuffle FFTW2Nek
106{
107 int halfN = m_N / 2;
108
109 m_wsp[1] = coef[halfN];
110
111 Vmath::Vcopy(halfN, coef, 1, m_wsp, 2);
112
113 for (int i = 0; i < (halfN - 1); i++)
114 {
115 m_wsp[(m_N - 1) - 2 * i] = coef[halfN + 1 + i];
116 }
117
118 Vmath::Vmul(m_N, m_wsp, 1, m_FFTW_w, 1, coef, 1);
119
120 return;
121}
122
123// Reshuffle Nek2FFTW
125{
126 int halfN = m_N / 2;
127
128 Vmath::Vmul(m_N, coef, 1, m_FFTW_w_inv, 1, coef, 1);
129
130 m_wsp[halfN] = coef[1];
131
132 Vmath::Vcopy(halfN, coef, 2, m_wsp, 1);
133
134 for (int i = 0; i < (halfN - 1); i++)
135 {
136 m_wsp[halfN + 1 + i] = coef[(m_N - 1) - 2 * i];
137 }
138
139 Vmath::Smul(m_N, 1.0 / m_N, m_wsp, 1, coef, 1);
140
141 return;
142}
143} // namespace LibUtilities
144} // namespace Nektar
virtual void v_FFTBwdTrans(Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Definition: NekFFTW.cpp:92
Array< OneD, NekDouble > m_coef
Definition: NekFFTW.h:85
Array< OneD, NekDouble > m_phys
Definition: NekFFTW.h:84
static NektarFFTSharedPtr create(int N)
Creates an instance of this class.
Definition: NekFFTW.h:63
static std::string className
Name of class.
Definition: NekFFTW.h:69
void Reshuffle_Nek2FFTW(Array< OneD, NekDouble > &coef)
Definition: NekFFTW.cpp:124
virtual void v_FFTFwdTrans(Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Definition: NekFFTW.cpp:79
void Reshuffle_FFTW2Nek(Array< OneD, NekDouble > &coef)
Definition: NekFFTW.cpp:105
Array< OneD, NekDouble > m_wsp
Definition: NekFFTW.h:87
Array< OneD, NekDouble > m_FFTW_w
Definition: NekFFTW.h:80
Array< OneD, NekDouble > m_FFTW_w_inv
Definition: NekFFTW.h:82
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
NektarFFTFactory & GetNektarFFTFactory()
Definition: NektarFFT.cpp:69
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
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:207
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:245
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1191