Skip to content

Commit 1b0f451

Browse files
author
fakeone
committed
adding a parameter for change SCF thresholds
1 parent 408e349 commit 1b0f451

14 files changed

+76
-43
lines changed

source/module_elecstate/potentials/pot_xc.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ void PotXC::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, Module
1919
//----------------------------------------------------------
2020
// calculate the exchange-correlation potential
2121
//----------------------------------------------------------
22-
2322
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
2423
{
2524
#ifdef USE_LIBXC
@@ -44,4 +43,4 @@ void PotXC::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, Module
4443
ModuleBase::timer::tick("PotXC", "cal_v_eff");
4544
}
4645

47-
} // namespace elecstate
46+
} // namespace elecstate

source/module_esolver/esolver_ks.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
189189
//! 4) it has been established that
190190
// xc_func is same for all elements, therefore
191191
// only the first one if used
192+
193+
// A little hacking of the code here. Adding the
194+
// following line to set up the density threshold
195+
// for DFT calculations.
196+
XC_Functional::set_xc_ingred_thrs(PARAM.inp.xc_dens_thr);
192197
if (PARAM.inp.use_paw)
193198
{
194199
XC_Functional::set_xc_type(PARAM.inp.dft_functional);

source/module_hamilt_general/module_xc/xc_functional.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,27 @@ XC_Functional::XC_Functional(){}
1414

1515
XC_Functional::~XC_Functional(){}
1616

17+
//double XC_Functional::dens_threshold;
18+
//double XC_Functional::zeta_threshold;
19+
//double XC_Functional::grho_threshold;
20+
//double XC_Functional::tau_threshold;
21+
22+
double XC_Functional::dens_threshold = 1.0e-10;
23+
double XC_Functional::zeta_threshold = dens_threshold;
24+
double XC_Functional::grho_threshold = dens_threshold;
25+
double XC_Functional::tau_threshold = dens_threshold;
26+
1727
std::vector<int> XC_Functional::func_id(1);
1828
int XC_Functional::func_type = 0;
1929
bool XC_Functional::use_libxc = true;
2030
double XC_Functional::hybrid_alpha = 0.25;
21-
double XC_Functional::default_dft_threshold=1.0e-10;
22-
double XC_Functional::dens_threshold=1.0e-10;
23-
double XC_Functional::zeta_threshold=1.0e-10;
24-
double XC_Functional::grho_threshold=1.0e-10;
25-
double XC_Functional::tau_threshold=1.0e-10;
2631

27-
void XC_Functional::set_dft_ingred_thrs(double d_thr, double z_thr, double g_thr, double t_thr)
28-
{ dens_threshold = d_thr;
29-
zeta_threshold = z_thr;
30-
grho_threshold = g_thr;
31-
tau_threshold = t_thr;
32+
void XC_Functional::set_xc_ingred_thrs(double _thr_in)
33+
{
34+
XC_Functional::dens_threshold = _thr_in;
35+
XC_Functional::zeta_threshold = dens_threshold;
36+
XC_Functional::grho_threshold = dens_threshold*1.0e-4;
37+
XC_Functional::tau_threshold = dens_threshold*1.0e-4;
3238
}
3339

3440
double XC_Functional::get_dens_threshold()

source/module_hamilt_general/module_xc/xc_functional.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class XC_Functional
6565
static int get_func_type();
6666
static void set_xc_type(const std::string xc_func_in);
6767

68-
static void set_dft_ingred_thrs(double d_thr, double z_thr, double g_thr, double t_thr);
68+
static void set_xc_ingred_thrs(double _thr_in);
6969
static double get_dens_threshold();
7070
static double get_grho_threshold();
7171
static double get_zeta_threshold();
@@ -88,7 +88,6 @@ class XC_Functional
8888
static double grho_threshold;
8989
static double zeta_threshold;
9090
static double tau_threshold;
91-
static double default_dft_threshold;
9291
//exx_hybrid_alpha for mixing exx in hybrid functional:
9392
static double hybrid_alpha;
9493

source/module_hamilt_general/module_xc/xc_functional_gradcorr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
191191

192192
}
193193

194-
const double epsr = 1.0e-6;
195-
const double epsg = 1.0e-10;
194+
const double epsr = dens_threshold;
195+
const double epsg = grho_threshold;
196196

197197
double vtxcgc = 0.0;
198198
double etxcgc = 0.0;
@@ -791,4 +791,4 @@ template void XC_Functional::grad_wfc<std::complex<double>, base_device::DEVICE_
791791
const ModulePW::PW_Basis_K* wfc_basis,
792792
const std::complex<double>* rhog,
793793
std::complex<double>* grad);
794-
#endif // __CUDA || __ROCM
794+
#endif // __CUDA || __ROCM

source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ ModuleBase::matrix XC_Functional_Libxc::convert_v_nspin4(
268268
const ModuleBase::matrix &v)
269269
{
270270
assert(PARAM.inp.nspin==4);
271-
constexpr double vanishing_charge = 1.0e-10;
271+
const double vanishing_charge = XC_Functional::get_dens_threshold();
272272
ModuleBase::matrix v_nspin4(PARAM.inp.nspin, nrxx);
273273
for( int ir=0; ir<nrxx; ++ir )
274274
v_nspin4(0,ir) = 0.5 * (v(0,ir)+v(1,ir));
@@ -287,4 +287,4 @@ ModuleBase::matrix XC_Functional_Libxc::convert_v_nspin4(
287287
return v_nspin4;
288288
}
289289

290-
#endif
290+
#endif

source/module_hamilt_general/module_xc/xc_functional_libxc_vxc.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
7676
double vtxc = 0.0;
7777
ModuleBase::matrix v(nspin,nrxx);
7878

79+
// std::cout<< "hello from v_xc_libxc, threshold = " << XC_Functional::get_dens_threshold() << " " << XC_Functional::get_grho_threshold()<< std::endl;
80+
7981
for( xc_func_type &func : funcs )
8082
{
8183
// jiyy add for threshold
82-
constexpr double rho_threshold = 1E-6;
83-
constexpr double grho_threshold = 1E-10;
84+
const double rho_threshold = XC_Functional::get_dens_threshold();
85+
const double grho_threshold = XC_Functional::get_grho_threshold();
8486

8587
xc_func_set_dens_threshold(&func, rho_threshold);
8688

@@ -207,9 +209,9 @@ std::tuple<double,double,ModuleBase::matrix,ModuleBase::matrix> XC_Functional_Li
207209
std::vector<double> vtau ( nrxx * nspin );
208210
std::vector<double> vlapl ( nrxx * nspin );
209211

210-
constexpr double rho_th = 1e-8;
211-
constexpr double grho_th = 1e-12;
212-
constexpr double tau_th = 1e-8;
212+
const double rho_th = XC_Functional::get_dens_threshold();
213+
const double grho_th = XC_Functional::get_grho_threshold();
214+
const double tau_th = XC_Functional::get_tau_threshold();
213215
// sgn for threshold mask
214216
std::vector<double> sgn( nrxx * nspin);
215217
#ifdef _OPENMP
@@ -392,4 +394,4 @@ std::tuple<double,double,ModuleBase::matrix,ModuleBase::matrix> XC_Functional_Li
392394
return std::make_tuple( etxc, vtxc, std::move(v), std::move(vofk) );
393395
}
394396

395-
#endif
397+
#endif

source/module_hamilt_general/module_xc/xc_functional_libxc_wrapper_gcxc.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifdef USE_LIBXC
22

33
#include "xc_functional_libxc.h"
4+
#include "xc_functional.h"
45

56
#include <xc.h>
67
#include <array>
@@ -12,9 +13,12 @@ void XC_Functional_Libxc::gcxc_libxc(
1213
{
1314
sxc = v1xc = v2xc = 0.0;
1415

15-
constexpr double small = 1.e-6;
16-
constexpr double smallg = 1.e-10;
17-
if (rho <= small || grho < smallg)
16+
// constexpr double small = 1.e-6;
17+
// constexpr double smallg = 1.e-10;
18+
19+
// std::cout << "hello from XC_Functional_Libxc, threshold = " << XC_Functional::get_dens_threshold() << std::endl;
20+
21+
if (rho <= XC_Functional::get_dens_threshold() || grho < XC_Functional::get_grho_threshold())
1822
{
1923
return;
2024
}
@@ -49,8 +53,9 @@ void XC_Functional_Libxc::gcxc_spin_libxc(
4953
{
5054
if( func.info->family == XC_FAMILY_GGA || func.info->family == XC_FAMILY_HYB_GGA)
5155
{
52-
constexpr double rho_threshold = 1E-6;
53-
constexpr double grho_threshold = 1E-10;
56+
// std::cout << "hello libxc gcxc_spin_libxc, threshold: " << XC_Functional::get_dens_threshold() << std::endl;
57+
const double rho_threshold = XC_Functional::get_dens_threshold();
58+
const double grho_threshold = XC_Functional::get_grho_threshold();
5459
std::array<double,2> sgn = {1.0, 1.0};
5560
if(func.info->kind==XC_CORRELATION)
5661
{
@@ -76,4 +81,4 @@ void XC_Functional_Libxc::gcxc_spin_libxc(
7681
XC_Functional_Libxc::finish_func(funcs);
7782
}
7883

79-
#endif
84+
#endif

source/module_hamilt_general/module_xc/xc_functional_libxc_wrapper_tauxc.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifdef USE_LIBXC
66

77
#include "xc_functional_libxc.h"
8+
#include "xc_functional.h"
89
#include "module_hamilt_pw/hamilt_pwdft/global.h"
910
#include <array>
1011

@@ -67,8 +68,8 @@ void XC_Functional_Libxc::tau_xc_spin(
6768
{
6869
if( func.info->family == XC_FAMILY_MGGA || func.info->family == XC_FAMILY_HYB_MGGA)
6970
{
70-
constexpr double rho_threshold = 1E-6;
71-
constexpr double grho_threshold = 1E-10;
71+
const double rho_threshold = XC_Functional::get_dens_threshold();
72+
const double grho_threshold = XC_Functional::get_grho_threshold();
7273
std::array<double,2> sgn = {1.0, 1.0};
7374
if(func.info->kind==XC_CORRELATION)
7475
{
@@ -98,4 +99,4 @@ void XC_Functional_Libxc::tau_xc_spin(
9899
XC_Functional_Libxc::finish_func(funcs);
99100
}
100101

101-
#endif
102+
#endif

source/module_hamilt_general/module_xc/xc_functional_vxc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional::v_xc(
4040
// in Rydeberg unit, so * 2.0.
4141
double e2 = 2.0;
4242

43-
double vanishing_charge = 1.0e-10;
43+
double vanishing_charge = dens_threshold;
4444

4545
if (PARAM.inp.nspin == 1 || ( PARAM.inp.nspin ==4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z))
4646
{

0 commit comments

Comments
 (0)