67
67
namespace ModuleESolver
68
68
{
69
69
70
- // ------------------------------------------------------------------------------
71
- // ! the 1st function of ESolver_KS_LCAO: constructor
72
- // ------------------------------------------------------------------------------
73
70
template <typename TK, typename TR>
74
71
ESolver_KS_LCAO<TK, TR>::ESolver_KS_LCAO()
75
72
{
76
73
this ->classname = " ESolver_KS_LCAO" ;
77
74
this ->basisname = " LCAO" ;
75
+
78
76
#ifdef __EXX
79
77
// 1. currently this initialization must be put in constructor rather than `before_all_runners()`
80
78
// because the latter is not reused by ESolver_LCAO_TDDFT,
@@ -94,47 +92,30 @@ ESolver_KS_LCAO<TK, TR>::ESolver_KS_LCAO()
94
92
#endif
95
93
}
96
94
97
- // ------------------------------------------------------------------------------
98
- // ! the 2nd function of ESolver_KS_LCAO: deconstructor
99
- // ------------------------------------------------------------------------------
100
95
template <typename TK, typename TR>
101
96
ESolver_KS_LCAO<TK, TR>::~ESolver_KS_LCAO ()
102
97
{
103
98
}
104
99
105
- // ------------------------------------------------------------------------------
106
- // ! the 3rd function of ESolver_KS_LCAO: init
107
- // ! 1) calculate overlap matrix S or initialize
108
- // ! 2) init ElecState
109
- // ! 3) init LCAO basis
110
- // ! 4) initialize the density matrix
111
- // ! 5) initialize exx
112
- // ! 6) initialize DFT+U
113
- // ! 7) ppcell
114
- // ! 8) inititlize the charge density
115
- // ! 9) initialize the potential.
116
- // ! 10) initialize deepks
117
- // ! 11) set occupations
118
- // ! 12) print a warning if needed
119
- // ------------------------------------------------------------------------------
120
100
template <typename TK, typename TR>
121
101
void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_para& inp)
122
102
{
123
103
ModuleBase::TITLE (" ESolver_KS_LCAO" , " before_all_runners" );
124
104
ModuleBase::timer::tick (" ESolver_KS_LCAO" , " before_all_runners" );
125
105
106
+ // 1) before_all_runners in ESolver_KS
126
107
ESolver_KS<TK>::before_all_runners (ucell, inp);
127
108
128
109
// 2) init ElecState
129
- // autoset nbands in ElecState, it should before basis_init (for Psi 2d division)
110
+ // autoset nbands in ElecState before basis_init (for Psi 2d division)
130
111
if (this ->pelec == nullptr )
131
112
{
132
113
// TK stands for double and complex<double>?
133
114
this ->pelec = new elecstate::ElecStateLCAO<TK>(&(this ->chr ), // use which parameter?
134
115
&(this ->kv ),
135
116
this ->kv .get_nks (),
136
- &(this ->GG ), // mohan add 2024-04-01
137
- &(this ->GK ), // mohan add 2024-04-01
117
+ &(this ->GG ),
118
+ &(this ->GK ),
138
119
this ->pw_rho ,
139
120
this ->pw_big );
140
121
}
@@ -157,9 +138,8 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
157
138
// DMR is not initialized here, it will be constructed in each before_scf
158
139
dynamic_cast <elecstate::ElecStateLCAO<TK>*>(this ->pelec )->init_DM (&this ->kv , &(this ->pv ), PARAM.inp .nspin );
159
140
141
+ // 5) initialize exact exchange calculations
160
142
#ifdef __EXX
161
- // 5) initialize exx
162
- // PLEASE simplify the Exx_Global interface
163
143
if (PARAM.inp .calculation == " scf"
164
144
|| PARAM.inp .calculation == " relax"
165
145
|| PARAM.inp .calculation == " cell-relax"
@@ -190,7 +170,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
190
170
dftu->init (ucell, &this ->pv , this ->kv .get_nks (), &orb_);
191
171
}
192
172
193
- // 7) initialize ppcell
173
+ // 7) initialize local pseudopotentials
194
174
this ->locpp .init_vloc (ucell, this ->pw_rho );
195
175
ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " LOCAL POTENTIAL" );
196
176
@@ -211,8 +191,9 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
211
191
&(this ->pelec ->f_en .vtxc ));
212
192
}
213
193
214
- # ifdef __DEEPKS
194
+
215
195
// 10) initialize deepks
196
+ #ifdef __DEEPKS
216
197
LCAO_domain::DeePKS_init (ucell, pv, this ->kv .get_nks (), orb_, this ->ld , GlobalV::ofs_running);
217
198
if (PARAM.inp .deepks_scf )
218
199
{
@@ -279,10 +260,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
279
260
return ;
280
261
}
281
262
282
- // ------------------------------------------------------------------------------
283
- // ! the 5th function of ESolver_KS_LCAO: cal_energy
284
- // ! mohan add 2024-05-11
285
- // ------------------------------------------------------------------------------
263
+
286
264
template <typename TK, typename TR>
287
265
double ESolver_KS_LCAO<TK, TR>::cal_energy()
288
266
{
@@ -291,10 +269,7 @@ double ESolver_KS_LCAO<TK, TR>::cal_energy()
291
269
return this ->pelec ->f_en .etot ;
292
270
}
293
271
294
- // ------------------------------------------------------------------------------
295
- // ! the 6th function of ESolver_KS_LCAO: cal_force
296
- // ! mohan add 2024-05-11
297
- // ------------------------------------------------------------------------------
272
+
298
273
template <typename TK, typename TR>
299
274
void ESolver_KS_LCAO<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& force)
300
275
{
@@ -380,6 +355,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
380
355
GlobalV::ofs_running << " !FINAL_ETOT_IS " << this ->pelec ->f_en .etot * ModuleBase::Ry_to_eV << " eV" << std::endl;
381
356
GlobalV::ofs_running << " --------------------------------------------\n\n " << std::endl;
382
357
358
+ // 1) write information
383
359
if (PARAM.inp .out_dos != 0 || PARAM.inp .out_band [0 ] != 0 || PARAM.inp .out_proj_band != 0 )
384
360
{
385
361
GlobalV::ofs_running << " \n\n\n\n " ;
@@ -412,14 +388,16 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
412
388
<< std::endl;
413
389
GlobalV::ofs_running << " \n\n\n\n " ;
414
390
}
415
- // qianrui modify 2020-10-18
391
+
392
+ // 2) write information
416
393
if (PARAM.inp .calculation == " scf" || PARAM.inp .calculation == " md" || PARAM.inp .calculation == " relax" )
417
394
{
418
395
ModuleIO::write_istate_info (this ->pelec ->ekb , this ->pelec ->wg , this ->kv );
419
396
}
420
397
421
398
const int nspin0 = (PARAM.inp .nspin == 2 ) ? 2 : 1 ;
422
399
400
+ // 3) print out band information
423
401
if (PARAM.inp .out_band [0 ])
424
402
{
425
403
for (int is = 0 ; is < nspin0; is++)
@@ -435,13 +413,15 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
435
413
this ->pelec ->ekb ,
436
414
this ->kv );
437
415
}
438
- } // out_band
416
+ }
439
417
440
- if (PARAM.inp .out_proj_band ) // Projeced band structure added by jiyy-2022-4-20
418
+ // 4) write projected band structure by jiyy-2022-4-20
419
+ if (PARAM.inp .out_proj_band )
441
420
{
442
421
ModuleIO::write_proj_band_lcao (this ->psi , this ->pv , this ->pelec , this ->kv , ucell, this ->p_hamilt );
443
422
}
444
423
424
+ // 5) print out density of states (DOS)
445
425
if (PARAM.inp .out_dos )
446
426
{
447
427
ModuleIO::out_dos_nao (this ->psi ,
@@ -458,6 +438,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
458
438
this ->p_hamilt );
459
439
}
460
440
441
+ // 6) print out exchange-correlation potential
461
442
if (PARAM.inp .out_mat_xc )
462
443
{
463
444
ModuleIO::write_Vxc<TK, TR>(PARAM.inp .nspin ,
@@ -486,6 +467,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
486
467
);
487
468
}
488
469
470
+ // 7) write eband terms
489
471
if (PARAM.inp .out_eband_terms )
490
472
{
491
473
ModuleIO::write_eband_terms<TK, TR>(PARAM.inp .nspin ,
@@ -518,10 +500,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
518
500
ModuleBase::timer::tick (" ESolver_KS_LCAO" , " after_all_runners" );
519
501
}
520
502
521
- // ------------------------------------------------------------------------------
522
- // ! the 10th function of ESolver_KS_LCAO: iter_init
523
- // ! mohan add 2024-05-11
524
- // ------------------------------------------------------------------------------
503
+
525
504
template <typename TK, typename TR>
526
505
void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const int iter)
527
506
{
@@ -546,6 +525,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
546
525
std::cout << " eV " << std::endl;
547
526
}
548
527
}
528
+
549
529
// for mixing restart
550
530
if (iter == this ->p_chgmix ->mixing_restart_step && PARAM.inp .mixing_restart > 0.0 )
551
531
{
@@ -581,7 +561,6 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
581
561
// mohan update 2012-06-05
582
562
this ->pelec ->f_en .deband_harris = this ->pelec ->cal_delta_eband (ucell);
583
563
584
- // mohan move it outside 2011-01-13
585
564
// first need to calculate the weight according to
586
565
// electrons number.
587
566
if (istep == 0 && PARAM.inp .init_wfc == " file" )
@@ -591,7 +570,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
591
570
std::cout << " WAVEFUN -> CHARGE " << std::endl;
592
571
593
572
// calculate the density matrix using read in wave functions
594
- // and the ncalculate the charge density on grid.
573
+ // and then calculate the charge density on grid.
595
574
596
575
this ->pelec ->skip_weights = true ;
597
576
this ->pelec ->calculate_weights ();
@@ -695,33 +674,18 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
695
674
}
696
675
}
697
676
698
- // ------------------------------------------------------------------------------
699
- // ! the 11th function of ESolver_KS_LCAO: hamilt2density_single
700
- // ! mohan add 2024-05-11
701
- // ! 1) save input rho
702
- // ! 2) save density matrix DMR for mixing
703
- // ! 3) solve the Hamiltonian and output band gap
704
- // ! 4) print bands for each k-point and each band
705
- // ! 5) EXX:
706
- // ! 6) DFT+U: compute local occupation number matrix and energy correction
707
- // ! 7) DeePKS: compute delta_e
708
- // ! 8) DeltaSpin:
709
- // ! 9) use new charge density to calculate energy
710
- // ! 10) symmetrize the charge density
711
- // ! 11) compute magnetization, only for spin==2
712
- // ! 12) calculate delta energy
713
- // ------------------------------------------------------------------------------
677
+
714
678
template <typename TK, typename TR>
715
679
void ESolver_KS_LCAO<TK, TR>::hamilt2density_single(UnitCell& ucell, int istep, int iter, double ethr)
716
680
{
717
681
ModuleBase::TITLE (" ESolver_KS_LCAO" , " hamilt2density_single" );
718
682
719
- // reset energy
683
+ // i1) reset energy
720
684
this ->pelec ->f_en .eband = 0.0 ;
721
685
this ->pelec ->f_en .demet = 0.0 ;
722
686
bool skip_charge = PARAM.inp .calculation == " nscf" ? true : false ;
723
687
724
- // run the inner lambda loop to contrain atomic moments with the DeltaSpin method
688
+ // 2) run the inner lambda loop to contrain atomic moments with the DeltaSpin method
725
689
bool skip_solve = false ;
726
690
if (PARAM.inp .sc_mag_switch )
727
691
{
@@ -740,13 +704,15 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2density_single(UnitCell& ucell, int istep,
740
704
skip_solve = true ;
741
705
}
742
706
}
707
+
708
+ // 3) run Hsolver
743
709
if (!skip_solve)
744
710
{
745
711
hsolver::HSolverLCAO<TK> hsolver_lcao_obj (&(this ->pv ), PARAM.inp .ks_solver );
746
712
hsolver_lcao_obj.solve (this ->p_hamilt , this ->psi [0 ], this ->pelec , skip_charge);
747
713
}
748
714
749
- // 5) what's the exd used for?
715
+ // 4) EXX
750
716
#ifdef __EXX
751
717
if (PARAM.inp .calculation != " nscf" )
752
718
{
@@ -761,22 +727,18 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2density_single(UnitCell& ucell, int istep,
761
727
}
762
728
#endif
763
729
764
- // 10 ) symmetrize the charge density
730
+ // 5 ) symmetrize the charge density
765
731
Symmetry_rho srho;
766
732
for (int is = 0 ; is < PARAM.inp .nspin ; is++)
767
733
{
768
734
srho.begin (is, this ->chr , this ->pw_rho , ucell.symm );
769
735
}
770
736
771
- // 12 ) calculate delta energy
737
+ // 6 ) calculate delta energy
772
738
this ->pelec ->f_en .deband = this ->pelec ->cal_delta_eband (ucell);
773
739
}
774
740
775
- // ------------------------------------------------------------------------------
776
- // ! the 12th function of ESolver_KS_LCAO: update_pot
777
- // ! mohan add 2024-05-11
778
- // ! 1) print potential
779
- // ------------------------------------------------------------------------------
741
+
780
742
template <typename TK, typename TR>
781
743
void ESolver_KS_LCAO<TK, TR>::update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver)
782
744
{
@@ -794,21 +756,14 @@ void ESolver_KS_LCAO<TK, TR>::update_pot(UnitCell& ucell, const int istep, const
794
756
}
795
757
}
796
758
797
- // ------------------------------------------------------------------------------
798
- // ! the 13th function of ESolver_KS_LCAO: iter_finish
799
- // ! mohan add 2024-05-11
800
- // ! 1) mix density matrix
801
- // ! 2) output charge density
802
- // ! 3) output exx matrix
803
- // ! 4) output charge density and density matrix
804
- // ------------------------------------------------------------------------------
759
+
805
760
template <typename TK, typename TR>
806
761
void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int & iter, bool & conv_esolver)
807
762
{
808
763
ModuleBase::TITLE (" ESolver_KS_LCAO" , " iter_finish" );
809
764
810
- // 6 ) calculate the local occupation number matrix and energy correction in
811
- // DFT+U
765
+ // 1 ) calculate the local occupation number matrix and energy correction
766
+ // in DFT+U
812
767
if (PARAM.inp .dft_plus_u )
813
768
{
814
769
// only old DFT+U method should calculated energy correction in esolver,
@@ -831,7 +786,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
831
786
GlobalC::dftu.output (ucell);
832
787
}
833
788
834
- // (7 ) for deepks, calculate delta_e
789
+ // 2 ) for deepks, calculate delta_e
835
790
#ifdef __DEEPKS
836
791
if (PARAM.inp .deepks_scf )
837
792
{
@@ -844,25 +799,25 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
844
799
}
845
800
#endif
846
801
847
- // 8 ) for delta spin
802
+ // 3 ) for delta spin
848
803
if (PARAM.inp .sc_mag_switch )
849
804
{
850
805
spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance ();
851
806
sc.cal_mi_lcao (iter);
852
807
}
853
808
854
- // call iter_finish() of ESolver_KS
809
+ // 4) call iter_finish() of ESolver_KS
855
810
ESolver_KS<TK>::iter_finish (ucell, istep, iter, conv_esolver);
856
811
857
- // 1 ) mix density matrix if mixing_restart + mixing_dmr + not first
812
+ // 5 ) mix density matrix if mixing_restart + mixing_dmr + not first
858
813
// mixing_restart at every iter
859
814
if (PARAM.inp .mixing_restart > 0 && this ->p_chgmix ->mixing_restart_count > 0 && PARAM.inp .mixing_dmr )
860
815
{
861
816
elecstate::DensityMatrix<TK, double >* dm = dynamic_cast <elecstate::ElecStateLCAO<TK>*>(this ->pelec )->get_DM ();
862
817
this ->p_chgmix ->mix_dmr (dm);
863
818
}
864
819
865
- // 2 ) save charge density
820
+ // 6 ) save charge density
866
821
// Peize Lin add 2020.04.04
867
822
if (GlobalC::restart.info_save .save_charge )
868
823
{
@@ -873,7 +828,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
873
828
}
874
829
875
830
#ifdef __EXX
876
- // 3 ) save exx matrix
831
+ // 7 ) save exx matrix
877
832
if (PARAM.inp .calculation != " nscf" )
878
833
{
879
834
if (GlobalC::exx_info.info_global .cal_exx )
@@ -900,7 +855,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
900
855
}
901
856
#endif
902
857
903
- // 6 ) use the converged occupation matrix for next MD/Relax SCF calculation
858
+ // 8 ) use the converged occupation matrix for next MD/Relax SCF calculation
904
859
if (PARAM.inp .dft_plus_u && conv_esolver)
905
860
{
906
861
GlobalC::dftu.initialed_locale = true ;
0 commit comments