(git:6344619)
Loading...
Searching...
No Matches
hfx_pair_list_methods_unittest.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
10 USE kinds, ONLY: dp
11
12 IMPLICIT NONE
13
14 REAL(kind=dp), DIMENSION(3, 3) :: hmat
15
16 ! Orthorhombic cell with two reversed cell vectors (positive determinant):
17 ! moving r = (4,0,0) by the image (-10,0,0) gives |r'|**2 = 36, i.e. a gap of 20.
18 hmat = 0.0_dp
19 hmat(1, 1) = -10.0_dp
20 hmat(2, 2) = -12.0_dp
21 hmat(3, 3) = 14.0_dp
22 IF (abs(min_image_gap_sq([4.0_dp, 0.0_dp, 0.0_dp], hmat) - 20.0_dp) > 1.0e-12_dp) THEN
23 error stop "Wrong minimum-image gap for reversed cell vectors"
24 END IF
25
26 CALL check_against_all_images([10.0_dp, 12.0_dp, 14.0_dp])
27 CALL check_against_all_images([-10.0_dp, -12.0_dp, 14.0_dp])
28 CALL check_against_all_images([-10.0_dp, 12.0_dp, 14.0_dp])
29 CALL check_against_all_images([10.0_dp, -12.0_dp, -14.0_dp])
30
31CONTAINS
32
33! **************************************************************************************************
34!> \brief Compare min_image_gap_sq with an explicit search over neighbouring images.
35!> \param diag diagonal entries of an orthorhombic cell matrix
36! **************************************************************************************************
37 SUBROUTINE check_against_all_images(diag)
38 REAL(KIND=dp), DIMENSION(3), INTENT(IN) :: diag
39
40 INTEGER :: i, j, k, n1, n2, n3
41 REAL(KIND=dp) :: exact, gap
42 REAL(KIND=dp), DIMENSION(3) :: r, shifted
43 REAL(KIND=dp), DIMENSION(3, 3) :: cell
44
45 cell = 0.0_dp
46 cell(1, 1) = diag(1)
47 cell(2, 2) = diag(2)
48 cell(3, 3) = diag(3)
49
50 ! minimum-image vectors on a grid of fractional coordinates in [-1/2, 1/2]
51 DO i = -8, 8
52 DO j = -8, 8
53 DO k = -8, 8
54 r = [real(i, dp)*abs(diag(1)), real(j, dp)*abs(diag(2)), real(k, dp)*abs(diag(3))]/16.0_dp
55 gap = min_image_gap_sq(r, cell)
56 exact = huge(1.0_dp)
57 DO n1 = -2, 2
58 DO n2 = -2, 2
59 DO n3 = -2, 2
60 IF (n1 == 0 .AND. n2 == 0 .AND. n3 == 0) cycle
61 shifted = r - matmul(cell, real([n1, n2, n3], dp))
62 exact = min(exact, sum(shifted**2) - sum(r**2))
63 END DO
64 END DO
65 END DO
66 IF (abs(gap - exact) > 1.0e-10_dp) THEN
67 error stop "min_image_gap_sq differs from the explicit image search"
68 END IF
69 END DO
70 END DO
71 END DO
72
73 END SUBROUTINE check_against_all_images
74
subroutine check_against_all_images(diag)
Compare min_image_gap_sq with an explicit search over neighbouring images.
program hfx_pair_list_methods_unittest
Routines for optimizing load balance between processes in HFX calculations.
pure real(dp) function, public min_image_gap_sq(r, hmat)
Smallest increase of |r|**2 when r is moved to any other periodic image of an orthorhombic,...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34