50 #include "./base/base_uses.f90"
56 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'scf_control_types'
57 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
61 PUBLIC :: scf_control_type, &
94 REAL(KIND=
dp) :: electronic_temperature, &
98 REAL(KIND=
dp),
DIMENSION(:),
POINTER ::
list
101 TYPE diagonalization_type
103 REAL(KIND=
dp) :: eps_jacobi
104 REAL(KIND=
dp) :: jacobi_threshold
105 INTEGER :: max_iter, nkrylov, nblock_krylov
107 LOGICAL :: mom, mom_didguess
108 INTEGER :: mom_proj_formula
110 INTEGER,
DIMENSION(:),
POINTER :: mom_deoccA, mom_deoccB, mom_occA, mom_occB
117 REAL(KIND=
dp) :: eps_iter
118 REAL(KIND=
dp) :: eps_adapt
119 TYPE(qs_ot_settings_type) :: ot_settings
120 END TYPE diagonalization_type
122 TYPE scf_control_type
123 TYPE(outer_scf_control_type) :: outer_scf
124 TYPE(smear_type),
POINTER :: smear
125 TYPE(diagonalization_type) :: diagonalization
126 INTEGER :: density_guess, mixing_method
127 REAL(KIND=
dp) :: eps_eigval, eps_scf, eps_scf_hist, &
130 INTEGER :: max_iter_lumos, max_diis, nmixing
131 INTEGER :: max_scf, max_scf_hist, &
133 LOGICAL :: do_diag_sub, &
134 use_cholesky, use_ot, use_diag, do_outer_scf_reortho, &
135 ignore_convergence_failure
136 INTEGER,
DIMENSION(2) :: added_mos
137 INTEGER :: roks_scheme
138 REAL(KIND=
dp) :: roks_f
139 REAL(KIND=
dp),
DIMENSION(0:2, 0:2, 1:2) :: roks_parameter
140 END TYPE scf_control_type
154 TYPE(scf_control_type),
INTENT(OUT) :: scf_control
156 CHARACTER(LEN=*),
PARAMETER :: routinen =
'scf_c_create'
160 CALL timeset(routinen, handle)
165 scf_control%eps_eigval = 1.0e-5_dp
166 scf_control%eps_scf = 1.0e-5_dp
167 scf_control%eps_scf_hist = 0.0_dp
168 scf_control%eps_lumos = 1.0e-5_dp
169 scf_control%max_iter_lumos = 2999
170 scf_control%eps_diis = 0.1_dp
171 scf_control%level_shift = 0.0_dp
172 scf_control%max_diis = 4
173 scf_control%max_scf = 50
174 scf_control%nmixing = 2
175 scf_control%use_cholesky = .true.
176 scf_control%use_diag = .true.
177 scf_control%do_diag_sub = .false.
178 scf_control%use_ot = .false.
179 scf_control%ignore_convergence_failure = .false.
180 scf_control%do_outer_scf_reortho = .true.
181 scf_control%max_diis = 4
182 scf_control%eps_diis = 0.1_dp
183 scf_control%added_mos(:) = 0
184 scf_control%max_scf_hist = 0
190 scf_control%diagonalization%method = 0
191 scf_control%diagonalization%eps_jacobi = 0.0_dp
192 scf_control%diagonalization%jacobi_threshold = 1.0e-7_dp
193 scf_control%diagonalization%max_iter = 0
194 scf_control%diagonalization%eps_iter = 0.0_dp
195 scf_control%diagonalization%eps_adapt = 0.0_dp
196 scf_control%diagonalization%nkrylov = 0
197 scf_control%diagonalization%nblock_krylov = 0
200 scf_control%diagonalization%mom = .false.
201 scf_control%diagonalization%mom_didguess = .false.
202 scf_control%diagonalization%mom_proj_formula = 0
203 NULLIFY (scf_control%diagonalization%mom_deoccA)
204 NULLIFY (scf_control%diagonalization%mom_deoccB)
205 NULLIFY (scf_control%diagonalization%mom_occA)
206 NULLIFY (scf_control%diagonalization%mom_occB)
207 scf_control%diagonalization%mom_start = 0
212 scf_control%roks_f = 0.5_dp
217 scf_control%roks_parameter(0, 0, 1) = 1.5_dp
218 scf_control%roks_parameter(0, 0, 2) = -0.5_dp
219 scf_control%roks_parameter(1, 1, 1) = 0.5_dp
220 scf_control%roks_parameter(1, 1, 2) = 0.5_dp
221 scf_control%roks_parameter(2, 2, 1) = -0.5_dp
222 scf_control%roks_parameter(2, 2, 2) = 1.5_dp
226 scf_control%roks_parameter(0, 1, 1) = 1.0_dp
227 scf_control%roks_parameter(0, 1, 2) = 0.0_dp
228 scf_control%roks_parameter(0, 2, 1) = 0.5_dp
229 scf_control%roks_parameter(0, 2, 2) = 0.5_dp
230 scf_control%roks_parameter(1, 2, 1) = 0.0_dp
231 scf_control%roks_parameter(1, 2, 2) = 1.0_dp
235 scf_control%roks_parameter(1, 0, 1) = scf_control%roks_parameter(0, 1, 1)
236 scf_control%roks_parameter(1, 0, 2) = scf_control%roks_parameter(0, 1, 2)
237 scf_control%roks_parameter(2, 0, 1) = scf_control%roks_parameter(0, 2, 1)
238 scf_control%roks_parameter(2, 0, 2) = scf_control%roks_parameter(0, 2, 2)
239 scf_control%roks_parameter(2, 1, 1) = scf_control%roks_parameter(1, 2, 1)
240 scf_control%roks_parameter(2, 1, 2) = scf_control%roks_parameter(1, 2, 2)
244 scf_control%outer_scf%have_scf = .false.
245 scf_control%outer_scf%max_scf = 0
246 scf_control%outer_scf%eps_scf = 0.0_dp
247 scf_control%outer_scf%step_size = 0.0_dp
248 scf_control%outer_scf%type = -1
249 scf_control%outer_scf%optimizer = -1
250 scf_control%outer_scf%diis_buffer_length = -1
251 NULLIFY (scf_control%outer_scf%cdft_opt_control)
255 NULLIFY (scf_control%smear)
257 CALL timestop(handle)
272 TYPE(scf_control_type),
INTENT(INOUT) :: scf_control
274 IF (
ASSOCIATED(scf_control%smear%list))
THEN
275 DEALLOCATE (scf_control%smear%list)
277 DEALLOCATE (scf_control%smear)
279 IF (
ASSOCIATED(scf_control%outer_scf%cdft_opt_control)) &
300 TYPE(scf_control_type),
INTENT(INOUT) :: scf_control
301 TYPE(section_vals_type),
POINTER :: inp_section
303 CHARACTER(LEN=*),
PARAMETER :: routinen =
'scf_c_read_parameters'
305 INTEGER :: cholesky_flag, handle, ialgo
306 INTEGER,
DIMENSION(:),
POINTER :: added_mos
308 REAL(kind=
dp),
DIMENSION(:),
POINTER :: roks_parameter
309 TYPE(section_vals_type),
POINTER :: mixing_section, outer_scf_section, &
310 scf_section, smear_section
312 CALL timeset(routinen, handle)
316 l_val=scf_control%use_diag)
317 IF (scf_control%use_diag)
THEN
319 l_val=scf_control%do_diag_sub)
322 IF (scf_control%use_diag .AND. scf_control%use_ot)
THEN
324 cpabort(
"Don't activate OT and Diagonaliztion together")
325 ELSEIF (.NOT. (scf_control%use_diag .OR. scf_control%use_ot))
THEN
327 scf_control%use_diag = .true.
335 IF (cholesky_flag > 0)
THEN
336 scf_control%use_cholesky = .true.
338 CALL section_vals_val_get(scf_section,
"IGNORE_CONVERGENCE_FAILURE", l_val=scf_control%ignore_convergence_failure)
345 IF (scf_control%use_diag)
THEN
347 i_val=scf_control%diagonalization%method)
349 r_val=scf_control%diagonalization%eps_jacobi)
351 r_val=scf_control%diagonalization%jacobi_threshold)
353 i_val=scf_control%diagonalization%max_iter)
355 r_val=scf_control%diagonalization%eps_iter)
357 r_val=scf_control%diagonalization%eps_adapt)
359 i_val=scf_control%diagonalization%nkrylov)
361 i_val=scf_control%diagonalization%nblock_krylov)
362 IF (scf_control%diagonalization%method ==
diag_ot)
THEN
364 CALL ot_diag_read_input(scf_control%diagonalization%ot_settings, scf_section)
368 l_val=scf_control%diagonalization%MOM)
369 IF (scf_control%diagonalization%mom)
THEN
371 i_val=scf_control%diagonalization%mom_type)
374 i_val=scf_control%diagonalization%mom_start)
377 i_vals=scf_control%diagonalization%mom_deoccA)
380 i_vals=scf_control%diagonalization%mom_deoccB)
383 i_vals=scf_control%diagonalization%mom_occA)
386 i_vals=scf_control%diagonalization%mom_occB)
389 i_val=scf_control%diagonalization%mom_proj_formula)
396 SELECT CASE (scf_control%roks_scheme)
403 NULLIFY (roks_parameter)
405 IF (
ASSOCIATED(roks_parameter))
THEN
406 scf_control%roks_parameter(2, 2, 1) = roks_parameter(1)
407 scf_control%roks_parameter(2, 2, 2) = roks_parameter(2)
408 scf_control%roks_parameter(1, 1, 1) = roks_parameter(3)
409 scf_control%roks_parameter(1, 1, 2) = roks_parameter(4)
410 scf_control%roks_parameter(0, 0, 1) = roks_parameter(5)
411 scf_control%roks_parameter(0, 0, 2) = roks_parameter(6)
421 cpassert(
ASSOCIATED(added_mos))
422 IF (
SIZE(added_mos) > 0)
THEN
423 scf_control%added_mos(1) = added_mos(1)
424 IF (
SIZE(added_mos) > 1)
THEN
425 scf_control%added_mos(2) = added_mos(2)
432 IF (scf_control%level_shift /= 0.0_dp) scf_control%use_cholesky = .false.
439 CALL init_smear(scf_control%smear)
440 CALL read_smear_section(scf_control%smear, smear_section)
448 i_val=scf_control%mixing_method)
452 CALL timestop(handle)
460 SUBROUTINE init_smear(smear)
461 TYPE(smear_type),
POINTER :: smear
463 cpassert(.NOT.
ASSOCIATED(smear))
465 smear%do_smear = .false.
467 smear%electronic_temperature = 0.0_dp
468 smear%eps_fermi_dirac = 1.0e-5_dp
469 smear%fixed_mag_mom = -100.0_dp
470 smear%window_size = 0.0_dp
472 END SUBROUTINE init_smear
479 SUBROUTINE read_smear_section(smear, smear_section)
480 TYPE(smear_type),
POINTER :: smear
481 TYPE(section_vals_type),
POINTER :: smear_section
483 REAL(kind=
dp),
DIMENSION(:),
POINTER :: r_vals
488 l_val=smear%do_smear)
489 IF (smear%do_smear)
THEN
493 r_val=smear%electronic_temperature)
495 r_val=smear%eps_fermi_dirac)
497 r_val=smear%window_size)
501 cpassert(
ASSOCIATED(r_vals))
502 ALLOCATE (smear%list(
SIZE(r_vals)))
506 r_val=smear%fixed_mag_mom)
508 END SUBROUTINE read_smear_section
521 TYPE(scf_control_type),
INTENT(IN) :: scf_control
522 TYPE(section_vals_type),
POINTER :: dft_section
524 CHARACTER(LEN=*),
PARAMETER :: routinen =
'scf_c_write_parameters'
526 INTEGER :: handle, output_unit, roks_scheme
528 REAL(kind=
dp) :: elec_temp
529 TYPE(cp_logger_type),
POINTER :: logger
530 TYPE(enumeration_type),
POINTER :: enum
531 TYPE(keyword_type),
POINTER :: keyword
532 TYPE(section_type),
POINTER :: section
533 TYPE(section_vals_type),
POINTER :: scf_section
535 CALL timeset(routinen, handle)
540 NULLIFY (scf_section)
547 IF (output_unit > 0)
THEN
549 IF (scf_control%max_scf > 0)
THEN
556 WRITE (unit=output_unit, &
557 fmt=
"(/,/,T2,A,T25,A,T51,A30,/,T25,56('-'),3(/,T25,A,T76,I5),/, "// &
558 "T25,56('-'),4(/,T25,A,T72,ES9.2),/,T25,56('-'), "// &
559 "1(/,T25,A,T71,F10.6))") &
561 "Density guess: ", adjustr(trim(
enum_i2c(enum, scf_control%density_guess))), &
562 "max_scf: ", scf_control%max_scf, &
563 "max_scf_history: ", scf_control%max_scf_hist, &
564 "max_diis: ", scf_control%max_diis, &
565 "eps_scf: ", scf_control%eps_scf, &
566 "eps_scf_history: ", scf_control%eps_scf_hist, &
567 "eps_diis: ", scf_control%eps_diis, &
568 "eps_eigval: ", scf_control%eps_eigval, &
569 "level_shift [a.u.]:", scf_control%level_shift
570 IF (sum(abs(scf_control%added_mos)) > 0)
THEN
571 WRITE (unit=output_unit, fmt=
"(T25,A,T71,2I5)") &
572 "added MOs ", scf_control%added_mos
575 IF (scf_control%diagonalization%mom)
THEN
577 WRITE (unit=output_unit, fmt=
"(T25,A)")
"MOM enabled"
580 IF (scf_control%mixing_method > 0 .AND. .NOT. scf_control%use_ot)
THEN
583 WRITE (unit=output_unit, fmt=
"(T25,A,/,T25,A,T51,A30)") &
585 "Mixing method: ", adjustr(trim(
enum_i2c(enum, scf_control%mixing_method)))
586 IF (scf_control%mixing_method > 1)
THEN
587 WRITE (unit=output_unit, fmt=
"(T47,A34)")
"charge density mixing in g-space"
590 IF (scf_control%smear%do_smear)
THEN
593 WRITE (unit=output_unit, fmt=
"(T25,A,/,T25,A,T51,A30)") &
595 "Smear method: ", adjustr(trim(
enum_i2c(enum, scf_control%smear%method)))
596 SELECT CASE (scf_control%smear%method)
600 WRITE (unit=output_unit, fmt=
"(T25,A,T61,F20.1)") &
601 "Electronic temperature [K]:", elec_temp
602 WRITE (unit=output_unit, fmt=
"(T25,A,T71,ES10.2)") &
603 "Electronic temperature [a.u.]:", scf_control%smear%electronic_temperature, &
604 "Accuracy threshold:", scf_control%smear%eps_fermi_dirac
605 IF (scf_control%smear%fixed_mag_mom > 0.0_dp)
WRITE (unit=output_unit, fmt=
"(T25,A,F10.5)") &
606 "Spin channel alpha and spin channel beta are smeared independently, keeping"// &
607 " fixed difference in number of electrons equal to ", scf_control%smear%fixed_mag_mom
609 WRITE (unit=output_unit, fmt=
"(T25,A,T71,F10.6)") &
610 "Smear window [a.u.]: ", scf_control%smear%window_size
615 IF (roks .AND. (.NOT. scf_control%use_ot))
THEN
620 WRITE (unit=output_unit, fmt=
"(T25,A,/,T25,A,T51,A30)") &
622 "ROKS scheme:", adjustr(trim(
enum_i2c(enum, roks_scheme)))
623 SELECT CASE (roks_scheme)
625 WRITE (unit=output_unit, fmt=
"(T25,A,T71,F10.6)") &
626 "ROKS parameter f:", scf_control%roks_f
628 WRITE (unit=output_unit, &
629 fmt=
"(T25,A,6(/,T25,A,T71,F10.6))") &
630 "ROKS parameters: a)lpha, b)eta; c)losed, o)pen, v)irtual", &
631 "acc", scf_control%roks_parameter(2, 2, 1), &
632 "bcc", scf_control%roks_parameter(2, 2, 2), &
633 "aoo", scf_control%roks_parameter(1, 1, 1), &
634 "boo", scf_control%roks_parameter(1, 1, 2), &
635 "avv", scf_control%roks_parameter(0, 0, 1), &
636 "bvv", scf_control%roks_parameter(0, 0, 2)
641 IF (scf_control%outer_scf%have_scf)
THEN
642 WRITE (output_unit,
"(T25,56('-'),/,T25,A)")
"Outer loop SCF in use "
643 SELECT CASE (scf_control%outer_scf%type)
645 WRITE (output_unit,
'(T25,A)')
"No variables optimised in outer loop"
647 WRITE (output_unit,
'(T25,A)')
"DDAPC constraint enforced"
649 WRITE (output_unit,
'(T25,A)')
"S2 constraint enforced"
651 WRITE (output_unit,
'(T25,A)')
"Floating basis function optimization enforced"
653 cpabort(
"CDFT constraints must be defined in QS&CDFT")
657 WRITE (output_unit,
'(T25,A,T72,ES9.2)')
"eps_scf", scf_control%outer_scf%eps_scf
658 WRITE (output_unit,
'(T25,A,T72,I9)')
"max_scf", scf_control%outer_scf%max_scf
659 SELECT CASE (scf_control%outer_scf%optimizer)
661 WRITE (output_unit,
'(T25,A)')
"No outer loop optimization"
663 WRITE (output_unit,
'(T25,A)')
"Steepest descent optimization"
665 WRITE (output_unit,
'(T25,A)')
"Gradient bisection"
666 WRITE (output_unit,
'(T25,A,T72,I9)')
"bisect_trust_count", scf_control%outer_scf%bisect_trust_count
668 WRITE (output_unit,
'(T25,A)')
"DIIS optimization"
669 WRITE (output_unit,
'(T25,A,T72,I9)')
"DIIS buffer length", &
670 scf_control%outer_scf%diis_buffer_length
673 cpabort(
"Selected optimizer only compatible with CDFT")
675 WRITE (output_unit,
'(T25,A)')
"Optimization with the secant method"
679 WRITE (output_unit,
'(T25,A,T72,ES9.2)')
"step_size", scf_control%outer_scf%step_size
681 WRITE (output_unit,
"(T25,56('-'),/,T25,A)")
"No outer SCF"
689 "PRINT%PROGRAM_RUN_INFO")
691 CALL timestop(handle)
702 SUBROUTINE ot_diag_read_input(settings, scf_section)
703 TYPE(qs_ot_settings_type) :: settings
704 TYPE(section_vals_type),
POINTER :: scf_section
706 CHARACTER(len=*),
PARAMETER :: routinen =
'ot_diag_read_input'
708 INTEGER :: handle, output_unit
710 TYPE(cp_logger_type),
POINTER :: logger
711 TYPE(section_vals_type),
POINTER :: ot_section
713 CALL timeset(routinen, handle)
729 "PRINT%PROGRAM_RUN_INFO")
731 CALL timestop(handle)
733 END SUBROUTINE ot_diag_read_input
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
Defines the basic variable types.
integer, parameter, public dp
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
parameters that control the outer loop of an SCF iteration
subroutine, public outer_scf_read_parameters(outer_scf, outer_scf_section)
reads the parameters of the outer_scf section into the given outer_scf
Control parameters for optimizers that work with CDFT constraints.
subroutine, public cdft_opt_type_release(cdft_opt_control)
releases the CDFT optimizer control object
subroutine, public qs_ot_settings_init(settings)
sets default values for the settings type
subroutine, public ot_readwrite_input(settings, ot_section, output_unit)
...
parameters that control an scf iteration
subroutine, public scf_c_read_parameters(scf_control, inp_section)
reads the parameters of the scf section into the given scf_control
subroutine, public scf_c_release(scf_control)
releases the given scf_control (see cp2k/doc/ReferenceCounting.html)
subroutine, public scf_c_write_parameters(scf_control, dft_section)
writes out the scf parameters
subroutine, public scf_c_create(scf_control)
allocates and initializes an scf control object with the default values