PSCF v1.4.0
cpu/WaveList.h
1#ifndef PRDC_CPU_WAVE_LIST_H
2#define PRDC_CPU_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/cpu/RField.h> // member
12#include <pscf/math/IntVec.h> // member
13#include <util/containers/DArray.h> // member
14#include <util/containers/GArray.h> // member
15#include <util/containers/Pair.h> // member
16
17// Forward declarations
18namespace Pscf {
19 template <int D> class Mesh;
20 namespace Prdc {
21 template <int D> class UnitCell;
22 }
23}
24
25namespace Pscf {
26namespace Prdc {
27namespace Cpu {
28
29 using namespace Util;
30
65 template <int D>
67 {
68 public:
69
72
78 WaveList(bool isRealField = true);
79
83 ~WaveList();
84
91 void allocate(Mesh<D> const & m, UnitCell<D> const & c);
92
96
104 void clearUnitCellData();
105
124
133 void computeKSq();
134
143 void computedKSq();
144
152 void sortWaves();
153
157
167 DArray< IntVec<D> > const & minImages() const;
168
177 RField<D> const & kSq() const;
178
196 RField<D> const & dKSq(int i) const;
197
205 DArray< RField<D> > const & dKSq() const;
206
221 DArray<bool> const & implicitInverse() const;
222
231 DArray<int> const & sortedIds() const;
232
246 GArray< Pair<int> > const & sortedBunches() const;
247
258 DArray<int> const & bunchIds() const;
259
267 { return kMeshDimensions_; }
268
275 int kSize() const
276 { return kSize_; }
277
281 int nBunch() const
282 {
283 UTIL_CHECK(isSorted_);
284 return nBunch_;
285 }
286
290
294 bool isAllocated() const
295 { return isAllocated_; }
296
300 bool hasMinImages() const
301 { return hasMinImages_; }
302
306 bool hasKSq() const
307 { return hasKSq_; }
308
312 bool hasdKSq() const
313 { return hasdKSq_; }
314
318 bool isSorted() const
319 { return isSorted_; }
320
324 bool isRealField() const
325 { return isRealField_; }
326
328
329 private:
330
331 /*
332 * Array indices for arrays minImages_, kSq_, dKSq_ implicitInverse_,
333 * and bunchIds_ correspond to ranks with the mesh with dimensions
334 * given by kMeshDimensions_.
335 */
336
340 DArray< IntVec<D> > minImages_;
341
345 RField<D> kSq_;
346
353 DArray< RField<D> > dKSq_;
354
360 DArray<bool> implicitInverse_;
361
367 DArray<int> sortedIds_;
368
379 GArray< Pair<int> > sortedBunches_;
380
390 DArray<int> bunchIds_;
391
398 IntVec<D> kMeshDimensions_;
399
406 int kSize_;
407
411 int nBunch_;
412
414 bool isAllocated_;
415
417 bool hasMinImages_;
418
420 bool hasKSq_;
421
423 bool hasdKSq_;
424
426 bool isSorted_;
427
429 bool isRealField_;
430
432 UnitCell<D> const * unitCellPtr_;
433
435 Mesh<D> const * meshPtr_;
436
438 UnitCell<D> const & unitCell() const
439 { return *unitCellPtr_; }
440
442 Mesh<D> const & mesh() const
443 { return *meshPtr_; }
444
445 };
446
447 // Get the array of minimum images on the device by reference.
448 template <int D> inline
450 {
451 UTIL_CHECK(hasMinImages_);
452 return minImages_;
453 }
454
455 // Get the kSq array on the device by reference.
456 template <int D> inline
458 {
459 UTIL_CHECK(hasKSq_);
460 return kSq_;
461 }
462
463 // Get dKSq for unit cell parameter array i.
464 template <int D> inline
465 RField<D> const & WaveList<D>::dKSq(int i) const
466 {
467 UTIL_CHECK(hasdKSq_);
468 return dKSq_[i];
469 }
470
471 // Get entire dKSq container by const reference.
472 template <int D> inline
474 {
475 UTIL_CHECK(hasdKSq_);
476 return dKSq_;
477 }
478
479 // Get the implicitInverse array by const reference.
480 template <int D> inline
482 {
483 UTIL_CHECK(isAllocated_);
484 UTIL_CHECK(isRealField_);
485 return implicitInverse_;
486 }
487
488 // Get the sortedIds array by const reference.
489 template <int D> inline
491 {
492 UTIL_CHECK(isSorted_);
493 return sortedIds_;
494 }
495
496 // Get the sortedBunches array by const reference.
497 template <int D> inline
499 {
500 UTIL_CHECK(isSorted_);
501 return sortedBunches_;
502 }
503
504 // Get the bunchIds array by const reference.
505 template <int D> inline
507 {
508 UTIL_CHECK(isSorted_);
509 return bunchIds_;
510 }
511
512 // Explicit instantiation declarations
513 extern template class WaveList<1>;
514 extern template class WaveList<2>;
515 extern template class WaveList<3>;
516
517} // Cpu
518} // Prdc
519} // Pscf
520#endif
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:27
Class to compute and store properties associated with wavevectors.
void computeKSq()
Compute square norm |k|^2 for all wavevectors.
RField< D > const & kSq() const
Get the kSq array on the device by const reference.
DArray< IntVec< D > > const & minImages() const
Get the array of minimum image vectors by const reference.
void sortWaves()
Sort waves in order of ascending wavevector norm.
bool hasMinImages() const
Are minimum images up to date ?
void computeMinimumImages()
Compute minimum images of wavevectors, and also calculates kSq.
GArray< Pair< int > > const & sortedBunches() const
Get the sortedBunches array by reference.
bool isRealField() const
Is this WaveList set up for use with real-valued fields?
bool hasKSq() const
Are values of kSq up-to-date ?
int nBunch() const
Return the number of bunches of sorted waves.
void allocate(Mesh< D > const &m, UnitCell< D > const &c)
Allocate memory and set association with a Mesh and UnitCell object.
bool isSorted() const
Have the waves been sorted by magnitude ?
void computedKSq()
Compute derivatives of |k|^2 w/ respect to unit cell parameters.
bool isAllocated() const
Has memory been allocated for arrays?
DArray< bool > const & implicitInverse() const
Get the implicitInverse array by reference.
int kSize() const
Return the number of points in the k-grid mesh.
bool hasdKSq() const
Are values of dKSq up-to-date?
DArray< int > const & sortedIds() const
Get the sortedIds array by reference.
void clearUnitCellData()
Clear all internal data that depends on lattice parameters.
WaveList(bool isRealField=true)
Constructor.
DArray< RField< D > > const & dKSq() const
Get all derivatives of kSq with respect to unit cell parameters.
DArray< int > const & bunchIds() const
Get the bunchIds array by reference.
IntVec< D > const & kMeshDimensions() const
Return the dimensions of the k-grid mesh.
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 and FFTs for periodic boundary conditions (CPU)
Definition complex.cpp:12
Periodic fields and crystallography.
Definition complex.cpp:11
PSCF package top-level namespace.