(git:f2099e5)
Loading...
Searching...
No Matches
topology_snapshot_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 cp_files, ONLY: close_file,&
11 USE kinds, ONLY: dp
17
18 IMPLICIT NONE
19 REAL(kind=dp), PARAMETER :: pi = 3.1415926535897932384626433832795_dp, tolerance = 1.e-12_dp
20 TYPE(snapshot_type) :: a, b
21 COMPLEX(KIND=dp) :: m(1, 1), reverse(1, 1), phase
22 REAL(kind=dp) :: metric, gap
23 INTEGER :: i
26 a%nao = 1
27 a%rank = 1
28 a%nspin = 1
29 a%channel = 1
30 DO i = 1, 3
31 a%cell(i, i) = 20.0_dp
32 a%inverse(i, i) = 0.05_dp
33 END DO
34 ALLOCATE (a%atoms(1), a%bands(1), a%energies(2), a%coefficients(1, 1))
35 a%bands(1) = 1
36 a%energies(:) = [-1.0_dp, 1.0_dp]
37 a%coefficients(:, :) = 1.0_dp
38 a%atoms(1)%kind = 1
39 a%atoms(1)%count = 1
40 ALLOCATE (a%atoms(1)%shells(1))
41 associate(s => a%atoms(1)%shells(1))
42 s%first = 1
43 s%count = 1
44 s%radius = 5.0_dp
45 ALLOCATE (s%exponent(1), s%radii(1), s%contraction(1, 1))
46 s%exponent(1) = 1.0_dp
47 s%radii(1) = 5.0_dp
48 s%contraction(1, 1) = (2.0_dp/pi)**0.75_dp
49 END associate
50 CALL check_snapshot(a, tolerance, tolerance, metric, gap)
51 IF (metric > tolerance .OR. abs(gap - 2.0_dp) > tolerance) error stop 'Incorrect snapshot metric or gap'
52 ! Derived-type assignment deliberately deep-copies allocatable frame components.
53 b = a
54 b%atoms(1)%center(1) = 0.7_dp
55 b%atoms(1)%shells(1)%center(1) = 0.7_dp
56 phase = exp(cmplx(0.0_dp, 0.3_dp, dp))
57 b%coefficients(:, :) = phase
58 CALL snapshot_overlap(a, b, a%k, b%k, m)
59 IF (abs(m(1, 1) - phase*exp(-0.7_dp**2/2.0_dp)) > tolerance) error stop 'Moving Gaussian overlap failed'
60 CALL snapshot_overlap(b, a, b%k, a%k, reverse)
61 IF (abs(m(1, 1) - conjg(reverse(1, 1))) > tolerance) error stop 'Directed overlap adjoint failed'
62 b%atoms(1)%center(:) = 0.0_dp
63 b%atoms(1)%shells(1)%center(:) = 0.0_dp
64 CALL check_snapshot_seam(a, b, [1], tolerance)
65 CALL snapshot_overlap(a, b, a%k, b%k, m)
66 IF (abs(m(1, 1) - phase) > tolerance) error stop 'Endpoint gauge sewing failed'
67
68CONTAINS
69
70! **************************************************************************************************
71!> \brief Exercise anonymous link storage without named files or shared-unit collisions.
72! **************************************************************************************************
73 SUBROUTINE test_scratch_links()
74 CHARACTER(LEN=5) :: text
75 COMPLEX(KIND=dp) :: link(2, 2), restored(2, 2)
76 INTEGER :: binary_unit, ios, record_size, text_unit
77 LOGICAL :: named, opened
78
79 link(:, :) = cmplx(1.0_dp, 2.0_dp, dp)
80 CALL open_file('', unit_number=binary_unit, file_status='SCRATCH', file_access='STREAM', &
81 file_form='UNFORMATTED', file_action='READWRITE')
82 INQUIRE (unit=binary_unit, named=named, iostat=ios)
83 IF (ios /= 0) error stop 'Cannot inquire scratch link storage'
84 IF (named) error stop 'Link scratch storage must be anonymous'
85 CALL open_file('', unit_number=text_unit, file_status='SCRATCH', file_pad='NO', file_action='READWRITE')
86 IF (binary_unit == text_unit) error stop 'Scratch streams share a unit'
87 INQUIRE (iolength=record_size) link
88 WRITE (binary_unit, iostat=ios) link
89 IF (ios /= 0) error stop 'Cannot write first scratch link'
90 WRITE (binary_unit, iostat=ios) 2.0_dp*link
91 IF (ios /= 0) error stop 'Cannot write second scratch link'
92 READ (binary_unit, pos=record_size + 1, iostat=ios) restored
93 IF (ios /= 0) error stop 'Cannot read second scratch link'
94 IF (maxval(abs(restored - 2.0_dp*link)) > tolerance) error stop 'Incorrect second scratch link'
95 READ (binary_unit, pos=1, iostat=ios) restored
96 IF (ios /= 0) error stop 'Cannot read first scratch link'
97 IF (maxval(abs(restored - link)) > tolerance) error stop 'Incorrect first scratch link'
98 WRITE (text_unit, '(A)', iostat=ios) 'links'
99 IF (ios /= 0) error stop 'Cannot write formatted scratch file'
100 rewind(text_unit)
101 READ (text_unit, '(A)', iostat=ios) text
102 IF (ios /= 0) error stop 'Cannot read formatted scratch file'
103 IF (text /= 'links') error stop 'Incorrect formatted scratch contents'
104 CALL close_file(binary_unit)
105 CALL close_file(text_unit)
106 INQUIRE (unit=binary_unit, opened=opened, iostat=ios)
107 IF (ios /= 0) error stop 'Cannot inquire closed scratch stream'
108 IF (opened) error stop 'Scratch stream was not closed'
109 INQUIRE (unit=text_unit, opened=opened, iostat=ios)
110 IF (ios /= 0) error stop 'Cannot inquire closed formatted scratch file'
111 IF (opened) error stop 'Formatted scratch file was not closed'
112 END SUBROUTINE test_scratch_links
Utility routines to open and close files. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:323
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Definition cp_files.F:123
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Provides Cartesian and spherical orbital pointers and indices.
subroutine, public init_orbital_pointers(maxl)
Initialize or update the orbital pointers.
Reader and physical moving-basis links for version-1 topology snapshots.
subroutine, public check_snapshot_seam(a, b, permutation, tolerance)
Check explicitly prescribed atom permutation, periodic translations and basis at a seam.
subroutine, public snapshot_overlap(a, b, ka, kb, overlap)
Apply screened Gaussian cross-geometry operator by atom blocks, without a dense AO matrix.
subroutine, public check_snapshot(a, metric_tol, gap_tol, metric_error, gap)
Check AO-metric normalization and separation at every selected/excluded boundary.
program topology_snapshot_unittest
subroutine test_scratch_links()
Exercise anonymous link storage without named files or shared-unit collisions.