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