Skip to content

Commit 0b1025b

Browse files
committed
update dos and eig and eig_occ to adapt to g index
1 parent b12774a commit 0b1025b

File tree

9 files changed

+116
-50
lines changed

9 files changed

+116
-50
lines changed

source/source_esolver/esolver_fp.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
173173
}
174174
}
175175

176+
std::string geom_block;
177+
if(istep_in==-1)
178+
{
179+
// do nothing
180+
}
181+
else if(istep_in>=0)
182+
{
183+
geom_block = "g" + std::to_string(istep + 1);
184+
}
185+
176186
// 4) write charge density
177187
if (PARAM.inp.out_chg[0] > 0)
178188
{
@@ -192,7 +202,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
192202
// do nothing
193203
}
194204

195-
fn += spin_block + ".cube";
205+
fn += spin_block + geom_block + ".cube";
196206

197207
ModuleIO::write_vdata_palgrid(Pgrid,
198208
this->chr.rho_save[is],
@@ -209,7 +219,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
209219
{
210220
fn = PARAM.globalv.global_out_dir + "tau";
211221

212-
fn += spin_block + ".cube";
222+
fn += spin_block + geom_block + ".cube";
213223

214224
ModuleIO::write_vdata_palgrid(Pgrid,
215225
this->chr.kin_r_save[is],
@@ -240,7 +250,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
240250
// do nothing
241251
}
242252

243-
fn += spin_block + ".cube";
253+
fn += spin_block + geom_block + ".cube";
244254

245255
ModuleIO::write_vdata_palgrid(Pgrid,
246256
this->pelec->pot->get_effective_v(is),
@@ -256,7 +266,9 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
256266
}
257267
else if (PARAM.inp.out_pot == 2)
258268
{
259-
std::string fn =PARAM.globalv.global_out_dir + "pot_es.cube";
269+
std::string fn =PARAM.globalv.global_out_dir + "potes";
270+
fn += geom_block + ".cube";
271+
260272
ModuleIO::write_elecstat_pot(
261273
#ifdef __MPI
262274
this->pw_big->bz,

source/source_esolver/esolver_ks.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -557,23 +557,17 @@ void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep, const bo
557557
ESolver_FP::after_scf(ucell, istep, conv_esolver);
558558

559559
// 3) write eigenvalues
560+
int istep_in = -1;
560561
if (PARAM.inp.out_freq_ion>0) // default value of out_freq_ion is 0
561562
{
562563
if (istep % PARAM.inp.out_freq_ion == 0)
563564
{
565+
istep_in = istep;
564566
// celecstate::print_eigenvalue(this->pelec->ekb,this->pelec->wg,this->pelec->klist,GlobalV::ofs_running);
565567
}
566568
}
567-
}
568-
569-
template <typename T, typename Device>
570-
void ESolver_KS<T, Device>::after_all_runners(UnitCell& ucell)
571-
{
572-
// 1) write Etot information
573-
ESolver_FP::after_all_runners(ucell);
574569

575-
// 2) write eigenvalue information
576-
ModuleIO::write_eig_file(this->pelec->ekb, this->pelec->wg, this->kv);
570+
ModuleIO::write_eig_file(this->pelec->ekb, this->pelec->wg, this->kv, istep_in);
577571

578572
// 3) write band information
579573
if (PARAM.inp.out_band[0])
@@ -583,16 +577,26 @@ void ESolver_KS<T, Device>::after_all_runners(UnitCell& ucell)
583577
{
584578
std::stringstream ss;
585579
ss << PARAM.globalv.global_out_dir << "eig";
586-
587-
if(nspin0==1)
580+
581+
if(nspin0==1)
582+
{
583+
// do nothing
584+
}
585+
else if(nspin0==2)
586+
{
587+
ss << "s" << is + 1;
588+
}
589+
590+
if(istep == -1)
588591
{
589592
// do nothing
590593
}
591-
else if(nspin0==2)
594+
else if(istep>=0)
592595
{
593-
ss << "s" << is + 1;
596+
ss << "g" << istep+1;
594597
}
595-
ss << ".txt";
598+
599+
ss << ".txt";
596600

597601
const double eshift = 0.0;
598602
ModuleIO::nscf_band(is,
@@ -604,6 +608,16 @@ void ESolver_KS<T, Device>::after_all_runners(UnitCell& ucell)
604608
this->kv);
605609
}
606610
}
611+
612+
613+
614+
}
615+
616+
template <typename T, typename Device>
617+
void ESolver_KS<T, Device>::after_all_runners(UnitCell& ucell)
618+
{
619+
// 1) write Etot information
620+
ESolver_FP::after_all_runners(ucell);
607621
}
608622

609623
//------------------------------------------------------------------------------

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,34 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
710710
this->psi[0].size());
711711
}
712712

713+
//----------------------------------------------------------
714+
//! 4) Compute density of states (DOS)
715+
//----------------------------------------------------------
716+
if (PARAM.inp.out_dos)
717+
{
718+
int istep_in = -1;
719+
if (PARAM.inp.out_freq_ion>0) // default value of out_freq_ion is 0
720+
{
721+
if (istep % PARAM.inp.out_freq_ion == 0)
722+
{
723+
istep_in=istep;
724+
}
725+
}
726+
ModuleIO::write_dos_pw(ucell,
727+
this->pelec->ekb,
728+
this->pelec->wg,
729+
this->kv,
730+
PARAM.inp.nbands,
731+
istep_in,
732+
this->pelec->eferm,
733+
PARAM.inp.dos_edelta_ev,
734+
PARAM.inp.dos_scale,
735+
PARAM.inp.dos_sigma,
736+
GlobalV::ofs_running);
737+
}
738+
713739
//------------------------------------------------------------------
714-
// 4) calculate band-decomposed (partial) charge density in pw basis
740+
// 5) calculate band-decomposed (partial) charge density in pw basis
715741
//------------------------------------------------------------------
716742
if (PARAM.inp.out_pchg.size() > 0)
717743
{
@@ -745,7 +771,7 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
745771
}
746772

747773
//------------------------------------------------------------------
748-
//! 5) calculate Wannier functions in pw basis
774+
//! 6) calculate Wannier functions in pw basis
749775
//------------------------------------------------------------------
750776
if (PARAM.inp.calculation == "nscf" && PARAM.inp.towannier90)
751777
{
@@ -763,7 +789,7 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
763789
}
764790

765791
//------------------------------------------------------------------
766-
//! 6) calculate Berry phase polarization in pw basis
792+
//! 7) calculate Berry phase polarization in pw basis
767793
//------------------------------------------------------------------
768794
if (PARAM.inp.calculation == "nscf" && berryphase::berry_phase_flag && ModuleSymmetry::Symmetry::symm_flag != 1)
769795
{
@@ -774,7 +800,7 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
774800
}
775801

776802
//------------------------------------------------------------------
777-
// 7) write spin constrian results in pw basis
803+
// 8) write spin constrian results in pw basis
778804
// spin constrain calculations, write atomic magnetization and magnetic force.
779805
//------------------------------------------------------------------
780806
if (PARAM.inp.sc_mag_switch)
@@ -786,7 +812,7 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
786812
}
787813

788814
//------------------------------------------------------------------
789-
// 8) write onsite occupations for charge and magnetizations
815+
// 9) write onsite occupations for charge and magnetizations
790816
//------------------------------------------------------------------
791817
if (PARAM.inp.onsite_radius > 0)
792818
{ // float type has not been implemented
@@ -878,24 +904,7 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
878904
ESolver_KS<T, Device>::after_all_runners(ucell);
879905

880906
//----------------------------------------------------------
881-
//! 2) Compute density of states (DOS)
882-
//----------------------------------------------------------
883-
if (PARAM.inp.out_dos)
884-
{
885-
ModuleIO::write_dos_pw(ucell,
886-
this->pelec->ekb,
887-
this->pelec->wg,
888-
this->kv,
889-
PARAM.inp.nbands,
890-
this->pelec->eferm,
891-
PARAM.inp.dos_edelta_ev,
892-
PARAM.inp.dos_scale,
893-
PARAM.inp.dos_sigma,
894-
GlobalV::ofs_running);
895-
}
896-
897-
//----------------------------------------------------------
898-
//! 3) Compute LDOS
907+
//! 2) Compute LDOS
899908
//----------------------------------------------------------
900909
if (PARAM.inp.out_ldos[0])
901910
{
@@ -906,7 +915,7 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
906915
}
907916

908917
//----------------------------------------------------------
909-
//! 4) Calculate the spillage value,
918+
//! 3) Calculate the spillage value,
910919
//! which are used to generate numerical atomic orbitals
911920
//----------------------------------------------------------
912921
if (PARAM.inp.basis_type == "pw" && PARAM.inp.out_spillage)
@@ -929,7 +938,7 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
929938
}
930939

931940
//----------------------------------------------------------
932-
//! 5) Print out electronic wave functions in real space
941+
//! 4) Print out electronic wave functions in real space
933942
//----------------------------------------------------------
934943
if (PARAM.inp.out_wfc_norm.size() > 0 || PARAM.inp.out_wfc_re_im.size() > 0)
935944
{
@@ -960,7 +969,7 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
960969
}
961970

962971
//----------------------------------------------------------
963-
//! 6) Use Kubo-Greenwood method to compute conductivities
972+
//! 5) Use Kubo-Greenwood method to compute conductivities
964973
//----------------------------------------------------------
965974
if (PARAM.inp.cal_cond)
966975
{

source/source_io/test/write_dos_pw_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ TEST_F(DosPWTest,Dos1)
7777
dosp.wg,
7878
*kv,
7979
PARAM.inp.nbands,
80+
-1, // istep_in
8081
fermi_energy,
8182
dosp.de_ev,
8283
dos_scale,
@@ -140,7 +141,8 @@ TEST_F(DosPWTest,Dos2)
140141
dosp.ekb,
141142
dosp.wg,
142143
*kv,
143-
PARAM.inp.nbands,
144+
PARAM.inp.nbands,
145+
-1, // istep_in
144146
fermi_energy,
145147
dosp.de_ev,
146148
dos_scale,

source/source_io/test/write_eig_occ_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ TEST_F(IstateInfoTest, OutIstateInfoS1)
9898
}
9999

100100
// write eigenvalues and occupations
101-
ModuleIO::write_eig_file(ekb, wg, *kv);
101+
const int istep_in = -1;
102+
ModuleIO::write_eig_file(ekb, wg, *kv, istep_in);
102103

103104
// check the output files
104105
std::ifstream ifs;

source/source_io/write_dos_pw.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ void ModuleIO::write_dos_pw(
1010
const ModuleBase::matrix& wg,
1111
const K_Vectors& kv,
1212
const int nbands,
13+
const int istep_in,
1314
const elecstate::efermi &energy_fermi,
1415
const double& dos_edelta_ev,
1516
const double& dos_scale,
@@ -47,6 +48,16 @@ void ModuleIO::write_dos_pw(
4748
{
4849
// do nothing;
4950
}
51+
52+
if(istep_in==-1)
53+
{
54+
// do nothing
55+
}
56+
else if(istep_in >= 0)
57+
{
58+
ss << "g" << std::to_string(istep_in+1);
59+
}
60+
5061
ss << ".txt";
5162

5263
ModuleBase::GlobalFunc::OUT(ofs_running, "DOS file", ss.str());

source/source_io/write_dos_pw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace ModuleIO
1515
const ModuleBase::matrix &wg,
1616
const K_Vectors& kv,
1717
const int nbands,
18+
const int istep_in,
1819
const elecstate::efermi &energy_fermi,
1920
const double &dos_edelta_ev,
2021
const double &dos_scale,

source/source_io/write_eig_occ.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ void ModuleIO::write_eig_iter(const ModuleBase::matrix &ekb,const ModuleBase::ma
158158
ModuleBase::timer::tick("ModuleIO", "write_eig_iter");
159159
}
160160

161-
void ModuleIO::write_eig_file(const ModuleBase::matrix &ekb,const ModuleBase::matrix &wg, const K_Vectors& kv)
161+
void ModuleIO::write_eig_file(const ModuleBase::matrix &ekb,
162+
const ModuleBase::matrix &wg,
163+
const K_Vectors& kv,
164+
const int istep_in)
162165
{
163166
ModuleBase::TITLE("ModuleIO","write_eig_file");
164167
ModuleBase::timer::tick("ModuleIO", "write_eig_file");
@@ -207,7 +210,19 @@ void ModuleIO::write_eig_file(const ModuleBase::matrix &ekb,const ModuleBase::ma
207210
#endif
208211

209212
// file name to store eigenvalues
210-
std::string filename = PARAM.globalv.global_out_dir + "eig_occ.txt";
213+
std::string filename = PARAM.globalv.global_out_dir + "eig_occ_";
214+
215+
if(istep_in == -1)
216+
{
217+
// do nothing
218+
}
219+
else if(istep_in >= 0)
220+
{
221+
filename += "g" + std::to_string(istep_in+1);
222+
}
223+
224+
filename += ".txt";
225+
211226
GlobalV::ofs_running << " Write eigenvalues and occupations to file: " << filename << std::endl;
212227

213228
if (GlobalV::MY_RANK == 0)

source/source_io/write_eig_occ.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ namespace ModuleIO
1111
const K_Vectors& kv);
1212

1313
void write_eig_file(const ModuleBase::matrix &ekb,
14-
const ModuleBase::matrix &wg,
15-
const K_Vectors& kv);
14+
const ModuleBase::matrix &wg,
15+
const K_Vectors& kv,
16+
const int istep_in);
1617
}
1718

1819
#endif

0 commit comments

Comments
 (0)