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)
208 type is (energy_criterion_t)
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
219
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)
252
253 call messages_obsolete_variable(namespace, 'What2Mix', 'MixField')
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_load%has_flag(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_load%has_flag(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_load%has_flag(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_load%has_flag(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_world%is_root()) 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_world%is_root()) 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
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 ! Are we asked to stop? (Whenever Fortran is ready for signals, this should go away)
954 scf%forced_finish = clean_stop(mc%master_comm) .or. walltimer_alarm(mc%master_comm)
955
956 if (scf%finish .and. st%modelmbparticles%nparticle > 0) then
957 call modelmb_sym_all_states(space, gr, st)
958 end if
959
960 if (present(outp) .and. present(restart_dump)) then
961 ! save restart information
962
963 if ( (scf%finish .or. (modulo(iter, outp%restart_write_interval) == 0) &
964 .or. iter == scf%max_iter .or. scf%forced_finish) ) then
965
966 call states_elec_dump(scf%restart_dump, space, st, gr, hm%kpoints, ierr, iter=iter)
967 if (ierr /= 0) then
968 message(1) = 'Unable to write states wavefunctions.'
969 call messages_warning(1, namespace=namespace)
970 end if
971
972 call states_elec_dump_rho(scf%restart_dump, space, st, gr, ierr, iter=iter)
973 if (ierr /= 0) then
974 message(1) = 'Unable to write density.'
975 call messages_warning(1, namespace=namespace)
976 end if
977
978 if(hm%lda_u_level /= dft_u_none) then
979 call lda_u_dump(scf%restart_dump, namespace, hm%lda_u, st, gr, ierr)
980 if (ierr /= 0) then
981 message(1) = 'Unable to write DFT+U information.'
982 call messages_warning(1, namespace=namespace)
983 end if
984 end if
985
986 select case (scf%mix_field)
987 case (option__mixfield__density)
988 call mix_dump(namespace, scf%restart_dump, scf%smix, space, gr, ierr)
989 if (ierr /= 0) then
990 message(1) = 'Unable to write mixing information.'
991 call messages_warning(1, namespace=namespace)
992 end if
993 case (option__mixfield__potential)
994 call hm%ks_pot%dump(scf%restart_dump, space, gr, ierr)
995 if (ierr /= 0) then
996 message(1) = 'Unable to write Vhxc.'
997 call messages_warning(1, namespace=namespace)
998 end if
999
1000 call mix_dump(namespace, scf%restart_dump, scf%smix, space, gr, ierr)
1001 if (ierr /= 0) then
1002 message(1) = 'Unable to write mixing information.'
1003 call messages_warning(1, namespace=namespace)
1004 end if
1005 end select
1006 end if
1007 end if
1008
1009 call write_convergence_file(static_dir, "convergence")
1010
1011 call profiling_out("SCF_CYCLE")
1012
1013 pop_sub(scf_iter)
1014 contains
1015
1016 ! ---------------------------------------------------------
1017 subroutine scf_write_iter(namespace)
1018 type(namespace_t), intent(in) :: namespace
1019
1020 character(len=50) :: str
1021 real(real64) :: dipole(1:space%dim)
1022
1023 push_sub(scf_run.scf_write_iter)
1024
1025 if ( scf%verbosity_ == verb_full ) then
1026
1027 write(str, '(a,i5)') 'SCF CYCLE ITER #' ,iter
1028 call messages_print_with_emphasis(msg=trim(str), namespace=namespace)
1029 write(message(1),'(a,es15.8,2(a,es9.2))') ' etot = ', units_from_atomic(units_out%energy, hm%energy%total), &
1030 ' abs_ev = ', units_from_atomic(units_out%energy, scf%evsum_diff), &
1031 ' rel_ev = ', scf%evsum_diff/(abs(scf%evsum_out)+1e-20)
1032 write(message(2),'(a,es15.2,2(a,es9.2))') &
1033 ' ediff = ', scf%energy_diff, ' abs_dens = ', scf%abs_dens_diff, &
1034 ' rel_dens = ', scf%abs_dens_diff/st%qtot
1035 call messages_info(2, namespace=namespace)
1036
1037 if(.not.scf%lcao_restricted) then
1038 write(message(1),'(a,i6)') 'Matrix vector products: ', scf%eigens%matvec
1039 write(message(2),'(a,i6)') 'Converged eigenvectors: ', sum(scf%eigens%converged(1:st%nik))
1040 call messages_info(2, namespace=namespace)
1041 call states_elec_write_eigenvalues(st%nst, st, space, hm%kpoints, scf%eigens%diff, compact = .true., namespace=namespace)
1042 else
1043 call states_elec_write_eigenvalues(st%nst, st, space, hm%kpoints, compact = .true., namespace=namespace)
1044 end if
1045
1046 if (allocated(hm%vberry)) then
1047 call calc_dipole(dipole, space, gr, st, ions)
1048 call write_dipole(st, hm, space, dipole, namespace=namespace)
1049 end if
1050
1051 if(st%d%ispin > unpolarized) then
1052 call write_magnetic_moments(gr, st, ions, gr%der%boundaries, scf%lmm_r, namespace=namespace)
1053 end if
1054
1055 if(hm%lda_u_level == dft_u_acbn0) then
1056 call lda_u_write_u(hm%lda_u, namespace=namespace)
1057 call lda_u_write_v(hm%lda_u, namespace=namespace)
1058 end if
1059
1060 write(message(1),'(a)') ''
1061 write(message(2),'(a,i5,a,f14.2)') 'Elapsed time for SCF step ', iter,':', etime
1062 call messages_info(2, namespace=namespace)
1063
1064 call scf_print_mem_use(namespace)
1065
1066 call messages_print_with_emphasis(namespace=namespace)
1067
1068 end if
1069
1070 if ( scf%verbosity_ == verb_compact ) then
1071 write(message(1),'(a,i4,a,es15.8, a,es9.2, a, f7.1, a)') &
1072 'iter ', iter, &
1073 ' : etot ', units_from_atomic(units_out%energy, hm%energy%total), &
1074 ' : abs_dens', scf%abs_dens_diff, &
1075 ' : etime ', etime, 's'
1076 call messages_info(1, namespace=namespace)
1077 end if
1078
1079 pop_sub(scf_run.scf_write_iter)
1080 end subroutine scf_write_iter
1081
1082
1083 ! -----------------------------------------------------
1084 subroutine write_convergence_file(dir, fname)
1085 character(len=*), intent(in) :: dir
1086 character(len=*), intent(in) :: fname
1087
1088 integer :: iunit
1089
1090 if(mpi_world%is_root()) then ! this the absolute master writes
1091 call io_mkdir(dir, namespace)
1092 iunit = io_open(trim(dir) // "/" // trim(fname), namespace, action='write', position='append')
1093 write(iunit, '(i5,es18.8)', advance = 'no') iter, units_from_atomic(units_out%energy, hm%energy%total)
1094 call iterator%start(scf%criterion_list)
1095 do while (iterator%has_next())
1096 crit => iterator%get_next()
1097 select type (crit)
1098 type is (energy_criterion_t)
1099 write(iunit, '(es13.5)', advance = 'no') units_from_atomic(units_out%energy, crit%val_abs)
1100 type is (density_criterion_t)
1101 write(iunit, '(2es13.5)', advance = 'no') crit%val_abs, crit%val_rel
1102 type is (eigenval_criterion_t)
1103 write(iunit, '(es13.5)', advance = 'no') units_from_atomic(units_out%energy, crit%val_abs)
1104 write(iunit, '(es13.5)', advance = 'no') crit%val_rel
1105 class default
1106 assert(.false.)
1107 end select
1108 end do
1109 if (bitand(ks%xc_family, xc_family_oep) /= 0 .and. ks%theory_level /= hartree_fock &
1110 .and. ks%theory_level /= generalized_kohn_sham_dft) then
1111 if (ks%oep%level == oep_level_full) then
1112 write(iunit, '(es13.5)', advance = 'no') ks%oep%norm2ss
1113 end if
1114 end if
1115 write(iunit,'(a)') ''
1116 call io_close(iunit)
1117 end if
1118 end subroutine write_convergence_file
1119
1120 end subroutine scf_iter
1121
1122 logical function scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, &
1123 verbosity, iters_done) result(completed)
1124 type(scf_t), intent(inout) :: scf
1125 type(namespace_t), intent(in) :: namespace
1126 type(electron_space_t), intent(in) :: space
1127 type(grid_t), intent(inout) :: gr
1128 type(ions_t), intent(inout) :: ions
1129 type(states_elec_t), intent(inout) :: st
1130 type(v_ks_t), intent(inout) :: ks
1131 type(hamiltonian_elec_t), intent(inout) :: hm
1132 integer, intent(in) :: iter
1133 type(output_t), optional, intent(in) :: outp
1134 integer, optional, intent(in) :: verbosity
1135 integer, optional, intent(out) :: iters_done
1136
1137 character(len=MAX_PATH_LEN) :: dirname
1138 integer(int64) :: what_i
1139
1140 push_sub(scf_iter_finish)
1141
1142 completed = .false.
1143
1144 if(scf%finish) then
1145 if(present(iters_done)) iters_done = iter
1146 if(scf%verbosity_ >= verb_compact) then
1147 write(message(1), '(a, i4, a)') 'Info: SCF converged in ', iter, ' iterations'
1148 write(message(2), '(a)') ''
1149 call messages_info(2, namespace=namespace)
1150 end if
1151 completed = .true.
1152 pop_sub(scf_iter_finish)
1153 return
1154 end if
1155 if (present(outp)) then
1156 if (any(outp%what) .and. outp%duringscf) then
1157 do what_i = lbound(outp%what, 1), ubound(outp%what, 1)
1158 if (outp%what_now(what_i, iter)) then
1159 write(dirname,'(a,a,i4.4)') trim(outp%iter_dir),"scf.", iter
1160 call output_all(outp, namespace, space, dirname, gr, ions, iter, st, hm, ks)
1161 call output_modelmb(outp, namespace, space, dirname, gr, ions, iter, st)
1162 exit
1163 end if
1164 end do
1165 end if
1166 end if
1167
1168 ! save information for the next iteration
1169 call lalg_copy(gr%np, st%d%nspin, st%rho, scf%rhoin)
1170
1171 ! restart mixing
1172 if (scf%mix_field /= option__mixfield__none) then
1173 if (scf%smix%ns_restart > 0) then
1174 if (mod(iter, scf%smix%ns_restart) == 0) then
1175 message(1) = "Info: restarting mixing."
1176 call messages_info(1, namespace=namespace)
1177 call scf_mix_clear(scf)
1178 end if
1179 end if
1180 end if
1181
1182 select case(scf%mix_field)
1183 case(option__mixfield__potential)
1184 call mixfield_set_vin(scf%mixfield, hm%ks_pot%vhxc(1:gr%np, 1:st%d%nspin))
1185 call vtau_mixer_set_vin(scf%vtau_mix, hm)
1186 case (option__mixfield__density)
1187 call mixfield_set_vin(scf%mixfield, scf%rhoin)
1188 end select
1189
1190 !If we use LDA+U, we also have do mix it
1191 if (scf%mix_field /= option__mixfield__states) then
1192 call lda_u_mixer_set_vin(hm%lda_u, scf%lda_u_mix)
1193 end if
1194
1195 ! check if debug mode should be enabled or disabled on the fly
1196 call io_debug_on_the_fly(namespace)
1197
1198 pop_sub(scf_iter_finish)
1199 end function scf_iter_finish
1200
1201 ! ---------------------------------------------------------
1202 subroutine scf_finish(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, iter, outp, &
1203 verbosity, iters_done, restart_dump)
1204 type(scf_t), intent(inout) :: scf
1205 type(namespace_t), intent(in) :: namespace
1206 type(electron_space_t), intent(in) :: space
1207 type(multicomm_t), intent(in) :: mc
1208 type(grid_t), intent(inout) :: gr
1209 type(ions_t), intent(inout) :: ions
1210 type(partner_list_t), intent(in) :: ext_partners
1211 type(states_elec_t), intent(inout) :: st
1212 type(v_ks_t), intent(inout) :: ks
1213 type(hamiltonian_elec_t), intent(inout) :: hm
1214 integer, intent(in) :: iter
1215 type(output_t), optional, intent(in) :: outp
1216 integer, optional, intent(in) :: verbosity
1217 integer, optional, intent(out) :: iters_done
1218 type(restart_t), optional, intent(in) :: restart_dump
1219
1220 integer :: iqn, ib
1221 class(convergence_criterion_t), pointer :: crit
1222 type(criterion_iterator_t) :: iterator
1223
1224
1225 push_sub(scf_finish)
1226
1227 if(scf%lcao_restricted) call lcao_end(scf%lcao)
1228
1229 ! Compute the KS potential corresponding to the final density
1230 ! This is critical for getting consistent TD calculations
1231 if ((scf%max_iter > 0 .and. scf%mix_field == option__mixfield__potential) .or. scf%calc_current) then
1232 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
1233 calc_current=scf%calc_current)
1234 end if
1235
1236 select case(scf%mix_field)
1237 case(option__mixfield__states)
1238
1239 do iqn = st%d%kpt%start, st%d%kpt%end
1240 do ib = st%group%block_start, st%group%block_end
1241 call scf%psioutb(ib, iqn)%end()
1242 end do
1243 end do
1244
1245 ! There is a ICE with foss2022a-serial. I am changing to deallocate - NTD
1246 deallocate(scf%psioutb)
1247 end select
1248
1249 safe_deallocate_a(scf%rhoout)
1250 safe_deallocate_a(scf%rhoin)
1251
1252 if (scf%max_iter > 0 .and. any(scf%eigens%converged < st%nst) .and. .not. scf%lcao_restricted) then
1253 write(message(1),'(a)') 'Some of the states are not fully converged!'
1254 if (all(scf%eigens%converged >= st%nst_conv)) then
1255 write(message(2),'(a)') 'But all requested states to converge are converged.'
1256 call messages_info(2, namespace=namespace)
1257 else
1258 call messages_warning(1, namespace=namespace)
1259 end if
1260 end if
1261
1262 if (.not.scf%finish) then
1263 write(message(1), '(a,i4,a)') 'SCF *not* converged after ', iter - 1, ' iterations.'
1264 call messages_warning(1, namespace=namespace)
1265 end if
1266
1267 write(message(1), '(a,i10)') 'Info: Number of matrix-vector products: ', scf%matvec
1268 call messages_info(1)
1269
1270 if (scf%calc_force) then
1271 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old=scf%vhxc_old)
1272 end if
1273
1274 if (scf%calc_stress) call stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
1275
1276 ! Update the eigenvalues, to match the KS potential that just got recomputed
1277 if (scf%mix_field == option__mixfield__potential) then
1278 call energy_calc_eigenvalues(namespace, hm, gr%der, st)
1279 call states_elec_fermi(st, namespace, gr)
1280 end if
1281
1282 if(present(outp)) then
1283 ! output final information
1284 call scf_write_static(static_dir, "info")
1285 call output_all(outp, namespace, space, static_dir, gr, ions, -1, st, hm, ks)
1286 call output_modelmb(outp, namespace, space, static_dir, gr, ions, -1, st)
1287 end if
1288
1289 if (space%is_periodic() .and. st%nik > st%d%nspin) then
1290 if (bitand(hm%kpoints%method, kpoints_path) /= 0) then
1291 call states_elec_write_bandstructure(static_dir, namespace, st%nst, st, &
1292 ions, gr, hm%kpoints, hm%phase, vec_pot = hm%hm_base%uniform_vector_potential, &
1293 vec_pot_var = hm%hm_base%vector_potential)
1294 end if
1295 end if
1296
1297 if (ks%vdw%vdw_correction == option__vdwcorrection__vdw_ts) then
1298 call vdw_ts_write_c6ab(ks%vdw%vdw_ts, ions, static_dir, 'c6ab_eff', namespace)
1299 end if
1300
1301 safe_deallocate_a(scf%vhxc_old)
1302
1303 pop_sub(scf_finish)
1304
1305 contains
1306
1307 ! ---------------------------------------------------------
1308 subroutine scf_write_static(dir, fname)
1309 character(len=*), intent(in) :: dir, fname
1310
1311 integer :: iunit
1312 real(real64) :: dipole(1:space%dim)
1313 real(real64) :: ex_virial
1314
1315 push_sub(scf_run.scf_write_static)
1316
1317 if(mpi_world%is_root()) then ! this the absolute master writes
1318 call io_mkdir(dir, namespace)
1319 iunit = io_open(trim(dir) // "/" // trim(fname), namespace, action='write')
1320
1321 call grid_write_info(gr, iunit=iunit)
1322
1323 call symmetries_write_info(gr%symm, space, iunit=iunit)
1324
1325 if (space%is_periodic()) then
1326 call hm%kpoints%write_info(iunit=iunit)
1327 write(iunit,'(1x)')
1328 end if
1329
1330 call v_ks_write_info(ks, iunit=iunit)
1331
1332 ! scf information
1333 if(scf%finish) then
1334 write(iunit, '(a, i4, a)')'SCF converged in ', iter, ' iterations'
1335 else
1336 write(iunit, '(a)') 'SCF *not* converged!'
1337 end if
1338 write(iunit, '(1x)')
1339
1340 if(any(scf%eigens%converged < st%nst) .and. .not. scf%lcao_restricted) then
1341 write(iunit,'(a)') 'Some of the states are not fully converged!'
1342 if (all(scf%eigens%converged >= st%nst_conv)) then
1343 write(iunit,'(a)') 'But all requested states to converge are converged.'
1344 end if
1345 end if
1346
1347 call states_elec_write_eigenvalues(st%nst, st, space, hm%kpoints, iunit=iunit)
1348 write(iunit, '(1x)')
1349
1350 if (space%is_periodic()) then
1351 call states_elec_write_gaps(iunit, st, space)
1352 write(iunit, '(1x)')
1353 end if
1354
1355 write(iunit, '(3a)') 'Energy [', trim(units_abbrev(units_out%energy)), ']:'
1356 else
1357 iunit = -1
1358 end if
1359
1360 call energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full = .true.)
1361
1362 if(mpi_world%is_root()) write(iunit, '(1x)')
1363 if(st%d%ispin > unpolarized) then
1364 call write_magnetic_moments(gr, st, ions, gr%der%boundaries, scf%lmm_r, iunit=iunit)
1365 if (mpi_world%is_root()) write(iunit, '(1x)')
1366 end if
1367
1368 if(st%d%ispin == spinors .and. space%dim == 3 .and. &
1369 (ks%theory_level == kohn_sham_dft .or. ks%theory_level == generalized_kohn_sham_dft) ) then
1370 call write_total_xc_torque(iunit, gr, hm%ks_pot%vxc, st)
1371 if(mpi_world%is_root()) write(iunit, '(1x)')
1372 end if
1373
1374 if(hm%lda_u_level == dft_u_acbn0) then
1375 call lda_u_write_u(hm%lda_u, iunit=iunit)
1376 call lda_u_write_v(hm%lda_u, iunit=iunit)
1377 if(mpi_world%is_root()) write(iunit, '(1x)')
1378 end if
1379
1380 if(scf%calc_dipole) then
1381 call calc_dipole(dipole, space, gr, st, ions)
1382 call write_dipole(st, hm, space, dipole, iunit=iunit)
1383 end if
1384
1385 ! This only works when we do not have a correlation part
1386 if(ks%theory_level == kohn_sham_dft .and. &
1387 hm%xc%functional(func_c,1)%family == xc_family_none .and. st%d%ispin /= spinors) then
1388 call energy_calc_virial_ex(gr%der, hm%ks_pot%vxc, st, ex_virial)
1389
1390 if (mpi_world%is_root()) then
1391 write(iunit, '(3a)') 'Virial relation for exchange [', trim(units_abbrev(units_out%energy)), ']:'
1392 write(iunit,'(a,es14.6)') "Energy from the orbitals ", units_from_atomic(units_out%energy, hm%energy%exchange)
1393 write(iunit,'(a,es14.6)') "Energy from the potential (virial) ", units_from_atomic(units_out%energy, ex_virial)
1394 write(iunit, '(1x)')
1395 end if
1396 end if
1397
1398 if(mpi_world%is_root()) then
1399 if(scf%max_iter > 0) then
1400 write(iunit, '(a)') 'Convergence:'
1401 call iterator%start(scf%criterion_list)
1402 do while (iterator%has_next())
1403 crit => iterator%get_next()
1404 call crit%write_info(iunit)
1405 end do
1406 write(iunit,'(1x)')
1407 end if
1408 ! otherwise, these values are uninitialized, and unknown.
1409
1410 if (bitand(ks%xc_family, xc_family_oep) /= 0 .and. ks%theory_level /= hartree_fock &
1411 .and. ks%theory_level /= generalized_kohn_sham_dft) then
1412 if ((ks%oep_photon%level == oep_level_full) .or. (ks%oep_photon%level == oep_level_kli)) then
1413 write(iunit, '(a)') 'Photon observables:'
1414 write(iunit, '(6x, a, es15.8,a,es15.8,a)') 'Photon number = ', ks%oep_photon%pt%number(1)
1415 write(iunit, '(6x, a, es15.8,a,es15.8,a)') 'Photon ex. = ', ks%oep_photon%pt%ex
1416 write(iunit,'(1x)')
1417 end if
1418 end if
1419
1420 if (scf%calc_force) call forces_write_info(iunit, ions, dir, namespace)
1421
1422 if (scf%calc_stress) then
1423 call output_stress(iunit, space%periodic_dim, st%stress_tensors, all_terms=.false.)
1424 call output_pressure(iunit, space%periodic_dim, st%stress_tensors%total)
1425 end if
1426
1427 end if
1428
1429 if(scf%calc_partial_charges) then
1430 call partial_charges_compute_and_print_charges(gr, st, ions, iunit)
1431 end if
1432
1433 if(mpi_world%is_root()) then
1434 call io_close(iunit)
1435 end if
1436
1437 pop_sub(scf_run.scf_write_static)
1438 end subroutine scf_write_static
1439
1440 end subroutine scf_finish
1441
1442 ! ---------------------------------------------------------
1443 subroutine scf_state_info(namespace, st)
1444 type(namespace_t), intent(in) :: namespace
1445 class(states_abst_t), intent(in) :: st
1446
1447 push_sub(scf_state_info)
1448
1449 if (states_are_real(st)) then
1450 call messages_write('Info: SCF using real wavefunctions.')
1451 else
1452 call messages_write('Info: SCF using complex wavefunctions.')
1453 end if
1454 call messages_info(namespace=namespace)
1455
1456 pop_sub(scf_state_info)
1457
1458 end subroutine scf_state_info
1459
1460 ! ---------------------------------------------------------
1461 subroutine scf_print_mem_use(namespace)
1462 type(namespace_t), intent(in) :: namespace
1463 real(real64) :: mem
1464 real(real64) :: mem_tmp
1465
1466 push_sub(scf_print_mem_use)
1467
1468 if(conf%report_memory) then
1469 mem = loct_get_memory_usage()/(1024.0_real64**2)
1470 call mpi_world%allreduce(mem, mem_tmp, 1, mpi_double_precision, mpi_sum)
1471 mem = mem_tmp
1472 write(message(1),'(a,f14.2)') 'Memory usage [Mbytes] :', mem
1473 call messages_info(1, namespace=namespace)
1474 end if
1475
1476 pop_sub(scf_print_mem_use)
1477 end subroutine scf_print_mem_use
1478
1479 ! --------------------------------------------------------
1481 subroutine scf_update_initial_quantity(scf, hm, criterion)
1482 type(scf_t), intent(inout) :: scf
1483 type(hamiltonian_elec_t), intent(in) :: hm
1484 class(convergence_criterion_t), intent(in) :: criterion
1485
1487
1488 select type (criterion)
1489 type is (energy_criterion_t)
1490 scf%energy_in = hm%energy%total
1491 type is (density_criterion_t)
1492 !Do nothing here
1493 type is (eigenval_criterion_t)
1494 !Setting of the value is done in the scf_update_diff_quantity routine
1495 class default
1496 assert(.false.)
1497 end select
1498
1500 end subroutine scf_update_initial_quantity
1501
1502 ! --------------------------------------------------------
1504 subroutine scf_update_diff_quantity(scf, hm, st, gr, rhoout, rhoin, criterion)
1505 type(scf_t), intent(inout) :: scf
1506 type(hamiltonian_elec_t), intent(in) :: hm
1507 type(states_elec_t), intent(in) :: st
1508 type(grid_t), intent(in) :: gr
1509 real(real64), intent(in) :: rhoout(:,:), rhoin(:,:)
1510 class(convergence_criterion_t), intent(in) :: criterion
1511
1512 integer :: is
1513 real(real64), allocatable :: tmp(:)
1514
1515 push_sub(scf_update_diff_quantity)
1516
1517 select type (criterion)
1518 type is (energy_criterion_t)
1519 scf%energy_diff = abs(hm%energy%total - scf%energy_in)
1520
1521 type is (density_criterion_t)
1522 scf%abs_dens_diff = m_zero
1523 safe_allocate(tmp(1:gr%np))
1524 do is = 1, st%d%nspin
1525 tmp(:) = abs(rhoin(1:gr%np, is) - rhoout(1:gr%np, is))
1526 scf%abs_dens_diff = scf%abs_dens_diff + dmf_integrate(gr, tmp)
1527 end do
1528 safe_deallocate_a(tmp)
1529
1530 type is (eigenval_criterion_t)
1531 scf%evsum_out = states_elec_eigenvalues_sum(st)
1532 scf%evsum_diff = abs(scf%evsum_out - scf%evsum_in)
1533 scf%evsum_in = scf%evsum_out
1534
1535 class default
1536 assert(.false.)
1537 end select
1540 end subroutine scf_update_diff_quantity
1541
1542 ! ---------------------------------------------------------
1543 subroutine write_dipole(st, hm, space, dipole, iunit, namespace)
1544 type(states_elec_t), intent(in) :: st
1545 type(hamiltonian_elec_t), intent(in) :: hm
1546 type(electron_space_t), intent(in) :: space
1547 real(real64), intent(in) :: dipole(:)
1548 integer, optional, intent(in) :: iunit
1549 type(namespace_t), optional, intent(in) :: namespace
1550
1551 push_sub(write_dipole)
1552
1553 if(mpi_world%is_root()) then
1554 call output_dipole(dipole, space%dim, iunit=iunit, namespace=namespace)
1555
1556 if (space%is_periodic()) then
1557 message(1) = "Defined only up to quantum of polarization (e * lattice vector)."
1558 message(2) = "Single-point Berry's phase method only accurate for large supercells."
1559 call messages_info(2, iunit=iunit, namespace=namespace)
1560
1561 if (hm%kpoints%full%npoints > 1) then
1562 message(1) = &
1563 "WARNING: Single-point Berry's phase method for dipole should not be used when there is more than one k-point."
1564 message(2) = "Instead, finite differences on k-points (not yet implemented) are needed."
1565 call messages_info(2, iunit=iunit, namespace=namespace)
1566 end if
1567
1568 if(.not. smear_is_semiconducting(st%smear)) then
1569 message(1) = "Single-point Berry's phase dipole calculation not correct without integer occupations."
1570 call messages_info(1, iunit=iunit, namespace=namespace)
1571 end if
1572 end if
1573
1574 call messages_info(iunit=iunit, namespace=namespace)
1575 end if
1577 pop_sub(write_dipole)
1578 end subroutine write_dipole
1579
1580
1581end module scf_oct_m
1582
1583
1584!! Local Variables:
1585!! mode: f90
1586!! coding: utf-8
1587!! End:
batchified version of the BLAS axpy routine:
Definition: batch_ops.F90:156
scale a batch by a constant or vector
Definition: batch_ops.F90:164
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:188
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:118
subroutine, public berry_perform_internal_scf(this, namespace, space, eigensolver, gr, st, hm, iter, ks, ions, ext_partners)
Definition: berry.F90:186
subroutine, public berry_init(this, namespace)
Definition: berry.F90:161
subroutine, public calc_dipole(dipole, space, mesh, st, ions)
Definition: berry.F90:252
subroutine, public criteria_factory_init(list, namespace, check_conv)
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:612
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:596
subroutine, public forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old, t, dt)
Definition: forces.F90:342
real(real64), parameter, public m_zero
Definition: global.F90:190
real(real64), parameter, public lmm_r_single_atom
Default local magnetic moments sphere radius for an isolated system.
Definition: global.F90:220
type(conf_t), public conf
Global instance of Octopus configuration.
Definition: global.F90:180
character(len= *), parameter, public static_dir
Definition: global.F90:256
real(real64), parameter, public m_half
Definition: global.F90:196
real(real64), parameter, public m_one
Definition: global.F90:191
This module implements the underlying real-space grid.
Definition: grid.F90:119
subroutine, public grid_write_info(gr, iunit, namespace)
Definition: grid.F90:530
subroutine, public hamiltonian_elec_update_pot(this, mesh, accumulate)
Update the KS potential of the electronic Hamiltonian.
This module defines classes and functions for interaction partners.
Definition: io.F90:116
subroutine, public io_close(iunit, grp)
Definition: io.F90:466
subroutine, public io_debug_on_the_fly(namespace)
check if debug mode should be enabled or disabled on the fly
Definition: io.F90:534
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:360
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:401
integer, parameter, public kpoints_path
Definition: kpoints.F90:211
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:1495
subroutine, public lcao_wf(this, st, gr, ions, hm, namespace, start)
Definition: lcao.F90:968
subroutine, public lcao_end(this)
Definition: lcao.F90:938
subroutine, public lcao_init(this, namespace, space, gr, ions, st, st_start)
Definition: lcao.F90:250
logical function, public lcao_is_available(this)
Returns true if LCAO can be done.
Definition: lcao.F90:1007
subroutine, public lda_u_dump(restart, namespace, this, st, mesh, ierr)
Definition: lda_u_io.F90:648
subroutine, public lda_u_write_u(this, iunit, namespace)
Definition: lda_u_io.F90:532
subroutine, public lda_u_load(restart, this, st, dftu_energy, ierr, occ_only, u_only)
Definition: lda_u_io.F90:729
subroutine, public lda_u_write_v(this, iunit, namespace)
Definition: lda_u_io.F90:581
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:203
integer, parameter, public dft_u_acbn0
Definition: lda_u.F90:203
subroutine, public lda_u_update_occ_matrices(this, namespace, mesh, st, hm_base, phase, energy)
Definition: lda_u.F90:800
subroutine, public write_magnetic_moments(mesh, st, ions, boundaries, lmm_r, iunit, namespace)
Definition: magnetic.F90:207
subroutine, public write_total_xc_torque(iunit, mesh, vxc, st)
Definition: magnetic.F90:421
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:904
character(len=512), private msg
Definition: messages.F90:167
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:531
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1029
subroutine, public messages_new_line()
Definition: messages.F90:1118
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:416
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:697
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1069
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:600
real(real64) pure function, public mix_coefficient(this)
Definition: mix.F90:804
subroutine, public mixing(namespace, smix)
Main entry-point to SCF mixer.
Definition: mix.F90:830
subroutine, public mix_get_field(this, mixfield)
Definition: mix.F90:822
subroutine, public mix_dump(namespace, restart, smix, space, mesh, ierr)
Definition: mix.F90:579
subroutine, public mix_load(namespace, restart, smix, space, mesh, ierr)
Definition: mix.F90:679
subroutine, public mix_init(smix, namespace, space, der, d1, d2, def_, func_type_, prefix_)
Initialise mix_t instance.
Definition: mix.F90:268
subroutine, public mix_end(smix)
Definition: mix.F90:556
subroutine, public mix_clear(smix)
Definition: mix.F90:541
subroutine, public modelmb_sym_all_states(space, mesh, st)
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:272
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
this module contains the low-level part of the output system
Definition: output_low.F90:117
subroutine, public output_modelmb(outp, namespace, space, dir, gr, ions, iter, st)
this module contains the output system
Definition: output.F90:117
logical function, public output_needs_current(outp, states_are_real)
Definition: output.F90:993
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
Definition: output.F90:507
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:625
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:554
logical function, public clean_stop(comm)
returns true if a file named stop exists
Definition: restart.F90:335
integer, parameter, public restart_flag_mix
Definition: restart.F90:188
integer, parameter, public restart_flag_rho
Definition: restart.F90:188
integer, parameter, public restart_flag_vhxc
Definition: restart.F90:188
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:595
logical function, public scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, verbosity, iters_done)
Definition: scf.F90:1219
subroutine write_dipole(st, hm, space, dipole, iunit, namespace)
Definition: scf.F90:1639
subroutine scf_update_initial_quantity(scf, hm, criterion)
Update the quantity at the begining of a SCF cycle.
Definition: scf.F90:1577
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:1600
subroutine, public scf_state_info(namespace, st)
Definition: scf.F90:1539
subroutine, public scf_print_mem_use(namespace)
Definition: scf.F90:1557
subroutine, public scf_mix_clear(scf)
Definition: scf.F90:578
integer, parameter, public verb_full
Definition: scf.F90:204
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:1299
integer, parameter, public verb_compact
Definition: scf.F90:204
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
Definition: scf.F90:255
subroutine, public scf_end(scf)
Definition: scf.F90:548
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:827
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:871
subroutine, public scf_start(scf, namespace, space, gr, ions, st, ks, hm, outp, verbosity)
Preparation of the SCF cycle.
Definition: scf.F90:680
logical pure function, public smear_is_semiconducting(this)
Definition: smear.F90:838
pure logical function, public states_are_real(st)
This module defines routines to write information about states.
subroutine, public states_elec_write_eigenvalues(nst, st, space, kpoints, error, st_start, compact, iunit, namespace)
write the eigenvalues for some states to a file.
subroutine, public states_elec_write_gaps(iunit, st, space)
calculate gaps and write to a file.
subroutine, public states_elec_write_bandstructure(dir, namespace, nst, st, ions, mesh, kpoints, phase, vec_pot, vec_pot_var)
calculate and write the bandstructure
subroutine, public states_elec_fermi(st, namespace, mesh, compute_spin)
calculate the Fermi level for the states in this object
real(real64) function, public states_elec_eigenvalues_sum(st, alt_eig)
function to calculate the eigenvalues sum using occupations as weights
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_dump(restart, space, st, mesh, kpoints, ierr, iter, lr, verbose)
subroutine, public states_elec_load_rho(restart, 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:120
subroutine, public output_pressure(iunit, space_dim, total_stress_tensor)
Definition: stress.F90:1121
subroutine, public stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
This computes the total stress on the lattice.
Definition: stress.F90:188
subroutine, public output_stress(iunit, space_dim, stress_tensors, all_terms)
Definition: stress.F90:1059
subroutine, public symmetries_write_info(this, space, iunit, namespace)
Definition: symmetries.F90:606
type(type_t), public type_float
Definition: types.F90:135
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:225
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_system_t), public units_inp
the units systems for reading and writing
This module is intended to contain simple general-purpose utility functions and procedures.
Definition: utils.F90:120
subroutine, public output_dipole(dipole, ndim, iunit, namespace)
Definition: utils.F90:281
subroutine, public v_ks_write_info(ks, iunit, namespace)
Definition: v_ks.F90:659
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:1472
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:748
Tkatchenko-Scheffler pairwise method for van der Waals (vdW, dispersion) interactions.
Definition: vdw_ts.F90:121
subroutine, public vdw_ts_write_c6ab(this, ions, dir, fname, namespace)
Definition: vdw_ts.F90:553
subroutine, public vtau_mixer_end(mixer, smix)
Definition: vtau_mixer.F90:189
subroutine, public vtau_mixer_init_auxmixer(namespace, mixer, smix, hm, np, nspin)
Definition: vtau_mixer.F90:152
subroutine, public vtau_mixer_set_vout(mixer, hm)
Definition: vtau_mixer.F90:202
subroutine, public vtau_mixer_get_vnew(mixer, hm)
Definition: vtau_mixer.F90:228
subroutine, public vtau_mixer_clear(mixer, smix)
Definition: vtau_mixer.F90:176
subroutine, public vtau_mixer_set_vin(mixer, hm)
Definition: vtau_mixer.F90:215
This module provices a simple timer class which can be used to trigger the writing of a restart file ...
Definition: walltimer.F90:123
logical function, public walltimer_alarm(comm, print)
indicate whether time is up
Definition: walltimer.F90:305
integer, parameter, public xc_family_nc_mgga
integer, parameter, public func_c
Definition: xc.F90:116
integer, parameter, public oep_level_full
Definition: xc_oep.F90:174
integer, parameter, public oep_level_kli
Definition: xc_oep.F90:174
subroutine scf_write_static(dir, fname)
Definition: rdmft.F90:584
subroutine create_convergence_file(dir, fname)
Definition: scf.F90:789
subroutine scf_write_iter(namespace)
Definition: scf.F90:1113
subroutine write_convergence_file(dir, fname)
Definition: scf.F90:1180
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
Stores all communicators and groups.
Definition: multicomm.F90:208
output handler class
Definition: output_low.F90:166
some variables used for the SCF cycle
Definition: scf.F90:210
abstract class for states
The states_elec_t class contains all electronic wave functions.
batches of electronic states
Definition: wfs_elec.F90:141
int true(void)