Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ModuleIO::read/write_cube() #5109

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/module_hamilt_pw/hamilt_pwdft/parallel_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void Parallel_Grid::z_distribution(void)


#ifdef __MPI
void Parallel_Grid::zpiece_to_all(double *zpiece, const int &iz, double *rho)
void Parallel_Grid::zpiece_to_all(double *zpiece, const int &iz, double *rho) const
{
if(PARAM.inp.esolver_type == "sdft")
{
Expand Down Expand Up @@ -256,7 +256,7 @@ void Parallel_Grid::zpiece_to_all(double *zpiece, const int &iz, double *rho)
#endif

#ifdef __MPI
void Parallel_Grid::zpiece_to_stogroup(double *zpiece, const int &iz, double *rho)
void Parallel_Grid::zpiece_to_stogroup(double *zpiece, const int &iz, double *rho) const
{
assert(allocate);
//TITLE("Parallel_Grid","zpiece_to_all");
Expand Down
4 changes: 2 additions & 2 deletions source/module_hamilt_pw/hamilt_pwdft/parallel_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Parallel_Grid
const int &nczp, const int &nrxx, const int &nbz, const int &bz); //LiuXh add 20180606

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

void reduce_to_fullrho(double *rhotot, double *rhoin);
#endif
Expand Down
100 changes: 69 additions & 31 deletions source/module_io/cube_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,83 @@

namespace ModuleIO
{
bool read_cube(
extern bool read_cube(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you explain why you add extern here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing extern explicitly will ask the compiler to report an error if the functions in .h and .cpp are different.

#ifdef __MPI
Parallel_Grid* Pgrid,
const Parallel_Grid*const Pgrid,
#endif
int my_rank,
std::string esolver_type,
int rank_in_stogroup,
const int& is,
const int my_rank,
const std::string esolver_type,
const int rank_in_stogroup,
const int is,
std::ofstream& ofs_running,
const int& nspin,
const int nspin,
const std::string& fn,
double* data,
const int& nx,
const int& ny,
const int& nz,
double*const data,
const int nx,
const int ny,
const int nz,
double& ef,
const UnitCell* ucell,
const UnitCell*const ucell,
int& prenspin,
const bool& warning_flag = true);
const bool warning_flag = true);

void write_cube(
extern void write_cube(
#ifdef __MPI
const int& bz,
const int& nbz,
const int& nplane,
const int& startz_current,
const int bz,
const int nbz,
const int nplane,
const int startz_current,
#endif
const double* data,
const int& is,
const int& nspin,
const int& iter,
const double*const data,
const int is,
const int nspin,
const int iter,
const std::string& fn,
const int& nx,
const int& ny,
const int& nz,
const double& ef,
const UnitCell* ucell,
const int& precision = 11,
const int& out_fermi = 1); // mohan add 2007-10-17
const int nx,
const int ny,
const int nz,
const double ef,
const UnitCell*const ucell,
const int precision = 11,
const int out_fermi = 1); // mohan add 2007-10-17


extern void read_cube_core_match(
std::ifstream &ifs,
#ifdef __MPI
const Parallel_Grid*const Pgrid,
const bool flag_read_rank,
#endif
double*const data,
const int nxy,
const int nz);

extern void read_cube_core_mismatch(
std::ifstream &ifs,
#ifdef __MPI
const Parallel_Grid*const Pgrid,
const bool flag_read_rank,
#endif
double*const data,
const int nx,
const int ny,
const int nz,
const int nx_read,
const int ny_read,
const int nz_read);

extern void write_cube_core(
std::ofstream &ofs_cube,
#ifdef __MPI
const int bz,
const int nbz,
const int nplane,
const int startz_current,
#endif
const double*const data,
const int nxy,
const int nz,
const int n_data_newline);

/**
* @brief The trilinear interpolation method
Expand Down Expand Up @@ -78,15 +116,15 @@ void write_cube(
* @param nz the dimension of grids along z
* @param data the interpolated results
*/
void trilinear_interpolate(std::ifstream& ifs,
extern void trilinear_interpolate(std::ifstream& ifs,
const int& nx_read,
const int& ny_read,
const int& nz_read,
const int& nx,
const int& ny,
const int& nz,
#ifdef __MPI
double** data
std::vector<std::vector<double>> &data
#else
double* data
#endif
Expand Down
Loading
Loading