PSCF v1.4.0
Pscf::Prdc::Cuda::WaveList< D > Class Template Reference

Class to compute and store properties associated with wavevectors. More...

#include <WaveList.h>

Public Member Functions

Construction, Destruction and Initialization
 WaveList (bool isRealField=true)
 Constructor.
 ~WaveList ()
 Destructor.
void allocate (Mesh< D > const &m, UnitCell< D > const &c)
 Allocate memory and set association with a Mesh and UnitCell object.
Computation
void clearUnitCellData ()
 Clear all internal data that depends on lattice parameters.
void computeMinimumImages ()
 Compute minimum images of wavevectors, and also calculate kSq.
void computeKSq ()
 Compute square norm |k|^2 for all wavevectors.
void computedKSq ()
 Compute derivatives of |k|^2 w/ respect to unit cell parameters.
void sortWaves ()
 Sort waves in order of ascending wavevector norm.
Data Access
DeviceArray< int > const & minImages_d () const
 Get the array of minimum images 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 & kSq () const
 Get the kSq array on the device by reference.
RField< D > const & dKSq (int i) const
 Get derivatives of |k|^2 with respect to lattice parameter i.
DeviceArray< bool > const & implicitInverse () const
 Get the implicitInverse array by reference.
DArray< int > const & sortedIds () const
 Get the sortedIds array by reference.
GArray< Pair< int > > const & sortedBunches () const
 Get the sortedBunches array by reference.
DArray< int > const & bunchIds () const
 Get the bunchIds array by reference.
IntVec< D > const & kMeshDimensions () const
 Return the dimensions of the k-space mesh.
int kSize () const
 Return the number of points in the k-space mesh.
int nBunch () const
 Return the number of bunches of sorted waves.
Boolean Queries
bool isAllocated () const
 Has memory been allocated for arrays?
bool hasMinImages () const
 Have minimum images been computed?
bool hasKSq () const
 Has the kSq array been computed?
bool hasdKSq () const
 Has the dKSq array been computed?
bool isSorted () const
 Have the waves been sorted by magnitude ?
bool isRealField () const
 Is this WaveList set up for use with real-valued fields?

Detailed Description

template<int D>
class Pscf::Prdc::Cuda::WaveList< D >

Class to compute and store properties associated with wavevectors.

A WaveList computes and stores minimum images of wavevectors, square norms of wavevectors (kSq), and derivatives of the square norms with respect to the unit cell parameters (dKSq). A WaveList can also be used to sort wavevectors in order of increasing wavevector norm.

A WaveList computes these properties for a mesh of grid points in k-space. Different dimensions are used for this mesh depending on the value of the parameter isRealField that is passed to constructor. This parameter specifies whether this class will use a k-space mesh designed for real or complex fields throughout the lifetime of this WaveList object. If isRealField == true, this class uses the k-space mesh used by FFTW for the result of a real-to-complex discrete Fourier transform, which is contains slightly more than half the number of grid points as the corresponding real-space mesh. If isRealField == true, this class uses a k-space mesh with dimensions that are the same as those of the associated real-space mesh. The dimensions of this k-space mesh are returned as an IntVec<D> by member function kMeshDimensions().

In most of the arrays constructed by this class, each element corresponds to a wavevector in the associated k-space mesh, and the index of each element correspond to the rank of the associated wavevector within that mesh. This applies to the arrays returned by the functions minImages(), kSq(), dkSq(int i), and bunchIds().

Any time the lattice parameters change, the clearUnitCellData() method should be called. This function sets internal flags that mark some properties as being outdated, indicating that they are outdated and thus must be recalculated before the next use.

Definition at line 68 of file cuda/WaveList.h.

Constructor & Destructor Documentation

◆ WaveList()

template<int D>
Pscf::Prdc::Cuda::WaveList< D >::WaveList ( bool isRealField = true)

Constructor.

Parameters
isRealFieldWill this object be used for real-valued fields?

Definition at line 441 of file cuda/WaveList.tpp.

References isRealField().

◆ ~WaveList()

template<int D>
Pscf::Prdc::Cuda::WaveList< D >::~WaveList ( )

Destructor.

Definition at line 459 of file cuda/WaveList.tpp.

Member Function Documentation

◆ allocate()

template<int D>
void Pscf::Prdc::Cuda::WaveList< D >::allocate ( Mesh< D > const & m,
UnitCell< D > const & c )

Allocate memory and set association with a Mesh and UnitCell object.

Parameters
mspatial discretization mesh (input)
ccrystallographic unit cell (input)

Definition at line 492 of file cuda/WaveList.tpp.

References Pscf::MeshIterator< D >::atEnd(), Pscf::MeshIterator< D >::begin(), clearUnitCellData(), Pscf::Prdc::Cuda::FFT< D >::computeKMesh(), Pscf::Prdc::UnitCellBase< D >::nParameter(), Pscf::MeshIterator< D >::position(), Pscf::MeshIterator< D >::rank(), Pscf::Mesh< D >::size(), and UTIL_CHECK.

◆ clearUnitCellData()

template<int D>
void Pscf::Prdc::Cuda::WaveList< D >::clearUnitCellData ( )

Clear all internal data that depends on lattice parameters.

Sets hasKSq_ and hasdKSq_ to false, and sets hasMinImages_ to false only if the unit cell type has variable angles.

Definition at line 552 of file cuda/WaveList.tpp.

References Pscf::Prdc::hasVariableAngle().

Referenced by allocate().

◆ computeMinimumImages()

template<int D>
void Pscf::Prdc::Cuda::WaveList< D >::computeMinimumImages ( )

Compute minimum images of wavevectors, and also calculate kSq.

This function recomputes the minimum images of all wavevectors if necessary (i.e., if hasMinImages() == false), but does nothing if the minimum images are up to date (if hasMinImages() == true).

The minimum images may change if a lattice angle in the unit cell is changed, so this method should be called whenever such changes occur.

In the process of computing the minimum images, the square norm |k|^2 for all wavevectors is also calculated and stored, so it is not necessary to call computeKSq after calling this method. computeKSq is provided to allow calculation of kSq without recalculating minimum images.

Definition at line 571 of file cuda/WaveList.tpp.

References Pscf::MeshIterator< D >::atEnd(), Pscf::MeshIterator< D >::begin(), Pscf::DeviceArray< Data >::cArray(), Util::Log::file(), Pscf::MeshIterator< D >::position(), Pscf::MeshIterator< D >::rank(), Pscf::ThreadArray::setThreadsLogical(), Pscf::ThreadArray::setThreadsPerBlock(), and UTIL_CHECK.

Referenced by computedKSq(), and computeKSq().

◆ computeKSq()

template<int D>
void Pscf::Prdc::Cuda::WaveList< D >::computeKSq ( )

Compute square norm |k|^2 for all wavevectors.

This function recomputes values of the square norm for all wavevectors if necessary (i.e., if hasKSq() == false), and does nothing if these values are up to date (if hasKSq() == true). Mininum image values are updated if necessary.

Definition at line 650 of file cuda/WaveList.tpp.

References Pscf::DeviceArray< Data >::cArray(), computeMinimumImages(), Pscf::ThreadArray::setThreadsLogical(), and UTIL_CHECK.

Referenced by sortWaves().

◆ computedKSq()

template<int D>
void Pscf::Prdc::Cuda::WaveList< D >::computedKSq ( )

Compute derivatives of |k|^2 w/ respect to unit cell parameters.

This function computes values of the derivatives of wavevector square norms with respect to unit cell parameters if necessary (i.e., if hasdKSq() == false), and does nothing if these values are up to date. Minimum images are updated if necessary.

Definition at line 699 of file cuda/WaveList.tpp.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), computeMinimumImages(), Pscf::ThreadArray::setThreadsLogical(), and UTIL_CHECK.

◆ sortWaves()

template<int D>
void Pscf::Prdc::Cuda::WaveList< D >::sortWaves ( )

Sort waves in order of ascending wavevector norm.

This function computes the sortedIds, sortedBunches, and bunchIds arrays. Values of kSq are updated before sorting waves if hasKSq() is false on entry.

Definition at line 759 of file cuda/WaveList.tpp.

References computeKSq(), Pscf::Sort::findBunches(), Pscf::Sort::sort(), and UTIL_CHECK.

◆ minImages_d()

template<int D>
DeviceArray< int > const & Pscf::Prdc::Cuda::WaveList< D >::minImages_d ( ) const
inline

Get the array of minimum images on the device by reference.

The array has size kSize * D, where kSize is the number of grid points in the FFT k-space mesh. The array is unwrapped into a linear array in an index-by-index manner, in which the first kSize elements of the array contain the first index of each minimum image, and so on. If isRealField is true, kSize is smaller than the size of the real-space mesh. Otherwise, it is equal.

Definition at line 499 of file cuda/WaveList.h.

References UTIL_CHECK.

◆ minImages_h()

template<int D>
HostDArray< IntVec< D > > const & Pscf::Prdc::Cuda::WaveList< D >::minImages_h ( ) const

Get minimum images as IntVec<D> objects on the host.

This function returns an array of kSize elements in which each element is an IntVec<D> containing the integer coordinates of the minimum image of one wavevector in the k-space mesh used for discrete Fourier transforms.

Definition at line 827 of file cuda/WaveList.tpp.

References UTIL_CHECK.

◆ kSq()

template<int D>
RField< D > const & Pscf::Prdc::Cuda::WaveList< D >::kSq ( ) const
inline

Get the kSq array on the device by reference.

This method returns an RField<D> in which each element is the square magnitude |k|^2 of a wavevector k in the k-space mesh used for a DFT. If isRealField is true, this k-space mesh is smaller than the real-space mesh. Otherwise, it is the same size.

Definition at line 507 of file cuda/WaveList.h.

References UTIL_CHECK.

Referenced by Pscf::Rpg::BinaryStructureFactor< D >::setup().

◆ dKSq()

template<int D>
RField< D > const & Pscf::Prdc::Cuda::WaveList< D >::dKSq ( int i) const
inline

Get derivatives of |k|^2 with respect to lattice parameter i.

This method returns an RField<D> in which each element is the derivative of the square-wavevector with respect to unit cell parameter i, multiplied by a prefactor. The prefactor is 2.0 for waves that have an implicit inverse and 1.0 otherwise. The choice of prefactor is designed to simplify use of the array to compute stress.

Each element corresponds to one wavevector k in the k-space mesh used for the DFT. If isRealField is true, this k-space mesh is smaller than the real-space mesh. Otherwise, it is the same size. In the latter case, there are no implicit waves, so the prefactor is always 1.0.

Parameters
iindex of lattice parameter

Definition at line 515 of file cuda/WaveList.h.

References UTIL_CHECK.

◆ implicitInverse()

template<int D>
DeviceArray< bool > const & Pscf::Prdc::Cuda::WaveList< D >::implicitInverse ( ) const
inline

Get the implicitInverse array by reference.

This array is defined on a k-grid mesh, with a boolean value for each wavevector. The boolean represents whether the inverse of the wave at the given gridpoint is an implicit wave. Implicit here is used to mean any wave that is outside the bounds of the k-grid.

This method will throw an error if isRealField == false, because there are no implicit inverses in such a case.

Definition at line 523 of file cuda/WaveList.h.

References UTIL_CHECK.

Referenced by Pscf::Rpg::BinaryStructureFactor< D >::setup().

◆ sortedIds()

template<int D>
DArray< int > const & Pscf::Prdc::Cuda::WaveList< D >::sortedIds ( ) const
inline

Get the sortedIds array by reference.

The array returned by this function contains k-grid rank indices of wavevectors sorted in order of increasing wavevector magnitude.

This method throws an Exception if isSorted == false.

Definition at line 533 of file cuda/WaveList.h.

References UTIL_CHECK.

◆ sortedBunches()

template<int D>
GArray< Pair< int > > const & Pscf::Prdc::Cuda::WaveList< D >::sortedBunches ( ) const
inline

Get the sortedBunches array by reference.

Each element in this array contains a Pair<int> of two integers that give upper and lower index bounds of a contiguous slice (a "bunch") that contains ids of wavevectors of equal magnitude. The first value in such a pair is the array index in sortIds_ of the first element of such bunch, and the second is one greater than the index of the last element in that bunch.

This method throws an Exception if isSorted == false.

Definition at line 541 of file cuda/WaveList.h.

References UTIL_CHECK.

◆ bunchIds()

template<int D>
DArray< int > const & Pscf::Prdc::Cuda::WaveList< D >::bunchIds ( ) const
inline

Get the bunchIds array by reference.

This function returns an array, indexed by wave rank, in which the value is the integer identifier of a bunch to which the wave belongs. Each such value corresponds to an array index of the corresponding bunch in the sortedBunches array.

This method throws an Exception if isSorted == false.

Definition at line 549 of file cuda/WaveList.h.

References UTIL_CHECK.

◆ kMeshDimensions()

template<int D>
IntVec< D > const & Pscf::Prdc::Cuda::WaveList< D >::kMeshDimensions ( ) const
inline

Return the dimensions of the k-space mesh.

If isRealField() == true, the reciprocal-space grid is smaller than the real-space grid. Otherwise, the two grids are identical.

Definition at line 266 of file cuda/WaveList.h.

◆ kSize()

template<int D>
int Pscf::Prdc::Cuda::WaveList< D >::kSize ( ) const
inline

Return the number of points in the k-space mesh.

If isRealField() == true, kSize is approximately half the size of the real-space grid. Otherwise, the two grids are identical.

Definition at line 276 of file cuda/WaveList.h.

◆ nBunch()

template<int D>
int Pscf::Prdc::Cuda::WaveList< D >::nBunch ( ) const
inline

Return the number of bunches of sorted waves.

Definition at line 282 of file cuda/WaveList.h.

References UTIL_CHECK.

◆ isAllocated()

template<int D>
bool Pscf::Prdc::Cuda::WaveList< D >::isAllocated ( ) const
inline

Has memory been allocated for arrays?

Definition at line 295 of file cuda/WaveList.h.

◆ hasMinImages()

template<int D>
bool Pscf::Prdc::Cuda::WaveList< D >::hasMinImages ( ) const
inline

Have minimum images been computed?

Definition at line 301 of file cuda/WaveList.h.

◆ hasKSq()

template<int D>
bool Pscf::Prdc::Cuda::WaveList< D >::hasKSq ( ) const
inline

Has the kSq array been computed?

Definition at line 307 of file cuda/WaveList.h.

◆ hasdKSq()

template<int D>
bool Pscf::Prdc::Cuda::WaveList< D >::hasdKSq ( ) const
inline

Has the dKSq array been computed?

Definition at line 313 of file cuda/WaveList.h.

◆ isSorted()

template<int D>
bool Pscf::Prdc::Cuda::WaveList< D >::isSorted ( ) const
inline

Have the waves been sorted by magnitude ?

Definition at line 319 of file cuda/WaveList.h.

◆ isRealField()

template<int D>
bool Pscf::Prdc::Cuda::WaveList< D >::isRealField ( ) const
inline

Is this WaveList set up for use with real-valued fields?

Definition at line 325 of file cuda/WaveList.h.

Referenced by WaveList().


The documentation for this class was generated from the following files: