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