ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
klist.h
Go to the documentation of this file.
1#ifndef K_VECTORS_H
2#define K_VECTORS_H
3
7#include "parallel_kpoints.h"
8#include "reciprocal_grid.h"
9#include <vector>
10
20{
21public:
22 std::vector<int> isk;
23
26 std::vector<std::map<int, ModuleBase::Vector3<double>>> kstars;
27
30 K_Vectors& operator=(const K_Vectors&) = default;
31 K_Vectors& operator=(K_Vectors&& rhs) = default;
32
34
35
56 void set(const UnitCell& ucell,
57 const ModuleSymmetry::Symmetry& symm,
58 const std::string& k_file_name,
59 const int& nspin,
60 const ModuleBase::Matrix3& reciprocal_vec,
61 const ModuleBase::Matrix3& latvec,
62 std::ofstream& ofs,
63 std::ofstream& ofs_warning,
64 const bool use_ibz,
65 const std::string& global_out_dir,
66 const bool gamma_only_local,
67 const double kspacing[3],
68 const std::string& kmesh_type,
69 const double koffset[3]);
70
71 int get_nks() const
72 {
73 return this->nks;
74 }
75
76 int get_nkstot() const
77 {
78 return this->nkstot;
79 }
80
82 {
83 return this->nkstot_nospin;
84 }
85
86 double get_koffset(const int i) const
87 {
88 return this->koffset[i];
89 }
90
91 int get_k_nkstot() const
92 {
93 return this->k_nkstot;
94 }
95
98 int get_spin_mult() const
99 {
100 return this->spin_mult;
101 }
102
103 std::string get_k_kword() const
104 {
105 return this->k_kword;
106 }
107
108 void set_nks(int value)
109 {
110 this->nks = value;
111 }
112
113 void set_nkstot(int value)
114 {
115 this->nkstot = value;
116 }
117
118 void set_nkstot_nospin(int value)
119 {
120 this->nkstot_nospin = value;
121 }
122
125 void set_spin_mult(int value)
126 {
127 this->spin_mult = value;
128 }
129
130 bool get_is_mp() const
131 {
132 return is_mp;
133 }
134
135 bool is_uniform_mp() const;
136
137 std::vector<int> ik2iktot;
138 std::vector<int> ibz_index;
139
157 void update_use_ibz(const int& nkstot_ibz,
158 const std::vector<ModuleBase::Vector3<double>>& kvec_d_ibz,
159 const std::vector<double>& wk_ibz,
160 std::ofstream& ofs_running,
161 const int my_rank);
162
179 void set_after_vc(const ModuleBase::Matrix3& G,
180 const ModuleSymmetry::Symmetry& symm,
181 const bool update_symmetry,
182 std::ofstream& ofs_running);
183
184 //====================================================================
185 // Test seam.
186 //
187 // set() is the single production entry point: it drives read_kpoints(),
188 // reduce_by_symmetry(), set_kup_and_kdw() and renew() in order. The unit
189 // tests exercise those stages one at a time -- most of the KPT-file parsing
190 // paths are only reachable that way -- so each one is called through the
191 // wrappers here rather than by reinterpreting the access specifiers.
192 //
193 // Production code must keep going through set(); nothing outside the tests
194 // should call the *_for_testing() wrappers.
195 //====================================================================
196
198 const std::string& fn,
199 const bool gamma_only_local,
200 const double kspacing[3],
201 const std::string& kmesh_type,
202 const double koffset_in[3],
203 std::ofstream& ofs_running,
204 std::ofstream& ofs_warning,
205 const int my_rank)
206 {
207 return read_kpoints(ucell,
208 fn,
209 gamma_only_local,
210 kspacing,
211 kmesh_type,
212 koffset_in,
213 ofs_running,
214 ofs_warning,
215 my_rank);
216 }
217
218 void renew_for_testing(const int& kpoint_number)
219 {
220 renew(kpoint_number);
221 }
222
224 const ModuleSymmetry::Symmetry& symm,
225 bool use_symm,
226 std::string& skpt,
227 bool& match,
228 const int my_rank,
229 std::ofstream& ofs_running)
230 {
231 reduce_by_symmetry(ucell, symm, use_symm, skpt, match, my_rank, ofs_running);
232 }
233
234 void set_kup_and_kdw_for_testing(std::ofstream& ofs_running)
235 {
236 set_kup_and_kdw(ofs_running);
237 }
238
239 private:
243 int spin_mult = 0;
244 double koffset[3] = {0.0};
245
256 void renew(const int& kpoint_number) override;
257
259 int spin_factor() const override
260 {
261 return this->spin_mult;
262 }
263
279 void reduce_by_symmetry(const UnitCell& ucell,
280 const ModuleSymmetry::Symmetry& symm,
281 bool use_symm,
282 std::string& skpt,
283 bool& match,
284 const int my_rank,
285 std::ofstream& ofs_running) override;
286
288
308 bool read_kpoints(const UnitCell& ucell,
309 const std::string& fn,
310 const bool gamma_only_local,
311 const double kspacing[3],
312 const std::string& kmesh_type,
313 const double koffset[3],
314 std::ofstream& ofs_running,
315 std::ofstream& ofs_warning,
316 const int my_rank); // return 0: something wrong.
317
330 bool parse_kfile(const std::string& fn, std::ofstream& ofs_running, std::ofstream& ofs_warning);
331
345 bool read_mp_mesh(std::ifstream& ifk,
346 const std::string& kword,
347 std::ofstream& ofs_running,
348 std::ofstream& ofs_warning);
349
363 bool read_listed_kpoints(std::ifstream& ifk, const std::string& kword, std::ofstream& ofs_warning);
364
377 bool setup_line_kpoints(std::ifstream& ifk,
378 std::vector<ModuleBase::Vector3<double>>& kvec,
379 const bool cartesian,
380 std::ofstream& ofs_warning);
381
395 void handle_symmetry_mismatch(const UnitCell& ucell,
396 const ModuleSymmetry::Symmetry& symm,
397 std::string& skpt,
398 bool& match,
399 const int my_rank,
400 std::ofstream& ofs);
401
423 void interpolate_k_between(std::ifstream& ifk, std::vector<ModuleBase::Vector3<double>>& kvec);
424
426
446 void set_kup_and_kdw(std::ofstream& ofs_running);
447
448#ifdef __MPI
459 void mpi_k(std::ofstream& ofs_running, const int my_rank, const int my_pool);
460#endif
461};
462#endif // KVECT_H
void interpolate_k_between(std::ifstream &ifk, std::vector< ModuleBase::Vector3< double > > &kvec)
Adds k-points linearly between special points.
Definition klist.cpp:423
void mpi_k(std::ofstream &ofs_running, const int my_rank, const int my_pool)
Distributes k-points among MPI processes.
Definition klist.cpp:681
double koffset[3]
used only in automatic k-points
Definition klist.h:244
void reduce_by_symmetry(const UnitCell &ucell, const ModuleSymmetry::Symmetry &symm, bool use_symm, std::string &skpt, bool &match, const int my_rank, std::ofstream &ofs_running) override
Reduce the k-points to the irreducible Brillouin zone (IBZ).
Definition klist.cpp:510
void renew_for_testing(const int &kpoint_number)
Definition klist.h:218
int get_nks() const
Definition klist.h:71
void set_nks(int value)
Definition klist.h:108
K_Vectors()
Definition klist.h:28
void set_spin_mult(int value)
Set the spin multiplicity: 1 (no doubling, also for non-collinear nspin=4) or 2 (LSDA,...
Definition klist.h:125
double get_koffset(const int i) const
Definition klist.h:86
void update_use_ibz(const int &nkstot_ibz, const std::vector< ModuleBase::Vector3< double > > &kvec_d_ibz, const std::vector< double > &wk_ibz, std::ofstream &ofs_running, const int my_rank)
Updates the k-points to use the irreducible Brillouin zone (IBZ).
Definition klist.cpp:439
bool read_kpoints_for_testing(const UnitCell &ucell, const std::string &fn, const bool gamma_only_local, const double kspacing[3], const std::string &kmesh_type, const double koffset_in[3], std::ofstream &ofs_running, std::ofstream &ofs_warning, const int my_rank)
Definition klist.h:197
~K_Vectors()
Definition klist.h:29
bool read_kpoints(const UnitCell &ucell, const std::string &fn, const bool gamma_only_local, const double kspacing[3], const std::string &kmesh_type, const double koffset[3], std::ofstream &ofs_running, std::ofstream &ofs_warning, const int my_rank)
step 1 : generate kpoints
Definition klist.cpp:229
bool read_listed_kpoints(std::ifstream &ifk, const std::string &kword, std::ofstream &ofs_warning)
Read the explicitly listed k points (nkstot > 0 form of KPT).
Definition klist.cpp:366
K_Vectors & operator=(K_Vectors &&rhs)=default
std::vector< int > ik2iktot
[nks] map ik to the global index of k points
Definition klist.h:137
void set_kup_and_kdw_for_testing(std::ofstream &ofs_running)
Definition klist.h:234
K_Vectors & operator=(const K_Vectors &)=default
int get_spin_mult() const
Spin multiplicity of the k-point list: 1 (no doubling, also for non-collinear nspin=4) or 2 (LSDA,...
Definition klist.h:98
void set(const UnitCell &ucell, const ModuleSymmetry::Symmetry &symm, const std::string &k_file_name, const int &nspin, const ModuleBase::Matrix3 &reciprocal_vec, const ModuleBase::Matrix3 &latvec, std::ofstream &ofs, std::ofstream &ofs_warning, const bool use_ibz, const std::string &global_out_dir, const bool gamma_only_local, const double kspacing[3], const std::string &kmesh_type, const double koffset[3])
Set up the k-points for the system.
Definition klist.cpp:13
std::vector< int > isk
distinguish spin up and down k points
Definition klist.h:22
bool setup_line_kpoints(std::ifstream &ifk, std::vector< ModuleBase::Vector3< double > > &kvec, const bool cartesian, std::ofstream &ofs_warning)
Build line-mode k points by interpolating between special points.
Definition klist.cpp:395
int spin_factor() const override
Spin multiplicity used when generating the mesh (1/2).
Definition klist.h:259
int get_k_nkstot() const
Definition klist.h:91
void set_nkstot(int value)
Definition klist.h:113
void set_nkstot_nospin(int value)
Definition klist.h:118
int get_nkstot_nospin() const
Definition klist.h:81
int spin_mult
Definition klist.h:243
void set_kup_and_kdw(std::ofstream &ofs_running)
step 4 : *2 kpoints
Definition klist.cpp:477
Parallel_Kpoints para_k
parallel for kpoints
Definition klist.h:33
bool is_uniform_mp() const
Definition klist.cpp:209
std::string get_k_kword() const
Definition klist.h:103
std::vector< std::map< int, ModuleBase::Vector3< double > > > kstars
equal k points to each ibz-kpont, corresponding to a certain symmetry operations. dim: [iks_ibz][(isy...
Definition klist.h:26
bool read_mp_mesh(std::ifstream &ifk, const std::string &kword, std::ofstream &ofs_running, std::ofstream &ofs_warning)
Read the Monkhorst-Pack/Gamma mesh block and generate the mesh.
Definition klist.cpp:317
bool parse_kfile(const std::string &fn, std::ofstream &ofs_running, std::ofstream &ofs_warning)
Read the KPT file and build the k-point list from it.
Definition klist.cpp:254
int get_nkstot() const
Definition klist.h:76
void set_after_vc(const ModuleBase::Matrix3 &G, const ModuleSymmetry::Symmetry &symm, const bool update_symmetry, std::ofstream &ofs_running)
Updates the k-points after a volume change.
Definition klist.cpp:599
void handle_symmetry_mismatch(const UnitCell &ucell, const ModuleSymmetry::Symmetry &symm, std::string &skpt, bool &match, const int my_rank, std::ofstream &ofs)
Handle a reciprocal/real lattice Bravais-type mismatch after IBZ reduction.
Definition klist.cpp:168
std::vector< int > ibz_index
map k points (before symmetry reduction) to irreducible k-points
Definition klist.h:138
void renew(const int &kpoint_number) override
Resize the k-point related vectors according to the new k-point number.
Definition klist.cpp:201
bool get_is_mp() const
Definition klist.h:130
void reduce_by_symmetry_for_testing(const UnitCell &ucell, const ModuleSymmetry::Symmetry &symm, bool use_symm, std::string &skpt, bool &match, const int my_rank, std::ofstream &ofs_running)
Definition klist.h:223
3x3 matrix and related mathamatical operations
Definition matrix3.h:15
3 elements vector
Definition vector3.h:21
Abstract base class shared by K_Vectors (electrons) and QList (phonons).
Definition reciprocal_grid.h:52
std::string k_kword
Type keyword of the point-list file.
Definition reciprocal_grid.h:178
int nks
Number of points in the current pool (spin-free view).
Definition reciprocal_grid.h:75
int nkstot
Definition reciprocal_grid.h:78
int nkstot_nospin
Definition reciprocal_grid.h:82
int k_nkstot
Total number of points read from a point-list file (0 = auto mesh).
Definition reciprocal_grid.h:176
bool is_mp
Whether this is a Monkhorst-Pack grid.
Definition reciprocal_grid.h:174
Symmetry analysis class.
Definition symmetry.h:24
Parallel_Kpoints class for k-point parallelization.
Definition parallel_kpoints.h:17
Provide the basic information about unitcell.
Definition unitcell.h:16
Parallel_Kpoints class for k-point parallelization.
Abstract base class for reciprocal-space point grids.