51#include "./base/base_uses.f90"
57 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'scf_control_types'
58 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
93 LOGICAL :: do_smear = .false.
94 LOGICAL :: common_mu = .false.
95 INTEGER :: method = -1
96 REAL(kind=
dp) :: electronic_temperature = -1.0_dp, &
97 fixed_mag_mom = -1.0_dp, &
98 eps_fermi_dirac = -1.0_dp, &
99 window_size = -1.0_dp, &
100 smearing_width = -1.0_dp
101 REAL(kind=
dp),
DIMENSION(:),
POINTER ::
list => null()
104 TYPE diagonalization_type
105 INTEGER :: method = -1
106 REAL(kind=
dp) :: eps_jacobi = -1.0_dp
107 REAL(kind=
dp) :: jacobi_threshold = -1.0_dp
108 INTEGER :: max_iter = -1, nkrylov = -1, nblock_krylov = -1
110 LOGICAL :: mom = .false., mom_didguess = .false.
111 INTEGER :: mom_proj_formula = -1
113 INTEGER,
DIMENSION(:),
POINTER :: mom_deocca => null(), mom_deoccb => null(), &
114 mom_occa => null(), mom_occb => null()
119 INTEGER :: mom_start = -1
120 INTEGER :: mom_type = -1
121 REAL(kind=
dp) :: eps_iter = -1.0_dp
122 REAL(kind=
dp) :: eps_adapt = -1.0_dp
124 END TYPE diagonalization_type
129 TYPE(diagonalization_type) :: diagonalization = diagonalization_type()
131 INTEGER :: density_guess = -1, mixing_method = -1
132 REAL(kind=
dp) :: eps_eigval = -1.0_dp, eps_scf = -1.0_dp, eps_scf_hist = -1.0_dp, &
133 level_shift = -1.0_dp, &
134 eps_lumos = -1.0_dp, eps_diis = -1.0_dp
135 INTEGER :: max_iter_lumos = -1, max_diis = -1, nmixing = -1
136 INTEGER :: max_scf = -1, max_scf_hist = -1, &
137 maxl = -1, nkind = -1
138 LOGICAL :: do_diag_sub = .false., &
139 use_cholesky = .false., use_ot = .false., &
140 use_diag = .false., do_outer_scf_reortho = .false., &
141 ignore_convergence_failure = .false.
142 LOGICAL :: force_scf_calculation = .false.
143 LOGICAL :: non_selfconsistent = .false.
144 INTEGER,
DIMENSION(2) :: added_mos = -1
145 INTEGER :: roks_scheme = -1
146 REAL(kind=
dp) :: roks_f = -1.0_dp
147 REAL(kind=
dp),
DIMENSION(0:2, 0:2, 1:2) :: roks_parameter = -1.0_dp
151 LOGICAL :: do_gce = .false.
152 REAL(kind=
dp) :: target_workfunction = 0.16_dp, &
154 mixing_coef = 0.3_dp, &
155 prev_workfunction = -1001.0_dp
172 CHARACTER(LEN=*),
PARAMETER :: routinen =
'scf_c_create'
176 CALL timeset(routinen, handle)
180 IF (scf_control%non_selfconsistent)
THEN
181 scf_control%density_guess =
no_guess
185 scf_control%eps_eigval = 1.0e-5_dp
186 scf_control%eps_scf = 1.0e-5_dp
187 scf_control%eps_scf_hist = 0.0_dp
188 scf_control%eps_lumos = 1.0e-5_dp
189 scf_control%max_iter_lumos = 2999
190 scf_control%eps_diis = 0.1_dp
191 scf_control%level_shift = 0.0_dp
192 scf_control%max_diis = 4
193 scf_control%max_scf = 50
194 scf_control%nmixing = 2
195 scf_control%use_cholesky = .true.
196 scf_control%use_diag = .true.
197 scf_control%do_diag_sub = .false.
198 scf_control%use_ot = .false.
199 scf_control%ignore_convergence_failure = .false.
200 scf_control%force_scf_calculation = .false.
201 scf_control%do_outer_scf_reortho = .true.
202 scf_control%max_diis = 4
203 scf_control%eps_diis = 0.1_dp
204 scf_control%added_mos(:) = 0
205 scf_control%max_scf_hist = 0
208 IF (scf_control%non_selfconsistent)
THEN
209 scf_control%mixing_method =
no_mix
215 scf_control%diagonalization%method = 0
216 scf_control%diagonalization%eps_jacobi = 0.0_dp
217 scf_control%diagonalization%jacobi_threshold = 1.0e-7_dp
218 scf_control%diagonalization%max_iter = 0
219 scf_control%diagonalization%eps_iter = 0.0_dp
220 scf_control%diagonalization%eps_adapt = 0.0_dp
221 scf_control%diagonalization%nkrylov = 0
222 scf_control%diagonalization%nblock_krylov = 0
225 scf_control%diagonalization%mom = .false.
226 scf_control%diagonalization%mom_didguess = .false.
227 scf_control%diagonalization%mom_proj_formula = 0
228 NULLIFY (scf_control%diagonalization%mom_deoccA)
229 NULLIFY (scf_control%diagonalization%mom_deoccB)
230 NULLIFY (scf_control%diagonalization%mom_occA)
231 NULLIFY (scf_control%diagonalization%mom_occB)
232 scf_control%diagonalization%mom_start = 0
237 scf_control%roks_f = 0.5_dp
242 scf_control%roks_parameter(0, 0, 1) = 1.5_dp
243 scf_control%roks_parameter(0, 0, 2) = -0.5_dp
244 scf_control%roks_parameter(1, 1, 1) = 0.5_dp
245 scf_control%roks_parameter(1, 1, 2) = 0.5_dp
246 scf_control%roks_parameter(2, 2, 1) = -0.5_dp
247 scf_control%roks_parameter(2, 2, 2) = 1.5_dp
251 scf_control%roks_parameter(0, 1, 1) = 1.0_dp
252 scf_control%roks_parameter(0, 1, 2) = 0.0_dp
253 scf_control%roks_parameter(0, 2, 1) = 0.5_dp
254 scf_control%roks_parameter(0, 2, 2) = 0.5_dp
255 scf_control%roks_parameter(1, 2, 1) = 0.0_dp
256 scf_control%roks_parameter(1, 2, 2) = 1.0_dp
260 scf_control%roks_parameter(1, 0, 1) = scf_control%roks_parameter(0, 1, 1)
261 scf_control%roks_parameter(1, 0, 2) = scf_control%roks_parameter(0, 1, 2)
262 scf_control%roks_parameter(2, 0, 1) = scf_control%roks_parameter(0, 2, 1)
263 scf_control%roks_parameter(2, 0, 2) = scf_control%roks_parameter(0, 2, 2)
264 scf_control%roks_parameter(2, 1, 1) = scf_control%roks_parameter(1, 2, 1)
265 scf_control%roks_parameter(2, 1, 2) = scf_control%roks_parameter(1, 2, 2)
269 scf_control%outer_scf%have_scf = .false.
270 scf_control%outer_scf%max_scf = 0
271 scf_control%outer_scf%eps_scf = 0.0_dp
272 scf_control%outer_scf%step_size = 0.0_dp
273 scf_control%outer_scf%type = -1
274 scf_control%outer_scf%optimizer = -1
275 scf_control%outer_scf%diis_buffer_length = -1
276 NULLIFY (scf_control%outer_scf%cdft_opt_control)
280 NULLIFY (scf_control%smear)
282 CALL timestop(handle)
299 IF (
ASSOCIATED(scf_control%smear%list))
THEN
300 DEALLOCATE (scf_control%smear%list)
302 DEALLOCATE (scf_control%smear)
304 IF (
ASSOCIATED(scf_control%outer_scf%cdft_opt_control)) &
307 IF (
ASSOCIATED(scf_control%gce))
THEN
308 DEALLOCATE (scf_control%gce)
332 CHARACTER(LEN=*),
PARAMETER :: routinen =
'scf_c_read_parameters'
334 INTEGER :: cholesky_flag, handle, ialgo
335 INTEGER,
DIMENSION(:),
POINTER :: added_mos
336 LOGICAL :: do_mixing, explicit
337 REAL(kind=
dp),
DIMENSION(:),
POINTER :: roks_parameter
339 outer_scf_section, scf_section, &
342 CALL timeset(routinen, handle)
346 l_val=scf_control%use_diag)
347 IF (scf_control%use_diag)
THEN
349 l_val=scf_control%do_diag_sub)
352 IF (scf_control%use_diag .AND. scf_control%use_ot)
THEN
354 cpabort(
"Don't activate OT and Diagonaliztion together")
355 ELSEIF (.NOT. (scf_control%use_diag .OR. scf_control%use_ot))
THEN
357 scf_control%use_diag = .true.
364 IF (scf_control%use_ot)
THEN
366 scf_control%eps_diis = 0.0_dp
374 IF (cholesky_flag > 0)
THEN
375 scf_control%use_cholesky = .true.
377 CALL section_vals_val_get(scf_section,
"IGNORE_CONVERGENCE_FAILURE", l_val=scf_control%ignore_convergence_failure)
378 CALL section_vals_val_get(scf_section,
"FORCE_SCF_CALCULATION", l_val=scf_control%force_scf_calculation)
385 IF (scf_control%use_diag)
THEN
387 i_val=scf_control%diagonalization%method)
389 r_val=scf_control%diagonalization%eps_jacobi)
391 r_val=scf_control%diagonalization%jacobi_threshold)
393 i_val=scf_control%diagonalization%max_iter)
395 r_val=scf_control%diagonalization%eps_iter)
397 r_val=scf_control%diagonalization%eps_adapt)
399 i_val=scf_control%diagonalization%nkrylov)
401 i_val=scf_control%diagonalization%nblock_krylov)
402 IF (scf_control%diagonalization%method ==
diag_ot)
THEN
404 CALL ot_diag_read_input(scf_control%diagonalization%ot_settings, scf_section)
408 l_val=scf_control%diagonalization%MOM)
409 IF (scf_control%diagonalization%mom)
THEN
411 i_val=scf_control%diagonalization%mom_type)
414 i_val=scf_control%diagonalization%mom_start)
417 i_vals=scf_control%diagonalization%mom_deoccA)
420 i_vals=scf_control%diagonalization%mom_deoccB)
423 i_vals=scf_control%diagonalization%mom_occA)
426 i_vals=scf_control%diagonalization%mom_occB)
429 i_val=scf_control%diagonalization%mom_proj_formula)
436 SELECT CASE (scf_control%roks_scheme)
443 NULLIFY (roks_parameter)
445 IF (
ASSOCIATED(roks_parameter))
THEN
446 scf_control%roks_parameter(2, 2, 1) = roks_parameter(1)
447 scf_control%roks_parameter(2, 2, 2) = roks_parameter(2)
448 scf_control%roks_parameter(1, 1, 1) = roks_parameter(3)
449 scf_control%roks_parameter(1, 1, 2) = roks_parameter(4)
450 scf_control%roks_parameter(0, 0, 1) = roks_parameter(5)
451 scf_control%roks_parameter(0, 0, 2) = roks_parameter(6)
461 cpassert(
ASSOCIATED(added_mos))
462 IF (
SIZE(added_mos) > 0)
THEN
463 scf_control%added_mos(1) = added_mos(1)
464 IF (
SIZE(added_mos) > 1)
THEN
465 scf_control%added_mos(2) = added_mos(2)
472 IF (scf_control%level_shift /= 0.0_dp) scf_control%use_cholesky = .false.
479 CALL init_smear(scf_control%smear)
480 CALL read_smear_section(scf_control%smear, smear_section)
488 i_val=scf_control%mixing_method)
493 CALL init_gce(scf_control%gce)
494 CALL read_gce_section(scf_control%gce, gce_section)
496 CALL timestop(handle)
504 SUBROUTINE init_smear(smear)
507 cpassert(.NOT.
ASSOCIATED(smear))
509 smear%do_smear = .false.
511 smear%electronic_temperature = 0.0_dp
512 smear%eps_fermi_dirac = 1.0e-5_dp
513 smear%fixed_mag_mom = -100.0_dp
514 smear%window_size = 0.0_dp
515 smear%smearing_width = 0.0_dp
517 END SUBROUTINE init_smear
524 SUBROUTINE read_smear_section(smear, smear_section)
528 REAL(kind=
dp),
DIMENSION(:),
POINTER :: r_vals
533 l_val=smear%do_smear)
534 IF (smear%do_smear)
THEN
538 r_val=smear%electronic_temperature)
540 r_val=smear%eps_fermi_dirac)
542 r_val=smear%window_size)
547 r_val=smear%smearing_width)
552 cpassert(
ASSOCIATED(r_vals))
553 ALLOCATE (smear%list(
SIZE(r_vals)))
557 r_val=smear%fixed_mag_mom)
559 END SUBROUTINE read_smear_section
565 SUBROUTINE init_gce(gce)
568 cpassert(.NOT.
ASSOCIATED(gce))
571 gce%target_workfunction = 0.16_dp
572 gce%prev_workfunction = -1001.0_dp
574 gce%mixing_coef = 0.3_dp
575 END SUBROUTINE init_gce
582 SUBROUTINE read_gce_section(gce, gce_section)
590 r_val=gce%target_workfunction)
592 r_val=gce%mixing_coef)
594 END SUBROUTINE read_gce_section
610 CHARACTER(LEN=*),
PARAMETER :: routinen =
'scf_c_write_parameters'
612 INTEGER :: handle, output_unit, roks_scheme
614 REAL(kind=
dp) :: elec_temp
621 CALL timeset(routinen, handle)
626 NULLIFY (scf_section)
633 IF (output_unit > 0)
THEN
635 IF (scf_control%max_scf > 0)
THEN
642 IF (.NOT. scf_control%non_selfconsistent .OR. scf_control%force_scf_calculation)
THEN
643 WRITE (unit=output_unit, &
644 fmt=
"(/,/,T2,A,T25,A,T51,A30,/,T25,56('-'),3(/,T25,A,T76,I5),/, "// &
645 "T25,56('-'),4(/,T25,A,T72,ES9.2),/,T25,56('-'), "// &
646 "1(/,T25,A,T71,F10.6))") &
648 "Density guess: ", adjustr(trim(
enum_i2c(enum, scf_control%density_guess))), &
649 "max_scf: ", scf_control%max_scf, &
650 "max_scf_history: ", scf_control%max_scf_hist, &
651 "max_diis: ", scf_control%max_diis, &
652 "eps_scf: ", scf_control%eps_scf, &
653 "eps_scf_history: ", scf_control%eps_scf_hist, &
654 "eps_diis: ", scf_control%eps_diis, &
655 "eps_eigval: ", scf_control%eps_eigval, &
656 "level_shift [a.u.]:", scf_control%level_shift
659 IF (sum(abs(scf_control%added_mos)) > 0)
THEN
660 WRITE (unit=output_unit, fmt=
"(T25,A,T71,2I5)") &
661 "added MOs ", scf_control%added_mos
664 IF (scf_control%diagonalization%mom)
THEN
666 WRITE (unit=output_unit, fmt=
"(T25,A)")
"MOM enabled"
669 IF (scf_control%mixing_method > 0 .AND. .NOT. scf_control%use_ot .AND. &
670 .NOT. scf_control%non_selfconsistent)
THEN
673 WRITE (unit=output_unit, fmt=
"(T25,A,/,T25,A,T51,A30)") &
675 "Mixing method: ", adjustr(trim(
enum_i2c(enum, scf_control%mixing_method)))
676 IF (scf_control%mixing_method > 1)
THEN
677 WRITE (unit=output_unit, fmt=
"(T47,A34)")
"charge density mixing in g-space"
680 IF (scf_control%smear%do_smear)
THEN
683 WRITE (unit=output_unit, fmt=
"(T25,A,/,T25,A,T51,A30)") &
685 "Smear method: ", adjustr(trim(
enum_i2c(enum, scf_control%smear%method)))
686 SELECT CASE (scf_control%smear%method)
690 WRITE (unit=output_unit, fmt=
"(T25,A,T61,F20.1)") &
691 "Electronic temperature [K]:", elec_temp
692 WRITE (unit=output_unit, fmt=
"(T25,A,T71,ES10.2)") &
693 "Electronic temperature [a.u.]:", scf_control%smear%electronic_temperature, &
694 "Accuracy threshold:", scf_control%smear%eps_fermi_dirac
695 IF (scf_control%smear%fixed_mag_mom > 0.0_dp)
WRITE (unit=output_unit, fmt=
"(T25,A,T61,F20.1)") &
696 "Fixed magnetic moment set to:", scf_control%smear%fixed_mag_mom
698 WRITE (unit=output_unit, fmt=
"(T25,A,T71,ES10.2)") &
699 "Smearing width (sigma) [a.u.]:", scf_control%smear%smearing_width, &
700 "Accuracy threshold:", scf_control%smear%eps_fermi_dirac
701 IF (scf_control%smear%fixed_mag_mom > 0.0_dp) &
702 WRITE (unit=output_unit, fmt=
"(T25,A,T61,F20.1)") &
703 "Fixed magnetic moment set to:", scf_control%smear%fixed_mag_mom
705 WRITE (unit=output_unit, fmt=
"(T25,A,T71,F10.6)") &
706 "Smear window [a.u.]: ", scf_control%smear%window_size
710 IF (scf_control%gce%do_gce)
THEN
711 WRITE (unit=output_unit, fmt=
"(T25,A,/,T25,A,T61,F20.1)") &
713 "Target workfunction [eV]:", scf_control%gce%target_workfunction
714 WRITE (unit=output_unit, fmt=
"(T25,A,T61,F20.1)")
"Mixing coefficient:", scf_control%gce%mixing_coef
715 WRITE (unit=output_unit, fmt=
"(T25,A)")
"Grand canonical SCF is activated."
719 IF (roks .AND. (.NOT. scf_control%use_ot))
THEN
724 WRITE (unit=output_unit, fmt=
"(T25,A,/,T25,A,T51,A30)") &
726 "ROKS scheme:", adjustr(trim(
enum_i2c(enum, roks_scheme)))
727 SELECT CASE (roks_scheme)
729 WRITE (unit=output_unit, fmt=
"(T25,A,T71,F10.6)") &
730 "ROKS parameter f:", scf_control%roks_f
732 WRITE (unit=output_unit, &
733 fmt=
"(T25,A,6(/,T25,A,T71,F10.6))") &
734 "ROKS parameters: a)lpha, b)eta; c)losed, o)pen, v)irtual", &
735 "acc", scf_control%roks_parameter(2, 2, 1), &
736 "bcc", scf_control%roks_parameter(2, 2, 2), &
737 "aoo", scf_control%roks_parameter(1, 1, 1), &
738 "boo", scf_control%roks_parameter(1, 1, 2), &
739 "avv", scf_control%roks_parameter(0, 0, 1), &
740 "bvv", scf_control%roks_parameter(0, 0, 2)
745 IF (scf_control%outer_scf%have_scf)
THEN
746 WRITE (output_unit,
"(T25,56('-'),/,T25,A)")
"Outer loop SCF in use "
747 SELECT CASE (scf_control%outer_scf%type)
749 WRITE (output_unit,
'(T25,A)')
"No variables optimised in outer loop"
751 WRITE (output_unit,
'(T25,A)')
"DDAPC constraint enforced"
753 WRITE (output_unit,
'(T25,A)')
"S2 constraint enforced"
755 WRITE (output_unit,
'(T25,A)')
"Floating basis function optimization enforced"
757 cpabort(
"CDFT constraints must be defined in QS&CDFT")
761 WRITE (output_unit,
'(T25,A,T72,ES9.2)')
"eps_scf", scf_control%outer_scf%eps_scf
762 WRITE (output_unit,
'(T25,A,T72,I9)')
"max_scf", scf_control%outer_scf%max_scf
763 SELECT CASE (scf_control%outer_scf%optimizer)
765 WRITE (output_unit,
'(T25,A)')
"No outer loop optimization"
767 WRITE (output_unit,
'(T25,A)')
"Steepest descent optimization"
769 WRITE (output_unit,
'(T25,A)')
"Gradient bisection"
770 WRITE (output_unit,
'(T25,A,T72,I9)')
"bisect_trust_count", scf_control%outer_scf%bisect_trust_count
772 WRITE (output_unit,
'(T25,A)')
"DIIS optimization"
773 WRITE (output_unit,
'(T25,A,T72,I9)')
"DIIS buffer length", &
774 scf_control%outer_scf%diis_buffer_length
777 cpabort(
"Selected optimizer only compatible with CDFT")
779 WRITE (output_unit,
'(T25,A)')
"Optimization with the secant method"
783 WRITE (output_unit,
'(T25,A,T72,ES9.2)')
"step_size", scf_control%outer_scf%step_size
785 WRITE (output_unit,
"(T25,56('-'),/,T25,A)")
"No outer SCF"
793 "PRINT%PROGRAM_RUN_INFO")
795 CALL timestop(handle)
806 SUBROUTINE ot_diag_read_input(settings, scf_section)
810 CHARACTER(len=*),
PARAMETER :: routinen =
'ot_diag_read_input'
812 INTEGER :: handle, output_unit
817 CALL timeset(routinen, handle)
833 "PRINT%PROGRAM_RUN_INFO")
835 CALL timestop(handle)
837 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
type of a logger, at the moment it contains just a print level starting at which level it should be l...
contains the parameters needed by a scf run
notice, this variable needs to be copyable, needed for spins as e.g. in qs_ot_scf
contains the parameters needed by a scf run