(git:98357aa)
Loading...
Searching...
No Matches
cell_types_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
9 USE cell_types, ONLY: cell_type,&
13 USE kinds, ONLY: dp
14
15 IMPLICIT NONE
16
17 TYPE(cell_type), POINTER :: cell
18
19 ALLOCATE (cell)
20 cell%hmat = 0.0_dp
21 cell%h_inv = 0.0_dp
22 cell%hmat(1, 1) = 2.0_dp
23 cell%hmat(2, 2) = 3.0_dp
24 cell%hmat(3, 3) = 4.0_dp
25 cell%h_inv(1, 1) = 0.5_dp
26 cell%h_inv(2, 2) = 1.0_dp/3.0_dp
27 cell%h_inv(3, 3) = 0.25_dp
28 cell%perd = 1
29
30 cell%orthorhombic = .true.
32
33 cell%orthorhombic = .false.
34 cell%hmat(1, 2) = 0.5_dp
35 cell%h_inv(1, 2) = -1.0_dp/12.0_dp
37
38 DEALLOCATE (cell)
39
40CONTAINS
41
42! **************************************************************************************************
43!> \brief Check that roundoff around half-cell boundaries does not change the periodic image.
44!> \param cell ...
45! **************************************************************************************************
47
48 TYPE(cell_type), POINTER :: cell
49
50 INTEGER, DIMENSION(3), PARAMETER :: lattice_translation = [-1, 1, -2]
51 REAL(KIND=dp), PARAMETER :: delta = 8.0_dp*epsilon(1.0_dp)
52
53 REAL(KIND=dp), DIMENSION(3) :: r, scaled, wrapped, wrapped_scaled, &
54 wrapped_translated, &
55 wrapped_translated_scaled
56
57 scaled = [0.5_dp - delta, -0.5_dp + delta, 1.5_dp - delta]
58 CALL scaled_to_real(r, scaled, cell)
59 wrapped = pbc_stable(r, cell)
60 CALL real_to_scaled(wrapped_scaled, wrapped, cell)
61 IF (any(sign(1.0_dp, wrapped_scaled) /= [-1.0_dp, -1.0_dp, -1.0_dp])) THEN
62 error stop "Roundoff changed the image at a half-cell boundary"
63 END IF
64 IF (any(abs(abs(wrapped_scaled) - 0.5_dp) > 2.0_dp*delta)) THEN
65 error stop "Unexpected wrapped coordinate at a half-cell boundary"
66 END IF
67
68 CALL scaled_to_real(r, scaled + real(lattice_translation, kind=dp), cell)
69 wrapped_translated = pbc_stable(r, cell)
70 CALL real_to_scaled(wrapped_translated_scaled, wrapped_translated, cell)
71 IF (any(abs(wrapped_translated_scaled - wrapped_scaled) > 4.0_dp*delta)) THEN
72 error stop "Periodic wrapping changed under a lattice translation"
73 END IF
74
75 scaled = [0.5_dp - 128.0_dp*epsilon(1.0_dp), &
76 -0.5_dp - 128.0_dp*epsilon(1.0_dp), &
77 1.5_dp + 128.0_dp*epsilon(1.0_dp)]
78 CALL scaled_to_real(r, scaled, cell)
79 wrapped = pbc_stable(r, cell)
80 CALL real_to_scaled(wrapped_scaled, wrapped, cell)
81 IF (any(sign(1.0_dp, wrapped_scaled) /= [1.0_dp, 1.0_dp, -1.0_dp])) THEN
82 error stop "Coordinate outside the boundary tolerance changed image"
83 END IF
84
85 END SUBROUTINE check_half_cell_boundaries
86
87END PROGRAM cell_types_test
subroutine check_half_cell_boundaries(cell)
Check that roundoff around half-cell boundaries does not change the periodic image.
program cell_types_test
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public scaled_to_real(r, s, cell)
Transform scaled cell coordinates real coordinates. r=h*s.
Definition cell_types.F:625
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
Definition cell_types.F:595
real(kind=dp) function, dimension(3), public pbc_stable(r, cell)
Apply a stable periodic-image convention for k-point Bloch gauges.
Definition cell_types.F:422
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Type defining parameters related to the simulation cell.
Definition cell_types.F:60