Skip to content

Commit 9c7d553

Browse files
committed
update chg_init and pot_init files
1 parent fa7f6ab commit 9c7d553

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,11 +1655,11 @@ These variables are used to control the output of properties.
16551655
- **Description**:
16561656
The first integer controls whether to output the charge density on real space grids:
16571657
- 1: Output the charge density (in Bohr^-3) on real space grids into the density files in the folder `OUT.${suffix}`. The files are named as:
1658-
- nspin = 1: `chgs1.cube`;
1658+
- nspin = 1: `chg.cube`;
16591659
- nspin = 2: `chgs1.cube`, and `chgs2.cube`;
16601660
- nspin = 4: `chgs1.cube`, `chgs2.cube`, `chgs3.cube`, and `chgs4.cube`;
16611661
Note that by using the Meta-GGA functional, additional files containing the kinetic energy density will be output with the following names:
1662-
- nspin = 1: `taus1.cube`;
1662+
- nspin = 1: `tau.cube`;
16631663
- nspin = 2: `taus1.cube`, and `taus2.cube`;
16641664
- nspin = 4: `taus1.cube`, `taus2.cube`, `taus3.cube`, and `taus4.cube`;
16651665
- 2: On top of 1, also output the initial charge density files with a suffix name as '_ini', such as `taus1_ini.cube`, etc.

source/source_esolver/esolver_fp.cpp

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,23 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
184184
}
185185

186186
// 4) write charge density
187+
188+
const int nspin = PARAM.inp.nspin;
189+
187190
if (PARAM.inp.out_chg[0] > 0)
188191
{
189-
for (int is = 0; is < PARAM.inp.nspin; ++is)
192+
for (int is = 0; is < nspin; ++is)
190193
{
191194
this->pw_rhod->real2recip(this->chr.rho_save[is], this->chr.rhog_save[is]);
192195

193196
std::string fn =PARAM.globalv.global_out_dir + "chg";
194197

195198
std::string spin_block;
196-
if(PARAM.inp.nspin == 2 || PARAM.inp.nspin == 4)
199+
if(nspin == 2 || nspin == 4)
197200
{
198201
spin_block= "s" + std::to_string(is + 1);
199202
}
200-
else if(PARAM.inp.nspin == 1)
203+
else if(nspin == 1)
201204
{
202205
// do nothing
203206
}
@@ -207,7 +210,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
207210
ModuleIO::write_vdata_palgrid(Pgrid,
208211
this->chr.rho_save[is],
209212
is,
210-
PARAM.inp.nspin,
213+
nspin,
211214
istep_in,
212215
fn,
213216
this->pelec->eferm.get_efval(is),
@@ -224,7 +227,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
224227
ModuleIO::write_vdata_palgrid(Pgrid,
225228
this->chr.kin_r_save[is],
226229
is,
227-
PARAM.inp.nspin,
230+
nspin,
228231
istep,
229232
fn,
230233
this->pelec->eferm.get_efval(is),
@@ -236,16 +239,16 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
236239
// 5) write potential
237240
if (PARAM.inp.out_pot == 1 || PARAM.inp.out_pot == 3)
238241
{
239-
for (int is = 0; is < PARAM.inp.nspin; is++)
242+
for (int is = 0; is < nspin; is++)
240243
{
241244
std::string fn =PARAM.globalv.global_out_dir + "pot";
242245

243246
std::string spin_block;
244-
if(PARAM.inp.nspin == 2 || PARAM.inp.nspin == 4)
247+
if(nspin == 2 || nspin == 4)
245248
{
246249
spin_block= "s" + std::to_string(is + 1);
247250
}
248-
else if(PARAM.inp.nspin == 1)
251+
else if(nspin == 1)
249252
{
250253
// do nothing
251254
}
@@ -255,7 +258,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
255258
ModuleIO::write_vdata_palgrid(Pgrid,
256259
this->pelec->pot->get_effective_v(is),
257260
is,
258-
PARAM.inp.nspin,
261+
nspin,
259262
istep_in,
260263
fn,
261264
0.0, // efermi
@@ -288,7 +291,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
288291
{
289292
this->chr.cal_elf = true;
290293
Symmetry_rho srho;
291-
for (int is = 0; is < PARAM.inp.nspin; is++)
294+
for (int is = 0; is < nspin; is++)
292295
{
293296
srho.begin(is, this->chr, this->pw_rhod, ucell.symm);
294297
}
@@ -301,7 +304,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
301304
#endif
302305
out_dir,
303306
istep,
304-
PARAM.inp.nspin,
307+
nspin,
305308
this->chr.rho,
306309
this->chr.kin_r,
307310
this->pw_rhod,
@@ -402,19 +405,32 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
402405
//----------------------------------------------------------
403406
elecstate::cal_ux(ucell);
404407

408+
409+
405410
//----------------------------------------------------------
406411
//! output the initial charge density
407412
//----------------------------------------------------------
413+
const int nspin = PARAM.inp.nspin;
408414
if (PARAM.inp.out_chg[0] == 2)
409415
{
410-
for (int is = 0; is < PARAM.inp.nspin; is++)
416+
for (int is = 0; is < nspin; is++)
411417
{
412418
std::stringstream ss;
413-
ss << PARAM.globalv.global_out_dir << "chgs" << is + 1 << "_ini.cube";
419+
ss << PARAM.globalv.global_out_dir << "chg";
420+
421+
if(nspin==1)
422+
{
423+
ss << "ini.cube";
424+
}
425+
else if(nspin==2 || nspin==4)
426+
{
427+
ss << "s" << is + 1 << "ini.cube";
428+
}
429+
414430
ModuleIO::write_vdata_palgrid(this->Pgrid,
415431
this->chr.rho[is],
416432
is,
417-
PARAM.inp.nspin,
433+
nspin,
418434
istep,
419435
ss.str(),
420436
this->pelec->eferm.ef,
@@ -427,14 +443,24 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
427443
//----------------------------------------------------------
428444
if (PARAM.inp.out_pot == 3)
429445
{
430-
for (int is = 0; is < PARAM.inp.nspin; is++)
446+
for (int is = 0; is < nspin; is++)
431447
{
432448
std::stringstream ss;
433-
ss << PARAM.globalv.global_out_dir << "pots" << is + 1 << "_ini.cube";
449+
ss << PARAM.globalv.global_out_dir << "pot";
450+
451+
if(nspin==1)
452+
{
453+
ss << "ini.cube";
454+
}
455+
else if(nspin==2 || nspin==4)
456+
{
457+
ss << "s" << is + 1 << "ini.cube";
458+
}
459+
434460
ModuleIO::write_vdata_palgrid(this->Pgrid,
435461
this->pelec->pot->get_effective_v(is),
436462
is,
437-
PARAM.inp.nspin,
463+
nspin,
438464
istep,
439465
ss.str(),
440466
0.0, // efermi

0 commit comments

Comments
 (0)