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