Skip to content

Commit

Permalink
Refactor: delete unused code in src_ri ; remove GlobalC in `module_…
Browse files Browse the repository at this point in the history
…ri`, `src_ri` (#2325)

* delete exx_lcao.cpp

* delete Exx_Abfs, Abfs, DM3, Htime, Order, Schwarz

* delete exx_abfs-parrellel*

* delete DM, cauchy, util, 4lcaos

* delete unused headers

* GlobalC::kv -> pointer in RPA_LRI

* GlobalC::kv -> pointer in Exx_LRI

* GlobalC::kv -> parameter in Exx_IO

* delete unused code in abfs headers

* delete test code for unused code

* GlobalC::kv, symm -> parameter in Exx_Lip, CCPK

* unix2dos
  • Loading branch information
maki49 authored Apr 28, 2023
1 parent cd1de74 commit d5557f9
Show file tree
Hide file tree
Showing 79 changed files with 177 additions and 10,132 deletions.
18 changes: 1 addition & 17 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -401,33 +401,17 @@ OBJS_LCAO=DM_gamma.o\
dm_2d.o\
wavefunc_in_pw.o\

OBJS_SRC_RI=abfs.o\
conv_coulomb_pot.o\
OBJS_SRC_RI=conv_coulomb_pot.o\
conv_coulomb_pot_k.o\
exx_abfs.o \
exx_abfs-abfs_index.o \
exx_abfs-dm.o \
exx_abfs-inverse_matrix_double.o \
exx_abfs-jle.o \
exx_abfs-io.o \
exx_abfs-construct_orbs.o \
exx_abfs-matrix_orbs11.o \
exx_abfs-matrix_orbs21.o \
exx_abfs-matrix_orbs22.o \
exx_abfs-matrix_lcaoslcaos_lcaoslcaos.o \
exx_abfs-pca.o \
exx_abfs-parallel-communicate-function.o \
exx_abfs-parallel-communicate-dm3.o \
exx_abfs-parallel-communicate-dm3-allreduce.o \
exx_abfs-parallel-communicate-hexx.o \
exx_abfs-parallel-communicate-hexx-allreduce2.o \
exx_abfs-parallel-distribute-htime.o \
exx_abfs-parallel-distribute-kmeans.o \
exx_abfs-parallel-distribute-order.o \
exx_abfs-util.o \
exx_abfs-screen-schwarz.o \
exx_abfs-screen-cauchy.o \
exx_lcao.o \
exx_opt_orb.o \
exx_opt_orb-print.o \
exx_lip.o\
Expand Down
18 changes: 1 addition & 17 deletions source/module_esolver/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -395,33 +395,17 @@ OBJS_LCAO=DM_gamma.o\
dm_2d.o\
wavefunc_in_pw.o\

OBJS_SRC_RI=abfs.o\
conv_coulomb_pot.o\
OBJS_SRC_RI=conv_coulomb_pot.o\
conv_coulomb_pot_k.o\
exx_abfs.o \
exx_abfs-abfs_index.o \
exx_abfs-dm.o \
exx_abfs-inverse_matrix_double.o \
exx_abfs-jle.o \
exx_abfs-io.o \
exx_abfs-construct_orbs.o \
exx_abfs-matrix_orbs11.o \
exx_abfs-matrix_orbs21.o \
exx_abfs-matrix_orbs22.o \
exx_abfs-matrix_lcaoslcaos_lcaoslcaos.o \
exx_abfs-pca.o \
exx_abfs-parallel-communicate-function.o \
exx_abfs-parallel-communicate-dm3.o \
exx_abfs-parallel-communicate-dm3-allreduce.o \
exx_abfs-parallel-communicate-hexx.o \
exx_abfs-parallel-communicate-hexx-allreduce2.o \
exx_abfs-parallel-distribute-htime.o \
exx_abfs-parallel-distribute-kmeans.o \
exx_abfs-parallel-distribute-order.o \
exx_abfs-util.o \
exx_abfs-screen-schwarz.o \
exx_abfs-screen-cauchy.o \
exx_lcao.o \
exx_opt_orb.o \
exx_opt_orb-print.o \
exx_lip.o\
Expand Down
8 changes: 4 additions & 4 deletions source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ void ESolver_KS_LCAO::Init(Input& inp, UnitCell& ucell)

// GlobalC::exx_lcao.init();
if (GlobalC::exx_info.info_ri.real_number)
GlobalC::exx_lri_double.init(MPI_COMM_WORLD);
GlobalC::exx_lri_double.init(MPI_COMM_WORLD, GlobalC::kv);
else
GlobalC::exx_lri_complex.init(MPI_COMM_WORLD);
GlobalC::exx_lri_complex.init(MPI_COMM_WORLD, GlobalC::kv);
}
}
#endif
Expand Down Expand Up @@ -1179,8 +1179,8 @@ void ESolver_KS_LCAO::afterscf(const int istep)
// rpa_interface.rpa_exx_lcao().info.files_abfs = GlobalV::rpa_orbitals;
// rpa_interface.out_for_RPA(*(this->LOWF.ParaV), *(this->psi), this->LOC, this->pelec);
RPA_LRI<double> rpa_lri_double(GlobalC::exx_info.info_ri);
rpa_lri_double.cal_postSCF_exx(MPI_COMM_WORLD, this->LOC, *this->LOWF.ParaV);
rpa_lri_double.init(MPI_COMM_WORLD);
rpa_lri_double.cal_postSCF_exx(MPI_COMM_WORLD, GlobalC::kv, this->LOC, *this->LOWF.ParaV);
rpa_lri_double.init(MPI_COMM_WORLD, GlobalC::kv);
rpa_lri_double.out_for_RPA(*(this->LOWF.ParaV), *(this->psi), this->LOC, this->pelec);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion source/module_esolver/esolver_ks_lcao_elec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ namespace ModuleESolver
{
//program should be stopped after this judgement
Exx_Opt_Orb exx_opt_orb;
exx_opt_orb.generate_matrix();
exx_opt_orb.generate_matrix(GlobalC::kv);
ModuleBase::timer::tick("ESolver_KS_LCAO", "beforescf");
return;
}
Expand Down
79 changes: 0 additions & 79 deletions source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ void LCAO_Hamilt::calculate_HSR_sparse(const int &current_spin, const double &sp
#ifdef __MPI
if( GlobalC::exx_info.info_global.cal_exx )
{
//calculate_HR_exx_sparse(current_spin, sparse_threshold);
if(GlobalC::exx_info.info_ri.real_number)
this->calculate_HR_exx_sparse(current_spin, sparse_threshold, GlobalC::exx_lri_double.Hexxs);
else
Expand Down Expand Up @@ -728,84 +727,6 @@ void LCAO_Hamilt::calculat_HR_dftu_soc_sparse(const int &current_spin, const dou

}

#ifdef __EXX
// Peize Lin add 2021.11.16
void LCAO_Hamilt::calculate_HR_exx_sparse(const int &current_spin, const double &sparse_threshold)
{
ModuleBase::TITLE("LCAO_Hamilt","calculate_HR_exx_sparse");
ModuleBase::timer::tick("LCAO_Hamilt","calculate_HR_exx_sparse");

const Abfs::Vector3_Order<int> Rs_period(GlobalC::kv.nmp[0], GlobalC::kv.nmp[1], GlobalC::kv.nmp[2]);
if(Rs_period.x<=0 || Rs_period.y<=0 || Rs_period.z<=0)
throw std::invalid_argument("Rs_period = ("+ModuleBase::GlobalFunc::TO_STRING(Rs_period.x)+","+ModuleBase::GlobalFunc::TO_STRING(Rs_period.y)+","+ModuleBase::GlobalFunc::TO_STRING(Rs_period.z)+").\n"
+ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__));
const std::vector<Abfs::Vector3_Order<int>> Rs = Abfs::get_Born_von_Karmen_boxes( Rs_period );

const int ik_begin = (GlobalV::NSPIN==2) ? (current_spin*GlobalC::kv.nks/2) : 0;
const int ik_end = (GlobalV::NSPIN==2) ? ((current_spin+1)*GlobalC::kv.nks/2) : GlobalC::kv.nks;
const double frac = (GlobalV::NSPIN==1) ? 0.5 : 1.0; // Peize Lin add 2022.07.09

for(const Abfs::Vector3_Order<int> &R : Rs)
{
ModuleBase::matrix HexxR;
for(int ik=ik_begin; ik<ik_end; ++ik)
{
ModuleBase::matrix HexxR_tmp;
if(GlobalV::GAMMA_ONLY_LOCAL)
HexxR_tmp = GlobalC::exx_info.info_global.hybrid_alpha
* GlobalC::exx_lcao.Hexx_para.HK_Gamma_m2D[ik]
* (GlobalC::kv.wk[ik] * frac);
else
HexxR_tmp = GlobalC::exx_info.info_global.hybrid_alpha
* (GlobalC::exx_lcao.Hexx_para.HK_K_m2D[ik]
* std::exp( ModuleBase::TWO_PI*ModuleBase::IMAG_UNIT * (GlobalC::kv.kvec_c[ik] * (R*GlobalC::ucell.latvec)) )).real()
* (GlobalC::kv.wk[ik] * frac);

if(HexxR.c)
HexxR += HexxR_tmp;
else
HexxR = std::move(HexxR_tmp);
}

for(int iwt1_local=0; iwt1_local<HexxR.nr; ++iwt1_local)
{
const int iwt1_global = ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER()
? this->LM->ParaV->MatrixInfo.col_set[iwt1_local]
: this->LM->ParaV->MatrixInfo.row_set[iwt1_local];
for(int iwt2_local=0; iwt2_local<HexxR.nc; ++iwt2_local)
{
const int iwt2_global = ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER()
? this->LM->ParaV->MatrixInfo.row_set[iwt2_local]
: this->LM->ParaV->MatrixInfo.col_set[iwt2_local];
if(std::abs(HexxR(iwt1_local,iwt2_local)) > sparse_threshold)
{
if(GlobalV::NSPIN==1 || GlobalV::NSPIN==2)
{
auto &HR_sparse_ptr = this->LM->HR_sparse[current_spin][R][iwt1_global];
auto &HR_sparse = HR_sparse_ptr[iwt2_global];
HR_sparse += HexxR(iwt1_local,iwt2_local);
if(std::abs(HR_sparse) < sparse_threshold)
HR_sparse_ptr.erase(iwt2_global);
}
else
{
auto &HR_sparse_ptr = this->LM->HR_soc_sparse[R][iwt1_global];
auto &HR_sparse = HR_sparse_ptr[iwt2_global];
HR_sparse += HexxR(iwt1_local,iwt2_local);
if(std::abs(HR_sparse) < sparse_threshold)
HR_sparse_ptr.erase(iwt2_global);
}
}
}
}
}

// In the future it should be changed to mpi communication, since some Hexx(R) of R in Rs may be zeros
this->LM->all_R_coor.insert(Rs.begin(),Rs.end());

ModuleBase::timer::tick("LCAO_Hamilt","calculate_HR_exx_sparse");
}
#endif // __EXX

// in case there are elements smaller than the threshold
void LCAO_Hamilt::clear_zero_elements(const int &current_spin, const double &sparse_threshold)
Expand Down
1 change: 0 additions & 1 deletion source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class LCAO_Hamilt
void calculate_STN_R_sparse_for_T(const double &sparse_threshold);
void calculat_HR_dftu_sparse(const int &current_spin, const double &sparse_threshold);
void calculat_HR_dftu_soc_sparse(const int &current_spin, const double &sparse_threshold);
void calculate_HR_exx_sparse(const int &current_spin, const double &sparse_threshold);
#ifdef __EXX
template<typename Tdata> void calculate_HR_exx_sparse(const int &current_spin, const double &sparse_threshold,
const std::vector< std::map<int, std::map<std::pair<int,std::array<int,3>>, RI::Tensor<Tdata>>>> &Hexxs);
Expand Down
1 change: 0 additions & 1 deletion source/module_hamilt_lcao/hamilt_lcaodft/global_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace GlobalC
Grid_Driver GridD(GlobalV::test_deconstructor, GlobalV::test_grid_driver,GlobalV::test_grid);

#ifdef __EXX
Exx_Lcao exx_lcao(GlobalC::exx_info.info_global); // Peize Lin add 2016-12-03
Exx_LRI<double> exx_lri_double(GlobalC::exx_info.info_ri); // Peize Lin add 2022-08-06
Exx_LRI<std::complex<double>> exx_lri_complex(GlobalC::exx_info.info_ri); // Peize Lin add 2022-08-06
#endif
Expand Down
2 changes: 0 additions & 2 deletions source/module_hamilt_lcao/hamilt_lcaodft/global_fp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
#include "module_basis/module_ao/ORB_read.h"
#include "module_basis/module_ao/ORB_gen_tables.h"
#ifdef __EXX
#include "src_ri/exx_lcao.h"
#include "module_ri/Exx_LRI.h"
#endif

namespace GlobalC
{
extern Grid_Driver GridD;
#ifdef __EXX
extern Exx_Lcao exx_lcao; // Peize Lin add 2016-12-03
extern Exx_LRI<double> exx_lri_double; // Peize Lin add 2022-08-06
extern Exx_LRI<std::complex<double>> exx_lri_complex; // Peize Lin add 2022-08-06
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ void OperatorEXX<OperatorLCAO<double>>::contributeHk(int ik)
if(XC_Functional::get_func_type()==4 || XC_Functional::get_func_type()==5)
{
if(GlobalC::exx_info.info_ri.real_number)
RI_2D_Comm::add_Hexx(
ik,
RI_2D_Comm::add_Hexx(
GlobalC::kv,
ik,
GlobalC::exx_info.info_global.hybrid_alpha,
GlobalC::exx_lri_double.Hexxs,
*this->LM->ParaV,
*this->LM);
else
RI_2D_Comm::add_Hexx(
ik,
RI_2D_Comm::add_Hexx(
GlobalC::kv,
ik,
GlobalC::exx_info.info_global.hybrid_alpha,
GlobalC::exx_lri_complex.Hexxs,
*this->LM->ParaV,
Expand All @@ -52,15 +54,17 @@ void OperatorEXX<OperatorLCAO<std::complex<double>>>::contributeHk(int ik)
if(XC_Functional::get_func_type()==4 || XC_Functional::get_func_type()==5)
{
if(GlobalC::exx_info.info_ri.real_number)
RI_2D_Comm::add_Hexx(
ik,
RI_2D_Comm::add_Hexx(
GlobalC::kv,
ik,
GlobalC::exx_info.info_global.hybrid_alpha,
GlobalC::exx_lri_double.Hexxs,
*this->LM->ParaV,
*this->LM);
else
RI_2D_Comm::add_Hexx(
ik,
RI_2D_Comm::add_Hexx(
GlobalC::kv,
ik,
GlobalC::exx_info.info_global.hybrid_alpha,
GlobalC::exx_lri_complex.Hexxs,
*this->LM->ParaV,
Expand Down
5 changes: 3 additions & 2 deletions source/module_ri/Exx_LRI.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Exx_LRI
public:
Exx_LRI( const Exx_Info::Exx_Info_RI &info_in ) :info(info_in){}

void init(const MPI_Comm &mpi_comm_in);
void init(const MPI_Comm &mpi_comm_in, const K_Vectors &kv_in);
void cal_exx_ions();
void cal_exx_elec(const Local_Orbital_Charge &loc, const Parallel_Orbitals &pv);
void cal_exx_force();
Expand All @@ -53,7 +53,8 @@ class Exx_LRI

private:
const Exx_Info::Exx_Info_RI &info;
MPI_Comm mpi_comm;
MPI_Comm mpi_comm;
const K_Vectors *p_kv;

std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> lcaos;
std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> abfs;
Expand Down
15 changes: 8 additions & 7 deletions source/module_ri/Exx_LRI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include "RI_2D_Comm.h"
#include "RI_Util.h"
#include "src_ri/exx_abfs-construct_orbs.h"
#include "src_ri/exx_abfs-util.h"
#include "src_ri/exx_abfs-io.h"
#include "src_ri/conv_coulomb_pot_k.h"
#include "src_ri/conv_coulomb_pot_k-template.h"
#include "module_base/tool_title.h"
#include "module_base/timer.h"
#include "src_ri/serialization_cereal.h"
Expand All @@ -26,7 +26,7 @@
#include <string>

template<typename Tdata>
void Exx_LRI<Tdata>::init(const MPI_Comm &mpi_comm_in)
void Exx_LRI<Tdata>::init(const MPI_Comm &mpi_comm_in, const K_Vectors &kv_in)
{
ModuleBase::TITLE("Exx_LRI","init");
ModuleBase::timer::tick("Exx_LRI", "init");
Expand All @@ -48,7 +48,8 @@ void Exx_LRI<Tdata>::init(const MPI_Comm &mpi_comm_in)
// }


this->mpi_comm = mpi_comm_in;
this->mpi_comm = mpi_comm_in;
this->p_kv = &kv_in;

this->lcaos = Exx_Abfs::Construct_Orbs::change_orbs( GlobalC::ORB, this->info.kmesh_times );

Expand Down Expand Up @@ -78,7 +79,7 @@ void Exx_LRI<Tdata>::init(const MPI_Comm &mpi_comm_in)
throw std::domain_error(std::string(__FILE__)+" line "+std::to_string(__LINE__)); break;
}
};
this->abfs_ccp = Conv_Coulomb_Pot_K::cal_orbs_ccp( this->abfs, info.ccp_type, get_ccp_parameter(), this->info.ccp_rmesh_times );
this->abfs_ccp = Conv_Coulomb_Pot_K::cal_orbs_ccp( this->abfs, info.ccp_type, get_ccp_parameter(), this->info.ccp_rmesh_times, p_kv->nks );


for( size_t T=0; T!=this->abfs.size(); ++T )
Expand Down Expand Up @@ -112,7 +113,7 @@ void Exx_LRI<Tdata>::cal_exx_ions()
= {RI_Util::Vector3_to_array3(GlobalC::ucell.a1),
RI_Util::Vector3_to_array3(GlobalC::ucell.a2),
RI_Util::Vector3_to_array3(GlobalC::ucell.a3)};
const std::array<Tcell,Ndim> period = {GlobalC::kv.nmp[0], GlobalC::kv.nmp[1], GlobalC::kv.nmp[2]};
const std::array<Tcell,Ndim> period = {p_kv->nmp[0], p_kv->nmp[1], p_kv->nmp[2]};

this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period);

Expand Down Expand Up @@ -170,8 +171,8 @@ void Exx_LRI<Tdata>::cal_exx_elec(const Local_Orbital_Charge &loc, const Paralle

std::vector<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>> Ds =
GlobalV::GAMMA_ONLY_LOCAL
? RI_2D_Comm::split_m2D_ktoR<Tdata>(loc.dm_gamma, pv)
: RI_2D_Comm::split_m2D_ktoR<Tdata>(loc.dm_k, pv);
? RI_2D_Comm::split_m2D_ktoR<Tdata>(*p_kv, loc.dm_gamma, pv)
: RI_2D_Comm::split_m2D_ktoR<Tdata>(*p_kv, loc.dm_k, pv);

this->exx_lri.set_csm_threshold(this->info.cauchy_threshold);

Expand Down
7 changes: 4 additions & 3 deletions source/module_ri/RI_2D_Comm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "RI_2D_Comm.h"
#include "module_hamilt_pw/hamilt_pwdft/global.h"
#include "module_cell/klist.h"

#include <string>
#include <stdexcept>
Expand Down Expand Up @@ -60,11 +61,11 @@ auto RI_2D_Comm::get_2D_judge(const Parallel_Orbitals &pv)


std::vector<int>
RI_2D_Comm::get_ik_list(const int is_k)
RI_2D_Comm::get_ik_list(const K_Vectors &kv, const int is_k)
{
std::vector<int> ik_list;
for(int ik=0; ik<GlobalC::kv.nks; ++ik)
if(GlobalC::kv.isk[ik]==is_k)
for(int ik=0; ik<kv.nks; ++ik)
if(kv.isk[ik]==is_k)
ik_list.push_back(ik);
return ik_list;
}
Loading

0 comments on commit d5557f9

Please sign in to comment.