PSCF v1.4.0
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> // member
12#include <pscf/cuda/DeviceArray.h> // member
13#include <pscf/cuda/HostDArray.h> // member
14#include <pscf/math/IntVec.h> // member
15#include <util/containers/DArray.h> // member
16#include <util/containers/GArray.h> // member
17#include <util/containers/Pair.h> // member
18
19// Forward declarations
20namespace Pscf {
21 template <int D> class Mesh;
22 namespace Prdc {
23 template <int D> class UnitCell;
24 }
25}
26
27namespace Pscf {
28namespace Prdc {
29namespace Cuda {
30
31 using namespace Util;
32
67 template <int D>
69 {
70 public:
71
74
80 WaveList(bool isRealField = true);
81
85 ~WaveList();
86
93 void allocate(Mesh<D> const & m, UnitCell<D> const & c);
94
98
105 void clearUnitCellData();
106
125
134 void computeKSq();
135
144 void computedKSq();
145
153 void sortWaves();
154
158
169 DeviceArray<int> const & minImages_d() const;
170
179 HostDArray< IntVec<D> > const & minImages_h() const;
180
189 RField<D> const & kSq() const;
190
209 RField<D> const & dKSq(int i) const;
210
222 DeviceArray<bool> const & implicitInverse() const;
223
232 DArray<int> const & sortedIds() const;
233
246 GArray< Pair<int> > const & sortedBunches() const;
247
258 DArray<int> const & bunchIds() const;
259
267 { return kMeshDimensions_; }
268
276 int kSize() const
277 { return kSize_; }
278
282 int nBunch() const
283 {
284 UTIL_CHECK(isSorted_);
285 return nBunch_;
286 }
287
291
295 bool isAllocated() const
296 { return isAllocated_; }
297
301 bool hasMinImages() const
302 { return hasMinImages_; }
303
307 bool hasKSq() const
308 { return hasKSq_; }
309
313 bool hasdKSq() const
314 { return hasdKSq_; }
315
319 bool isSorted() const
320 { return isSorted_; }
321
325 bool isRealField() const
326 { return isRealField_; }
327
329
330 private:
331
332 // Private member variables
333
345 DeviceArray<int> minImages_;
346
356 mutable
357 HostDArray< IntVec<D> > minImages_h_;
358
364 RField<D> kSq_;
365
373
388 DArray< RField<D> > dKSqSlices_;
389
396 DeviceArray<bool> implicitInverse_;
397
403 DArray<int> sortedIds_;
404
415 GArray< Pair<int> > sortedBunches_;
416
426 DArray<int> bunchIds_;
427
440 IntVec<D> kMeshDimensions_;
441
450 int kSize_;
451
455 int nBunch_;
456
458 bool isAllocated_;
459
461 bool hasMinImages_;
462
464 mutable
465 bool hasMinImages_h_;
466
468 bool hasKSq_;
469
471 bool hasdKSq_;
472
474 bool isSorted_;
475
477 bool isRealField_;
478
480 UnitCell<D> const * unitCellPtr_;
481
483 Mesh<D> const * meshPtr_;
484
485 // Private member functions
486
488 UnitCell<D> const & unitCell() const
489 { return *unitCellPtr_; }
490
492 Mesh<D> const & mesh() const
493 { return *meshPtr_; }
494
495 };
496
497 // Get the array of minimum images on the device by reference.
498 template <int D> inline
500 {
501 UTIL_CHECK(hasMinImages_);
502 return minImages_;
503 }
504
505 // Get the kSq array on the device by reference.
506 template <int D> inline
508 {
509 UTIL_CHECK(hasKSq_);
510 return kSq_;
511 }
512
513 // Get a slice of the dKSq array on the device by reference.
514 template <int D> inline
515 RField<D> const & WaveList<D>::dKSq(int i) const
516 {
517 UTIL_CHECK(hasdKSq_);
518 return dKSqSlices_[i];
519 }
520
521 // Get the implicitInverse array by reference.
522 template <int D> inline
524 {
525 UTIL_CHECK(isAllocated_);
526 UTIL_CHECK(isRealField_);
527 return implicitInverse_;
528 }
529
530 // Get the sortedIds array by const reference.
531 template <int D>
532 inline
534 {
535 UTIL_CHECK(isSorted_);
536 return sortedIds_;
537 }
538
539 // Get the sortedBunches array by const reference.
540 template <int D> inline
542 {
543 UTIL_CHECK(isSorted_);
544 return sortedBunches_;
545 }
546
547 // Get the bunchIds array by const reference.
548 template <int D> inline
550 {
551 UTIL_CHECK(isSorted_);
552 return bunchIds_;
553 }
554
555 // Explicit instantiation declarations
556 extern template class WaveList<1>;
557 extern template class WaveList<2>;
558 extern template class WaveList<3>;
559
560} // namespace Cuda
561} // namespace Prdc
562} // namespace Pscf
563#endif
Dynamic array on the GPU device with aligned data.
Definition DeviceArray.h:96
Template for dynamic array stored in host CPU memory.
Definition HostDArray.h:41
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 values on a regular mesh, allocated on a GPU device.
Definition cuda/RField.h:33
Class to compute and store properties associated with wavevectors.
bool isAllocated() const
Has memory been allocated for arrays?
void sortWaves()
Sort waves in order of ascending wavevector norm.
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.
DArray< int > const & sortedIds() const
Get the sortedIds array by reference.
DeviceArray< int > const & minImages_d() const
Get the array of minimum images on the device by reference.
void computeMinimumImages()
Compute minimum images of wavevectors, and also calculate kSq.
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
Is this WaveList set up for use with real-valued fields?
GArray< Pair< int > > const & sortedBunches() const
Get the sortedBunches array by reference.
int kSize() const
Return the number of points in the k-space mesh.
int nBunch() const
Return the number of bunches of sorted waves.
bool isSorted() const
Have the waves been sorted by magnitude ?
RField< D > const & kSq() const
Get the kSq array on the device by reference.
IntVec< D > const & kMeshDimensions() const
Return the dimensions of the k-space mesh.
DArray< int > const & bunchIds() const
Get the bunchIds array 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
An automatically growable array, analogous to a std::vector.
Definition GArray.h:34
#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 CField.cu:12
Periodic fields and crystallography.
Definition complex.cpp:11
PSCF package top-level namespace.