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
35#include <fftw3.h>
36
40
42{
43std::string NekFFTW::className =
45
47{
49
51 fftw_plan_r2r_1d(m_N, nullptr, nullptr, FFTW_R2HC, FFTW_ESTIMATE);
53 fftw_plan_r2r_1d(m_N, nullptr, nullptr, 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] = 1.0;
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// Destructor
73{
74 fftw_destroy_plan((fftw_plan)m_plan_forward);
75 fftw_destroy_plan((fftw_plan)m_plan_backward);
76}
77
78// Forward transformation
80 Array<OneD, NekDouble> &outarray)
81{
82 // FFTW_R2HC
83 fftw_execute_r2r((fftw_plan)m_plan_forward, inarray.data(), m_wsp.data());
84
85 // Reshuffle
86 int halfN = m_N / 2;
87
88 outarray[1] = m_FFTW_w[1] * m_wsp[halfN];
89
90 Vmath::Vmul(halfN, m_wsp, 1, m_FFTW_w, 2, outarray, 2);
91
92 for (int i = 0; i < halfN - 1; i++)
93 {
94 outarray[(m_N - 1) - 2 * i] =
95 m_FFTW_w[(m_N - 1) - 2 * i] * m_wsp[halfN + 1 + i];
96 }
97}
98
99// Backward transformation
101 Array<OneD, NekDouble> &outarray)
102{
103 // Reshuffle
104 int halfN = m_N / 2;
105
106 m_wsp[halfN] = m_FFTW_w_inv[1] * inarray[1];
107
108 Vmath::Vmul(halfN, inarray, 2, m_FFTW_w_inv, 2, m_wsp, 1);
109
110 for (int i = 0; i < (halfN - 1); i++)
111 {
112 m_wsp[halfN + 1 + i] =
113 m_FFTW_w_inv[(m_N - 1) - 2 * i] * inarray[(m_N - 1) - 2 * i];
114 }
115
116 // FFTW_HC2R
117 fftw_execute_r2r((fftw_plan)m_plan_backward, m_wsp.data(), outarray.data());
118}
119
120} // namespace Nektar::LibUtilities
void v_FFTBwdTrans(Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Definition NekFFTW.cpp:100
static NektarFFTSharedPtr create(int N)
Creates an instance of this class.
Definition NekFFTW.h:61
static std::string className
Name of class.
Definition NekFFTW.h:67
void v_FFTFwdTrans(Array< OneD, NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Definition NekFFTW.cpp:79
Array< OneD, NekDouble > m_wsp
Definition NekFFTW.h:82
Array< OneD, NekDouble > m_FFTW_w
Definition NekFFTW.h:78
Array< OneD, NekDouble > m_FFTW_w_inv
Definition NekFFTW.h:80
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