Skip to content

Commit 4865b77

Browse files
Feature: improved implementation of kerker preconditioner (#3133)
* improved implementation of kerker preconditioner * fix bug in charge_mixing_test
1 parent 9c7398a commit 4865b77

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

source/module_elecstate/module_charge/charge_mixing.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,9 @@ void Charge_Mixing::auto_set(const double& bandgap_in, const UnitCell& ucell_)
108108
}
109109
}
110110
}
111-
// auto set kerker mixing for trans metal system
112-
if (has_trans_metal)
113-
{
114-
this->mixing_gg0 = 1.5;
115-
}
116-
else
117-
{
118-
this->mixing_gg0 = 0.0;
119-
}
111+
// auto set kerker mixing_gg0 = 1.0 as default
112+
this->mixing_gg0 = 1.0;
113+
120114
GlobalV::ofs_running << " Autoset mixing_gg0 to " << this->mixing_gg0 << std::endl;
121115
GlobalV::ofs_running << "-------------------------------------" << std::endl;
122116
// auto set for inhomogeneous system
@@ -362,7 +356,7 @@ void Charge_Mixing::mix_rho(Charge* chr)
362356

363357
void Charge_Mixing::Kerker_screen_recip(std::complex<double>* drhog)
364358
{
365-
if (this->mixing_gg0 <= 0.0)
359+
if (this->mixing_gg0 <= 0.0 || this->mixing_beta <= 0.1)
366360
return;
367361
const double fac = this->mixing_gg0;
368362
const double gg0 = std::pow(fac * 0.529177 / GlobalC::ucell.tpiba, 2);
@@ -374,7 +368,7 @@ void Charge_Mixing::Kerker_screen_recip(std::complex<double>* drhog)
374368
for (int ig = 0; ig < this->rhopw->npw; ++ig)
375369
{
376370
double gg = this->rhopw->gg[ig];
377-
double filter_g = std::max(gg / (gg + gg0), 0.1);
371+
double filter_g = std::max(gg / (gg + gg0), 0.1 / this->mixing_beta);
378372
drhog[is * this->rhopw->npw + ig] *= filter_g;
379373
}
380374
}
@@ -383,7 +377,7 @@ void Charge_Mixing::Kerker_screen_recip(std::complex<double>* drhog)
383377

384378
void Charge_Mixing::Kerker_screen_real(double* drhor)
385379
{
386-
if (this->mixing_gg0 <= 0.0)
380+
if (this->mixing_gg0 <= 0.0 || this->mixing_beta <= 0.1)
387381
return;
388382
std::vector<std::complex<double>> drhog(this->rhopw->npw * GlobalV::NSPIN);
389383
std::vector<double> drhor_filter(this->rhopw->nrxx * GlobalV::NSPIN);
@@ -405,7 +399,7 @@ void Charge_Mixing::Kerker_screen_real(double* drhor)
405399
for (int ig = 0; ig < this->rhopw->npw; ig++)
406400
{
407401
double gg = this->rhopw->gg[ig];
408-
double filter_g = std::max(gg / (gg + gg0), 0.1);
402+
double filter_g = std::max(gg / (gg + gg0), 0.1 / this->mixing_beta);
409403
drhog[is * this->rhopw->npw + ig] *= (1 - filter_g);
410404
}
411405
}

source/module_elecstate/test/charge_mixing_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,20 @@ TEST_F(ChargeMixingTest, AutoSetTest)
148148
CMtest.auto_set(0.0, GlobalC::ucell);
149149
EXPECT_EQ(CMtest.mixing_beta, 0.2);
150150
EXPECT_EQ(CMtest.mixing->mixing_beta, 0.2);
151-
EXPECT_EQ(CMtest.mixing_gg0, 0.0);
151+
EXPECT_EQ(CMtest.mixing_gg0, 1.0);
152152

153153
CMtest.need_auto_set();
154154
CMtest.auto_set(1.0, GlobalC::ucell);
155155
EXPECT_EQ(CMtest.mixing_beta, 0.7);
156156
EXPECT_EQ(CMtest.mixing->mixing_beta, 0.7);
157-
EXPECT_EQ(CMtest.mixing_gg0, 0.0);
157+
EXPECT_EQ(CMtest.mixing_gg0, 1.0);
158158

159159
GlobalC::ucell.atoms = new Atom[1];
160160
GlobalC::ucell.ntype = 1;
161161
GlobalC::ucell.atoms[0].ncpp.psd = "Sc";
162162
CMtest.need_auto_set();
163163
CMtest.auto_set(1.0, GlobalC::ucell);
164-
EXPECT_EQ(CMtest.mixing_gg0, 1.5);
164+
EXPECT_EQ(CMtest.mixing_gg0, 1.0);
165165
}
166166

167167
TEST_F(ChargeMixingTest, KerkerScreenRecipTest)
@@ -194,7 +194,7 @@ TEST_F(ChargeMixingTest, KerkerScreenRecipTest)
194194
{
195195
std::complex<double> ration = drhog[i] / drhog_old[i];
196196
double gg = this->pw_basis.gg[i];
197-
double ration_ref = std::max(gg / (gg + gg0), 0.1);
197+
double ration_ref = std::max(gg / (gg + gg0), 0.1 / CMtest.mixing_beta);
198198
EXPECT_NEAR(ration.real(), ration_ref, 1e-10);
199199
EXPECT_NEAR(ration.imag(), 0, 1e-10);
200200
}

0 commit comments

Comments
 (0)