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
93
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
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_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)
214 call crit%set_pointers(scf%energy_diff, scf%energy_in)
216 call crit%set_pointers(scf%abs_dens_diff, st%qtot)
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 end if
374
375 !%Variable SCFCalculateStress
376 !%Type logical
377 !%Default no
378 !%Section SCF
379 !%Description
380 !% This variable controls whether the stress on the lattice is
381 !% calculated at the end of a self-consistent iteration. The
382 !% default is no.
383 !%End
384 call parse_variable(namespace, 'SCFCalculateStress', .false. , scf%calc_stress)
385
386 !%Variable SCFCalculateDipole
387 !%Type logical
388 !%Section SCF
389 !%Description
390 !% This variable controls whether the dipole is calculated at the
391 !% end of a self-consistent iteration. For finite systems the
392 !% default is yes. For periodic systems the default is no, unless
393 !% an electric field is being applied in a periodic direction.
394 !% The single-point Berry`s phase approximation is used for
395 !% periodic directions. Ref:
396 !% E Yaschenko, L Fu, L Resca, and R Resta, <i>Phys. Rev. B</i> <b>58</b>, 1222-1229 (1998).
397 !%End
398 call parse_variable(namespace, 'SCFCalculateDipole', .not. space%is_periodic(), scf%calc_dipole)
399 if (allocated(hm%vberry)) scf%calc_dipole = .true.
400
401 !%Variable SCFCalculateOrbitalMoments
402 !%Type logical
403 !%Default no
404 !%Section SCF
405 !%Description
406 !% This variable controls whether the local orbital angular moments are
407 !% calculated at the end of a self-consistent iteration. The
408 !% default is no. This is only applicable for spinors with SOC.
409 !%
410 !% This is computed by integrating around atom-centered spheres, and does not include the
411 !% interstitial contribution.
412 !% The same sphere are used as for the spin magnetic moments.
413 !%End
414 call parse_variable(namespace, 'SCFCalculateOrbitalMoments', .false. , scf%calc_orb_moments)
415 if((st%d%ispin /= spinors .or. space%dim /= 3) .and. scf%calc_orb_moments) then
416 message(1) = "Orbital moments are only implemented for spinors and in 3D."
417 call messages_fatal(1, namespace=namespace)
418 end if
419 if (scf%calc_orb_moments .and. .not. (hm%ep%reltype == spin_orbit &
420 .or. hm%ep%reltype == fully_relativistic_zora)) then
421 message(1) = "Orbital moments are only available with SOC."
422 call messages_fatal(1, namespace=namespace)
423 end if
424 if(gr%use_curvilinear .and. scf%calc_orb_moments) then
425 call messages_not_implemented("Orbital angular moments with curvilinear coordinates")
426 end if
427
428 !%Variable SCFCalculatePartialCharges
429 !%Type logical
430 !%Default no
431 !%Section SCF
432 !%Description
433 !% (Experimental) This variable controls whether partial charges
434 !% are calculated at the end of a self-consistent iteration.
435 !%End
436 call parse_variable(namespace, 'SCFCalculatePartialCharges', .false., scf%calc_partial_charges)
437 if (scf%calc_partial_charges) call messages_experimental('SCFCalculatePartialCharges', namespace=namespace)
438
439 rmin = ions%min_distance()
440
441 !%Variable LocalMagneticMomentsSphereRadius
442 !%Type float
443 !%Section Output
444 !%Description
445 !% The local magnetic moments are calculated by integrating the
446 !% magnetization density in spheres centered around each atom.
447 !% This variable controls the radius of the spheres.
448 !% The default is half the minimum distance between two atoms
449 !% in the input coordinates, or 100 a.u. if there is only one atom (for isolated systems).
450 !%End
451 call parse_variable(namespace, 'LocalMagneticMomentsSphereRadius', min(m_half*rmin, lmm_r_single_atom), scf%lmm_r, &
452 unit=units_inp%length)
453 ! this variable is also used in td/td_write.F90
454
455 scf%forced_finish = .false.
456
457 pop_sub(scf_init)
458 end subroutine scf_init
459
460
461 ! ---------------------------------------------------------
462 subroutine scf_end(scf)
463 type(scf_t), intent(inout) :: scf
464
465 class(convergence_criterion_t), pointer :: crit
466 type(criterion_iterator_t) :: iter
467
468 push_sub(scf_end)
469
470 call eigensolver_end(scf%eigens)
471
472 if(scf%mix_field /= option__mixfield__none) call mix_end(scf%smix)
473
474 nullify(scf%mixfield)
475
476 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none) then
477 call lda_u_mixer_end(scf%lda_u_mix, scf%smix)
478 call vtau_mixer_end(scf%vtau_mix, scf%smix)
479 end if
480
481 call iter%start(scf%criterion_list)
482 do while (iter%has_next())
483 crit => iter%get_next()
484 safe_deallocate_p(crit)
485 end do
486
487 pop_sub(scf_end)
488 end subroutine scf_end
489
490
491 ! ---------------------------------------------------------
492 subroutine scf_mix_clear(scf)
493 type(scf_t), intent(inout) :: scf
494
495 push_sub(scf_mix_clear)
496
497 call mix_clear(scf%smix)
498
499 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none) then
500 call lda_u_mixer_clear(scf%lda_u_mix, scf%smix)
501 call vtau_mixer_clear(scf%vtau_mix, scf%smix)
502 end if
503
504 pop_sub(scf_mix_clear)
505 end subroutine scf_mix_clear
506
507 ! ---------------------------------------------------------
509 subroutine scf_load(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, restart_load)
510 type(scf_t), intent(inout) :: scf
511 type(namespace_t), intent(in) :: namespace
512 type(electron_space_t), intent(in) :: space
513 type(grid_t), intent(inout) :: gr
514 type(ions_t), intent(in) :: ions
515 type(partner_list_t), intent(in) :: ext_partners
516 type(states_elec_t), intent(inout) :: st
517 type(v_ks_t), intent(inout) :: ks
518 type(hamiltonian_elec_t), intent(inout) :: hm
519 type(restart_t), intent(in) :: restart_load
520
521 integer :: ierr, is
522
523 push_sub(scf_load)
524
525 if (restart_load%has_flag(restart_flag_rho)) then
526 ! Load density and used it to recalculated the KS potential.
527 call states_elec_load_rho(restart_load, st, gr, ierr)
528 if (ierr /= 0) then
529 message(1) = 'Unable to read density. Density will be calculated from states.'
530 call messages_warning(1, namespace=namespace)
531 else
532 if (bitand(ks%xc_family, xc_family_oep) == 0) then
533 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
534 else
535 if (.not. restart_load%has_flag(restart_flag_vhxc) .and. ks%oep%level /= oep_level_full) then
536 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
537 end if
538 end if
539 end if
540 end if
541
542 if (restart_load%has_flag(restart_flag_vhxc)) then
543 call hm%ks_pot%load(restart_load, gr, ierr)
544 if (ierr /= 0) then
545 message(1) = 'Unable to read Vhxc. Vhxc will be calculated from states.'
546 call messages_warning(1, namespace=namespace)
547 else
548 call hm%update(gr, namespace, space, ext_partners)
549 if (bitand(ks%xc_family, xc_family_oep) /= 0) then
550 if (ks%oep%level == oep_level_full) then
551 do is = 1, st%d%nspin
552 ks%oep%vxc(1:gr%np, is) = hm%ks_pot%vhxc(1:gr%np, is) - hm%ks_pot%vhartree(1:gr%np)
553 end do
554 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners)
555 end if
556 end if
557 end if
558 end if
559
560 if (restart_load%has_flag(restart_flag_mix)) then
561 if (scf%mix_field == option__mixfield__density .or. scf%mix_field == option__mixfield__potential) then
562 call mix_load(namespace, restart_load, scf%smix, gr, ierr)
563 if (ierr /= 0) then
564 message(1) = "Unable to read mixing information. Mixing will start from scratch."
565 call messages_warning(1, namespace=namespace)
566 end if
567 end if
568 end if
569
570 if(hm%lda_u_level /= dft_u_none) then
571 call lda_u_load(restart_load, hm%lda_u, st, hm%energy%dft_u, ierr)
572 if (ierr /= 0) then
573 message(1) = "Unable to read DFT+U information. DFT+U data will be calculated from states."
574 call messages_warning(1, namespace=namespace)
575 end if
576
577 ! As v_ks_calc has already been called, we need to update hm%energy%int_dft_u
578 call v_ks_update_dftu_energy(ks, namespace, hm, st, hm%energy%int_dft_u)
579 end if
580
581 !TODO: Create a dedicated routine and call it from the initialize
582
583! if (present(outp) .and. st%system_grp%is_root()) then
584! call io_rm(STATIC_DIR //"info")
585! end if
586! end if
588 pop_sub(scf_load)
589 end subroutine scf_load
590
591 ! ---------------------------------------------------------
593 subroutine scf_start(scf, namespace, gr, ions, st, ks, hm, outp, verbosity)
594 type(scf_t), intent(inout) :: scf
595 type(namespace_t), intent(in) :: namespace
596 type(grid_t), intent(inout) :: gr
597 type(ions_t), intent(inout) :: ions
598 type(states_elec_t), intent(inout) :: st
599 type(v_ks_t), intent(inout) :: ks
600 type(hamiltonian_elec_t), intent(inout) :: hm
601 type(output_t), optional, intent(in) :: outp
602 integer, optional, intent(in) :: verbosity
603
604 integer :: ib, iqn
605
606 push_sub(scf_start)
607
608 if(scf%forced_finish) then
609 message(1) = "Previous clean stop, not doing SCF and quitting."
610 call messages_fatal(1, only_root_writes = .true., namespace=namespace)
611 end if
612
613 if (.not. hm%is_hermitian()) then
614 message(1) = "Trying to run a SCF calculation for a non-hermitian Hamiltonian. This is not supported."
615 call messages_fatal(1, namespace=namespace)
616 end if
617
618 scf%verbosity_ = optional_default(verbosity, verb_full)
619
620 scf%output_during_scf = .false.
621 scf%output_forces = .false.
622 scf%calc_current = .false.
623
624 if (present(outp)) then
625 ! if the user has activated output=stress but not SCFCalculateStress,
626 ! we assume that is implied
627 if (outp%what(option__output__stress)) then
628 scf%calc_stress = .true.
629 end if
630
631 scf%output_during_scf = outp%duringscf
632 scf%calc_current = output_needs_current(outp, states_are_real(st))
633
634 if (outp%duringscf .and. outp%what(option__output__forces)) then
635 scf%output_forces = .true.
636 end if
637 end if
638
639 safe_allocate(scf%rhoout(1:gr%np, 1:st%d%nspin))
640 safe_allocate(scf%rhoin (1:gr%np, 1:st%d%nspin))
641
642 call lalg_copy(gr%np, st%d%nspin, st%rho, scf%rhoin)
643 scf%rhoout = m_zero
644
645 if (scf%calc_force .or. scf%output_forces) then
646 !We store the Hxc potential for the contribution to the forces
647 safe_allocate(scf%vhxc_old(1:gr%np, 1:st%d%nspin))
648 call lalg_copy(gr%np, st%d%nspin, hm%ks_pot%vhxc, scf%vhxc_old)
649 end if
650
651
652 select case(scf%mix_field)
653 case(option__mixfield__potential)
654 call mixfield_set_vin(scf%mixfield, hm%ks_pot%vhxc)
655 call vtau_mixer_set_vin(scf%vtau_mix, hm)
656 case(option__mixfield__density)
657 call mixfield_set_vin(scf%mixfield, scf%rhoin)
658
659 case(option__mixfield__states)
660
661 ! There is a ICE with foss2022a-serial. I am changing to allocate - NTD
662 allocate(wfs_elec_t::scf%psioutb (st%group%block_start:st%group%block_end, st%d%kpt%start:st%d%kpt%end))
663
664 do iqn = st%d%kpt%start, st%d%kpt%end
665 do ib = st%group%block_start, st%group%block_end
666 call st%group%psib(ib, iqn)%copy_to(scf%psioutb(ib, iqn))
667 end do
668 end do
669
670 end select
671
672 call lda_u_update_occ_matrices(hm%lda_u, namespace, gr, st, hm%phase, hm%energy)
673 ! If we use DFT+U, we also have do mix it
674 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none) then
675 call lda_u_mixer_set_vin(hm%lda_u, scf%lda_u_mix)
676 end if
677
678 call create_convergence_file(static_dir, "convergence")
679
680 if ( scf%verbosity_ /= verb_no ) then
681 if(scf%max_iter > 0) then
682 write(message(1),'(a)') 'Info: Starting SCF iteration.'
683 else
684 write(message(1),'(a)') 'Info: No SCF iterations will be done.'
685 ! we cannot tell whether it is converged.
686 scf%finish = .false.
687 end if
688 call messages_info(1, namespace=namespace)
689 end if
690
691 scf%converged_current = .false.
692 scf%matvec = 0
693
694 pop_sub(scf_start)
695
696 contains
697
698 ! -----------------------------------------------------
699
700 subroutine create_convergence_file(dir, fname)
701 character(len=*), intent(in) :: dir
702 character(len=*), intent(in) :: fname
703
704 integer :: iunit
705 character(len=12) :: label
706 if(st%system_grp%is_root()) then
707 call io_mkdir(dir, namespace)
708 iunit = io_open(trim(dir) // "/" // trim(fname), namespace, action='write')
709 write(iunit, '(a)', advance = 'no') '#iter energy '
710 label = 'energy_diff'
711 write(iunit, '(1x,a)', advance = 'no') label
712 label = 'abs_dens'
713 write(iunit, '(1x,a)', advance = 'no') label
714 label = 'rel_dens'
715 write(iunit, '(1x,a)', advance = 'no') label
716 label = 'abs_ev'
717 write(iunit, '(1x,a)', advance = 'no') label
718 label = 'rel_ev'
719 write(iunit, '(1x,a)', advance = 'no') label
720 if (bitand(ks%xc_family, xc_family_oep) /= 0 .and. ks%theory_level /= hartree_fock &
721 .and. ks%theory_level /= generalized_kohn_sham_dft) then
722 if (ks%oep%level == oep_level_full) then
723 label = 'OEP norm2ss'
724 write(iunit, '(1x,a)', advance = 'no') label
725 end if
726 end if
727 write(iunit,'(a)') ''
728 call io_close(iunit)
729 end if
730
731 end subroutine create_convergence_file
732
733 end subroutine scf_start
734
735 ! ---------------------------------------------------------
737 subroutine scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, &
738 verbosity, iters_done, restart_dump)
739 type(scf_t), intent(inout) :: scf
740 type(namespace_t), intent(in) :: namespace
741 type(electron_space_t), intent(in) :: space
742 type(multicomm_t), intent(in) :: mc
743 type(grid_t), intent(inout) :: gr
744 type(ions_t), intent(inout) :: ions
745 type(partner_list_t), intent(in) :: ext_partners
746 type(states_elec_t), intent(inout) :: st
747 type(v_ks_t), intent(inout) :: ks
748 type(hamiltonian_elec_t), intent(inout) :: hm
749 type(output_t), optional, intent(in) :: outp
750 integer, optional, intent(in) :: verbosity
751 integer, optional, intent(out) :: iters_done
752 type(restart_t), optional, intent(in) :: restart_dump
753
754 integer :: iter
755 logical :: completed
756
757 push_sub(scf_run)
758
759 call scf_start(scf, namespace, gr, ions, st, ks, hm, outp, verbosity)
760
761 ! SCF cycle
762 do iter = 1, scf%max_iter
763
764 call scf_iter(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, iter, outp, &
765 restart_dump)
766
767 completed = scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, iters_done)
768
769 if(scf%forced_finish .or. completed) then
770 exit
771 end if
772 end do
773
774 if (.not.scf%forced_finish) then
775 ! this is only executed if the computation has converged
776 call scf_finish(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, iter, outp)
777 end if
778
779 pop_sub(scf_run)
780 end subroutine scf_run
781
782 ! ---------------------------------------------------------
783 subroutine scf_iter(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, iter, outp, &
784 restart_dump)
785 type(scf_t), intent(inout) :: scf
786 type(namespace_t), intent(in) :: namespace
787 type(electron_space_t), intent(in) :: space
788 type(multicomm_t), intent(in) :: mc
789 type(grid_t), intent(inout) :: gr
790 type(ions_t), intent(inout) :: ions
791 type(partner_list_t), intent(in) :: ext_partners
792 type(states_elec_t), intent(inout) :: st
793 type(v_ks_t), intent(inout) :: ks
794 type(hamiltonian_elec_t), intent(inout) :: hm
795 integer, intent(in) :: iter
796 type(output_t), optional, intent(in) :: outp
797 type(restart_t), optional, intent(in) :: restart_dump
798
799 integer :: iqn, ib, ierr
800 class(convergence_criterion_t), pointer :: crit
801 type(criterion_iterator_t) :: iterator
802 logical :: is_crit_conv
803 real(real64) :: etime, itime
804
805 push_sub(scf_iter)
806
807 call profiling_in("SCF_CYCLE")
808 itime = loct_clock()
809
810 ! this initialization seems redundant but avoids improper optimization at -O3 by PGI 7 on chum,
811 ! which would cause a failure of testsuite/linear_response/04-vib_modes.03-vib_modes_fd.inp
812 scf%eigens%converged = 0
813
814 ! keep the information about the spectrum up to date, needed e.g. for Chebyshev expansion for imaginary time
815 call hm%update_span(gr%spacing(1:space%dim), minval(st%eigenval(:, :)), namespace)
816
817 !We update the quantities at the begining of the scf cycle
818 if (iter == 1) then
819 scf%evsum_in = states_elec_eigenvalues_sum(st)
820 end if
821 call iterator%start(scf%criterion_list)
822 do while (iterator%has_next())
823 crit => iterator%get_next()
824 call scf_update_initial_quantity(scf, hm, crit)
825 end do
826
827 if (scf%calc_force .or. scf%output_forces) then
828 !Used for computing the imperfect convegence contribution to the forces
829 scf%vhxc_old(1:gr%np, 1:st%d%nspin) = hm%ks_pot%vhxc(1:gr%np, 1:st%d%nspin)
830 end if
831
832 !We check if the system is coupled with a partner that requires self-consistency
833 ! if(hamiltonian_has_scf_partner(hm)) then
834 if (allocated(hm%vberry)) then
835 !In this case, v_Hxc is frozen and we do an internal SCF loop over the
836 ! partners that require SCF
837 ks%frozen_hxc = .true.
838 ! call perform_scf_partners()
839 call berry_perform_internal_scf(scf%berry, namespace, space, scf%eigens, gr, st, hm, iter, ks, ions, ext_partners)
840 !and we unfreeze the potential once finished
841 ks%frozen_hxc = .false.
842 else
843 scf%eigens%converged = 0
844 call scf%eigens%run(namespace, gr, st, hm, space, ext_partners, iter)
845 end if
846
847 scf%matvec = scf%matvec + scf%eigens%matvec
848
849 ! occupations
850 call states_elec_fermi(st, namespace, gr)
851 call lda_u_update_occ_matrices(hm%lda_u, namespace, gr, st, hm%phase, hm%energy)
852
853 ! compute output density, potential (if needed) and eigenvalues sum
854 call density_calc(st, gr, st%rho)
855
856 call lalg_copy(gr%np, st%d%nspin, st%rho, scf%rhoout)
857
858 select case (scf%mix_field)
859 case (option__mixfield__potential)
860 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
861 call mixfield_set_vout(scf%mixfield, hm%ks_pot%vhxc)
862 call vtau_mixer_set_vout(scf%vtau_mix, hm)
863 case (option__mixfield__density)
864 call mixfield_set_vout(scf%mixfield, scf%rhoout)
865 case(option__mixfield__states)
866 do iqn = st%d%kpt%start, st%d%kpt%end
867 do ib = st%group%block_start, st%group%block_end
868 call st%group%psib(ib, iqn)%copy_data_to(gr%np, scf%psioutb(ib, iqn))
869 end do
870 end do
871 end select
872
873 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none) then
874 call lda_u_mixer_set_vout(hm%lda_u, scf%lda_u_mix)
875 endif
876
877 ! recalculate total energy
878 call energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit = -1)
879
880 if (present(outp)) then
881 ! compute forces only if requested
882 if (outp%duringscf .and. outp%what_now(option__output__forces, iter)) then
883 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old=scf%vhxc_old)
884 end if
885 end if
886
887 !We update the quantities at the end of the scf cycle
888 call iterator%start(scf%criterion_list)
889 do while (iterator%has_next())
890 crit => iterator%get_next()
891 call scf_update_diff_quantity(scf, hm, st, gr, scf%rhoout, scf%rhoin, crit)
892 end do
893
894 ! are we finished?
895 scf%converged_last = scf%converged_current
896
897 scf%converged_current = scf%check_conv .and. &
898 (.not. scf%conv_eigen_error .or. all(scf%eigens%converged >= st%nst_conv))
899 !Loop over the different criteria
900 call iterator%start(scf%criterion_list)
901 do while (iterator%has_next())
902 crit => iterator%get_next()
903 call crit%is_converged(is_crit_conv)
904 scf%converged_current = scf%converged_current .and. is_crit_conv
905 end do
906
907 ! only finish if the convergence criteria are fulfilled in two
908 ! consecutive iterations
909 scf%finish = scf%converged_last .and. scf%converged_current
910
911 etime = loct_clock() - itime
912 call scf_write_iter(namespace)
913
914 ! mixing
915 select case (scf%mix_field)
916 case (option__mixfield__density)
917 ! mix input and output densities and compute new potential
918 call mixing(namespace, scf%smix)
919 call mixfield_get_vnew(scf%mixfield, st%rho)
920 ! Mixing updated st%rho on the host only; refresh the GPU density buffer so
921 ! the GPU XC path does not evaluate vxc from the unmixed density.
923 ! for spinors, having components 3 or 4 be negative is not unphysical
924 if (minval(st%rho(1:gr%np, 1:st%d%spin_channels)) < -1e-6_real64) then
925 write(message(1),*) 'Negative density after mixing. Minimum value = ', &
926 minval(st%rho(1:gr%np, 1:st%d%spin_channels))
927 call messages_warning(1, namespace=namespace)
928 end if
929 call lda_u_mixer_get_vnew(hm%lda_u, scf%lda_u_mix, st)
930 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
931
932 case (option__mixfield__potential)
933 ! mix input and output potentials
934 call mixing(namespace, scf%smix)
935 call mixfield_get_vnew(scf%mixfield, hm%ks_pot%vhxc)
936 call lda_u_mixer_get_vnew(hm%lda_u, scf%lda_u_mix, st)
937 call vtau_mixer_get_vnew(scf%vtau_mix, hm)
938 call hamiltonian_elec_update_pot(hm, gr)
939
940 case(option__mixfield__states)
941 do iqn = st%d%kpt%start, st%d%kpt%end
942 do ib = st%group%block_start, st%group%block_end
943 call batch_axpby(gr%np, mix_coefficient(scf%smix), scf%psioutb(ib, iqn), &
944 m_one - mix_coefficient(scf%smix), st%group%psib(ib, iqn))
945 end do
946 end do
947 call density_calc(st, gr, st%rho)
948 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
949
950 case (option__mixfield__none)
951 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_current=scf%output_during_scf)
952 end select
953
954 ! Are we asked to stop? (Whenever Fortran is ready for signals, this should go away)
955 scf%forced_finish = clean_stop(mc%master_comm) .or. walltimer_alarm(mc%master_comm)
956
957 if (scf%finish .and. st%modelmbparticles%nparticle > 0) then
958 call modelmb_sym_all_states(space, gr, st)
959 end if
960
961 if (present(outp) .and. present(restart_dump)) then
962 ! save restart information
963
964 if ( (scf%finish .or. restart_walltime_period_alarm(mc%master_comm) &
965 .or. iter == scf%max_iter .or. scf%forced_finish) ) then
966
967 call states_elec_dump(restart_dump, space, st, gr, hm%kpoints, ierr, iter=iter)
968 if (ierr /= 0) then
969 message(1) = 'Unable to write states wavefunctions.'
970 call messages_warning(1, namespace=namespace)
971 end if
972
973 call states_elec_dump_rho(restart_dump, st, gr, ierr, iter=iter)
974 if (ierr /= 0) then
975 message(1) = 'Unable to write density.'
976 call messages_warning(1, namespace=namespace)
977 end if
978
979 if(hm%lda_u_level /= dft_u_none) then
980 call lda_u_dump(restart_dump, namespace, hm%lda_u, st, gr, ierr)
981 if (ierr /= 0) then
982 message(1) = 'Unable to write DFT+U information.'
983 call messages_warning(1, namespace=namespace)
984 end if
985 end if
986
987 select case (scf%mix_field)
988 case (option__mixfield__density)
989 call mix_dump(namespace, restart_dump, scf%smix, gr, ierr)
990 if (ierr /= 0) then
991 message(1) = 'Unable to write mixing information.'
992 call messages_warning(1, namespace=namespace)
993 end if
994 case (option__mixfield__potential)
995 call hm%ks_pot%dump(restart_dump, gr, ierr)
996 if (ierr /= 0) then
997 message(1) = 'Unable to write Vhxc.'
998 call messages_warning(1, namespace=namespace)
999 end if
1000
1001 call mix_dump(namespace, restart_dump, scf%smix, gr, ierr)
1002 if (ierr /= 0) then
1003 message(1) = 'Unable to write mixing information.'
1004 call messages_warning(1, namespace=namespace)
1005 end if
1006 end select
1007
1008 end if
1009 end if
1010
1011 call write_convergence_file(static_dir, "convergence")
1012
1013 call profiling_out("SCF_CYCLE")
1014
1015 pop_sub(scf_iter)
1016 contains
1017
1018 ! ---------------------------------------------------------
1019 subroutine scf_write_iter(namespace)
1020 type(namespace_t), intent(in) :: namespace
1021
1022 character(len=50) :: str
1023 real(real64) :: dipole(1:space%dim)
1024
1025 push_sub(scf_run.scf_write_iter)
1026
1027 if ( scf%verbosity_ == verb_full ) then
1028
1029 write(str, '(a,i5)') 'SCF CYCLE ITER #' ,iter
1030 call messages_print_with_emphasis(msg=trim(str), namespace=namespace)
1031 write(message(1),'(a,es15.8,2(a,es9.2))') ' etot = ', units_from_atomic(units_out%energy, hm%energy%total), &
1032 ' abs_ev = ', units_from_atomic(units_out%energy, scf%evsum_diff), &
1033 ' rel_ev = ', scf%evsum_diff/(abs(scf%evsum_out)+1e-20)
1034 write(message(2),'(a,es15.2,2(a,es9.2))') &
1035 ' ediff = ', scf%energy_diff, ' abs_dens = ', scf%abs_dens_diff, &
1036 ' rel_dens = ', scf%abs_dens_diff/st%qtot
1037 call messages_info(2, namespace=namespace)
1038
1039 write(message(1),'(a,i0)') 'Matrix vector products: ', scf%eigens%matvec
1040 write(message(2),'(a,i0)') 'Converged eigenvectors: ', sum(scf%eigens%converged(1:st%nik))
1041 call messages_info(2, namespace=namespace)
1042 call states_elec_write_eigenvalues(st%nst, st, space, hm%kpoints, scf%eigens%diff, compact = .true., namespace=namespace)
1043
1044 if (allocated(hm%vberry)) then
1045 call calc_dipole(dipole, space, gr, st, ions)
1046 call write_dipole(st, hm, space, dipole, namespace=namespace)
1047 end if
1048
1049 if(st%d%ispin > unpolarized) then
1050 call compute_and_write_magnetic_moments(gr, st, hm%phase, hm%ep, ions, scf%lmm_r, namespace=namespace)
1051 end if
1052
1053 if(hm%lda_u_level == dft_u_acbn0) then
1054 call lda_u_write_u(hm%lda_u, namespace=namespace)
1055 call lda_u_write_v(hm%lda_u, namespace=namespace)
1056 end if
1057
1058 write(message(1),'(a)') ''
1059 write(message(2),'(a,i5,a,f14.2)') 'Elapsed time for SCF step ', iter,':', etime
1060 call messages_info(2, namespace=namespace)
1061
1062 call scf_print_mem_use(namespace)
1063
1064 call messages_print_with_emphasis(namespace=namespace)
1065
1066 end if
1067
1068 if ( scf%verbosity_ == verb_compact ) then
1069 write(message(1),'(a,i4,a,es15.8, a,es9.2, a, f7.1, a)') &
1070 'iter ', iter, &
1071 ' : etot ', units_from_atomic(units_out%energy, hm%energy%total), &
1072 ' : abs_dens', scf%abs_dens_diff, &
1073 ' : etime ', etime, 's'
1074 call messages_info(1, namespace=namespace)
1075 end if
1076
1077 pop_sub(scf_run.scf_write_iter)
1078 end subroutine scf_write_iter
1079
1080
1081 ! -----------------------------------------------------
1082 subroutine write_convergence_file(dir, fname)
1083 character(len=*), intent(in) :: dir
1084 character(len=*), intent(in) :: fname
1085
1086 integer :: iunit
1087
1088 if(st%system_grp%is_root()) then ! this the absolute master writes
1089 call io_mkdir(dir, namespace)
1090 iunit = io_open(trim(dir) // "/" // trim(fname), namespace, action='write', position='append')
1091 write(iunit, '(i5,es18.8)', advance = 'no') iter, units_from_atomic(units_out%energy, hm%energy%total)
1092 call iterator%start(scf%criterion_list)
1093 do while (iterator%has_next())
1094 crit => iterator%get_next()
1095 select type (crit)
1096 type is (energy_criterion_t)
1097 write(iunit, '(es13.5)', advance = 'no') units_from_atomic(units_out%energy, crit%val_abs)
1098 type is (density_criterion_t)
1099 write(iunit, '(2es13.5)', advance = 'no') crit%val_abs, crit%val_rel
1100 type is (eigenval_criterion_t)
1101 write(iunit, '(es13.5)', advance = 'no') units_from_atomic(units_out%energy, crit%val_abs)
1102 write(iunit, '(es13.5)', advance = 'no') crit%val_rel
1103 class default
1104 assert(.false.)
1105 end select
1106 end do
1107 if (bitand(ks%xc_family, xc_family_oep) /= 0 .and. ks%theory_level /= hartree_fock &
1108 .and. ks%theory_level /= generalized_kohn_sham_dft) then
1109 if (ks%oep%level == oep_level_full) then
1110 write(iunit, '(es13.5)', advance = 'no') ks%oep%norm2ss
1111 end if
1112 end if
1113 write(iunit,'(a)') ''
1114 call io_close(iunit)
1115 end if
1116 end subroutine write_convergence_file
1117
1118 end subroutine scf_iter
1119
1120 logical function scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, &
1121 iters_done) result(completed)
1122 type(scf_t), intent(inout) :: scf
1123 type(namespace_t), intent(in) :: namespace
1124 type(electron_space_t), intent(in) :: space
1125 type(grid_t), intent(inout) :: gr
1126 type(ions_t), intent(inout) :: ions
1127 type(states_elec_t), intent(inout) :: st
1128 type(v_ks_t), intent(inout) :: ks
1129 type(hamiltonian_elec_t), intent(inout) :: hm
1130 integer, intent(in) :: iter
1131 type(output_t), optional, intent(in) :: outp
1132 integer, optional, intent(out) :: iters_done
1133
1134 character(len=MAX_PATH_LEN) :: dirname
1135 integer(int64) :: what_i
1136
1137 push_sub(scf_iter_finish)
1138
1139 completed = .false.
1140
1141 if(scf%finish) then
1142 if(present(iters_done)) iters_done = iter
1143 if(scf%verbosity_ >= verb_compact) then
1144 write(message(1), '(a, i4, a)') 'Info: SCF converged in ', iter, ' iterations'
1145 write(message(2), '(a)') ''
1146 call messages_info(2, namespace=namespace)
1147 end if
1148 completed = .true.
1149 pop_sub(scf_iter_finish)
1150 return
1151 end if
1152 if (present(outp)) then
1153 if (any(outp%what) .and. outp%duringscf) then
1154 do what_i = lbound(outp%what, 1), ubound(outp%what, 1)
1155 if (outp%what_now(what_i, iter)) then
1156 write(dirname,'(a,a,i4.4)') trim(outp%iter_dir),"scf.", iter
1157 call output_all(outp, namespace, space, dirname, gr, ions, iter, st, hm, ks)
1158 call output_modelmb(outp, namespace, space, dirname, gr, ions, iter, st)
1159 exit
1160 end if
1161 end do
1162 end if
1163 end if
1164
1165 ! save information for the next iteration
1166 call lalg_copy(gr%np, st%d%nspin, st%rho, scf%rhoin)
1167
1168 ! restart mixing
1169 if (scf%mix_field /= option__mixfield__none) then
1170 if (scf%smix%ns_restart > 0) then
1171 if (mix_scheme(scf%smix) /= option__mixingscheme__broyden_adaptive .and. &
1172 mod(iter, scf%smix%ns_restart) == 0) then
1173 message(1) = "Info: restarting mixing."
1174 call messages_info(1, namespace=namespace)
1175 call scf_mix_clear(scf)
1176 end if
1177 end if
1178 end if
1179
1180 select case(scf%mix_field)
1181 case(option__mixfield__potential)
1182 call mixfield_set_vin(scf%mixfield, hm%ks_pot%vhxc(1:gr%np, 1:st%d%nspin))
1183 call vtau_mixer_set_vin(scf%vtau_mix, hm)
1184 case (option__mixfield__density)
1185 call mixfield_set_vin(scf%mixfield, scf%rhoin)
1186 end select
1187
1188 !If we use LDA+U, we also have do mix it
1189 if (scf%mix_field /= option__mixfield__states .and. scf%mix_field /= option__mixfield__none) then
1190 call lda_u_mixer_set_vin(hm%lda_u, scf%lda_u_mix)
1191 end if
1192
1193 ! check if debug mode should be enabled or disabled on the fly
1194 call io_debug_on_the_fly(namespace)
1195
1196 pop_sub(scf_iter_finish)
1197 end function scf_iter_finish
1198
1199 ! ---------------------------------------------------------
1200 subroutine scf_finish(scf, namespace, space, gr, ions, ext_partners, st, ks, hm, iter, outp)
1201 type(scf_t), intent(inout) :: scf
1202 type(namespace_t), intent(in) :: namespace
1203 type(electron_space_t), intent(in) :: space
1204 type(grid_t), intent(inout) :: gr
1205 type(ions_t), intent(inout) :: ions
1206 type(partner_list_t), intent(in) :: ext_partners
1207 type(states_elec_t), intent(inout) :: st
1208 type(v_ks_t), intent(inout) :: ks
1209 type(hamiltonian_elec_t), intent(inout) :: hm
1210 integer, intent(in) :: iter
1211 type(output_t), optional, intent(in) :: outp
1212
1213 integer :: iqn, ib
1214 class(convergence_criterion_t), pointer :: crit
1215 type(criterion_iterator_t) :: iterator
1216
1217
1218 push_sub(scf_finish)
1219
1220 ! Compute the KS potential corresponding to the final density
1221 ! This is critical for getting consistent TD calculations
1222 if ((scf%max_iter > 0 .and. scf%mix_field == option__mixfield__potential) .or. scf%calc_current) then
1223 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
1224 calc_current=scf%calc_current)
1225 end if
1226
1227 select case(scf%mix_field)
1228 case(option__mixfield__states)
1229
1230 do iqn = st%d%kpt%start, st%d%kpt%end
1231 do ib = st%group%block_start, st%group%block_end
1232 call scf%psioutb(ib, iqn)%end()
1233 end do
1234 end do
1235
1236 ! There is a ICE with foss2022a-serial. I am changing to deallocate - NTD
1237 deallocate(scf%psioutb)
1238 end select
1239
1240 safe_deallocate_a(scf%rhoout)
1241 safe_deallocate_a(scf%rhoin)
1242
1243 if (scf%max_iter > 0 .and. any(scf%eigens%converged < st%nst)) then
1244 write(message(1),'(a)') 'Some of the states are not fully converged!'
1245 if (all(scf%eigens%converged >= st%nst_conv)) then
1246 write(message(2),'(a)') 'But all requested states to converge are converged.'
1247 call messages_info(2, namespace=namespace)
1248 else
1249 if(scf%eigens%es_type == rs_chebyshev) then
1250 write(message(2),'(a)') 'With the Chebyshev filtering eigensolver, it usually helps to'
1251 write(message(3),'(a)') 'increase ExtraStates and set ExtraStatesToConverge to the number'
1252 write(message(4),'(a)') 'of states to be converged.'
1253 call messages_warning(4, namespace=namespace)
1254 else
1255 call messages_warning(1, namespace=namespace)
1256 end if
1257 end if
1258 end if
1259
1260 if (.not.scf%finish) then
1261 write(message(1), '(a,i4,a)') 'SCF *not* converged after ', iter - 1, ' iterations.'
1262 if(scf%eigens%es_type == rs_chebyshev) then
1263 write(message(2),'(a)') 'With the Chebyshev filtering eigensolver, it usually helps to'
1264 write(message(3),'(a)') 'increase ExtraStates to improve convergence.'
1265 call messages_warning(3, namespace=namespace)
1266 else
1267 call messages_warning(1, namespace=namespace)
1268 end if
1269 end if
1270
1271 write(message(1), '(a,i10)') 'Info: Number of matrix-vector products: ', scf%matvec
1272 call messages_info(1)
1273
1274 if (scf%calc_force) then
1275 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old=scf%vhxc_old)
1276 end if
1277
1278 if (scf%calc_stress) call stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
1279
1280 ! Update the eigenvalues, to match the KS potential that just got recomputed
1281 if (scf%mix_field == option__mixfield__potential) then
1282 call energy_calc_eigenvalues(namespace, hm, gr%der, st)
1283 call states_elec_fermi(st, namespace, gr)
1284 end if
1285
1286 if(present(outp)) then
1287 ! output final information
1288 call scf_write_static(static_dir, "info")
1289 call output_all(outp, namespace, space, static_dir, gr, ions, -1, st, hm, ks)
1290 call output_modelmb(outp, namespace, space, static_dir, gr, ions, -1, st)
1291 end if
1292
1293 if (space%is_periodic() .and. st%nik > st%d%nspin) then
1294 if (bitand(hm%kpoints%method, kpoints_path) /= 0) then
1295 call states_elec_write_bandstructure(static_dir, namespace, st%nst, st, &
1296 ions, gr, hm%kpoints, hm%phase, vec_pot = hm%hm_base%uniform_vector_potential, &
1297 vec_pot_var = hm%hm_base%vector_potential)
1298 end if
1299 end if
1300
1301 if (ks%vdw%vdw_correction == option__vdwcorrection__vdw_ts) then
1302 call vdw_ts_write_c6ab(ks%vdw%vdw_ts, ions, static_dir, 'c6ab_eff', namespace)
1303 end if
1304
1305 safe_deallocate_a(scf%vhxc_old)
1306
1307 pop_sub(scf_finish)
1308
1309 contains
1310
1311 ! ---------------------------------------------------------
1312 subroutine scf_write_static(dir, fname)
1313 character(len=*), intent(in) :: dir, fname
1314
1315 integer :: iunit
1316 real(real64) :: dipole(1:space%dim)
1317 real(real64) :: ex_virial
1318
1319 push_sub(scf_run.scf_write_static)
1320
1321 if(st%system_grp%is_root()) then ! this the absolute master writes
1322 call io_mkdir(dir, namespace)
1323 iunit = io_open(trim(dir) // "/" // trim(fname), namespace, action='write')
1324
1325 call grid_write_info(gr, iunit=iunit)
1326
1327 call symmetries_write_info(gr%symm, space, iunit=iunit)
1328
1329 if (space%is_periodic()) then
1330 call hm%kpoints%write_info(iunit=iunit)
1331 write(iunit,'(1x)')
1332 end if
1333
1334 call v_ks_write_info(ks, iunit=iunit)
1335
1336 ! scf information
1337 if(scf%finish) then
1338 write(iunit, '(a, i4, a)')'SCF converged in ', iter, ' iterations'
1339 else
1340 write(iunit, '(a)') 'SCF *not* converged!'
1341 end if
1342 write(iunit, '(1x)')
1343
1344 if(any(scf%eigens%converged < st%nst)) then
1345 write(iunit,'(a)') 'Some of the states are not fully converged!'
1346 if (all(scf%eigens%converged >= st%nst_conv)) then
1347 write(iunit,'(a)') 'But all requested states to converge are converged.'
1348 end if
1349 end if
1350
1351 call states_elec_write_eigenvalues(st%nst, st, space, hm%kpoints, iunit=iunit)
1352 write(iunit, '(1x)')
1353
1354 if (space%is_periodic()) then
1355 call states_elec_write_gaps(iunit, st, space)
1356 write(iunit, '(1x)')
1357 end if
1358
1359 write(iunit, '(3a)') 'Energy [', trim(units_abbrev(units_out%energy)), ']:'
1360 else
1361 iunit = -1
1362 end if
1363
1364 call energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full = .true.)
1365
1366 if(st%system_grp%is_root()) write(iunit, '(1x)')
1367 if(st%d%ispin > unpolarized) then
1368 call compute_and_write_magnetic_moments(gr, st, hm%phase, hm%ep, ions, scf%lmm_r, iunit=iunit, &
1369 calc_orb_moments=scf%calc_orb_moments)
1370 if (st%system_grp%is_root()) write(iunit, '(1x)')
1371 end if
1372
1373 if(st%d%ispin == spinors .and. space%dim == 3 .and. &
1374 (ks%theory_level == kohn_sham_dft .or. ks%theory_level == generalized_kohn_sham_dft) ) then
1375 call write_total_xc_torque(iunit, gr, hm%ks_pot%vxc, st)
1376 if(st%system_grp%is_root()) write(iunit, '(1x)')
1377 end if
1378
1379 if(hm%lda_u_level == dft_u_acbn0) then
1380 call lda_u_write_u(hm%lda_u, iunit=iunit)
1381 call lda_u_write_v(hm%lda_u, iunit=iunit)
1382 if(st%system_grp%is_root()) write(iunit, '(1x)')
1383 end if
1384
1385 if(scf%calc_dipole) then
1386 call calc_dipole(dipole, space, gr, st, ions)
1387 call write_dipole(st, hm, space, dipole, iunit=iunit)
1388 end if
1389
1390 ! This only works when we do not have a correlation part
1391 if(ks%theory_level == kohn_sham_dft .and. &
1392 hm%xc%functional(func_c,1)%family == xc_family_none .and. st%d%ispin /= spinors &
1393 .and. .not. space%is_periodic()) then
1394 call energy_calc_virial_ex(gr%der, hm%ks_pot%vxc, st, ex_virial)
1395
1396 if (st%system_grp%is_root()) then
1397 write(iunit, '(3a)') 'Virial relation for exchange [', trim(units_abbrev(units_out%energy)), ']:'
1398 write(iunit,'(a,es14.6)') "Energy from the orbitals ", units_from_atomic(units_out%energy, hm%energy%exchange)
1399 write(iunit,'(a,es14.6)') "Energy from the potential (virial) ", units_from_atomic(units_out%energy, ex_virial)
1400 write(iunit, '(1x)')
1401 end if
1402 end if
1403
1404 if(st%system_grp%is_root()) then
1405 if(scf%max_iter > 0) then
1406 write(iunit, '(a)') 'Convergence:'
1407 call iterator%start(scf%criterion_list)
1408 do while (iterator%has_next())
1409 crit => iterator%get_next()
1410 call crit%write_info(iunit)
1411 end do
1412 write(iunit,'(1x)')
1413 end if
1414 ! otherwise, these values are uninitialized, and unknown.
1415
1416 if (bitand(ks%xc_family, xc_family_oep) /= 0 .and. ks%theory_level /= hartree_fock &
1417 .and. ks%theory_level /= generalized_kohn_sham_dft) then
1418 if ((ks%oep_photon%level == oep_level_full) .or. (ks%oep_photon%level == oep_level_kli)) then
1419 write(iunit, '(a)') 'Photon observables:'
1420 write(iunit, '(6x, a, es15.8,a,es15.8,a)') 'Photon number = ', ks%oep_photon%pt%number(1)
1421 write(iunit, '(6x, a, es15.8,a,es15.8,a)') 'Photon ex. = ', ks%oep_photon%pt%ex
1422 write(iunit,'(1x)')
1423 end if
1424 end if
1425
1426 if (scf%calc_force) call forces_write_info(iunit, ions, dir, namespace)
1427
1428 if (scf%calc_stress) then
1429 call output_stress(iunit, space%periodic_dim, st%stress_tensors, all_terms=.false.)
1430 call output_pressure(iunit, space%periodic_dim, st%stress_tensors%total)
1431 end if
1432
1433 end if
1434
1435 if(scf%calc_partial_charges) then
1436 call partial_charges_compute_and_print_charges(gr, st, ions, iunit)
1437 end if
1438
1439 if(st%system_grp%is_root()) then
1440 call io_close(iunit)
1441 end if
1442
1443 pop_sub(scf_run.scf_write_static)
1444 end subroutine scf_write_static
1445
1446 end subroutine scf_finish
1447
1448 ! ---------------------------------------------------------
1449 subroutine scf_state_info(namespace, st)
1450 type(namespace_t), intent(in) :: namespace
1451 class(states_abst_t), intent(in) :: st
1452
1453 push_sub(scf_state_info)
1454
1455 if (states_are_real(st)) then
1456 call messages_write('Info: SCF using real wavefunctions.')
1457 else
1458 call messages_write('Info: SCF using complex wavefunctions.')
1459 end if
1460 call messages_info(namespace=namespace)
1461
1462 pop_sub(scf_state_info)
1463
1464 end subroutine scf_state_info
1465
1466 ! ---------------------------------------------------------
1467 subroutine scf_print_mem_use(namespace)
1468 type(namespace_t), intent(in) :: namespace
1469 real(real64) :: mem
1470 real(real64) :: mem_tmp
1471
1472 push_sub(scf_print_mem_use)
1473
1474 if(conf%report_memory) then
1475 mem = loct_get_memory_usage()/(1024.0_real64**2)
1476 call mpi_world%allreduce(mem, mem_tmp, 1, mpi_double_precision, mpi_sum)
1477 mem = mem_tmp
1478 write(message(1),'(a,f14.2)') 'Memory usage [Mbytes] :', mem
1479 call messages_info(1, namespace=namespace)
1480 end if
1481
1482 pop_sub(scf_print_mem_use)
1483 end subroutine scf_print_mem_use
1484
1485 ! --------------------------------------------------------
1487 subroutine scf_update_initial_quantity(scf, hm, criterion)
1488 type(scf_t), intent(inout) :: scf
1489 type(hamiltonian_elec_t), intent(in) :: hm
1490 class(convergence_criterion_t), intent(in) :: criterion
1491
1493
1494 select type (criterion)
1495 type is (energy_criterion_t)
1496 scf%energy_in = hm%energy%total
1497 type is (density_criterion_t)
1498 !Do nothing here
1499 type is (eigenval_criterion_t)
1500 !Setting of the value is done in the scf_update_diff_quantity routine
1501 class default
1502 assert(.false.)
1503 end select
1504
1506 end subroutine scf_update_initial_quantity
1507
1508 ! --------------------------------------------------------
1510 subroutine scf_update_diff_quantity(scf, hm, st, gr, rhoout, rhoin, criterion)
1511 type(scf_t), intent(inout) :: scf
1512 type(hamiltonian_elec_t), intent(in) :: hm
1513 type(states_elec_t), intent(in) :: st
1514 type(grid_t), intent(in) :: gr
1515 real(real64), intent(in) :: rhoout(:,:), rhoin(:,:)
1516 class(convergence_criterion_t), intent(in) :: criterion
1517
1518 integer :: is
1519 real(real64), allocatable :: tmp(:)
1520
1521 push_sub(scf_update_diff_quantity)
1522
1523 select type (criterion)
1524 type is (energy_criterion_t)
1525 scf%energy_diff = abs(hm%energy%total - scf%energy_in)
1526
1527 type is (density_criterion_t)
1528 scf%abs_dens_diff = m_zero
1529 safe_allocate(tmp(1:gr%np))
1530 do is = 1, st%d%nspin
1531 tmp(:) = abs(rhoin(1:gr%np, is) - rhoout(1:gr%np, is))
1532 scf%abs_dens_diff = scf%abs_dens_diff + dmf_integrate(gr, tmp)
1533 end do
1534 safe_deallocate_a(tmp)
1535
1536 type is (eigenval_criterion_t)
1537 scf%evsum_out = states_elec_eigenvalues_sum(st)
1538 scf%evsum_diff = abs(scf%evsum_out - scf%evsum_in)
1539 scf%evsum_in = scf%evsum_out
1540
1541 class default
1542 assert(.false.)
1543 end select
1546 end subroutine scf_update_diff_quantity
1547
1548 ! ---------------------------------------------------------
1549 subroutine write_dipole(st, hm, space, dipole, iunit, namespace)
1550 type(states_elec_t), intent(in) :: st
1551 type(hamiltonian_elec_t), intent(in) :: hm
1552 type(electron_space_t), intent(in) :: space
1553 real(real64), intent(in) :: dipole(:)
1554 integer, optional, intent(in) :: iunit
1555 type(namespace_t), optional, intent(in) :: namespace
1556
1557 push_sub(write_dipole)
1558
1559 if(st%system_grp%is_root()) then
1560 call output_dipole(dipole, space%dim, iunit=iunit, namespace=namespace)
1561
1562 if (space%is_periodic()) then
1563 message(1) = "Defined only up to quantum of polarization (e * lattice vector)."
1564 message(2) = "Single-point Berry's phase method only accurate for large supercells."
1565 call messages_info(2, iunit=iunit, namespace=namespace)
1566
1567 if (hm%kpoints%full%npoints > 1) then
1568 message(1) = &
1569 "WARNING: Single-point Berry's phase method for dipole should not be used when there is more than one k-point."
1570 message(2) = "Instead, finite differences on k-points (not yet implemented) are needed."
1571 call messages_info(2, iunit=iunit, namespace=namespace)
1572 end if
1573
1574 if(.not. smear_is_semiconducting(st%smear)) then
1575 message(1) = "Single-point Berry's phase dipole calculation not correct without integer occupations."
1576 call messages_info(1, iunit=iunit, namespace=namespace)
1577 end if
1578 end if
1579
1580 call messages_info(iunit=iunit, namespace=namespace)
1581 end if
1583 pop_sub(write_dipole)
1584 end subroutine write_dipole
1585
1587 subroutine scf_set_lower_bound_is_known(scf, known_lower_bound)
1588 type(scf_t), intent(inout) :: scf
1589 logical, intent(in) :: known_lower_bound
1590
1591 call scf%eigens%set_lower_bound_is_known(known_lower_bound)
1592 end subroutine scf_set_lower_bound_is_known
1593
1594end module scf_oct_m
1595
1596
1597!! Local Variables:
1598!! mode: f90
1599!! coding: utf-8
1600!! End:
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:188
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:118
subroutine, public berry_perform_internal_scf(this, namespace, space, eigensolver, gr, st, hm, iter, ks, ions, ext_partners)
Definition: berry.F90:186
subroutine, public berry_init(this, namespace)
Definition: berry.F90:161
subroutine, public calc_dipole(dipole, space, mesh, st, ions)
Definition: berry.F90:252
subroutine, public criteria_factory_init(list, namespace, check_conv)
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
subroutine, public 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 fully_relativistic_zora
Definition: epot.F90:168
subroutine, public forces_write_info(iunit, ions, dir, namespace)
Definition: forces.F90:594
subroutine, public forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old, t, dt)
Definition: forces.F90:340
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:279
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:519
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:223
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:895
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:214
subroutine, public write_total_xc_torque(iunit, mesh, vxc, st)
Definition: magnetic.F90:567
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:826
real(real64) pure function, public mix_coefficient(this)
Definition: mix.F90:820
subroutine, public mixing(namespace, smix)
Main entry-point to SCF mixer.
Definition: mix.F90:846
subroutine, public mix_get_field(this, mixfield)
Definition: mix.F90:838
subroutine, public mix_dump(namespace, restart, smix, mesh, ierr)
Definition: mix.F90:591
subroutine, public mix_init(smix, namespace, space, der, d1, d2, def_, func_type_, prefix_)
Initialise mix_t instance.
Definition: mix.F90:269
subroutine, public mix_load(namespace, restart, smix, mesh, ierr)
Definition: mix.F90:690
subroutine, public mix_end(smix)
Definition: mix.F90:568
subroutine, public mix_clear(smix)
Definition: mix.F90:552
subroutine, public modelmb_sym_all_states(space, mesh, st)
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:272
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
this module contains the low-level part of the output system
Definition: output_low.F90:117
subroutine, public output_modelmb(outp, namespace, space, dir, gr, ions, iter, st)
this module contains the output system
Definition: output.F90:117
logical function, public output_needs_current(outp, states_are_real)
Definition: output.F90:981
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
Definition: output.F90:495
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:337
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:1296
subroutine, public scf_set_lower_bound_is_known(scf, known_lower_bound)
Set the flag lower_bound_is_known.
Definition: scf.F90:1683
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:605
subroutine write_dipole(st, hm, space, dipole, iunit, namespace)
Definition: scf.F90:1645
subroutine scf_update_initial_quantity(scf, hm, criterion)
Update the quantity at the begining of a SCF cycle.
Definition: scf.F90:1583
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:1606
subroutine, public scf_state_info(namespace, st)
Definition: scf.F90:1545
subroutine, public scf_print_mem_use(namespace)
Definition: scf.F90:1563
subroutine, public scf_mix_clear(scf)
Definition: scf.F90:588
subroutine, public scf_start(scf, namespace, gr, ions, st, ks, hm, outp, verbosity)
Preparation of the SCF cycle.
Definition: scf.F90:689
integer, parameter, public verb_full
Definition: scf.F90:207
integer, parameter, public verb_compact
Definition: scf.F90:207
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
Definition: scf.F90:260
subroutine, public scf_end(scf)
Definition: scf.F90:558
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:834
subroutine, public scf_iter(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, iter, outp, restart_dump)
Definition: scf.F90:880
logical function, public scf_iter_finish(scf, namespace, space, gr, ions, st, ks, hm, iter, outp, iters_done)
Definition: scf.F90:1217
logical pure function, public smear_is_semiconducting(this)
Definition: smear.F90:1042
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:1145
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:1080
subroutine, public symmetries_write_info(this, space, iunit, namespace)
Definition: symmetries.F90:615
type(type_t), parameter, public type_float
Definition: types.F90:135
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:225
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_system_t), public units_inp
the units systems for reading and writing
This module is intended to contain simple general-purpose utility functions and procedures.
Definition: utils.F90:120
subroutine, public output_dipole(dipole, ndim, iunit, namespace)
Definition: utils.F90:281
subroutine, public v_ks_write_info(ks, iunit, namespace)
Definition: v_ks.F90:665
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:1538
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:754
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:174
integer, parameter, public oep_level_kli
Definition: xc_oep.F90:174
subroutine scf_write_static(dir, fname)
Definition: rdmft.F90:586
subroutine create_convergence_file(dir, fname)
Definition: scf.F90:796
subroutine scf_write_iter(namespace)
Definition: scf.F90:1115
subroutine write_convergence_file(dir, fname)
Definition: scf.F90:1178
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:213
abstract class for states
The states_elec_t class contains all electronic wave functions.
batches of electronic states
Definition: wfs_elec.F90:141
int true(void)