PSCF v1.1
pspc/field/FFT.h
1#ifndef PSPC_FFT_H
2#define PSPC_FFT_H
3
4/*
5* PSCF Package
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pspc/field/RField.h>
12#include <pspc/field/RFieldDft.h>
13#include <pscf/math/IntVec.h>
14#include <util/global.h>
15
16#include <fftw3.h>
17
18namespace Pscf {
19namespace Pspc {
20
21 using namespace Util;
22 using namespace Pscf;
23
29 template <int D>
30 class FFT
31 {
32
33 public:
34
38 FFT();
39
43 virtual ~FFT();
44
50 void setup(IntVec<D> const & meshDimensions);
51
58 void setup(RField<D>& rField, RFieldDft<D>& kField);
59
73 void forwardTransform(RField<D> const & in, RFieldDft<D>& out) const;
74
91 void inverseTransform(RFieldDft<D>& in, RField<D>& out) const;
92
99 void inverseTransformSafe(RFieldDft<D> const & in, RField<D>& out) const;
100
104 IntVec<D> const & meshDimensions() const;
105
109 bool isSetup() const;
110
111 private:
112
114 mutable RField<D> rFieldCopy_;
115
117 mutable RFieldDft<D> kFieldCopy_;
118
120 IntVec<D> meshDimensions_;
121
123 int rSize_;
124
126 int kSize_;
127
129 fftw_plan fPlan_;
130
132 fftw_plan iPlan_;
133
135 bool isSetup_;
136
140 void makePlans(RField<D>& rField, RFieldDft<D>& kField);
141
142 };
143
144 // Declarations of explicit specializations
145
146 template <>
147 void FFT<1>::makePlans(RField<1>& rField, RFieldDft<1>& kField);
148
149 template <>
150 void FFT<2>::makePlans(RField<2>& rField, RFieldDft<2>& kField);
151
152 template <>
153 void FFT<3>::makePlans(RField<3>& rField, RFieldDft<3>& kField);
154
155 /*
156 * Has this object been setup?
157 */
158 template <int D>
159 inline bool FFT<D>::isSetup() const
160 { return isSetup_; }
161
162 /*
163 * Return the dimensions of the grid for which this was allocated.
164 */
165 template <int D>
166 inline IntVec<D> const & FFT<D>::meshDimensions() const
167 { return meshDimensions_; }
168
169 #ifndef PSPC_FFT_TPP
170 // Suppress implicit instantiation
171 extern template class FFT<1>;
172 extern template class FFT<2>;
173 extern template class FFT<3>;
174 #endif
175
176} // namespace Pscf::Pspc
177} // namespace Pscf
178#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition: IntVec.h:27
Fourier transform wrapper for real data.
void forwardTransform(RField< D > const &in, RFieldDft< D > &out) const
Compute forward (real-to-complex) Fourier transform.
virtual ~FFT()
Destructor.
FFT()
Default constructor.
IntVec< D > const & meshDimensions() const
Return the dimensions of the grid for which this was allocated.
void inverseTransformSafe(RFieldDft< D > const &in, RField< D > &out) const
Compute inverse (complex-to-real) Fourier transform without destroying input.
void inverseTransform(RFieldDft< D > &in, RField< D > &out) const
Compute inverse (complex-to-real) Fourier transform.
bool isSetup() const
Has this FFT object been setup?
void setup(IntVec< D > const &meshDimensions)
Setup grid dimensions, plans and work space.
Fourier transform of a real field on an FFT mesh.
Definition: RFieldDft.h:31
Field of real double precision values on an FFT mesh.
Definition: RField.h:29
File containing preprocessor macros for error handling.
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1