(git:f2099e5)
Loading...
Searching...
No Matches
qs_fod_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 kinds, ONLY: dp
10 USE qs_fod, ONLY: fod_weights
11
12 IMPLICIT NONE
13 REAL(dp), DIMENSION(4) :: occ, eig, weight, expected
14
15 eig = [-1.0_dp, -0.1_dp, 0.0_dp, 0.2_dp]
16 occ = [2.0_dp, 1.6_dp, 1.0_dp, 0.2_dp]
17 expected = [0.0_dp, 0.4_dp, 1.0_dp, 0.2_dp]
18 weight = fod_weights(occ, eig, 0.0_dp, 2.0_dp)
19 IF (maxval(abs(weight - expected)) > 1.0e-14_dp) error stop "Restricted FOD weights"
20 weight = fod_weights(0.5_dp*occ, eig, 0.0_dp, 1.0_dp)
21 IF (maxval(abs(2.0_dp*weight - expected)) > 1.0e-14_dp) error stop "Unrestricted FOD weights"
22
23 ! Fractional spin populations: the electron-count/index split is not valid.
24 eig = [0.1_dp, 0.2_dp, 0.3_dp, 0.4_dp]
25 occ = [0.4_dp, 0.3_dp, 0.2_dp, 0.1_dp]
26 weight = fod_weights(occ, eig, 0.0_dp, 1.0_dp)
27 IF (maxval(abs(weight - occ)) > 1.0e-14_dp) error stop "FOD must use the chemical potential"
28 weight = fod_weights(occ(4:1:-1), eig(4:1:-1), 0.0_dp, 1.0_dp)
29 IF (maxval(abs(weight - occ(4:1:-1))) > 1.0e-14_dp) error stop "FOD orbital permutation"
30
31 ! Integer occupations vanish; a shift of the energy zero changes nothing.
32 eig = [-2.0_dp, -1.0_dp, 1.0_dp, 2.0_dp]
33 occ = [2.0_dp, 2.0_dp, 0.0_dp, 0.0_dp]
34 weight = fod_weights(occ, eig + 3.0_dp, 3.0_dp, 2.0_dp)
35 IF (any(weight /= 0.0_dp)) error stop "Integer occupations should have no FOD"
36END PROGRAM qs_fod_unittest
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Fractional occupation number weighted density (Grimme and Hansen).
Definition qs_fod.F:12
pure real(dp) function, dimension(size(occupation)), public fod_weights(occupation, eigenvalues, mu, maxocc)
Hole weights below the chemical potential, particle weights above it.
Definition qs_fod.F:71
program qs_fod_unittest