Skip to content

Commit 38eb1db

Browse files
mohanchenabacus_fixer
andauthored
resolve the wrong dependency between klist and berryphase (#7622)
Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
1 parent a76c946 commit 38eb1db

9 files changed

Lines changed: 20 additions & 19 deletions

File tree

source/source_cell/klist.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "source_base/parallel_global.h"
77
#include "source_base/parallel_reduce.h"
88
#include "source_cell/module_symmetry/symmetry.h"
9-
#include "source_io/module_unk/berryphase.h"
109
#include "source_io/module_parameter/parameter.h"
1110

1211
void K_Vectors::cal_ik_global()
@@ -44,7 +43,8 @@ void K_Vectors::set(const UnitCell& ucell,
4443
const int& nspin_in,
4544
const ModuleBase::Matrix3& reciprocal_vec,
4645
const ModuleBase::Matrix3& latvec,
47-
std::ofstream& ofs)
46+
std::ofstream& ofs,
47+
const bool use_ibz)
4848
{
4949
ModuleBase::TITLE("K_Vectors", "set");
5050

@@ -99,9 +99,8 @@ void K_Vectors::set(const UnitCell& ucell,
9999

100100

101101
// (2)
102-
// only berry phase need all kpoints including time-reversal symmetry!
103-
// if symm_flag is not set, only time-reversal symmetry would be considered.
104-
if (!berryphase::berry_phase_flag && ModuleSymmetry::Symmetry::symm_flag != -1)
102+
// reduce kpoints to IBZ according to symmetry operations
103+
if (use_ibz)
105104
{
106105
bool match = true;
107106
// calculate kpoints in IBZ and reduce kpoints according to symmetry

source/source_cell/klist.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class K_Vectors
4949
* @param nspin_in The number of spins.
5050
* @param reciprocal_vec The reciprocal vector of the system.
5151
* @param latvec The lattice vector of the system.
52+
* @param use_ibz Whether to reduce k-points to the irreducible Brillouin zone.
5253
*
5354
* @return void
5455
*
@@ -63,7 +64,8 @@ class K_Vectors
6364
const int& nspin,
6465
const ModuleBase::Matrix3& reciprocal_vec,
6566
const ModuleBase::Matrix3& latvec,
66-
std::ofstream& ofs);
67+
std::ofstream& ofs,
68+
const bool use_ibz);
6769

6870
int get_nks() const
6971
{

source/source_cell/test/klist_test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
#include "source_pw/module_pwdft/vl_pw.h"
1616
#include "source_pw/module_pwdft/vnl_pw.h"
1717
#include "source_pw/module_pwdft/parallel_grid.h"
18-
#include "source_io/module_unk/berryphase.h"
1918
#include "source_io/module_parameter/parameter.h"
2019
#undef private
2120
#include "source_base/mathzone.h"
2221
#include "source_base/parallel_global.h"
2322
#include "source_cell/parallel_kpoints.h"
24-
bool berryphase::berry_phase_flag = false;
2523

2624
pseudo::pseudo()
2725
{

source/source_cell/test/klist_test_para.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
#include "source_pw/module_pwdft/vl_pw.h"
2424
#include "source_pw/module_pwdft/vnl_pw.h"
2525
#include "source_pw/module_pwdft/parallel_grid.h"
26-
#include "source_io/module_unk/berryphase.h"
2726
#undef private
28-
bool berryphase::berry_phase_flag = false;
2927

3028
pseudo::pseudo()
3129
{
@@ -236,7 +234,8 @@ TEST_F(KlistParaTest, Set)
236234
GlobalV::RANK_IN_POOL,
237235
GlobalV::MY_POOL);
238236
ModuleSymmetry::Symmetry::symm_flag = 1;
239-
kv->set(ucell,symm, k_file, kv->nspin, ucell.G, ucell.latvec, GlobalV::ofs_running);
237+
const bool use_ibz = true;
238+
kv->set(ucell, symm, k_file, kv->nspin, ucell.G, ucell.latvec, GlobalV::ofs_running, use_ibz);
240239
EXPECT_EQ(kv->get_nkstot(), 35);
241240
EXPECT_EQ(kv->get_nkstot_full(), 512);
242241
EXPECT_GT(kv->get_nkstot_full(), kv->get_nkstot());
@@ -353,7 +352,8 @@ TEST_F(KlistParaTest, SetAfterVC)
353352
GlobalV::RANK_IN_POOL,
354353
GlobalV::MY_POOL);
355354
ModuleSymmetry::Symmetry::symm_flag = 1;
356-
kv->set(ucell,symm, k_file, kv->nspin, ucell.G, ucell.latvec, GlobalV::ofs_running);
355+
const bool use_ibz = true;
356+
kv->set(ucell, symm, k_file, kv->nspin, ucell.G, ucell.latvec, GlobalV::ofs_running, use_ibz);
357357
EXPECT_EQ(kv->get_nkstot(), 35);
358358
EXPECT_TRUE(kv->kc_done);
359359
EXPECT_TRUE(kv->kd_done);

source/source_esolver/esolver_fp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ void ESolver_FP::before_all_runners(UnitCell& ucell, const Input_para& inp)
6565
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SETUP UNITCELL");
6666

6767
//! 7) setup k points in the Brillouin zone according to symmetry.
68-
this->kv.set(ucell,ucell.symm, inp.kpoint_file, inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running);
68+
const bool use_ibz = !inp.berry_phase && ModuleSymmetry::Symmetry::symm_flag != -1;
69+
this->kv.set(ucell, ucell.symm, inp.kpoint_file, inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running, use_ibz);
6970
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS");
7071

7172
//! 8) print information

source/source_esolver/esolver_gets.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ void ESolver_GetS::before_all_runners(UnitCell& ucell, const Input_para& inp)
4040
}
4141

4242
// 1.3) Setup k-points according to symmetry.
43-
this->kv.set(ucell, ucell.symm, inp.kpoint_file, inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running);
43+
const bool use_ibz = !inp.berry_phase && ModuleSymmetry::Symmetry::symm_flag != -1;
44+
this->kv.set(ucell, ucell.symm, inp.kpoint_file, inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running, use_ibz);
4445
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS");
4546

4647
ModuleIO::print_parameters(ucell, this->kv, inp);

source/source_io/test/for_testing_klist.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
#include "source_pw/module_pwdft/vl_pw.h"
1515
#include "source_pw/module_pwdft/vnl_pw.h"
1616
#include "source_pw/module_pwdft/parallel_grid.h"
17-
#include "source_io/module_unk/berryphase.h"
18-
19-
bool berryphase::berry_phase_flag=0;
2017

2118
pseudo::pseudo(){}
2219
pseudo::~pseudo(){}

source/source_lcao/module_deepks/test/deepks_test_prep.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,15 @@ template <typename T>
258258
void test_deepks<T>::setup_kpt()
259259
{
260260
ModuleSymmetry::Symmetry::symm_flag = -1;
261+
const bool use_ibz = false;
261262
this->kv.set(ucell,
262263
ucell.symm,
263264
PARAM.inp.kpoint_file,
264265
this->nspin,
265266
ucell.G,
266267
ucell.latvec,
267-
GlobalV::ofs_running);
268+
GlobalV::ofs_running,
269+
use_ibz);
268270
}
269271

270272
template class test_deepks<double>;

source/source_lcao/module_lr/esolver_lrtd_lcao.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ LR::ESolver_LR<T, TR>::ESolver_LR(const Input_para& inp, UnitCell& ucell) : inpu
303303
ucell.symm.analy_sys(ucell.lat, ucell.st, ucell.atoms, GlobalV::ofs_running);
304304
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SYMMETRY");
305305
}
306-
this->kv.set(ucell,ucell.symm, PARAM.inp.kpoint_file, PARAM.inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running);
306+
const bool use_ibz = false;
307+
this->kv.set(ucell, ucell.symm, PARAM.inp.kpoint_file, PARAM.inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running, use_ibz);
307308
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS");
308309
ModuleIO::print_parameters(ucell, this->kv, inp);
309310

0 commit comments

Comments
 (0)