PSCF v1.3
cuda/WaveList.h
1#ifndef PRDC_CUDA_WAVE_LIST_H
2#define PRDC_CUDA_WAVE_LIST_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <prdc/cuda/RField.h>
12#include <prdc/crystal/UnitCell.h>
13
14#include <pscf/mesh/Mesh.h>
15#include <pscf/math/IntVec.h>
16#include <pscf/cuda/DeviceArray.h>
17#include <pscf/cuda/HostDArray.h>
18
19#include <util/containers/DArray.h>
20
21namespace Pscf {
22namespace Prdc {
23namespace Cuda {
24
25 using namespace Util;
26
47 template <int D>
49 {
50 public:
51
57 WaveList(bool isRealField = true);
58
63
70 void allocate(Mesh<D> const & m, UnitCell<D> const & c);
71
79
94
102
107
118 DeviceArray<int> const & minImages_d() const;
119
127 HostDArray< IntVec<D> > const & minImages_h() const;
128
137 RField<D> const & kSq() const;
138
157 RField<D> const & dKSq(int i) const;
158
171
175 bool isAllocated() const
176 { return isAllocated_; }
177
181 bool hasMinImages() const
182 { return hasMinImages_; }
183
187 bool hasKSq() const
188 { return hasKSq_; }
189
193 bool hasdKSq() const
194 { return hasdKSq_; }
195
199 bool isRealField() const
200 { return isRealField_; }
201
202 private:
203
214 DeviceArray<int> minImages_;
215
225 mutable
226 HostDArray< IntVec<D> > minImages_h_;
227
229 RField<D> kSq_;
230
233
235 DArray<RField<D> > dKSqSlices_;
236
238 DeviceArray<bool> implicitInverse_;
239
247 IntVec<D> kMeshDimensions_;
248
256 int kSize_;
257
259 bool isAllocated_;
260
262 bool hasMinImages_;
263
265 mutable
266 bool hasMinImages_h_;
267
269 bool hasKSq_;
270
272 bool hasdKSq_;
273
275 bool isRealField_;
276
278 UnitCell<D> const * unitCellPtr_;
279
281 Mesh<D> const * meshPtr_;
282
284 UnitCell<D> const & unitCell() const
285 { return *unitCellPtr_; }
286
288 Mesh<D> const & mesh() const
289 { return *meshPtr_; }
290
291 };
292
293 // Get the array of minimum images on the device by reference.
294 template <int D>
296 {
297 UTIL_CHECK(hasMinImages_);
298 return minImages_;
299 }
300
301 // Get the kSq array on the device by reference.
302 template <int D>
303 inline RField<D> const & WaveList<D>::kSq() const
304 {
305 UTIL_CHECK(hasKSq_);
306 return kSq_;
307 }
308
309 // Get a slice of the dKSq array on the device by reference.
310 template <int D>
311 inline RField<D> const & WaveList<D>::dKSq(int i) const
312 {
313 UTIL_CHECK(hasdKSq_);
314 return dKSqSlices_[i];
315 }
316
317 // Get the implicitInverse array by reference.
318 template <int D>
320 {
321 UTIL_CHECK(isAllocated_);
322 UTIL_CHECK(isRealField_);
323 return implicitInverse_;
324 }
325
326 #ifndef PRDC_CUDA_WAVE_LIST_TPP
327 // Suppress implicit instantiation
328 extern template class WaveList<1>;
329 extern template class WaveList<2>;
330 extern template class WaveList<3>;
331 #endif
332
333} // Cuda
334} // Prdc
335} // Pscf
336#endif
Dynamic array on the GPU device with aligned data.
Definition DeviceArray.h:43
Template for dynamic array stored in host CPU memory.
Definition HostDArray.h:43
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Description of a regular grid of points in a periodic domain.
Definition Mesh.h:61
Field of real double precision values on an FFT mesh.
Definition cpu/RField.h:29
DArray< RField< D > > const & dKSq() const
Get all derivatives of kSq with respect to unit cell parameters.
bool isAllocated() const
Has memory been allocated for arrays?
bool hasdKSq() const
Has the dKSq array been computed?
void clearUnitCellData()
Clear all internal data that depends on lattice parameters.
void computedKSq()
Compute derivatives of |k|^2 w/ respect to unit cell parameters.
WaveList(bool isRealField=true)
Constructor.
DeviceArray< int > const & minImages_d() const
Get the array of minimum images on the device by reference.
void computeMinimumImages()
Compute minimum images of wavevectors.
void allocate(Mesh< D > const &m, UnitCell< D > const &c)
Allocate memory and set association with a Mesh and UnitCell object.
void computeKSq()
Compute square norm |k|^2 for all wavevectors.
bool isRealField() const
Does this WaveList correspond to real-valued fields?
RField< D > const & kSq() const
Get the kSq array on the device by reference.
HostDArray< IntVec< D > > const & minImages_h() const
Get minimum images as IntVec<D> objects on the host.
RField< D > const & dKSq(int i) const
Get derivatives of |k|^2 with respect to lattice parameter i.
bool hasMinImages() const
Have minimum images been computed?
bool hasKSq() const
Has the kSq array been computed?
DeviceArray< bool > const & implicitInverse() const
Get the implicitInverse array by reference.
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
Dynamically allocatable contiguous array template.
Definition DArray.h:32
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Fields, FFTs, and utilities for periodic boundary conditions (CUDA)
Definition Reduce.cpp:14
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1