Skip to content

Commit 8a3ce55

Browse files
committed
change shared_ptr to raw pointer
1 parent 3d05448 commit 8a3ce55

File tree

6 files changed

+24
-23
lines changed

6 files changed

+24
-23
lines changed

source/module_esolver/esolver_ks_lcaopw.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ namespace ModuleESolver
139139
// It is not a good choice to overload another solve function here, this will spoil the concept of
140140
// multiple inheritance and polymorphism. But for now, we just do it in this way.
141141
// In the future, there will be a series of class ESolver_KS_LCAO_PW, HSolver_LCAO_PW and so on.
142-
std::weak_ptr<psi::Psi<T>> psig = this->p_wf_init->get_psig();
142+
auto psig = this->p_wf_init->get_psig();
143143

144-
if (psig.expired())
144+
if (/*psig.expired()*/ psig == nullptr)
145145
{
146146
ModuleBase::WARNING_QUIT("ESolver_KS_PW::hamilt2density_single", "psig lifetime is expired");
147147
}
148148

149149
hsolver::HSolverLIP<T> hsolver_lip_obj(this->pw_wfc);
150-
hsolver_lip_obj.solve(this->p_hamilt, this->kspw_psi[0], this->pelec, psig.lock().get()[0], skip_charge);
150+
hsolver_lip_obj.solve(this->p_hamilt, this->kspw_psi[0], this->pelec, psig[0], skip_charge);
151151

152152
// add exx
153153
#ifdef __EXX

source/module_io/to_wannier90_lcao_in_pw.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,16 @@ void toWannier90_LCAO_IN_PW::nao_G_expansion(
216216
{
217217
int npwx = wfcpw->npwk_max;
218218
this->psi_init_->proj_ao_onkG(ik);
219-
std::weak_ptr<psi::Psi<std::complex<double>>> psig = this->psi_init_->share_psig();
220-
if(psig.expired()) { ModuleBase::WARNING_QUIT("toWannier90_LCAO_IN_PW::nao_G_expansion", "psig is expired");
219+
auto psig = this->psi_init_->share_psig();
220+
if(/*psig.expired()*/ psig == nullptr) { ModuleBase::WARNING_QUIT("toWannier90_LCAO_IN_PW::nao_G_expansion", "psig is expired");
221221
}
222222
int nbands = PARAM.globalv.nlocal;
223223
int nbasis = npwx*PARAM.globalv.npol;
224224
for (int ib = 0; ib < nbands; ib++)
225225
{
226226
for (int ig = 0; ig < nbasis; ig++)
227227
{
228-
psi(ib, ig) = psig.lock().get()[0](ik, ib, ig);
228+
psi(ib, ig) = psig[0](ik, ib, ig);
229229
}
230230
}
231231
}

source/module_psi/psi_init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PSIInit
1717
const std::string& basis_type_in,
1818
const bool& use_psiinitializer_in,
1919
ModulePW::PW_Basis_K* pw_wfc_in);
20-
~PSIInit(){};
20+
~PSIInit(){ this->psi_init->deallocate_psig(); }
2121

2222
// prepare the wavefunction initialization
2323
void prepare_init(Structure_Factor* p_sf, //< structure factor

source/module_psi/psi_initializer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ class PsiInitializer
155155
void deallocate_psig()
156156
{
157157
// this->psig_.reset();
158-
delete this->d_psig_;
158+
delete this->d_psig_;
159+
this->d_psig_ = nullptr;
159160
}
160161
// tool methods
161162
// the following function is for compatibility concern, in ESolver_KS_PW the FPTYPE

source/module_psi/psi_initializer_atomic.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ template <typename T, typename Device>
165165
void PsiInitializerAtomic<T, Device>::proj_ao_onkG(const int ik)
166166
{
167167
ModuleBase::timer::tick("PsiInitializerAtomic", "proj_ao_onkG");
168-
const int ik_psig = (this->psig_->get_nk() == 1) ? 0 : ik;
169-
this->psig_->fix_k(ik_psig);
168+
const int ik_psig = (this->d_psig_->get_nk() == 1) ? 0 : ik;
169+
this->d_psig_->fix_k(ik_psig);
170170
//this->print_status(psi);
171171
const int npw = this->pw_wfc_->npwk[ik];
172172
int lmax = this->p_ucell_->lmax_ppwf;
@@ -247,7 +247,7 @@ void PsiInitializerAtomic<T, Device>::proj_ao_onkG(const int ik)
247247
}
248248
for(int ig = 0; ig < npw; ig++)
249249
{
250-
(*(this->psig_))(index,
250+
(*(this->d_psig_))(index,
251251
ig + this->pw_wfc_->npwk_max*is ) =
252252
this->template cast_to_T<T>(
253253
lphase * cg_coeffs[is] * sk[ig] * aux[ig] * ovlp_pswfcjlg[ig]
@@ -258,7 +258,7 @@ void PsiInitializerAtomic<T, Device>::proj_ao_onkG(const int ik)
258258
{
259259
for(int ig=0; ig < npw; ig++)
260260
{
261-
(*(this->psig_))(index,
261+
(*(this->d_psig_))(index,
262262
ig + this->pw_wfc_->npwk_max*is ) =
263263
this->template cast_to_T<T>(
264264
std::complex<double>(0.0, 0.0)
@@ -339,16 +339,16 @@ void PsiInitializerAtomic<T, Device>::proj_ao_onkG(const int ik)
339339
fdw = phase_factor(0.5*alpha, -1)*aux[ig];
340340
//build the orthogonal wfc
341341
//first rotation with angle (alpha + ModuleBase::PI) around (OX)
342-
(*(this->psig_))(index, ig) =
342+
(*(this->d_psig_))(index, ig) =
343343
this->template cast_to_T<T>(phase_factor(0.5*gamma, 0)*fup);
344-
(*(this->psig_))(index, ig+this->pw_wfc_->npwk_max) =
344+
(*(this->d_psig_))(index, ig+this->pw_wfc_->npwk_max) =
345345
this->template cast_to_T<T>(phase_factor(-0.5*gamma, 0)*fdw);
346346
//second rotation with angle gamma around(OZ)
347347
fup = phase_factor(0.5*(alpha + ModuleBase::PI), 1)*aux[ig];
348348
fdw = phase_factor(0.5*(alpha + ModuleBase::PI), -1)*aux[ig];
349-
(*(this->psig_))(index+2*l+1, ig) =
349+
(*(this->d_psig_))(index+2*l+1, ig) =
350350
this->template cast_to_T<T>(phase_factor(0.5*gamma, 0)*fup);
351-
(*(this->psig_))(index+2*l+1, ig+this->pw_wfc_->npwk_max) =
351+
(*(this->d_psig_))(index+2*l+1, ig+this->pw_wfc_->npwk_max) =
352352
this->template cast_to_T<T>(phase_factor(-0.5*gamma, 0)*fdw);
353353
}
354354
index++;
@@ -385,22 +385,22 @@ void PsiInitializerAtomic<T, Device>::proj_ao_onkG(const int ik)
385385
fdown = ModuleBase::IMAG_UNIT * sin(0.5* alpha) * aux[ig];
386386
//build the orthogonal wfc
387387
//first rotation with angle(alpha+ModuleBase::PI) around(OX)
388-
(*(this->psig_))(index, ig) =
388+
(*(this->d_psig_))(index, ig) =
389389
this->template cast_to_T<T>(
390390
(cos(0.5*gamman) + ModuleBase::IMAG_UNIT * sin(0.5*gamman)) * fup
391391
);
392-
(*(this->psig_))(index, ig+ this->pw_wfc_->npwk_max) =
392+
(*(this->d_psig_))(index, ig+ this->pw_wfc_->npwk_max) =
393393
this->template cast_to_T<T>(
394394
(cos(0.5*gamman) - ModuleBase::IMAG_UNIT * sin(0.5*gamman)) * fdown
395395
);
396396
//second rotation with angle gamma around(OZ)
397397
fup = cos(0.5 * (alpha + ModuleBase::PI)) * aux[ig];
398398
fdown = ModuleBase::IMAG_UNIT * sin(0.5 * (alpha + ModuleBase::PI)) * aux[ig];
399-
(*(this->psig_))(index+2*l+1, ig) =
399+
(*(this->d_psig_))(index+2*l+1, ig) =
400400
this->template cast_to_T<T>(
401401
(cos(0.5*gamman) + ModuleBase::IMAG_UNIT * sin(0.5*gamman)) * fup
402402
);
403-
(*(this->psig_))(index+2*l+1, ig+ this->pw_wfc_->npwk_max) =
403+
(*(this->d_psig_))(index+2*l+1, ig+ this->pw_wfc_->npwk_max) =
404404
this->template cast_to_T<T>(
405405
(cos(0.5*gamman) - ModuleBase::IMAG_UNIT * sin(0.5*gamman)) * fdown
406406
);
@@ -417,7 +417,7 @@ void PsiInitializerAtomic<T, Device>::proj_ao_onkG(const int ik)
417417
const int lm = l * l + m;
418418
for (int ig = 0; ig < npw; ig++)
419419
{
420-
(*(this->psig_))(index, ig) =
420+
(*(this->d_psig_))(index, ig) =
421421
this->template cast_to_T<T>(
422422
lphase * sk [ig] * ylm(lm, ig) * ovlp_pswfcjlg[ig]
423423
);
@@ -433,7 +433,7 @@ void PsiInitializerAtomic<T, Device>::proj_ao_onkG(const int ik)
433433
/* complement the rest of bands if there are */
434434
if(this->nbands_complem() > 0)
435435
{
436-
this->random_t(this->psig_->get_pointer(), index, this->psig_->get_nbands(), ik);
436+
this->random_t(this->d_psig_->get_pointer(), index, this->d_psig_->get_nbands(), ik);
437437
}
438438
ModuleBase::timer::tick("PsiInitializerAtomic", "proj_ao_onkG");
439439
}

source/module_psi/psi_initializer_random.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void PsiInitializerRandom<T, Device>::proj_ao_onkG(const int ik)
6161
ModuleBase::timer::tick("PsiInitializerRandom", "initialize");
6262
const int ik_psig = (this->d_psig_->get_nk() == 1) ? 0 : ik;
6363
this->d_psig_->fix_k(ik_psig);
64-
this->random(this->d_psig_->get_pointer(), 0, this->psig_->get_nbands(), ik);
64+
this->random(this->d_psig_->get_pointer(), 0, this->d_psig_->get_nbands(), ik);
6565
ModuleBase::timer::tick("PsiInitializerRandom", "initialize");
6666
}
6767

0 commit comments

Comments
 (0)