24#include "./base/base_uses.f90"
30 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_cdft_opt_types'
66 LOGICAL :: build_jacobian = .false.
67 LOGICAL :: broyden_update = .false.
68 LOGICAL :: continue_ls = .false.
69 LOGICAL :: jacobian_restart = .false.
70 REAL(kind=
dp) :: newton_step = 0.0_dp
71 REAL(kind=
dp) :: newton_step_save = 0.0_dp
72 REAL(kind=
dp) :: factor_ls = 0.0_dp
73 REAL(kind=
dp),
DIMENSION(:), &
74 ALLOCATABLE :: jacobian_step
75 REAL(kind=
dp),
DIMENSION(:), &
76 POINTER :: jacobian_vector => null()
77 INTEGER :: jacobian_type = -1
78 INTEGER :: broyden_type = -1
79 INTEGER :: jacobian_freq(2) = -1
80 INTEGER :: ijacobian(2) = -1
81 INTEGER :: max_ls = -1
97 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cdft_opt_type_create'
101 CALL timeset(routinen, handle)
103 cpassert(.NOT.
ASSOCIATED(cdft_opt_control))
104 ALLOCATE (cdft_opt_control)
108 cdft_opt_control%jacobian_type = -1
109 cdft_opt_control%broyden_type = -1
110 cdft_opt_control%jacobian_freq(:) = 1
111 cdft_opt_control%newton_step = 1.0_dp
112 cdft_opt_control%newton_step_save = 1.0_dp
113 cdft_opt_control%factor_ls = 0.5_dp
114 cdft_opt_control%ijacobian(:) = 0
115 cdft_opt_control%max_ls = 0
116 cdft_opt_control%build_jacobian = .false.
117 cdft_opt_control%broyden_update = .false.
118 cdft_opt_control%continue_ls = .false.
119 cdft_opt_control%jacobian_restart = .false.
120 NULLIFY (cdft_opt_control%jacobian_vector)
122 CALL timestop(handle)
137 IF (
ASSOCIATED(cdft_opt_control))
THEN
138 IF (
ASSOCIATED(cdft_opt_control%jacobian_vector))
THEN
139 DEALLOCATE (cdft_opt_control%jacobian_vector)
141 IF (
ALLOCATED(cdft_opt_control%jacobian_step))
THEN
142 DEALLOCATE (cdft_opt_control%jacobian_step)
145 DEALLOCATE (cdft_opt_control)
148 NULLIFY (cdft_opt_control)
165 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cdft_opt_type_read'
168 INTEGER,
DIMENSION(:),
POINTER :: tmplist
170 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rtmplist
173 CALL timeset(routinen, handle)
175 cpassert(
ASSOCIATED(cdft_opt_control))
179 i_val=cdft_opt_control%max_ls)
181 i_val=cdft_opt_control%jacobian_type)
184 ALLOCATE (cdft_opt_control%jacobian_step(
SIZE(rtmplist)))
185 cdft_opt_control%jacobian_step(:) = rtmplist
187 i_val=cdft_opt_control%broyden_type)
189 l_val=cdft_opt_control%continue_ls)
191 r_val=cdft_opt_control%factor_ls)
192 IF (cdft_opt_control%factor_ls <= 0.0_dp .OR. &
193 cdft_opt_control%factor_ls >= 1.0_dp)
THEN
194 CALL cp_abort(__location__, &
195 "Keyword FACTOR_LS must be between 0.0 and 1.0.")
201 IF (
SIZE(tmplist) /= 2)
THEN
202 CALL cp_abort(__location__, &
203 "Keyword JACOBIAN_FREQ takes exactly two input values.")
205 IF (any(tmplist < 0))
THEN
206 CALL cp_abort(__location__, &
207 "Keyword JACOBIAN_FREQ takes only positive values.")
209 IF (all(tmplist == 0))
THEN
210 CALL cp_abort(__location__, &
211 "Both values to keyword JACOBIAN_FREQ cannot be zero.")
213 cdft_opt_control%jacobian_freq(:) = tmplist(1:2)
216 l_val=cdft_opt_control%jacobian_restart)
217 IF (cdft_opt_control%jacobian_restart)
THEN
220 ALLOCATE (cdft_opt_control%jacobian_vector(
SIZE(rtmplist)))
221 cdft_opt_control%jacobian_vector = rtmplist
224 CALL timestop(handle)
239 INTEGER :: optimizer, output_unit
241 cpassert(
ASSOCIATED(cdft_opt_control))
243 SELECT CASE (optimizer)
247 WRITE (output_unit,
'(T3,A)')
"Optimization with Broyden's method"
248 SELECT CASE (cdft_opt_control%broyden_type)
250 WRITE (output_unit,
'(A)')
" variant : 1st method"
252 WRITE (output_unit,
'(A)')
" variant : 1st method with explicit initial Jacobian"
254 WRITE (output_unit,
'(A)')
" variant : 1st method with backtracking line search"
256 WRITE (output_unit,
'(A)') &
257 " variant : 1st method with explicit initial Jacobian"
258 WRITE (output_unit,
'(A)') &
259 " and backtracking line search"
261 WRITE (output_unit,
'(A)')
" variant : 2nd method"
263 WRITE (output_unit,
'(A)')
" variant : 2nd method with explicit initial Jacobian"
265 WRITE (output_unit,
'(A)')
" variant : 2nd method with backtracking line search"
267 WRITE (output_unit,
'(A)') &
268 " variant : 2nd method with explicit initial Jacobian"
269 WRITE (output_unit,
'(A)') &
270 " and backtracking line search"
273 WRITE (output_unit,
'(T3,A)')
"Optimization with Newton's method"
275 WRITE (output_unit,
'(T3,A)')
"Optimization with Newton's method using backtracking line search"
277 SELECT CASE (optimizer)
281 IF (cdft_opt_control%jacobian_freq(2) > 0)
THEN
282 WRITE (output_unit,
'(T6,A,I4,A)') &
283 "The Jacobian is restarted every ", cdft_opt_control%jacobian_freq(2),
" energy evaluation"
284 IF (cdft_opt_control%jacobian_freq(1) > 0)
THEN
285 WRITE (output_unit,
'(T29,A,I4,A)') &
286 "or every ", cdft_opt_control%jacobian_freq(1),
" CDFT SCF iteration"
289 WRITE (output_unit,
'(T6,A,I4,A)') &
290 "The Jacobian is restarted every ", cdft_opt_control%jacobian_freq(1),
" CDFT SCF iteration"
292 WRITE (output_unit,
'(T3,A,F8.4)') &
293 "Optimizer step size: ", cdft_opt_control%newton_step_save
310 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cdft_opt_type_copy'
316 IF (.NOT.
ASSOCIATED(old))
RETURN
318 CALL timeset(routinen, handle)
321 new%max_ls = old%max_ls
322 new%continue_ls = old%continue_ls
323 new%factor_ls = old%factor_ls
324 new%jacobian_type = old%jacobian_type
325 new%jacobian_freq(:) = old%jacobian_freq(:)
326 new%newton_step = old%newton_step
327 new%newton_step_save = old%newton_step_save
328 new%ijacobian(:) = old%ijacobian(:)
329 new%build_jacobian = old%build_jacobian
330 new%broyden_type = old%broyden_type
331 new%broyden_update = old%broyden_update
332 IF (
ALLOCATED(new%jacobian_step))
DEALLOCATE (new%jacobian_step)
333 ALLOCATE (new%jacobian_step(
SIZE(old%jacobian_step)))
334 new%jacobian_step(:) = old%jacobian_step
335 IF (old%jacobian_restart)
THEN
338 new%jacobian_restart = .true.
339 ALLOCATE (new%jacobian_vector(
SIZE(old%jacobian_vector)))
340 new%jacobian_vector = old%jacobian_vector
341 DEALLOCATE (old%jacobian_vector)
342 old%jacobian_restart = .false.
345 CALL timestop(handle)
Defines the basic variable types.
integer, parameter, public dp
Control parameters for optimizers that work with CDFT constraints.
subroutine, public cdft_opt_type_create(cdft_opt_control)
allocates and initializes the CDFT optimizer control object with default values
subroutine, public cdft_opt_type_release(cdft_opt_control)
releases the CDFT optimizer control object
subroutine, public cdft_opt_type_copy(new, old)
copies settings between two CDFT optimizer control objects retaining both
subroutine, public cdft_opt_type_read(cdft_opt_control, inp_section)
reads the parameters of the CDFT optimizer type
subroutine, public cdft_opt_type_write(cdft_opt_control, optimizer, output_unit)
writes information about the CDFT optimizer object
contains the parameters needed by CDFT specific optimizers