Skip to content

Commit d9ac0c6

Browse files
authored
Clean and Reconstruct ESolver --- 3rd time (#6567)
* add setup_dm in module_dm * update before_all_runners in esolver * change setup_dm back * add setup_exx * fix bug * add setup_exx in normal LCAO codes * fix bug about p_hamilt and fix setup_exx * fix bug * fix bug * eliminate exd and exc from ctrl_iter_lcao input parameters * add setup_deepks * update the input variables of ctrl_scf_lcao * reconstruct the constructor of p_hamilt * update ld * fix a few bugs * DeePKS has been used in operator, fix it
1 parent 39d1383 commit d9ac0c6

30 files changed

Lines changed: 527 additions & 519 deletions

examples/relax/lcao_output/INPUT

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ out_band 0
4040
out_stru 0
4141
out_app_flag 0
4242

43-
out_interval 1

source/Makefile.Objects

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ OBJS_ELECSTAT=elecstate.o\
253253

254254
OBJS_ELECSTAT_LCAO=elecstate_lcao.o\
255255
elecstate_lcao_cal_tau.o\
256+
setup_dm.o\
256257
density_matrix.o\
257258
density_matrix_io.o\
258259
cal_dm_psi.o\
@@ -668,6 +669,8 @@ OBJS_LCAO=evolve_elec.o\
668669
LCAO_allocate.o\
669670
LCAO_set_mat2d.o\
670671
LCAO_init_basis.o\
672+
setup_exx.o\
673+
setup_deepks.o\
671674
center2_orb.o\
672675
center2_orb-orb11.o\
673676
center2_orb-orb21.o\
@@ -676,13 +679,13 @@ OBJS_LCAO=evolve_elec.o\
676679
wavefunc_in_pw.o\
677680

678681
OBJS_MODULE_RI=conv_coulomb_pot_k.o\
679-
exx_abfs-abfs_index.o \
680-
exx_abfs-jle.o \
681-
exx_abfs-io.o \
682-
exx_abfs-construct_orbs.o \
683-
ABFs_Construct-PCA.o \
684-
exx_opt_orb.o \
685-
exx_opt_orb-print.o \
682+
exx_abfs-abfs_index.o\
683+
exx_abfs-jle.o\
684+
exx_abfs-io.o\
685+
exx_abfs-construct_orbs.o\
686+
ABFs_Construct-PCA.o\
687+
exx_opt_orb-print.o\
688+
exx_opt_orb.o\
686689
Matrix_Orbs11.o\
687690
Matrix_Orbs21.o\
688691
Matrix_Orbs22.o\

source/source_esolver/esolver_double_xc.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,14 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
154154
this->kv,
155155
this->two_center_bundle_,
156156
this->orb_,
157-
DM
158-
#ifdef __MLALGO
159-
,
160-
&this->ld
161-
#endif
157+
DM,
158+
this->deepks
162159
#ifdef __EXX
163160
,
164161
istep,
165-
GlobalC::exx_info.info_ri.real_number ? &this->exd->two_level_step : &this->exc->two_level_step,
166-
GlobalC::exx_info.info_ri.real_number ? &this->exd->get_Hexxs() : nullptr,
167-
GlobalC::exx_info.info_ri.real_number ? nullptr : &this->exc->get_Hexxs()
162+
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->two_level_step : &this->exx_nao.exc->two_level_step,
163+
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->get_Hexxs() : nullptr,
164+
GlobalC::exx_info.info_ri.real_number ? nullptr : &this->exx_nao.exc->get_Hexxs()
168165
#endif
169166
);
170167
}
@@ -238,7 +235,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
238235
#ifdef __MLALGO
239236
// ---------- output tot and precalc ----------
240237
hamilt::HamiltLCAO<TK, TR>* p_ham_deepks = dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(this->p_hamilt);
241-
std::shared_ptr<LCAO_Deepks<TK>> ld_shared_ptr(&this->ld, [](LCAO_Deepks<TK>*) {});
238+
std::shared_ptr<LCAO_Deepks<TK>> ld_shared_ptr(&this->deepks.ld, [](LCAO_Deepks<TK>*) {});
242239
LCAO_Deepks_Interface<TK, TR> deepks_interface(ld_shared_ptr);
243240

244241
deepks_interface.out_deepks_labels(this->pelec->f_en.etot,
@@ -412,14 +409,11 @@ void ESolver_DoubleXC<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& fo
412409
this->pw_rho,
413410
this->solvent,
414411
#ifdef __MLALGO
415-
this->ld,
412+
this->deepks.ld,
416413
"base",
417414
#endif
418-
#ifdef __EXX
419-
*this->exd,
420-
*this->exc,
421-
#endif
422-
&ucell.symm);
415+
this->exx_nao,
416+
&ucell.symm);
423417
// restore to original xc
424418
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
425419

source/source_esolver/esolver_fp.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ void ESolver_FP::before_all_runners(UnitCell& ucell, const Input_para& inp)
4848
this->pw_rho, this->pw_rhod, this->pw_big,
4949
this->classname, inp);
5050

51-
// setup the structure factors
51+
// setup structure factors
5252
this->sf.set(this->pw_rhod, inp.nbspline);
5353

54+
// write geometry file
5455
ModuleIO::CifParser::write(PARAM.globalv.global_out_dir + "STRU.cif",
5556
ucell,
5657
"# Generated by ABACUS ModuleIO::CifParser",
5758
"data_?");
5859

59-
//! initialize the charge extrapolation method if necessary
60+
// init charge extrapolation
6061
this->CE.Init_CE(inp.nspin, ucell.nat, this->pw_rhod->nrxx, inp.chg_extrap);
6162

6263
return;
6364
}
6465

65-
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
6666
void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_esolver)
6767
{
6868
ModuleBase::TITLE("ESolver_FP", "after_scf");
@@ -125,12 +125,8 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
125125
if (ucell.ionic_position_updated)
126126
{
127127
this->CE.update_all_dis(ucell);
128-
this->CE.extrapolate_charge(&this->Pgrid,
129-
ucell,
130-
&this->chr,
131-
&this->sf,
132-
GlobalV::ofs_running,
133-
GlobalV::ofs_warning);
128+
this->CE.extrapolate_charge(&this->Pgrid, ucell, &this->chr, &this->sf,
129+
GlobalV::ofs_running, GlobalV::ofs_warning);
134130
}
135131

136132
//! calculate D2 or D3 vdW

source/source_esolver/esolver_ks.cpp

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ template <typename T, typename Device>
5151
void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para& inp)
5252
{
5353
ModuleBase::TITLE("ESolver_KS", "before_all_runners");
54-
//! 1) initialize "before_all_runniers" in ESolver_FP
54+
55+
//! 1) init "before_all_runniers" in ESolver_FP
5556
ESolver_FP::before_all_runners(ucell, inp);
5657

58+
//! 2) setup some parameters
5759
classname = "ESolver_KS";
5860
basisname = "";
5961

@@ -65,8 +67,8 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
6567

6668
std::string fft_device = inp.device;
6769

68-
// Fast Fourier Transform
69-
// LCAO basis doesn't support GPU acceleration on FFT currently
70+
//! 3) setup pw_wfc
71+
// currently LCAO doesn't support GPU acceleration of FFT
7072
if(inp.basis_type == "lcao")
7173
{
7274
fft_device = "cpu";
@@ -82,71 +84,49 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
8284
pw_wfc = new ModulePW::PW_Basis_K_Big(fft_device, fft_precision);
8385
ModulePW::PW_Basis_K_Big* tmp = static_cast<ModulePW::PW_Basis_K_Big*>(pw_wfc);
8486

85-
// should not use INPUT here, mohan 2024-05-12
8687
tmp->setbxyz(inp.bx, inp.by, inp.bz);
8788

88-
///----------------------------------------------------------
89-
/// charge mixing
90-
///----------------------------------------------------------
89+
//! 4) setup charge mixing
9190
p_chgmix = new Charge_Mixing();
9291
p_chgmix->set_rhopw(this->pw_rho, this->pw_rhod);
9392

9493
// cell_factor
9594
this->ppcell.cell_factor = inp.cell_factor;
9695

96+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SETUP UNITCELL");
9797

98-
//! 3) it has been established that
99-
// xc_func is same for all elements, therefore
100-
// only the first one if used
98+
//! 5) setup Exc for the first element '0', because all elements have same exc
10199
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
102100

103-
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SETUP UNITCELL");
104-
105-
//! 4) setup the charge mixing parameters
106-
p_chgmix->set_mixing(inp.mixing_mode,
107-
inp.mixing_beta,
108-
inp.mixing_ndim,
109-
inp.mixing_gg0,
110-
inp.mixing_tau,
111-
inp.mixing_beta_mag,
112-
inp.mixing_gg0_mag,
113-
inp.mixing_gg0_min,
114-
inp.mixing_angle,
115-
inp.mixing_dmr,
116-
ucell.omega,
117-
ucell.tpiba);
101+
//! 6) setup the charge mixing parameters
102+
p_chgmix->set_mixing(inp.mixing_mode, inp.mixing_beta, inp.mixing_ndim,
103+
inp.mixing_gg0, inp.mixing_tau, inp.mixing_beta_mag, inp.mixing_gg0_mag,
104+
inp.mixing_gg0_min, inp.mixing_angle, inp.mixing_dmr, ucell.omega, ucell.tpiba);
118105

119106
p_chgmix->init_mixing();
120107

121-
//! 5) ESolver depends on the Symmetry module
122-
// symmetry analysis should be performed every time the cell is changed
108+
//! 7) symmetry analysis should be performed every time the cell is changed
123109
if (ModuleSymmetry::Symmetry::symm_flag == 1)
124110
{
125111
ucell.symm.analy_sys(ucell.lat, ucell.st, ucell.atoms, GlobalV::ofs_running);
126112
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SYMMETRY");
127113
}
128114

129-
//! 6) Setup the k points according to symmetry.
115+
//! 8) Setup the k points according to symmetry.
130116
this->kv.set(ucell,ucell.symm, inp.kpoint_file, inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running);
131117
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS");
132118

133-
//! 7) print information
119+
//! 9) print information
134120
ModuleIO::setup_parameters(ucell, this->kv);
135121

136-
//! 8) setup plane wave for electronic wave functions
122+
//! 10) setup plane wave for electronic wave functions
137123
ModuleESolver::pw_setup(inp, ucell, *this->pw_rho, this->kv, *this->pw_wfc);
138124

139-
//! 9) initialize the real-space uniform grid for FFT and parallel
140-
//! distribution of plane waves
141-
Pgrid.init(this->pw_rhod->nx,
142-
this->pw_rhod->ny,
143-
this->pw_rhod->nz,
144-
this->pw_rhod->nplane,
145-
this->pw_rhod->nrxx,
146-
pw_big->nbz,
147-
pw_big->bz);
148-
149-
//! 10) calculate the structure factor
125+
//! 11) parallel of FFT grid
126+
Pgrid.init(this->pw_rhod->nx, this->pw_rhod->ny, this->pw_rhod->nz,
127+
this->pw_rhod->nplane, this->pw_rhod->nrxx, pw_big->nbz, pw_big->bz);
128+
129+
//! 12) calculate the structure factor
150130
this->sf.setup_structure_factor(&ucell, Pgrid, this->pw_rhod);
151131
}
152132

0 commit comments

Comments
 (0)