Skip to content

Commit 9c61d29

Browse files
authored
refactor: locate more functions into namespace ModuleIO (#1856)
* refactor: locate more functions into namespace ModuleIO * restore files in src_ri * remove charge_density.h * locate write_HS and write_wfc_realspace into ModuleIO * treat write_HS_R and rename psi to wfc * build write_HS_sparse.h * adjust header files * build write_occ and write_orb_info * locate write_dos_pw into ModuleIO * locate write_dos_lcao into ModuleIO * combine write_rho_cube with write_rho * Fix CI err * Fix CI err
1 parent 3137f62 commit 9c61d29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1874
-1909
lines changed

source/Makefile.Objects

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ OBJS_IO=input.o\
336336
berryphase.o\
337337
bessel_basis.o\
338338
cal_test.o\
339-
energy_dos_pw.o\
339+
write_occ.o\
340+
write_dos_pw.o\
340341
dos.o\
341342
numerical_descriptor.o\
342343
numerical_basis.o\
@@ -347,24 +348,27 @@ OBJS_IO=input.o\
347348
rwstream.o\
348349
to_wannier90.o\
349350
unk_overlap_pw.o\
350-
wf_io.o\
351+
write_wfc_pw.o\
351352
winput.o\
352353
write_input.o\
353354
write_rho.o\
354-
write_rho_cube.o\
355-
write_wfc_realspace.o\
355+
write_wfc_r.o\
356356

357357
OBJS_IO_LCAO=cal_r_overlap_R.o\
358-
energy_dos.o\
358+
write_orb_info.o\
359+
write_dos_lcao.o\
359360
istate_charge.o\
360361
istate_envelope.o\
361362
mulliken_charge.o\
362363
read_dm.o\
363364
unk_overlap_lcao.o\
364-
wf_local.o\
365+
read_wfc_nao.o\
366+
write_wfc_nao.o\
365367
write_HS.o\
368+
write_HS_sparse.o\
366369
write_HS_R.o\
367370
write_dm.o\
371+
write_dm_sparse.o\
368372

369373
OBJS_LCAO=DM_gamma.o\
370374
DM_k.o\

source/module_elecstate/energy.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ class energy
2727
energy();
2828
~energy();
2929

30-
//calculate density of states(DOS) and partial density of states(PDOS) and mulliken charge for LCAO base
31-
void perform_dos(
32-
const psi::Psi<double> *psid,
33-
const psi::Psi<std::complex<double>> *psi,
34-
LCAO_Hamilt &uhm,
35-
const elecstate::ElecState* pelec);
36-
//calculate density of states(DOS) for PW base
37-
void perform_dos_pw(const elecstate::ElecState* pelec);
38-
3930
double etot; // the total energy of the solid
4031
double ef; // the fermi energy
4132
double ef_up; // spin up fermi energy
@@ -98,12 +89,8 @@ class energy
9889
void print_etot(const bool converged, const int &iter,
9990
const double &scf_thr, const double &duration, const double &pw_diag_thr=0, const double &avg_iter=0, bool print = true);
10091

101-
void print_occ(const elecstate::ElecState* pelec);
102-
10392
void print_format(const std::string &name, const double &value);
10493

105-
void print_orbital_file();
106-
10794
void calculate_harris(); //mohan add 2012-06-05
10895

10996
double delta_e(const elecstate::ElecState* pelec);

source/module_elecstate/module_charge/charge.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <vector>
3030
#include "module_base/timer.h"
3131
#include "module_base/tool_threading.h"
32+
#include "module_io/rho_io.h"
3233

3334
Charge::Charge()
3435
{
@@ -157,7 +158,7 @@ void Charge::init_rho()
157158
ssc << GlobalV::global_readin_dir << "SPIN" << is + 1 << "_CHG";
158159
GlobalV::ofs_running << ssc.str() << std::endl;
159160
// mohan update 2012-02-10
160-
if (this->read_rho(is, ssc.str(), this->rho[is]))
161+
if (ModuleIO::read_rho(is, ssc.str(), this->rho[is], this->prenspin))
161162
{
162163
GlobalV::ofs_running << " Read in the charge density: " << ssc.str() << std::endl;
163164
}
@@ -212,7 +213,7 @@ void Charge::init_rho()
212213
ssc << GlobalV::global_readin_dir << "SPIN" << is + 1 << "_TAU";
213214
GlobalV::ofs_running << " try to read kinetic energy density from file : " << ssc.str() << std::endl;
214215
// mohan update 2012-02-10
215-
if (this->read_rho(is, ssc.str(), this->kin_r[is]))
216+
if (ModuleIO::read_rho(is, ssc.str(), this->kin_r[is], this->prenspin))
216217
{
217218
GlobalV::ofs_running << " Read in the kinetic energy density: " << ssc.str() << std::endl;
218219
}

source/module_elecstate/module_charge/charge.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ class Charge
7979

8080
public:
8181

82-
void write_rho(const double* rho_save, const int &is, const int &iter, const std::string &fn,
83-
const int &precision = 11, const bool for_plot = false);//mohan add 2007-10-17
84-
85-
void write_rho_cube(const double* rho_save, const int &is, const std::string &fn,
86-
const int &precision = 11);
87-
88-
bool read_rho(const int &is, const std::string &fn, double* rho);//mohan add 2007-10-17
8982
void rho_mpi(void);
9083

9184
// mohan add 2021-02-20

source/module_elecstate/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if(ENABLE_LCAO)
1313
../module_charge/charge.cpp ../../src_parallel/parallel_reduce.cpp
1414
../../module_hamilt_pw/hamilt_pwdft/structure_factor.cpp
1515
../../module_cell/klist.cpp ../../src_parallel/parallel_kpoints.cpp ../occupy.cpp
16-
../kernels/elecstate_op.cpp ../../module_io/rwstream.cpp ../../module_io/wf_io.cpp
16+
../kernels/elecstate_op.cpp ../../module_io/rwstream.cpp ../../module_io/write_wfc_pw.cpp
1717
)
1818

1919
install(DIRECTORY support DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

source/module_elecstate/test/elecstate_lcao_test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ XC_Functional::XC_Functional(){}
7474
XC_Functional::~XC_Functional(){}
7575
int XC_Functional::get_func_type(){return 0;}
7676

77-
namespace WF_Local
77+
namespace ModuleIO
7878
{
79-
int read_lowf(double** ctot, const int& is, const Parallel_Orbitals* ParaV, psi::Psi<double>*, elecstate::ElecState*) {return 1;};
80-
int read_lowf_complex(std::complex<double>** ctot, const int& ik, const Parallel_Orbitals* ParaV, psi::Psi<std::complex<double> >*, elecstate::ElecState*) {return 1;}
81-
void write_lowf(const std::string &name, double **ctot, const ModuleBase::matrix& ekb, const ModuleBase::matrix& wg) {}
82-
void write_lowf_complex(const std::string &name, std::complex<double>** ctot, const int &ik, const ModuleBase::matrix& ekb, const ModuleBase::matrix& wg) {}
79+
int read_wfc_nao(double** ctot, const int& is, const Parallel_Orbitals* ParaV, psi::Psi<double>*, elecstate::ElecState*) {return 1;};
80+
int read_wfc_nao_complex(std::complex<double>** ctot, const int& ik, const Parallel_Orbitals* ParaV, psi::Psi<std::complex<double> >*, elecstate::ElecState*) {return 1;}
81+
void write_wfc_nao(const std::string &name, double **ctot, const ModuleBase::matrix& ekb, const ModuleBase::matrix& wg) {}
82+
void write_wfc_nao_complex(const std::string &name, std::complex<double>** ctot, const int &ik, const ModuleBase::matrix& ekb, const ModuleBase::matrix& wg) {}
8383
}
8484

8585
//mock the unrelated functions in charge.cpp

source/module_elecstate/test/updaterhok_pw_test.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "updaterhok_pw_test.h"
1515
#include "module_io/berryphase.h"
16-
#include "module_io/wf_io.h"
16+
#include "module_io/write_wfc_pw.h"
1717
bool berryphase::berry_phase_flag;
1818
using::testing::AtLeast;
1919
using::testing::Assign;
@@ -146,6 +146,7 @@ struct ENVPrepare
146146
std::string init_wfc_;
147147
int out_wfc_pw_;
148148
std::string out_dir_;
149+
int prenspin_;
149150
// default values
150151
ENVPrepare()
151152
{
@@ -180,7 +181,8 @@ struct ENVPrepare
180181
init_chg_ = "atomic";
181182
init_wfc_ = "atomic";
182183
out_wfc_pw_ = 1;
183-
out_dir_="./support/";
184+
out_dir_="./support/";
185+
prenspin_ = 1;
184186
}
185187
};
186188

@@ -207,8 +209,8 @@ class ENVEnvironment : public ::testing::Environment
207209
GlobalV::stru_file = env->stru_file_;
208210
running_log = env->running_log_;
209211
// INPUT is an object of Input, and declared in input.h
210-
GlobalC::ucell.latName = env->latname_;
211-
GlobalC::ucell.ntype = env->ntype_;
212+
GlobalC::ucell.latName = env->latname_;
213+
GlobalC::ucell.ntype = env->ntype_;
212214
// important in pseudo_nc::set_pseudo_atom
213215
GlobalV::PSEUDORCUT = env->pseudo_rcut_;
214216
ModuleSymmetry::Symmetry::symm_flag = env->symm_flag_;
@@ -233,8 +235,9 @@ class ENVEnvironment : public ::testing::Environment
233235
INPUT.cell_factor = env->cell_factor_;
234236
GlobalV::init_chg = env->init_chg_;
235237
GlobalC::wf.init_wfc = env->init_wfc_;
236-
GlobalC::wf.out_wfc_pw = env->out_wfc_pw_;
237-
GlobalV::global_out_dir = env->out_dir_;
238+
GlobalC::wf.out_wfc_pw = env->out_wfc_pw_;
239+
GlobalV::global_out_dir = env->out_dir_;
240+
GlobalC::CHR.prenspin = env->prenspin_;
238241
}
239242

240243
void set_variables_in_set_up(ENVPrepare* envtmp)
@@ -326,8 +329,8 @@ TEST_F(EState,RhoPW)
326329
{
327330
std::stringstream ssw;
328331
ssw << "WFC";
329-
WF_io::write_wfc(ssw.str(), psi[0], &GlobalC::kv, GlobalC::wfcpw);
330-
remove("WFC1.dat");
332+
ModuleIO::write_wfc_pw(ssw.str(), psi[0], &GlobalC::kv, GlobalC::wfcpw);
333+
remove("WFC1.dat");
331334
}
332335

333336
// copy data from old wf.evc to new evc(an object of Psi)
@@ -370,7 +373,7 @@ TEST_F(EState,RhoPW)
370373
rho_for_compare[is] = new double[GlobalC::rhopw->nrxx];
371374
std::stringstream ssc;
372375
ssc <<GlobalV::global_out_dir<< "SPIN" << is + 1 << "_CHG";
373-
GlobalC::CHR.read_rho(is, ssc.str(), rho_for_compare[is]);
376+
ModuleIO::read_rho(is, ssc.str(), rho_for_compare[is],GlobalC::CHR.prenspin);
374377
for (int ix = 0; ix < GlobalC::rhopw->nrxx; ix++)
375378
//for (int ix = 0; ix < 5; ix++)
376379
{

source/module_elecstate/test/updaterhok_pw_test.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "module_hamilt_general/module_xc/xc_functional.h"
2222
#include "module_pw/pw_basis_k.h"
2323
#include "module_io/restart.h"
24+
#include "module_io/rho_io.h"
2425

2526
int ModuleSymmetry::Symmetry::symm_flag;
2627

@@ -103,7 +104,7 @@ psi::Psi<complex<double>>* wavefunc::allocate(const int nks)
103104
return psi;
104105
}
105106

106-
bool Charge::read_rho(const int &is, const std::string &fn, double* rho) //add by dwan
107+
bool ModuleIO::read_rho(const int &is, const std::string &fn, double* rho, int &prenspin) //add by dwan
107108
{
108109
std::ifstream ifs(fn.c_str());
109110

@@ -322,4 +323,4 @@ bool UnitCell::read_atom_positions(LCAO_Orbitals &orb, std::ifstream &ifpos, std
322323
void elecstate::Potential::init_pot(int istep, const Charge* chg)
323324
{
324325
return;
325-
}
326+
}

source/module_esolver/Makefile.Objects

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ OBJS_IO=input.o\
336336
berryphase.o\
337337
bessel_basis.o\
338338
cal_test.o\
339-
energy_dos_pw.o\
339+
write_dos_pw.o\
340340
dos.o\
341341
numerical_descriptor.o\
342342
numerical_basis.o\
@@ -347,24 +347,26 @@ OBJS_IO=input.o\
347347
rwstream.o\
348348
to_wannier90.o\
349349
unk_overlap_pw.o\
350-
wf_io.o\
350+
write_wfc_pw.o\
351351
winput.o\
352352
write_input.o\
353353
write_rho.o\
354-
write_rho_cube.o\
355354
write_wfc_realspace.o\
356355

357356
OBJS_IO_LCAO=cal_r_overlap_R.o\
358-
energy_dos.o\
357+
write_dos_lcao.o\
359358
istate_charge.o\
360359
istate_envelope.o\
361360
mulliken_charge.o\
362361
read_dm.o\
363362
unk_overlap_lcao.o\
364-
wf_local.o\
363+
read_wfc_nao.o\
364+
write_wfc_nao.o\
365365
write_HS.o\
366+
write_HS_sparse.o\
366367
write_HS_R.o\
367368
write_dm.o\
369+
write_dm_sparse.o\
368370

369371
OBJS_LCAO=DM_gamma.o\
370372
DM_k.o\

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include "esolver_ks_lcao.h"
22
#include "module_io/cal_r_overlap_R.h"
3-
#include "module_io/density_matrix.h"
3+
#include "module_io/dm_io.h"
4+
#include "module_io/write_dm_sparse.h"
5+
#include "module_io/rho_io.h"
6+
#include "module_io/write_HS_R.h"
7+
#include "module_io/write_dos_lcao.h"
48

59
//--------------temporary----------------------------
610
#include "module_base/global_function.h"
@@ -227,7 +231,19 @@ void ESolver_KS_LCAO::postprocess()
227231
GlobalV::ofs_running << " !FINAL_ETOT_IS " << GlobalC::en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl;
228232
GlobalV::ofs_running << " --------------------------------------------\n\n" << std::endl;
229233

230-
GlobalC::en.perform_dos(this->psid, this->psi, this->UHM, this->pelec);
234+
ModuleIO::write_dos_lcao(this->psid,
235+
this->psi,
236+
this->UHM,
237+
this->pelec,
238+
GlobalC::en.out_dos,
239+
GlobalC::en.out_band,
240+
GlobalC::en.out_proj_band,
241+
GlobalC::en.dos_edelta_ev,
242+
GlobalC::en.bcoeff,
243+
GlobalC::en.dos_scale,
244+
GlobalC::en.ef,
245+
GlobalC::en.ef_up,
246+
GlobalC::en.ef_dw);
231247
}
232248

233249
void ESolver_KS_LCAO::Init_Basis_lcao(ORB_control& orb_con, Input& inp, UnitCell& ucell)
@@ -547,9 +563,7 @@ void ESolver_KS_LCAO::eachiterfinish(int iter)
547563
std::stringstream ss1;
548564
ssc << GlobalV::global_out_dir << "tmp"
549565
<< "_SPIN" << is + 1 << "_CHG";
550-
pelec->charge->write_rho(pelec->charge->rho_save[is], is, iter, ssc.str(), precision); // mohan add 2007-10-17
551-
ss1 << GlobalV::global_out_dir << "tmp" << "_SPIN" << is + 1 << "_CHG.cube";
552-
pelec->charge->write_rho_cube(pelec->charge->rho_save[is], is, ss1.str(), 3);
566+
ModuleIO::write_rho(pelec->charge->rho_save[is], is, iter, ssc.str(), precision); // mohan add 2007-10-17
553567

554568
std::stringstream ssd;
555569

@@ -575,9 +589,7 @@ void ESolver_KS_LCAO::eachiterfinish(int iter)
575589
std::stringstream ss1;
576590
ssc << GlobalV::global_out_dir << "tmp"
577591
<< "_SPIN" << is + 1 << "_TAU";
578-
pelec->charge->write_rho(pelec->charge->kin_r_save[is], is, iter, ssc.str(), precision); // mohan add 2007-10-17
579-
ss1 << GlobalV::global_out_dir << "tmp" << "_SPIN" << is + 1 << "_TAU.cube";
580-
pelec->charge->write_rho_cube(pelec->charge->kin_r_save[is], is, ss1.str(), 3);
592+
ModuleIO::write_rho(pelec->charge->kin_r_save[is], is, iter, ssc.str(), precision); // mohan add 2007-10-17
581593
}
582594
}
583595

@@ -616,9 +628,7 @@ void ESolver_KS_LCAO::afterscf(const int istep)
616628
std::stringstream ssc;
617629
std::stringstream ss1;
618630
ssc << GlobalV::global_out_dir << "SPIN" << is + 1 << "_CHG";
619-
ss1 << GlobalV::global_out_dir << "SPIN" << is + 1 << "_CHG.cube";
620-
pelec->charge->write_rho(pelec->charge->rho_save[is], is, 0, ssc.str()); // mohan add 2007-10-17
621-
pelec->charge->write_rho_cube(pelec->charge->rho_save[is], is, ss1.str(), 3);
631+
ModuleIO::write_rho(pelec->charge->rho_save[is], is, 0, ssc.str()); // mohan add 2007-10-17
622632

623633
std::stringstream ssd;
624634
if (GlobalV::GAMMA_ONLY_LOCAL)
@@ -651,9 +661,7 @@ void ESolver_KS_LCAO::afterscf(const int istep)
651661
std::stringstream ssc;
652662
std::stringstream ss1;
653663
ssc << GlobalV::global_out_dir << "SPIN" << is + 1 << "_TAU";
654-
ss1 << GlobalV::global_out_dir << "SPIN" << is + 1 << "_TAU.cube";
655-
pelec->charge->write_rho(pelec->charge->kin_r_save[is], is, 0, ssc.str()); // mohan add 2007-10-17
656-
pelec->charge->write_rho_cube(pelec->charge->kin_r_save[is], is, ss1.str(), 3);
664+
ModuleIO::write_rho(pelec->charge->kin_r_save[is], is, 0, ssc.str()); // mohan add 2007-10-17
657665
}
658666
}
659667

@@ -894,7 +902,7 @@ void ESolver_KS_LCAO::afterscf(const int istep)
894902
{
895903
if( !(GlobalV::CALCULATION=="md" && (istep%hsolver::HSolverLCAO::out_hsR_interval!=0)) )
896904
{
897-
this->output_HS_R(istep, this->pelec->pot->get_effective_v()); // LiuXh add 2019-07-15
905+
ModuleIO::output_HS_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15
898906
} // LiuXh add 2019-07-15
899907
}
900908

0 commit comments

Comments
 (0)