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