Loading [MathJax]/extensions/TeX/AMSsymbols.js
PSCF v1.2
cpu/FFT.h
1#ifndef PRDC_CPU_FFT_H
2#define PRDC_CPU_FFT_H
3
4/*
5* PSCF Package
6*
7* Copyright 2016 - 2024, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <prdc/cpu/RField.h>
12#include <prdc/cpu/RFieldDft.h>
13#include <prdc/cpu/CField.h>
14#include <pscf/math/IntVec.h>
15#include <util/global.h>
16
17#include <fftw3.h>
18
19namespace Pscf {
20namespace Prdc {
21namespace Cpu {
22
23 using namespace Util;
24 using namespace Pscf;
25
31 template <int D>
32 class FFT
33 {
34
35 public:
36
40 FFT();
41
45 virtual ~FFT();
46
52 void setup(IntVec<D> const & meshDimensions);
53
54 // Real Data (Real <-> Complex Transforms)
55
70 void forwardTransform(RField<D> const & in, RFieldDft<D>& out) const;
71
89 void inverseTransformUnsafe(RFieldDft<D>& in, RField<D>& out) const;
90
103 void inverseTransformSafe(RFieldDft<D> const & in, RField<D>& out)
104 const;
105
106 // Complex Data (Complex <-> Complex Transforms)
107
126 void forwardTransform(CField<D> const & in, CField<D>& out) const;
127
141 void inverseTransform(CField<D> const & in, CField<D>& out) const;
142
143 // Accessors
144
148 IntVec<D> const & meshDimensions() const;
149
153 bool isSetup() const;
154
155 private:
156
158 mutable RFieldDft<D> kFieldCopy_;
159
161 IntVec<D> meshDimensions_;
162
164 int rSize_;
165
167 int kSize_;
168
170 fftw_plan rcfPlan_;
171
173 fftw_plan criPlan_;
174
176 fftw_plan ccfPlan_;
177
179 fftw_plan cciPlan_;
180
182 bool isSetup_;
183
187 void makePlans(RField<D>& rField, RFieldDft<D>& kField,
188 CField<D>& cFieldIn, CField<D>& cFieldOut);
189
190 };
191
192 // Declarations of explicit specializations
193
194 template <>
195 void FFT<1>::makePlans(RField<1>& rField, RFieldDft<1>& kField,
196 CField<1>& cFieldIn, CField<1>& cFieldOut);
197
198 template <>
199 void FFT<2>::makePlans(RField<2>& rField, RFieldDft<2>& kField,
200 CField<2>& cFieldIn, CField<2>& cFieldOut);
201
202 template <>
203 void FFT<3>::makePlans(RField<3>& rField, RFieldDft<3>& kField,
204 CField<3>& cFieldIn, CField<3>& cFieldOut);
205
206 /*
207 * Has this object been setup?
208 */
209 template <int D>
210 inline bool FFT<D>::isSetup() const
211 { return isSetup_; }
212
213 /*
214 * Return the dimensions of the grid for which this was allocated.
215 */
216 template <int D>
217 inline IntVec<D> const & FFT<D>::meshDimensions() const
218 { return meshDimensions_; }
219
220 #ifndef PRDC_CPU_FFT_TPP
221 // Suppress implicit instantiation
222 extern template class FFT<1>;
223 extern template class FFT<2>;
224 extern template class FFT<3>;
225 #endif
226
227} // namespace Pscf::Prdc::Cpu
228} // namespace Pscf::Prdc
229} // namespace Pscf
230#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Fourier transform wrapper.
void inverseTransformUnsafe(RFieldDft< D > &in, RField< D > &out) const
Compute inverse (complex-to-real) DFT, overwriting the input.
Definition cpu/FFT.tpp:179
FFT()
Default constructor.
Definition cpu/FFT.tpp:57
void forwardTransform(RField< D > const &in, RFieldDft< D > &out) const
Compute forward (real-to-complex) discrete Fourier transform.
Definition cpu/FFT.tpp:151
void inverseTransform(CField< D > const &in, CField< D > &out) const
Compute complex-to-complex inverse Fourier transform.
Definition cpu/FFT.tpp:241
bool isSetup() const
Has this FFT object been setup?
Definition cpu/FFT.h:210
void setup(IntVec< D > const &meshDimensions)
Setup grid dimensions, FFT plans and work space.
Definition cpu/FFT.tpp:92
IntVec< D > const & meshDimensions() const
Return the dimensions of the grid for which this was setup.
Definition cpu/FFT.h:217
virtual ~FFT()
Destructor.
Definition cpu/FFT.tpp:72
void inverseTransformSafe(RFieldDft< D > const &in, RField< D > &out) const
Compute inverse (complex-to-real) DFT without overwriting input.
Definition cpu/FFT.tpp:197
File containing preprocessor macros for error handling.
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.