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