9 USE ieee_arithmetic,
ONLY: ieee_is_finite
19 USE mctc_env,
ONLY: error_type
20 USE tblite_scf_mixer_type,
ONLY: mixer_type
26 REAL(kind=
dp),
DIMENSION(1, 1) :: charges
30 NULLIFY (mixing_store, para_env)
34 ALLOCATE (mixing_store)
35 mixing_store%ncall = 0
36 mixing_store%nbuffer = 4
37 mixing_store%n_simple_mix = 0
38 mixing_store%nskip_mixing = 0
39 mixing_store%alpha = 0.1_dp
40 mixing_store%broy_w0 = 0.01_dp
41 mixing_store%nat_local = 1
42 mixing_store%max_shell = 1
43 ALLOCATE (mixing_store%acharge(1, 1, 4), mixing_store%dacharge(1, 1, 4), &
44 mixing_store%dfbroy(1, 1, 4), mixing_store%ubroy(1, 1, 4), &
45 mixing_store%abroy(4, 4), mixing_store%wbroy(4), mixing_store%atlist(1))
46 mixing_store%acharge = 0.0_dp
47 mixing_store%dacharge = 0.0_dp
48 mixing_store%dfbroy = 0.0_dp
49 mixing_store%ubroy = 0.0_dp
50 mixing_store%abroy = 0.0_dp
51 mixing_store%wbroy = 0.0_dp
52 mixing_store%atlist = 1
60 charges(1, 1) = mixing_store%acharge(1, 1, 2) - mixing_store%dacharge(1, 1, 1)
63 IF (.NOT. all(ieee_is_finite(charges)))
THEN
64 error stop
"Broyden mixing produced non-finite charges for identical residuals"
66 IF (.NOT. all(mixing_store%dfbroy(:, :, 1) == 0.0_dp))
THEN
67 error stop
"Degenerate Broyden direction was not discarded"
71 DEALLOCATE (mixing_store)
73 CALL test_tblite_history()
84 SUBROUTINE test_tblite_history()
85 INTEGER,
PARAMETER :: nstep = 16, nvar = 4
87 INTEGER :: config, i, j, memory, step
88 REAL(kind=
dp) :: damping, max_weight, min_weight, omega0, &
90 REAL(kind=
dp),
DIMENSION(nvar) :: actual, expected
91 REAL(kind=
dp),
DIMENSION(nvar, nstep) :: qin, qout
93 CLASS(mixer_type),
ALLOCATABLE :: mixer, replay
94 TYPE(error_type),
ALLOCATABLE :: error
98 qin(i, step) = sin(0.37_dp*real(i*step,
dp))
99 qout(i, step) = qin(i, step) + 0.05_dp*cos(0.21_dp*real(i + 2*step,
dp))
106 max_weight = 100000.0_dp
107 weight_factor = 0.01_dp
108 IF (config == 2)
THEN
113 weight_factor = 0.2_dp
116 CALL new_cp2k_tblite_mixer(mixer, memory, nvar, damping, omega0, min_weight, max_weight, weight_factor)
118 CALL mixer%set(qin(:, step))
119 CALL mixer%diff(qout(:, step))
120 CALL mixer%next(error)
121 IF (
ALLOCATED(error)) error stop
"Wrapped tblite mixer failed"
122 CALL mixer%get(actual)
126 CALL new_cp2k_tblite_mixer(replay, memory, nvar, damping, omega0, min_weight, max_weight, weight_factor)
127 DO j = max(1, step - memory), step
128 CALL replay%set(qin(:, j))
129 CALL replay%diff(qout(:, j))
130 CALL replay%next(error)
131 IF (
ALLOCATED(error)) error stop
"Replayed tblite mixer failed"
133 CALL replay%get(expected)
134 IF (.NOT. all(ieee_is_finite(actual))) error stop
"Non-finite wrapped tblite history"
135 IF (maxval(abs(actual - expected)) > 1.0e-10_dp)
THEN
136 error stop
"Wrapped tblite history differs from an unwrapped replay"
142 END SUBROUTINE test_tblite_history
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
subroutine, public mp_world_init(mp_comm)
initializes the system default communicator
subroutine, public mp_world_finalize()
Finalize the system default communicator and MPI when CP2K owns MPI.
subroutine, public charge_mixing(mixing_method, mixing_store, charges, para_env, iter_count, scc_mixer, tblite_mixer_iterations, tblite_mixer_damping, tblite_mixer_memory, tblite_mixer_omega0, tblite_mixer_min_weight, tblite_mixer_max_weight, tblite_mixer_weight_factor)
Driver for TB SCC variable mixing, calls the requested method.
module that contains the definitions of the scf types
integer, parameter, public broyden_mixing_nr
subroutine, public mixing_storage_release(mixing_store)
releases a mixing_storage
CP2K-side tblite-compatible SCC Broyden mixer.
program qs_charge_mixing_unittest
stores all the informations relevant to an mpi environment