Skip to content

Commit 6df9240

Browse files
authored
Update esolver_ks_lcao.cpp (#5632)
1 parent 32f1547 commit 6df9240

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -987,18 +987,18 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
987987
this->pelec->cal_tau(*(this->psi));
988988
}
989989

990-
// 2) call after_scf() of ESolver_KS
990+
//! 5) call after_scf() of ESolver_KS
991991
ESolver_KS<TK>::after_scf(ucell, istep);
992992

993-
// 3) write density matrix for sparse matrix
993+
//! 6) write density matrix for sparse matrix
994994
ModuleIO::write_dmr(dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM()->get_DMR_vector(),
995995
this->pv,
996996
PARAM.inp.out_dm1,
997997
false,
998998
PARAM.inp.out_app_flag,
999999
istep);
10001000

1001-
// 4) write density matrix
1001+
//! 7) write density matrix
10021002
if (PARAM.inp.out_dm)
10031003
{
10041004
std::vector<double> efermis(PARAM.inp.nspin == 2 ? 2 : 1);
@@ -1015,7 +1015,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
10151015
}
10161016

10171017
#ifdef __EXX
1018-
// 5) write Hexx matrix for NSCF (see `out_chg` in docs/advanced/input_files/input-main.md)
1018+
//! 8) write Hexx matrix for NSCF (see `out_chg` in docs/advanced/input_files/input-main.md)
10191019
if (PARAM.inp.calculation != "nscf")
10201020
{
10211021
if (GlobalC::exx_info.info_global.cal_exx && PARAM.inp.out_chg[0]
@@ -1034,7 +1034,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
10341034
}
10351035
#endif
10361036

1037-
// 10) write deepks information
1037+
//! 9) Write DeePKS information
10381038
#ifdef __DEEPKS
10391039
std::shared_ptr<LCAO_Deepks> ld_shared_ptr(&GlobalC::ld, [](LCAO_Deepks*) {});
10401040
LCAO_Deepks_Interface LDI = LCAO_Deepks_Interface(ld_shared_ptr);
@@ -1056,14 +1056,22 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
10561056
ModuleBase::timer::tick("ESolver_KS_LCAO", "out_deepks_labels");
10571057
#endif
10581058

1059+
//! 10) Perform RDMFT calculations
10591060
/******** test RDMFT *********/
10601061
if ( PARAM.inp.rdmft == true ) // rdmft, added by jghan, 2024-10-17
10611062
{
10621063
ModuleBase::matrix occ_number_ks(this->pelec->wg);
1063-
for(int ik=0; ik < occ_number_ks.nr; ++ik) { for(int inb=0; inb < occ_number_ks.nc; ++inb) occ_number_ks(ik, inb) /= this->kv.wk[ik]; }
1064+
for(int ik=0; ik < occ_number_ks.nr; ++ik)
1065+
{
1066+
for(int inb=0; inb < occ_number_ks.nc; ++inb)
1067+
{
1068+
occ_number_ks(ik, inb) /= this->kv.wk[ik];
1069+
}
1070+
}
10641071
this->rdmft_solver.update_elec(occ_number_ks, *(this->psi));
10651072

1066-
//initialize the gradients of Etotal on occupation numbers and wfc, and set all elements to 0.
1073+
//! initialize the gradients of Etotal with respect to occupation numbers and wfc,
1074+
//! and set all elements to 0.
10671075
ModuleBase::matrix dE_dOccNum(this->pelec->wg.nr, this->pelec->wg.nc, true);
10681076
psi::Psi<TK> dE_dWfc(this->psi->get_nk(), this->psi->get_nbands(), this->psi->get_nbasis());
10691077
dE_dWfc.zero_out();
@@ -1074,7 +1082,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
10741082

10751083

10761084
#ifdef __EXX
1077-
// 11) write rpa information
1085+
// 11) Write RPA information.
10781086
if (PARAM.inp.rpa)
10791087
{
10801088
// ModuleRPA::DFT_RPA_interface
@@ -1089,7 +1097,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
10891097
}
10901098
#endif
10911099

1092-
// 12) write HR in npz format
1100+
// 12) write HR in npz format.
10931101
if (PARAM.inp.out_hr_npz)
10941102
{
10951103
this->p_hamilt->updateHk(0); // first k point, up spin
@@ -1108,7 +1116,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
11081116
}
11091117
}
11101118

1111-
// 13) write dm in npz format
1119+
// 13) write density matrix in the 'npz' format.
11121120
if (PARAM.inp.out_dm_npz)
11131121
{
11141122
const elecstate::DensityMatrix<TK, double>* dm
@@ -1123,32 +1131,33 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
11231131
}
11241132
}
11251133

1126-
// 14) output sparse matrix
1134+
//! 14) Print out information every 'out_interval' steps.
11271135
if (PARAM.inp.calculation != "md" || istep % PARAM.inp.out_interval == 0)
11281136
{
1137+
//! Print out sparse matrix
11291138
ModuleIO::output_mat_sparse(PARAM.inp.out_mat_hs2,
11301139
PARAM.inp.out_mat_dh,
11311140
PARAM.inp.out_mat_t,
11321141
PARAM.inp.out_mat_r,
11331142
istep,
11341143
this->pelec->pot->get_effective_v(),
11351144
this->pv,
1136-
this->GK, // mohan add 2024-04-01
1145+
this->GK,
11371146
two_center_bundle_,
11381147
orb_,
11391148
ucell,
1140-
GlobalC::GridD, // mohan add 2024-04-06
1149+
GlobalC::GridD,
11411150
this->kv,
11421151
this->p_hamilt);
1143-
// mulliken charge analysis
1152+
1153+
//! Perform Mulliken charge analysis
11441154
if (PARAM.inp.out_mul)
11451155
{
11461156
ModuleIO::cal_mag(&(this->pv), this->p_hamilt, this->kv, this->pelec, ucell, istep, true);
11471157
}
11481158
}
11491159

1150-
// 15) write atomic magnetization only when spin_constraint is on
1151-
// spin constrain calculations.
1160+
//! 15) Print out atomic magnetization only when 'spin_constraint' is on.
11521161
if (PARAM.inp.sc_mag_switch)
11531162
{
11541163
spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance();
@@ -1157,13 +1166,14 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
11571166
sc.print_Mag_Force(GlobalV::ofs_running);
11581167
}
11591168

1160-
// 16) delete grid
1169+
//! 16) Clean up RA.
1170+
//! this should be last function and put it in the end, mohan request 2024-11-28
11611171
if (!PARAM.inp.cal_force && !PARAM.inp.cal_stress)
11621172
{
11631173
RA.delete_grid();
11641174
}
11651175

1166-
// 17) write quasi-orbitals, added by Yike Huang.
1176+
//! 17) Print out quasi-orbitals.
11671177
if (PARAM.inp.qo_switch)
11681178
{
11691179
toQO tqo(PARAM.inp.qo_basis, PARAM.inp.qo_strategy, PARAM.inp.qo_thr, PARAM.inp.qo_screening_coeff);
@@ -1178,6 +1188,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
11781188
tqo.calculate();
11791189
}
11801190

1191+
//! 18) Print out kinetic matrix.
11811192
if (PARAM.inp.out_mat_tk[0])
11821193
{
11831194
hamilt::HS_Matrix_K<TK> hsk(&pv, true);
@@ -1208,10 +1219,11 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
12081219
GlobalV::DRANK);
12091220
}
12101221

1222+
// where is new? mohan ask 2024-11-28
12111223
delete ekinetic;
12121224
}
12131225

1214-
// add by jingan in 2018.11.7
1226+
//! 19) Wannier 90 function, added by jingan in 2018.11.7
12151227
if (PARAM.inp.calculation == "nscf" && PARAM.inp.towannier90)
12161228
{
12171229
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "Wave function to Wannier90");
@@ -1225,8 +1237,13 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
12251237
PARAM.inp.nnkpfile,
12261238
PARAM.inp.wannier_spin);
12271239

1228-
myWannier
1229-
.calculate(this->pelec->ekb, this->pw_wfc, this->pw_big, this->sf, this->kv, this->psi, &(this->pv));
1240+
myWannier.calculate(this->pelec->ekb,
1241+
this->pw_wfc,
1242+
this->pw_big,
1243+
this->sf,
1244+
this->kv,
1245+
this->psi,
1246+
&(this->pv));
12301247
}
12311248
else if (PARAM.inp.wannier_method == 2)
12321249
{
@@ -1244,8 +1261,10 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
12441261
std::cout << FmtCore::format(" >> Finish %s.\n * * * * * *\n", "Wave function to Wannier90");
12451262
}
12461263

1247-
// add by jingan
1248-
if (PARAM.inp.calculation == "nscf" && berryphase::berry_phase_flag && ModuleSymmetry::Symmetry::symm_flag != 1)
1264+
//! 20) berry phase calculations, added by jingan
1265+
if (PARAM.inp.calculation == "nscf" &&
1266+
berryphase::berry_phase_flag &&
1267+
ModuleSymmetry::Symmetry::symm_flag != 1)
12491268
{
12501269
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "Berry phase calculation");
12511270
berryphase bp(&(this->pv));
@@ -1259,11 +1278,6 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
12591278
}
12601279
}
12611280

1262-
1263-
//------------------------------------------------------------------------------
1264-
//! the 20th,21th,22th functions of ESolver_KS_LCAO
1265-
//! mohan add 2024-05-11
1266-
//------------------------------------------------------------------------------
12671281
template class ESolver_KS_LCAO<double, double>;
12681282
template class ESolver_KS_LCAO<std::complex<double>, double>;
12691283
template class ESolver_KS_LCAO<std::complex<double>, std::complex<double>>;

0 commit comments

Comments
 (0)