@@ -107,7 +107,7 @@ void LR::ESolver_LR<T, TR>::set_dimension()
107107 this ->nbasis = PARAM .globalv .nlocal ;
108108 // calculate the number of occupied and unoccupied states
109109 // which determines the basis size of the excited states
110- this ->nocc_max = LR_Util::cal_nocc (LR_Util::cal_nelec (ucell ));
110+ this ->nocc_max = LR_Util::cal_nocc (LR_Util::cal_nelec (* this -> ucell_ ));
111111 this ->nocc_in = std::max (1 , std::min (input.nocc , this ->nocc_max ));
112112 this ->nvirt_in = PARAM .inp .nbands - this ->nocc_max ; // nbands-nocc
113113 if (input.nvirt > this ->nvirt_in ) { GlobalV::ofs_warning << " ESolver_LR: input nvirt is too large to cover by nbands, set nvirt = nbands - nocc = " << this ->nvirt_in << std::endl; }
@@ -128,7 +128,7 @@ void LR::ESolver_LR<T, TR>::set_dimension()
128128 // calculate total number of basis funcs, see https://en.cppreference.com/w/cpp/algorithm/inner_product
129129 this ->nbasis = std::inner_product (input.aims_nbasis .begin (), /* iterator1.begin */
130130 input.aims_nbasis .end (), /* iterator1.end */
131- ucell. atoms , /* iterator2.begin */
131+ this -> ucell_ -> atoms , /* iterator2.begin */
132132 0 , /* init value */
133133 std::plus<int >(), /* iter op1 */
134134 [](const int & a, const Atom& b) { return a * b.na ; }); /* iter op2 */
@@ -173,12 +173,35 @@ void LR::ESolver_LR<T, TR>::reset_dim_spin2()
173173}
174174
175175template <typename T, typename TR >
176- LR ::ESolver_LR<T, TR >::ESolver_LR(ModuleESolver::ESolver_KS_LCAO<T, TR >&& ks_sol,
177- const Input_para& inp, UnitCell& ucell)
178- : input(inp), ucell(ucell)
176+ LR ::ESolver_LR<T, TR >::ESolver_LR(const Input_para& inp)
177+ : input(inp)
179178#ifdef __EXX
180179 , exx_info(GlobalC::exx_info)
181180#endif
181+ {
182+ }
183+
184+ template <typename T, typename TR >
185+ void LR ::ESolver_LR<T, TR >::before_all_runners(UnitCell& ucell, const Input_para& inp)
186+ {
187+ this ->ucell_ = &ucell;
188+ if (inp.esolver_type == " ks-lr" )
189+ {
190+ ModuleESolver::ESolver_KS_LCAO<T, TR > ks_solver;
191+ ks_solver.before_all_runners (ucell, inp);
192+ ks_solver.runner (ucell, 0 );
193+ this ->initialize_from_ks_ (std::move (ks_solver), ucell, inp);
194+ }
195+ else
196+ {
197+ this ->initialize_from_unitcell_ (ucell, inp);
198+ }
199+ }
200+
201+ template <typename T, typename TR >
202+ void LR ::ESolver_LR<T, TR >::initialize_from_ks_(ModuleESolver::ESolver_KS_LCAO<T, TR >&& ks_sol,
203+ UnitCell& ucell,
204+ const Input_para& inp)
182205{
183206 ModuleBase::TITLE (" ESolver_LR" , " ESolver_LR(KS)" );
184207
@@ -289,10 +312,7 @@ LR::ESolver_LR<T, TR>::ESolver_LR(ModuleESolver::ESolver_KS_LCAO<T, TR>&& ks_sol
289312}
290313
291314template <typename T, typename TR >
292- LR ::ESolver_LR<T, TR >::ESolver_LR(const Input_para& inp, UnitCell& ucell) : input(inp), ucell(ucell)
293- #ifdef __EXX
294- , exx_info(GlobalC::exx_info)
295- #endif
315+ void LR ::ESolver_LR<T, TR >::initialize_from_unitcell_(UnitCell& ucell, const Input_para& inp)
296316{
297317 ModuleBase::TITLE (" ESolver_LR" , " ESolver_LR(from scratch)" );
298318 // xc kernel
@@ -392,7 +412,7 @@ LR::ESolver_LR<T, TR>::ESolver_LR(const Input_para& inp, UnitCell& ucell) : inpu
392412 atom_arrange::search (PARAM .globalv .search_pbc ,
393413 GlobalV::ofs_running,
394414 this ->gd ,
395- this ->ucell ,
415+ * this ->ucell_ ,
396416 search_radius,
397417 PARAM .inp .test_atom_input );
398418 gint_info_.reset (
@@ -463,7 +483,7 @@ void LR::ESolver_LR<T, TR>::runner(UnitCell& ucell, const int istep)
463483 this ->nbasis ,
464484 this ->nocc ,
465485 this ->nvirt ,
466- this ->ucell ,
486+ * this ->ucell_ ,
467487 orb_cutoff_,
468488 this ->gd ,
469489 *this ->psi_ks ,
@@ -493,7 +513,7 @@ void LR::ESolver_LR<T, TR>::runner(UnitCell& ucell, const int istep)
493513 this ->nbasis ,
494514 this ->nocc ,
495515 this ->nvirt ,
496- this ->ucell ,
516+ * this ->ucell_ ,
497517 orb_cutoff_,
498518 this ->gd ,
499519 *this ->psi_ks ,
@@ -559,7 +579,7 @@ void LR::ESolver_LR<T, TR>::after_all_runners(UnitCell& ucell)
559579 for (int is = 0 ;is < this ->X .size ();++is)
560580 {
561581 LR_Spectrum<T> spectrum (nspin, this ->nbasis , this ->nocc , this ->nvirt , *this ->pw_rho , *this ->psi_ks ,
562- this ->ucell , this ->kv , this ->gd , this ->orb_cutoff_ , this ->two_center_bundle_ ,
582+ * this ->ucell_ , this ->kv , this ->gd , this ->orb_cutoff_ , this ->two_center_bundle_ ,
563583 this ->paraX_ , this ->paraC_ , this ->paraMat_ ,
564584 &this ->pelec ->ekb .c [is * nstates], this ->X [is].template data <T>(), nstates, openshell,
565585 LR_Util::tolower (input.abs_gauge ));
@@ -656,11 +676,11 @@ void LR::ESolver_LR<T, TR>::init_pot(const Charge& chg_gs)
656676 {
657677 using ST = PotHxcLR::SpinType;
658678 case 1 :
659- this ->pot [0 ] = std::make_shared<PotHxcLR>(xc_kernel, *this ->pw_rho , ucell , chg_gs, Pgrid, ST ::S1 , input.lr_init_xc_kernel );
679+ this ->pot [0 ] = std::make_shared<PotHxcLR>(xc_kernel, *this ->pw_rho , * this -> ucell_ , chg_gs, Pgrid, ST ::S1 , input.lr_init_xc_kernel );
660680 break ;
661681 case 2 :
662- this ->pot [0 ] = std::make_shared<PotHxcLR>(xc_kernel, *this ->pw_rho , ucell , chg_gs, Pgrid, openshell ? ST ::S2_updown : ST ::S2_singlet, input.lr_init_xc_kernel );
663- this ->pot [1 ] = std::make_shared<PotHxcLR>(xc_kernel, *this ->pw_rho , ucell , chg_gs, Pgrid, openshell ? ST ::S2_updown : ST ::S2_triplet, input.lr_init_xc_kernel );
682+ this ->pot [0 ] = std::make_shared<PotHxcLR>(xc_kernel, *this ->pw_rho , * this -> ucell_ , chg_gs, Pgrid, openshell ? ST ::S2_updown : ST ::S2_singlet, input.lr_init_xc_kernel );
683+ this ->pot [1 ] = std::make_shared<PotHxcLR>(xc_kernel, *this ->pw_rho , * this -> ucell_ , chg_gs, Pgrid, openshell ? ST ::S2_updown : ST ::S2_triplet, input.lr_init_xc_kernel );
664684 break ;
665685 default :
666686 throw std::invalid_argument (" ESolver_LR: nspin must be 1 or 2" );
@@ -717,7 +737,7 @@ void LR::ESolver_LR<T, TR>::read_ks_chg(Charge& chg_gs)
717737 GlobalV::ofs_running,
718738 ssc.str (),
719739 chg_gs.rho [is],
720- ucell. nat )) {
740+ this -> ucell_ -> nat )) {
721741 GlobalV::ofs_running << " Read in the charge density: " << ssc.str () << std::endl;
722742 } else { // prenspin for nspin=4 is not supported currently
723743 ModuleBase::WARNING_QUIT (
0 commit comments