PSCF v1.5.0
cuda/FFT.h
1#ifndef PSCF_FFT_CU_H
2#define PSCF_FFT_CU_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pscf/backend/cuda/CUT.h> // class template argument
12#include "RFieldDft.h" // member
13#include <pscf/math/IntVec.h> // member
14
15#include <util/global.h>
16#include <cufft.h>
17
18// Forward declarations
19namespace Pscf {
20 template <int D, class T> class CField;
21 template <int D, class T> class RField;
22 template <int D, class T> class FFT;
23}
24
25namespace Pscf {
26
27 using namespace Util;
28
39 template <int D>
40 class FFT<D,CUT>
41 {
42
43 public:
44
48 FFT();
49
53 virtual ~FFT();
54
60 void setup(IntVec<D> const & meshDimensions);
61
62 // Real <-> Complex transforms
63
79 void forwardTransform(RField<D,CUT> const & rField, RFieldDft<D,CUT>& kField)
80 const;
81
96 const;
97
107 void inverseTransformSafe(RFieldDft<D,CUT> const & kField,
108 RField<D,CUT>& rField) const;
109
110 // Complex <-> Complex transforms
111
131 void forwardTransform(CField<D,CUT> const & rField, CField<D,CUT>& kField)
132 const;
133
150 void inverseTransform(CField<D,CUT> const & kField, CField<D,CUT>& rField)
151 const;
152
156 const IntVec<D>& meshDimensions() const;
157
161 bool isSetup() const;
162
163 // Static function
164
176 static
177 void computeKMesh(IntVec<D> const & rMeshDimensions,
178 IntVec<D> & kMeshDimensions,
179 int & kSize );
180
198 static
199 bool hasImplicitInverse(IntVec<D> const & wavevector,
200 IntVec<D> const & meshDimensions);
201
202 private:
203
205 IntVec<D> meshDimensions_;
206
208 mutable RFieldDft<D,CUT> kFieldCopy_;
209
211 int rSize_;
212
214 int kSize_;
215
217 cufftHandle rcfPlan_;
218
220 cufftHandle criPlan_;
221
223 cufftHandle ccPlan_;
224
226 bool isSetup_;
227
231 void makePlans();
232
233 };
234
235 // Declarations of explicit specializations
236
237 template <>
238 void FFT<1,CUT>::makePlans();
239
240 template <>
241 void FFT<2,CUT>::makePlans();
242
243 template <>
244 void FFT<3,CUT>::makePlans();
245
246 // Inline functions
247
248 /*
249 * Return the dimensions of the grid for which this was allocated.
250 */
251 template <int D>
253 { return meshDimensions_; }
254
255 /*
256 * Has this FFT object been setup?
257 */
258 template <int D>
259 inline bool FFT<D,CUT>::isSetup() const
260 { return isSetup_; }
261
262 /*
263 * Does this wavevector have an implicit inverse?
264 */
265 template <int D>
266 inline
269 {
270 int i = wavevector[D-1];
271 int d = meshDimensions[D-1];
272 UTIL_CHECK(i >= 0 && i < d);
273 if ( (i != 0) && (d - i > d / 2) ) {
274 return true;
275 } else {
276 return false;
277 }
278 }
279
280 // Explicit instantiation declarations
281 extern template class FFT<1,CUT>;
282 extern template class FFT<2,CUT>;
283 extern template class FFT<3,CUT>;
284
285} // namespace Pscf
286#endif
Backend identifier class for the GPU-enabled CUDA backend.
Definition CUT.h:31
void inverseTransform(CField< D, CUT > const &kField, CField< D, CUT > &rField) const
Compute inverse (complex-to-complex) discrete Fourier transform.
Definition cuda/FFT.tpp:247
void inverseTransformUnsafe(RFieldDft< D, CUT > &kField, RField< D, CUT > &rField) const
Compute inverse (complex-to-real) DFT, overwriting the input.
Definition cuda/FFT.tpp:166
const IntVec< D > & meshDimensions() const
Return the dimensions of the grid for which this was allocated.
Definition cuda/FFT.h:252
static void computeKMesh(IntVec< D > const &rMeshDimensions, IntVec< D > &kMeshDimensions, int &kSize)
Compute dimensions and size of k-space mesh for DFT of real data.
Definition cuda/FFT.tpp:279
void forwardTransform(RField< D, CUT > const &rField, RFieldDft< D, CUT > &kField) const
Compute forward (real-to-complex) discrete Fourier transform.
Definition cuda/FFT.tpp:135
static bool hasImplicitInverse(IntVec< D > const &wavevector, IntVec< D > const &meshDimensions)
Does a wavevector have an implicit inverse in DFT mesh for real data?
Definition cuda/FFT.h:267
bool isSetup() const
Has this FFT object been setup?
Definition cuda/FFT.h:259
void inverseTransformSafe(RFieldDft< D, CUT > const &kField, RField< D, CUT > &rField) const
Compute inverse (complex-to-real) DFT without overwriting input.
Definition cuda/FFT.tpp:192
void setup(IntVec< D > const &meshDimensions)
Setup mesh dimensions, plans and work space.
Definition cuda/FFT.tpp:98
FFT()
Default constructor.
Definition cuda/FFT.tpp:67
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.