Skip to content

Commit 8b98a20

Browse files
authored
Refactor: merge before_all_runners of tddft and lcao (#5531)
* Refactor: merge before_all_runners of tddft and lcao * Refactor: remove elecstate_lcao_tddft
1 parent 8040017 commit 8b98a20

File tree

8 files changed

+36
-181
lines changed

8 files changed

+36
-181
lines changed

source/Makefile.Objects

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ OBJS_ELECSTAT=elecstate.o\
228228
pot_xc.o\
229229

230230
OBJS_ELECSTAT_LCAO=elecstate_lcao.o\
231-
elecstate_lcao_tddft.o\
232231
elecstate_lcao_cal_tau.o\
233232
density_matrix.o\
234233
density_matrix_io.o\

source/module_elecstate/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ list(APPEND objects
3636
if(ENABLE_LCAO)
3737
list(APPEND objects
3838
elecstate_lcao.cpp
39-
elecstate_lcao_tddft.cpp
4039
elecstate_lcao_cal_tau.cpp
4140
potentials/H_TDDFT_pw.cpp
4241
module_dm/density_matrix.cpp

source/module_elecstate/elecstate_lcao_tddft.cpp

Lines changed: 0 additions & 84 deletions
This file was deleted.

source/module_elecstate/elecstate_lcao_tddft.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
222222
#endif
223223

224224
// 12) set occupations
225-
if (PARAM.inp.ocp)
225+
// tddft does not need to set occupations in the first scf
226+
if (PARAM.inp.ocp && inp.esolver_type != "tddft")
226227
{
227228
this->pelec->fixed_weights(PARAM.inp.ocp_kb, PARAM.inp.nbands, PARAM.inp.nelec);
228229
}

source/module_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include "module_base/lapack_connector.h"
1414
#include "module_base/scalapack_connector.h"
1515
#include "module_elecstate/module_charge/symmetry_rho.h"
16+
#include "module_elecstate/module_dm/cal_dm_psi.h"
1617
#include "module_elecstate/module_dm/cal_edm_tddft.h"
18+
#include "module_elecstate/module_dm/density_matrix.h"
1719
#include "module_elecstate/occupy.h"
1820
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h" // need divide_HS_in_frag
1921
#include "module_hamilt_lcao/module_tddft/evolve_elec.h"
@@ -23,7 +25,6 @@
2325

2426
//-----HSolver ElecState Hamilt--------
2527
#include "module_elecstate/elecstate_lcao.h"
26-
#include "module_elecstate/elecstate_lcao_tddft.h"
2728
#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h"
2829
#include "module_hsolver/hsolver_lcao.h"
2930
#include "module_parameter/parameter.h"
@@ -66,57 +67,11 @@ ESolver_KS_LCAO_TDDFT::~ESolver_KS_LCAO_TDDFT()
6667

6768
void ESolver_KS_LCAO_TDDFT::before_all_runners(const Input_para& inp, UnitCell& ucell)
6869
{
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));
70+
// 1) run before_all_runners in ESolver_KS_LCAO
71+
ESolver_KS_LCAO<std::complex<double>, double>::before_all_runners(inp, ucell);
11772

11873
// this line should be optimized
119-
this->pelec_td = dynamic_cast<elecstate::ElecStateLCAO_TDDFT*>(this->pelec);
74+
// this->pelec = dynamic_cast<elecstate::ElecStateLCAO_TDDFT*>(this->pelec);
12075
}
12176

12277
void ESolver_KS_LCAO_TDDFT::hamilt2density_single(const int istep, const int iter, const double ethr)
@@ -134,13 +89,13 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density_single(const int istep, const int ite
13489
this->psi_laststep,
13590
this->Hk_laststep,
13691
this->Sk_laststep,
137-
this->pelec_td->ekb,
92+
this->pelec->ekb,
13893
td_htype,
13994
PARAM.inp.propagator,
14095
kv.get_nks());
141-
this->pelec_td->psiToRho_td(this->psi[0]);
96+
this->weight_dm_rho();
14297
}
143-
this->pelec_td->psiToRho_td(this->psi[0]);
98+
this->weight_dm_rho();
14499
}
145100
else if (istep >= 2)
146101
{
@@ -153,11 +108,11 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density_single(const int istep, const int ite
153108
this->psi_laststep,
154109
this->Hk_laststep,
155110
this->Sk_laststep,
156-
this->pelec_td->ekb,
111+
this->pelec->ekb,
157112
td_htype,
158113
PARAM.inp.propagator,
159114
kv.get_nks());
160-
this->pelec_td->psiToRho_td(this->psi[0]);
115+
this->weight_dm_rho();
161116
}
162117
else
163118
{
@@ -168,7 +123,7 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density_single(const int istep, const int ite
168123
{
169124
bool skip_charge = PARAM.inp.calculation == "nscf" ? true : false;
170125
hsolver::HSolverLCAO<std::complex<double>> hsolver_lcao_obj(&this->pv, PARAM.inp.ks_solver);
171-
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec_td, skip_charge);
126+
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec, skip_charge);
172127
}
173128
}
174129

@@ -203,8 +158,7 @@ void ESolver_KS_LCAO_TDDFT::iter_finish(const int istep, int& iter)
203158
for (int ib = 0; ib < PARAM.inp.nbands; ib++)
204159
{
205160
std::setprecision(6);
206-
GlobalV::ofs_running << ik + 1 << " " << ib + 1 << " " << this->pelec_td->wg(ik, ib)
207-
<< std::endl;
161+
GlobalV::ofs_running << ik + 1 << " " << ib + 1 << " " << this->pelec->wg(ik, ib) << std::endl;
208162
}
209163
}
210164
GlobalV::ofs_running << std::endl;
@@ -379,7 +333,7 @@ void ESolver_KS_LCAO_TDDFT::update_pot(const int istep, const int iter)
379333
for (int ib = 0; ib < PARAM.inp.nbands; ib++)
380334
{
381335
GlobalV::ofs_running << ik + 1 << " " << ib + 1 << " "
382-
<< this->pelec_td->ekb(ik, ib) * ModuleBase::Ry_to_eV << std::endl;
336+
<< this->pelec->ekb(ik, ib) * ModuleBase::Ry_to_eV << std::endl;
383337
}
384338
}
385339
GlobalV::ofs_running << std::endl;
@@ -417,4 +371,21 @@ void ESolver_KS_LCAO_TDDFT::after_scf(const int istep)
417371
ESolver_KS_LCAO<std::complex<double>, double>::after_scf(istep);
418372
}
419373

374+
void ESolver_KS_LCAO_TDDFT::weight_dm_rho()
375+
{
376+
if (PARAM.inp.ocp == 1)
377+
{
378+
this->pelec->fixed_weights(PARAM.inp.ocp_kb, PARAM.inp.nbands, PARAM.inp.nelec);
379+
}
380+
this->pelec->calEBand();
381+
382+
ModuleBase::GlobalFunc::NOTE("Calculate the density matrix.");
383+
384+
auto _pes = dynamic_cast<elecstate::ElecStateLCAO<std::complex<double>>*>(this->pelec);
385+
elecstate::cal_dm_psi(_pes->DM->get_paraV_pointer(), _pes->wg, this->psi[0], *(_pes->DM));
386+
_pes->DM->cal_DMR();
387+
388+
this->pelec->psiToRho(this->psi[0]);
389+
}
390+
420391
} // namespace ModuleESolver

source/module_esolver/esolver_ks_lcao_tddft.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define ESOLVER_KS_LCAO_TDDFT_H
33
#include "esolver_ks.h"
44
#include "esolver_ks_lcao.h"
5-
#include "module_elecstate/elecstate_lcao_tddft.h"
65
#include "module_hamilt_lcao/hamilt_lcaodft/record_adj.h"
76
#include "module_psi/psi.h"
87

@@ -36,10 +35,10 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO<std::complex<double>, doubl
3635
//! Overlap matrix of last time step
3736
std::complex<double>** Sk_laststep = nullptr;
3837

39-
//! Electronic states of rt-TDDFT
40-
elecstate::ElecStateLCAO_TDDFT* pelec_td = nullptr;
41-
4238
int td_htype = 1;
39+
40+
private:
41+
void weight_dm_rho();
4342
};
4443

4544
} // namespace ModuleESolver

0 commit comments

Comments
 (0)