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