1#ifndef PRDC_CPU_WAVE_LIST_TPP
2#define PRDC_CPU_WAVE_LIST_TPP
13#include <prdc/cpu/FFT.h>
14#include <prdc/crystal/UnitCell.h>
15#include <prdc/crystal/shiftToMinimum.h>
16#include <prdc/crystal/hasVariableAngle.h>
18#include <pscf/mesh/MeshIterator.h>
19#include <pscf/mesh/Mesh.h>
20#include <pscf/math/Sort.h>
39 unitCellPtr_(nullptr),
65 int nParams = unitCell().nParameter();
66 IntVec<D> const & meshDimensions = mesh().dimensions();
72 kMeshDimensions_ = meshDimensions;
73 kSize_ = mesh().size();
77 minImages_.allocate(kSize_);
78 kSq_.allocate(kMeshDimensions_);
79 dKSq_.allocate(nParams);
80 for (
int i = 0; i < nParams; i++) {
81 dKSq_[i].allocate(kMeshDimensions_);
87 implicitInverse_.allocate(kSize_);
94 implicitInverse_[rank] =
111 if (unitCell().nParameter() > 1) {
113 sortedBunches_.clear();
117 hasMinImages_ =
false;
127 if (hasMinImages_)
return;
139 minImages_[rank] = shiftToMinimum(kItr.
position(),
140 mesh().dimensions(), unitCell());
141 kSq_[rank] = unitCell().ksq(minImages_[rank]);
144 hasMinImages_ =
true;
158 if (!hasMinImages_) {
174 kSq_[rank] = unitCell().ksq(minImages_[rank]);
186 if (hasdKSq_)
return;
189 if (!hasMinImages_) {
201 for (i = 0 ; i < unitCell().nParameter(); ++i) {
205 dksq[rank] = unitCell().dksq(minImages_[rank], i);
207 if (implicitInverse_[rank]) {
223 if (isSorted_)
return;
232 std::vector< Sort::Item<double> > items;
234 for (
int i = 0; i < kSize_; ++i) {
235 item.value = kSq_[i];
237 items.push_back(item);
243 if (!sortedIds_.isAllocated()) {
244 sortedIds_.allocate(kSize_);
247 for (
int i = 0; i < kSize_; ++i) {
248 sortedIds_[i] = items[i].id;
252 double epsilon = 1.0E-8;
253 sortedBunches_.clear();
255 nBunch_ = sortedBunches_.size();
259 if (!bunchIds_.isAllocated()) {
260 bunchIds_.allocate(kSize_);
263 int begin, end, ib, iw;
264 for (ib = 0; ib < nBunch_; ++ib) {
265 begin = sortedBunches_[ib][0];
266 end = sortedBunches_[ib][1];
268 for (iw = begin; iw < end; ++iw) {
269 bunchIds_[sortedIds_[iw]] = ib;
An IntVec<D, T> is a D-component vector of elements of integer type T.
Iterator over points in a Mesh<D>.
int rank() const
Get the rank of current element.
void begin()
Set iterator to the first point in the mesh.
bool atEnd() const
Is this the end (i.e., one past the last point)?
IntVec< D > position() const
Get current position in the grid, as integer vector.
Description of a regular grid of points in a periodic domain.
int size() const
Get total number of grid points.
static bool hasImplicitInverse(IntVec< D > const &wavevector, IntVec< D > const &meshDimensions)
Does this wavevector have implicit inverse in DFT or real data?
static void computeKMesh(IntVec< D > const &rMeshDimensions, IntVec< D > &kMeshDimensions, int &kSize)
Compute dimensions and size of k-space mesh for DFT of real data.
Field of real double precision values on an FFT mesh.
void computeKSq()
Compute square norm |k|^2 for all wavevectors.
void sortWaves()
Sort waves in order of ascending wavevector norm.
void computeMinimumImages()
Compute minimum images of wavevectors, and also calculates kSq.
bool isRealField() const
Is this WaveList set up for use with real-valued fields?
void allocate(Mesh< D > const &m, UnitCell< D > const &c)
Allocate memory and set association with a Mesh and UnitCell object.
void computedKSq()
Compute derivatives of |k|^2 w/ respect to unit cell parameters.
void clearUnitCellData()
Clear all internal data that depends on lattice parameters.
WaveList(bool isRealField=true)
Constructor.
int nParameter() const
Get the number of parameters in the unit cell.
Base template for UnitCell<D> classes, D=1, 2 or 3.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
void findBunches(std::vector< Item< T > > const &items, GArray< Bunch > &bunches, T epsilon)
Identify "bunches" of equal values within a sorted vector.
void sort(std::vector< Item< T > > &items)
Sort a std::vector< Item<T> > by ascending item value.
Fields and FFTs for periodic boundary conditions (CPU)
Periodic fields and crystallography.
bool hasVariableAngle(typename UnitCell< D >::LatticeSystem lattice)
Return true if lattice type has variable angle parameters.
PSCF package top-level namespace.
Struct with value and index, to keep track of permutation.