Skip to content

Commit

Permalink
change nkstot_ibz and kvec_d_ibz from member into local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
maki49 committed Jun 28, 2024
1 parent a339356 commit a563eeb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 56 deletions.
44 changes: 20 additions & 24 deletions source/module_cell/klist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ K_Vectors::K_Vectors()

nks = 0;
nkstot = 0;
nkstot_ibz = 0;

k_nkstot = 0; // LiuXh add 20180619
}

Expand Down Expand Up @@ -124,12 +122,6 @@ void K_Vectors::set(const ModuleSymmetry::Symmetry& symm,
3. Close symemtry: set `symmetry` to 0 in INPUT. \n \
4. Set `symmetry_autoclose` to 1 in INPUT to automatically close symmetry when this error occurs.");
}
if (ModuleSymmetry::Symmetry::symm_flag || is_mp)
{
// resize the kpoint container according to nkstot_ibz
this->update_use_ibz();
this->nks = this->nkstot = this->nkstot_ibz;
}
}

// (3)
Expand Down Expand Up @@ -531,23 +523,23 @@ void K_Vectors::Monkhorst_Pack(const int* nmp_in, const double* koffset_in, cons
return;
}

void K_Vectors::update_use_ibz(void)
void K_Vectors::update_use_ibz(const int& nkstot_ibz, const std::vector<ModuleBase::Vector3<double>>& kvec_d_ibz)
{
if (GlobalV::MY_RANK != 0)
return;
ModuleBase::TITLE("K_Vectors", "update_use_ibz");
assert(nkstot_ibz > 0);

assert(nkstot_ibz <= kvec_d_ibz.size());
// update nkstot
this->nkstot = this->nkstot_ibz;
this->nks = this->nkstot = nkstot_ibz;

ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "nkstot now", nkstot);

this->kvec_d.resize(this->nkstot * nspin); // qianrui fix a bug 2021-7-13 for nspin=2 in set_kup_and_kdw()

for (int i = 0; i < this->nkstot; ++i)
{
this->kvec_d[i] = this->kvec_d_ibz[i];
this->kvec_d[i] = kvec_d_ibz[i];

// update weight.
this->wk[i] = this->wk_ibz[i];
Expand Down Expand Up @@ -774,10 +766,10 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry& symm,

// use operation : kgmatrix to find
// the new set kvec_d : ir_kpt
this->nkstot_ibz = 0;
int nkstot_ibz = 0;

assert(nkstot > 0);
kvec_d_ibz.resize(this->nkstot);
std::vector<ModuleBase::Vector3<double>> kvec_d_ibz(this->nkstot);
wk_ibz.resize(this->nkstot);
ibz2bz.resize(this->nkstot);

Expand Down Expand Up @@ -848,10 +840,10 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry& symm,
// kvec_rot_k.z;
kvec_rot_k = kvec_rot_k * ucell.G * k_vec.Inverse(); // convert back to k-latice
}
for (int k = 0; k < this->nkstot_ibz; ++k)
for (int k = 0; k < nkstot_ibz; ++k)
{
if (symm.equal(kvec_rot.x, this->kvec_d_ibz[k].x) && symm.equal(kvec_rot.y, this->kvec_d_ibz[k].y)
&& symm.equal(kvec_rot.z, this->kvec_d_ibz[k].z))
if (symm.equal(kvec_rot.x, kvec_d_ibz[k].x) && symm.equal(kvec_rot.y, kvec_d_ibz[k].y)
&& symm.equal(kvec_rot.z, kvec_d_ibz[k].z))
{
already_exist = true;
// find another ibz k point,
Expand All @@ -869,7 +861,7 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry& symm,
{
// if it's a new ibz kpoint.
// nkstot_ibz indicate the index of ibz kpoint.
this->kvec_d_ibz[nkstot_ibz] = kvec_rot;
kvec_d_ibz[nkstot_ibz] = kvec_rot;
// output in kpoints file
ibz_index[i] = nkstot_ibz;

Expand Down Expand Up @@ -936,9 +928,9 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry& symm,
this->kvec_d[i].y,
this->kvec_d[i].z,
ibz_index[i] + 1,
this->kvec_d_ibz[ibz_index[i]].x,
this->kvec_d_ibz[ibz_index[i]].y,
this->kvec_d_ibz[ibz_index[i]].z);
kvec_d_ibz[ibz_index[i]].x,
kvec_d_ibz[ibz_index[i]].y,
kvec_d_ibz[ibz_index[i]].z);
}
ss << table << std::endl;
skpt = ss.str();
Expand All @@ -951,13 +943,17 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry& symm,
{
table += FmtCore::format("%8d%12.8f%12.8f%12.8f%8.4f%8d\n",
ik + 1,
this->kvec_d_ibz[ik].x,
this->kvec_d_ibz[ik].y,
this->kvec_d_ibz[ik].z,
kvec_d_ibz[ik].x,
kvec_d_ibz[ik].y,
kvec_d_ibz[ik].z,
this->wk_ibz[ik],
this->ibz2bz[ik]);
}
GlobalV::ofs_running << table << std::endl;

// resize the kpoint container according to nkstot_ibz
if (use_symm || is_mp) { this->update_use_ibz(nkstot_ibz, kvec_d_ibz); }

return;
}

Expand Down
19 changes: 4 additions & 15 deletions source/module_cell/klist.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class K_Vectors
public:
std::vector<ModuleBase::Vector3<double>> kvec_c; /// Cartesian coordinates of k points
std::vector<ModuleBase::Vector3<double>> kvec_d; /// Direct coordinates of k points
std::vector<ModuleBase::Vector3<double>> kvec_d_ibz; /// ibz Direct coordinates of k points

std::vector<double> wk; /// wk, weight of k points
std::vector<double> wk_ibz; /// ibz kpoint wk ,weight of k points
Expand Down Expand Up @@ -125,11 +124,6 @@ class K_Vectors
return this->nkstot;
}

int get_nkstot_ibz() const
{
return this->nkstot_ibz;
}

int get_nkstot_full() const
{
return this->nkstot_full;
Expand All @@ -143,19 +137,14 @@ class K_Vectors
this->nkstot = value;
}

void set_nkstot_ibz(int value) {
this->nkstot_ibz = value;
}

void set_nkstot_full(int value) {
this->nkstot_full = value;
}

private:
int nks; // number of k points in this pool(processor, up+dw)
int nkstot; /// total number of k points, equal to nkstot_ibz after reducing k points
int nkstot_ibz; /// number of k points in IBZ
int nkstot_full; /// number of k points in full k mesh
int nks; // number of symmetry-reduced k points in this pool(processor, up+dw)
int nkstot; /// number of symmetry-reduced k points in full k mesh
int nkstot_full; /// number of k points before symmetry reduction in full k mesh

int nspin;
bool kc_done;
Expand Down Expand Up @@ -282,7 +271,7 @@ class K_Vectors
* updated, and the flag kc_done is set to false to indicate that the Cartesian coordinates of the k-points need to
* be recalculated.
*/
void update_use_ibz(void);
void update_use_ibz(const int& nkstot_ibz, const std::vector<ModuleBase::Vector3<double>>& kvec_d_ibz);

/**
* @brief Sets both the direct and Cartesian k-vectors.
Expand Down
14 changes: 5 additions & 9 deletions source/module_cell/test/klist_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ class KlistTest : public testing::Test
TEST_F(KlistTest, Construct)
{
EXPECT_EQ(kv->get_nks(),0);
EXPECT_EQ(kv->get_nkstot(),0);
EXPECT_EQ(kv->get_nkstot_ibz(),0);
EXPECT_EQ(kv->get_nkstot(), 0);
EXPECT_EQ(kv->nspin,0);
EXPECT_EQ(kv->k_nkstot,0);
EXPECT_FALSE(kv->kc_done);
Expand Down Expand Up @@ -680,11 +679,8 @@ TEST_F(KlistTest, UpdateUseIBZ)
kv->nspin = 1;
kv->set_nkstot(3);
kv->set_nks(3);
kv->renew(kv->get_nkstot());
kv->set_nkstot_ibz(2);
kv->kvec_d_ibz.resize(kv->get_nkstot_ibz());
kv->wk_ibz.resize(kv->get_nkstot_ibz());
kv->update_use_ibz();
kv->renew(kv->get_nkstot());
kv->update_use_ibz(kv->get_nkstot(), std::vector<ModuleBase::Vector3<double>>(2, { 0,0,0 }));
EXPECT_EQ(kv->get_nkstot(),2);
EXPECT_EQ(kv->kvec_d.size(),2);
EXPECT_TRUE(kv->kd_done);
Expand All @@ -708,7 +704,7 @@ TEST_F(KlistTest, IbzKpoint)
ModuleSymmetry::Symmetry::symm_flag = 1;
bool match = true;
kv->ibz_kpoint(symm, ModuleSymmetry::Symmetry::symm_flag, skpt, ucell, match);
EXPECT_EQ(kv->get_nkstot_ibz(),35);
EXPECT_EQ(kv->get_nkstot(), 35);
GlobalV::ofs_running<<skpt<<std::endl;
GlobalV::ofs_running.close();
ClearUcell();
Expand All @@ -733,7 +729,7 @@ TEST_F(KlistTest, IbzKpointIsMP)
ModuleSymmetry::Symmetry::symm_flag = 0;
bool match = true;
kv->ibz_kpoint(symm, ModuleSymmetry::Symmetry::symm_flag, skpt, ucell, match);
EXPECT_EQ(kv->get_nkstot_ibz(),260);
EXPECT_EQ(kv->get_nks(), 260);
GlobalV::ofs_running<<skpt<<std::endl;
GlobalV::ofs_running.close();
ClearUcell();
Expand Down
3 changes: 1 addition & 2 deletions source/module_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,7 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
#ifdef __RAPIDJSON
// add nkstot,nkstot_ibz to output json
int Jnkstot = this->pelec->klist->get_nkstot();
int Jnkstot_ibz = this->pelec->klist->get_nkstot_ibz();
Json::add_nkstot(Jnkstot, Jnkstot_ibz);
Json::add_nkstot(Jnkstot);
#endif //__RAPIDJSON
return;
};
Expand Down
5 changes: 2 additions & 3 deletions source/module_io/json_output/init_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ void gen_init(UnitCell *ucell){
}


void add_nkstot(int nkstot,int nkstot_ibz){
Json::AbacusJson::add_json({"init", "nkstot"}, nkstot,false);
Json::AbacusJson::add_json({"init", "nkstot_ibz"}, nkstot_ibz,false);
void add_nkstot(int nkstot) {
Json::AbacusJson::add_json({ "init", "nkstot" }, nkstot, false);

// Json::AbacusJson::add_Json(nkstot,false,"init", "nkstot");
// Json::AbacusJson::add_Json(nkstot_ibz,false,"init", "nkstot_ibz");
Expand Down
5 changes: 2 additions & 3 deletions source/module_io/json_output/test/para_json_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,14 @@ TEST(AbacusJsonTest, InitInfo)
}
// init the doc allocator
Json::AbacusJson::doc.Parse("{}");
int Jnkstot=1,Jnkstot_ibz = 2;
int Jnkstot = 1;

Json::add_nkstot(Jnkstot,Jnkstot_ibz);
Json::add_nkstot(Jnkstot);
Json::gen_init(&ucell);


ASSERT_TRUE(Json::AbacusJson::doc.HasMember("init"));
ASSERT_EQ(Json::AbacusJson::doc["init"]["nkstot"].GetInt(), 1);
ASSERT_EQ(Json::AbacusJson::doc["init"]["nkstot_ibz"].GetInt(), 2);

ASSERT_EQ(Json::AbacusJson::doc["init"]["natom"].GetInt(), 6);
ASSERT_EQ(Json::AbacusJson::doc["init"]["nband"].GetInt(), 10);
Expand Down

0 comments on commit a563eeb

Please sign in to comment.