Skip to content

Commit

Permalink
fix: the memory leak in berryphase (#4631)
Browse files Browse the repository at this point in the history
  • Loading branch information
pxlxingliang authored Jul 10, 2024
1 parent 94d0de0 commit 8009513
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
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 @@ -712,7 +712,7 @@ void ESolver_KS_LCAO<TK, TR>::nscf() {
if (berryphase::berry_phase_flag
&& ModuleSymmetry::Symmetry::symm_flag != 1) {
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "Berry phase calculation");
berryphase bp(this->orb_con.ParaV);
berryphase bp(&(this->orb_con.ParaV));
bp.lcao_init(this->kv,
this->GridT); // additional step before calling
// macroscopic_polarization (why capitalize
Expand Down
5 changes: 2 additions & 3 deletions source/module_io/berryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ berryphase::berryphase()
}

#ifdef __LCAO
berryphase::berryphase(const Parallel_Orbitals& paraV_in) : paraV(paraV_in)
berryphase::berryphase(const Parallel_Orbitals* paraV_in) : paraV(paraV_in)
{
GDIR = INPUT.gdir;
}
#endif

berryphase::~berryphase()
{
// GlobalV::ofs_running << "this is ~berryphase()" << std::endl;
}

void berryphase::get_occupation_bands()
Expand Down Expand Up @@ -347,7 +346,7 @@ double berryphase::stringPhase(int index_str,
if (GlobalV::NSPIN != 4)
{
// std::complex<double> my_det = lcao_method.det_berryphase(ik_1,ik_2,dk,nbands);
zeta = zeta * lcao_method.det_berryphase(ik_1, ik_2, dk, nbands, this->paraV, psi_in, kv);
zeta = zeta * lcao_method.det_berryphase(ik_1, ik_2, dk, nbands, *(this->paraV), psi_in, kv);
// test by jingan
// GlobalV::ofs_running << "methon 1: det = " << my_det << std::endl;
// test by jingan
Expand Down
4 changes: 2 additions & 2 deletions source/module_io/berryphase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class berryphase
public:
berryphase(); // for pw-line
#ifdef __LCAO
berryphase(const Parallel_Orbitals& paraV_in); // for lcao-line
berryphase(const Parallel_Orbitals* paraV_in); // for lcao-line
#endif
~berryphase();

Expand All @@ -25,7 +25,7 @@ class berryphase
unkOverlap_pw pw_method;
#ifdef __LCAO
unkOverlap_lcao lcao_method;
Parallel_Orbitals paraV;
const Parallel_Orbitals* paraV;
#endif

int total_string;
Expand Down
4 changes: 2 additions & 2 deletions source/module_io/unk_overlap_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ unkOverlap_lcao::~unkOverlap_lcao()
{
for (int iw = 0; iw < GlobalV::NLOCAL; iw++)
{
delete cal_tag[iw];
delete [] cal_tag[iw];
}
delete cal_tag;
delete [] cal_tag;
}

// GlobalV::ofs_running << "this is ~unkOverlap_lcao()" << std::endl;
Expand Down

0 comments on commit 8009513

Please sign in to comment.