Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 6 additions & 10 deletions source/source_esolver/esolver_ks_lcaopw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ namespace ModuleESolver
//****************************************************
delete this->psi_local;
// delete Hamilt
this->deallocate_hamilt();
if (this->p_hamilt != nullptr)
{
delete this->p_hamilt;
this->p_hamilt = nullptr;
}
}

template <typename T>
Expand All @@ -68,15 +72,7 @@ namespace ModuleESolver
#endif
);
}
template <typename T>
void ESolver_KS_LIP<T>::deallocate_hamilt()
{
if (this->p_hamilt != nullptr)
{
delete reinterpret_cast<hamilt::HamiltLIP<T>*>(this->p_hamilt);
this->p_hamilt = nullptr;
}
}

template <typename T>
void ESolver_KS_LIP<T>::before_scf(UnitCell& ucell, const int istep)
{
Expand Down
1 change: 0 additions & 1 deletion source/source_esolver/esolver_ks_lcaopw.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace ModuleESolver
const double ethr) override;

virtual void allocate_hamilt(const UnitCell& ucell) override;
virtual void deallocate_hamilt() override;

psi::Psi<T, base_device::DEVICE_CPU>* psi_local = nullptr; ///< psi for all local NAOs

Expand Down
29 changes: 15 additions & 14 deletions source/source_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ ESolver_KS_PW<T, Device>::~ESolver_KS_PW()
// do not add any codes in this deconstructor funcion
//****************************************************
// delete Hamilt
this->deallocate_hamilt();
if (this->p_hamilt != nullptr)
{
delete this->p_hamilt;
this->p_hamilt = nullptr;
}

// delete exx_helper
if (this->exx_helper != nullptr)
Expand All @@ -77,15 +81,7 @@ void ESolver_KS_PW<T, Device>::allocate_hamilt(const UnitCell& ucell)
&ucell);
}

template <typename T, typename Device>
void ESolver_KS_PW<T, Device>::deallocate_hamilt()
{
if (this->p_hamilt != nullptr)
{
delete static_cast<hamilt::HamiltPW<T, Device>*>(this->p_hamilt);
this->p_hamilt = nullptr;
}
}


template <typename T, typename Device>
void ESolver_KS_PW<T, Device>::before_all_runners(UnitCell& ucell, const Input_para& inp)
Expand Down Expand Up @@ -147,14 +143,17 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)

if (ucell.cell_parameter_updated)
{
auto* p_psi_init = static_cast<psi::PSIPrepare<T, Device>*>(this->stp.p_psi_init);
p_psi_init->prepare_init(PARAM.inp.pw_seed);
this->stp.p_psi_init->prepare_init(PARAM.inp.pw_seed);
}

//! Init Hamiltonian (cell changed)
//! Operators in HamiltPW should be reallocated once cell changed
//! delete Hamilt if not first scf
this->deallocate_hamilt();
if (this->p_hamilt != nullptr)
{
delete this->p_hamilt;
this->p_hamilt = nullptr;
}

//! Allocate HamiltPW
this->allocate_hamilt(ucell);
Expand All @@ -164,7 +163,9 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)
// init DFT+U is done in "before_all_runners" in LCAO basis. This should be refactored, mohan note 2025-11-06
pw::setup_pot(istep, ucell, this->kv, this->sf, this->pelec, this->Pgrid,
this->chr, this->locpp, this->ppcell, this->dftu, this->vsep_cell,
this->stp.template get_psi_t<T, Device>(), static_cast<hamilt::Hamilt<T, Device>*>(this->p_hamilt), this->pw_wfc, this->pw_rhod, PARAM.inp);
this->stp.template get_psi_t<T, Device>(),
this->p_hamilt,
this->pw_wfc, this->pw_rhod, PARAM.inp);

// setup psi (electronic wave functions)
this->stp.init(this->p_hamilt);
Expand Down
1 change: 0 additions & 1 deletion source/source_esolver/esolver_ks_pw.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class ESolver_KS_PW : public ESolver_KS
virtual void hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override;

virtual void allocate_hamilt(const UnitCell& ucell);
virtual void deallocate_hamilt();

// Electronic wave function psi
Setup_Psi_pw stp;
Expand Down
1 change: 1 addition & 0 deletions source/source_psi/psi_prepare_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PSIPrepareBase
public:
PSIPrepareBase() = default;
virtual ~PSIPrepareBase() = default;
virtual void prepare_init(const int& random_seed) = 0;
};

} // namespace psi
Expand Down
214 changes: 107 additions & 107 deletions source/source_pw/module_pwdft/setup_pot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@

template <typename T, typename Device>
void pw::setup_pot(const int istep,
UnitCell& ucell, // unitcell
const K_Vectors &kv, // kpoints
UnitCell& ucell, // unitcell
const K_Vectors &kv, // kpoints
Structure_Factor &sf, // structure factors
elecstate::ElecState *pelec, // pointer of electrons
const Parallel_Grid &para_grid, // parallel of FFT grids
const Charge &chr, // charge density
pseudopot_cell_vl &locpp, // local pseudopotentials
pseudopot_cell_vnl &ppcell, // non-local pseudopotentials
elecstate::ElecState *pelec, // pointer of electrons
const Parallel_Grid &para_grid, // parallel of FFT grids
const Charge &chr, // charge density
pseudopot_cell_vl &locpp, // local pseudopotentials
pseudopot_cell_vnl &ppcell, // non-local pseudopotentials
Plus_U &dftu, // mohan add 2025-11-06
VSep* vsep_cell, // U-1/2 method
psi::Psi<T, Device>* kspw_psi, // electronic wave functions
hamilt::Hamilt<T, Device>* p_hamilt, // hamiltonian
ModulePW::PW_Basis_K *pw_wfc, // pw for wfc
const ModulePW::PW_Basis *pw_rhod, // pw for rhod
const Input_para& inp) // input parameters
VSep* vsep_cell, // U-1/2 method
psi::Psi<T, Device>* kspw_psi, // electronic wave functions
hamilt::HamiltBase* p_hamilt, // hamiltonian
ModulePW::PW_Basis_K *pw_wfc, // pw for wfc
const ModulePW::PW_Basis *pw_rhod, // pw for rhod
const Input_para& inp) // input parameters
{
ModuleBase::TITLE("pw", "setup_pot");

Expand All @@ -41,48 +41,48 @@ void pw::setup_pot(const int istep,
pelec->init_scf(ucell, para_grid, sf.strucFac,
locpp.numeric, ucell.symm, (void*)pw_wfc);

//----------------------------------------------------------
//! 2) Symmetrize the charge density (rho)
//----------------------------------------------------------

//! Symmetry_rho should behind init_scf, because charge should be
//! initialized first. liuyu comment: Symmetry_rho should be
//! located between init_rho and v_of_rho?
Symmetry_rho srho;
for (int is = 0; is < inp.nspin; is++)
{
srho.begin(is, chr, pw_rhod, ucell.symm);
}

//----------------------------------------------------------
//! 3) Calculate the effective potential with rho
//----------------------------------------------------------
//! liuyu move here 2023-10-09
//! D in uspp need vloc, thus behind init_scf()
//! calculate the effective coefficient matrix
//! for non-local pseudopotential projectors
ModuleBase::matrix veff = pelec->pot->get_eff_v();

ppcell.cal_effective_D(veff, pw_rhod, ucell);

//----------------------------------------------------------
//! 4) Onsite projectors
//----------------------------------------------------------
if (PARAM.inp.onsite_radius > 0)
{
auto* onsite_p = projectors::OnsiteProjector<double, Device>::get_instance();
onsite_p->init(PARAM.inp.orbital_dir,
&ucell,
*(kspw_psi),
kv,
*(pw_wfc),
sf,
PARAM.inp.onsite_radius,
PARAM.globalv.nqx,
PARAM.globalv.dq,
pelec->wg,
pelec->ekb);
}
//----------------------------------------------------------
//! 2) Symmetrize the charge density (rho)
//----------------------------------------------------------

//! Symmetry_rho should behind init_scf, because charge should be
//! initialized first. liuyu comment: Symmetry_rho should be
//! located between init_rho and v_of_rho?
Symmetry_rho srho;
for (int is = 0; is < inp.nspin; is++)
{
srho.begin(is, chr, pw_rhod, ucell.symm);
}

//----------------------------------------------------------
//! 3) Calculate the effective potential with rho
//----------------------------------------------------------
//! liuyu move here 2023-10-09
//! D in uspp need vloc, thus behind init_scf()
//! calculate the effective coefficient matrix
//! for non-local pseudopotential projectors
ModuleBase::matrix veff = pelec->pot->get_eff_v();

ppcell.cal_effective_D(veff, pw_rhod, ucell);

//----------------------------------------------------------
//! 4) Onsite projectors
//----------------------------------------------------------
if (PARAM.inp.onsite_radius > 0)
{
auto* onsite_p = projectors::OnsiteProjector<double, Device>::get_instance();
onsite_p->init(PARAM.inp.orbital_dir,
&ucell,
*(kspw_psi),
kv,
*(pw_wfc),
sf,
PARAM.inp.onsite_radius,
PARAM.globalv.nqx,
PARAM.globalv.dq,
pelec->wg,
pelec->ekb);
}

//----------------------------------------------------------
//! 5) Spin-constrained algorithms
Expand Down Expand Up @@ -126,77 +126,77 @@ void pw::setup_pot(const int istep,

template void pw::setup_pot<std::complex<float>, base_device::DEVICE_CPU>(
const int istep, // ionic step
UnitCell& ucell, // unitcell
const K_Vectors &kv, // kpoints
UnitCell& ucell, // unitcell
const K_Vectors &kv, // kpoints
Structure_Factor &sf, // structure factors
elecstate::ElecState *pelec, // pointer of electrons
const Parallel_Grid &para_grid, // parallel of FFT grids
const Charge &chr, // charge density
pseudopot_cell_vl &locpp, // local pseudopotentials
pseudopot_cell_vnl &ppcell, // non-local pseudopotentials
elecstate::ElecState *pelec, // pointer of electrons
const Parallel_Grid &para_grid, // parallel of FFT grids
const Charge &chr, // charge density
pseudopot_cell_vl &locpp, // local pseudopotentials
pseudopot_cell_vnl &ppcell, // non-local pseudopotentials
Plus_U &dftu, // mohan add 2025-11-06
VSep* vsep_cell, // U-1/2 method
psi::Psi<std::complex<float>, base_device::DEVICE_CPU>* kspw_psi, // electronic wave functions
hamilt::Hamilt<std::complex<float>, base_device::DEVICE_CPU>* p_hamilt, // hamiltonian
ModulePW::PW_Basis_K *pw_wfc, // pw for wfc
const ModulePW::PW_Basis *pw_rhod, // pw for rhod
const Input_para& inp); // input parameters
VSep* vsep_cell, // U-1/2 method
psi::Psi<std::complex<float>, base_device::DEVICE_CPU>* kspw_psi, // electronic wave functions
hamilt::HamiltBase* p_hamilt, // hamiltonian
ModulePW::PW_Basis_K *pw_wfc, // pw for wfc
const ModulePW::PW_Basis *pw_rhod, // pw for rhod
const Input_para& inp); // input parameters


template void pw::setup_pot<std::complex<double>, base_device::DEVICE_CPU>(
const int istep, // ionic step
UnitCell& ucell, // unitcell
const K_Vectors &kv, // kpoints
UnitCell& ucell, // unitcell
const K_Vectors &kv, // kpoints
Structure_Factor &sf, // structure factors
elecstate::ElecState *pelec, // pointer of electrons
const Parallel_Grid &para_grid, // parallel of FFT grids
const Charge &chr, // charge density
pseudopot_cell_vl &locpp, // local pseudopotentials
pseudopot_cell_vnl &ppcell, // non-local pseudopotentials
elecstate::ElecState *pelec, // pointer of electrons
const Parallel_Grid &para_grid, // parallel of FFT grids
const Charge &chr, // charge density
pseudopot_cell_vl &locpp, // local pseudopotentials
pseudopot_cell_vnl &ppcell, // non-local pseudopotentials
Plus_U &dftu, // mohan add 2025-11-06
VSep* vsep_cell, // U-1/2 method
psi::Psi<std::complex<double>, base_device::DEVICE_CPU>* kspw_psi, // electronic wave functions
hamilt::Hamilt<std::complex<double>, base_device::DEVICE_CPU>* p_hamilt, // hamiltonian
ModulePW::PW_Basis_K *pw_wfc, // pw for wfc
const ModulePW::PW_Basis *pw_rhod, // pw for rhod
const Input_para& inp); // input parameters
VSep* vsep_cell, // U-1/2 method
psi::Psi<std::complex<double>, base_device::DEVICE_CPU>* kspw_psi, // electronic wave functions
hamilt::HamiltBase* p_hamilt, // hamiltonian
ModulePW::PW_Basis_K *pw_wfc, // pw for wfc
const ModulePW::PW_Basis *pw_rhod, // pw for rhod
const Input_para& inp); // input parameters

#if ((defined __CUDA) || (defined __ROCM))

template void pw::setup_pot<std::complex<float>, base_device::DEVICE_GPU>(
const int istep, // ionic step
UnitCell& ucell, // unitcell
const K_Vectors &kv, // kpoints
UnitCell& ucell, // unitcell
const K_Vectors &kv, // kpoints
Structure_Factor &sf, // structure factors
elecstate::ElecState *pelec, // pointer of electrons
const Parallel_Grid &para_grid, // parallel of FFT grids
const Charge &chr, // charge density
pseudopot_cell_vl &locpp, // local pseudopotentials
pseudopot_cell_vnl &ppcell, // non-local pseudopotentials
elecstate::ElecState *pelec, // pointer of electrons
const Parallel_Grid &para_grid, // parallel of FFT grids
const Charge &chr, // charge density
pseudopot_cell_vl &locpp, // local pseudopotentials
pseudopot_cell_vnl &ppcell, // non-local pseudopotentials
Plus_U &dftu, // mohan add 2025-11-06
VSep* vsep_cell, // U-1/2 method
psi::Psi<std::complex<float>, base_device::DEVICE_GPU>* kspw_psi, // electronic wave functions
hamilt::Hamilt<std::complex<float>, base_device::DEVICE_GPU>* p_hamilt, // hamiltonian
ModulePW::PW_Basis_K *pw_wfc, // pw for wfc
const ModulePW::PW_Basis *pw_rhod, // pw for rhod
const Input_para& inp); // input parameters
VSep* vsep_cell, // U-1/2 method
psi::Psi<std::complex<float>, base_device::DEVICE_GPU>* kspw_psi, // electronic wave functions
hamilt::HamiltBase* p_hamilt, // hamiltonian
ModulePW::PW_Basis_K *pw_wfc, // pw for wfc
const ModulePW::PW_Basis *pw_rhod, // pw for rhod
const Input_para& inp); // input parameters

template void pw::setup_pot<std::complex<double>, base_device::DEVICE_GPU>(
const int istep, // ionic step
UnitCell& ucell, // unitcell
const K_Vectors &kv, // kpoints
UnitCell& ucell, // unitcell
const K_Vectors &kv, // kpoints
Structure_Factor &sf, // structure factors
elecstate::ElecState *pelec, // pointer of electrons
const Parallel_Grid &para_grid, // parallel of FFT grids
const Charge &chr, // charge density
pseudopot_cell_vl &locpp, // local pseudopotentials
pseudopot_cell_vnl &ppcell, // non-local pseudopotentials
elecstate::ElecState *pelec, // pointer of electrons
const Parallel_Grid &para_grid, // parallel of FFT grids
const Charge &chr, // charge density
pseudopot_cell_vl &locpp, // local pseudopotentials
pseudopot_cell_vnl &ppcell, // non-local pseudopotentials
Plus_U &dftu, // mohan add 2025-11-06
VSep* vsep_cell, // U-1/2 method
psi::Psi<std::complex<double>, base_device::DEVICE_GPU>* kspw_psi, // electronic wave functions
hamilt::Hamilt<std::complex<double>, base_device::DEVICE_GPU>* p_hamilt, // hamiltonian
ModulePW::PW_Basis_K *pw_wfc, // pw for wfc
const ModulePW::PW_Basis *pw_rhod, // pw for rhod
const Input_para& inp); // input parameters
VSep* vsep_cell, // U-1/2 method
psi::Psi<std::complex<double>, base_device::DEVICE_GPU>* kspw_psi, // electronic wave functions
hamilt::HamiltBase* p_hamilt, // hamiltonian
ModulePW::PW_Basis_K *pw_wfc, // pw for wfc
const ModulePW::PW_Basis *pw_rhod, // pw for rhod
const Input_para& inp); // input parameters

#endif
Loading
Loading