Skip to content

Commit 025b653

Browse files
authored
Update esolver_ks_lcao.cpp
1 parent 9cc044e commit 025b653

File tree

1 file changed

+42
-49
lines changed

1 file changed

+42
-49
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,20 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
156156
// DMR is not initialized here, it will be constructed in each before_scf
157157
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)->init_DM(&this->kv, &(this->pv), PARAM.inp.nspin);
158158

159-
// 5) initialize Hamilt in LCAO
160-
// * allocate H and S matrices according to computational resources
161-
// * set the 'trace' between local H/S and global H/S
162-
LCAO_domain::divide_HS_in_frag(PARAM.globalv.gamma_only_local, pv, this->kv.get_nks(), orb_);
159+
//! 5) initialize the Hamiltonian (H) and overlap (S) matrices in LCAO basis
160+
//! set the 'trace' between local H/S and global H/S
161+
LCAO_domain::divide_HS_in_frag(PARAM.globalv.gamma_only_local,
162+
pv,
163+
this->kv.get_nks(),
164+
orb_);
163165

164166
#ifdef __EXX
165167
// 6) initialize exx
166168
// PLEASE simplify the Exx_Global interface
167-
if (PARAM.inp.calculation == "scf" || PARAM.inp.calculation == "relax" || PARAM.inp.calculation == "cell-relax"
168-
|| PARAM.inp.calculation == "md")
169+
if (PARAM.inp.calculation == "scf" ||
170+
PARAM.inp.calculation == "relax" ||
171+
PARAM.inp.calculation == "cell-relax" ||
172+
PARAM.inp.calculation == "md")
169173
{
170174
if (GlobalC::exx_info.info_global.cal_exx)
171175
{
@@ -188,11 +192,15 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
188192
// 7) initialize DFT+U
189193
if (PARAM.inp.dft_plus_u)
190194
{
191-
GlobalC::dftu.init(ucell, &this->pv, this->kv.get_nks(), orb_);
195+
GlobalC::dftu.init(ucell,
196+
&this->pv,
197+
this->kv.get_nks(),
198+
orb_);
192199
}
193200

194201
// 8) initialize ppcell
195-
GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, this->pw_rho);
202+
GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc,
203+
this->pw_rho);
196204

197205
// 9) inititlize the charge density
198206
this->pelec->charge->allocate(PARAM.inp.nspin);
@@ -214,15 +222,16 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
214222
// 11) initialize deepks
215223
if (PARAM.inp.deepks_scf)
216224
{
217-
// load the DeePKS model from deep neural network
225+
//! load the DeePKS model from deep neural network
218226
GlobalC::ld.load_model(PARAM.inp.deepks_model);
219-
// read pdm from file for NSCF or SCF-restart, do it only once in whole calculation
227+
228+
//! read pdm from file for NSCF or SCF-restart, do it only once in whole calculation
220229
GlobalC::ld.read_projected_DM((PARAM.inp.init_chg == "file"), PARAM.inp.deepks_equiv, *orb_.Alpha);
221230
}
222231
#endif
223232

224-
// 12) set occupations
225-
// tddft does not need to set occupations in the first scf
233+
//! 12) set occupations
234+
//! tddft does not need to set occupations in the first scf
226235
if (PARAM.inp.ocp && inp.esolver_type != "tddft")
227236
{
228237
this->pelec->fixed_weights(PARAM.inp.ocp_kb, PARAM.inp.nbands, PARAM.inp.nelec);
@@ -344,7 +353,9 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners()
344353
GlobalV::ofs_running << " !FINAL_ETOT_IS " << this->pelec->f_en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl;
345354
GlobalV::ofs_running << " --------------------------------------------\n\n" << std::endl;
346355

347-
if (PARAM.inp.out_dos != 0 || PARAM.inp.out_band[0] != 0 || PARAM.inp.out_proj_band != 0)
356+
if (PARAM.inp.out_dos != 0 ||
357+
PARAM.inp.out_band[0] != 0 ||
358+
PARAM.inp.out_proj_band != 0)
348359
{
349360
GlobalV::ofs_running << "\n\n\n\n";
350361
GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
@@ -376,14 +387,21 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners()
376387
<< std::endl;
377388
GlobalV::ofs_running << "\n\n\n\n";
378389
}
390+
379391
// qianrui modify 2020-10-18
380-
if (PARAM.inp.calculation == "scf" || PARAM.inp.calculation == "md" || PARAM.inp.calculation == "relax")
392+
if (PARAM.inp.calculation == "scf" ||
393+
PARAM.inp.calculation == "md" ||
394+
PARAM.inp.calculation == "relax")
381395
{
382-
ModuleIO::write_istate_info(this->pelec->ekb, this->pelec->wg, this->kv, &(GlobalC::Pkpoints));
396+
ModuleIO::write_istate_info(this->pelec->ekb,
397+
this->pelec->wg,
398+
this->kv,
399+
&(GlobalC::Pkpoints));
383400
}
384401

385402
const int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1;
386403

404+
//! print out band information
387405
if (PARAM.inp.out_band[0])
388406
{
389407
for (int is = 0; is < nspin0; is++)
@@ -400,9 +418,10 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners()
400418
this->kv,
401419
&(GlobalC::Pkpoints));
402420
}
403-
} // out_band
421+
}
404422

405-
if (PARAM.inp.out_proj_band) // Projeced band structure added by jiyy-2022-4-20
423+
//! Projeced band structure added by jiyy-2022-4-20
424+
if (PARAM.inp.out_proj_band)
406425
{
407426
ModuleIO::write_proj_band_lcao(this->psi, this->pv, this->pelec, this->kv, GlobalC::ucell, this->p_hamilt);
408427
}
@@ -572,25 +591,6 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(const int istep, const int iter)
572591
// calculate the local potential(rho) again.
573592
// the grid integration will do in later grid integration.
574593

575-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
576-
// a puzzle remains here.
577-
// if I don't renew potential,
578-
// The scf_thr is very small.
579-
// OneElectron, Hartree and
580-
// Exc energy are all correct
581-
// except the band energy.
582-
//
583-
// solved by mohan 2010-09-10
584-
// there are there rho here:
585-
// rho1: formed by read in orbitals.
586-
// rho2: atomic rho, used to construct H
587-
// rho3: generated by after diagonalize
588-
// here converged because rho3 and rho1
589-
// are very close.
590-
// so be careful here, make sure
591-
// rho1 and rho2 are the same rho.
592-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
593-
594594
if (PARAM.inp.nspin == 4)
595595
{
596596
GlobalC::ucell.cal_ux();
@@ -686,16 +686,17 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2density_single(int istep, int iter, double
686686
{
687687
ModuleBase::TITLE("ESolver_KS_LCAO", "hamilt2density_single");
688688

689-
// reset energy
689+
//! reset energy
690690
this->pelec->f_en.eband = 0.0;
691691
this->pelec->f_en.demet = 0.0;
692692
bool skip_charge = PARAM.inp.calculation == "nscf" ? true : false;
693693

694-
// run the inner lambda loop to contrain atomic moments with the DeltaSpin method
694+
//! run the inner lambda loop to contrain atomic moments with the DeltaSpin method
695695
bool skip_solve = false;
696696
if (PARAM.inp.sc_mag_switch)
697697
{
698698
spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance();
699+
699700
if(!sc.mag_converged() && this->drho>0 && this->drho < PARAM.inp.sc_scf_thr)
700701
{
701702
// optimize lambda to get target magnetic moments, but the lambda is not near target
@@ -853,8 +854,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(const int istep, int& iter)
853854
{
854855
ModuleBase::TITLE("ESolver_KS_LCAO", "iter_finish");
855856

856-
// 6) calculate the local occupation number matrix and energy correction in
857-
// DFT+U
857+
// 6) calculate local occupation number matrix and energy correction in DFT+U
858858
if (PARAM.inp.dft_plus_u)
859859
{
860860
// only old DFT+U method should calculated energy correction in esolver,
@@ -926,15 +926,8 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(const int istep, int& iter)
926926
iter,
927927
istep,
928928
this->conv_esolver)
929-
: this->exc->exx_iter_finish(this->kv,
930-
GlobalC::ucell,
931-
*this->p_hamilt,
932-
*this->pelec,
933-
*this->p_chgmix,
934-
this->scf_ene_thr,
935-
iter,
936-
istep,
937-
this->conv_esolver);
929+
: this->exc->exx_iter_finish(this->kv,GlobalC::ucell,*this->p_hamilt,*this->pelec,
930+
*this->p_chgmix,this->scf_ene_thr,iter,istep,this->conv_esolver);
938931
}
939932
}
940933
#endif

0 commit comments

Comments
 (0)