PSCF v1.5.0
cpp/CField.h
1#ifndef PSCF_C_FIELD_CP_H
2#define PSCF_C_FIELD_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
17namespace Pscf {
18
19 using namespace Util;
20
21 // Declare primary template
22 template <int D, class T> class CField;
23
29 template <int D>
30 class CField<D,CPT>
31 : public BackendArray<fftw_complex,CPT>
32 {
33
34 public:
35
36 // Type aliases
37
38 using FftwDRArray<fftw_complex>::ValueType;
39
43 using RealType = double;
44
45 // Member functions
46
50 CField();
51
59 CField(CField<D,CPT> const & other);
60
66 virtual ~CField();
67
79 CField& operator = (CField<D,CPT> const & other);
80
89
93 virtual void deallocate();
94
98 const IntVec<D>& meshDimensions() const;
99
106 template <class Archive>
107 void serialize(Archive& ar, const unsigned int version);
108
109 private:
110
111 // Vector containing number of grid points in each direction.
112 IntVec<D> meshDimensions_;
113
114 using FftwDRArray<fftw_complex>::allocate;
115
116 };
117
118 /*
119 * Return mesh dimensions by constant reference.
120 */
121 template <int D> inline
123 { return meshDimensions_; }
124
125 /*
126 * Serialize a Field to/from an Archive.
127 */
128 template <int D>
129 template <class Archive>
131 Archive& ar,
132 const unsigned int version)
133 {
135 ar & meshDimensions_;
136 }
137
138 // Explicit instantiation declarations
139 extern template class CField<1,CPT>;
140 extern template class CField<2,CPT>;
141 extern template class CField<3,CPT>;
142
143} // namespace Pscf
144#endif
CField()
Default constructor.
const IntVec< D > & meshDimensions() const
Return mesh dimensions by constant reference.
Definition cpp/CField.h:122
virtual void deallocate()
Deallocate underlying C array and clear mesh dimensions.
void allocate(const IntVec< D > &meshDimensions)
Allocate the underlying C array for an FFT grid.
double RealType
Type of real and imaginary parts of a complex value.
Definition cpp/CField.h:43
void serialize(Archive &ar, const unsigned int version)
Serialize a Field to/from an Archive.
Definition cpp/CField.h:130
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
PSCF package top-level namespace.