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