Skip to content

Commit

Permalink
Fix: instable nonlocal pp in uspp (#5798)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuLiu98 authored Jan 3, 2025
1 parent cecf36a commit 7d14803
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/module_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)

if (ucell.cell_parameter_updated)
{
this->ppcell.init_vnl(ucell, this->pw_rhod);
this->ppcell.rescale_vnl(ucell.omega);
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "NON-LOCAL POTENTIAL");

this->pw_wfc->initgrids(ucell.lat0, ucell.latvec, this->pw_wfc->nx, this->pw_wfc->ny, this->pw_wfc->nz);
Expand Down
23 changes: 23 additions & 0 deletions source/module_hamilt_pw/hamilt_pwdft/VNL_in_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ void pseudopot_cell_vnl::init_vnl(UnitCell& cell, const ModulePW::PW_Basis* rho_
ModuleBase::TITLE("pseudopot_cell_vnl", "init_vnl");
ModuleBase::timer::tick("ppcell_vnl", "init_vnl");

this->omega_old = cell.omega;

// from init_us_1
// a) For each non vanderbilt pseudopotential it computes the D and
// the betar in the same form of the Vanderbilt pseudopotential.
Expand Down Expand Up @@ -1733,6 +1735,27 @@ void pseudopot_cell_vnl::newd_nc(const int& iat, UnitCell& cell)
}
}

// scale the non-local pseudopotential tables
void pseudopot_cell_vnl::rescale_vnl(const double& omega_in)
{
const double ratio = this->omega_old / omega_in;
const double sqrt_ratio = std::sqrt(ratio);
this->omega_old = omega_in;

for (int i = 0; i < this->tab.getSize(); i++)
{
this->tab.ptr[i] *= sqrt_ratio;
}
for (int i = 0; i < this->tab_at.getSize(); i++)
{
this->tab_at.ptr[i] *= sqrt_ratio;
}
for (int i = 0; i < this->qrad.getSize(); i++)
{
this->qrad.ptr[i] *= ratio;
}
}

template <>
float* pseudopot_cell_vnl::get_nhtol_data() const
{
Expand Down
4 changes: 4 additions & 0 deletions source/module_hamilt_pw/hamilt_pwdft/VNL_in_pw.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class pseudopot_cell_vnl

void init_vnl(UnitCell& cell, const ModulePW::PW_Basis* rho_basis);

void rescale_vnl(const double& omega_in);

template <typename FPTYPE, typename Device>
void getvnl(Device* ctx, const UnitCell& ucell, const int& ik, std::complex<FPTYPE>* vkb_in) const;

Expand Down Expand Up @@ -200,6 +202,8 @@ class pseudopot_cell_vnl

Soc soc;

double omega_old = 0;

/**
* @brief Compute interpolation table qrad
*
Expand Down

0 comments on commit 7d14803

Please sign in to comment.