Skip to content

Commit dfa213a

Browse files
committed
Refactor: merge before_all_runners of tddft and lcao
1 parent da1baf5 commit dfa213a

File tree

4 files changed

+29
-61
lines changed

4 files changed

+29
-61
lines changed

source/module_elecstate/elecstate_lcao_tddft.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace elecstate
1212
// multi-k case
1313
void ElecStateLCAO_TDDFT::psiToRho_td(const psi::Psi<std::complex<double>>& psi)
1414
{
15-
ModuleBase::TITLE("ElecStateLCAO", "psiToRho");
16-
ModuleBase::timer::tick("ElecStateLCAO", "psiToRho");
15+
ModuleBase::TITLE("ElecStateLCAO_TDDFT", "psiToRho_td");
16+
ModuleBase::timer::tick("ElecStateLCAO_TDDFT", "psiToRho_td");
1717

1818
this->calculate_weights_td();
1919
this->calEBand();
@@ -41,7 +41,7 @@ void ElecStateLCAO_TDDFT::psiToRho_td(const psi::Psi<std::complex<double>>& psi)
4141

4242
this->charge->renormalize_rho();
4343

44-
ModuleBase::timer::tick("ElecStateLCAO", "psiToRho");
44+
ModuleBase::timer::tick("ElecStateLCAO_TDDFT", "psiToRho_td");
4545
return;
4646
}
4747

source/module_esolver/esolver_gets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ESolver_GetS : public ESolver_KS<TK>
4848

4949
TwoCenterBundle two_center_bundle_;
5050

51-
// // temporary introduced during removing GlobalC::ORB
51+
// temporary introduced during removing GlobalC::ORB
5252
LCAO_Orbitals orb_;
5353
};
5454
} // namespace ModuleESolver

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
//-----HSolver ElecState Hamilt--------
5858
#include "module_elecstate/elecstate_lcao.h"
59+
#include "module_elecstate/elecstate_lcao_tddft.h"
5960
#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h"
6061
#include "module_hsolver/hsolver_lcao.h"
6162
// function used by deepks
@@ -128,14 +129,26 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
128129
// autoset nbands in ElecState, it should before basis_init (for Psi 2d division)
129130
if (this->pelec == nullptr)
130131
{
131-
// TK stands for double and complex<double>?
132-
this->pelec = new elecstate::ElecStateLCAO<TK>(&(this->chr), // use which parameter?
133-
&(this->kv),
134-
this->kv.get_nks(),
135-
&(this->GG), // mohan add 2024-04-01
136-
&(this->GK), // mohan add 2024-04-01
137-
this->pw_rho,
138-
this->pw_big);
132+
if (inp.esolver_type == "tddft")
133+
{
134+
this->pelec = new elecstate::ElecStateLCAO_TDDFT(&(this->chr),
135+
&(this->kv),
136+
this->kv.get_nks(),
137+
&(this->GK), // mohan add 2024-04-01
138+
this->pw_rho,
139+
this->pw_big);
140+
}
141+
else
142+
{
143+
// TK stands for double and complex<double>?
144+
this->pelec = new elecstate::ElecStateLCAO<TK>(&(this->chr), // use which parameter?
145+
&(this->kv),
146+
this->kv.get_nks(),
147+
&(this->GG), // mohan add 2024-04-01
148+
&(this->GK), // mohan add 2024-04-01
149+
this->pw_rho,
150+
this->pw_big);
151+
}
139152
}
140153

141154
// 3) init LCAO basis
@@ -222,7 +235,8 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
222235
#endif
223236

224237
// 12) set occupations
225-
if (PARAM.inp.ocp)
238+
// tddft does not need to set occupations in the first scf
239+
if (PARAM.inp.ocp && inp.esolver_type != "tddft")
226240
{
227241
this->pelec->fixed_weights(PARAM.inp.ocp_kb, PARAM.inp.nbands, PARAM.inp.nelec);
228242
}

source/module_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -66,54 +66,8 @@ ESolver_KS_LCAO_TDDFT::~ESolver_KS_LCAO_TDDFT()
6666

6767
void ESolver_KS_LCAO_TDDFT::before_all_runners(const Input_para& inp, UnitCell& ucell)
6868
{
69-
// 1) run "before_all_runners" in ESolver_KS
70-
ESolver_KS::before_all_runners(inp, ucell);
71-
72-
// 2) initialize the local pseudopotential with plane wave basis set
73-
GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, pw_rho);
74-
75-
// 3) initialize the electronic states for TDDFT
76-
if (this->pelec == nullptr)
77-
{
78-
this->pelec = new elecstate::ElecStateLCAO_TDDFT(&this->chr,
79-
&kv,
80-
kv.get_nks(),
81-
&this->GK, // mohan add 2024-04-01
82-
this->pw_rho,
83-
pw_big);
84-
}
85-
86-
// 4) read the local orbitals and construct the interpolation tables.
87-
// initialize the pv
88-
LCAO_domain::init_basis_lcao(this->pv,
89-
inp.onsite_radius,
90-
inp.lcao_ecut,
91-
inp.lcao_dk,
92-
inp.lcao_dr,
93-
inp.lcao_rmax,
94-
ucell,
95-
two_center_bundle_,
96-
orb_);
97-
98-
// 5) allocate H and S matrices according to computational resources
99-
LCAO_domain::divide_HS_in_frag(PARAM.globalv.gamma_only_local, this->pv, kv.get_nks(), orb_);
100-
101-
// 6) initialize Density Matrix
102-
dynamic_cast<elecstate::ElecStateLCAO<std::complex<double>>*>(this->pelec)
103-
->init_DM(&kv, &this->pv, PARAM.inp.nspin);
104-
105-
// 8) initialize the charge density
106-
this->pelec->charge->allocate(PARAM.inp.nspin);
107-
this->pelec->omega = GlobalC::ucell.omega; // this line is very odd.
108-
109-
// 9) initializee the potential
110-
this->pelec->pot = new elecstate::Potential(pw_rhod,
111-
pw_rho,
112-
&GlobalC::ucell,
113-
&(GlobalC::ppcell.vloc),
114-
&(sf),
115-
&(pelec->f_en.etxc),
116-
&(pelec->f_en.vtxc));
69+
// 1) run before_all_runners in ESolver_KS_LCAO
70+
ESolver_KS_LCAO<std::complex<double>, double>::before_all_runners(inp, ucell);
11771

11872
// this line should be optimized
11973
this->pelec_td = dynamic_cast<elecstate::ElecStateLCAO_TDDFT*>(this->pelec);

0 commit comments

Comments
 (0)