Skip to content

Commit 94525b5

Browse files
wenfei-liwenfei-liWHUweiqingzhou
authored
Feature : printing band density (#3501)
Co-authored-by: wenfei-li <liwenfei@gmail.com> Co-authored-by: wqzhou <33364058+WHUweiqingzhou@users.noreply.github.com>
1 parent 2189ba1 commit 94525b5

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,58 @@ void ESolver_KS_PW<T, Device>::afterscf(const int istep)
894894
this->kspw_psi[0].get_pointer() - this->kspw_psi[0].get_psi_bias(),
895895
this->psi[0].size());
896896
}
897+
898+
if(INPUT.band_print_num > 0)
899+
{
900+
std::complex<double> * wfcr = new std::complex<double>[this->pw_rho->nxyz];
901+
double * rho_band = new double [this->pw_rho->nxyz];
902+
for(int i = 0; i < this->pw_rho->nxyz; i++)
903+
{
904+
rho_band[i] = 0.0;
905+
}
906+
907+
for(int i = 0; i < INPUT.band_print_num; i++)
908+
{
909+
int ib = INPUT.bands_to_print[i];
910+
for(int ik = 0; ik < this->kv.nks; ik++)
911+
{
912+
this->psi->fix_k(ik);
913+
this->pw_wfc->recip_to_real(this->ctx,&psi[0](ib,0),wfcr,ik);
914+
915+
double w1 = static_cast<double>(this->kv.wk[ik] / GlobalC::ucell.omega);
916+
917+
for(int i = 0; i < this->pw_rho->nxyz; i++)
918+
{
919+
rho_band[i] += std::norm(wfcr[i]) * w1;
920+
}
921+
}
922+
923+
std::stringstream ssc;
924+
ssc << GlobalV::global_out_dir << "band" << ib << ".cube";
925+
926+
ModuleIO::write_rho
927+
(
928+
#ifdef __MPI
929+
this->pw_big->bz,
930+
this->pw_big->nbz,
931+
this->pw_big->nplane,
932+
this->pw_big->startz_current,
933+
#endif
934+
rho_band,
935+
0,
936+
GlobalV::NSPIN,
937+
0,
938+
ssc.str(),
939+
this->pw_rho->nx,
940+
this->pw_rho->ny,
941+
this->pw_rho->nz,
942+
0.0,
943+
&(GlobalC::ucell),
944+
11);
945+
}
946+
delete[] wfcr;
947+
delete[] rho_band;
948+
}
897949
}
898950

899951
template <typename T, typename Device>

source/module_io/input.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ void Input::Default(void)
327327

328328
out_bandgap = 0; // QO added for bandgap printing
329329

330+
band_print_num = 0;
331+
330332
deepks_out_labels = 0; // caoyu added 2020-11-24, mohan added 2021-01-03
331333
deepks_scf = 0;
332334
deepks_bandgap = 0;
@@ -1327,6 +1329,14 @@ bool Input::Read(const std::string& fn)
13271329
{
13281330
read_bool(ifs, out_chg);
13291331
}
1332+
else if (strcmp("band_print_num", word) == 0)
1333+
{
1334+
read_value(ifs, band_print_num);
1335+
}
1336+
else if (strcmp("bands_to_print", word) == 0)
1337+
{
1338+
ifs.ignore(150, '\n');
1339+
}
13301340
else if (strcmp("out_dm", word) == 0)
13311341
{
13321342
read_bool(ifs, out_dm);
@@ -2369,6 +2379,29 @@ bool Input::Read(const std::string& fn)
23692379
ModuleBase::WARNING_QUIT("Input", "The ntype in INPUT is not equal to the ntype counted in STRU, check it.");
23702380
}
23712381

2382+
if(band_print_num > 0)
2383+
{
2384+
bands_to_print.resize(band_print_num);
2385+
ifs.clear();
2386+
ifs.seekg(0); // move to the beginning of the file
2387+
ifs.rdstate();
2388+
while (ifs.good())
2389+
{
2390+
ifs >> word1;
2391+
if (ifs.eof() != 0)
2392+
break;
2393+
strtolower(word1, word); // convert uppercase std::string to lower case; word1 --> word
2394+
2395+
if (strcmp("bands_to_print", word) == 0)
2396+
{
2397+
for(int i = 0; i < band_print_num; i ++)
2398+
{
2399+
ifs >> bands_to_print[i];
2400+
}
2401+
}
2402+
}
2403+
}
2404+
23722405
//----------------------------------------------------------
23732406
// DFT+U Xin Qu added on 2020-10-29
23742407
//----------------------------------------------------------
@@ -3524,6 +3557,17 @@ void Input::Bcast()
35243557
Parallel_Common::bcast_bool(restart_save); // Peize Lin add 2020.04.04
35253558
Parallel_Common::bcast_bool(restart_load); // Peize Lin add 2020.04.04
35263559

3560+
Parallel_Common::bcast_int(band_print_num);
3561+
if(GlobalV::MY_RANK != 0)
3562+
{
3563+
bands_to_print.resize(band_print_num);
3564+
}
3565+
3566+
for(int i = 0; i < band_print_num; i++)
3567+
{
3568+
Parallel_Common::bcast_int(bands_to_print[i]);
3569+
}
3570+
35273571
//-----------------------------------------------------------------------------------
35283572
// DFT+U (added by Quxin 2020-10-29)
35293573
//-----------------------------------------------------------------------------------

source/module_io/input.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ class Input
259259
bool out_chg; // output charge density. 0: no; 1: yes
260260
bool out_dm; // output density matrix.
261261
bool out_dm1;
262+
int band_print_num;
263+
std::vector<int> bands_to_print;
262264
int out_pot; // yes or no
263265
int out_wfc_pw; // 0: no; 1: txt; 2: dat
264266
bool out_wfc_r; // 0: no; 1: yes

0 commit comments

Comments
 (0)