PSCF v1.5.0
cpp/WaveList.h
1#ifndef PSCF_WAVE_LIST_CP_H
2#define PSCF_WAVE_LIST_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/CPT.h> // template argument
12#include <pscf/field/cpp/RField.h> // member
13#include <pscf/math/IntVec.h> // member
14#include <util/containers/DArray.h> // member
15#include <util/containers/GArray.h> // member
16#include <util/containers/Pair.h> // member
17
18#include <util/global.h> // inline functions
19
20// Forward declarations
21namespace Pscf {
22 template <int D> class Mesh;
23 template <int D> class UnitCell;
24}
25
26namespace Pscf {
27
28 using namespace Util;
29
30 // Declare primary template
31 template <int D, class T> class WaveList;
32
67 template <int D>
68 class WaveList<D,CPT>
69 {
70 public:
71
74
80 WaveList(bool isRealField = true);
81
85 ~WaveList();
86
87 // Prohibit copy construction and assignment.
88 WaveList(WaveList<D,CPT> const &) = delete;
89 WaveList<D,CPT>& operator = (WaveList<D,CPT> const &) = delete;
90
97 void allocate(Mesh<D> const & m, UnitCell<D> const & c);
98
102
110 void clearUnitCellData();
111
130
139 void computeKSq();
140
149 void computedKSq();
150
158 void sortWaves();
159
163
173 DArray< IntVec<D> > const & minImages() const;
174
183 RField<D,CPT> const & kSq() const;
184
202 RField<D,CPT> const & dKSq(int i) const;
203
211 DArray< RField<D,CPT> > const & dKSq() const;
212
227 DArray<bool> const & implicitInverse() const;
228
237 DArray<int> const & sortedIds() const;
238
252 GArray< Pair<int> > const & sortedBunches() const;
253
264 DArray<int> const & bunchIds() const;
265
273 { return kMeshDimensions_; }
274
281 int kSize() const
282 { return kSize_; }
283
287 int nBunch() const
288 {
289 UTIL_CHECK(isSorted_);
290 return nBunch_;
291 }
292
296
300 bool isAllocated() const
301 { return isAllocated_; }
302
306 bool hasMinImages() const
307 { return hasMinImages_; }
308
312 bool hasKSq() const
313 { return hasKSq_; }
314
318 bool hasdKSq() const
319 { return hasdKSq_; }
320
324 bool isSorted() const
325 { return isSorted_; }
326
330 bool isRealField() const
331 { return isRealField_; }
332
334
335 private:
336
337 /*
338 * Array indices for arrays minImages_, kSq_, dKSq_ implicitInverse_,
339 * and bunchIds_ correspond to ranks with the mesh with dimensions
340 * given by kMeshDimensions_.
341 */
342
346 DArray< IntVec<D> > minImages_;
347
351 RField<D,CPT> kSq_;
352
359 DArray< RField<D,CPT> > dKSq_;
360
366 DArray<bool> implicitInverse_;
367
373 DArray<int> sortedIds_;
374
385 GArray< Pair<int> > sortedBunches_;
386
396 DArray<int> bunchIds_;
397
404 IntVec<D> kMeshDimensions_;
405
412 int kSize_;
413
417 int nBunch_;
418
420 bool isAllocated_;
421
423 bool hasMinImages_;
424
426 bool hasKSq_;
427
429 bool hasdKSq_;
430
432 bool isSorted_;
433
435 bool isRealField_;
436
438 UnitCell<D> const * unitCellPtr_;
439
441 Mesh<D> const * meshPtr_;
442
444 UnitCell<D> const & unitCell() const
445 { return *unitCellPtr_; }
446
448 Mesh<D> const & mesh() const
449 { return *meshPtr_; }
450
451 };
452
453 // Get the array of minimum images on the device by reference.
454 template <int D> inline
456 {
457 UTIL_CHECK(hasMinImages_);
458 return minImages_;
459 }
460
461 // Get the kSq array on the device by reference.
462 template <int D> inline
464 {
465 UTIL_CHECK(hasKSq_);
466 return kSq_;
467 }
468
469 // Get dKSq for unit cell parameter array i.
470 template <int D> inline
472 {
473 UTIL_CHECK(hasdKSq_);
474 return dKSq_[i];
475 }
476
477 // Get entire dKSq container by const reference.
478 template <int D> inline
480 {
481 UTIL_CHECK(hasdKSq_);
482 return dKSq_;
483 }
484
485 // Get the implicitInverse array by const reference.
486 template <int D> inline
488 {
489 UTIL_CHECK(isAllocated_);
490 UTIL_CHECK(isRealField_);
491 return implicitInverse_;
492 }
493
494 // Get the sortedIds array by const reference.
495 template <int D> inline
497 {
498 UTIL_CHECK(isSorted_);
499 return sortedIds_;
500 }
501
502 // Get the sortedBunches array by const reference.
503 template <int D> inline
505 {
506 UTIL_CHECK(isSorted_);
507 return sortedBunches_;
508 }
509
510 // Get the bunchIds array by const reference.
511 template <int D> inline
513 {
514 UTIL_CHECK(isSorted_);
515 return bunchIds_;
516 }
517
518 // Explicit instantiation declarations
519 extern template class WaveList<1,CPT>;
520 extern template class WaveList<2,CPT>;
521 extern template class WaveList<3,CPT>;
522
523} // Pscf
524#endif
Backend identifier class for the C++ serial CPU backend.
Definition CPT.h:32
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
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:55
bool isSorted() const
Have the waves been sorted by magnitude ?
bool hasKSq() const
Are values of kSq up-to-date ?
void clearUnitCellData()
Clear all internal data that depends on lattice parameters.
IntVec< D > const & kMeshDimensions() const
Return the dimensions of the k-grid mesh.
DArray< bool > const & implicitInverse() const
Get the implicitInverse array by reference.
int nBunch() const
Return the number of bunches of sorted waves.
DArray< int > const & sortedIds() const
Get the sortedIds array by reference.
void allocate(Mesh< D > const &m, UnitCell< D > const &c)
Allocate memory and set association with a Mesh and UnitCell object.
bool hasMinImages() const
Are minimum images up to date ?
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.
void sortWaves()
Sort waves in order of ascending wavevector norm.
DArray< int > const & bunchIds() const
Get the bunchIds array by reference.
void computeMinimumImages()
Compute minimum images of wavevectors, and also calculates kSq.
RField< D, CPT > const & dKSq(int i) const
Get derivatives of kSq with respect to unit cell parameter i.
WaveList(bool isRealField=true)
Constructor.
void computedKSq()
Compute derivatives of |k|^2 w/ respect to unit cell parameters.
RField< D, CPT > const & kSq() const
Get the kSq array on the device by const reference.
bool isAllocated() const
Has memory been allocated for arrays?
DArray< IntVec< D > > const & minImages() const
Get the array of minimum image vectors by const reference.
void computeKSq()
Compute square norm |k|^2 for all wavevectors.
bool hasdKSq() const
Are values of dKSq up-to-date?
int kSize() const
Return the number of points in the k-grid mesh.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
An automatically growable array, analogous to a std::vector.
Definition GArray.h:34
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.