11#include " esolver_ks.h"
2- #include " pw_setup.h" // setup plane wave
32
4- #include " source_base/timer.h"
5- #include " source_base/global_variable.h"
6- #include " source_pw/module_pwdft/global.h"
7- #include " source_io/module_parameter/parameter.h"
8- #include " source_lcao/module_dftu/dftu.h"
9-
10- #include " source_cell/cal_atoms_info.h"
11- #include " source_estate/elecstate_print.h"
12- #include " source_hamilt/module_xc/xc_functional.h"
13- #include " source_hsolver/hsolver.h"
14- #include " source_io/cube_io.h"
15-
16- // for NSCF calculations of band structures
17- #include " source_io/nscf_band.h"
18- // for output log information
19- #include " source_io/output_log.h"
20- #include " source_io/print_info.h"
21- #include " source_io/write_eig_occ.h"
223// for jason output information
234#include " source_io/json_output/init_info.h"
245#include " source_io/json_output/output_info.h"
256
267#include " source_estate/update_pot.h" // mohan add 20251016
278#include " source_estate/module_charge/chgmixing.h" // mohan add 20251018
9+ #include " source_pw/module_pwdft/setup_pwwfc.h" // mohan add 20251018
10+ #include " source_hsolver/hsolver.h"
11+ #include " source_io/write_eig_occ.h"
12+ #include " source_io/write_bands.h"
13+ #include " source_hamilt/module_xc/xc_functional.h"
14+ #include " source_io/output_log.h" // use write_head
15+ #include " source_estate/elecstate_print.h" // print_etot
16+ #include " source_io/print_info.h" // print_parameters
2817
2918namespace ModuleESolver
3019{
@@ -40,10 +29,12 @@ ESolver_KS<T, Device>::~ESolver_KS()
4029 // do not add any codes in this deconstructor funcion
4130 // ****************************************************
4231 delete this ->psi ;
43- delete this ->pw_wfc ;
4432 delete this ->p_hamilt ;
4533 delete this ->p_chgmix ;
4634 this ->ppcell .release_memory ();
35+
36+ // mohan add 2025-10-18, should be put int clean() function
37+ pw::teardown_pwwfc (this ->pw_wfc );
4738}
4839
4940
@@ -59,74 +50,53 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
5950 classname = " ESolver_KS" ;
6051 basisname = " " ;
6152
62- scf_thr = inp.scf_thr ;
63- scf_ene_thr = inp.scf_ene_thr ;
64- maxniter = inp.scf_nmax ;
65- niter = maxniter;
66- drho = 0.0 ;
67-
68- std::string fft_device = inp.device ;
53+ this ->scf_thr = inp.scf_thr ;
54+ this ->scf_ene_thr = inp.scf_ene_thr ;
55+ this ->maxniter = inp.scf_nmax ;
56+ this ->niter = maxniter;
57+ this ->drho = 0.0 ;
6958
70- // ! 3) setup pw_wfc
71- // currently LCAO doesn't support GPU acceleration of FFT
72- if (inp.basis_type == " lcao" )
73- {
74- fft_device = " cpu" ;
75- }
76- std::string fft_precision = inp.precision ;
77- #ifdef __ENABLE_FLOAT_FFTW
78- if (inp.cal_cond && inp.esolver_type == " sdft" )
79- {
80- fft_precision = " mixing" ;
81- }
82- #endif
83-
84- pw_wfc = new ModulePW::PW_Basis_K_Big (fft_device, fft_precision);
85- ModulePW::PW_Basis_K_Big* tmp = static_cast <ModulePW::PW_Basis_K_Big*>(pw_wfc);
86-
87- tmp->setbxyz (inp.bx , inp.by , inp.bz );
59+ // cell_factor
60+ this ->ppcell .cell_factor = inp.cell_factor ;
8861
89- // ! 4 ) setup charge mixing
62+ // ! 3 ) setup charge mixing
9063 p_chgmix = new Charge_Mixing ();
9164 p_chgmix->set_rhopw (this ->pw_rho , this ->pw_rhod );
9265
93- // cell_factor
94- this ->ppcell .cell_factor = inp.cell_factor ;
95-
9666 ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " SETUP UNITCELL" );
9767
98- // ! 5 ) setup Exc for the first element '0', because all elements have same exc
68+ // ! 4 ) setup Exc for the first element '0', because all elements have same exc
9969 XC_Functional::set_xc_type (ucell.atoms [0 ].ncpp .xc_func );
10070
101- // ! 6 ) setup the charge mixing parameters
71+ // ! 5 ) setup the charge mixing parameters
10272 p_chgmix->set_mixing (inp.mixing_mode , inp.mixing_beta , inp.mixing_ndim ,
10373 inp.mixing_gg0 , inp.mixing_tau , inp.mixing_beta_mag , inp.mixing_gg0_mag ,
10474 inp.mixing_gg0_min , inp.mixing_angle , inp.mixing_dmr , ucell.omega , ucell.tpiba );
10575
10676 p_chgmix->init_mixing ();
10777
108- // ! 7 ) symmetry analysis should be performed every time the cell is changed
78+ // ! 6 ) symmetry analysis should be performed every time the cell is changed
10979 if (ModuleSymmetry::Symmetry::symm_flag == 1 )
11080 {
11181 ucell.symm .analy_sys (ucell.lat , ucell.st , ucell.atoms , GlobalV::ofs_running);
11282 ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " SYMMETRY" );
11383 }
11484
115- // ! 8 ) Setup the k points according to symmetry.
85+ // ! 7 ) Setup the k points according to symmetry.
11686 this ->kv .set (ucell,ucell.symm , inp.kpoint_file , inp.nspin , ucell.G , ucell.latvec , GlobalV::ofs_running);
11787 ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " INIT K-POINTS" );
11888
119- // ! 9 ) print information
120- ModuleIO::setup_parameters (ucell, this ->kv );
89+ // ! 8 ) print information
90+ ModuleIO::print_parameters (ucell, this ->kv , inp );
12191
122- // ! 10 ) setup plane wave for electronic wave functions
123- ModuleESolver::pw_setup (inp, ucell, *this ->pw_rho , this ->kv , * this ->pw_wfc );
92+ // ! 9 ) setup plane wave for electronic wave functions
93+ pw::setup_pwwfc (inp, ucell, *this ->pw_rho , this ->kv , this ->pw_wfc );
12494
125- // ! 11 ) parallel of FFT grid
95+ // ! 10 ) parallel of FFT grid
12696 Pgrid.init (this ->pw_rhod ->nx , this ->pw_rhod ->ny , this ->pw_rhod ->nz ,
12797 this ->pw_rhod ->nplane , this ->pw_rhod ->nrxx , pw_big->nbz , pw_big->bz );
12898
129- // ! 12 ) calculate the structure factor
99+ // ! 11 ) calculate the structure factor
130100 this ->sf .setup_structure_factor (&ucell, Pgrid, this ->pw_rhod );
131101}
132102
@@ -303,13 +273,13 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
303273 }
304274
305275 // 1.2) print out eigenvalues and occupations
306- if (iter % PARAM.inp .out_freq_elec == 0 )
307- {
308- if (PARAM.inp .out_band [ 0 ] || iter == PARAM.inp .scf_nmax || conv_esolver)
276+ if ( PARAM.inp .out_band [ 0 ] )
277+ {
278+ if (iter % PARAM.inp .out_freq_elec == 0 || iter == PARAM.inp .scf_nmax || conv_esolver)
309279 {
310280 ModuleIO::write_eig_iter (this ->pelec ->ekb ,this ->pelec ->wg ,*this ->pelec ->klist );
311281 }
312- }
282+ }
313283
314284 // 2.1) compute magnetization, only for spin==2
315285 ucell.magnet .compute_mag (ucell.omega , this ->chr .nrxx , this ->chr .nxyz , this ->chr .rho ,
@@ -388,32 +358,9 @@ void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep, const bo
388358 // 3) write eigenvalues and occupations to eig_occ.txt
389359 ModuleIO::write_eig_file (this ->pelec ->ekb , this ->pelec ->wg , this ->kv , istep);
390360
391- // 3) write band information to band.txt
392- if (PARAM.inp .out_band [0 ])
393- {
394- const int nspin0 = (PARAM.inp .nspin == 2 ) ? 2 : 1 ;
395- for (int is = 0 ; is < nspin0; is++)
396- {
397- std::stringstream ss;
398- ss << PARAM.globalv .global_out_dir << " band" ;
399-
400- if (nspin0==1 )
401- {
402- // do nothing
403- }
404- else if (nspin0==2 )
405- {
406- ss << " s" << is + 1 ;
407- }
408-
409- ss << " .txt" ;
361+ // 4) write band information to band.txt
362+ ModuleIO::write_bands (PARAM.inp , this ->pelec ->ekb , this ->kv );
410363
411- const double eshift = 0.0 ;
412- ModuleIO::nscf_band (is, ss.str (), PARAM.inp .nbands ,
413- eshift, PARAM.inp .out_band [1 ], // precision
414- this ->pelec ->ekb , this ->kv );
415- }
416- }
417364}
418365
419366template <typename T, typename Device>
0 commit comments