42 use,
intrinsic :: iso_fortran_env
111 integer,
public,
parameter :: &
119 integer,
public :: max_iter
121 real(real64),
public :: lmm_r
124 logical :: conv_eigen_error
125 logical :: check_conv
128 logical :: calc_force
129 logical,
public :: calc_stress
130 logical :: calc_dipole
131 logical :: calc_polarization
132 logical :: calc_partial_charges
133 logical :: calc_orb_moments = .false.
136 type(mixfield_t),
pointer :: mixfield
137 type(eigensolver_t) :: eigens
139 logical :: forced_finish = .false.
140 type(lda_u_mixer_t) :: lda_u_mix
141 type(vtau_mixer_t) :: vtau_mix
142 type(berry_t) :: berry
145 type(restart_t),
public :: restart_load, restart_dump
147 type(criterion_list_t),
public :: criterion_list
148 real(real64) :: energy_in, energy_diff, abs_dens_diff, evsum_in, evsum_out, evsum_diff
151 logical :: converged_current, converged_last
152 integer :: verbosity_
154 real(real64),
allocatable :: rhoout(:,:), rhoin(:,:)
155 real(real64),
allocatable :: vhxc_old(:,:)
156 class(wfs_elec_t),
allocatable :: psioutb(:, :)
157 logical :: output_forces, calc_current, output_during_scf
158 logical :: finish = .false.
164 subroutine scf_init(scf, namespace, gr, ions, st, mc, hm, space)
165 type(scf_t),
intent(inout) :: scf
166 type(grid_t),
intent(in) :: gr
167 type(namespace_t),
intent(in) :: namespace
168 type(ions_t),
intent(in) :: ions
169 type(states_elec_t),
intent(in) :: st
170 type(multicomm_t),
intent(in) :: mc
171 type(hamiltonian_elec_t),
intent(inout) :: hm
172 class(space_t),
intent(in) :: space
175 integer :: mixdefault
176 type(type_t) :: mix_type
177 class(convergence_criterion_t),
pointer :: crit
178 type(criterion_iterator_t) :: iter
179 logical :: deactivate_oracle
202 if (
allocated(hm%vberry))
then
209 call iter%start(scf%criterion_list)
210 do while (iter%has_next())
211 crit => iter%get_next()
214 call crit%set_pointers(scf%energy_diff, scf%energy_in)
216 call crit%set_pointers(scf%abs_dens_diff, st%qtot)
218 call crit%set_pointers(scf%evsum_diff, scf%evsum_out)
225 if(.not. scf%check_conv .and. scf%max_iter < 0)
then
226 call messages_write(
"All convergence criteria are disabled. Octopus is cowardly refusing")
231 call messages_write(
"Please set one of the following variables to a positive value:")
254 call parse_variable(namespace,
'ConvEigenError', .false., scf%conv_eigen_error)
256 if(scf%max_iter < 0) scf%max_iter = huge(scf%max_iter)
262 call eigensolver_init(scf%eigens, namespace, gr, st, hm, mc, space, deactivate_oracle)
264 if(scf%eigens%es_type /=
rs_evo)
then
288 mixdefault = option__mixfield__potential
291 call parse_variable(namespace,
'MixField', mixdefault, scf%mix_field)
295 if (scf%mix_field == option__mixfield__potential .and. hm%theory_level ==
independent_particles)
then
296 call messages_write(
'Input: Cannot mix the potential for non-interacting particles.')
300 if (scf%mix_field == option__mixfield__potential .and. hm%pcm%run_pcm)
then
301 call messages_write(
'Input: You have selected to mix the potential.', new_line = .
true.)
302 call messages_write(
' This might produce convergence problems for solvated systems.', new_line = .
true.)
307 if(scf%mix_field == option__mixfield__density &
310 call messages_write(
'Input: You have selected to mix the density with OEP or MGGA XC functionals.', new_line = .
true.)
311 call messages_write(
' This might produce convergence problems. Mix the potential instead.')
315 if(scf%mix_field == option__mixfield__states)
then
320 select case(scf%mix_field)
321 case (option__mixfield__potential, option__mixfield__density)
323 case(option__mixfield__states)
330 if (scf%mix_field /= option__mixfield__none)
then
331 call mix_init(scf%smix, namespace, space, gr%der, scf%mixdim1, st%d%nspin, func_type_ = mix_type)
335 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none )
then
341 if(scf%mix_field == option__mixfield__potential)
then
347 scf%mix_field = option__mixfield__none
359 call parse_variable(namespace,
'SCFCalculateForces', .not. ions%only_user_def, scf%calc_force)
361 if(scf%calc_force .and. gr%der%boundaries%spiralBC)
then
362 message(1) =
'Forces cannot be calculated when using spiral boundary conditions.'
363 write(
message(2),
'(a)')
'Please use SCFCalculateForces = no.'
366 if(scf%calc_force)
then
367 if (
allocated(hm%ep%b_field) .or.
allocated(hm%ep%a_static))
then
368 write(
message(1),
'(a)')
'The forces are currently not properly calculated if static'
369 write(
message(2),
'(a)')
'magnetic fields or static vector potentials are present.'
370 write(
message(3),
'(a)')
'Please use SCFCalculateForces = no.'
374 write(
message(1),
'(a)')
'The forces receive no contribution from the ZORA terms of the'
375 write(
message(2),
'(a)')
'Hamiltonian, and are therefore only approximate.'
389 call parse_variable(namespace,
'SCFCalculateStress', .false. , scf%calc_stress)
403 call parse_variable(namespace,
'SCFCalculateDipole', .not. space%is_periodic(), scf%calc_dipole)
404 if (
allocated(hm%vberry)) scf%calc_dipole = .
true.
418 call parse_variable(namespace,
'SCFCalculatePolarization', .false., scf%calc_polarization)
433 call parse_variable(namespace,
'SCFCalculateOrbitalMoments', .false. , scf%calc_orb_moments)
434 if((st%d%ispin /=
spinors .or. space%dim /= 3) .and. scf%calc_orb_moments)
then
435 message(1) =
"Orbital moments are only implemented for spinors and in 3D."
438 if (scf%calc_orb_moments .and. .not. (hm%ep%reltype ==
spin_orbit &
440 message(1) =
"Orbital moments are only available with SOC."
443 if(gr%use_curvilinear .and. scf%calc_orb_moments)
then
455 call parse_variable(namespace,
'SCFCalculatePartialCharges', .false., scf%calc_partial_charges)
456 if (scf%calc_partial_charges)
call messages_experimental(
'SCFCalculatePartialCharges', namespace=namespace)
458 rmin = ions%min_distance()
474 scf%forced_finish = .false.
482 type(
scf_t),
intent(inout) :: scf
491 if(scf%mix_field /= option__mixfield__none)
call mix_end(scf%smix)
493 nullify(scf%mixfield)
495 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none)
then
500 call iter%start(scf%criterion_list)
501 do while (iter%has_next())
502 crit => iter%get_next()
503 safe_deallocate_p(crit)
512 type(
scf_t),
intent(inout) :: scf
518 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none)
then
528 subroutine scf_load(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, restart_load)
529 type(
scf_t),
intent(inout) :: scf
532 type(
grid_t),
intent(inout) :: gr
533 type(
ions_t),
intent(in) :: ions
536 type(
v_ks_t),
intent(inout) :: ks
538 type(
restart_t),
intent(in) :: restart_load
540 integer :: ierr, is, ip
548 message(1) =
'Unable to read density. Density will be calculated from states.'
551 if (
bitand(ks%xc_family, xc_family_oep) == 0)
then
552 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
555 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
562 call hm%ks_pot%load(restart_load, gr, ierr)
564 message(1) =
'Unable to read Vhxc. Vhxc will be calculated from states.'
567 call hm%update(gr, namespace, space, ext_partners)
568 if (
bitand(ks%xc_family, xc_family_oep) /= 0)
then
571 do is = 1, st%d%nspin
574 ks%oep%vxc(ip, is) = hm%ks_pot%vhxc(ip, is) - hm%ks_pot%vhartree(ip)
578 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
585 if (scf%mix_field == option__mixfield__density .or. scf%mix_field == option__mixfield__potential)
then
586 call mix_load(namespace, restart_load, scf%smix, gr, ierr)
588 message(1) =
"Unable to read mixing information. Mixing will start from scratch."
595 call lda_u_load(restart_load, hm%lda_u, st, hm%energy%dft_u, ierr)
597 message(1) =
"Unable to read DFT+U information. DFT+U data will be calculated from states."
617 subroutine scf_start(scf, namespace, gr, ions, st, ks, hm, outp, verbosity)
618 type(
scf_t),
intent(inout) :: scf
620 type(
grid_t),
intent(inout) :: gr
621 type(
ions_t),
intent(inout) :: ions
625 type(
output_t),
optional,
intent(in) :: outp
626 integer,
optional,
intent(in) :: verbosity
632 if(scf%forced_finish)
then
633 message(1) =
"Previous clean stop, not doing SCF and quitting."
637 if (.not. hm%is_hermitian())
then
638 message(1) =
"Trying to run a SCF calculation for a non-hermitian Hamiltonian. This is not supported."
644 scf%output_during_scf = .false.
645 scf%output_forces = .false.
646 scf%calc_current = .false.
648 if (
present(outp))
then
651 if (outp%what(option__output__stress))
then
652 scf%calc_stress = .
true.
655 scf%output_during_scf = outp%duringscf
658 if (outp%duringscf .and. outp%what(option__output__forces))
then
659 scf%output_forces = .
true.
663 safe_allocate(scf%rhoout(1:gr%np, 1:st%d%nspin))
664 safe_allocate(scf%rhoin (1:gr%np, 1:st%d%nspin))
666 call lalg_copy(gr%np, st%d%nspin, st%rho, scf%rhoin)
669 if (scf%calc_force .or. scf%output_forces)
then
671 safe_allocate(scf%vhxc_old(1:gr%np, 1:st%d%nspin))
672 call lalg_copy(gr%np, st%d%nspin, hm%ks_pot%vhxc, scf%vhxc_old)
676 select case(scf%mix_field)
677 case(option__mixfield__potential)
680 case(option__mixfield__density)
683 case(option__mixfield__states)
686 allocate(
wfs_elec_t::scf%psioutb (st%group%block_start:st%group%block_end, st%d%kpt%start:st%d%kpt%end))
688 do iqn = st%d%kpt%start, st%d%kpt%end
689 do ib = st%group%block_start, st%group%block_end
690 call st%group%psib(ib, iqn)%copy_to(scf%psioutb(ib, iqn))
698 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none)
then
704 if ( scf%verbosity_ /= verb_no )
then
705 if(scf%max_iter > 0)
then
706 write(
message(1),
'(a)')
'Info: Starting SCF iteration.'
708 write(
message(1),
'(a)')
'Info: No SCF iterations will be done.'
715 scf%converged_current = .false.
725 character(len=*),
intent(in) :: dir
726 character(len=*),
intent(in) :: fname
729 character(len=12) :: label
730 if(st%system_grp%is_root())
then
732 iunit =
io_open(trim(dir) //
"/" // trim(fname), namespace, action=
'write')
733 write(iunit,
'(a)', advance =
'no')
'#iter energy '
734 label =
'energy_diff'
735 write(iunit,
'(1x,a)', advance =
'no') label
737 write(iunit,
'(1x,a)', advance =
'no') label
739 write(iunit,
'(1x,a)', advance =
'no') label
741 write(iunit,
'(1x,a)', advance =
'no') label
743 write(iunit,
'(1x,a)', advance =
'no') label
747 label =
'OEP norm2ss'
748 write(iunit,
'(1x,a)', advance =
'no') label
751 write(iunit,
'(a)')
''
761 subroutine scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, &
762 verbosity, iters_done, restart_dump)
763 type(
scf_t),
intent(inout) :: scf
767 type(
grid_t),
intent(inout) :: gr
768 type(
ions_t),
intent(inout) :: ions
771 type(
v_ks_t),
intent(inout) :: ks
773 type(
output_t),
optional,
intent(in) :: outp
774 integer,
optional,
intent(in) :: verbosity
775 integer,
optional,
intent(out) :: iters_done
776 type(
restart_t),
optional,
intent(in) :: restart_dump
783 call scf_start(scf, namespace, gr, ions, st, ks, hm, outp, verbosity)
786 do iter = 1, scf%max_iter
788 call scf_iter(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, iter, outp, &
791 completed =
scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, iters_done)
793 if(scf%forced_finish .or. completed)
then
798 if (.not.scf%forced_finish)
then
800 call scf_finish(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, iter, outp)
807 subroutine scf_iter(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, iter, outp, &
809 type(
scf_t),
intent(inout) :: scf
813 type(
grid_t),
intent(inout) :: gr
814 type(
ions_t),
intent(inout) :: ions
817 type(
v_ks_t),
intent(inout) :: ks
819 integer,
intent(in) :: iter
820 type(
output_t),
optional,
intent(in) :: outp
821 type(
restart_t),
optional,
intent(in) :: restart_dump
823 integer :: iqn, ib, ierr
826 logical :: is_crit_conv
827 real(real64) :: etime, itime
836 scf%eigens%converged = 0
839 call hm%update_span(gr%spacing(1:space%dim), minval(st%eigenval(:, :)), namespace)
845 call iterator%start(scf%criterion_list)
846 do while (iterator%has_next())
847 crit => iterator%get_next()
851 if (scf%calc_force .or. scf%output_forces)
then
853 scf%vhxc_old(1:gr%np, 1:st%d%nspin) = hm%ks_pot%vhxc(1:gr%np, 1:st%d%nspin)
858 if (
allocated(hm%vberry))
then
861 ks%frozen_hxc = .
true.
863 call berry_perform_internal_scf(scf%berry, namespace, space, scf%eigens, gr, st, hm, iter, ks, ions, ext_partners)
865 ks%frozen_hxc = .false.
867 scf%eigens%converged = 0
868 call scf%eigens%run(namespace, gr, st, hm, space, ext_partners, iter)
871 scf%matvec = scf%matvec + scf%eigens%matvec
880 call lalg_copy(gr%np, st%d%nspin, st%rho, scf%rhoout)
882 select case (scf%mix_field)
883 case (option__mixfield__potential)
884 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
887 case (option__mixfield__density)
889 case(option__mixfield__states)
890 do iqn = st%d%kpt%start, st%d%kpt%end
891 do ib = st%group%block_start, st%group%block_end
892 call st%group%psib(ib, iqn)%copy_data_to(gr%np, scf%psioutb(ib, iqn))
897 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none)
then
904 if (
present(outp))
then
906 if (outp%duringscf .and. outp%what_now(option__output__forces, iter))
then
907 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old=scf%vhxc_old)
912 call iterator%start(scf%criterion_list)
913 do while (iterator%has_next())
914 crit => iterator%get_next()
919 scf%converged_last = scf%converged_current
921 scf%converged_current = scf%check_conv .and. &
922 (.not. scf%conv_eigen_error .or. all(scf%eigens%converged >= st%nst_conv))
924 call iterator%start(scf%criterion_list)
925 do while (iterator%has_next())
926 crit => iterator%get_next()
927 call crit%is_converged(is_crit_conv)
928 scf%converged_current = scf%converged_current .and. is_crit_conv
933 scf%finish = scf%converged_last .and. scf%converged_current
939 select case (scf%mix_field)
940 case (option__mixfield__density)
942 call mixing(namespace, scf%smix)
948 if (minval(st%rho(1:gr%np, 1:st%d%spin_channels)) < -1e-6_real64)
then
949 write(
message(1),*)
'Negative density after mixing. Minimum value = ', &
950 minval(st%rho(1:gr%np, 1:st%d%spin_channels))
954 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
956 case (option__mixfield__potential)
958 call mixing(namespace, scf%smix)
964 case(option__mixfield__states)
965 do iqn = st%d%kpt%start, st%d%kpt%end
966 do ib = st%group%block_start, st%group%block_end
972 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
974 case (option__mixfield__none)
975 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
981 if (scf%finish .and. st%modelmbparticles%nparticle > 0)
then
985 if (
present(outp) .and.
present(restart_dump))
then
989 .or. iter == scf%max_iter .or. scf%forced_finish) )
then
991 call states_elec_dump(restart_dump, space, st, gr, hm%kpoints, ierr, iter=iter)
993 message(1) =
'Unable to write states wavefunctions.'
999 message(1) =
'Unable to write density.'
1004 call lda_u_dump(restart_dump, namespace, hm%lda_u, st, gr, ierr)
1006 message(1) =
'Unable to write DFT+U information.'
1011 select case (scf%mix_field)
1012 case (option__mixfield__density)
1013 call mix_dump(namespace, restart_dump, scf%smix, gr, ierr)
1015 message(1) =
'Unable to write mixing information.'
1018 case (option__mixfield__potential)
1019 call hm%ks_pot%dump(restart_dump, gr, ierr)
1021 message(1) =
'Unable to write Vhxc.'
1025 call mix_dump(namespace, restart_dump, scf%smix, gr, ierr)
1027 message(1) =
'Unable to write mixing information.'
1046 character(len=50) :: str
1047 real(real64) :: dipole(1:space%dim)
1053 write(str,
'(a,i5)')
'SCF CYCLE ITER #' ,iter
1057 ' rel_ev = ', scf%evsum_diff/(abs(scf%evsum_out)+1e-20)
1058 write(
message(2),
'(a,es15.2,2(a,es9.2))') &
1059 ' ediff = ', scf%energy_diff,
' abs_dens = ', scf%abs_dens_diff, &
1060 ' rel_dens = ', scf%abs_dens_diff/st%qtot
1063 write(
message(1),
'(a,i0)')
'Matrix vector products: ', scf%eigens%matvec
1064 write(
message(2),
'(a,i0)')
'Converged eigenvectors: ', sum(scf%eigens%converged(1:st%nik))
1068 if (
allocated(hm%vberry))
then
1070 call write_dipole(st, hm, space, dipole, namespace=namespace)
1083 write(
message(2),
'(a,i5,a,f14.2)')
'Elapsed time for SCF step ', iter,
':', etime
1093 write(
message(1),
'(a,i4,a,es15.8, a,es9.2, a, f7.1, a)') &
1096 ' : rel_dens', scf%abs_dens_diff/st%qtot, &
1097 ' : etime ', etime,
's'
1107 character(len=*),
intent(in) :: dir
1108 character(len=*),
intent(in) :: fname
1112 if(st%system_grp%is_root())
then
1114 iunit =
io_open(trim(dir) //
"/" // trim(fname), namespace, action=
'write', position=
'append')
1116 call iterator%start(scf%criterion_list)
1117 do while (iterator%has_next())
1118 crit => iterator%get_next()
1123 write(iunit,
'(2es13.5)', advance =
'no') crit%val_abs, crit%val_rel
1126 write(iunit,
'(es13.5)', advance =
'no') crit%val_rel
1134 write(iunit,
'(es13.5)', advance =
'no') ks%oep%norm2ss
1137 write(iunit,
'(a)')
''
1144 logical function scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, &
1145 iters_done)
result(completed)
1146 type(
scf_t),
intent(inout) :: scf
1149 type(
grid_t),
intent(inout) :: gr
1150 type(
ions_t),
intent(inout) :: ions
1152 type(
v_ks_t),
intent(inout) :: ks
1154 integer,
intent(in) :: iter
1155 type(
output_t),
optional,
intent(in) :: outp
1156 integer,
optional,
intent(out) :: iters_done
1158 character(len=MAX_PATH_LEN) :: dirname
1159 integer(int64) :: what_i
1166 if(
present(iters_done)) iters_done = iter
1168 write(
message(1),
'(a, i4, a)')
'Info: SCF converged in ', iter,
' iterations'
1176 if (
present(outp))
then
1177 if (any(outp%what) .and. outp%duringscf)
then
1178 do what_i = lbound(outp%what, 1), ubound(outp%what, 1)
1179 if (outp%what_now(what_i, iter))
then
1180 write(dirname,
'(a,a,i4.4)') trim(outp%iter_dir),
"scf.", iter
1181 call output_all(outp, namespace, space, dirname, gr, ions, iter, st, hm, ks)
1182 call output_modelmb(outp, namespace, space, dirname, gr, ions, iter, st)
1190 call lalg_copy(gr%np, st%d%nspin, st%rho, scf%rhoin)
1193 if (scf%mix_field /= option__mixfield__none)
then
1194 if (scf%smix%ns_restart > 0)
then
1195 if (
mix_scheme(scf%smix) /= option__mixingscheme__broyden_adaptive .and. &
1196 mod(iter, scf%smix%ns_restart) == 0)
then
1197 message(1) =
"Info: restarting mixing."
1204 select case(scf%mix_field)
1205 case(option__mixfield__potential)
1208 case (option__mixfield__density)
1213 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none)
then
1224 subroutine scf_finish(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, iter, outp)
1225 type(
scf_t),
intent(inout) :: scf
1228 type(
grid_t),
intent(inout) :: gr
1229 type(
ions_t),
intent(inout) :: ions
1232 type(
v_ks_t),
intent(inout) :: ks
1234 integer,
intent(in) :: iter
1235 type(
output_t),
optional,
intent(in) :: outp
1246 if ((scf%max_iter > 0 .and. scf%mix_field == option__mixfield__potential) .or. scf%calc_current)
then
1247 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
1248 calc_current=scf%calc_current)
1251 select case(scf%mix_field)
1252 case(option__mixfield__states)
1254 do iqn = st%d%kpt%start, st%d%kpt%end
1255 do ib = st%group%block_start, st%group%block_end
1256 call scf%psioutb(ib, iqn)%end()
1261 deallocate(scf%psioutb)
1264 safe_deallocate_a(scf%rhoout)
1265 safe_deallocate_a(scf%rhoin)
1267 if (scf%max_iter > 0 .and. any(scf%eigens%converged < st%nst))
then
1268 write(
message(1),
'(a)')
'Some of the states are not fully converged!'
1269 if (all(scf%eigens%converged >= st%nst_conv))
then
1270 write(
message(2),
'(a)')
'But all requested states to converge are converged.'
1274 write(
message(2),
'(a)')
'With the Chebyshev filtering eigensolver, it usually helps to'
1275 write(
message(3),
'(a)')
'increase ExtraStates and set ExtraStatesToConverge to the number'
1276 write(
message(4),
'(a)')
'of states to be converged.'
1284 if (.not.scf%finish)
then
1285 write(
message(1),
'(a,i4,a)')
'SCF *not* converged after ', iter - 1,
' iterations.'
1287 write(
message(2),
'(a)')
'With the Chebyshev filtering eigensolver, it usually helps to'
1288 write(
message(3),
'(a)')
'increase ExtraStates to improve convergence.'
1295 write(
message(1),
'(a,i10)')
'Info: Number of matrix-vector products: ', scf%matvec
1298 if (scf%calc_force)
then
1299 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old=scf%vhxc_old)
1302 if (scf%calc_stress)
call stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
1305 if (scf%mix_field == option__mixfield__potential)
then
1310 if(
present(outp))
then
1317 if (space%is_periodic() .and.
kpoints_number(hm%kpoints) > 1)
then
1320 ions, gr, hm%kpoints, hm%phase, vec_pot = hm%hm_base%uniform_vector_potential, &
1321 vec_pot_var = hm%hm_base%vector_potential)
1325 if (ks%vdw%vdw_correction == option__vdwcorrection__vdw_ts)
then
1329 safe_deallocate_a(scf%vhxc_old)
1337 character(len=*),
intent(in) :: dir, fname
1340 real(real64) :: dipole(1:space%dim)
1341 real(real64) :: ex_virial
1345 if(st%system_grp%is_root())
then
1347 iunit =
io_open(trim(dir) //
"/" // trim(fname), namespace, action=
'write')
1353 if (space%is_periodic())
then
1354 call hm%kpoints%write_info(iunit=iunit)
1363 write(iunit,
'(1x)')
1367 write(iunit,
'(a, i4, a)')
'SCF converged in ', iter,
' iterations'
1369 write(iunit,
'(a)')
'SCF *not* converged!'
1371 write(iunit,
'(1x)')
1373 if(any(scf%eigens%converged < st%nst))
then
1374 write(iunit,
'(a)')
'Some of the states are not fully converged!'
1375 if (all(scf%eigens%converged >= st%nst_conv))
then
1376 write(iunit,
'(a)')
'But all requested states to converge are converged.'
1381 write(iunit,
'(1x)')
1383 if (space%is_periodic())
then
1385 write(iunit,
'(1x)')
1395 if(st%system_grp%is_root())
write(iunit,
'(1x)')
1398 calc_orb_moments=scf%calc_orb_moments)
1399 if (st%system_grp%is_root())
write(iunit,
'(1x)')
1402 if(st%d%ispin ==
spinors .and. space%dim == 3 .and. &
1405 if(st%system_grp%is_root())
write(iunit,
'(1x)')
1411 if(st%system_grp%is_root())
write(iunit,
'(1x)')
1414 if(scf%calc_dipole)
then
1419 if (scf%calc_polarization)
then
1421 if (st%system_grp%is_root())
write(iunit,
'(1x)')
1426 hm%xc%functional(
func_c,1)%family == xc_family_none .and. st%d%ispin /=
spinors &
1427 .and. .not. space%is_periodic())
then
1430 if (st%system_grp%is_root())
then
1434 write(iunit,
'(1x)')
1438 if(st%system_grp%is_root())
then
1439 if(scf%max_iter > 0)
then
1440 write(iunit,
'(a)')
'Convergence:'
1441 call iterator%start(scf%criterion_list)
1442 do while (iterator%has_next())
1443 crit => iterator%get_next()
1444 call crit%write_info(iunit)
1452 call ks%v_ks_photons%write_info(iunit)
1457 if (scf%calc_stress)
then
1458 call output_stress(iunit, space%periodic_dim, st%stress_tensors, all_terms=.false.)
1459 call output_pressure(iunit, space%periodic_dim, st%stress_tensors%total)
1464 if(scf%calc_partial_charges)
then
1468 if(st%system_grp%is_root())
then
1499 real(real64) :: mem_tmp
1503 if(
conf%report_memory)
then
1505 call mpi_world%allreduce(mem, mem_tmp, 1, mpi_double_precision, mpi_sum)
1507 write(
message(1),
'(a,f14.2)')
'Memory usage [Mbytes] :', mem
1517 type(
scf_t),
intent(inout) :: scf
1523 select type (criterion)
1525 scf%energy_in = hm%energy%total
1540 type(
scf_t),
intent(inout) :: scf
1543 type(
grid_t),
intent(in) :: gr
1544 real(real64),
contiguous,
intent(in) :: rhoout(:,:), rhoin(:,:)
1548 real(real64),
allocatable :: tmp(:)
1552 select type (criterion)
1554 scf%energy_diff = abs(hm%energy%total - scf%energy_in)
1557 scf%abs_dens_diff =
m_zero
1558 safe_allocate(tmp(1:gr%np))
1559 do is = 1, st%d%nspin
1560 tmp(:) = abs(rhoin(1:gr%np, is) - rhoout(1:gr%np, is))
1561 scf%abs_dens_diff = scf%abs_dens_diff +
dmf_integrate(gr, tmp)
1563 safe_deallocate_a(tmp)
1567 scf%evsum_diff = abs(scf%evsum_out - scf%evsum_in)
1568 scf%evsum_in = scf%evsum_out
1578 subroutine write_dipole(st, hm, space, dipole, iunit, namespace)
1582 real(real64),
contiguous,
intent(in) :: dipole(:)
1583 integer,
optional,
intent(in) :: iunit
1584 type(
namespace_t),
optional,
intent(in) :: namespace
1588 if(st%system_grp%is_root())
then
1589 call output_dipole(dipole, space%dim, iunit=iunit, namespace=namespace)
1591 if (space%is_periodic())
then
1592 message(1) =
"Defined only up to quantum of polarization (e * lattice vector)."
1593 message(2) =
"Single-point Berry's phase method only accurate for large supercells."
1596 if (hm%kpoints%full%npoints > 1)
then
1598 "WARNING: Single-point Berry's phase method for dipole should not be used when there is more than one k-point."
1599 message(2) =
"Instead, finite differences on k-points (not yet implemented) are needed."
1604 message(1) =
"Single-point Berry's phase dipole calculation not correct without integer occupations."
1617 type(
scf_t),
intent(inout) :: scf
1618 logical,
intent(in) :: known_lower_bound
1620 call scf%eigens%set_lower_bound_is_known(known_lower_bound)
Copies a vector x, to a vector y.
This module implements common operations on batches of mesh functions.
Berry-phase routines for periodic dipoles, static polarization, and the finite-field electric enthalp...
subroutine, public berry_perform_internal_scf(this, namespace, space, eigensolver, gr, st, hm, iter, ks, ions, ext_partners)
Inner self-consistency loop for a static electric field in periodic systems.
subroutine, public berry_write_polarization(namespace, space, mesh, st, ions, kpoints, iunit)
Compute and write the static modern-theory polarization after SCF.
subroutine, public berry_init(this, namespace)
subroutine, public calc_dipole(dipole, space, mesh, st, ions)
Calculate the total dipole used by the finite-field Berry machinery.
subroutine, public criteria_factory_init(list, namespace, check_conv)
This module implements a calculator for the density and defines related functions.
subroutine, public states_elec_sync_buff_density(st, mesh)
Synchronize the GPU density buffer with the host density strho.
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
integer, parameter, public rs_evo
subroutine, public eigensolver_init(eigens, namespace, gr, st, hm, mc, space, deactivate_oracle)
integer, parameter, public rs_chebyshev
subroutine, public eigensolver_end(eigens)
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
subroutine, public energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full)
This subroutine calculates the total energy of the system. Basically, it adds up the KS eigenvalues,...
subroutine, public energy_calc_virial_ex(der, vxc, st, ex)
subroutine, public energy_calc_eigenvalues(namespace, hm, der, st)
integer, parameter, public spin_orbit
integer, parameter, public scalar_relativistic_zora
integer, parameter, public fully_relativistic_zora
subroutine, public forces_write_info(iunit, ions, dir, namespace)
subroutine, public forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old, t, dt)
real(real64), parameter, public m_zero
integer, parameter, public hartree_fock
integer, parameter, public independent_particles
Theory level.
integer, parameter, public generalized_kohn_sham_dft
real(real64), parameter, public lmm_r_single_atom
Default local magnetic moments sphere radius for an isolated system.
integer, parameter, public kohn_sham_dft
type(conf_t), public conf
Global instance of Octopus configuration.
character(len= *), parameter, public static_dir
real(real64), parameter, public m_half
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
subroutine, public grid_write_info(gr, iunit, namespace)
subroutine, public hamiltonian_elec_update_pot(this, mesh, accumulate)
Update the KS potential of the electronic Hamiltonian.
This module defines classes and functions for interaction partners.
subroutine, public io_close(iunit, grp)
subroutine, public io_debug_on_the_fly(namespace)
check if debug mode should be enabled or disabled on the fly
subroutine, public io_mkdir(fname, namespace, parents)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
integer, parameter, public kpoints_path
integer pure function, public kpoints_number(this)
A module to handle KS potential, without the external potential.
subroutine, public lda_u_dump(restart, namespace, this, st, mesh, ierr)
subroutine, public lda_u_write_u(this, iunit, namespace)
subroutine, public lda_u_load(restart, this, st, dftu_energy, ierr, occ_only, u_only)
subroutine, public lda_u_write_v(this, iunit, namespace)
subroutine, public lda_u_mixer_set_vin(this, mixer)
subroutine, public lda_u_mixer_init(this, mixer, st)
subroutine, public lda_u_mixer_clear(mixer, smix)
subroutine, public lda_u_mixer_init_auxmixer(this, namespace, mixer, smix, st)
subroutine, public lda_u_mixer_get_vnew(this, mixer, st)
subroutine, public lda_u_mixer_set_vout(this, mixer)
subroutine, public lda_u_mixer_end(mixer, smix)
integer, parameter, public dft_u_none
subroutine, public lda_u_update_occ_matrices(this, namespace, mesh, st, phase, energy)
integer, parameter, public dft_u_acbn0
System information (time, memory, sysname)
subroutine, public compute_and_write_magnetic_moments(gr, st, phase, ep, ions, lmm_r, calc_orb_moments, iunit, namespace)
Computes and prints the global and local magnetic moments.
subroutine, public write_total_xc_torque(iunit, mesh, vxc, st)
This module is intended to contain "only mathematical" functions and procedures.
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
subroutine, public messages_not_implemented(feature, namespace)
character(len=512), private msg
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_obsolete_variable(namespace, name, rep)
subroutine, public messages_new_line()
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_experimental(name, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
integer pure function, public mix_scheme(this)
real(real64) pure function, public mix_coefficient(this)
subroutine, public mixing(namespace, smix)
Main entry-point to SCF mixer.
subroutine, public mix_get_field(this, mixfield)
subroutine, public mix_dump(namespace, restart, smix, mesh, ierr)
subroutine, public mix_init(smix, namespace, space, der, d1, d2, def_, func_type_, prefix_)
Initialise mix_t instance.
subroutine, public mix_load(namespace, restart, smix, mesh, ierr)
subroutine, public mix_end(smix)
subroutine, public mix_clear(smix)
subroutine, public modelmb_sym_all_states(space, mesh, st)
type(mpi_grp_t), public mpi_world
This module handles the communicators for the various parallelization strategies.
this module contains the low-level part of the output system
subroutine, public output_modelmb(outp, namespace, space, dir, gr, ions, iter, st)
this module contains the output system
logical function, public output_needs_current(outp, states_are_real)
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
subroutine, public partial_charges_compute_and_print_charges(mesh, st, ions, iunit)
Computes and write partial charges to a file.
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
logical function, public clean_stop(comm)
returns true if a file named stop exists
integer, parameter, public restart_flag_mix
integer, parameter, public restart_flag_rho
integer, parameter, public restart_flag_vhxc
subroutine, public scf_finish(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, iter, outp)
subroutine, public scf_set_lower_bound_is_known(scf, known_lower_bound)
Set the flag lower_bound_is_known.
subroutine, public scf_load(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, restart_load)
Loading of restarting data of the SCF cycle.
subroutine write_dipole(st, hm, space, dipole, iunit, namespace)
subroutine scf_update_initial_quantity(scf, hm, criterion)
Update the quantity at the begining of a SCF cycle.
subroutine scf_update_diff_quantity(scf, hm, st, gr, rhoout, rhoin, criterion)
Update the quantity at the begining of a SCF cycle.
subroutine, public scf_state_info(namespace, st)
subroutine, public scf_print_mem_use(namespace)
subroutine, public scf_mix_clear(scf)
subroutine, public scf_start(scf, namespace, gr, ions, st, ks, hm, outp, verbosity)
Preparation of the SCF cycle.
integer, parameter, public verb_full
integer, parameter, public verb_compact
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
subroutine, public scf_end(scf)
subroutine, public scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, verbosity, iters_done, restart_dump)
Legacy version of the SCF code.
subroutine, public scf_iter(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, iter, outp, restart_dump)
logical function, public scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, iters_done)
logical pure function, public smear_is_semiconducting(this)
pure logical function, public states_are_real(st)
This module defines routines to write information about states.
subroutine, public states_elec_write_eigenvalues(nst, st, space, kpoints, error, st_start, compact, iunit, namespace)
write the eigenvalues for some states to a file.
subroutine, public states_elec_write_gaps(iunit, st, space)
calculate gaps and write to a file.
subroutine, public states_elec_write_bandstructure(dir, namespace, nst, st, ions, mesh, kpoints, phase, vec_pot, vec_pot_var)
calculate and write the bandstructure
subroutine, public states_elec_fermi(st, namespace, mesh, compute_spin)
calculate the Fermi level for the states in this object
real(real64) function, public states_elec_eigenvalues_sum(st, alt_eig)
function to calculate the eigenvalues sum using occupations as weights
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_dump(restart, space, st, mesh, kpoints, ierr, iter, lr, verbose)
subroutine, public states_elec_load_rho(restart, st, mesh, ierr)
subroutine, public states_elec_dump_rho(restart, st, mesh, ierr, iter)
This module implements the calculation of the stress tensor.
subroutine, public output_pressure(iunit, space_dim, total_stress_tensor)
subroutine, public stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
This computes the total stress on the lattice.
subroutine, public output_stress(iunit, space_dim, stress_tensors, all_terms)
subroutine, public symmetries_write_info(this, space, iunit, namespace)
type(type_t), parameter, public type_float
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
character(len=20) pure function, public units_abbrev(this)
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_system_t), public units_inp
the units systems for reading and writing
This module is intended to contain simple general-purpose utility functions and procedures.
subroutine, public output_dipole(dipole, ndim, iunit, namespace)
subroutine, public v_ks_write_info(ks, iunit, namespace)
subroutine, public v_ks_update_dftu_energy(ks, namespace, hm, st, int_dft_u)
Update the value of <\psi | V_U | \psi>, where V_U is the DFT+U potential.
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
Tkatchenko-Scheffler pairwise method for van der Waals (vdW, dispersion) interactions.
subroutine, public vdw_ts_write_c6ab(this, ions, dir, fname, namespace)
subroutine, public vtau_mixer_end(mixer, smix)
subroutine, public vtau_mixer_init_auxmixer(namespace, mixer, smix, hm, np, nspin)
subroutine, public vtau_mixer_set_vout(mixer, hm)
subroutine, public vtau_mixer_get_vnew(mixer, hm)
subroutine, public vtau_mixer_clear(mixer, smix)
subroutine, public vtau_mixer_set_vin(mixer, hm)
This module provices a simple timer class which can be used to trigger the writing of a restart file ...
logical function, public walltimer_alarm(comm, print)
indicate whether time is up
logical function, public restart_walltime_period_alarm(comm)
integer, parameter, public xc_family_nc_mgga
integer, parameter, public func_c
integer, parameter, public oep_level_full
subroutine scf_write_static(dir, fname)
subroutine create_convergence_file(dir, fname)
subroutine scf_write_iter(namespace)
subroutine write_convergence_file(dir, fname)
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Stores all communicators and groups.
some variables used for the SCF cycle
abstract class for states
The states_elec_t class contains all electronic wave functions.
batches of electronic states