@@ -62,46 +62,26 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
6262 // cell_factor
6363 this ->ppcell .cell_factor = inp.cell_factor ;
6464
65- // ! 3) setup charge mixing
65+ // ! 3) setup Exc for the first element '0' (all elements have same exc)
66+ // XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
67+ // GlobalV::ofs_running<<XC_Functional::output_info()<<std::endl;
68+
69+ // ! 4) setup charge mixing
6670 p_chgmix = new Charge_Mixing ();
6771 p_chgmix->set_rhopw (this ->pw_rho , this ->pw_rhod );
68-
69- ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " SETUP UNITCELL" );
70-
71- // ! 4) setup Exc for the first element '0' (all elements have same exc)
72- XC_Functional::set_xc_type (ucell.atoms [0 ].ncpp .xc_func );
73- GlobalV::ofs_running<<XC_Functional::output_info ()<<std::endl;
74-
75- // ! 5) setup the charge mixing parameters
7672 p_chgmix->set_mixing (inp.mixing_mode , inp.mixing_beta , inp.mixing_ndim ,
7773 inp.mixing_gg0 , inp.mixing_tau , inp.mixing_beta_mag , inp.mixing_gg0_mag ,
7874 inp.mixing_gg0_min , inp.mixing_angle , inp.mixing_dmr , ucell.omega , ucell.tpiba );
79-
8075 p_chgmix->init_mixing ();
8176
82- // ! 6) symmetry analysis should be performed every time the cell is changed
83- if (ModuleSymmetry::Symmetry::symm_flag == 1 )
84- {
85- ucell.symm .analy_sys (ucell.lat , ucell.st , ucell.atoms , GlobalV::ofs_running);
86- ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " SYMMETRY" );
87- }
88-
89- // ! 7) setup k points in the Brillouin zone according to symmetry.
90- this ->kv .set (ucell,ucell.symm , inp.kpoint_file , inp.nspin , ucell.G , ucell.latvec , GlobalV::ofs_running);
91- ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " INIT K-POINTS" );
92-
93- // ! 8) print information
94- ModuleIO::print_parameters (ucell, this ->kv , inp);
95-
96- // ! 9) setup plane wave for electronic wave functions
77+ // ! 5) setup plane wave for electronic wave functions
9778 pw::setup_pwwfc (inp, ucell, *this ->pw_rho , this ->kv , this ->pw_wfc );
9879
99- // ! 10) parallel of FFT grid
100- Pgrid.init (this ->pw_rhod ->nx , this ->pw_rhod ->ny , this ->pw_rhod ->nz ,
101- this ->pw_rhod ->nplane , this ->pw_rhod ->nrxx , pw_big->nbz , pw_big->bz );
102-
103- // ! 11) calculate the structure factor
104- this ->sf .setup (&ucell, Pgrid, this ->pw_rhod );
80+ // ! 6) read in charge density, mohan add 2025-11-28
81+ // ! Inititlize the charge density.
82+ this ->chr .init_rho (ucell, this ->Pgrid , this ->sf .strucFac , ucell.symm , &this ->kv , this ->pw_wfc );
83+ this ->chr .check_rho (); // check the rho
84+
10585}
10686
10787template <typename T, typename Device>
@@ -115,20 +95,14 @@ void ESolver_KS<T, Device>::hamilt2rho(UnitCell& ucell, const int istep, const i
11595 this ->hamilt2rho_single (ucell, istep, iter, diag_ethr);
11696
11797 // 2) for MPI: STOGROUP? need to rewrite
118- // <Temporary> It may be changed when more clever parallel algorithm is
119- // put forward.
120- // When parallel algorithm for bands are adopted. Density will only be
121- // treated in the first group.
122- // (Different ranks should have abtained the same, but small differences
123- // always exist in practice.)
98+ // <Temporary> It may be changed when more clever parallel algorithm is put forward.
99+ // When parallel algorithm for bands are adopted. Density will only be treated in the first group.
100+ // (Different ranks should have abtained the same, but small differences always exist in practice.)
124101 // Maybe in the future, density and wavefunctions should use different
125102 // parallel algorithms, in which they do not occupy all processors, for
126103 // example wavefunctions uses 20 processors while density uses 10.
127104 if (PARAM.globalv .ks_run )
128105 {
129- // double drho = this->estate.caldr2();
130- // EState should be used after it is constructed.
131-
132106 drho = p_chgmix->get_drho (&this ->chr , PARAM.inp .nelec );
133107 hsolver_error = 0.0 ;
134108 if (iter == 1 && PARAM.inp .calculation != " nscf" )
@@ -140,23 +114,16 @@ void ESolver_KS<T, Device>::hamilt2rho(UnitCell& ucell, const int istep, const i
140114 // so a more precise HSolver should be executed.
141115 if (hsolver_error > drho)
142116 {
143- diag_ethr = hsolver::reset_diag_ethr (GlobalV::ofs_running,
144- PARAM.inp .basis_type ,
145- PARAM.inp .esolver_type ,
146- PARAM.inp .precision ,
147- hsolver_error,
148- drho,
149- diag_ethr,
150- PARAM.inp .nelec );
117+ diag_ethr = hsolver::reset_diag_ethr (GlobalV::ofs_running, PARAM.inp .basis_type ,
118+ PARAM.inp .esolver_type , PARAM.inp .precision , hsolver_error,
119+ drho, diag_ethr, PARAM.inp .nelec );
151120
152121 this ->hamilt2rho_single (ucell, istep, iter, diag_ethr);
153122
154123 drho = p_chgmix->get_drho (&this ->chr , PARAM.inp .nelec );
155124
156125 hsolver_error = hsolver::cal_hsolve_error (PARAM.inp .basis_type ,
157- PARAM.inp .esolver_type ,
158- diag_ethr,
159- PARAM.inp .nelec );
126+ PARAM.inp .esolver_type , diag_ethr, PARAM.inp .nelec );
160127 }
161128 }
162129 }
@@ -168,22 +135,17 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
168135 ModuleBase::TITLE (" ESolver_KS" , " runner" );
169136 ModuleBase::timer::tick (this ->classname , " runner" );
170137
171- // ----------------------------------------------------------------
172138 // 1) before_scf (electronic iteration loops)
173- // ----------------------------------------------------------------
174139 this ->before_scf (ucell, istep);
175140 ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " INIT SCF" );
176141
177- // ----------------------------------------------------------------
178142 // 2) SCF iterations
179- // ----------------------------------------------------------------
180143 bool conv_esolver = false ;
181144 this ->niter = this ->maxniter ;
182145 this ->diag_ethr = PARAM.inp .pw_diag_thr ;
183146 this ->scf_nmax_flag = false ; // mohan add 2025-09-21
184147 for (int iter = 1 ; iter <= this ->maxniter ; ++iter)
185148 {
186- // mohan add 2025-09-21
187149 if (iter == this ->maxniter )
188150 {
189151 this ->scf_nmax_flag =true ;
0 commit comments