Skip to content

Commit 74b3500

Browse files
committed
update before_all_runners in esolver
1 parent 5cc6367 commit 74b3500

File tree

4 files changed

+78
-180
lines changed

4 files changed

+78
-180
lines changed

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

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,24 @@
11
#include "esolver_ks_lcao.h"
2-
3-
#include "source_base/global_variable.h"
4-
#include "source_base/tool_title.h"
52
#include "source_estate/elecstate_tools.h"
6-
7-
#include "source_estate/module_dm/cal_dm_psi.h"
83
#include "source_lcao/module_deltaspin/spin_constrain.h"
9-
#include "source_lcao/module_dftu/dftu.h"
10-
#include "source_io/cube_io.h"
11-
#include "source_io/output_log.h"
124
#include "source_io/read_wfc_nao.h"
13-
#include "source_io/write_elecstat_pot.h"
14-
#include "source_io/module_parameter/parameter.h"
15-
16-
// be careful of hpp, there may be multiple definitions of functions, 20250302, mohan
17-
#include "source_lcao/hs_matrix_k.hpp"
18-
19-
#include "source_base/global_function.h"
20-
#include "source_cell/module_neighbor/sltk_grid_driver.h"
5+
#include "source_lcao/hs_matrix_k.hpp" // there may be multiple definitions if using hpp
216
#include "source_estate/cal_ux.h"
227
#include "source_estate/module_charge/symmetry_rho.h"
23-
#include "source_estate/occupy.h"
248
#include "source_lcao/LCAO_domain.h" // need DeePKS_init
259
#include "source_lcao/module_dftu/dftu.h"
26-
#include "source_pw/module_pwdft/global.h"
27-
#include "source_io/print_info.h"
28-
29-
#include <memory>
30-
3110
#ifdef __MLALGO
3211
#include "source_lcao/module_deepks/LCAO_deepks.h"
3312
#include "source_lcao/module_deepks/LCAO_deepks_interface.h"
3413
#endif
35-
//-----force& stress-------------------
3614
#include "source_lcao/FORCE_STRESS.h"
37-
38-
//-----HSolver ElecState Hamilt--------
3915
#include "source_estate/elecstate_lcao.h"
4016
#include "source_lcao/hamilt_lcao.h"
4117
#include "source_hsolver/hsolver_lcao.h"
42-
4318
#ifdef __EXX
4419
#include "../source_lcao/module_ri/exx_opt_orb.h"
4520
#endif
46-
47-
// test RDMFT
4821
#include "source_lcao/module_rdmft/rdmft.h"
49-
#include "source_lcao/module_gint/temp_gint/gint_info.h"
50-
5122
#include "source_estate/module_charge/chgmixing.h" // use charge mixing, mohan add 20251006
5223
#include "source_estate/module_dm/setup_dm.h" // setup dm from electronic wave functions
5324
#include "source_io/ctrl_runner_lcao.h" // use ctrl_runner_lcao()
@@ -96,32 +67,31 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
9667
// 1) before_all_runners in ESolver_KS
9768
ESolver_KS<TK>::before_all_runners(ucell, inp);
9869

99-
// 2) init ElecState
100-
// autoset nbands in ElecState before init_basis (for Psi 2d division)
70+
// 2) autoset nbands in ElecState before init_basis (for Psi 2d division)
10171
if (this->pelec == nullptr)
10272
{
10373
// TK stands for double and std::complex<double>?
10474
this->pelec = new elecstate::ElecStateLCAO<TK>(&(this->chr), &(this->kv),
10575
this->kv.get_nks(), &(this->GG), &(this->GK), this->pw_rho, this->pw_big);
10676
}
10777

108-
// 3) read the LCAO orbitals/projectors and construct the interpolation tables.
78+
// 3) read LCAO orbitals/projectors and construct the interpolation tables.
10979
LCAO_domain::init_basis_lcao(this->pv, inp.onsite_radius, inp.lcao_ecut,
11080
inp.lcao_dk, inp.lcao_dr, inp.lcao_rmax, ucell, two_center_bundle_, orb_);
11181

11282
// 4) setup EXX calculations
11383
if (PARAM.inp.calculation == "gen_opt_abfs")
11484
{
115-
#ifdef __EXX
85+
#ifdef __EXX
11686
Exx_Opt_Orb exx_opt_orb;
11787
exx_opt_orb.generate_matrix(GlobalC::exx_info.info_opt_abfs, this->kv, ucell, this->orb_);
118-
#else
88+
#else
11989
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::before_all_runners", "calculation=gen_opt_abfs must compile __EXX");
120-
#endif
90+
#endif
12191
return;
12292
}
12393

124-
// 5) initialize electronic wave function psi
94+
// 5) init electronic wave function psi
12595
if (this->psi == nullptr)
12696
{
12797
int nsk = 0;
@@ -160,11 +130,10 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
160130
}
161131
}
162132

163-
// 7) initialize the density matrix
164-
// DMK are allocated here, but DMR is constructed in before_scf()
133+
// 7) init DMK, but DMR is constructed in before_scf()
165134
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)->init_DM(&this->kv, &(this->pv), inp.nspin);
166135

167-
// 8) initialize exact exchange calculations
136+
// 8) init exact exchange calculations
168137
#ifdef __EXX
169138
if (inp.calculation == "scf" || inp.calculation == "relax" || inp.calculation == "cell-relax"
170139
|| inp.calculation == "md")
@@ -198,23 +167,23 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
198167
dftu->init(ucell, &this->pv, this->kv.get_nks(), &orb_);
199168
}
200169

201-
// 10) initialize local pseudopotentials
170+
// 10) init local pseudopotentials
202171
this->locpp.init_vloc(ucell, this->pw_rho);
203172
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
204173

205-
// 11) inititlize the charge density
174+
// 11) init charge density
206175
this->chr.allocate(inp.nspin);
207176
this->pelec->omega = ucell.omega;
208177

209-
// 12) initialize the potential
178+
// 12) init potentials
210179
if (this->pelec->pot == nullptr)
211180
{
212181
this->pelec->pot = new elecstate::Potential(this->pw_rhod, this->pw_rho,
213182
&ucell, &(this->locpp.vloc), &(this->sf), &(this->solvent),
214183
&(this->pelec->f_en.etxc), &(this->pelec->f_en.vtxc));
215184
}
216185

217-
// 13) initialize deepks
186+
// 13) init deepks
218187
#ifdef __MLALGO
219188
LCAO_domain::DeePKS_init(ucell, pv, this->kv.get_nks(), orb_, this->ld, GlobalV::ofs_running);
220189
if (inp.deepks_scf)
@@ -228,8 +197,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
228197
}
229198
#endif
230199

231-
// 14) set occupations
232-
// tddft does not need to set occupations in the first scf
200+
// 14) set occupations, tddft does not need to set occupations in the first scf
233201
if (inp.ocp && inp.esolver_type != "tddft")
234202
{
235203
elecstate::fixed_weights(inp.ocp_kb, inp.nbands, inp.nelec,
@@ -257,7 +225,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
257225
}
258226
}
259227

260-
// 16) initialize rdmft, added by jghan
228+
// 16) init rdmft, added by jghan
261229
if (inp.rdmft == true)
262230
{
263231
rdmft_solver.init(this->GG, this->GK, this->pv, ucell,

0 commit comments

Comments
 (0)