Nektar++
Loading...
Searching...
No Matches
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{
47
49 fftw_plan_r2r_1d(m_N, nullptr, nullptr, FFTW_R2HC, FFTW_ESTIMATE);
51 fftw_plan_r2r_1d(m_N, nullptr, nullptr, FFTW_HC2R, FFTW_ESTIMATE);
52
55
56 m_FFTW_w[0] = 1.0 / (NekDouble)m_N;
57 m_FFTW_w[1] = 0.0;
58
59 m_FFTW_w_inv[0] = 1.0;
60 m_FFTW_w_inv[1] = 0.0;
61
62 for (int i = 2; i < m_N; i++)
63 {
64 m_FFTW_w[i] = m_FFTW_w[0] * 2;
65 m_FFTW_w_inv[i] = m_FFTW_w_inv[0] / 2;
66 }
67}
68
69// Destructor
71{
72 fftw_destroy_plan(m_plan_forward);
73 fftw_destroy_plan(m_plan_backward);
74}
75
76// Forward transformation
78 Array<OneD, NekDouble> &outarray)
79{
80 // FFTW_R2HC
81 fftw_execute_r2r(m_plan_forward, inarray.data(), m_wsp.data());
82
83 // Reshuffle
84 int halfN = m_N / 2;
85
86 outarray[1] = m_FFTW_w[1] * m_wsp[halfN];
87
88 Vmath::Vmul(halfN, m_wsp, 1, m_FFTW_w, 2, outarray, 2);
89
90 for (int i = 0; i < halfN - 1; i++)
91 {
92 outarray[(m_N - 1) - 2 * i] =
93 m_FFTW_w[(m_N - 1) - 2 * i] * m_wsp[halfN + 1 + i];
94 }
95}
96
97// Backward transformation
99 Array<OneD, NekDouble> &outarray)
100{
101 // Reshuffle
102 int halfN = m_N / 2;
103
104 m_wsp[halfN] = m_FFTW_w_inv[1] * inarray[1];
105
106 Vmath::Vmul(halfN, inarray, 2, m_FFTW_w_inv, 2, m_wsp, 1);
107
108 for (int i = 0; i < (halfN - 1); i++)
109 {
110 m_wsp[halfN + 1 + i] =
111 m_FFTW_w_inv[(m_N - 1) - 2 * i] * inarray[(m_N - 1) - 2 * i];
112 }
113
114 // FFTW_HC2R
115 fftw_execute_r2r(m_plan_backward, m_wsp.data(), outarray.data());
116}
117
118} // namespace Nektar::LibUtilities
void v_FFTBwdTrans(Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Definition NekFFTW.cpp:98
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 v_FFTFwdTrans(Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Definition NekFFTW.cpp:77
Array< OneD, NekDouble > m_wsp
Definition NekFFTW.h:84
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.
NektarFFTFactory & GetNektarFFTFactory()
Definition NektarFFT.cpp:65
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