Skip to content

Commit 90e6523

Browse files
committed
Fix: Enhance the computational stability of tau_vw.
1 parent 274477a commit 90e6523

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

source/module_esolver/esolver_of_interface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void ESolver_OF::kinetic_energy_density(double** prho, double** pphi, double** r
193193
if (this->of_kinetic_ == "vw" || this->of_kinetic_ == "tf+" || this->of_kinetic_ == "wt"
194194
|| this->of_kinetic_ == "lkt")
195195
{
196-
this->vw_->tau_vw(prho, this->pw_rho, rtau[0]);
196+
this->vw_->tau_vw(pphi, this->pw_rho, rtau[0]);
197197
}
198198
if (this->of_kinetic_ == "wt")
199199
{

source/module_hamilt_pw/hamilt_ofdft/kedf_vw.cpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -117,35 +117,42 @@ double KEDF_vW::get_energy_density(double** pphi, int is, int ir, ModulePW::PW_B
117117

118118
/**
119119
* @brief Get the positive definite energy density of vW KEDF
120-
* \f[ \tau_{vW} = |\nabla \rho|^2 / (8 \rho) \f]
120+
* \f[ \tau_{vW} = |\nabla \phi|^2 / 2 \f]
121121
*
122-
* @param prho charge density
122+
* @param pphi sqrt(rho)
123123
* @param pw_rho pw basis
124124
* @param rtau_vw rtau_vw => rtau_vw + tau_vw
125125
*/
126-
void KEDF_vW::tau_vw(const double* const* prho, ModulePW::PW_Basis* pw_rho, double* rtau_vw)
126+
void KEDF_vW::tau_vw(const double* const* pphi, ModulePW::PW_Basis* pw_rho, double* rtau_vw)
127127
{
128+
std::vector<double> abs_phi = std::vector<double>(pw_rho->nrxx, 0.);
129+
128130
for (int is = 0; is < PARAM.inp.nspin; ++is)
129131
{
130-
std::vector<std::vector<double>> nabla_rho(3, std::vector<double>(pw_rho->nrxx, 0.));
132+
for (int ir = 0; ir < pw_rho->nrxx; ++ir)
133+
{
134+
abs_phi[ir] = std::abs(pphi[is][ir]);
135+
}
136+
137+
std::vector<std::vector<double>> nabla_phi(3, std::vector<double>(pw_rho->nrxx, 0.));
138+
std::vector<std::complex<double>> recip_phi(pw_rho->npw, 0.);
139+
std::vector<std::complex<double>> recip_nabla_phi(pw_rho->npw, 0.);
131140

132-
std::vector<std::complex<double>> recip_rho(pw_rho->npw, 0.);
133-
std::vector<std::complex<double>> recip_nabla_rho(pw_rho->npw, 0.);
134-
pw_rho->real2recip(prho[is], recip_rho.data());
141+
pw_rho->real2recip(abs_phi.data(), recip_phi.data());
135142

136143
std::complex<double> img(0.0, 1.0);
137144
for (int j = 0; j < 3; ++j)
138145
{
139146
for (int ip = 0; ip < pw_rho->npw; ++ip)
140147
{
141-
recip_nabla_rho[ip] = img * pw_rho->gcar[ip][j] * recip_rho[ip] * pw_rho->tpiba;
148+
recip_nabla_phi[ip] = img * pw_rho->gcar[ip][j] * recip_phi[ip] * pw_rho->tpiba;
142149
}
143150

144-
pw_rho->recip2real(recip_nabla_rho.data(), nabla_rho[j].data());
151+
pw_rho->recip2real(recip_nabla_phi.data(), nabla_phi[j].data());
145152

146153
for (int ir = 0; ir < pw_rho->nrxx; ++ir)
147154
{
148-
rtau_vw[ir] += nabla_rho[j][ir] * nabla_rho[j][ir] / (8. * prho[is][ir]) * 2.0; // convert Ha to Ry.
155+
rtau_vw[ir] += nabla_phi[j][ir] * nabla_phi[j][ir] / 2. * this->vw_weight_ * 2.0; // convert Ha to Ry.
149156
}
150157
}
151158
}

source/module_hamilt_pw/hamilt_ofdft/kedf_vw.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class KEDF_vW
2929

3030
double get_energy(double** pphi, ModulePW::PW_Basis* pw_rho);
3131
double get_energy_density(double** pphi, int is, int ir, ModulePW::PW_Basis* pw_rho);
32-
void tau_vw(const double* const* prho, ModulePW::PW_Basis* pw_rho, double* rtau_vw);
32+
void tau_vw(const double* const* pphi, ModulePW::PW_Basis* pw_rho, double* rtau_vw);
3333
void vw_potential(const double* const* pphi, ModulePW::PW_Basis* pw_rho, ModuleBase::matrix& rpotential);
3434
void get_stress(const double* const* pphi, ModulePW::PW_Basis* pw_rho);
3535

0 commit comments

Comments
 (0)