Skip to content

Commit 5011d10

Browse files
authored
Update output filenames for PCHG (#6299)
* update PCHG * update output file names of pchg * update reference data for PW tests * delete useless 074 example in 01_PW tests * update result.ref * update pchg output * delete a test in 01_PW * add ctrl_output_fp files * update tests in 01_PW * comment out a test in 11_PW_GPU
1 parent 415390d commit 5011d10

172 files changed

Lines changed: 245 additions & 380 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#include "module_io/ctrl_output_fp.h" // use ctrl_output_fp()
2+
3+
namespace ModuleIO
4+
{
5+
6+
template <typename TK, typename TR>
7+
void ctrl_output_fp(UnitCell& ucell,
8+
elecstate::ElecStateLCAO<TK>* pelec,
9+
const int istep)
10+
{
11+
ModuleBase::TITLE("ModuleIO", "ctrl_output_fp");
12+
ModuleBase::timer::tick("ModuleIO", "ctrl_output_fp");
13+
14+
const bool out_app_flag = PARAM.inp.out_app_flag;
15+
const bool gamma_only = PARAM.globalv.gamma_only_local;
16+
const int nspin = PARAM.inp.nspin;
17+
const std::string global_out_dir = PARAM.globalv.global_out_dir;
18+
19+
// 1) write charge density
20+
if (PARAM.inp.out_chg[0] > 0)
21+
{
22+
for (int is = 0; is < PARAM.inp.nspin; is++)
23+
{
24+
this->pw_rhod->real2recip(this->chr.rho_save[is], this->chr.rhog_save[is]);
25+
std::string fn =PARAM.globalv.global_out_dir + "/chgs" + std::to_string(is + 1) + ".cube";
26+
ModuleIO::write_vdata_palgrid(Pgrid,
27+
this->chr.rho_save[is],
28+
is,
29+
PARAM.inp.nspin,
30+
istep,
31+
fn,
32+
this->pelec->eferm.get_efval(is),
33+
&(ucell),
34+
PARAM.inp.out_chg[1],
35+
1);
36+
37+
if (XC_Functional::get_ked_flag())
38+
{
39+
fn =PARAM.globalv.global_out_dir + "/taus" + std::to_string(is + 1) + ".cube";
40+
ModuleIO::write_vdata_palgrid(Pgrid,
41+
this->chr.kin_r_save[is],
42+
is,
43+
PARAM.inp.nspin,
44+
istep,
45+
fn,
46+
this->pelec->eferm.get_efval(is),
47+
&(ucell));
48+
}
49+
}
50+
}
51+
52+
53+
// 2) write potential
54+
if (PARAM.inp.out_pot == 1 || PARAM.inp.out_pot == 3)
55+
{
56+
for (int is = 0; is < PARAM.inp.nspin; is++)
57+
{
58+
std::string fn =PARAM.globalv.global_out_dir + "/pots" + std::to_string(is + 1) + ".cube";
59+
60+
ModuleIO::write_vdata_palgrid(Pgrid,
61+
this->pelec->pot->get_effective_v(is),
62+
is,
63+
PARAM.inp.nspin,
64+
istep,
65+
fn,
66+
0.0, // efermi
67+
&(ucell),
68+
3, // precision
69+
0); // out_fermi
70+
}
71+
}
72+
else if (PARAM.inp.out_pot == 2)
73+
{
74+
std::string fn =PARAM.globalv.global_out_dir + "/pot_es.cube";
75+
ModuleIO::write_elecstat_pot(
76+
#ifdef __MPI
77+
this->pw_big->bz,
78+
this->pw_big->nbz,
79+
#endif
80+
fn,
81+
istep,
82+
this->pw_rhod,
83+
&this->chr,
84+
&(ucell),
85+
this->pelec->pot->get_fixed_v(),
86+
this->solvent);
87+
}
88+
89+
90+
// 3) write ELF
91+
if (PARAM.inp.out_elf[0] > 0)
92+
{
93+
this->chr.cal_elf = true;
94+
Symmetry_rho srho;
95+
for (int is = 0; is < PARAM.inp.nspin; is++)
96+
{
97+
srho.begin(is, this->chr, this->pw_rhod, ucell.symm);
98+
}
99+
100+
std::string out_dir =PARAM.globalv.global_out_dir;
101+
ModuleIO::write_elf(
102+
#ifdef __MPI
103+
this->pw_big->bz,
104+
this->pw_big->nbz,
105+
#endif
106+
out_dir,
107+
istep,
108+
PARAM.inp.nspin,
109+
this->chr.rho,
110+
this->chr.kin_r,
111+
this->pw_rhod,
112+
this->Pgrid,
113+
&(ucell),
114+
PARAM.inp.out_elf[1]);
115+
}
116+
117+
ModuleBase::timer::tick("ModuleIO", "ctrl_output_fp");
118+
}
119+
120+
} // End ModuleIO
121+
122+
123+
// For gamma only
124+
template void ModuleIO::ctrl_output_lcao<double, double>(UnitCell& ucell,
125+
const int istep);
126+
127+
// For multiple k-points
128+
template void ModuleIO::ctrl_output_lcao<std::complex<double>, double>(UnitCell& ucell,
129+
const int istep);
130+
131+
template void ModuleIO::ctrl_output_lcao<std::complex<double>, std::complex<double>>(UnitCell& ucell,
132+
const int istep);
133+

source/module_io/ctrl_output_fp.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef CTRL_OUTPUT_FP_H
2+
#define CTRL_OUTPUT_FP_H
3+
4+
namespace ModuleIO
5+
{
6+
template <typename TK, typename TR>
7+
void ctrl_output_fp(UnitCell& ucell,
8+
elecstate::ElecStateLCAO<TK>* pelec,
9+
const int istep);
10+
}
11+
#endif

source/module_io/get_pchg_lcao.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void IState_Charge::begin(Gint_Gamma& gg,
5555
{
5656
ModuleBase::TITLE("IState_Charge", "begin");
5757

58-
std::cout << " Calculate |psi(i)|^2 for selected bands (band-decomposed charge densities, gamma only)."
58+
std::cout << " Calculate |psi(i)|^2 for selected electronic states (gamma only)."
5959
<< std::endl;
6060

6161
// Determine the mode based on the input parameters
@@ -77,8 +77,8 @@ void IState_Charge::begin(Gint_Gamma& gg,
7777
// if ucell is even, it's also correct.
7878
// +1.0e-8 in case like (2.999999999+1)/2
7979
const int fermi_band = static_cast<int>((nelec + 1) / 2 + 1.0e-8);
80-
std::cout << " number of electrons = " << nelec << std::endl;
81-
std::cout << " number of occupied bands = " << fermi_band << std::endl;
80+
GlobalV::ofs_running << " number of electrons = " << nelec << std::endl;
81+
GlobalV::ofs_running << " number of occupied bands = " << fermi_band << std::endl;
8282

8383
// Set this->bands_picked_ according to the mode
8484
select_bands(nbands_istate, out_pchg, nbands, nelec, mode, fermi_band);
@@ -101,7 +101,7 @@ void IState_Charge::begin(Gint_Gamma& gg,
101101
ModuleBase::GlobalFunc::ZEROS(rho[is], rhopw_nrxx);
102102
}
103103

104-
std::cout << " Performing grid integral over real space grid for band " << ib + 1 << "..." << std::endl;
104+
//std::cout << " Performing grid integral over real space grid for band " << ib + 1 << "..." << std::endl;
105105

106106
DM.init_DMR(GridD_in, ucell_in);
107107
DM.cal_DMR();
@@ -120,21 +120,22 @@ void IState_Charge::begin(Gint_Gamma& gg,
120120
ModuleBase::GlobalFunc::DCOPY(rho[is], rho_save[is].data(), rhopw_nrxx); // Copy data
121121
}
122122

123-
std::cout << " Writing cube files...";
124123

125124
for (int is = 0; is < nspin; ++is)
126125
{
127126
// ssc should be inside the inner loop to reset the string stream each time
128127
std::stringstream ssc;
129-
ssc << global_out_dir << "BAND" << ib + 1 << "_GAMMA" << "_SPIN" << is + 1 << "_CHG.cube";
128+
ssc << global_out_dir << "pchgs" << is + 1 << "i" << ib + 1 << ".cube";
129+
130+
GlobalV::ofs_running << " Writing cube file " << ssc.str() << std::endl;
130131

131132
// Use a const vector to store efermi for all spins, replace the original implementation:
132133
// const double ef_tmp = pelec->eferm.get_efval(is);
133134
double ef_spin = ef_all_spin[is];
134135
ModuleIO::write_vdata_palgrid(pgrid, rho_save[is].data(), is, nspin, 0, ssc.str(), ef_spin, ucell_in);
135136
}
136137

137-
std::cout << " Complete!" << std::endl;
138+
//std::cout << " Complete!" << std::endl;
138139
}
139140
}
140141

@@ -251,7 +252,7 @@ void IState_Charge::begin(Gint_k& gk,
251252
{
252253
// ssc should be inside the inner loop to reset the string stream each time
253254
std::stringstream ssc;
254-
ssc << global_out_dir << "BAND" << ib + 1 << "_K" << ik + 1 << "_SPIN" << is + 1 << "_CHG.cube";
255+
ssc << global_out_dir << "pchgs" << is + 1 << "k" << ik+1 << "i" << ib + 1 << ".cube";
255256

256257
double ef_spin = ef_all_spin[is];
257258
ModuleIO::write_vdata_palgrid(pgrid,
@@ -292,7 +293,7 @@ void IState_Charge::begin(Gint_k& gk,
292293
}
293294

294295
// Symmetrize the charge density, otherwise the results are incorrect if the symmetry is on
295-
std::cout << " Symmetrizing band-decomposed charge density..." << std::endl;
296+
// std::cout << " Symmetrizing band-decomposed charge density..." << std::endl;
296297
Symmetry_rho srho;
297298
for (int is = 0; is < nspin; ++is)
298299
{
@@ -310,7 +311,7 @@ void IState_Charge::begin(Gint_k& gk,
310311
{
311312
// ssc should be inside the inner loop to reset the string stream each time
312313
std::stringstream ssc;
313-
ssc << global_out_dir << "BAND" << ib + 1 << "_SPIN" << is + 1 << "_CHG.cube";
314+
ssc << global_out_dir << "pchgs" << is + 1 << "i" << ib + 1 << ".cube";
314315

315316
double ef_spin = ef_all_spin[is];
316317
ModuleIO::write_vdata_palgrid(pgrid,

source/module_io/get_pchg_pw.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ void get_pchg_pw(const std::vector<int>& out_pchg,
135135
}
136136

137137
std::stringstream ssc;
138-
ssc << global_out_dir << "BAND" << ib + 1 << "_K" << k_number << "_SPIN" << spin_index + 1
139-
<< "_CHG.cube";
138+
ssc << global_out_dir << "pchgs" << spin_index + 1 << "k" << k_number << "i" << ib + 1
139+
<< ".cube";
140140

141141
ModuleIO::write_vdata_palgrid(pgrid,
142142
rho_band[spin_index].data(),
@@ -182,7 +182,7 @@ void get_pchg_pw(const std::vector<int>& out_pchg,
182182
#endif
183183

184184
// Symmetrize the charge density, otherwise the results are incorrect if the symmetry is on
185-
std::cout << " Symmetrizing band-decomposed charge density..." << std::endl;
185+
// std::cout << " Symmetrizing band-decomposed charge density..." << std::endl;
186186
Symmetry_rho srho;
187187
for (int is = 0; is < nspin; ++is)
188188
{
@@ -208,7 +208,7 @@ void get_pchg_pw(const std::vector<int>& out_pchg,
208208
for (int is = 0; is < nspin; ++is)
209209
{
210210
std::stringstream ssc;
211-
ssc << global_out_dir << "BAND" << ib + 1 << "_SPIN" << is + 1 << "_CHG.cube";
211+
ssc << global_out_dir << "pchgs" << is + 1 << "i" << ib + 1 << ".cube";
212212

213213
ModuleIO::write_vdata_palgrid(pgrid, rho_band[is].data(), is, nspin, 0, ssc.str(), 0.0, ucell);
214214
}
File renamed without changes.

0 commit comments

Comments
 (0)