Skip to content

Commit e298c81

Browse files
author
dyzheng
committed
Feature(xc): implement gga_grad=3 via SF builtin for noncollinear GGA
Call SF builtin (v_xc_ncgga_sf_builtin) from v_xc for gga_grad=3 noncollinear calculations, which computes LDA and GGA in a single self-consistent function with per-mu independent div correction. Use gga_grad=2 per-component gradient decomposition and projected div in gradcorr for gga_grad=3 as fallback when not using SF builtin. Scope libxc SF path to gga_grad=2 only.
1 parent e14b77d commit e298c81

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

source/source_hamilt/module_xc/xc_functional_gradcorr.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include "source_base/timer.h"
1313
#include "source_basis/module_pw/pw_basis_k.h"
1414
#include "source_io/module_parameter/parameter.h"
15+
16+
#include "xc_functional_gga_noncol_sf_builtin.h"
17+
1518
#include <ATen/core/tensor.h>
1619
#include <ATen/core/tensor_map.h>
1720
#include <ATen/core/tensor_types.h>
@@ -21,7 +24,7 @@
2124
#include "xc_functional_libxc.h"
2225
#endif
2326

24-
#include "xc_functional_gga_noncol_sf_builtin.h"
27+
2528

2629
void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
2730
const Charge* const chr, ModulePW::PW_Basis* rhopw, const UnitCell *ucell,
@@ -187,7 +190,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
187190
gdr2 = new ModuleBase::Vector3<double>[rhopw->nrxx];
188191
if(!is_stress) h2 = new ModuleBase::Vector3<double>[rhopw->nrxx];
189192

190-
if (gga_grad == 2)
193+
if (gga_grad == 2 || gga_grad == 3)
191194
{
192195
tmp_recip = new std::complex<double>[rhopw->npw];
193196
gdr_mag = new ModuleBase::Vector3<double>[rhopw->nrxx];
@@ -491,7 +494,7 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
491494
}
492495
#endif
493496

494-
if(!is_stress && PARAM.inp.nspin==4 && gga_grad==2)
497+
if(!is_stress && PARAM.inp.nspin==4 && (PARAM.globalv.domag||PARAM.globalv.domag_z) && (gga_grad==2 || gga_grad==3))
495498
{
496499
#ifdef _OPENMP
497500
#pragma omp parallel for schedule(static, 1024)

source/source_hamilt/module_xc/xc_functional_libxc_tools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ std::pair<double,ModuleBase::matrix> XC_Functional_Libxc::convert_vtxc_v(
235235

236236
if(func.info->family == XC_FAMILY_GGA || func.info->family == XC_FAMILY_HYB_GGA)
237237
{
238-
if(PARAM.inp.nspin==4 && PARAM.inp.gga_grad >= 2 && (PARAM.globalv.domag || PARAM.globalv.domag_z))
238+
if(PARAM.inp.nspin==4 && PARAM.inp.gga_grad == 2 && (PARAM.globalv.domag || PARAM.globalv.domag_z))
239239
{
240240
std::vector<double> mag_part_tmp = XC_Functional_Libxc::compute_mag_part_nspin4(nrxx, chr);
241241
const std::vector<std::vector<double>> dh = XC_Functional_Libxc::cal_dh_sf(nspin, nrxx, sgn, gdr, vsigma, mag_part_tmp, tpiba, chr);

source/source_hamilt/module_xc/xc_functional_libxc_vxc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
6666
std::tuple<std::vector<double>,std::vector<double>> rho_amag = XC_Functional_Libxc::convert_rho_amag_nspin4(nspin, nrxx, chr);
6767
rho = std::get<0>(std::move(rho_amag));
6868
amag = std::get<1>(std::move(rho_amag));
69-
if(PARAM.inp.gga_grad >= 2 && (PARAM.globalv.domag || PARAM.globalv.domag_z))
69+
if(PARAM.inp.gga_grad == 2 && (PARAM.globalv.domag || PARAM.globalv.domag_z))
7070
{
7171
mag_part = XC_Functional_Libxc::compute_mag_part_nspin4(nrxx, chr);
7272
}
@@ -76,7 +76,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
7676
std::vector<double> sigma;
7777
if(is_gga)
7878
{
79-
if(PARAM.inp.nspin==4 && PARAM.inp.gga_grad >= 2 && (PARAM.globalv.domag || PARAM.globalv.domag_z))
79+
if(PARAM.inp.nspin==4 && PARAM.inp.gga_grad == 2 && (PARAM.globalv.domag || PARAM.globalv.domag_z))
8080
{
8181
gdr = XC_Functional_Libxc::cal_gdr_sf(nspin, nrxx, rho, mag_part, tpiba, chr);
8282
}
@@ -181,7 +181,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
181181

182182
if(4==PARAM.inp.nspin)
183183
{
184-
if(PARAM.inp.gga_grad >= 2 && (PARAM.globalv.domag || PARAM.globalv.domag_z))
184+
if(PARAM.inp.gga_grad == 2 && (PARAM.globalv.domag || PARAM.globalv.domag_z))
185185
{
186186
v = XC_Functional_Libxc::convert_v_nspin4_sf(nrxx, chr, mag_part, v);
187187
}

source/source_hamilt/module_xc/xc_functional_vxc.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
#include "source_io/module_parameter/parameter.h"
1010
#include "xc_functional.h"
1111

12+
#include "xc_functional_gga_noncol_sf_builtin.h"
13+
1214
#ifdef USE_LIBXC
1315
#include "xc_functional_libxc.h"
1416
#endif
1517

16-
#include "xc_functional_gga_noncol_sf_builtin.h"
18+
1719

1820
// [etxc, vtxc, v] = XC_Functional::v_xc(...)
1921
std::tuple<double, double, ModuleBase::matrix> XC_Functional::v_xc(const int& nrxx, // number of real-space grid
@@ -36,6 +38,11 @@ std::tuple<double, double, ModuleBase::matrix> XC_Functional::v_xc(const int& nr
3638
#endif
3739
}
3840

41+
if (PARAM.inp.nspin == 4 && (PARAM.globalv.domag || PARAM.globalv.domag_z) && PARAM.inp.gga_grad == 3)
42+
{
43+
return ModuleXC::NCGGA_SF_Builtin::v_xc_ncgga_sf_builtin(nrxx, ucell->omega, ucell->tpiba, chr);
44+
}
45+
3946
ModuleBase::timer::start("XC_Functional", "v_xc");
4047

4148
//Exchange-Correlation potential Vxc(r) from n(r)

0 commit comments

Comments
 (0)