PSCF v1.5.0
cpp/RField.h
1#ifndef PSCF_R_FIELD_CP_H
2#define PSCF_R_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// Forward declaration
16namespace Pscf {
17 template <typename Data, class T> class HostSendArray;
18}
19
20namespace Pscf {
21
22 using namespace Util;
23
24 // Declaration of primary class template
25 template <int D, class T> class RField;
26
32 template <int D>
33 class RField<D,CPT> : public BackendArray<double,CPT>
34 {
35
36 public:
37
38 // Public type alias
39
40 using typename FftwDRArray<double>::ValueType;
41
42 // Public member functions
43
47 RField();
48
56 RField(const RField<D,CPT>& other);
57
61 ~RField() override = default;
62
73 RField<D,CPT>& operator = (RField<D,CPT> const& other);
74
88 RField<D,CPT>& operator = (HostSendArray<double,CPT> const & other);
89
97 void allocate(IntVec<D> const & meshDimensions);
98
102 void deallocate() override;
103
113 void associate(BackendArray<double,CPT>& arr, int beginId,
114 IntVec<D> const & meshDimensions);
115
119 IntVec<D> const & meshDimensions() const;
120
127 template <class Archive>
128 void serialize(Archive& ar, const unsigned int version);
129
130 using BackendArray<double,CPT>::dissociate;
131
132 private:
133
134 // Vector containing number of grid points in each direction.
135 IntVec<D> meshDimensions_;
136
137 // Make private to prevent allocation without mesh dimensions.
138 using BackendArray<double,CPT>::allocate;
139
140 // Make private to prevent association without mesh dimensions.
141 using BackendArray<double,CPT>::associate;
142
143 // Make private to prevent assignment without mesh dimensions.
144 using BackendArray<double,CPT>::operator =;
145
146 };
147
148 /*
149 * Return mesh dimensions by constant reference.
150 */
151 template <int D> inline
153 { return meshDimensions_; }
154
155 /*
156 * Serialize a Field to/from an Archive.
157 */
158 template <int D>
159 template <class Archive>
160 void RField<D,CPT>::serialize(Archive& ar,
161 const unsigned int version)
162 {
164 ar & meshDimensions_;
165 }
166
167 // Explicit instantiation declarations
168 extern template class RField<1,CPT>;
169 extern template class RField<2,CPT>;
170 extern template class RField<3,CPT>;
171
172} // namespace Pscf
173#endif
174
Backend identifier class for the C++ serial CPU backend.
Definition CPT.h:32
Data ValueType
Data type of each array element.
Definition FftwDRArray.h:79
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.
Definition cpp/RField.h:160
void associate(BackendArray< double, CPT > &arr, int beginId, IntVec< D > const &meshDimensions)
Associate this object with a slice of another BackendArray.
void allocate(IntVec< D > const &meshDimensions)
Allocate the underlying C array for values on a regular mesh.
~RField() override=default
Destructor.
void deallocate() override
Deallocate memory and return to empty state.
RField()
Default constructor.
IntVec< D > const & meshDimensions() const
Return mesh dimensions by constant reference.
Definition cpp/RField.h:152
PSCF package top-level namespace.