20 #ifndef JDFTX_CORE_LATTICEUTILS_H 21 #define JDFTX_CORE_LATTICEUTILS_H 29 static const double symmThreshold = 1e-4;
30 static const double symmThresholdSq = symmThreshold * symmThreshold;
44 std::vector<matrix3<int>> getSymmetries(
const matrix3<>& R,
64 std::vector<KmeshTransform> kmeshTransform;
69 const std::vector<
vector3<>>& kmeshReduced,
70 const std::vector<
matrix3<int>>& sym,
const std::vector<int>& invertList);
76 std::map<vector3<int>,
double> getCellMap(
const matrix3<>& R,
const matrix3<>& Rsup,
string fname=
string());
84 {
const std::vector<T>& points;
86 std::vector< std::vector<size_t> > indices;
89 {
for(
int k=0; k<3; k++)
90 {
if(iv[k] < 0) iv[k] += S[k];
91 if(iv[k] >= S[k]) iv[k] -= S[k];
93 return iv[0]+S[0]*size_t(iv[1]+S[1]*iv[2]);
101 vector3<> Stmp;
for(
int k=0; k<3; k++) Stmp[k] =
sqrt(metric(k,k));
102 Stmp *=
pow(std::max(points.size(), nPointsTarget)/(Stmp[0]*Stmp[1]*Stmp[2]), 1./3);
103 for(
int k=0; k<3; k++)
104 { S[k] = std::max(1,
int(
round(Stmp[k])));
105 assert(symmThreshold*S[k] < 0.5);
108 indices.resize(S[0]*S[1]*S[2]);
109 for(
size_t iPoint=0; iPoint<points.size(); iPoint++)
110 addPoint(iPoint, points[iPoint]);
118 for(
int k=0; k<3; k++)
119 { v[k] -= floor(v[k]);
120 iv[k] = int(floor(v[k]*S[k] + 0.5));
122 indices[meshIndex(iv)].push_back(iPoint);
127 template<
typename Tag =
double,
typename TagEquality = std::equal_to<Tag> >
128 size_t find(
vector3<> v, Tag tag = Tag(),
const std::vector<Tag>* tagArr=0, TagEquality tagEquality = std::equal_to<Tag>())
const 130 for(
int k=0; k<3; k++)
131 { v[k] -= floor(v[k]);
132 ivMin[k] = int(floor((v[k]-symmThreshold)*S[k] + 0.5));
133 ivMax[k] = int(floor((v[k]+symmThreshold)*S[k] + 0.5));
136 for(iv[0]=ivMin[0]; iv[0]<=ivMax[0]; iv[0]++)
137 for(iv[1]=ivMin[1]; iv[1]<=ivMax[1]; iv[1]++)
138 for(iv[2]=ivMin[2]; iv[2]<=ivMax[2]; iv[2]++)
139 for(
size_t index: indices[meshIndex(iv)])
141 && (!tagArr || tagEquality(tag, tagArr->at(index))) )
147 #endif // JDFTX_CORE_LATTICEUTILS_H ScalarField pow(const ScalarField &, double alpha)
Elementwise power (preserve input)
ScalarField sqrt(const ScalarField &)
Elementwise square root (preserve input)
Simulation grid descriptor.
Definition: GridInfo.h:45
PeriodicLookup(const std::vector< T > &points, matrix3<> metric, size_t nPointsTarget=0)
Definition: LatticeUtils.h:99
const GridInfo & gInfo
unit cell and corresponding grids
Definition: LatticeUtils.h:51
matrix3< int > super
linear combinations to get Rsuper (Rsuper = R * super)
Definition: LatticeUtils.h:54
std::vector< vector3<> > kmesh
closure of kmeshReduced under symmetry group sym
Definition: LatticeUtils.h:52
void addPoint(size_t iPoint, const T &point)
Definition: LatticeUtils.h:115
matrix3 Rsuper
super-cell lattice vectors
Definition: LatticeUtils.h:53
Geometry of the simulation grid.
__hostanddev__ vector3< int > round(const vector3<> &v, double *err=0)
Round vector3<> to vector3<int> (and optionally retrieve error)
Definition: vector3.h:128
__hostanddev__ double circDistanceSquared(const vector3<> &a, const vector3<> &b)
Definition: vector3.h:138
size_t find(vector3<> v, Tag tag=Tag(), const std::vector< Tag > *tagArr=0, TagEquality tagEquality=std::equal_to< Tag >()) const
Definition: LatticeUtils.h:128
Supercell corresponding to a given k-point mesh.
Definition: LatticeUtils.h:49
Supercell(const GridInfo &gInfo, const std::vector< vector3<>> &kmeshReduced, const std::vector< matrix3< int >> &sym, const std::vector< int > &invertList)
Definition: LatticeUtils.h:83
#define assert(expr)
A custom assertion with stack trace (NOTE: enabled in release modes as well)
Definition: Util.h:100