22
33#include " module_base/formatter.h"
44#include " module_base/global_variable.h"
5+ #include " module_base/kernels/math_kernel_op.h"
56#include " module_base/memory.h"
67#include " module_elecstate/cal_ux.h"
78#include " module_elecstate/elecstate_pw.h"
@@ -99,7 +100,7 @@ ESolver_KS_PW<T, Device>::~ESolver_KS_PW()
99100 std::cout << " ** Closing DSP Hardware..." << std::endl;
100101 mtfunc::dspDestoryHandle (GlobalV::MY_RANK);
101102#endif
102- if (PARAM.inp .device == " gpu" || PARAM.inp .precision == " single" )
103+ if (PARAM.inp .device == " gpu" || PARAM.inp .precision == " single" )
103104 {
104105 delete this ->kspw_psi ;
105106 }
@@ -181,7 +182,6 @@ void ESolver_KS_PW<T, Device>::before_all_runners(UnitCell& ucell, const Input_p
181182 &(this ->pelec ->f_en .vtxc ));
182183 }
183184
184-
185185 // ! initalize local pseudopotential
186186 this ->locpp .init_vloc (ucell, this ->pw_rhod );
187187 ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " LOCAL POTENTIAL" );
@@ -243,16 +243,6 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)
243243
244244 this ->p_psi_init ->prepare_init (PARAM.inp .pw_seed );
245245 }
246- if (ucell.ionic_position_updated )
247- {
248- this ->CE .update_all_dis (ucell);
249- this ->CE .extrapolate_charge (&this ->Pgrid ,
250- ucell,
251- this ->pelec ->charge ,
252- &this ->sf ,
253- GlobalV::ofs_running,
254- GlobalV::ofs_warning);
255- }
256246
257247 // init Hamilt, this should be allocated before each scf loop
258248 // Operators in HamiltPW should be reallocated once cell changed
@@ -262,77 +252,12 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)
262252 // allocate HamiltPW
263253 this ->allocate_hamilt (ucell);
264254
265- // ----------------------------------------------------------
266- // about vdw, jiyy add vdwd3 and linpz add vdwd2
267- // ----------------------------------------------------------
268- auto vdw_solver = vdw::make_vdw (ucell, PARAM.inp , &(GlobalV::ofs_running));
269- if (vdw_solver != nullptr )
270- {
271- this ->pelec ->f_en .evdw = vdw_solver->get_energy ();
272- }
273-
274- // ----------------------------------------------------------
275- // calculate ewald energy
276- // ----------------------------------------------------------
277- if (!PARAM.inp .test_skip_ewald )
278- {
279- this ->pelec ->f_en .ewald_energy = H_Ewald_pw::compute_ewald (ucell, this ->pw_rhod , this ->sf .strucFac );
280- }
281-
282- // ----------------------------------------------------------
283- // ! cal_ux should be called before init_scf because
284- // ! the direction of ux is used in noncoline_rho
285- // ----------------------------------------------------------
286- elecstate::cal_ux (ucell);
287-
288255 // ----------------------------------------------------------
289256 // ! calculate the total local pseudopotential in real space
290257 // ----------------------------------------------------------
291258 this ->pelec
292259 ->init_scf (istep, ucell, this ->Pgrid , this ->sf .strucFac , this ->locpp .numeric , ucell.symm , (void *)this ->pw_wfc );
293260
294- // ----------------------------------------------------------
295- // ! output the initial charge density
296- // ----------------------------------------------------------
297- if (PARAM.inp .out_chg [0 ] == 2 )
298- {
299- for (int is = 0 ; is < PARAM.inp .nspin ; is++)
300- {
301- std::stringstream ss;
302- ss << PARAM.globalv .global_out_dir << " SPIN" << is + 1 << " _CHG_INI.cube" ;
303- ModuleIO::write_vdata_palgrid (this ->Pgrid ,
304- this ->pelec ->charge ->rho [is],
305- is,
306- PARAM.inp .nspin ,
307- istep,
308- ss.str (),
309- this ->pelec ->eferm .ef ,
310- &(ucell));
311- }
312- }
313-
314- // ----------------------------------------------------------
315- // ! output total local potential of the initial charge density
316- // ----------------------------------------------------------
317- if (PARAM.inp .out_pot == 3 )
318- {
319- for (int is = 0 ; is < PARAM.inp .nspin ; is++)
320- {
321- std::stringstream ss;
322- ss << PARAM.globalv .global_out_dir << " SPIN" << is + 1 << " _POT_INI.cube" ;
323- ModuleIO::write_vdata_palgrid (this ->Pgrid ,
324- this ->pelec ->pot ->get_effective_v (is),
325- is,
326- PARAM.inp .nspin ,
327- istep,
328- ss.str (),
329- 0.0 , // efermi
330- &(ucell),
331- 11 , // precsion
332- 0 ); // out_fermi
333- }
334- }
335-
336261 // ----------------------------------------------------------
337262 // ! Symmetry_rho should behind init_scf, because charge should be
338263 // ! initialized first. liuyu comment: Symmetry_rho should be located between
@@ -583,7 +508,7 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
583508
584509 // 2) Update USPP-related quantities
585510 // D in USPP needs vloc, thus needs update when veff updated
586- // calculate the effective coefficient matrix for non-local pp projectors
511+ // calculate the effective coefficient matrix for non-local pp projectors
587512 // liuyu 2023-10-24
588513 if (PARAM.globalv .use_uspp )
589514 {
@@ -594,9 +519,7 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
594519 // 3) Print out electronic wavefunctions in pw basis
595520 if (PARAM.inp .out_wfc_pw == 1 || PARAM.inp .out_wfc_pw == 2 )
596521 {
597- if (iter % PARAM.inp .out_freq_elec == 0 ||
598- iter == PARAM.inp .scf_nmax ||
599- conv_esolver)
522+ if (iter % PARAM.inp .out_freq_elec == 0 || iter == PARAM.inp .scf_nmax || conv_esolver)
600523 {
601524 std::stringstream ssw;
602525 ssw << PARAM.globalv .global_out_dir << " WAVEFUNC" ;
@@ -931,35 +854,35 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
931854
932855#ifdef __MLKEDF
933856 // generate training data for ML-KEDF
934- if (PARAM.inp .of_ml_gene_data == 1 )
857+ if (PARAM.inp .of_ml_gene_data == 1 )
935858 {
936859 this ->pelec ->pot ->update_from_charge (this ->pelec ->charge , &ucell);
937860
938- ML_data ml_data;
939- ml_data.set_para (this ->pelec ->charge ->nrxx ,
940- PARAM.inp .nelec ,
941- PARAM.inp .of_tf_weight ,
942- PARAM.inp .of_vw_weight ,
943- PARAM.inp .of_ml_chi_p ,
944- PARAM.inp .of_ml_chi_q ,
945- PARAM.inp .of_ml_chi_xi ,
946- PARAM.inp .of_ml_chi_pnl ,
947- PARAM.inp .of_ml_chi_qnl ,
948- PARAM.inp .of_ml_nkernel ,
949- PARAM.inp .of_ml_kernel ,
950- PARAM.inp .of_ml_kernel_scaling ,
951- PARAM.inp .of_ml_yukawa_alpha ,
952- PARAM.inp .of_ml_kernel_file ,
953- ucell.omega ,
954- this ->pw_rho );
955-
956- ml_data.generateTrainData_KS (this ->kspw_psi ,
957- this ->pelec ,
958- this ->pw_wfc ,
959- this ->pw_rho ,
960- ucell,
961- this ->pelec ->pot ->get_effective_v (0 ));
962- }
861+ ML_data ml_data;
862+ ml_data.set_para (this ->pelec ->charge ->nrxx ,
863+ PARAM.inp .nelec ,
864+ PARAM.inp .of_tf_weight ,
865+ PARAM.inp .of_vw_weight ,
866+ PARAM.inp .of_ml_chi_p ,
867+ PARAM.inp .of_ml_chi_q ,
868+ PARAM.inp .of_ml_chi_xi ,
869+ PARAM.inp .of_ml_chi_pnl ,
870+ PARAM.inp .of_ml_chi_qnl ,
871+ PARAM.inp .of_ml_nkernel ,
872+ PARAM.inp .of_ml_kernel ,
873+ PARAM.inp .of_ml_kernel_scaling ,
874+ PARAM.inp .of_ml_yukawa_alpha ,
875+ PARAM.inp .of_ml_kernel_file ,
876+ ucell.omega ,
877+ this ->pw_rho );
878+
879+ ml_data.generateTrainData_KS (this ->kspw_psi ,
880+ this ->pelec ,
881+ this ->pw_wfc ,
882+ this ->pw_rho ,
883+ ucell,
884+ this ->pelec ->pot ->get_effective_v (0 ));
885+ }
963886#endif
964887}
965888
0 commit comments