@@ -47,10 +47,7 @@ ESolver_OF::~ESolver_OF()
47
47
delete[] this ->task_ ;
48
48
delete this ->ptemp_rho_ ;
49
49
50
- delete this ->tf_ ;
51
- delete this ->vw_ ;
52
- delete this ->wt_ ;
53
- delete this ->lkt_ ;
50
+ delete this ->kedf_manager_ ;
54
51
55
52
delete this ->opt_cg_ ;
56
53
delete this ->opt_tn_ ;
@@ -142,7 +139,8 @@ void ESolver_OF::before_all_runners(UnitCell& ucell, const Input_para& inp)
142
139
this ->nelec_ [0 ] = this ->pelec ->nelec_spin [0 ];
143
140
this ->nelec_ [1 ] = this ->pelec ->nelec_spin [1 ];
144
141
}
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 ]);
146
144
ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " INIT KEDF" );
147
145
148
146
// Initialize optimization methods
@@ -159,11 +157,6 @@ void ESolver_OF::runner(UnitCell& ucell, const int istep)
159
157
this ->before_opt (istep, ucell);
160
158
this ->iter_ = 0 ;
161
159
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
-
167
160
bool conv_esolver = false ; // this conv_esolver is added by mohan 20250302
168
161
#ifdef __MPI
169
162
this ->iter_time = MPI_Wtime ();
@@ -228,7 +221,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell)
228
221
this ->init_elecstate (ucell);
229
222
230
223
// Initialize KEDF
231
- this ->init_kedf (PARAM.inp );
224
+ this ->kedf_manager_ -> init (PARAM.inp , this -> pw_rho , this -> dV_ , this -> nelec_ [ 0 ] );
232
225
233
226
// Initialize optimization methods
234
227
this ->init_opt ();
@@ -320,9 +313,10 @@ void ESolver_OF::update_potential(UnitCell& ucell)
320
313
elecstate::cal_ux (ucell);
321
314
322
315
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
326
320
for (int is = 0 ; is < PARAM.inp .nspin ; ++is)
327
321
{
328
322
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
497
491
// ------------------------------------------------------------------
498
492
if (PARAM.inp .out_elf [0 ] > 0 )
499
493
{
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 );
501
495
}
502
496
503
497
// ------------------------------------------------------------------
@@ -513,43 +507,27 @@ void ESolver_OF::after_opt(const int istep, UnitCell& ucell, const bool conv_eso
513
507
}
514
508
515
509
#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
-
533
510
// ------------------------------------------------------------------
534
511
// Generate data if needed
535
512
// ------------------------------------------------------------------
536
513
if (PARAM.inp .of_ml_gene_data )
537
514
{
538
515
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
540
520
541
521
const double * vr_eff = this ->pelec ->pot ->get_effective_v (0 );
542
522
for (int ir = 0 ; ir < this ->pw_rho ->nrxx ; ++ir)
543
523
{
544
524
this ->pdEdphi_ [0 ][ir] = vr_eff[ir];
545
525
}
546
526
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
+
550
528
std::cout << " Generating Training data..." << std::endl;
551
529
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);
553
531
}
554
532
#endif
555
533
@@ -573,7 +551,7 @@ void ESolver_OF::after_all_runners(UnitCell& ucell)
573
551
double ESolver_OF::cal_energy ()
574
552
{
575
553
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
577
555
double pseudopot_energy = 0 .; // electron-ion interaction energy
578
556
for (int is = 0 ; is < PARAM.inp .nspin ; ++is)
579
557
{
@@ -609,7 +587,11 @@ void ESolver_OF::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress)
609
587
{
610
588
ModuleBase::matrix kinetic_stress_;
611
589
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
613
595
614
596
OF_Stress_PW ss (this ->pelec , this ->pw_rho );
615
597
ss.cal_stress (stress, kinetic_stress_, ucell, &ucell.symm , this ->locpp , &sf, &kv);
0 commit comments