@@ -47,10 +47,7 @@ ESolver_OF::~ESolver_OF()
4747 delete[] this ->task_ ;
4848 delete this ->ptemp_rho_ ;
4949
50- delete this ->tf_ ;
51- delete this ->vw_ ;
52- delete this ->wt_ ;
53- delete this ->lkt_ ;
50+ delete this ->kedf_manager_ ;
5451
5552 delete this ->opt_cg_ ;
5653 delete this ->opt_tn_ ;
@@ -142,7 +139,8 @@ void ESolver_OF::before_all_runners(UnitCell& ucell, const Input_para& inp)
142139 this ->nelec_ [0 ] = this ->pelec ->nelec_spin [0 ];
143140 this ->nelec_ [1 ] = this ->pelec ->nelec_spin [1 ];
144141 }
145- this ->init_kedf (inp);
142+ this ->kedf_manager_ = new KEDF_Manager ();
143+ this ->kedf_manager_ ->init (inp, this ->pw_rho , this ->dV_ , this ->nelec_ [0 ]);
146144 ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " INIT KEDF" );
147145
148146 // Initialize optimization methods
@@ -159,11 +157,6 @@ void ESolver_OF::runner(UnitCell& ucell, const int istep)
159157 this ->before_opt (istep, ucell);
160158 this ->iter_ = 0 ;
161159
162- #ifdef __MLALGO
163- // for ML KEDF test
164- if (PARAM.inp .of_ml_local_test ) this ->ml_ ->localTest (this ->chr .rho , this ->pw_rho );
165- #endif
166-
167160 bool conv_esolver = false ; // this conv_esolver is added by mohan 20250302
168161#ifdef __MPI
169162 this ->iter_time = MPI_Wtime ();
@@ -228,7 +221,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell)
228221 this ->init_elecstate (ucell);
229222
230223 // Initialize KEDF
231- this ->init_kedf (PARAM.inp );
224+ this ->kedf_manager_ -> init (PARAM.inp , this -> pw_rho , this -> dV_ , this -> nelec_ [ 0 ] );
232225
233226 // Initialize optimization methods
234227 this ->init_opt ();
@@ -320,9 +313,10 @@ void ESolver_OF::update_potential(UnitCell& ucell)
320313 elecstate::cal_ux (ucell);
321314
322315 this ->pelec ->pot ->update_from_charge (&this ->chr , &ucell); // Hartree + XC + external
323- this ->kinetic_potential (this ->chr .rho ,
324- this ->pphi_ ,
325- this ->pelec ->pot ->get_effective_v ()); // (kinetic + Hartree + XC + external) * 2 * phi
316+ this ->kedf_manager_ ->get_potential (this ->chr .rho ,
317+ this ->pphi_ ,
318+ this ->pw_rho ,
319+ this ->pelec ->pot ->get_effective_v ()); // KEDF potential
326320 for (int is = 0 ; is < PARAM.inp .nspin ; ++is)
327321 {
328322 const double * vr_eff = this ->pelec ->pot ->get_effective_v (is);
@@ -497,7 +491,7 @@ void ESolver_OF::after_opt(const int istep, UnitCell& ucell, const bool conv_eso
497491 // ------------------------------------------------------------------
498492 if (PARAM.inp .out_elf [0 ] > 0 )
499493 {
500- this ->kinetic_energy_density (this ->chr .rho , this ->pphi_ , this ->chr .kin_r );
494+ this ->kedf_manager_ -> get_energy_density (this ->chr .rho , this ->pphi_ , this -> pw_rho , this ->chr .kin_r );
501495 }
502496
503497 // ------------------------------------------------------------------
@@ -513,43 +507,27 @@ void ESolver_OF::after_opt(const int istep, UnitCell& ucell, const bool conv_eso
513507 }
514508
515509#ifdef __MLALGO
516- // ------------------------------------------------------------------
517- // Check the positivity of Pauli energy
518- // ------------------------------------------------------------------
519- if (this ->of_kinetic_ == " ml" )
520- {
521- this ->tf_ ->get_energy (this ->chr .rho );
522-
523- std::cout << " ML Term = " << this ->ml_ ->ml_energy
524- << " Ry, TF Term = " << this ->tf_ ->tf_energy
525- << " Ry." << std::endl;
526-
527- if (this ->ml_ ->ml_energy >= this ->tf_ ->tf_energy )
528- {
529- std::cout << " WARNING: ML >= TF" << std::endl;
530- }
531- }
532-
533510 // ------------------------------------------------------------------
534511 // Generate data if needed
535512 // ------------------------------------------------------------------
536513 if (PARAM.inp .of_ml_gene_data )
537514 {
538515 this ->pelec ->pot ->update_from_charge (&this ->chr , &ucell); // Hartree + XC + external
539- this ->kinetic_potential (this ->chr .rho , this ->pphi_ , this ->pelec ->pot ->get_effective_v ()); // (kinetic + Hartree + XC + external) * 2 * phi
516+ this ->kedf_manager_ ->get_potential (this ->chr .rho ,
517+ this ->pphi_ ,
518+ this ->pw_rho ,
519+ this ->pelec ->pot ->get_effective_v ()); // KEDF potential
540520
541521 const double * vr_eff = this ->pelec ->pot ->get_effective_v (0 );
542522 for (int ir = 0 ; ir < this ->pw_rho ->nrxx ; ++ir)
543523 {
544524 this ->pdEdphi_ [0 ][ir] = vr_eff[ir];
545525 }
546526 this ->pelec ->eferm .set_efval (0 , this ->cal_mu (this ->pphi_ [0 ], this ->pdEdphi_ [0 ], this ->nelec_ [0 ]));
547- // === temporary ===
548- // assert(GlobalV::of_kinetic == "wt" || GlobalV::of_kinetic == "ml");
549- // =================
527+
550528 std::cout << " Generating Training data..." << std::endl;
551529 std::cout << " mu = " << this ->pelec ->eferm .get_efval (0 ) << std::endl;
552- this ->ml_ -> generateTrainData (this ->chr .rho , *( this -> wt_ ), *( this -> tf_ ) , this ->pw_rho , vr_eff);
530+ this ->kedf_manager_ -> generate_ml_target (this ->chr .rho , this ->pw_rho , vr_eff);
553531 }
554532#endif
555533
@@ -573,7 +551,7 @@ void ESolver_OF::after_all_runners(UnitCell& ucell)
573551double ESolver_OF::cal_energy ()
574552{
575553 this ->pelec ->cal_energies (2 );
576- double kinetic_energy = this ->kinetic_energy (); // kinetic energy
554+ double kinetic_energy = this ->kedf_manager_ -> get_energy (); // kinetic energy
577555 double pseudopot_energy = 0 .; // electron-ion interaction energy
578556 for (int is = 0 ; is < PARAM.inp .nspin ; ++is)
579557 {
@@ -609,7 +587,11 @@ void ESolver_OF::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress)
609587{
610588 ModuleBase::matrix kinetic_stress_;
611589 kinetic_stress_.create (3 , 3 );
612- this ->kinetic_stress (kinetic_stress_);
590+ this ->kedf_manager_ ->get_stress (this ->pelec ->omega ,
591+ this ->chr .rho ,
592+ this ->pphi_ ,
593+ this ->pw_rho ,
594+ kinetic_stress_); // kinetic stress
613595
614596 OF_Stress_PW ss (this ->pelec , this ->pw_rho );
615597 ss.cal_stress (stress, kinetic_stress_, ucell, &ucell.symm , this ->locpp , &sf, &kv);
0 commit comments