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