Skip to content

Commit cc2032b

Browse files
authored
Refactor ModuleIO::read/write_cube() (#5150)
* Refactor ModuleIO::read/write_cube() * Refactor ModuleIO::write_cube_core() * Refactor ModuleIO::read_cube_core() * add annotation in ModuleIO::read/write_cube_core()
1 parent 3835a26 commit cc2032b

File tree

5 files changed

+249
-186
lines changed

5 files changed

+249
-186
lines changed

source/module_hamilt_pw/hamilt_pwdft/parallel_grid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void Parallel_Grid::z_distribution(void)
182182

183183

184184
#ifdef __MPI
185-
void Parallel_Grid::zpiece_to_all(double *zpiece, const int &iz, double *rho)
185+
void Parallel_Grid::zpiece_to_all(double *zpiece, const int &iz, double *rho) const
186186
{
187187
if(PARAM.inp.esolver_type == "sdft")
188188
{
@@ -256,7 +256,7 @@ void Parallel_Grid::zpiece_to_all(double *zpiece, const int &iz, double *rho)
256256
#endif
257257

258258
#ifdef __MPI
259-
void Parallel_Grid::zpiece_to_stogroup(double *zpiece, const int &iz, double *rho)
259+
void Parallel_Grid::zpiece_to_stogroup(double *zpiece, const int &iz, double *rho) const
260260
{
261261
assert(allocate);
262262
//TITLE("Parallel_Grid","zpiece_to_all");

source/module_hamilt_pw/hamilt_pwdft/parallel_grid.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class Parallel_Grid
2121
const int &nczp, const int &nrxx, const int &nbz, const int &bz); //LiuXh add 20180606
2222

2323
#ifdef __MPI
24-
void zpiece_to_all(double *zpiece, const int &iz, double *rho);
25-
void zpiece_to_stogroup(double *zpiece, const int &iz, double *rho); //qainrui add for sto-dft 2021-7-21
24+
void zpiece_to_all(double *zpiece, const int &iz, double *rho) const;
25+
void zpiece_to_stogroup(double *zpiece, const int &iz, double *rho) const; //qainrui add for sto-dft 2021-7-21
2626

2727
void reduce_to_fullrho(double *rhotot, double *rhoin);
2828
#endif

source/module_io/cube_io.h

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,89 @@ namespace ModuleIO
1010
{
1111
bool read_cube(
1212
#ifdef __MPI
13-
Parallel_Grid* Pgrid,
13+
const Parallel_Grid*const Pgrid,
1414
#endif
15-
int my_rank,
16-
std::string esolver_type,
17-
int rank_in_stogroup,
18-
const int& is,
15+
const int my_rank,
16+
const std::string esolver_type,
17+
const int rank_in_stogroup,
18+
const int is,
1919
std::ofstream& ofs_running,
20-
const int& nspin,
20+
const int nspin,
2121
const std::string& fn,
22-
double* data,
23-
const int& nx,
24-
const int& ny,
25-
const int& nz,
22+
double*const data,
23+
const int nx,
24+
const int ny,
25+
const int nz,
2626
double& ef,
27-
const UnitCell* ucell,
27+
const UnitCell*const ucell,
2828
int& prenspin,
29-
const bool& warning_flag = true);
29+
const bool warning_flag = true);
3030

3131
void write_cube(
3232
#ifdef __MPI
33-
const int& bz,
34-
const int& nbz,
35-
const int& nplane,
36-
const int& startz_current,
33+
const int bz,
34+
const int nbz,
35+
const int nplane,
36+
const int startz_current,
3737
#endif
38-
const double* data,
39-
const int& is,
40-
const int& nspin,
41-
const int& iter,
38+
const double*const data,
39+
const int is,
40+
const int nspin,
41+
const int iter,
4242
const std::string& fn,
43-
const int& nx,
44-
const int& ny,
45-
const int& nz,
46-
const double& ef,
47-
const UnitCell* ucell,
48-
const int& precision = 11,
49-
const int& out_fermi = 1); // mohan add 2007-10-17
43+
const int nx,
44+
const int ny,
45+
const int nz,
46+
const double ef,
47+
const UnitCell*const ucell,
48+
const int precision = 11,
49+
const int out_fermi = 1); // mohan add 2007-10-17
50+
51+
52+
// when MPI:
53+
// read file as order (ixy,iz) to data[ixy*nz+iz]
54+
// when serial:
55+
// read file as order (ixy,iz) to data[iz*nxy+ixy]
56+
void read_cube_core_match(
57+
std::ifstream &ifs,
58+
#ifdef __MPI
59+
const Parallel_Grid*const Pgrid,
60+
const bool flag_read_rank,
61+
#endif
62+
double*const data,
63+
const int nxy,
64+
const int nz);
65+
66+
void read_cube_core_mismatch(
67+
std::ifstream &ifs,
68+
#ifdef __MPI
69+
const Parallel_Grid*const Pgrid,
70+
const bool flag_read_rank,
71+
#endif
72+
double*const data,
73+
const int nx,
74+
const int ny,
75+
const int nz,
76+
const int nx_read,
77+
const int ny_read,
78+
const int nz_read);
79+
80+
// when MPI:
81+
// write data[ixy*nplane+iz] to file as order (ixy,iz)
82+
// when serial:
83+
// write data[iz*nxy+ixy] to file as order (ixy,iz)
84+
void write_cube_core(
85+
std::ofstream &ofs_cube,
86+
#ifdef __MPI
87+
const int bz,
88+
const int nbz,
89+
const int nplane,
90+
const int startz_current,
91+
#endif
92+
const double*const data,
93+
const int nxy,
94+
const int nz,
95+
const int n_data_newline);
5096

5197
/**
5298
* @brief The trilinear interpolation method
@@ -86,7 +132,7 @@ void write_cube(
86132
const int& ny,
87133
const int& nz,
88134
#ifdef __MPI
89-
double** data
135+
std::vector<std::vector<double>> &data
90136
#else
91137
double* data
92138
#endif

0 commit comments

Comments
 (0)