PSCF v1.5.0
cpp/RFieldDft.h
1#ifndef PSCF_R_FIELD_DFT_CP_H
2#define PSCF_R_FIELD_DFT_CP_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/cpp/BackendArray.h> // base class
12#include <pscf/backend/cpp/CPT.h> // backend identifier class
13#include <pscf/math/IntVec.h> // member
14
15#include <fftw3.h>
16
17// Forward declaration
18namespace Pscf {
19 template <typename Data, class T> class HostSendArray;
20}
21
22namespace Pscf {
23
24 using namespace Util;
25
26 // Declaration of primary template
27 template <int D, class T> class RFieldDft;
28
34 template <int D>
35 class RFieldDft<D,CPT>
36 : public BackendArray<fftw_complex,CPT>
37 {
38
39 public:
40
41 // Type aliases
42
46 using FftwDRArray<fftw_complex>::ValueType;
47
51 using RealType = double;
52
53 // Member functions
54
58 RFieldDft();
59
67 RFieldDft(RFieldDft<D,CPT> const & other);
68
74 virtual ~RFieldDft();
75
90 operator = (RFieldDft<D,CPT> const & other);
91
105 RFieldDft<D,CPT>& operator = (HostSendArray<fftw_complex,CPT> const & other);
106
114 void allocate(IntVec<D> const & meshDimensions);
115
119 virtual void deallocate();
120
124 IntVec<D> const & meshDimensions() const;
125
133 IntVec<D> const & dftDimensions() const;
134
141 template <class Archive>
142 void serialize(Archive& ar, const unsigned int version);
143
144 private:
145
146 // Vector containing number of grid points in each direction.
147 IntVec<D> meshDimensions_;
148
149 // Vector containing dimensions of dft (Fourier) grid.
150 IntVec<D> dftDimensions_;
151
152 // Declare private to prevent allocation without mesh dimensions.
153 using BackendArray<fftw_complex,CPT>::allocate;
154
155 // Declare private to prevent association without mesh dimensions.
156 using BackendArray<fftw_complex,CPT>::associate;
157
158 // Declare private to prevent assignment without mesh dimensions.
159 using BackendArray<fftw_complex,CPT>::operator =;
160
161 };
162
163 /*
164 * Return mesh dimensions by const reference.
165 */
166 template <int D> inline
168 { return meshDimensions_; }
169
170 /*
171 * Return dimensions of dft grid by const reference.
172 */
173 template <int D> inline
175 { return dftDimensions_; }
176
177 /*
178 * Serialize a Field to/from an Archive.
179 */
180 template <int D>
181 template <class Archive>
183 const unsigned int version)
184 {
186 ar & meshDimensions_;
187 ar & dftDimensions_;
188 }
189
190 // Explicit instantiation declarations
191 extern template class RFieldDft<1,CPT>;
192 extern template class RFieldDft<2,CPT>;
193 extern template class RFieldDft<3,CPT>;
194
195} // namespace Pscf
196#endif
Backend identifier class for the C++ serial CPU backend.
Definition CPT.h:32
Dynamic reference counted array for use with FFTW library.
Definition FftwDRArray.h:72
void serialize(Archive &ar, const unsigned int version)
Serialize an FftwDRArray to/from an Archive.
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
void serialize(Archive &ar, const unsigned int version)
Serialize a Field to/from an Archive.
IntVec< D > const & dftDimensions() const
Return vector of dft (Fourier) grid dimensions by const reference.
RFieldDft()
Default constructor.
double RealType
Type of real and imaginary parts of a complex element value.
virtual void deallocate()
Deallocate underlying C array and clear mesh dimensions.
IntVec< D > const & meshDimensions() const
Return vector of spatial mesh dimensions by const reference.
void allocate(IntVec< D > const &meshDimensions)
Allocate the underlying C array and set mesh dimensions.
PSCF package top-level namespace.