Skip to content

Commit accd6da

Browse files
committed
remove some codes in esolver_ks_lcao and add LCAO_set.cpp
1 parent c3eb4e6 commit accd6da

File tree

2 files changed

+73
-54
lines changed

2 files changed

+73
-54
lines changed

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -74,62 +74,14 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
7474
return;
7575
}
7676

77-
// 5) init electronic wave function psi
78-
Setup_Psi<TK>::allocate_psi(this->psi, this->kv, this->pv, inp);
77+
LCAO_domain::set_psi_occ_dm_chg();
7978

80-
//! read psi from file
81-
if (inp.init_wfc == "file" && inp.esolver_type != "tddft")
82-
{
83-
if (!ModuleIO::read_wfc_nao(PARAM.globalv.global_readin_dir,
84-
this->pv, *this->psi, this->pelec->ekb, this->pelec->wg, this->kv.ik2iktot,
85-
this->kv.get_nkstot(), inp.nspin))
86-
{
87-
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "read electronic wave functions failed");
88-
}
89-
}
90-
91-
92-
// 7) init DMK, but DMR is constructed in before_scf()
93-
this->dmat.allocate_dm(&this->kv, &this->pv, inp.nspin);
94-
95-
// 8) init exact exchange calculations
96-
this->exx_nao.before_runner(ucell, this->kv, this->orb_, this->pv, inp);
97-
98-
// 9) initialize DFT+U
99-
if (inp.dft_plus_u)
100-
{
101-
this->dftu.init(ucell, &this->pv, this->kv.get_nks(), &orb_);
102-
}
79+
LCAO_domain::set_pot();
10380

104-
// 10) init local pseudopotentials
105-
this->locpp.init_vloc(ucell, this->pw_rho);
106-
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
107-
108-
// 11) init charge density
109-
this->chr.allocate(inp.nspin);
110-
111-
// 12) init potentials
112-
if (this->pelec->pot == nullptr)
113-
{
114-
this->pelec->pot = new elecstate::Potential(this->pw_rhod, this->pw_rho,
115-
&ucell, &(this->locpp.vloc), &(this->sf), &(this->solvent),
116-
&(this->pelec->f_en.etxc), &(this->pelec->f_en.vtxc));
117-
}
118-
119-
// 13) init deepks
120-
this->deepks.before_runner(ucell, this->kv.get_nks(), this->orb_, this->pv, inp);
121-
122-
// 14) set occupations, tddft does not need to set occupations in the first scf
123-
if (inp.ocp && inp.esolver_type != "tddft")
124-
{
125-
elecstate::fixed_weights(inp.ocp_kb, inp.nbands, inp.nelec,
126-
this->pelec->klist, this->pelec->wg, this->pelec->skip_weights);
127-
}
128-
129-
// 15) if kpar is not divisible by nks, print a warning
81+
//! if kpar is not divisible by nks, print a warning
13082
ModuleIO::print_kpar(this->kv.get_nks(), PARAM.globalv.kpar_lcao);
13183

132-
// 16) init rdmft, added by jghan
84+
//! init rdmft, added by jghan
13385
if (inp.rdmft == true)
13486
{
13587
rdmft_solver.init(this->pv, ucell,
@@ -310,8 +262,6 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
310262

311263
ESolver_KS<TK>::after_all_runners(ucell);
312264

313-
const int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1;
314-
315265
auto* hamilt_lcao = dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(this->p_hamilt);
316266
if(!hamilt_lcao)
317267
{

source/source_lcao/LCAO_set.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include "source_lcao/LCAO_set_pot.h"
2+
#include "source_io/module_parameter/parameter.h"
3+
4+
namespace LCAO_domain
5+
{
6+
7+
void set_psi_occ_dm_chg(psi, kv, pv, inp, pelec, dmat, chr)
8+
{
9+
//! 1) init electronic wave function psi
10+
Setup_Psi<TK>::allocate_psi(psi, kv, pv, inp);
11+
12+
//! 2) read psi from file
13+
if (inp.init_wfc == "file" && inp.esolver_type != "tddft")
14+
{
15+
if (!ModuleIO::read_wfc_nao(PARAM.globalv.global_readin_dir,
16+
pv, *psi, pelec->ekb, pelec->wg, kv.ik2iktot,
17+
kv.get_nkstot(), inp.nspin))
18+
{
19+
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "read electronic wave functions failed");
20+
}
21+
}
22+
23+
// 3) set occupations, tddft does not need to set occupations in the first scf
24+
if (inp.ocp && inp.esolver_type != "tddft")
25+
{
26+
elecstate::fixed_weights(inp.ocp_kb, inp.nbands, inp.nelec,
27+
pelec->klist, pelec->wg, pelec->skip_weights);
28+
}
29+
30+
// 4) init DMK, but DMR is constructed in before_scf()
31+
dmat.allocate_dm(&kv, &pv, inp.nspin);
32+
33+
// 5) init charge density
34+
chr.allocate(inp.nspin);
35+
}
36+
37+
38+
void set_pot(pelec, locpp, pw_rho, pw_rhod, sf, solvent, dftu, pv, kv, orb_, exx_nao, deepks)
39+
{
40+
// 1) init local pseudopotentials
41+
locpp.init_vloc(ucell, pw_rho);
42+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
43+
44+
// 2) init potentials
45+
if (pelec->pot == nullptr)
46+
{
47+
// where is the pot deleted?
48+
pelec->pot = new elecstate::Potential(pw_rhod, pw_rho,
49+
&ucell, &(locpp.vloc), &(sf), &(solvent),
50+
&(pelec->f_en.etxc), &(pelec->f_en.vtxc));
51+
}
52+
53+
// 3) initialize DFT+U
54+
if (inp.dft_plus_u)
55+
{
56+
dftu.init(ucell, &pv, kv.get_nks(), &orb_);
57+
}
58+
59+
// 4) init exact exchange calculations
60+
exx_nao.before_runner(ucell, kv, orb_, pv, inp);
61+
62+
// 5) init deepks
63+
deepks.before_runner(ucell, kv.get_nks(), orb_, pv, inp);
64+
65+
return;
66+
}
67+
68+
69+
}

0 commit comments

Comments
 (0)