41 use,
intrinsic :: iso_fortran_env
104 integer,
public,
parameter :: &
112 integer,
public :: max_iter
114 real(real64),
public :: lmm_r
117 logical :: conv_eigen_error
118 logical :: check_conv
121 logical :: lcao_restricted
122 logical :: calc_force
123 logical,
public :: calc_stress
124 logical :: calc_dipole
125 logical :: calc_partial_charges
127 type(mixfield_t),
pointer :: mixfield
128 type(eigensolver_t) :: eigens
130 logical :: forced_finish
131 type(lda_u_mixer_t) :: lda_u_mix
132 type(vtau_mixer_t) :: vtau_mix
133 type(berry_t) :: berry
136 type(criterion_list_t),
public :: criterion_list
137 real(real64) :: energy_in, energy_diff, abs_dens_diff, evsum_in, evsum_out, evsum_diff
143 subroutine scf_init(scf, namespace, gr, ions, st, mc, hm, space)
144 type(scf_t),
intent(inout) :: scf
145 type(grid_t),
intent(in) :: gr
146 type(namespace_t),
intent(in) :: namespace
147 type(ions_t),
intent(in) :: ions
148 type(states_elec_t),
intent(in) :: st
149 type(multicomm_t),
intent(in) :: mc
150 type(hamiltonian_elec_t),
intent(inout) :: hm
151 class(space_t),
intent(in) :: space
154 integer :: mixdefault
155 type(type_t) :: mix_type
156 class(convergence_criterion_t),
pointer :: crit
157 type(criterion_iterator_t) :: iter
180 if (
allocated(hm%vberry))
then
187 call iter%start(scf%criterion_list)
188 do while (iter%has_next())
189 crit => iter%get_next()
192 call crit%set_pointers(scf%energy_diff, scf%energy_in)
194 call crit%set_pointers(scf%abs_dens_diff, st%qtot)
196 call crit%set_pointers(scf%evsum_diff, scf%evsum_out)
203 if(.not. scf%check_conv .and. scf%max_iter < 0)
then
204 call messages_write(
"All convergence criteria are disabled. Octopus is cowardly refusing")
209 call messages_write(
"Please set one of the following variables to a positive value:")
212 call messages_write(
" | MaximumIter | ConvEnergy | ConvAbsDens | ConvRelDens |")
232 if(scf%max_iter < 0) scf%max_iter = huge(scf%max_iter)
239 if(scf%eigens%es_type /=
rs_evo)
then
263 mixdefault = option__mixfield__potential
266 call parse_variable(namespace,
'MixField', mixdefault, scf%mix_field)
270 if (scf%mix_field == option__mixfield__potential .and. hm%theory_level ==
independent_particles)
then
271 call messages_write(
'Input: Cannot mix the potential for non-interacting particles.')
275 if (scf%mix_field == option__mixfield__potential .and. hm%pcm%run_pcm)
then
276 call messages_write(
'Input: You have selected to mix the potential.', new_line = .
true.)
277 call messages_write(
' This might produce convergence problems for solvated systems.', new_line = .
true.)
282 if(scf%mix_field == option__mixfield__density &
285 call messages_write(
'Input: You have selected to mix the density with OEP or MGGA XC functionals.', new_line = .
true.)
286 call messages_write(
' This might produce convergence problems. Mix the potential instead.')
290 if(scf%mix_field == option__mixfield__states)
then
295 select case(scf%mix_field)
296 case (option__mixfield__potential, option__mixfield__density)
298 case(option__mixfield__states)
305 if (scf%mix_field /= option__mixfield__none)
then
306 call mix_init(scf%smix, namespace, space, gr%der, scf%mixdim1, st%d%nspin, func_type_ = mix_type)
310 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none )
then
316 if(scf%mix_field == option__mixfield__potential)
then
322 scf%mix_field = option__mixfield__none
335 call parse_variable(namespace,
'SCFinLCAO', .false., scf%lcao_restricted)
336 if(scf%lcao_restricted)
then
338 message(1) =
'Info: SCF restricted to LCAO subspace.'
341 if(scf%conv_eigen_error)
then
342 message(1) =
"ConvEigenError cannot be used with SCFinLCAO, since error is unknown."
357 call parse_variable(namespace,
'SCFCalculateForces', .not. ions%only_user_def, scf%calc_force)
359 if(scf%calc_force .and. gr%der%boundaries%spiralBC)
then
360 message(1) =
'Forces cannot be calculated when using spiral boundary conditions.'
361 write(
message(2),
'(a)')
'Please use SCFCalculateForces = no.'
364 if(scf%calc_force)
then
365 if (
allocated(hm%ep%b_field) .or.
allocated(hm%ep%a_static))
then
366 write(
message(1),
'(a)')
'The forces are currently not properly calculated if static'
367 write(
message(2),
'(a)')
'magnetic fields or static vector potentials are present.'
368 write(
message(3),
'(a)')
'Please use SCFCalculateForces = no.'
381 call parse_variable(namespace,
'SCFCalculateStress', .false. , scf%calc_stress)
395 call parse_variable(namespace,
'SCFCalculateDipole', .not. space%is_periodic(), scf%calc_dipole)
396 if (
allocated(hm%vberry)) scf%calc_dipole = .
true.
406 call parse_variable(namespace,
'SCFCalculatePartialCharges', .false., scf%calc_partial_charges)
407 if (scf%calc_partial_charges)
call messages_experimental(
'SCFCalculatePartialCharges', namespace=namespace)
409 rmin = ions%min_distance()
425 scf%forced_finish = .false.
433 type(
scf_t),
intent(inout) :: scf
442 if(scf%mix_field /= option__mixfield__none)
call mix_end(scf%smix)
444 nullify(scf%mixfield)
446 if (scf%mix_field /= option__mixfield__states)
then
451 call iter%start(scf%criterion_list)
452 do while (iter%has_next())
453 crit => iter%get_next()
454 safe_deallocate_p(crit)
463 type(
scf_t),
intent(inout) :: scf
469 if (scf%mix_field /= option__mixfield__states)
then
479 subroutine scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, &
480 verbosity, iters_done, restart_load, restart_dump)
481 type(
scf_t),
intent(inout) :: scf
485 type(
grid_t),
intent(inout) :: gr
486 type(
ions_t),
intent(inout) :: ions
489 type(
v_ks_t),
intent(inout) :: ks
491 type(
output_t),
optional,
intent(in) :: outp
492 integer,
optional,
intent(in) :: verbosity
493 integer,
optional,
intent(out) :: iters_done
494 type(
restart_t),
optional,
intent(in) :: restart_load
495 type(
restart_t),
optional,
intent(in) :: restart_dump
497 logical :: finish, converged_current, converged_last
498 integer :: iter, is, nspin, ierr, verbosity_, ib, iqn
499 integer(int64) :: what_i
500 real(real64) :: etime, itime
501 character(len=MAX_PATH_LEN) :: dirname
503 real(real64),
allocatable :: rhoout(:,:), rhoin(:,:)
504 real(real64),
allocatable :: vhxc_old(:,:)
505 class(
wfs_elec_t),
allocatable :: psioutb(:, :)
508 logical :: is_crit_conv, output_forces, calc_current, output_during_scf
512 if(scf%forced_finish)
then
513 message(1) =
"Previous clean stop, not doing SCF and quitting."
518 if(
present(verbosity)) verbosity_ = verbosity
520 output_during_scf = .false.
521 output_forces = .false.
522 calc_current = .false.
524 if (
present(outp))
then
527 if (outp%what(option__output__stress))
then
528 scf%calc_stress = .
true.
531 output_during_scf = outp%duringscf
534 if (outp%duringscf .and. outp%what(option__output__forces))
then
535 output_forces = .
true.
539 if(scf%lcao_restricted)
then
540 call lcao_init(lcao, namespace, space, gr, ions, st)
542 message(1) =
'LCAO is not available. Cannot do SCF in LCAO.'
549 if (
present(restart_load))
then
554 message(1) =
'Unable to read density. Density will be calculated from states.'
557 if (
bitand(ks%xc_family, xc_family_oep) == 0)
then
558 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
561 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
570 message(1) =
'Unable to read Vhxc. Vhxc will be calculated from states.'
573 call hm%update(gr, namespace, space, ext_partners)
574 if (
bitand(ks%xc_family, xc_family_oep) /= 0)
then
576 do is = 1, st%d%nspin
577 ks%oep%vxc(1:gr%np, is) = hm%vhxc(1:gr%np, is) - hm%vhartree(1:gr%np)
579 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
586 if (scf%mix_field == option__mixfield__density .or. scf%mix_field == option__mixfield__potential)
then
587 call mix_load(namespace, restart_load, scf%smix, space, gr, ierr)
590 message(1) =
"Unable to read mixing information. Mixing will start from scratch."
596 call lda_u_load(restart_load, hm%lda_u, st, hm%energy%dft_u, ierr)
598 message(1) =
"Unable to read DFT+U information. DFT+U data will be calculated from states."
608 safe_allocate(rhoout(1:gr%np, 1:nspin))
609 safe_allocate(rhoin(1:gr%np, 1:nspin))
611 call lalg_copy(gr%np, nspin, st%rho, rhoin)
614 if (scf%calc_force .or. output_forces)
then
616 safe_allocate(vhxc_old(1:gr%np, 1:nspin))
617 call lalg_copy(gr%np, nspin, hm%vhxc, vhxc_old)
621 select case(scf%mix_field)
622 case(option__mixfield__potential)
625 case (option__mixfield__density)
628 case(option__mixfield__states)
630 safe_allocate_type_array(
wfs_elec_t, psioutb, (st%group%block_start:st%group%block_end, st%d%kpt%start:st%d%kpt%end))
632 do iqn = st%d%kpt%start, st%d%kpt%end
633 do ib = st%group%block_start, st%group%block_end
634 call st%group%psib(ib, iqn)%copy_to(psioutb(ib, iqn))
642 if (scf%mix_field /= option__mixfield__states)
then
648 if ( verbosity_ /= verb_no )
then
649 if(scf%max_iter > 0)
then
650 write(
message(1),
'(a)')
'Info: Starting SCF iteration.'
652 write(
message(1),
'(a)')
'Info: No SCF iterations will be done.'
658 converged_current = .false.
665 do iter = 1, scf%max_iter
670 scf%eigens%converged = 0
673 call hm%update_span(gr%spacing(1:space%dim), minval(st%eigenval(:, :)), namespace)
679 call iterator%start(scf%criterion_list)
680 do while (iterator%has_next())
681 crit => iterator%get_next()
685 if (scf%calc_force .or. output_forces)
then
687 vhxc_old(1:gr%np, 1:nspin) = hm%vhxc(1:gr%np, 1:nspin)
690 if(scf%lcao_restricted)
then
692 call lcao_wf(lcao, st, gr, ions, hm, namespace)
697 if (
allocated(hm%vberry))
then
700 ks%frozen_hxc = .
true.
702 call berry_perform_internal_scf(scf%berry, namespace, space, scf%eigens, gr, st, hm, iter, ks, ions, ext_partners)
704 ks%frozen_hxc = .false.
706 scf%eigens%converged = 0
707 call scf%eigens%run(namespace, gr, st, hm, iter)
711 scf%matvec = scf%matvec + scf%eigens%matvec
720 call lalg_copy(gr%np, nspin, st%rho, rhoout)
722 select case (scf%mix_field)
723 case (option__mixfield__potential)
724 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=output_during_scf)
727 case (option__mixfield__density)
729 case(option__mixfield__states)
731 do iqn = st%d%kpt%start, st%d%kpt%end
732 do ib = st%group%block_start, st%group%block_end
733 call st%group%psib(ib, iqn)%copy_data_to(gr%np, psioutb(ib, iqn))
738 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none)
then
745 if (
present(outp))
then
747 if (outp%duringscf .and. outp%what_now(option__output__forces, iter))
then
748 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old=vhxc_old)
753 call iterator%start(scf%criterion_list)
754 do while (iterator%has_next())
755 crit => iterator%get_next()
760 converged_last = converged_current
762 converged_current = scf%check_conv .and. &
763 (.not. scf%conv_eigen_error .or. all(scf%eigens%converged == st%nst))
765 call iterator%start(scf%criterion_list)
766 do while (iterator%has_next())
767 crit => iterator%get_next()
768 call crit%is_converged(is_crit_conv)
769 converged_current = converged_current .and. is_crit_conv
774 finish = converged_last .and. converged_current
777 itime = etime + itime
781 select case (scf%mix_field)
782 case (option__mixfield__density)
784 call mixing(namespace, scf%smix)
787 if (minval(st%rho(1:gr%np, 1:st%d%spin_channels)) < -1e-6_real64)
then
788 write(
message(1),*)
'Negative density after mixing. Minimum value = ', &
789 minval(st%rho(1:gr%np, 1:st%d%spin_channels))
793 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=output_during_scf)
794 case (option__mixfield__potential)
796 call mixing(namespace, scf%smix)
802 case(option__mixfield__states)
804 do iqn = st%d%kpt%start, st%d%kpt%end
805 do ib = st%group%block_start, st%group%block_end
812 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=output_during_scf)
814 case (option__mixfield__none)
815 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=output_during_scf)
822 if (finish .and. st%modelmbparticles%nparticle > 0)
then
826 if (
present(outp) .and.
present(restart_dump))
then
829 if ( (finish .or. (modulo(iter, outp%restart_write_interval) == 0) &
830 .or. iter == scf%max_iter .or. scf%forced_finish) )
then
832 call states_elec_dump(restart_dump, space, st, gr, hm%kpoints, ierr, iter=iter)
834 message(1) =
'Unable to write states wavefunctions.'
840 message(1) =
'Unable to write density.'
845 call lda_u_dump(restart_dump, namespace, hm%lda_u, st, gr, ierr)
847 message(1) =
'Unable to write DFT+U information.'
852 select case (scf%mix_field)
853 case (option__mixfield__density)
854 call mix_dump(namespace, restart_dump, scf%smix, space, gr, ierr)
856 message(1) =
'Unable to write mixing information.'
859 case (option__mixfield__potential)
862 message(1) =
'Unable to write Vhxc.'
866 call mix_dump(namespace, restart_dump, scf%smix, space, gr, ierr)
868 message(1) =
'Unable to write mixing information.'
878 if(
present(iters_done)) iters_done = iter
880 write(
message(1),
'(a, i4, a)')
'Info: SCF converged in ', iter,
' iterations'
887 if (
present(outp))
then
888 if (any(outp%what) .and. outp%duringscf)
then
889 do what_i = lbound(outp%what, 1), ubound(outp%what, 1)
890 if (outp%what_now(what_i, iter))
then
891 write(dirname,
'(a,a,i4.4)') trim(outp%iter_dir),
"scf.",iter
892 call output_all(outp, namespace, space, dirname, gr, ions, iter, st, hm, ks)
893 call output_modelmb(outp, namespace, space, dirname, gr, ions, iter, st)
901 call lalg_copy(gr%np, nspin, st%rho, rhoin)
904 if (scf%mix_field /= option__mixfield__none)
then
905 if (scf%smix%ns_restart > 0)
then
906 if (mod(iter, scf%smix%ns_restart) == 0)
then
907 message(1) =
"Info: restarting mixing."
914 select case(scf%mix_field)
915 case(option__mixfield__potential)
918 case (option__mixfield__density)
921 if(scf%mix_field /= option__mixfield__states)
call lda_u_mixer_set_vin(hm%lda_u, scf%lda_u_mix)
923 if(scf%forced_finish)
then
934 if(scf%lcao_restricted)
call lcao_end(lcao)
936 if ((scf%max_iter > 0 .and. scf%mix_field == option__mixfield__potential) .or. calc_current)
then
937 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
938 calc_current=calc_current)
941 select case(scf%mix_field)
942 case(option__mixfield__states)
944 do iqn = st%d%kpt%start, st%d%kpt%end
945 do ib = st%group%block_start, st%group%block_end
946 call psioutb(ib, iqn)%end()
950 safe_deallocate_a(psioutb)
953 safe_deallocate_a(rhoout)
954 safe_deallocate_a(rhoin)
956 if(scf%max_iter > 0 .and. any(scf%eigens%converged < st%nst) .and. .not. scf%lcao_restricted)
then
957 write(
message(1),
'(a)')
'Some of the states are not fully converged!'
962 write(
message(1),
'(a,i4,a)')
'SCF *not* converged after ', iter - 1,
' iterations.'
966 write(
message(1),
'(a,i10)')
'Info: Number of matrix-vector products: ', scf%matvec
969 if (scf%calc_force)
then
970 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old=vhxc_old)
973 if (scf%calc_stress)
call stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
975 if(scf%max_iter == 0)
then
981 if(
present(outp))
then
988 if (space%is_periodic() .and. st%nik > st%d%nspin)
then
991 ions, gr, hm%kpoints, hm%phase, vec_pot = hm%hm_base%uniform_vector_potential, &
992 vec_pot_var = hm%hm_base%vector_potential)
996 if (ks%vdw%vdw_correction == option__vdwcorrection__vdw_ts)
then
1000 safe_deallocate_a(vhxc_old)
1011 character(len=50) :: str
1012 real(real64) :: dipole(1:space%dim)
1018 write(str,
'(a,i5)')
'SCF CYCLE ITER #' ,iter
1022 ' rel_ev = ', scf%evsum_diff/(abs(scf%evsum_out)+1e-20)
1023 write(
message(2),
'(a,es15.2,2(a,es9.2))') &
1024 ' ediff = ', scf%energy_diff,
' abs_dens = ', scf%abs_dens_diff, &
1025 ' rel_dens = ', scf%abs_dens_diff/st%qtot
1028 if(.not.scf%lcao_restricted)
then
1029 write(
message(1),
'(a,i6)')
'Matrix vector products: ', scf%eigens%matvec
1030 write(
message(2),
'(a,i6)')
'Converged eigenvectors: ', sum(scf%eigens%converged(1:st%nik))
1037 if (
allocated(hm%vberry))
then
1052 write(
message(2),
'(a,i5,a,f14.2)')
'Elapsed time for SCF step ', iter,
':', etime
1062 write(
message(1),
'(a,i4,a,es15.8, a,es9.2, a, f7.1, a)') &
1065 ' : abs_dens', scf%abs_dens_diff, &
1066 ' : etime ', etime,
's'
1076 character(len=*),
intent(in) :: dir, fname
1078 integer :: iunit, iatom
1079 real(real64),
allocatable :: hirshfeld_charges(:)
1080 real(real64) :: dipole(1:space%dim)
1081 real(real64) :: ex_virial
1087 iunit =
io_open(trim(dir) //
"/" // trim(fname), namespace, action=
'write')
1093 if (space%is_periodic())
then
1094 call hm%kpoints%write_info(iunit=iunit)
1102 write(iunit,
'(a, i4, a)')
'SCF converged in ', iter,
' iterations'
1104 write(iunit,
'(a)')
'SCF *not* converged!'
1106 write(iunit,
'(1x)')
1108 if(any(scf%eigens%converged < st%nst) .and. .not. scf%lcao_restricted)
then
1109 write(iunit,
'(a)')
'Some of the states are not fully converged!'
1113 write(iunit,
'(1x)')
1115 if (space%is_periodic())
then
1117 write(iunit,
'(1x)')
1133 if(st%d%ispin ==
spinors .and. space%dim == 3 .and. &
1145 if(scf%calc_dipole)
then
1152 hm%xc%functional(
func_c,1)%family == xc_family_none .and. st%d%ispin /=
spinors)
then
1159 write(iunit,
'(1x)')
1164 if(scf%max_iter > 0)
then
1165 write(iunit,
'(a)')
'Convergence:'
1166 call iterator%start(scf%criterion_list)
1167 do while (iterator%has_next())
1168 crit => iterator%get_next()
1169 call crit%write_info(iunit)
1178 write(iunit,
'(a)')
'Photon observables:'
1179 write(iunit,
'(6x, a, es15.8,a,es15.8,a)')
'Photon number = ', ks%oep_photon%pt%number(1)
1180 write(iunit,
'(6x, a, es15.8,a,es15.8,a)')
'Photon ex. = ', ks%oep_photon%pt%ex
1187 if (scf%calc_stress)
then
1188 call output_stress(iunit, space%periodic_dim, st%stress_tensors, all_terms=.false.)
1189 call output_pressure(iunit, space%periodic_dim, st%stress_tensors%total)
1194 if(scf%calc_partial_charges)
then
1195 safe_allocate(hirshfeld_charges(1:ions%natoms))
1201 write(iunit,
'(a)')
'Partial ionic charges'
1202 write(iunit,
'(a)')
' Ion Hirshfeld'
1204 do iatom = 1, ions%natoms
1205 write(iunit,
'(i4,a10,f16.3)') iatom, trim(ions%atom(iatom)%species%get_label()), hirshfeld_charges(iatom)
1211 safe_deallocate_a(hirshfeld_charges)
1224 real(real64),
intent(in) :: dipole(:)
1225 integer,
optional,
intent(in) :: iunit
1226 type(
namespace_t),
optional,
intent(in) :: namespace
1231 call output_dipole(dipole, space%dim, iunit=iunit, namespace=namespace)
1233 if (space%is_periodic())
then
1234 message(1) =
"Defined only up to quantum of polarization (e * lattice vector)."
1235 message(2) =
"Single-point Berry's phase method only accurate for large supercells."
1238 if (hm%kpoints%full%npoints > 1)
then
1240 "WARNING: Single-point Berry's phase method for dipole should not be used when there is more than one k-point."
1241 message(2) =
"Instead, finite differences on k-points (not yet implemented) are needed."
1246 message(1) =
"Single-point Berry's phase dipole calculation not correct without integer occupations."
1260 character(len=*),
intent(in) :: dir
1261 character(len=*),
intent(in) :: fname
1264 character(len=12) :: label
1267 iunit =
io_open(trim(dir) //
"/" // trim(fname), namespace, action=
'write')
1268 write(iunit,
'(a)', advance =
'no')
'#iter energy '
1269 label =
'energy_diff'
1270 write(iunit,
'(1x,a)', advance =
'no') label
1272 write(iunit,
'(1x,a)', advance =
'no') label
1274 write(iunit,
'(1x,a)', advance =
'no') label
1276 write(iunit,
'(1x,a)', advance =
'no') label
1278 write(iunit,
'(1x,a)', advance =
'no') label
1282 label =
'OEP norm2ss'
1283 write(iunit,
'(1x,a)', advance =
'no') label
1286 write(iunit,
'(a)')
''
1295 character(len=*),
intent(in) :: dir
1296 character(len=*),
intent(in) :: fname
1302 iunit =
io_open(trim(dir) //
"/" // trim(fname), namespace, action=
'write', position=
'append')
1304 call iterator%start(scf%criterion_list)
1305 do while (iterator%has_next())
1306 crit => iterator%get_next()
1311 write(iunit,
'(2es13.5)', advance =
'no') crit%val_abs, crit%val_rel
1314 write(iunit,
'(es13.5)', advance =
'no') crit%val_rel
1322 write(iunit,
'(es13.5)', advance =
'no') ks%oep%norm2ss
1325 write(iunit,
'(a)')
''
1355 real(real64) :: mem_tmp
1359 if(
conf%report_memory)
then
1361 call mpi_world%allreduce(mem, mem_tmp, 1, mpi_double_precision, mpi_sum)
1363 write(
message(1),
'(a,f14.2)')
'Memory usage [Mbytes] :', mem
1373 type(
scf_t),
intent(inout) :: scf
1379 select type (criterion)
1381 scf%energy_in = hm%energy%total
1396 type(
scf_t),
intent(inout) :: scf
1399 type(
grid_t),
intent(in) :: gr
1400 real(real64),
intent(in) :: rhoout(:,:), rhoin(:,:)
1404 real(real64),
allocatable :: tmp(:)
1408 select type (criterion)
1410 scf%energy_diff = abs(hm%energy%total - scf%energy_in)
1413 scf%abs_dens_diff =
m_zero
1414 safe_allocate(tmp(1:gr%np))
1415 do is = 1, st%d%nspin
1416 tmp = abs(rhoin(1:gr%np, is) - rhoout(1:gr%np, is))
1417 scf%abs_dens_diff = scf%abs_dens_diff +
dmf_integrate(gr, tmp)
1419 safe_deallocate_a(tmp)
1423 scf%evsum_diff = abs(scf%evsum_out - scf%evsum_in)
1424 scf%evsum_in = scf%evsum_out
batchified version of the BLAS axpy routine:
scale a batch by a constant or vector
Copies a vector x, to a vector y.
This module implements common operations on batches of mesh functions.
subroutine, public berry_perform_internal_scf(this, namespace, space, eigensolver, gr, st, hm, iter, ks, ions, ext_partners)
subroutine, public berry_init(this, namespace)
subroutine, public calc_dipole(dipole, space, mesh, st, ions)
subroutine, public criteria_factory_init(list, namespace, check_conv)
This module implements a calculator for the density and defines related functions.
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
subroutine, public eigensolver_init(eigens, namespace, gr, st, mc, space)
integer, parameter, public rs_evo
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)
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
real(real64), parameter, public lmm_r_single_atom
Default local magnetic moments sphere radius for an isolated system.
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)
integer, parameter, public generalized_kohn_sham_dft
integer, parameter, public hartree_fock
integer, parameter, public independent_particles
subroutine, public hamiltonian_elec_dump_vhxc(restart, hm, space, mesh, ierr)
subroutine, public hamiltonian_elec_update_pot(this, mesh, accumulate)
Update the KS potential of the electronic Hamiltonian.
subroutine, public hamiltonian_elec_load_vhxc(restart, hm, space, mesh, ierr)
integer, parameter, public kohn_sham_dft
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_rm(fname, namespace)
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
subroutine, public lcao_init_orbitals(this, namespace, st, gr, ions, start)
subroutine, public lcao_wf(this, st, gr, ions, hm, namespace, start)
subroutine, public lcao_end(this)
subroutine, public lcao_init(this, namespace, space, gr, ions, st)
logical function, public lcao_is_available(this)
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
integer, parameter, public dft_u_acbn0
subroutine, public lda_u_update_occ_matrices(this, namespace, mesh, st, hm_base, phase, energy)
subroutine, public write_magnetic_moments(mesh, st, ions, boundaries, lmm_r, iunit, namespace)
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.
real(real64) function, public dmf_integrate(mesh, ff, mask, reduce)
Integrate a function on the mesh.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_print_with_emphasis(msg, iunit, 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_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
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)
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, space, mesh, ierr)
subroutine, public mix_load(namespace, restart, smix, space, mesh, ierr)
subroutine, public mix_init(smix, namespace, space, der, d1, d2, def_, func_type_, prefix_)
Initialise mix_t instance.
subroutine, public mix_end(smix)
subroutine, public mix_clear(smix)
subroutine, public modelmb_sym_all_states(space, mesh, st)
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
type(mpi_grp_t), public mpi_world
This module handles the communicators for the various parallelization strategies.
this module contains 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_calculate(mesh, st, ions, hirshfeld_charges)
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
logical pure function, public restart_has_flag(restart, flag)
Returns true if...
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_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, verbosity, iters_done, restart_load, restart_dump)
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)
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, st_start_writing, verbose)
subroutine, public states_elec_load_rho(restart, space, st, mesh, ierr)
subroutine, public states_elec_dump_rho(restart, space, 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), 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_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
integer, parameter, public xc_family_nc_mgga
integer, parameter, public func_c
integer, parameter, public oep_level_full
integer, parameter, public oep_level_kli
subroutine scf_write_static(dir, fname)
subroutine write_dipole(dipole, iunit, namespace)
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