Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/CITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ The following references are required to be cited when using ABACUS. Specificall
Eike Caldeweyher, Jan-Michael Mewes, Sebastian Ehlert, and Stefan Grimme. "Extension and evaluation of the D4 London-dispersion model for periodic systems." Physical Chemistry Chemical Physics 22, 8499-8512 (2020). DOI: 10.1039/D0CP00502A.

Nikolay V. Tkachenko, Linus B. Dittmer, Rebecca Tomann, and Martin Head-Gordon. "Smooth D4S model." The Journal of Physical Chemistry Letters 15, 10629-10637 (2024). DOI: 10.1021/acs.jpclett.4c02653.

- **If the rVV10 nonlocal correlation (`vdw_method rvv10`) is used:**

O. A. Vydrov and T. Van Voorhis. "Nonlocal van der Waals density functional: The simpler the better." The Journal of Chemical Physics 133, 244103 (2010). DOI: 10.1063/1.3521275.

R. Sabatini, T. Gorni, and S. de Gironcoli. "Nonlocal van der Waals density functional made simple and efficient." Physical Review B 87, 041108(R) (2013). DOI: 10.1103/PhysRevB.87.041108.

G. Román-Pérez and J. M. Soler. "Efficient implementation of a van der Waals density functional: Application to double-wall carbon nanotubes." Physical Review Letters 103, 096102 (2009). DOI: 10.1103/PhysRevLett.103.096102.
1 change: 1 addition & 0 deletions docs/advanced/scf/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ To use VdW-correction, users need to supply value to the `vdw_method` keyword in
- d2: DFT-D2 method
- d3_0: DFT-D3(0) method
- d3_bj: DFT-D3(BJ) method
- rvv10: rVV10 nonlocal correlation. Unlike the DFT-D methods, it depends on the electron density and is added self-consistently to the exchange-correlation energy and potential; its parameter `rvv10_b` defaults to 6.3 (rPW86-PBE); use the value published for the chosen functional (15.7 for SCAN, 11.95 for r2SCAN).

Furthermore, ABACUS also provides a [list of keywords](../input_files/input-main.md#vdw-correction) to control relevant parmeters used in calculating the VdW correction, such as the scale factor (s6) term. Recommended values of such parameters can be found on the [webpage](https://www.chemie.uni-bonn.de/pctc/mulliken-center/software/dft-d3). The default values of the parameters in ABACUS are set to be the recommended values for PBE.

Expand Down
4 changes: 4 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ include(CompilerConfiguration)

set(_abacus_feature_definitions
__FFTW3
# The nonlocal vdW correction is always built. Focused unit tests that compile an XC evaluator
# without the plane-wave basis switch it off with abacus_disable_feature_definitions(__RVV10),
# which leaves the empty inline hooks of module_vdw/nonlocal_xc.h in their place.
__RVV10
$<$<BOOL:${ENABLE_JSON}>:__JSON>
$<$<BOOL:${USE_CUDA_ON_DCU}>:__CUDA_ON_DCU>
$<$<BOOL:${USE_CUDA_MPI}>:__CUDA_MPI>
Expand Down
3 changes: 3 additions & 0 deletions source/source_esolver/esolver_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ void ESolver_FP::before_all_runners(BaseCell &basecell, const Input_para &inp)
xc_parameters.exx_erfc_alpha = inp.exx_erfc_alpha;
xc_parameters.xc_exch_ext = inp.xc_exch_ext;
xc_parameters.xc_corr_ext = inp.xc_corr_ext;
xc_parameters.rvv10 = inp.vdw_method == "rvv10";
xc_parameters.rvv10_b = inp.rvv10_b;
xc_parameters.rvv10_c = inp.rvv10_c;
XC_Functional::set_runtime_parameters(xc_parameters);

ModuleBase::TITLE("ESolver_FP", "before_all_runners");
Expand Down
3 changes: 3 additions & 0 deletions source/source_hamilt/module_surchem/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# These targets compile an XC evaluator without the plane-wave basis, so they take the empty rVV10 hooks.
abacus_disable_feature_definitions(__RVV10)

abacus_disable_feature_definitions(__LCAO)
abacus_disable_feature_definitions(__LIBXC)
abacus_copy_test_files(support)
Expand Down
2 changes: 2 additions & 0 deletions source/source_hamilt/module_vdw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if(ENABLE_DFTD4)
list(APPEND vdw_sources vdwd4.cpp)
endif()

# nonlocal_xc.cpp and rvv10_kernel.cpp are not listed above: they call XC_Functional and the plane-wave
# basis, so module_xc/CMakeLists.txt compiles them into the xc_ target instead of this object library.
add_library(vdw OBJECT ${vdw_sources})

if(ENABLE_DFTD4)
Expand Down
178 changes: 178 additions & 0 deletions source/source_hamilt/module_vdw/nonlocal_xc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#include "nonlocal_xc.h"

#ifdef __RVV10

#include "rvv10_kernel.h"
#include "source_base/constants.h"
#include "source_base/matrix.h"
#include "source_base/matrix3.h"
#include "source_base/parallel_device.h"
#include "source_base/timer.h"
#include "source_base/tool_quit.h"
#include "source_base/tool_title.h"
#include "source_base/vector3.h"
#include "source_basis/module_pw/pw_basis.h"
#include "source_estate/module_charge/charge.h"
#include "source_hamilt/module_xc/xc_functional.h"

#include <algorithm>
#include <complex>
#include <vector>

namespace vdw
{
namespace
{

/// Cartesian components of the explicit strain derivative, stored as [3 * a + b].
const int stress_components = 9;

/// Spin channels of chr.rho that add up to the valence density (for nspin = 4, rho[0] is the total density).
int density_channels(const Charge &chr) { return (chr.nspin == 2) ? 2 : 1; }

/// rVV10 energy (Ha) of the total density of chr (valence plus core), with the plane-wave gradient of that
/// density, dE/dn (unless dedn is nullptr), dE/dsigma for sigma = |grad n|^2 and, with stress != nullptr,
/// the explicit strain derivative.
double evaluate_total_density(
const XCFunctionalParameters &parameters,
const Charge &chr,
std::vector<ModuleBase::Vector3<double>> &grad,
std::vector<double> *dedn,
std::vector<double> &dedsigma,
double *stress)
{
const ModulePW::PW_Basis &pw = *chr.rhopw;
const int nrxx = chr.nrxx;
const int nspin0 = density_channels(chr);
const double *core_begin = chr.rho_core;
const double *core_end = core_begin + nrxx;
std::vector<double> rho(core_begin, core_end);
for (int is = 0; is < nspin0; ++is)
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for (int ir = 0; ir < nrxx; ++ir)
{
rho[ir] += chr.rho[is][ir];
}
}
std::vector<std::complex<double>> rhog(pw.npw);
pw.real2recip(rho.data(), rhog.data());
grad.resize(nrxx);
XC_Functional::grad_rho(rhog.data(), grad.data(), &pw, pw.tpiba);
std::vector<double> sigma(nrxx);
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for (int ir = 0; ir < nrxx; ++ir)
{
sigma[ir] = grad[ir].norm2();
}
if (dedn != nullptr)
{
dedn->resize(nrxx);
}
dedsigma.resize(nrxx);
return rvv10_energy(pw, parameters.rvv10_b, parameters.rvv10_c, rho, sigma, dedn, dedsigma, stress);
}
} // namespace

void add_rvv10(
const XCFunctionalParameters &parameters,
const Charge &chr,
double &etxc,
double &vtxc,
ModuleBase::matrix &v)
{
if (!parameters.rvv10)
{
return;
}
ModuleBase::TITLE("vdw", "add_rvv10");
ModuleBase::timer::start("vdw", "add_rvv10");
const ModulePW::PW_Basis &pw = *chr.rhopw;
const int nrxx = chr.nrxx;
std::vector<ModuleBase::Vector3<double>> grad;
std::vector<double> dedn;
std::vector<double> dedsigma;
const double energy = evaluate_total_density(parameters, chr, grad, &dedn, dedsigma, nullptr);
// v = dE/dn - div(2 dE/dsigma grad n), Hartree to Ry by e2
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for (int ir = 0; ir < nrxx; ++ir)
{
grad[ir] *= 2.0 * dedsigma[ir];
}
std::vector<double> divergence(nrxx);
XC_Functional::grad_dot(grad.data(), divergence.data(), &pw, pw.tpiba);
// for nspin = 4 the potential of the total density goes to v(0) only
const int nspin0 = density_channels(chr);
// this reduction and the one of the stress stay serial, so the result does not depend on the thread count
double vtxc_nl = 0.0;
for (int ir = 0; ir < nrxx; ++ir)
{
const double v_nl = ModuleBase::e2 * (dedn[ir] - divergence[ir]);
for (int is = 0; is < nspin0; ++is)
{
v(is, ir) += v_nl;
vtxc_nl += v_nl * chr.rho[is][ir];
}
}
#ifdef __MPI
Parallel_Common::reduce_data(&vtxc_nl, 1, pw.pool_world);
#endif
etxc += ModuleBase::e2 * energy;
vtxc += vtxc_nl * pw.omega / pw.nxyz;
ModuleBase::timer::end("vdw", "add_rvv10");
}

void add_rvv10_stress(const XCFunctionalParameters &parameters, const Charge &chr, ModuleBase::matrix &sigma)
{
if (!parameters.rvv10)
{
return;
}
ModuleBase::TITLE("vdw", "add_rvv10_stress");
ModuleBase::timer::start("vdw", "add_rvv10_stress");
const ModulePW::PW_Basis &pw = *chr.rhopw;
const int nrxx = chr.nrxx;
std::vector<ModuleBase::Vector3<double>> grad;
std::vector<double> dedsigma;
double explicit_stress[stress_components] = {0.0};
// the stress needs dE/dsigma only
const double energy = evaluate_total_density(parameters, chr, grad, nullptr, dedsigma, explicit_stress);
// integral of dE/dsigma d_a n d_b n, in units of the volume element
double gradient_term[stress_components] = {0.0};
for (int ir = 0; ir < nrxx; ++ir)
{
const double g[3] = {grad[ir].x, grad[ir].y, grad[ir].z};
for (int a = 0; a < 3; ++a)
{
for (int b = 0; b < 3; ++b)
{
gradient_term[3 * a + b] += dedsigma[ir] * g[a] * g[b];
}
}
}
#ifdef __MPI
Parallel_Common::reduce_data(gradient_term, stress_components, pw.pool_world);
#endif
// The full strain derivative is T - delta_ab Int(n dE/dn + 2 sigma dE/dsigma) - 2 Int dE/dsigma d_a n d_b n,
// T the explicit part of the kernel. The XC diagonal -(etxc - vtxc)/omega in PW (in LCAO -etxc/omega plus the
// Pulay term of the potential) already holds -e2 (E - Int(n dE/dn + 2 sigma dE/dsigma)) / omega; the rest is below.
for (int a = 0; a < 3; ++a)
{
for (int b = 0; b < 3; ++b)
{
const double diagonal = (a == b) ? energy : 0.0;
sigma(a, b) += -ModuleBase::e2 / pw.omega * (explicit_stress[3 * a + b] - diagonal) +
2.0 * ModuleBase::e2 * gradient_term[3 * a + b] / pw.nxyz;
}
}
ModuleBase::timer::end("vdw", "add_rvv10_stress");
}

} // namespace vdw
#endif // __RVV10
57 changes: 57 additions & 0 deletions source/source_hamilt/module_vdw/nonlocal_xc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef NONLOCAL_XC_H
#define NONLOCAL_XC_H

class Charge;
struct XCFunctionalParameters;
namespace ModuleBase
{
class matrix;
} // namespace ModuleBase

namespace vdw
{

// rVV10 nonlocal correlation of vdw_method rvv10. Both functions do nothing unless parameters.rvv10 is set.
// They use the total density of chr (valence plus core) and are collective over the pool communicator of
// chr.rhopw. Without __RVV10 they are empty, so that an XC evaluator can be unit-tested without the
// plane-wave basis; the production build always defines it.

#ifdef __RVV10

/**
* @brief Add the rVV10 energy and potential to the result of an XC evaluation.
* @param parameters rVV10 switch and the parameters b and C
* @param chr density; the valence density plus rho_core is used, distributed over chr.rhopw
* @param[in,out] etxc XC energy (Ry), already reduced over the pool
* @param[in,out] vtxc integral of v_xc n (Ry), already reduced over the pool
* @param[in,out] v XC potential (Ry) on the nrxx points of this process; for nspin = 4 only v(0) is changed
*/
void add_rvv10(
const XCFunctionalParameters &parameters,
const Charge &chr,
double &etxc,
double &vtxc,
ModuleBase::matrix &v);

/**
* @brief Add the rVV10 stress (Ry/Bohr^3) that the XC diagonal and potential terms do not contain.
* @param parameters rVV10 switch and the parameters b and C
* @param chr density, as in add_rvv10
* @param[in,out] sigma 3 x 3 stress tensor
*/
void add_rvv10_stress(const XCFunctionalParameters &parameters, const Charge &chr, ModuleBase::matrix &sigma);
#else
inline void add_rvv10(
const XCFunctionalParameters &,
const Charge &,
double &,
double &,
ModuleBase::matrix &)
{
}
inline void add_rvv10_stress(const XCFunctionalParameters &, const Charge &, ModuleBase::matrix &) {}
#endif

} // namespace vdw

#endif // NONLOCAL_XC_H
Loading
Loading