Octopus
scf.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2014 M. Marques, A. Castro, A. Rubio, G. Bertsch, M. Oliveira
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21module scf_oct_m
23 use berry_oct_m
26 use debug_oct_m
34 use epot_oct_m
35 use forces_oct_m
36 use global_oct_m
37 use grid_oct_m
40 use io_oct_m
41 use ions_oct_m
42 use, intrinsic :: iso_fortran_env
46 use lcao_oct_m
47 use lda_u_oct_m
51 use loct_oct_m
53 use math_oct_m
54 use mesh_oct_m
57 use mix_oct_m
59 use mpi_oct_m
62 use output_oct_m
65 use parser_oct_m
69 use smear_oct_m
70 use space_oct_m
75 use stress_oct_m
77 use types_oct_m
78 use unit_oct_m
80 use utils_oct_m
81 use v_ks_oct_m
83 use vdw_ts_oct_m
87 use xc_oct_m
88 use xc_f03_lib_m
91 use xc_oep_oct_m
92
93 implicit none
94
95 private
96 public :: &
97 scf_t, &
98 scf_init, &
100 scf_load, &
101 scf_start, &
102 scf_run, &
103 scf_iter, &
105 scf_finish, &
106 scf_end, &
110
111 integer, public, parameter :: &
112 VERB_NO = 0, &
113 verb_compact = 1, &
114 verb_full = 3
115
117 type scf_t
118 private
119 integer, public :: max_iter
120
121 real(real64), public :: lmm_r
122
123 ! several convergence criteria
124 logical :: conv_eigen_error
125 logical :: check_conv
126
127 integer :: mix_field
128 logical :: calc_force
129 logical, public :: calc_stress
130 logical :: calc_dipole
131 logical :: calc_partial_charges
132 logical :: calc_orb_moments = .false.
133
134 type(mix_t) :: smix
135 type(mixfield_t), pointer :: mixfield
136 type(eigensolver_t) :: eigens
137 integer :: mixdim1
138 logical :: forced_finish = .false.
139 type(lda_u_mixer_t) :: lda_u_mix
140 type(vtau_mixer_t) :: vtau_mix
141 type(berry_t) :: berry
142 integer :: matvec
143
144 type(restart_t), public :: restart_load, restart_dump
145
146 type(criterion_list_t), public :: criterion_list
147 real(real64) :: energy_in, energy_diff, abs_dens_diff, evsum_in, evsum_out, evsum_diff
148
149 ! Variables needed to store information accross scf_start, scf_run, and scf_finish
150 logical :: converged_current, converged_last
151 integer :: verbosity_
152 type(lcao_t) :: lcao
153 real(real64), allocatable :: rhoout(:,:), rhoin(:,:)
154 real(real64), allocatable :: vhxc_old(:,:)
155 class(wfs_elec_t), allocatable :: psioutb(:, :)
156 logical :: output_forces, calc_current, output_during_scf
157 logical :: finish = .false.
158 end type scf_t
159
160contains
161
162 ! ---------------------------------------------------------
163 subroutine scf_init(scf, namespace, gr, ions, st, mc, hm, space)
164 type(scf_t), intent(inout) :: scf
165 type(grid_t), intent(in) :: gr
166 type(namespace_t), intent(in) :: namespace
167 type(ions_t), intent(in) :: ions
168 type(states_elec_t), intent(in) :: st
169 type(multicomm_t), intent(in) :: mc
170 type(hamiltonian_elec_t), intent(inout) :: hm
171 class(space_t), intent(in) :: space
172
173 real(real64) :: rmin
174 integer :: mixdefault
175 type(type_t) :: mix_type
176 class(convergence_criterion_t), pointer :: crit
177 type(criterion_iterator_t) :: iter
178 logical :: deactivate_oracle
179
180 push_sub(scf_init)
181
182 !%Variable MaximumIter
183 !%Type integer
184 !%Default 200
185 !%Section SCF::Convergence
186 !%Description
187 !% Maximum number of SCF iterations. The code will stop even if convergence
188 !% has not been achieved. -1 means unlimited.
189 !% 0 means just do LCAO (or read from restart), compute the eigenvalues and energy,
190 !% and stop, without updating the wavefunctions or density.
191 !%
192 !% If convergence criteria are set, the SCF loop will only stop once the criteria
193 !% are fulfilled for two consecutive iterations.
194 !%
195 !% Note that this variable is also used in the section Calculation Modes::Unoccupied States,
196 !% where it denotes the maximum number of calls of the eigensolver. In this context, the
197 !% default value is 50.
198 !%End
199 call parse_variable(namespace, 'MaximumIter', 200, scf%max_iter)
200
201 if (allocated(hm%vberry)) then
202 call berry_init(scf%berry, namespace)
203 end if
204
205 !Create the list of convergence criteria
206 call criteria_factory_init(scf%criterion_list, namespace, scf%check_conv)
207 !Setting the pointers
208 call iter%start(scf%criterion_list)
209 do while (iter%has_next())
210 crit => iter%get_next()
211 select type (crit)
213 call crit%set_pointers(scf%energy_diff, scf%energy_in)
215 call crit%set_pointers(scf%abs_dens_diff, st%qtot)
217 call crit%set_pointers(scf%evsum_diff, scf%evsum_out)
218 class default
219 assert(.false.)
220 end select
221 end do
224 if(.not. scf%check_conv .and. scf%max_iter < 0) then
225 call messages_write("All convergence criteria are disabled. Octopus is cowardly refusing")
227 call messages_write("to enter an infinite loop.")
228 call messages_new_line()
230 call messages_write("Please set one of the following variables to a positive value:")
233 call messages_write(" | MaximumIter | ConvEnergy | ConvAbsDens | ConvRelDens |")
235 call messages_write(" | ConvAbsEv | ConvRelEv |")
237 call messages_fatal(namespace=namespace)
238 end if
240 !%Variable ConvEigenError
241 !%Type logical
242 !%Default false
243 !%Section SCF::Convergence
244 !%Description
245 !% If true, the calculation will not be considered converged unless all states have
246 !% individual errors less than <tt>EigensolverTolerance</tt>.
247 !% If <tt>ExtraStatesToConverge</tt> is set, the calculation will stop
248 !% when all occupied states plus <tt>ExtraStatesToConverge</tt> extra states are converged.
249 !%
250 !% If this criterion is used, the SCF loop will only stop once it is
251 !% fulfilled for two consecutive iterations.
252 !%End
253 call parse_variable(namespace, 'ConvEigenError', .false., scf%conv_eigen_error)
254
255 if(scf%max_iter < 0) scf%max_iter = huge(scf%max_iter)
256
257 call messages_obsolete_variable(namespace, 'What2Mix', 'MixField')
259 ! now the eigensolver stuff
260 deactivate_oracle = hm%theory_level == independent_particles
261 call eigensolver_init(scf%eigens, namespace, gr, st, hm, mc, space, deactivate_oracle)
262
263 if(scf%eigens%es_type /= rs_evo) then
264 !%Variable MixField
265 !%Type integer
266 !%Section SCF::Mixing
267 !%Description
268 !% Selects what should be mixed during the SCF cycle. Note that
269 !% currently the exact-exchange part of hybrid functionals is not
270 !% mixed at all, which would require wavefunction-mixing, not yet
271 !% implemented. This may lead to instabilities in the SCF cycle,
272 !% so starting from a converged LDA/GGA calculation is recommended
273 !% for hybrid functionals. The default depends on the <tt>TheoryLevel</tt>
274 !% and the exchange-correlation potential used.
275 !% This is not used in case of imaginary-time evolution.
276 !%Option none 0
277 !% No mixing is done. This is the default for independent
278 !% particles.
279 !%Option potential 1
280 !% The Kohn-Sham potential is mixed. This is the default for other cases.
281 !%Option density 2
282 !% Mix the density.
283 !%Option states 3
284 !% (Experimental) Mix the states. In this case, the mixing is always linear.
285 !%End
286
287 mixdefault = option__mixfield__potential
288 if(hm%theory_level == independent_particles) mixdefault = option__mixfield__none
289
290 call parse_variable(namespace, 'MixField', mixdefault, scf%mix_field)
291 if(.not.varinfo_valid_option('MixField', scf%mix_field)) call messages_input_error(namespace, 'MixField')
292 call messages_print_var_option('MixField', scf%mix_field, "what to mix during SCF cycles", namespace=namespace)
293
294 if (scf%mix_field == option__mixfield__potential .and. hm%theory_level == independent_particles) then
295 call messages_write('Input: Cannot mix the potential for non-interacting particles.')
296 call messages_fatal(namespace=namespace)
297 end if
298
299 if (scf%mix_field == option__mixfield__potential .and. hm%pcm%run_pcm) then
300 call messages_write('Input: You have selected to mix the potential.', new_line = .true.)
301 call messages_write(' This might produce convergence problems for solvated systems.', new_line = .true.)
302 call messages_write(' Mix the Density instead.')
303 call messages_warning(namespace=namespace)
304 end if
305
306 if(scf%mix_field == option__mixfield__density &
307 .and. bitand(hm%xc%family, xc_family_oep + xc_family_mgga + xc_family_hyb_mgga + xc_family_nc_mgga) /= 0) then
308
309 call messages_write('Input: You have selected to mix the density with OEP or MGGA XC functionals.', new_line = .true.)
310 call messages_write(' This might produce convergence problems. Mix the potential instead.')
311 call messages_warning(namespace=namespace)
312 end if
313
314 if(scf%mix_field == option__mixfield__states) then
315 call messages_experimental('MixField = states', namespace=namespace)
316 end if
317
318 ! Handle mixing now...
319 select case(scf%mix_field)
320 case (option__mixfield__potential, option__mixfield__density)
321 scf%mixdim1 = gr%np
322 case(option__mixfield__states)
323 ! we do not really need the mixer, except for the value of the mixing coefficient
324 scf%mixdim1 = 1
325 end select
326
327 mix_type = type_float
328
329 if (scf%mix_field /= option__mixfield__none) then
330 call mix_init(scf%smix, namespace, space, gr%der, scf%mixdim1, st%d%nspin, func_type_ = mix_type)
331 end if
332
333 ! If we use DFT+U, we also have do mix it
334 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none ) then
335 call lda_u_mixer_init(hm%lda_u, scf%lda_u_mix, st)
336 call lda_u_mixer_init_auxmixer(hm%lda_u, namespace, scf%lda_u_mix, scf%smix, st)
337 end if
338
339 ! If we use tau-dependent MGGA, we need to mix vtau
340 if(scf%mix_field == option__mixfield__potential) then
341 call vtau_mixer_init_auxmixer(namespace, scf%vtau_mix, scf%smix, hm, gr%np, st%d%nspin)
342 end if
343
344 call mix_get_field(scf%smix, scf%mixfield)
345 else
346 scf%mix_field = option__mixfield__none
347 end if
348
349 !%Variable SCFCalculateForces
350 !%Type logical
351 !%Section SCF
352 !%Description
353 !% This variable controls whether the forces on the ions are
354 !% calculated at the end of a self-consistent iteration. The
355 !% default is yes, unless the system only has user-defined
356 !% species.
357 !%End
358 call parse_variable(namespace, 'SCFCalculateForces', .not. ions%only_user_def, scf%calc_force)
359
360 if(scf%calc_force .and. gr%der%boundaries%spiralBC) then
361 message(1) = 'Forces cannot be calculated when using spiral boundary conditions.'
362 write(message(2),'(a)') 'Please use SCFCalculateForces = no.'
363 call messages_fatal(2, namespace=namespace)
364 end if
365 if(scf%calc_force) then
366 if (allocated(hm%ep%b_field) .or. allocated(hm%ep%a_static)) then
367 write(message(1),'(a)') 'The forces are currently not properly calculated if static'
368 write(message(2),'(a)') 'magnetic fields or static vector potentials are present.'
369 write(message(3),'(a)') 'Please use SCFCalculateForces = no.'
370 call messages_fatal(3, namespace=namespace)
371 end if
372 end if
373
374 !%Variable SCFCalculateStress
375 !%Type logical
376 !%Default no
377 !%Section SCF
378 !%Description
379 !% This variable controls whether the stress on the lattice is
380 !% calculated at the end of a self-consistent iteration. The
381 !% default is no.
382 !%End
383 call parse_variable(namespace, 'SCFCalculateStress', .false. , scf%calc_stress)
384
385 !%Variable SCFCalculateDipole
386 !%Type logical
387 !%Section SCF
388 !%Description
389 !% This variable controls whether the dipole is calculated at the
390 !% end of a self-consistent iteration. For finite systems the
391 !% default is yes. For periodic systems the default is no, unless
392 !% an electric field is being applied in a periodic direction.
393 !% The single-point Berry`s phase approximation is used for
394 !% periodic directions. Ref:
395 !% E Yaschenko, L Fu, L Resca, and R Resta, <i>Phys. Rev. B</i> <b>58</b>, 1222-1229 (1998).
396 !%End
397 call parse_variable(namespace, 'SCFCalculateDipole', .not. space%is_periodic(), scf%calc_dipole)
398 if (allocated(hm%vberry)) scf%calc_dipole = .true.
399
400 !%Variable SCFCalculateOrbitalMoments
401 !%Type logical
402 !%Default no
403 !%Section SCF
404 !%Description
405 !% This variable controls whether the local orbital angular moments are
406 !% calculated at the end of a self-consistent iteration. The
407 !% default is no. This is only applicable for spinors with SOC.
408 !%
409 !% This is computed by integrating around atom-centered spheres, and does not include the
410 !% interstitial contribution.
411 !% The same sphere are used as for the spin magnetic moments.
412 !%End
413 call parse_variable(namespace, 'SCFCalculateOrbitalMoments', .false. , scf%calc_orb_moments)
414 if((st%d%ispin /= spinors .or. space%dim /= 3) .and. scf%calc_orb_moments) then
415 message(1) = "Orbital moments are only implemented for spinors and in 3D."
416 call messages_fatal(1, namespace=namespace)
417 end if
418 if (scf%calc_orb_moments .and. .not. (hm%ep%reltype == spin_orbit &
419 .or. hm%ep%reltype == fully_relativistic_zora)) then
420 message(1) = "Orbital moments are only available with SOC."
421 call messages_fatal(1, namespace=namespace)
422 end if
423 if(gr%use_curvilinear .and. scf%calc_orb_moments) then
424 call messages_not_implemented("Orbital angular moments with curvilinear coordinates")
425 end if
426
427 !%Variable SCFCalculatePartialCharges
428 !%Type logical
429 !%Default no
430 !%Section SCF
431 !%Description
432 !% (Experimental) This variable controls whether partial charges
433 !% are calculated at the end of a self-consistent iteration.
434 !%End
435 call parse_variable(namespace, 'SCFCalculatePartialCharges', .false., scf%calc_partial_charges)
436 if (scf%calc_partial_charges) call messages_experimental('SCFCalculatePartialCharges', namespace=namespace)
437
438 rmin = ions%min_distance()
439
440 !%Variable LocalMagneticMomentsSphereRadius
441 !%Type float
442 !%Section Output
443 !%Description
444 !% The local magnetic moments are calculated by integrating the
445 !% magnetization density in spheres centered around each atom.
446 !% This variable controls the radius of the spheres.
447 !% The default is half the minimum distance between two atoms
448 !% in the input coordinates, or 100 a.u. if there is only one atom (for isolated systems).
449 !%End
450 call parse_variable(namespace, 'LocalMagneticMomentsSphereRadius', min(m_half*rmin, lmm_r_single_atom), scf%lmm_r, &
451 unit=units_inp%length)
452 ! this variable is also used in td/td_write.F90
453
454 scf%forced_finish = .false.
455
456 pop_sub(scf_init)
457 end subroutine scf_init
458
459
460 ! ---------------------------------------------------------
461 subroutine scf_end(scf)
462 type(scf_t), intent(inout) :: scf
463
464 class(convergence_criterion_t), pointer :: crit
465 type(criterion_iterator_t) :: iter
466
467 push_sub(scf_end)
468
469 call eigensolver_end(scf%eigens)
470
471 if(scf%mix_field /= option__mixfield__none) call mix_end(scf%smix)
472
473 nullify(scf%mixfield)
474
475 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none) then
476 call lda_u_mixer_end(scf%lda_u_mix, scf%smix)
477 call vtau_mixer_end(scf%vtau_mix, scf%smix)
478 end if
479
480 call iter%start(scf%criterion_list)
481 do while (iter%has_next())
482 crit => iter%get_next()
483 safe_deallocate_p(crit)
484 end do
485
486 pop_sub(scf_end)
487 end subroutine scf_end
488
489
490 ! ---------------------------------------------------------
491 subroutine scf_mix_clear(scf)
492 type(scf_t), intent(inout) :: scf
493
494 push_sub(scf_mix_clear)
495
496 call mix_clear(scf%smix)
497
498 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none) then
499 call lda_u_mixer_clear(scf%lda_u_mix, scf%smix)
500 call vtau_mixer_clear(scf%vtau_mix, scf%smix)
501 end if
502
503 pop_sub(scf_mix_clear)
504 end subroutine scf_mix_clear
505
506 ! ---------------------------------------------------------
508 subroutine scf_load(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, restart_load)
509 type(scf_t), intent(inout) :: scf
510 type(namespace_t), intent(in) :: namespace
511 type(electron_space_t), intent(in) :: space
512 type(grid_t), intent(inout) :: gr
513 type(ions_t), intent(in) :: ions
514 type(partner_list_t), intent(in) :: ext_partners
515 type(states_elec_t), intent(inout) :: st
516 type(v_ks_t), intent(inout) :: ks
517 type(hamiltonian_elec_t), intent(inout) :: hm
518 type(restart_t), intent(in) :: restart_load
519
520 integer :: ierr, is, ip
521
522 push_sub(scf_load)
523
524 if (restart_load%has_flag(restart_flag_rho)) then
525 ! Load density and used it to recalculated the KS potential.
526 call states_elec_load_rho(restart_load, st, gr, ierr)
527 if (ierr /= 0) then
528 message(1) = 'Unable to read density. Density will be calculated from states.'
529 call messages_warning(1, namespace=namespace)
530 else
531 if (bitand(ks%xc_family, xc_family_oep) == 0) then
532 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
533 else
534 if (.not. restart_load%has_flag(restart_flag_vhxc) .and. ks%oep%level /= oep_level_full) then
535 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
536 end if
537 end if
538 end if
539 end if
540
541 if (restart_load%has_flag(restart_flag_vhxc)) then
542 call hm%ks_pot%load(restart_load, gr, ierr)
543 if (ierr /= 0) then
544 message(1) = 'Unable to read Vhxc. Vhxc will be calculated from states.'
545 call messages_warning(1, namespace=namespace)
546 else
547 call hm%update(gr, namespace, space, ext_partners)
548 if (bitand(ks%xc_family, xc_family_oep) /= 0) then
549 if (ks%oep%level == oep_level_full) then
550 !$omp parallel private(is, ip)
551 do is = 1, st%d%nspin
552 !$omp do
553 do ip = 1, gr%np
554 ks%oep%vxc(ip, is) = hm%ks_pot%vhxc(ip, is) - hm%ks_pot%vhartree(ip)
555 end do
556 end do
557 !$omp end parallel
558 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
559 end if
560 end if
561 end if
562 end if
563
564 if (restart_load%has_flag(restart_flag_mix)) then
565 if (scf%mix_field == option__mixfield__density .or. scf%mix_field == option__mixfield__potential) then
566 call mix_load(namespace, restart_load, scf%smix, gr, ierr)
567 if (ierr /= 0) then
568 message(1) = "Unable to read mixing information. Mixing will start from scratch."
569 call messages_warning(1, namespace=namespace)
570 end if
571 end if
572 end if
573
574 if(hm%lda_u_level /= dft_u_none) then
575 call lda_u_load(restart_load, hm%lda_u, st, hm%energy%dft_u, ierr)
576 if (ierr /= 0) then
577 message(1) = "Unable to read DFT+U information. DFT+U data will be calculated from states."
578 call messages_warning(1, namespace=namespace)
579 end if
580
581 ! As v_ks_calc has already been called, we need to update hm%energy%int_dft_u
582 call v_ks_update_dftu_energy(ks, namespace, hm, st, hm%energy%int_dft_u)
583 end if
584
585 !TODO: Create a dedicated routine and call it from the initialize
587! if (present(outp) .and. st%system_grp%is_root()) then
588! call io_rm(STATIC_DIR //"info")
589! end if
590! end if
591
592 pop_sub(scf_load)
593 end subroutine scf_load
594
595 ! ---------------------------------------------------------
597 subroutine scf_start(scf, namespace, gr, ions, st, ks, hm, outp, verbosity)
598 type(scf_t), intent(inout) :: scf
599 type(namespace_t), intent(in) :: namespace
600 type(grid_t), intent(inout) :: gr
601 type(ions_t), intent(inout) :: ions
602 type(states_elec_t), intent(inout) :: st
603 type(v_ks_t), intent(inout) :: ks
604 type(hamiltonian_elec_t), intent(inout) :: hm
605 type(output_t), optional, intent(in) :: outp
606 integer, optional, intent(in) :: verbosity
607
608 integer :: ib, iqn
609
610 push_sub(scf_start)
611
612 if(scf%forced_finish) then
613 message(1) = "Previous clean stop, not doing SCF and quitting."
614 call messages_fatal(1, only_root_writes = .true., namespace=namespace)
615 end if
616
617 if (.not. hm%is_hermitian()) then
618 message(1) = "Trying to run a SCF calculation for a non-hermitian Hamiltonian. This is not supported."
619 call messages_fatal(1, namespace=namespace)
620 end if
621
622 scf%verbosity_ = optional_default(verbosity, verb_full)
623
624 scf%output_during_scf = .false.
625 scf%output_forces = .false.
626 scf%calc_current = .false.
627
628 if (present(outp)) then
629 ! if the user has activated output=stress but not SCFCalculateStress,
630 ! we assume that is implied
631 if (outp%what(option__output__stress)) then
632 scf%calc_stress = .true.
633 end if
634
635 scf%output_during_scf = outp%duringscf
636 scf%calc_current = output_needs_current(outp, states_are_real(st))
637
638 if (outp%duringscf .and. outp%what(option__output__forces)) then
639 scf%output_forces = .true.
640 end if
641 end if
642
643 safe_allocate(scf%rhoout(1:gr%np, 1:st%d%nspin))
644 safe_allocate(scf%rhoin (1:gr%np, 1:st%d%nspin))
645
646 call lalg_copy(gr%np, st%d%nspin, st%rho, scf%rhoin)
647 scf%rhoout = m_zero
648
649 if (scf%calc_force .or. scf%output_forces) then
650 !We store the Hxc potential for the contribution to the forces
651 safe_allocate(scf%vhxc_old(1:gr%np, 1:st%d%nspin))
652 call lalg_copy(gr%np, st%d%nspin, hm%ks_pot%vhxc, scf%vhxc_old)
653 end if
654
655
656 select case(scf%mix_field)
657 case(option__mixfield__potential)
658 call mixfield_set_vin(scf%mixfield, hm%ks_pot%vhxc)
659 call vtau_mixer_set_vin(scf%vtau_mix, hm)
660 case(option__mixfield__density)
661 call mixfield_set_vin(scf%mixfield, scf%rhoin)
662
663 case(option__mixfield__states)
664
665 ! There is a ICE with foss2022a-serial. I am changing to allocate - NTD
666 allocate(wfs_elec_t::scf%psioutb (st%group%block_start:st%group%block_end, st%d%kpt%start:st%d%kpt%end))
667
668 do iqn = st%d%kpt%start, st%d%kpt%end
669 do ib = st%group%block_start, st%group%block_end
670 call st%group%psib(ib, iqn)%copy_to(scf%psioutb(ib, iqn))
671 end do
672 end do
673
674 end select
675
676 call lda_u_update_occ_matrices(hm%lda_u, namespace, gr, st, hm%phase, hm%energy)
677 ! If we use DFT+U, we also have do mix it
678 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none) then
679 call lda_u_mixer_set_vin(hm%lda_u, scf%lda_u_mix)
680 end if
681
682 call create_convergence_file(static_dir, "convergence")
683
684 if ( scf%verbosity_ /= verb_no ) then
685 if(scf%max_iter > 0) then
686 write(message(1),'(a)') 'Info: Starting SCF iteration.'
687 else
688 write(message(1),'(a)') 'Info: No SCF iterations will be done.'
689 ! we cannot tell whether it is converged.
690 scf%finish = .false.
691 end if
692 call messages_info(1, namespace=namespace)
693 end if
694
695 scf%converged_current = .false.
696 scf%matvec = 0
697
698 pop_sub(scf_start)
699
700 contains
701
702 ! -----------------------------------------------------
703
704 subroutine create_convergence_file(dir, fname)
705 character(len=*), intent(in) :: dir
706 character(len=*), intent(in) :: fname
707
708 integer :: iunit
709 character(len=12) :: label
710 if(st%system_grp%is_root()) then
711 call io_mkdir(dir, namespace)
712 iunit = io_open(trim(dir) // "/" // trim(fname), namespace, action='write')
713 write(iunit, '(a)', advance = 'no') '#iter energy '
714 label = 'energy_diff'
715 write(iunit, '(1x,a)', advance = 'no') label
716 label = 'abs_dens'
717 write(iunit, '(1x,a)', advance = 'no') label
718 label = 'rel_dens'
719 write(iunit, '(1x,a)', advance = 'no') label
720 label = 'abs_ev'
721 write(iunit, '(1x,a)', advance = 'no') label
722 label = 'rel_ev'
723 write(iunit, '(1x,a)', advance = 'no') label
724 if (bitand(ks%xc_family, xc_family_oep) /= 0 .and. ks%theory_level /= hartree_fock &
725 .and. ks%theory_level /= generalized_kohn_sham_dft) then
726 if (ks%oep%level == oep_level_full) then
727 label = 'OEP norm2ss'
728 write(iunit, '(1x,a)', advance = 'no') label
729 end if
730 end if
731 write(iunit,'(a)') ''
732 call io_close(iunit)
733 end if
734
735 end subroutine create_convergence_file
736
737 end subroutine scf_start
738
739 ! ---------------------------------------------------------
741 subroutine scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, &
742 verbosity, iters_done, restart_dump)
743 type(scf_t), intent(inout) :: scf
744 type(namespace_t), intent(in) :: namespace
745 type(electron_space_t), intent(in) :: space
746 type(multicomm_t), intent(in) :: mc
747 type(grid_t), intent(inout) :: gr
748 type(ions_t), intent(inout) :: ions
749 type(partner_list_t), intent(in) :: ext_partners
750 type(states_elec_t), intent(inout) :: st
751 type(v_ks_t), intent(inout) :: ks
752 type(hamiltonian_elec_t), intent(inout) :: hm
753 type(output_t), optional, intent(in) :: outp
754 integer, optional, intent(in) :: verbosity
755 integer, optional, intent(out) :: iters_done
756 type(restart_t), optional, intent(in) :: restart_dump
757
758 integer :: iter
759 logical :: completed
760
761 push_sub(scf_run)
762
763 call scf_start(scf, namespace, gr, ions, st, ks, hm, outp, verbosity)
764
765 ! SCF cycle
766 do iter = 1, scf%max_iter
767
768 call scf_iter(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, iter, outp, &
769 restart_dump)
770
771 completed = scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, iters_done)
772
773 if(scf%forced_finish .or. completed) then
774 exit
775 end if
776 end do
777
778 if (.not.scf%forced_finish) then
779 ! this is only executed if the computation has converged
780 call scf_finish(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, iter, outp)
781 end if
782
783 pop_sub(scf_run)
784 end subroutine scf_run
785
786 ! ---------------------------------------------------------
787 subroutine scf_iter(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, iter, outp, &
788 restart_dump)
789 type(scf_t), intent(inout) :: scf
790 type(namespace_t), intent(in) :: namespace
791 type(electron_space_t), intent(in) :: space
792 type(multicomm_t), intent(in) :: mc
793 type(grid_t), intent(inout) :: gr
794 type(ions_t), intent(inout) :: ions
795 type(partner_list_t), intent(in) :: ext_partners
796 type(states_elec_t), intent(inout) :: st
797 type(v_ks_t), intent(inout) :: ks
798 type(hamiltonian_elec_t), intent(inout) :: hm
799 integer, intent(in) :: iter
800 type(output_t), optional, intent(in) :: outp
801 type(restart_t), optional, intent(in) :: restart_dump
802
803 integer :: iqn, ib, ierr
804 class(convergence_criterion_t), pointer :: crit
805 type(criterion_iterator_t) :: iterator
806 logical :: is_crit_conv
807 real(real64) :: etime, itime
808
809 push_sub(scf_iter)
810
811 call profiling_in("SCF_CYCLE")
812 itime = loct_clock()
813
814 ! this initialization seems redundant but avoids improper optimization at -O3 by PGI 7 on chum,
815 ! which would cause a failure of testsuite/linear_response/04-vib_modes.03-vib_modes_fd.inp
816 scf%eigens%converged = 0
817
818 ! keep the information about the spectrum up to date, needed e.g. for Chebyshev expansion for imaginary time
819 call hm%update_span(gr%spacing(1:space%dim), minval(st%eigenval(:, :)), namespace)
820
821 !We update the quantities at the begining of the scf cycle
822 if (iter == 1) then
823 scf%evsum_in = states_elec_eigenvalues_sum(st)
824 end if
825 call iterator%start(scf%criterion_list)
826 do while (iterator%has_next())
827 crit => iterator%get_next()
828 call scf_update_initial_quantity(scf, hm, crit)
829 end do
830
831 if (scf%calc_force .or. scf%output_forces) then
832 !Used for computing the imperfect convegence contribution to the forces
833 scf%vhxc_old(1:gr%np, 1:st%d%nspin) = hm%ks_pot%vhxc(1:gr%np, 1:st%d%nspin)
834 end if
835
836 !We check if the system is coupled with a partner that requires self-consistency
837 ! if(hamiltonian_has_scf_partner(hm)) then
838 if (allocated(hm%vberry)) then
839 !In this case, v_Hxc is frozen and we do an internal SCF loop over the
840 ! partners that require SCF
841 ks%frozen_hxc = .true.
842 ! call perform_scf_partners()
843 call berry_perform_internal_scf(scf%berry, namespace, space, scf%eigens, gr, st, hm, iter, ks, ions, ext_partners)
844 !and we unfreeze the potential once finished
845 ks%frozen_hxc = .false.
846 else
847 scf%eigens%converged = 0
848 call scf%eigens%run(namespace, gr, st, hm, space, ext_partners, iter)
849 end if
850
851 scf%matvec = scf%matvec + scf%eigens%matvec
852
853 ! occupations
854 call states_elec_fermi(st, namespace, gr)
855 call lda_u_update_occ_matrices(hm%lda_u, namespace, gr, st, hm%phase, hm%energy)
856
857 ! compute output density, potential (if needed) and eigenvalues sum
858 call density_calc(st, gr, st%rho)
859
860 call lalg_copy(gr%np, st%d%nspin, st%rho, scf%rhoout)
861
862 select case (scf%mix_field)
863 case (option__mixfield__potential)
864 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
865 call mixfield_set_vout(scf%mixfield, hm%ks_pot%vhxc)
866 call vtau_mixer_set_vout(scf%vtau_mix, hm)
867 case (option__mixfield__density)
868 call mixfield_set_vout(scf%mixfield, scf%rhoout)
869 case(option__mixfield__states)
870 do iqn = st%d%kpt%start, st%d%kpt%end
871 do ib = st%group%block_start, st%group%block_end
872 call st%group%psib(ib, iqn)%copy_data_to(gr%np, scf%psioutb(ib, iqn))
873 end do
874 end do
875 end select
876
877 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none) then
878 call lda_u_mixer_set_vout(hm%lda_u, scf%lda_u_mix)
879 endif
880
881 ! recalculate total energy
882 call energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit = -1)
883
884 if (present(outp)) then
885 ! compute forces only if requested
886 if (outp%duringscf .and. outp%what_now(option__output__forces, iter)) then
887 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old=scf%vhxc_old)
888 end if
889 end if
890
891 !We update the quantities at the end of the scf cycle
892 call iterator%start(scf%criterion_list)
893 do while (iterator%has_next())
894 crit => iterator%get_next()
895 call scf_update_diff_quantity(scf, hm, st, gr, scf%rhoout, scf%rhoin, crit)
896 end do
897
898 ! are we finished?
899 scf%converged_last = scf%converged_current
900
901 scf%converged_current = scf%check_conv .and. &
902 (.not. scf%conv_eigen_error .or. all(scf%eigens%converged >= st%nst_conv))
903 !Loop over the different criteria
904 call iterator%start(scf%criterion_list)
905 do while (iterator%has_next())
906 crit => iterator%get_next()
907 call crit%is_converged(is_crit_conv)
908 scf%converged_current = scf%converged_current .and. is_crit_conv
909 end do
910
911 ! only finish if the convergence criteria are fulfilled in two
912 ! consecutive iterations
913 scf%finish = scf%converged_last .and. scf%converged_current
914
915 etime = loct_clock() - itime
916 call scf_write_iter(namespace)
917
918 ! mixing
919 select case (scf%mix_field)
920 case (option__mixfield__density)
921 ! mix input and output densities and compute new potential
922 call mixing(namespace, scf%smix)
923 call mixfield_get_vnew(scf%mixfield, st%rho)
924 ! Mixing updated st%rho on the host only; refresh the GPU density buffer so
925 ! the GPU XC path does not evaluate vxc from the unmixed density.
927 ! for spinors, having components 3 or 4 be negative is not unphysical
928 if (minval(st%rho(1:gr%np, 1:st%d%spin_channels)) < -1e-6_real64) then
929 write(message(1),*) 'Negative density after mixing. Minimum value = ', &
930 minval(st%rho(1:gr%np, 1:st%d%spin_channels))
931 call messages_warning(1, namespace=namespace)
932 end if
933 call lda_u_mixer_get_vnew(hm%lda_u, scf%lda_u_mix, st)
934 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
935
936 case (option__mixfield__potential)
937 ! mix input and output potentials
938 call mixing(namespace, scf%smix)
939 call mixfield_get_vnew(scf%mixfield, hm%ks_pot%vhxc)
940 call lda_u_mixer_get_vnew(hm%lda_u, scf%lda_u_mix, st)
941 call vtau_mixer_get_vnew(scf%vtau_mix, hm)
942 call hamiltonian_elec_update_pot(hm, gr)
943
944 case(option__mixfield__states)
945 do iqn = st%d%kpt%start, st%d%kpt%end
946 do ib = st%group%block_start, st%group%block_end
947 call batch_axpby(gr%np, mix_coefficient(scf%smix), scf%psioutb(ib, iqn), &
948 m_one - mix_coefficient(scf%smix), st%group%psib(ib, iqn))
949 end do
950 end do
951 call density_calc(st, gr, st%rho)
952 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
953
954 case (option__mixfield__none)
955 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
956 end select
957
958 ! Are we asked to stop? (Whenever Fortran is ready for signals, this should go away)
959 scf%forced_finish = clean_stop(mc%master_comm) .or. walltimer_alarm(mc%master_comm)
960
961 if (scf%finish .and. st%modelmbparticles%nparticle > 0) then
962 call modelmb_sym_all_states(space, gr, st)
963 end if
964
965 if (present(outp) .and. present(restart_dump)) then
966 ! save restart information
967
968 if ( (scf%finish .or. restart_walltime_period_alarm(mc%master_comm) &
969 .or. iter == scf%max_iter .or. scf%forced_finish) ) then
970
971 call states_elec_dump(restart_dump, space, st, gr, hm%kpoints, ierr, iter=iter)
972 if (ierr /= 0) then
973 message(1) = 'Unable to write states wavefunctions.'
974 call messages_warning(1, namespace=namespace)
975 end if
976
977 call states_elec_dump_rho(restart_dump, st, gr, ierr, iter=iter)
978 if (ierr /= 0) then
979 message(1) = 'Unable to write density.'
980 call messages_warning(1, namespace=namespace)
981 end if
982
983 if(hm%lda_u_level /= dft_u_none) then
984 call lda_u_dump(restart_dump, namespace, hm%lda_u, st, gr, ierr)
985 if (ierr /= 0) then
986 message(1) = 'Unable to write DFT+U information.'
987 call messages_warning(1, namespace=namespace)
988 end if
989 end if
990
991 select case (scf%mix_field)
992 case (option__mixfield__density)
993 call mix_dump(namespace, restart_dump, scf%smix, gr, ierr)
994 if (ierr /= 0) then
995 message(1) = 'Unable to write mixing information.'
996 call messages_warning(1, namespace=namespace)
997 end if
998 case (option__mixfield__potential)
999 call hm%ks_pot%dump(restart_dump, gr, ierr)
1000 if (ierr /= 0) then
1001 message(1) = 'Unable to write Vhxc.'
1002 call messages_warning(1, namespace=namespace)
1003 end if
1004
1005 call mix_dump(namespace, restart_dump, scf%smix, gr, ierr)
1006 if (ierr /= 0) then
1007 message(1) = 'Unable to write mixing information.'
1008 call messages_warning(1, namespace=namespace)
1009 end if
1010 end select
1011
1012 end if
1013 end if
1014
1015 call write_convergence_file(static_dir, "convergence")
1016
1017 call profiling_out("SCF_CYCLE")
1018
1019 pop_sub(scf_iter)
1020 contains
1021
1022 ! ---------------------------------------------------------
1023 subroutine scf_write_iter(namespace)
1024 type(namespace_t), intent(in) :: namespace
1025
1026 character(len=50) :: str
1027 real(real64) :: dipole(1:space%dim)
1028
1029 push_sub(scf_run.scf_write_iter)
1030
1031 if ( scf%verbosity_ == verb_full ) then
1032
1033 write(str, '(a,i5)') 'SCF CYCLE ITER #' ,iter
1034 call messages_print_with_emphasis(msg=trim(str), namespace=namespace)
1035 write(message(1),'(a,es15.8,2(a,es9.2))') ' etot = ', units_from_atomic(units_out%energy, hm%energy%total), &
1036 ' abs_ev = ', units_from_atomic(units_out%energy, scf%evsum_diff), &
1037 ' rel_ev = ', scf%evsum_diff/(abs(scf%evsum_out)+1e-20)
1038 write(message(2),'(a,es15.2,2(a,es9.2))') &
1039 ' ediff = ', scf%energy_diff, ' abs_dens = ', scf%abs_dens_diff, &
1040 ' rel_dens = ', scf%abs_dens_diff/st%qtot
1041 call messages_info(2, namespace=namespace)
1042
1043 write(message(1),'(a,i0)') 'Matrix vector products: ', scf%eigens%matvec
1044 write(message(2),'(a,i0)') 'Converged eigenvectors: ', sum(scf%eigens%converged(1:st%nik))
1045 call messages_info(2, namespace=namespace)
1046 call states_elec_write_eigenvalues(st%nst, st, space, hm%kpoints, scf%eigens%diff, compact = .true., namespace=namespace)
1047
1048 if (allocated(hm%vberry)) then
1049 call calc_dipole(dipole, space, gr, st, ions)
1050 call write_dipole(st, hm, space, dipole, namespace=namespace)
1051 end if
1052
1053 if(st%d%ispin > unpolarized) then
1054 call compute_and_write_magnetic_moments(gr, st, hm%phase, hm%ep, ions, scf%lmm_r, namespace=namespace)
1055 end if
1056
1057 if(hm%lda_u_level == dft_u_acbn0) then
1058 call lda_u_write_u(hm%lda_u, namespace=namespace)
1059 call lda_u_write_v(hm%lda_u, namespace=namespace)
1060 end if
1061
1062 write(message(1),'(a)') ''
1063 write(message(2),'(a,i5,a,f14.2)') 'Elapsed time for SCF step ', iter,':', etime
1064 call messages_info(2, namespace=namespace)
1065
1066 call scf_print_mem_use(namespace)
1067
1068 call messages_print_with_emphasis(namespace=namespace)
1069
1070 end if
1071
1072 if ( scf%verbosity_ == verb_compact ) then
1073 write(message(1),'(a,i4,a,es15.8, a,es9.2, a, f7.1, a)') &
1074 'iter ', iter, &
1075 ' : etot ', units_from_atomic(units_out%energy, hm%energy%total), &
1076 ' : abs_dens', scf%abs_dens_diff, &
1077 ' : etime ', etime, 's'
1078 call messages_info(1, namespace=namespace)
1079 end if
1080
1081 pop_sub(scf_run.scf_write_iter)
1082 end subroutine scf_write_iter
1083
1084
1085 ! -----------------------------------------------------
1086 subroutine write_convergence_file(dir, fname)
1087 character(len=*), intent(in) :: dir
1088 character(len=*), intent(in) :: fname
1089
1090 integer :: iunit
1091
1092 if(st%system_grp%is_root()) then ! this the absolute master writes
1093 call io_mkdir(dir, namespace)
1094 iunit = io_open(trim(dir) // "/" // trim(fname), namespace, action='write', position='append')
1095 write(iunit, '(i5,es18.8)', advance = 'no') iter, units_from_atomic(units_out%energy, hm%energy%total)
1096 call iterator%start(scf%criterion_list)
1097 do while (iterator%has_next())
1098 crit => iterator%get_next()
1099 select type (crit)
1100 type is (energy_criterion_t)
1101 write(iunit, '(es13.5)', advance = 'no') units_from_atomic(units_out%energy, crit%val_abs)
1102 type is (density_criterion_t)
1103 write(iunit, '(2es13.5)', advance = 'no') crit%val_abs, crit%val_rel
1104 type is (eigenval_criterion_t)
1105 write(iunit, '(es13.5)', advance = 'no') units_from_atomic(units_out%energy, crit%val_abs)
1106 write(iunit, '(es13.5)', advance = 'no') crit%val_rel
1107 class default
1108 assert(.false.)
1109 end select
1110 end do
1111 if (bitand(ks%xc_family, xc_family_oep) /= 0 .and. ks%theory_level /= hartree_fock &
1112 .and. ks%theory_level /= generalized_kohn_sham_dft) then
1113 if (ks%oep%level == oep_level_full) then
1114 write(iunit, '(es13.5)', advance = 'no') ks%oep%norm2ss
1115 end if
1116 end if
1117 write(iunit,'(a)') ''
1118 call io_close(iunit)
1119 end if
1120 end subroutine write_convergence_file
1121
1122 end subroutine scf_iter
1123
1124 logical function scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, &
1125 iters_done) result(completed)
1126 type(scf_t), intent(inout) :: scf
1127 type(namespace_t), intent(in) :: namespace
1128 type(electron_space_t), intent(in) :: space
1129 type(grid_t), intent(inout) :: gr
1130 type(ions_t), intent(inout) :: ions
1131 type(states_elec_t), intent(inout) :: st
1132 type(v_ks_t), intent(inout) :: ks
1133 type(hamiltonian_elec_t), intent(inout) :: hm
1134 integer, intent(in) :: iter
1135 type(output_t), optional, intent(in) :: outp
1136 integer, optional, intent(out) :: iters_done
1137
1138 character(len=MAX_PATH_LEN) :: dirname
1139 integer(int64) :: what_i
1140
1141 push_sub(scf_iter_finish)
1142
1143 completed = .false.
1144
1145 if(scf%finish) then
1146 if(present(iters_done)) iters_done = iter
1147 if(scf%verbosity_ >= verb_compact) then
1148 write(message(1), '(a, i4, a)') 'Info: SCF converged in ', iter, ' iterations'
1149 write(message(2), '(a)') ''
1150 call messages_info(2, namespace=namespace)
1151 end if
1152 completed = .true.
1153 pop_sub(scf_iter_finish)
1154 return
1155 end if
1156 if (present(outp)) then
1157 if (any(outp%what) .and. outp%duringscf) then
1158 do what_i = lbound(outp%what, 1), ubound(outp%what, 1)
1159 if (outp%what_now(what_i, iter)) then
1160 write(dirname,'(a,a,i4.4)') trim(outp%iter_dir),"scf.", iter
1161 call output_all(outp, namespace, space, dirname, gr, ions, iter, st, hm, ks)
1162 call output_modelmb(outp, namespace, space, dirname, gr, ions, iter, st)
1163 exit
1164 end if
1165 end do
1166 end if
1167 end if
1168
1169 ! save information for the next iteration
1170 call lalg_copy(gr%np, st%d%nspin, st%rho, scf%rhoin)
1171
1172 ! restart mixing
1173 if (scf%mix_field /= option__mixfield__none) then
1174 if (scf%smix%ns_restart > 0) then
1175 if (mix_scheme(scf%smix) /= option__mixingscheme__broyden_adaptive .and. &
1176 mod(iter, scf%smix%ns_restart) == 0) then
1177 message(1) = "Info: restarting mixing."
1178 call messages_info(1, namespace=namespace)
1179 call scf_mix_clear(scf)
1180 end if
1181 end if
1182 end if
1183
1184 select case(scf%mix_field)
1185 case(option__mixfield__potential)
1186 call mixfield_set_vin(scf%mixfield, hm%ks_pot%vhxc(1:gr%np, 1:st%d%nspin))
1187 call vtau_mixer_set_vin(scf%vtau_mix, hm)
1188 case (option__mixfield__density)
1189 call mixfield_set_vin(scf%mixfield, scf%rhoin)
1190 end select
1191
1192 !If we use LDA+U, we also have do mix it
1193 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none) then
1194 call lda_u_mixer_set_vin(hm%lda_u, scf%lda_u_mix)
1195 end if
1196
1197 ! check if debug mode should be enabled or disabled on the fly
1198 call io_debug_on_the_fly(namespace)
1199
1200 pop_sub(scf_iter_finish)
1201 end function scf_iter_finish
1202
1203 ! ---------------------------------------------------------
1204 subroutine scf_finish(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, iter, outp)
1205 type(scf_t), intent(inout) :: scf
1206 type(namespace_t), intent(in) :: namespace
1207 type(electron_space_t), intent(in) :: space
1208 type(grid_t), intent(inout) :: gr
1209 type(ions_t), intent(inout) :: ions
1210 type(partner_list_t), intent(in) :: ext_partners
1211 type(states_elec_t), intent(inout) :: st
1212 type(v_ks_t), intent(inout) :: ks
1213 type(hamiltonian_elec_t), intent(inout) :: hm
1214 integer, intent(in) :: iter
1215 type(output_t), optional, intent(in) :: outp
1216
1217 integer :: iqn, ib
1218 class(convergence_criterion_t), pointer :: crit
1219 type(criterion_iterator_t) :: iterator
1220
1221
1222 push_sub(scf_finish)
1223
1224 ! Compute the KS potential corresponding to the final density
1225 ! This is critical for getting consistent TD calculations
1226 if ((scf%max_iter > 0 .and. scf%mix_field == option__mixfield__potential) .or. scf%calc_current) then
1227 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
1228 calc_current=scf%calc_current)
1229 end if
1230
1231 select case(scf%mix_field)
1232 case(option__mixfield__states)
1233
1234 do iqn = st%d%kpt%start, st%d%kpt%end
1235 do ib = st%group%block_start, st%group%block_end
1236 call scf%psioutb(ib, iqn)%end()
1237 end do
1238 end do
1239
1240 ! There is a ICE with foss2022a-serial. I am changing to deallocate - NTD
1241 deallocate(scf%psioutb)
1242 end select
1243
1244 safe_deallocate_a(scf%rhoout)
1245 safe_deallocate_a(scf%rhoin)
1246
1247 if (scf%max_iter > 0 .and. any(scf%eigens%converged < st%nst)) then
1248 write(message(1),'(a)') 'Some of the states are not fully converged!'
1249 if (all(scf%eigens%converged >= st%nst_conv)) then
1250 write(message(2),'(a)') 'But all requested states to converge are converged.'
1251 call messages_info(2, namespace=namespace)
1252 else
1253 if(scf%eigens%es_type == rs_chebyshev) then
1254 write(message(2),'(a)') 'With the Chebyshev filtering eigensolver, it usually helps to'
1255 write(message(3),'(a)') 'increase ExtraStates and set ExtraStatesToConverge to the number'
1256 write(message(4),'(a)') 'of states to be converged.'
1257 call messages_warning(4, namespace=namespace)
1258 else
1259 call messages_warning(1, namespace=namespace)
1260 end if
1261 end if
1262 end if
1263
1264 if (.not.scf%finish) then
1265 write(message(1), '(a,i4,a)') 'SCF *not* converged after ', iter - 1, ' iterations.'
1266 if(scf%eigens%es_type == rs_chebyshev) then
1267 write(message(2),'(a)') 'With the Chebyshev filtering eigensolver, it usually helps to'
1268 write(message(3),'(a)') 'increase ExtraStates to improve convergence.'
1269 call messages_warning(3, namespace=namespace)
1270 else
1271 call messages_warning(1, namespace=namespace)
1272 end if
1273 end if
1274
1275 write(message(1), '(a,i10)') 'Info: Number of matrix-vector products: ', scf%matvec
1276 call messages_info(1)
1277
1278 if (scf%calc_force) then
1279 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old=scf%vhxc_old)
1280 end if
1281
1282 if (scf%calc_stress) call stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
1283
1284 ! Update the eigenvalues, to match the KS potential that just got recomputed
1285 if (scf%mix_field == option__mixfield__potential) then
1286 call energy_calc_eigenvalues(namespace, hm, gr%der, st)
1287 call states_elec_fermi(st, namespace, gr)
1288 end if
1289
1290 if(present(outp)) then
1291 ! output final information
1292 call scf_write_static(static_dir, "info")
1293 call output_all(outp, namespace, space, static_dir, gr, ions, -1, st, hm, ks)
1294 call output_modelmb(outp, namespace, space, static_dir, gr, ions, -1, st)
1295 end if
1296
1297 if (space%is_periodic() .and. st%nik > st%d%nspin) then
1298 if (bitand(hm%kpoints%method, kpoints_path) /= 0) then
1299 call states_elec_write_bandstructure(static_dir, namespace, st%nst, st, &
1300 ions, gr, hm%kpoints, hm%phase, vec_pot = hm%hm_base%uniform_vector_potential, &
1301 vec_pot_var = hm%hm_base%vector_potential)
1302 end if
1303 end if
1304
1305 if (ks%vdw%vdw_correction == option__vdwcorrection__vdw_ts) then
1306 call vdw_ts_write_c6ab(ks%vdw%vdw_ts, ions, static_dir, 'c6ab_eff', namespace)
1307 end if
1308
1309 safe_deallocate_a(scf%vhxc_old)
1310
1311 pop_sub(scf_finish)
1312
1313 contains
1314
1315 ! ---------------------------------------------------------
1316 subroutine scf_write_static(dir, fname)
1317 character(len=*), intent(in) :: dir, fname
1318
1319 integer :: iunit
1320 real(real64) :: dipole(1:space%dim)
1321 real(real64) :: ex_virial
1322
1323 push_sub(scf_run.scf_write_static)
1324
1325 if(st%system_grp%is_root()) then ! this the absolute master writes
1326 call io_mkdir(dir, namespace)
1327 iunit = io_open(trim(dir) // "/" // trim(fname), namespace, action='write')
1328
1329 call grid_write_info(gr, iunit=iunit)
1330
1331 call symmetries_write_info(gr%symm, space, iunit=iunit)
1332
1333 if (space%is_periodic()) then
1334 call hm%kpoints%write_info(iunit=iunit)
1335 write(iunit,'(1x)')
1336 end if
1337
1338 call v_ks_write_info(ks, iunit=iunit)
1339
1340 ! scf information
1341 if(scf%finish) then
1342 write(iunit, '(a, i4, a)')'SCF converged in ', iter, ' iterations'
1343 else
1344 write(iunit, '(a)') 'SCF *not* converged!'
1345 end if
1346 write(iunit, '(1x)')
1347
1348 if(any(scf%eigens%converged < st%nst)) then
1349 write(iunit,'(a)') 'Some of the states are not fully converged!'
1350 if (all(scf%eigens%converged >= st%nst_conv)) then
1351 write(iunit,'(a)') 'But all requested states to converge are converged.'
1352 end if
1353 end if
1354
1355 call states_elec_write_eigenvalues(st%nst, st, space, hm%kpoints, iunit=iunit)
1356 write(iunit, '(1x)')
1357
1358 if (space%is_periodic()) then
1359 call states_elec_write_gaps(iunit, st, space)
1360 write(iunit, '(1x)')
1361 end if
1362
1363 write(iunit, '(3a)') 'Energy [', trim(units_abbrev(units_out%energy)), ']:'
1364 else
1365 iunit = -1
1366 end if
1367
1368 call energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full = .true.)
1369
1370 if(st%system_grp%is_root()) write(iunit, '(1x)')
1371 if(st%d%ispin > unpolarized) then
1372 call compute_and_write_magnetic_moments(gr, st, hm%phase, hm%ep, ions, scf%lmm_r, iunit=iunit, &
1373 calc_orb_moments=scf%calc_orb_moments)
1374 if (st%system_grp%is_root()) write(iunit, '(1x)')
1375 end if
1376
1377 if(st%d%ispin == spinors .and. space%dim == 3 .and. &
1378 (ks%theory_level == kohn_sham_dft .or. ks%theory_level == generalized_kohn_sham_dft) ) then
1379 call write_total_xc_torque(iunit, gr, hm%ks_pot%vxc, st)
1380 if(st%system_grp%is_root()) write(iunit, '(1x)')
1381 end if
1382
1383 if(hm%lda_u_level == dft_u_acbn0) then
1384 call lda_u_write_u(hm%lda_u, iunit=iunit)
1385 call lda_u_write_v(hm%lda_u, iunit=iunit)
1386 if(st%system_grp%is_root()) write(iunit, '(1x)')
1387 end if
1388
1389 if(scf%calc_dipole) then
1390 call calc_dipole(dipole, space, gr, st, ions)
1391 call write_dipole(st, hm, space, dipole, iunit=iunit)
1392 end if
1393
1394 ! This only works when we do not have a correlation part
1395 if(ks%theory_level == kohn_sham_dft .and. &
1396 hm%xc%functional(func_c,1)%family == xc_family_none .and. st%d%ispin /= spinors &
1397 .and. .not. space%is_periodic()) then
1398 call energy_calc_virial_ex(gr%der, hm%ks_pot%vxc, st, ex_virial)
1399
1400 if (st%system_grp%is_root()) then
1401 write(iunit, '(3a)') 'Virial relation for exchange [', trim(units_abbrev(units_out%energy)), ']:'
1402 write(iunit,'(a,es14.6)') "Energy from the orbitals ", units_from_atomic(units_out%energy, hm%energy%exchange)
1403 write(iunit,'(a,es14.6)') "Energy from the potential (virial) ", units_from_atomic(units_out%energy, ex_virial)
1404 write(iunit, '(1x)')
1405 end if
1406 end if
1407
1408 if(st%system_grp%is_root()) then
1409 if(scf%max_iter > 0) then
1410 write(iunit, '(a)') 'Convergence:'
1411 call iterator%start(scf%criterion_list)
1412 do while (iterator%has_next())
1413 crit => iterator%get_next()
1414 call crit%write_info(iunit)
1415 end do
1416 write(iunit,'(1x)')
1417 end if
1418 ! otherwise, these values are uninitialized, and unknown.
1419
1420 if (bitand(ks%xc_family, xc_family_oep) /= 0 .and. ks%theory_level /= hartree_fock &
1421 .and. ks%theory_level /= generalized_kohn_sham_dft) then
1422 call ks%v_ks_photons%write_info(iunit)
1423 end if
1424
1425 if (scf%calc_force) call forces_write_info(iunit, ions, dir, namespace)
1426
1427 if (scf%calc_stress) then
1428 call output_stress(iunit, space%periodic_dim, st%stress_tensors, all_terms=.false.)
1429 call output_pressure(iunit, space%periodic_dim, st%stress_tensors%total)
1430 end if
1431
1432 end if
1433
1434 if(scf%calc_partial_charges) then
1435 call partial_charges_compute_and_print_charges(gr, st, ions, iunit)
1436 end if
1437
1438 if(st%system_grp%is_root()) then
1439 call io_close(iunit)
1440 end if
1441
1442 pop_sub(scf_run.scf_write_static)
1443 end subroutine scf_write_static
1444
1445 end subroutine scf_finish
1446
1447 ! ---------------------------------------------------------
1448 subroutine scf_state_info(namespace, st)
1449 type(namespace_t), intent(in) :: namespace
1450 class(states_abst_t), intent(in) :: st
1451
1452 push_sub(scf_state_info)
1453
1454 if (states_are_real(st)) then
1455 call messages_write('Info: SCF using real wavefunctions.')
1456 else
1457 call messages_write('Info: SCF using complex wavefunctions.')
1458 end if
1459 call messages_info(namespace=namespace)
1460
1461 pop_sub(scf_state_info)
1462
1463 end subroutine scf_state_info
1464
1465 ! ---------------------------------------------------------
1466 subroutine scf_print_mem_use(namespace)
1467 type(namespace_t), intent(in) :: namespace
1468 real(real64) :: mem
1469 real(real64) :: mem_tmp
1470
1471 push_sub(scf_print_mem_use)
1472
1473 if(conf%report_memory) then
1474 mem = loct_get_memory_usage()/(1024.0_real64**2)
1475 call mpi_world%allreduce(mem, mem_tmp, 1, mpi_double_precision, mpi_sum)
1476 mem = mem_tmp
1477 write(message(1),'(a,f14.2)') 'Memory usage [Mbytes] :', mem
1478 call messages_info(1, namespace=namespace)
1479 end if
1480
1481 pop_sub(scf_print_mem_use)
1482 end subroutine scf_print_mem_use
1483
1484 ! --------------------------------------------------------
1486 subroutine scf_update_initial_quantity(scf, hm, criterion)
1487 type(scf_t), intent(inout) :: scf
1488 type(hamiltonian_elec_t), intent(in) :: hm
1489 class(convergence_criterion_t), intent(in) :: criterion
1490
1492
1493 select type (criterion)
1494 type is (energy_criterion_t)
1495 scf%energy_in = hm%energy%total
1496 type is (density_criterion_t)
1497 !Do nothing here
1498 type is (eigenval_criterion_t)
1499 !Setting of the value is done in the scf_update_diff_quantity routine
1500 class default
1501 assert(.false.)
1502 end select
1503
1505 end subroutine scf_update_initial_quantity
1506
1507 ! --------------------------------------------------------
1509 subroutine scf_update_diff_quantity(scf, hm, st, gr, rhoout, rhoin, criterion)
1510 type(scf_t), intent(inout) :: scf
1511 type(hamiltonian_elec_t), intent(in) :: hm
1512 type(states_elec_t), intent(in) :: st
1513 type(grid_t), intent(in) :: gr
1514 real(real64), intent(in) :: rhoout(:,:), rhoin(:,:)
1515 class(convergence_criterion_t), intent(in) :: criterion
1516
1517 integer :: is
1518 real(real64), allocatable :: tmp(:)
1519
1520 push_sub(scf_update_diff_quantity)
1521
1522 select type (criterion)
1523 type is (energy_criterion_t)
1524 scf%energy_diff = abs(hm%energy%total - scf%energy_in)
1525
1526 type is (density_criterion_t)
1527 scf%abs_dens_diff = m_zero
1528 safe_allocate(tmp(1:gr%np))
1529 do is = 1, st%d%nspin
1530 tmp(:) = abs(rhoin(1:gr%np, is) - rhoout(1:gr%np, is))
1531 scf%abs_dens_diff = scf%abs_dens_diff + dmf_integrate(gr, tmp)
1532 end do
1533 safe_deallocate_a(tmp)
1534
1535 type is (eigenval_criterion_t)
1536 scf%evsum_out = states_elec_eigenvalues_sum(st)
1537 scf%evsum_diff = abs(scf%evsum_out - scf%evsum_in)
1538 scf%evsum_in = scf%evsum_out
1539
1540 class default
1541 assert(.false.)
1542 end select
1545 end subroutine scf_update_diff_quantity
1546
1547 ! ---------------------------------------------------------
1548 subroutine write_dipole(st, hm, space, dipole, iunit, namespace)
1549 type(states_elec_t), intent(in) :: st
1550 type(hamiltonian_elec_t), intent(in) :: hm
1551 type(electron_space_t), intent(in) :: space
1552 real(real64), intent(in) :: dipole(:)
1553 integer, optional, intent(in) :: iunit
1554 type(namespace_t), optional, intent(in) :: namespace
1555
1556 push_sub(write_dipole)
1557
1558 if(st%system_grp%is_root()) then
1559 call output_dipole(dipole, space%dim, iunit=iunit, namespace=namespace)
1560
1561 if (space%is_periodic()) then
1562 message(1) = "Defined only up to quantum of polarization (e * lattice vector)."
1563 message(2) = "Single-point Berry's phase method only accurate for large supercells."
1564 call messages_info(2, iunit=iunit, namespace=namespace)
1565
1566 if (hm%kpoints%full%npoints > 1) then
1567 message(1) = &
1568 "WARNING: Single-point Berry's phase method for dipole should not be used when there is more than one k-point."
1569 message(2) = "Instead, finite differences on k-points (not yet implemented) are needed."
1570 call messages_info(2, iunit=iunit, namespace=namespace)
1571 end if
1572
1573 if(.not. smear_is_semiconducting(st%smear)) then
1574 message(1) = "Single-point Berry's phase dipole calculation not correct without integer occupations."
1575 call messages_info(1, iunit=iunit, namespace=namespace)
1576 end if
1577 end if
1578
1579 call messages_info(iunit=iunit, namespace=namespace)
1580 end if
1582 pop_sub(write_dipole)
1583 end subroutine write_dipole
1584
1586 subroutine scf_set_lower_bound_is_known(scf, known_lower_bound)
1587 type(scf_t), intent(inout) :: scf
1588 logical, intent(in) :: known_lower_bound
1589
1590 call scf%eigens%set_lower_bound_is_known(known_lower_bound)
1591 end subroutine scf_set_lower_bound_is_known
1592
1593end module scf_oct_m
1594
1595
1596!! Local Variables:
1597!! mode: f90
1598!! coding: utf-8
1599!! End:
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:188
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:118
subroutine, public berry_perform_internal_scf(this, namespace, space, eigensolver, gr, st, hm, iter, ks, ions, ext_partners)
Definition: berry.F90:186
subroutine, public berry_init(this, namespace)
Definition: berry.F90:161
subroutine, public calc_dipole(dipole, space, mesh, st, ions)
Definition: berry.F90:252
subroutine, public criteria_factory_init(list, namespace, check_conv)
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
subroutine, public states_elec_sync_buff_density(st, mesh)
Synchronize the GPU density buffer with the host density strho.
Definition: density.F90:920
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:653
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
Definition: epot.F90:168
integer, parameter, public fully_relativistic_zora
Definition: epot.F90:168
subroutine, public forces_write_info(iunit, ions, dir, namespace)
Definition: forces.F90:594
subroutine, public forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old, t, dt)
Definition: forces.F90:340
real(real64), parameter, public m_zero
Definition: global.F90:200
integer, parameter, public hartree_fock
Definition: global.F90:250
integer, parameter, public independent_particles
Theory level.
Definition: global.F90:250
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:250
real(real64), parameter, public lmm_r_single_atom
Default local magnetic moments sphere radius for an isolated system.
Definition: global.F90:234
integer, parameter, public kohn_sham_dft
Definition: global.F90:250
type(conf_t), public conf
Global instance of Octopus configuration.
Definition: global.F90:190
character(len= *), parameter, public static_dir
Definition: global.F90:279
real(real64), parameter, public m_half
Definition: global.F90:206
real(real64), parameter, public m_one
Definition: global.F90:201
This module implements the underlying real-space grid.
Definition: grid.F90:119
subroutine, public grid_write_info(gr, iunit, namespace)
Definition: grid.F90:519
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.
Definition: io.F90:116
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
subroutine, public io_debug_on_the_fly(namespace)
check if debug mode should be enabled or disabled on the fly
Definition: io.F90:535
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:361
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
integer, parameter, public kpoints_path
Definition: kpoints.F90:223
A module to handle KS potential, without the external potential.
subroutine, public lda_u_dump(restart, namespace, this, st, mesh, ierr)
Definition: lda_u_io.F90:641
subroutine, public lda_u_write_u(this, iunit, namespace)
Definition: lda_u_io.F90:527
subroutine, public lda_u_load(restart, this, st, dftu_energy, ierr, occ_only, u_only)
Definition: lda_u_io.F90:722
subroutine, public lda_u_write_v(this, iunit, namespace)
Definition: lda_u_io.F90:575
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
Definition: lda_u.F90:205
subroutine, public lda_u_update_occ_matrices(this, namespace, mesh, st, phase, energy)
Definition: lda_u.F90:895
integer, parameter, public dft_u_acbn0
Definition: lda_u.F90:205
System information (time, memory, sysname)
Definition: loct.F90:117
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.
Definition: magnetic.F90:225
subroutine, public write_total_xc_torque(iunit, mesh, vxc, st)
Definition: magnetic.F90:578
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:898
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
character(len=512), private msg
Definition: messages.F90:167
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:525
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1000
subroutine, public messages_new_line()
Definition: messages.F90:1089
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:691
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1040
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
integer pure function, public mix_scheme(this)
Definition: mix.F90:826
real(real64) pure function, public mix_coefficient(this)
Definition: mix.F90:820
subroutine, public mixing(namespace, smix)
Main entry-point to SCF mixer.
Definition: mix.F90:846
subroutine, public mix_get_field(this, mixfield)
Definition: mix.F90:838
subroutine, public mix_dump(namespace, restart, smix, mesh, ierr)
Definition: mix.F90:591
subroutine, public mix_init(smix, namespace, space, der, d1, d2, def_, func_type_, prefix_)
Initialise mix_t instance.
Definition: mix.F90:269
subroutine, public mix_load(namespace, restart, smix, mesh, ierr)
Definition: mix.F90:690
subroutine, public mix_end(smix)
Definition: mix.F90:568
subroutine, public mix_clear(smix)
Definition: mix.F90:552
subroutine, public modelmb_sym_all_states(space, mesh, st)
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:272
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
this module contains the low-level part of the output system
Definition: output_low.F90:117
subroutine, public output_modelmb(outp, namespace, space, dir, gr, ions, iter, st)
this module contains the output system
Definition: output.F90:117
logical function, public output_needs_current(outp, states_are_real)
Definition: output.F90:958
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
Definition: output.F90:479
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.
Definition: profiling.F90:631
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:554
logical function, public clean_stop(comm)
returns true if a file named stop exists
Definition: restart.F90:337
integer, parameter, public restart_flag_mix
Definition: restart.F90:189
integer, parameter, public restart_flag_rho
Definition: restart.F90:189
integer, parameter, public restart_flag_vhxc
Definition: restart.F90:189
subroutine, public scf_finish(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, iter, outp)
Definition: scf.F90:1300
subroutine, public scf_set_lower_bound_is_known(scf, known_lower_bound)
Set the flag lower_bound_is_known.
Definition: scf.F90:1682
subroutine, public scf_load(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, restart_load)
Loading of restarting data of the SCF cycle.
Definition: scf.F90:604
subroutine write_dipole(st, hm, space, dipole, iunit, namespace)
Definition: scf.F90:1644
subroutine scf_update_initial_quantity(scf, hm, criterion)
Update the quantity at the begining of a SCF cycle.
Definition: scf.F90:1582
subroutine scf_update_diff_quantity(scf, hm, st, gr, rhoout, rhoin, criterion)
Update the quantity at the begining of a SCF cycle.
Definition: scf.F90:1605
subroutine, public scf_state_info(namespace, st)
Definition: scf.F90:1544
subroutine, public scf_print_mem_use(namespace)
Definition: scf.F90:1562
subroutine, public scf_mix_clear(scf)
Definition: scf.F90:587
subroutine, public scf_start(scf, namespace, gr, ions, st, ks, hm, outp, verbosity)
Preparation of the SCF cycle.
Definition: scf.F90:693
integer, parameter, public verb_full
Definition: scf.F90:206
integer, parameter, public verb_compact
Definition: scf.F90:206
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
Definition: scf.F90:259
subroutine, public scf_end(scf)
Definition: scf.F90:557
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.
Definition: scf.F90:838
subroutine, public scf_iter(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, iter, outp, restart_dump)
Definition: scf.F90:884
logical function, public scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, iters_done)
Definition: scf.F90:1221
logical pure function, public smear_is_semiconducting(this)
Definition: smear.F90:1042
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.
Definition: stress.F90:120
subroutine, public output_pressure(iunit, space_dim, total_stress_tensor)
Definition: stress.F90:1145
subroutine, public stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
This computes the total stress on the lattice.
Definition: stress.F90:188
subroutine, public output_stress(iunit, space_dim, stress_tensors, all_terms)
Definition: stress.F90:1080
subroutine, public symmetries_write_info(this, space, iunit, namespace)
Definition: symmetries.F90:631
type(type_t), parameter, public type_float
Definition: types.F90:135
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:225
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.
Definition: utils.F90:120
subroutine, public output_dipole(dipole, ndim, iunit, namespace)
Definition: utils.F90:281
subroutine, public v_ks_write_info(ks, iunit, namespace)
Definition: v_ks.F90:619
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.
Definition: v_ks.F90:1469
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
Definition: v_ks.F90:708
Tkatchenko-Scheffler pairwise method for van der Waals (vdW, dispersion) interactions.
Definition: vdw_ts.F90:121
subroutine, public vdw_ts_write_c6ab(this, ions, dir, fname, namespace)
Definition: vdw_ts.F90:549
subroutine, public vtau_mixer_end(mixer, smix)
Definition: vtau_mixer.F90:191
subroutine, public vtau_mixer_init_auxmixer(namespace, mixer, smix, hm, np, nspin)
Definition: vtau_mixer.F90:152
subroutine, public vtau_mixer_set_vout(mixer, hm)
Definition: vtau_mixer.F90:205
subroutine, public vtau_mixer_get_vnew(mixer, hm)
Definition: vtau_mixer.F90:231
subroutine, public vtau_mixer_clear(mixer, smix)
Definition: vtau_mixer.F90:178
subroutine, public vtau_mixer_set_vin(mixer, hm)
Definition: vtau_mixer.F90:218
This module provices a simple timer class which can be used to trigger the writing of a restart file ...
Definition: walltimer.F90:123
logical function, public walltimer_alarm(comm, print)
indicate whether time is up
Definition: walltimer.F90:333
logical function, public restart_walltime_period_alarm(comm)
Definition: walltimer.F90:375
integer, parameter, public xc_family_nc_mgga
integer, parameter, public func_c
Definition: xc.F90:120
integer, parameter, public oep_level_full
Definition: xc_oep.F90:174
subroutine scf_write_static(dir, fname)
Definition: rdmft.F90:587
subroutine create_convergence_file(dir, fname)
Definition: scf.F90:800
subroutine scf_write_iter(namespace)
Definition: scf.F90:1119
subroutine write_convergence_file(dir, fname)
Definition: scf.F90:1182
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
Stores all communicators and groups.
Definition: multicomm.F90:208
output handler class
Definition: output_low.F90:166
some variables used for the SCF cycle
Definition: scf.F90:212
abstract class for states
The states_elec_t class contains all electronic wave functions.
batches of electronic states
Definition: wfs_elec.F90:141
int true(void)