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
40{
41std::string NekFFTW::className =
43
45{
49
51 fftw_plan_r2r_1d(m_N, &m_phys[0], &m_coef[0], FFTW_R2HC, FFTW_ESTIMATE);
53 fftw_plan_r2r_1d(m_N, &m_coef[0], &m_phys[0], FFTW_HC2R, FFTW_ESTIMATE);
54
57
58 m_FFTW_w[0] = 1.0 / (NekDouble)m_N;
59 m_FFTW_w[1] = 0.0;
60
61 m_FFTW_w_inv[0] = m_N;
62 m_FFTW_w_inv[1] = 0.0;
63
64 for (int i = 2; i < m_N; i++)
65 {
66 m_FFTW_w[i] = m_FFTW_w[0] * 2;
67 m_FFTW_w_inv[i] = m_FFTW_w_inv[0] / 2;
68 }
69}
70
71// Distructor
73{
74}
75
76// Forward transformation
78 Array<OneD, NekDouble> &outarray)
79{
80 Vmath::Vcopy(m_N, inarray, 1, m_phys, 1);
81
82 fftw_execute(m_plan_forward);
83
85
86 Vmath::Vcopy(m_N, m_coef, 1, outarray, 1);
87}
88
89// Backward transformation
91 Array<OneD, NekDouble> &outarray)
92{
93 Vmath::Vcopy(m_N, inarray, 1, m_coef, 1);
94
96
97 fftw_execute(m_plan_backward);
98
99 Vmath::Vcopy(m_N, m_phys, 1, outarray, 1);
100}
101
102// Reshuffle FFTW2Nek
104{
105 int halfN = m_N / 2;
106
107 m_wsp[1] = coef[halfN];
108
109 Vmath::Vcopy(halfN, coef, 1, m_wsp, 2);
110
111 for (int i = 0; i < (halfN - 1); i++)
112 {
113 m_wsp[(m_N - 1) - 2 * i] = coef[halfN + 1 + i];
114 }
115
116 Vmath::Vmul(m_N, m_wsp, 1, m_FFTW_w, 1, coef, 1);
117
118 return;
119}
120
121// Reshuffle Nek2FFTW
123{
124 int halfN = m_N / 2;
125
126 Vmath::Vmul(m_N, coef, 1, m_FFTW_w_inv, 1, coef, 1);
127
128 m_wsp[halfN] = coef[1];
129
130 Vmath::Vcopy(halfN, coef, 2, m_wsp, 1);
131
132 for (int i = 0; i < (halfN - 1); i++)
133 {
134 m_wsp[halfN + 1 + i] = coef[(m_N - 1) - 2 * i];
135 }
136
137 Vmath::Smul(m_N, 1.0 / m_N, m_wsp, 1, coef, 1);
138
139 return;
140}
141} // namespace Nektar::LibUtilities
void v_FFTBwdTrans(Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Definition: NekFFTW.cpp:90
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:122
void v_FFTFwdTrans(Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Definition: NekFFTW.cpp:77
void Reshuffle_FFTW2Nek(Array< OneD, NekDouble > &coef)
Definition: NekFFTW.cpp:103
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:197
NektarFFTFactory & GetNektarFFTFactory()
Definition: NektarFFT.cpp:65
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.hpp:72
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.hpp:100
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825