@@ -28,8 +28,12 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
2828{
2929 ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running, " init_chg" , PARAM.inp .init_chg );
3030
31+ const int nspin = PARAM.inp .nspin ;
32+ assert (nspin>0 );
33+
3134 std::cout << " START CHARGE : " << PARAM.inp .init_chg << std::endl;
32- // here we need to set the omega for the charge density
35+
36+ // we need to set the omega for the charge density
3337 set_omega (&ucell.omega );
3438 this ->pgrid = &pgrid;
3539
@@ -46,17 +50,17 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
4650 if (ModuleIO::read_rhog (binary.str (), rhopw, rhog))
4751 {
4852 GlobalV::ofs_running << " Read electron density from file: " << binary.str () << std::endl;
49- for (int is = 0 ; is < PARAM. inp . nspin ; ++is)
53+ for (int is = 0 ; is < nspin; ++is)
5054 {
5155 rhopw->recip2real (rhog[is], rho[is]);
5256 }
5357 }
5458 else
5559 {
56- for (int is = 0 ; is < PARAM. inp . nspin ; ++is)
60+ for (int is = 0 ; is < nspin; ++is)
5761 {
5862 std::stringstream ssc;
59- ssc << PARAM.globalv .global_readin_dir << " SPIN " << is + 1 << " _CHG .cube" ;
63+ ssc << PARAM.globalv .global_readin_dir << " chgs " << is + 1 << " .cube" ;
6064 if (ModuleIO::read_vdata_palgrid (pgrid,
6165 (PARAM.inp .esolver_type == " sdft" ? GlobalV::RANK_IN_BPGROUP : GlobalV::MY_RANK),
6266 GlobalV::ofs_running,
@@ -103,7 +107,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
103107 {
104108 const std::string warn_msg
105109 = " WARNING: \" init_chg\" is enabled but ABACUS failed to read\n charge density from file.\n "
106- " Please check if there is SPINX_CHG .cube (X =1,.. .) or\n {suffix}-CHARGE-DENSITY.restart in the "
110+ " Please check if there is chgsx .cube (x =1,2,etc .) or\n {suffix}-CHARGE-DENSITY.restart in the "
107111 " directory.\n " ;
108112 std::cout << warn_msg;
109113 if (PARAM.inp .init_chg == " file" )
@@ -121,9 +125,9 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
121125 {
122126 GlobalV::ofs_running << " try to read kinetic energy density from file" << std::endl;
123127 // try to read charge from binary file first, which is the same as QE
124- std::vector<std::complex <double >> kin_g_space (PARAM. inp . nspin * this ->ngmc , {0.0 , 0.0 });
128+ std::vector<std::complex <double >> kin_g_space (nspin * this ->ngmc , {0.0 , 0.0 });
125129 std::vector<std::complex <double >*> kin_g;
126- for (int is = 0 ; is < PARAM. inp . nspin ; is++)
130+ for (int is = 0 ; is < nspin; is++)
127131 {
128132 kin_g.push_back (kin_g_space.data () + is * this ->ngmc );
129133 }
@@ -133,14 +137,14 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
133137 if (ModuleIO::read_rhog (binary.str (), rhopw, kin_g.data ()))
134138 {
135139 GlobalV::ofs_running << " Read in the kinetic energy density: " << binary.str () << std::endl;
136- for (int is = 0 ; is < PARAM. inp . nspin ; ++is)
140+ for (int is = 0 ; is < nspin; ++is)
137141 {
138142 rhopw->recip2real (kin_g[is], this ->kin_r [is]);
139143 }
140144 }
141145 else
142146 {
143- for (int is = 0 ; is < PARAM. inp . nspin ; is++)
147+ for (int is = 0 ; is < nspin; is++)
144148 {
145149 std::stringstream ssc;
146150 ssc << PARAM.globalv .global_readin_dir << " SPIN" << is + 1 << " _TAU.cube" ;
@@ -175,16 +179,16 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
175179 }
176180 }
177181
178- if (PARAM.inp .init_chg == " atomic" || read_error) // mohan add 2007-10-17
182+ if (PARAM.inp .init_chg == " atomic" || read_error)
179183 {
180184 if (read_error)
181185 {
182186 std::cout << " Charge::init_rho: use atomic initialization instead." << std::endl;
183187 }
184- this ->atomic_rho (PARAM. inp . nspin , ucell.omega , rho, strucFac, ucell);
188+ this ->atomic_rho (nspin, ucell.omega , rho, strucFac, ucell);
185189 }
186190
187- // wenfei 2021-7-29 : initial tau = 3/5 rho^2/3, Thomas-Fermi
191+ // initial tau = 3/5 rho^2/3, Thomas-Fermi
188192 if (XC_Functional::get_ked_flag ())
189193 {
190194 if (PARAM.inp .init_chg == " atomic" || read_kin_error)
@@ -194,11 +198,11 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
194198 std::cout << " Charge::init_rho: init kinetic energy density from rho." << std::endl;
195199 }
196200 const double fact = (3.0 / 5.0 ) * pow (3.0 * ModuleBase::PI * ModuleBase::PI, 2.0 / 3.0 );
197- for (int is = 0 ; is < PARAM. inp . nspin ; ++is)
201+ for (int is = 0 ; is < nspin; ++is)
198202 {
199203 for (int ir = 0 ; ir < this ->rhopw ->nrxx ; ++ir)
200204 {
201- kin_r[is][ir] = fact * pow (std::abs (rho[is][ir]) * PARAM. inp . nspin , 5.0 / 3.0 ) / PARAM. inp . nspin ;
205+ kin_r[is][ir] = fact * pow (std::abs (rho[is][ir]) * nspin, 5.0 / 3.0 ) / nspin;
202206 }
203207 }
204208 }
@@ -207,7 +211,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
207211 // Peize Lin add 2020.04.04
208212 if (GlobalC::restart.info_load .load_charge && !GlobalC::restart.info_load .load_charge_finish )
209213 {
210- for (int is = 0 ; is < PARAM. inp . nspin ; ++is)
214+ for (int is = 0 ; is < nspin; ++is)
211215 {
212216 try
213217 {
@@ -217,20 +221,21 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
217221 {
218222 // try to load from the output of `out_chg`
219223 std::stringstream ssc;
220- ssc << PARAM.globalv .global_readin_dir << " SPIN " << is + 1 << " _CHG .cube" ;
224+ ssc << PARAM.globalv .global_readin_dir << " chgs " << is + 1 << " .cube" ;
221225 if (ModuleIO::read_vdata_palgrid (pgrid,
222226 (PARAM.inp .esolver_type == " sdft" ? GlobalV::RANK_IN_BPGROUP : GlobalV::MY_RANK),
223227 GlobalV::ofs_running,
224228 ssc.str (),
225229 this ->rho [is],
226230 ucell.nat ))
227231 {
228- GlobalV::ofs_running << " Read in the electron density: " << ssc.str () << std::endl;
232+ GlobalV::ofs_running << " Read in electron density: " << ssc.str () << std::endl;
229233 }
230234 }
231235 }
232236 GlobalC::restart.info_load .load_charge_finish = true ;
233237 }
238+
234239#ifdef __MPI
235240 this ->init_chgmpi ();
236241#endif
@@ -248,7 +253,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
248253 PARAM.globalv .global_readin_dir ,
249254 GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::MY_RANK,
250255 GlobalV::NPROC_IN_POOL, GlobalV::RANK_IN_POOL,
251- PARAM.inp .nbands , PARAM. inp . nspin , PARAM.globalv .npol ,
256+ PARAM.inp .nbands , nspin, PARAM.globalv .npol ,
252257 kv->get_nkstot (),kv->ik2iktot ,kv->isk ,GlobalV::ofs_running);
253258 }
254259}
0 commit comments