Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ubuntu-24.04]
build: [meson, cmake, fpm]
build-type: [debug]
compiler: [gnu]
Expand All @@ -24,7 +24,7 @@ jobs:
compiler: gnu
version: 12

- os: ubuntu-latest
- os: ubuntu-24.04
build: meson
build-type: coverage
compiler: gnu
Expand Down Expand Up @@ -263,7 +263,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ubuntu-24.04]
build: [meson, cmake]
gcc_v: [10]
python_v: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
Expand Down
2 changes: 1 addition & 1 deletion config/cmake/Findmctc-lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
set(_lib "mctc-lib")
set(_pkg "MCTCLIB")
set(_url "https://github.com/grimme-lab/mctc-lib")
set(_rev "06db4d8")
set(_rev "v0.7.0")

if(NOT DEFINED "${_pkg}_FIND_METHOD")
if(DEFINED "${PROJECT_NAME}-dependency-method")
Expand Down
2 changes: 1 addition & 1 deletion config/cmake/Findmstore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
set(_lib "mstore")
set(_pkg "MSTORE")
set(_url "https://github.com/grimme-lab/mstore")
set(_rev "v0.3.0")
set(_rev "v0.4.0")

if(NOT DEFINED "${_pkg}_FIND_METHOD")
if(DEFINED "${PROJECT_NAME}-dependency-method")
Expand Down
2 changes: 1 addition & 1 deletion doc/api/c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Recreating a structure object requires to recreate the dispersion model as well.
Zero derives a particle mesh from the reciprocal cutoff, which scales as
:math:`O(N \log N)` and is the default.
A positive value interpolates the structure factors on a mesh of that many
points per direction, rounded up to a power of two.
points per direction, rounded up to a product of powers of two and three.
A negative value sums over the reciprocal lattice directly, which is exact but
scales quadratically with the number of atoms.

Expand Down
2 changes: 2 additions & 0 deletions doc/guide/accuracy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Particle mesh evaluation
The direct reciprocal space sum visits every atom at every wave vector, so its cost grows quadratically with the number of atoms.
Setting ``mesh`` interpolates the structure factors on an equispaced mesh with cardinal B-splines and evaluates the sum with a fast Fourier transform instead, which scales as :math:`O(N \log N)`.
This is the default; a negative ``mesh`` falls back to the direct summation.
Each requested mesh length is rounded up to the smallest product of powers of two and three.
For example, 271 points become 288 rather than 512, reducing the size of a cubic mesh by a factor of about 5.6.

The discretisation error is governed by the mesh spacing, not by the number of mesh points, so the mesh has to grow with the cell.
The table lists the deviation from the direct summation for cubic carbon monoxide supercells, in Hartree per atom, against the resulting spacing in a₀:
Expand Down
6 changes: 3 additions & 3 deletions doc/guide/pbc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ The mesh is derived from the reciprocal cutoff unless it is given explicitly:

.. code-block:: fortran

! explicit mesh, rounded up to a power of two
! explicit mesh, rounded up to a product of powers of two and three
call new_d3_model(disp, mol, lowrank=d3_lowrank_config(mesh=32))

! sum over the reciprocal lattice directly
Expand All @@ -133,7 +133,7 @@ The mesh is derived from the reciprocal cutoff unless it is given explicitly:

.. code-block:: c

/* explicit mesh, rounded up to a power of two */
/* explicit mesh, rounded up to a product of powers of two and three */
dftd3_set_model_ewald(error, d3, 0, 0.0, 0.0, 32);

/* sum over the reciprocal lattice directly */
Expand All @@ -144,7 +144,7 @@ The mesh is derived from the reciprocal cutoff unless it is given explicitly:

.. code-block:: python

# explicit mesh, rounded up to a power of two
# explicit mesh, rounded up to a product of powers of two and three
model.set_ewald_summation(mesh=32)

# sum over the reciprocal lattice directly
Expand Down
4 changes: 2 additions & 2 deletions fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ keywords = ["dispersion-correction", "quantum-chemistry"]

[dependencies]
mctc-lib.git = "https://github.com/grimme-lab/mctc-lib"
mctc-lib.tag = "v0.5.2"
mctc-lib.tag = "v0.7.0"

[dev-dependencies]
mstore.git = "https://github.com/grimme-lab/mstore"
mstore.tag = "v0.3.0"
mstore.tag = "v0.4.0"

[build]
external-modules = ["mpi_f08"]
Expand Down
29 changes: 17 additions & 12 deletions src/dftd3/disp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ subroutine get_dispersion_atomic_v2(error, mol, disp, param, cutoff, energies, &
!> Communication backend, enables partitioning the coordination number
class(work_reducer), intent(in), optional :: reducer

logical :: grad, hess, ewald
logical :: grad, hess, ewald, threebody
integer :: mref
real(wp), allocatable :: cn(:)
real(wp), allocatable :: gwvec(:, :), gwdcn(:, :)
Expand All @@ -101,6 +101,7 @@ subroutine get_dispersion_atomic_v2(error, mol, disp, param, cutoff, energies, &
mref = maxval(disp%ref)
grad = present(gradient) .or. present(sigma)
hess = present(hessian)
threebody = param%has_threebody()

! a low-rank model under three-dimensional boundary conditions asks for the
! reciprocal space summation, which the damping function has to support
Expand Down Expand Up @@ -132,13 +133,15 @@ subroutine get_dispersion_atomic_v2(error, mol, disp, param, cutoff, energies, &
if (grad) allocate(gwdcn(mref, mol%nat))
call disp%weight_references(mol, cn, gwvec, gwdcn)

allocate(c6(mol%nat, mol%nat))
if (grad) allocate(dc6dcn(mol%nat, mol%nat))
if (param%has_threebody()) then
! the three-body term reads coefficients of pairs this part does not own
call disp%get_atomic_c6(mol, gwvec, gwdcn, c6, dc6dcn)
else
call disp%get_atomic_c6(mol, gwvec, gwdcn, c6, dc6dcn, partition=partition)
if (.not.ewald .or. threebody) then
allocate(c6(mol%nat, mol%nat))
if (grad) allocate(dc6dcn(mol%nat, mol%nat))
if (threebody) then
! the three-body term reads coefficients of pairs this part does not own
call disp%get_atomic_c6(mol, gwvec, gwdcn, c6, dc6dcn)
else
call disp%get_atomic_c6(mol, gwvec, gwdcn, c6, dc6dcn, partition=partition)
end if
end if

energies(:) = 0.0_wp
Expand All @@ -160,10 +163,12 @@ subroutine get_dispersion_atomic_v2(error, mol, disp, param, cutoff, energies, &
& disp%rvdw, disp%r4r2, c6, dc6dcn, energies, dEdcn, gradient_local, &
& sigma_local, partition)
end if
call get_lattice_points(mol%periodic, mol%lattice, cutoff%disp3, lattr)
call param%get_dispersion3(mol, lattr, cutoff%disp3, cutoff%width3, &
& disp%rvdw, disp%r4r2, c6, dc6dcn, energies, dEdcn, gradient_local, &
& sigma_local, partition)
if (threebody) then
call get_lattice_points(mol%periodic, mol%lattice, cutoff%disp3, lattr)
call param%get_dispersion3(mol, lattr, cutoff%disp3, cutoff%width3, &
& disp%rvdw, disp%r4r2, c6, dc6dcn, energies, dEdcn, gradient_local, &
& sigma_local, partition)
end if
if (grad) then
call get_lattice_points(mol%periodic, mol%lattice, cutoff%cn, lattr)
if (present(reducer)) then
Expand Down
11 changes: 6 additions & 5 deletions src/dftd3/fourier/ewald.f90
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
module dftd3_fourier_ewald
use dftd3_cutoff, only : get_lattice_points
use dftd3_fourier_decomposition, only : d3_lowrank_c6
use dftd3_fourier_kernel, only : fourier_term, get_fourier_transform, &
& get_potential_zero
use dftd3_fourier_kernel, only : fourier_term, fourier_kernel, new_fourier_kernel, &
& get_fourier_transform, get_potential_zero
use dftd3_partition, only : work_partition, owns_index
use mctc_env, only : wp
use mctc_io, only : structure_type
Expand Down Expand Up @@ -87,7 +87,7 @@ subroutine get_dispersion_ewald(mol, lowrank, ghost, terms, nterm, kcut, gwvec,
type(work_partition), intent(in), optional :: partition

logical :: grad
type(work_partition) :: part
type(fourier_kernel), allocatable :: kernel(:, :, :)
integer :: nat, nid, rank, nk, ik, iat, izp, jzp, il, it, ic
real(wp) :: vol, rec(3, 3), kvec(3), knorm, kr, erecip, phi, dphi, pval, dpval
real(wp) :: qq, zre, zim
Expand All @@ -110,6 +110,7 @@ subroutine get_dispersion_ewald(mol, lowrank, ghost, terms, nterm, kcut, gwvec,
vol = abs(matdet_3x3(mol%lattice))
call get_lattice_points([.true., .true., .true.], rec, kcut, kpoints)
nk = size(kpoints, 2)
kernel = new_fourier_kernel(terms)

allocate(c6l(rank, nat))
allocate(dc6ldcn(rank, nat), source=0.0_wp)
Expand Down Expand Up @@ -144,7 +145,7 @@ subroutine get_dispersion_ewald(mol, lowrank, ghost, terms, nterm, kcut, gwvec,
erecip = -sum(esum)

!$omp parallel default(none) &
!$omp shared(mol, lowrank, terms, nterm, kcut, kpoints, nk, nat, nid, rank, &
!$omp shared(mol, lowrank, kernel, nterm, kcut, kpoints, nk, nat, nid, rank, &
!$omp& c6l, dc6ldcn, vol, grad, partition, esum, dsum, gsum, ssum) &
!$omp private(ik, iat, izp, jzp, il, it, ic, kvec, knorm, kr, phi, dphi, &
!$omp& pval, dpval, qq, zval, zre, zim, phihat, dphihat, phase, sf, fvec, &
Expand All @@ -168,7 +169,7 @@ subroutine get_dispersion_ewald(mol, lowrank, ghost, terms, nterm, kcut, gwvec,
phi = 0.0_wp
dphi = 0.0_wp
do it = 1, nterm(jzp, izp)
call get_fourier_transform(terms(it, jzp, izp), knorm, pval, dpval)
call get_fourier_transform(kernel(it, jzp, izp), knorm, pval, dpval, grad)
phi = phi + pval
dphi = dphi + dpval
end do
Expand Down
Loading
Loading