1#ifndef PSCF_WAVE_LIST_CP_TPP
2#define PSCF_WAVE_LIST_CP_TPP
13#include <pscf/field/cpp/FFT.h>
14#include <pscf/crystal/UnitCell.h>
15#include <pscf/crystal/shiftToMinimum.h>
16#include <pscf/crystal/hasVariableAngle.h>
18#include <pscf/mesh/MeshIterator.h>
19#include <pscf/mesh/Mesh.h>
20#include <pscf/math/Sort.h>
37 unitCellPtr_(nullptr),
63 int nParams = unitCell().nParameter();
64 IntVec<D> const & meshDimensions = mesh().dimensions();
70 kMeshDimensions_ = meshDimensions;
71 kSize_ = mesh().size();
75 minImages_.allocate(kSize_);
76 kSq_.allocate(kMeshDimensions_);
77 dKSq_.allocate(nParams);
78 for (
int i = 0; i < nParams; i++) {
79 dKSq_[i].allocate(kMeshDimensions_);
85 implicitInverse_.allocate(kSize_);
92 implicitInverse_[rank] =
109 if (unitCell().nParameter() > 1) {
111 sortedBunches_.clear();
115 hasMinImages_ =
false;
125 if (hasMinImages_)
return;
137 minImages_[rank] = shiftToMinimum(kItr.
position(),
138 mesh().dimensions(), unitCell());
139 kSq_[rank] = unitCell().ksq(minImages_[rank]);
142 hasMinImages_ =
true;
156 if (!hasMinImages_) {
172 kSq_[rank] = unitCell().ksq(minImages_[rank]);
184 if (hasdKSq_)
return;
187 if (!hasMinImages_) {
199 for (i = 0 ; i < unitCell().nParameter(); ++i) {
203 dksq[rank] = unitCell().dksq(minImages_[rank], i);
205 if (implicitInverse_[rank]) {
221 if (isSorted_)
return;
230 std::vector< Sort::Item<double> > items;
232 for (
int i = 0; i < kSize_; ++i) {
233 item.value = kSq_[i];
235 items.push_back(item);
241 if (!sortedIds_.isAllocated()) {
242 sortedIds_.allocate(kSize_);
245 for (
int i = 0; i < kSize_; ++i) {
246 sortedIds_[i] = items[i].id;
250 double epsilon = 1.0E-8;
251 sortedBunches_.clear();
253 nBunch_ = sortedBunches_.size();
257 if (!bunchIds_.isAllocated()) {
258 bunchIds_.allocate(kSize_);
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.
int nParameter() const
Get the number of parameters in the unit cell.
Base template for UnitCell<D> classes, D=1, 2 or 3.
void clearUnitCellData()
Clear all internal data that depends on lattice parameters.
bool isRealField() const
Is this WaveList set up for use with real-valued fields?
void computeMinimumImages()
Compute minimum images of wavevectors, and also calculates kSq.
WaveList(bool isRealField=true)
Constructor.
void computeKSq()
Compute square norm |k|^2 for all wavevectors.
#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.
PSCF package top-level namespace.
bool hasVariableAngle(typename UnitCell< D >::LatticeSystem lattice)
Return true if lattice type has variable angle parameters.
Struct with value and index, to keep track of permutation.