Skip to content

Commit 32228d7

Browse files
committed
remove the redundant info in read_cube
1 parent 7a29e2f commit 32228d7

File tree

5 files changed

+42
-135
lines changed

5 files changed

+42
-135
lines changed

source/module_elecstate/module_charge/charge_init.cpp

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -53,61 +53,43 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
5353
{
5454
std::stringstream ssc;
5555
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube";
56-
double& ef_tmp = eferm_iout.get_ef(is);
5756
if (ModuleIO::read_cube(
5857
#ifdef __MPI
5958
& (GlobalC::Pgrid),
6059
#endif
6160
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
62-
is,
6361
GlobalV::ofs_running,
64-
PARAM.inp.nspin,
6562
ssc.str(),
6663
this->rho[is],
6764
this->rhopw->nx,
6865
this->rhopw->ny,
6966
this->rhopw->nz,
70-
ef_tmp,
71-
& (GlobalC::ucell),
72-
this->prenspin))
67+
GlobalC::ucell.nat))
7368
{
7469
GlobalV::ofs_running << " Read in the charge density: " << ssc.str() << std::endl;
7570
}
76-
else if (is > 0)
71+
else if (is > 0) // nspin=2 or 4
7772
{
78-
if (prenspin == 1)
73+
if (is == 1) // failed at the second spin
7974
{
80-
GlobalV::ofs_running << " Didn't read in the charge density but autoset it for spin " << is + 1
81-
<< std::endl;
82-
for (int ir = 0; ir < this->rhopw->nrxx; ir++)
83-
{
84-
this->rho[is][ir] = 0.0;
85-
}
75+
std::cout << "Incomplete charge density file!" << std::endl;
76+
read_error = true;
77+
break;
8678
}
87-
//
88-
else if (prenspin == 2)
89-
{ // read up and down , then rearrange them.
90-
if (is == 1)
91-
{
92-
std::cout << "Incomplete charge density file!" << std::endl;
93-
read_error = true;
94-
break;
95-
}
96-
else if (is == 2)
97-
{
98-
GlobalV::ofs_running << " Didn't read in the charge density but would rearrange it later. "
99-
<< std::endl;
100-
}
101-
else if (is == 3)
79+
else if (is == 2) // read 2 files when nspin=4
80+
{
81+
GlobalV::ofs_running << " Didn't read in the charge density but would rearrange it later. "
82+
<< std::endl;
83+
}
84+
else if (is == 3) // read 2 files when nspin=4
85+
{
86+
GlobalV::ofs_running << " rearrange charge density " << std::endl;
87+
for (int ir = 0; ir < this->rhopw->nrxx; ir++)
10288
{
103-
GlobalV::ofs_running << " rearrange charge density " << std::endl;
104-
for (int ir = 0; ir < this->rhopw->nrxx; ir++)
105-
{
106-
this->rho[3][ir] = this->rho[0][ir] - this->rho[1][ir];
107-
this->rho[0][ir] = this->rho[0][ir] + this->rho[1][ir];
108-
this->rho[1][ir] = 0.0;
109-
this->rho[2][ir] = 0.0;
110-
}
89+
this->rho[3][ir] = this->rho[0][ir] - this->rho[1][ir];
90+
this->rho[0][ir] = this->rho[0][ir] + this->rho[1][ir];
91+
this->rho[1][ir] = 0.0;
92+
this->rho[2][ir] = 0.0;
11193
}
11294
}
11395
}
@@ -132,17 +114,13 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
132114
& (GlobalC::Pgrid),
133115
#endif
134116
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
135-
is,
136117
GlobalV::ofs_running,
137-
PARAM.inp.nspin,
138118
ssc.str(),
139119
this->kin_r[is],
140120
this->rhopw->nx,
141121
this->rhopw->ny,
142122
this->rhopw->nz,
143-
eferm_iout.ef,
144-
& (GlobalC::ucell),
145-
this->prenspin))
123+
GlobalC::ucell.nat))
146124
{
147125
GlobalV::ofs_running << " Read in the kinetic energy density: " << ssc.str() << std::endl;
148126
}

source/module_io/cube_io.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,13 @@ bool read_cube(
1313
const Parallel_Grid*const Pgrid,
1414
#endif
1515
const int my_rank,
16-
const int is,
1716
std::ofstream& ofs_running,
18-
const int nspin,
1917
const std::string& fn,
2018
double*const data,
2119
const int nx,
2220
const int ny,
2321
const int nz,
24-
double& ef,
25-
const UnitCell*const ucell,
26-
int& prenspin,
27-
const bool warning_flag = true);
22+
const int nat);
2823

2924
void write_cube(
3025
#ifdef __MPI

source/module_io/read_cube.cpp

Lines changed: 19 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
#include "module_io/cube_io.h"
2+
#include <limits>
23
// #include "module_base/global_variable.h" // GlobalV reference removed
34

45
bool ModuleIO::read_cube(
56
#ifdef __MPI
6-
const Parallel_Grid*const Pgrid,
7+
const Parallel_Grid* const Pgrid,
78
#endif
89
const int my_rank,
9-
const int is,
1010
std::ofstream& ofs_running,
11-
const int nspin,
1211
const std::string& fn,
13-
double*const data,
12+
double* const data,
1413
const int nx,
1514
const int ny,
1615
const int nz,
17-
double& ef,
18-
const UnitCell*const ucell,
19-
int& prenspin,
20-
const bool warning_flag)
16+
const int natom)
2117
{
22-
ModuleBase::TITLE("ModuleIO","read_cube");
18+
ModuleBase::TITLE("ModuleIO", "read_cube");
2319
std::ifstream ifs(fn.c_str());
2420
if (!ifs)
2521
{
@@ -33,90 +29,33 @@ bool ModuleIO::read_cube(
3329
ofs_running << " Find the file, try to read charge from file." << std::endl;
3430
}
3531

36-
bool quit=false;
37-
38-
ifs.ignore(300, '\n'); // skip the header
39-
40-
if(nspin != 4)
41-
{
42-
int v_in;
43-
ifs >> v_in;
44-
if (v_in != nspin)
45-
{
46-
std::cout << " WARNING: nspin mismatch: " << nspin << " in INPUT parameters but " << v_in << " in " << fn << std::endl;
47-
return false;
48-
}
49-
}
50-
else
51-
{
52-
ifs >> prenspin;
53-
}
54-
ifs.ignore(150, ')');
55-
56-
ifs >> ef;
57-
ofs_running << " read in fermi energy = " << ef << std::endl;
58-
59-
ifs.ignore(150, '\n');
60-
61-
ModuleBase::CHECK_INT(ifs, ucell->nat);
62-
ifs.ignore(150, '\n');
32+
// skip the first 3 lines
33+
for (int i = 0;i < 3;++i) { ifs.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); }
6334

6435
int nx_read = 0;
6536
int ny_read = 0;
6637
int nz_read = 0;
67-
double fac = ucell->lat0;
6838
std::string temp;
69-
if (warning_flag)
70-
{
71-
ifs >> nx_read;
72-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->latvec.e11 / double(nx), quit);
73-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->latvec.e12 / double(nx), quit);
74-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->latvec.e13 / double(nx), quit);
75-
ifs >> ny_read;
76-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->latvec.e21 / double(ny), quit);
77-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->latvec.e22 / double(ny), quit);
78-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->latvec.e23 / double(ny), quit);
79-
ifs >> nz_read;
80-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->latvec.e31 / double(nz), quit);
81-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->latvec.e32 / double(nz), quit);
82-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->latvec.e33 / double(nz), quit);
83-
}
84-
else
85-
{
86-
ifs >> nx_read;
87-
ifs >> temp >> temp >> temp;
88-
ifs >> ny_read;
89-
ifs >> temp >> temp >> temp;
90-
ifs >> nz_read;
91-
ifs >> temp >> temp >> temp;
92-
}
9339

94-
for (int it = 0; it < ucell->ntype; it++)
95-
{
96-
for (int ia = 0; ia < ucell->atoms[it].na; ia++)
97-
{
98-
ifs >> temp; // skip atomic number
99-
ifs >> temp; // skip Z valance
100-
if (warning_flag)
101-
{
102-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->atoms[it].tau[ia].x, quit);
103-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->atoms[it].tau[ia].y, quit);
104-
ModuleBase::CHECK_DOUBLE(ifs, fac * ucell->atoms[it].tau[ia].z, quit);
105-
}
106-
else
107-
{
108-
ifs >> temp >> temp >> temp;
109-
}
110-
}
111-
}
40+
ifs >> nx_read;
41+
ifs >> temp >> temp >> temp;
42+
ifs >> ny_read;
43+
ifs >> temp >> temp >> temp;
44+
ifs >> nz_read;
45+
ifs >> temp >> temp >> temp;
46+
47+
std::cout << "xyzread:" << nx_read << " " << ny_read << " " << nz_read << std::endl;
48+
49+
// skip this line and the next natom lines
50+
for (int i = 0;i < natom + 1;++i) { ifs.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); }
11251

11352
#ifdef __MPI
11453
if(nx == nx_read && ny == ny_read && nz == nz_read)
11554
ModuleIO::read_cube_core_match(ifs, Pgrid, (my_rank == 0), data, nx * ny, nz);
11655
else
11756
ModuleIO::read_cube_core_mismatch(ifs, Pgrid, (my_rank == 0), data, nx, ny, nz, nx_read, ny_read, nz_read);
11857
#else
119-
ofs_running << " Read SPIN = " << is + 1 << " charge now." << std::endl;
58+
12059
if(nx == nx_read && ny == ny_read && nz == nz_read)
12160
ModuleIO::read_cube_core_match(ifs, data, nx*ny, nz);
12261
else

source/module_io/test_serial/rho_io_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ TEST_F(RhoIOTest, Read)
9191
double ef;
9292
UcellTestPrepare utp = UcellTestLib["Si"];
9393
ucell = utp.SetUcellInfo();
94-
ModuleIO::read_cube(my_rank, is, ofs_running, nspin, fn, rho[is], nx, ny, nz, ef, ucell, prenspin);
95-
EXPECT_DOUBLE_EQ(ef, 0.461002);
94+
ModuleIO::read_cube(my_rank, ofs_running, fn, rho[is], nx, ny, nz, ucell->nat);
9695
EXPECT_DOUBLE_EQ(rho[0][0], 1.27020863940e-03);
9796
EXPECT_DOUBLE_EQ(rho[0][46655], 1.33581335706e-02);
9897
}

source/module_lr/esolver_lrtd_lcao.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,17 +659,13 @@ void LR::ESolver_LR<T, TR>::read_ks_chg(Charge& chg_gs)
659659
& (GlobalC::Pgrid),
660660
#endif
661661
GlobalV::MY_RANK,
662-
is,
663662
GlobalV::ofs_running,
664-
this->nspin,
665663
ssc.str(),
666664
chg_gs.rho[is],
667665
this->pw_rho->nx,
668666
this->pw_rho->ny,
669667
this->pw_rho->nz,
670-
ef,
671-
&(GlobalC::ucell),
672-
chg_gs.prenspin)) {
668+
ucell.nat)) {
673669
GlobalV::ofs_running << " Read in the charge density: " << ssc.str() << std::endl;
674670
} else { // prenspin for nspin=4 is not supported currently
675671
ModuleBase::WARNING_QUIT(

0 commit comments

Comments
 (0)