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 call messages_warning(1, namespace=namespace)
1213 end if
1214 end if
1215
1216 if (.not.scf%finish) then
1217 write(message(1), '(a,i4,a)') 'SCF *not* converged after ', iter - 1, ' iterations.'
1218 call messages_warning(1, namespace=namespace)
1219 end if
1220
1221 write(message(1), '(a,i10)') 'Info: Number of matrix-vector products: ', scf%matvec
1222 call messages_info(1)
1223
1224 if (scf%calc_force) then
1225 call forces_calculate(gr, namespace, ions, hm, ext_partners, st, ks, vhxc_old=scf%vhxc_old)
1226 end if
1227
1228 if (scf%calc_stress) call stress_calculate(namespace, gr, hm, st, ions, ks, ext_partners)
1229
1230 ! Update the eigenvalues, to match the KS potential that just got recomputed
1231 if (scf%mix_field == option__mixfield__potential) then
1232 call energy_calc_eigenvalues(namespace, hm, gr%der, st)
1233 call states_elec_fermi(st, namespace, gr)
1234 end if
1235
1236 if(present(outp)) then
1237 ! output final information
1238 call scf_write_static(static_dir, "info")
1239 call output_all(outp, namespace, space, static_dir, gr, ions, -1, st, hm, ks)
1240 call output_modelmb(outp, namespace, space, static_dir, gr, ions, -1, st)
1241 end if
1242
1243 if (space%is_periodic() .and. st%nik > st%d%nspin) then
1244 if (bitand(hm%kpoints%method, kpoints_path) /= 0) then
1245 call states_elec_write_bandstructure(static_dir, namespace, st%nst, st, &
1246 ions, gr, hm%kpoints, hm%phase, vec_pot = hm%hm_base%uniform_vector_potential, &
1247 vec_pot_var = hm%hm_base%vector_potential)
1248 end if
1249 end if
1250
1251 if (ks%vdw%vdw_correction == option__vdwcorrection__vdw_ts) then
1252 call vdw_ts_write_c6ab(ks%vdw%vdw_ts, ions, static_dir, 'c6ab_eff', namespace)
1253 end if
1254
1255 safe_deallocate_a(scf%vhxc_old)
1256
1257 pop_sub(scf_finish)
1259 contains
1260
1261 ! ---------------------------------------------------------
1262 subroutine scf_write_static(dir, fname)
1263 character(len=*), intent(in) :: dir, fname
1264
1265 integer :: iunit
1266 real(real64) :: dipole(1:space%dim)
1267 real(real64) :: ex_virial
1268
1269 push_sub(scf_run.scf_write_static)
1270
1271 if(mpi_world%is_root()) then ! this the absolute master writes
1272 call io_mkdir(dir, namespace)
1273 iunit = io_open(trim(dir) // "/" // trim(fname), namespace, action='write')
1274
1275 call grid_write_info(gr, iunit=iunit)
1276
1277 call symmetries_write_info(gr%symm, space, iunit=iunit)
1278
1279 if (space%is_periodic()) then
1280 call hm%kpoints%write_info(iunit=iunit)
1281 write(iunit,'(1x)')
1282 end if
1283
1284 call v_ks_write_info(ks, iunit=iunit)
1285
1286 ! scf information
1287 if(scf%finish) then
1288 write(iunit, '(a, i4, a)')'SCF converged in ', iter, ' iterations'
1289 else
1290 write(iunit, '(a)') 'SCF *not* converged!'
1291 end if
1292 write(iunit, '(1x)')
1293
1294 if(any(scf%eigens%converged < st%nst)) then
1295 write(iunit,'(a)') 'Some of the states are not fully converged!'
1296 if (all(scf%eigens%converged >= st%nst_conv)) then
1297 write(iunit,'(a)') 'But all requested states to converge are converged.'
1298 end if
1299 end if
1300
1301 call states_elec_write_eigenvalues(st%nst, st, space, hm%kpoints, iunit=iunit)
1302 write(iunit, '(1x)')
1303
1304 if (space%is_periodic()) then
1305 call states_elec_write_gaps(iunit, st, space)
1306 write(iunit, '(1x)')
1307 end if
1308
1309 write(iunit, '(3a)') 'Energy [', trim(units_abbrev(units_out%energy)), ']:'
1310 else
1311 iunit = -1
1312 end if
1313
1314 call energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full = .true.)
1315
1316 if(mpi_world%is_root()) write(iunit, '(1x)')
1317 if(st%d%ispin > unpolarized) then
1318 call write_magnetic_moments(gr, st, ions, gr%der%boundaries, scf%lmm_r, iunit=iunit)
1319 if (mpi_world%is_root()) write(iunit, '(1x)')
1320 end if
1321
1322 if(st%d%ispin == spinors .and. space%dim == 3 .and. &
1323 (ks%theory_level == kohn_sham_dft .or. ks%theory_level == generalized_kohn_sham_dft) ) then
1324 call write_total_xc_torque(iunit, gr, hm%ks_pot%vxc, st)
1325 if(mpi_world%is_root()) write(iunit, '(1x)')
1326 end if
1327
1328 if(hm%lda_u_level == dft_u_acbn0) then
1329 call lda_u_write_u(hm%lda_u, iunit=iunit)
1330 call lda_u_write_v(hm%lda_u, iunit=iunit)
1331 if(mpi_world%is_root()) write(iunit, '(1x)')
1332 end if
1333
1334 if(scf%calc_dipole) then
1335 call calc_dipole(dipole, space, gr, st, ions)
1336 call write_dipole(st, hm, space, dipole, iunit=iunit)
1337 end if
1338
1339 ! This only works when we do not have a correlation part
1340 if(ks%theory_level == kohn_sham_dft .and. &
1341 hm%xc%functional(func_c,1)%family == xc_family_none .and. st%d%ispin /= spinors &
1342 .and. .not. space%is_periodic()) then
1343 call energy_calc_virial_ex(gr%der, hm%ks_pot%vxc, st, ex_virial)
1344
1345 if (mpi_world%is_root()) then
1346 write(iunit, '(3a)') 'Virial relation for exchange [', trim(units_abbrev(units_out%energy)), ']:'
1347 write(iunit,'(a,es14.6)') "Energy from the orbitals ", units_from_atomic(units_out%energy, hm%energy%exchange)
1348 write(iunit,'(a,es14.6)') "Energy from the potential (virial) ", units_from_atomic(units_out%energy, ex_virial)
1349 write(iunit, '(1x)')
1350 end if
1351 end if
1352
1353 if(mpi_world%is_root()) then
1354 if(scf%max_iter > 0) then
1355 write(iunit, '(a)') 'Convergence:'
1356 call iterator%start(scf%criterion_list)
1357 do while (iterator%has_next())
1358 crit => iterator%get_next()
1359 call crit%write_info(iunit)
1360 end do
1361 write(iunit,'(1x)')
1362 end if
1363 ! otherwise, these values are uninitialized, and unknown.
1364
1365 if (bitand(ks%xc_family, xc_family_oep) /= 0 .and. ks%theory_level /= hartree_fock &
1366 .and. ks%theory_level /= generalized_kohn_sham_dft) then
1367 if ((ks%oep_photon%level == oep_level_full) .or. (ks%oep_photon%level == oep_level_kli)) then
1368 write(iunit, '(a)') 'Photon observables:'
1369 write(iunit, '(6x, a, es15.8,a,es15.8,a)') 'Photon number = ', ks%oep_photon%pt%number(1)
1370 write(iunit, '(6x, a, es15.8,a,es15.8,a)') 'Photon ex. = ', ks%oep_photon%pt%ex
1371 write(iunit,'(1x)')
1372 end if
1373 end if
1374
1375 if (scf%calc_force) call forces_write_info(iunit, ions, dir, namespace)
1376
1377 if (scf%calc_stress) then
1378 call output_stress(iunit, space%periodic_dim, st%stress_tensors, all_terms=.false.)
1379 call output_pressure(iunit, space%periodic_dim, st%stress_tensors%total)
1380 end if
1381
1382 end if
1383
1384 if(scf%calc_partial_charges) then
1385 call partial_charges_compute_and_print_charges(gr, st, ions, iunit)
1386 end if
1387
1388 if(mpi_world%is_root()) then
1389 call io_close(iunit)
1390 end if
1391
1392 pop_sub(scf_run.scf_write_static)
1393 end subroutine scf_write_static
1394
1395 end subroutine scf_finish
1396
1397 ! ---------------------------------------------------------
1398 subroutine scf_state_info(namespace, st)
1399 type(namespace_t), intent(in) :: namespace
1400 class(states_abst_t), intent(in) :: st
1401
1402 push_sub(scf_state_info)
1403
1404 if (states_are_real(st)) then
1405 call messages_write('Info: SCF using real wavefunctions.')
1406 else
1407 call messages_write('Info: SCF using complex wavefunctions.')
1408 end if
1409 call messages_info(namespace=namespace)
1410
1411 pop_sub(scf_state_info)
1412
1413 end subroutine scf_state_info
1414
1415 ! ---------------------------------------------------------
1416 subroutine scf_print_mem_use(namespace)
1417 type(namespace_t), intent(in) :: namespace
1418 real(real64) :: mem
1419 real(real64) :: mem_tmp
1420
1421 push_sub(scf_print_mem_use)
1422
1423 if(conf%report_memory) then
1424 mem = loct_get_memory_usage()/(1024.0_real64**2)
1425 call mpi_world%allreduce(mem, mem_tmp, 1, mpi_double_precision, mpi_sum)
1426 mem = mem_tmp
1427 write(message(1),'(a,f14.2)') 'Memory usage [Mbytes] :', mem
1428 call messages_info(1, namespace=namespace)
1429 end if
1430
1431 pop_sub(scf_print_mem_use)
1432 end subroutine scf_print_mem_use
1433
1434 ! --------------------------------------------------------
1436 subroutine scf_update_initial_quantity(scf, hm, criterion)
1437 type(scf_t), intent(inout) :: scf
1438 type(hamiltonian_elec_t), intent(in) :: hm
1439 class(convergence_criterion_t), intent(in) :: criterion
1440
1442
1443 select type (criterion)
1444 type is (energy_criterion_t)
1445 scf%energy_in = hm%energy%total
1446 type is (density_criterion_t)
1447 !Do nothing here
1448 type is (eigenval_criterion_t)
1449 !Setting of the value is done in the scf_update_diff_quantity routine
1450 class default
1451 assert(.false.)
1452 end select
1453
1455 end subroutine scf_update_initial_quantity
1456
1457 ! --------------------------------------------------------
1459 subroutine scf_update_diff_quantity(scf, hm, st, gr, rhoout, rhoin, criterion)
1460 type(scf_t), intent(inout) :: scf
1461 type(hamiltonian_elec_t), intent(in) :: hm
1462 type(states_elec_t), intent(in) :: st
1463 type(grid_t), intent(in) :: gr
1464 real(real64), intent(in) :: rhoout(:,:), rhoin(:,:)
1465 class(convergence_criterion_t), intent(in) :: criterion
1466
1467 integer :: is
1468 real(real64), allocatable :: tmp(:)
1469
1470 push_sub(scf_update_diff_quantity)
1471
1472 select type (criterion)
1473 type is (energy_criterion_t)
1474 scf%energy_diff = abs(hm%energy%total - scf%energy_in)
1475
1476 type is (density_criterion_t)
1477 scf%abs_dens_diff = m_zero
1478 safe_allocate(tmp(1:gr%np))
1479 do is = 1, st%d%nspin
1480 tmp(:) = abs(rhoin(1:gr%np, is) - rhoout(1:gr%np, is))
1481 scf%abs_dens_diff = scf%abs_dens_diff + dmf_integrate(gr, tmp)
1482 end do
1483 safe_deallocate_a(tmp)
1484
1485 type is (eigenval_criterion_t)
1486 scf%evsum_out = states_elec_eigenvalues_sum(st)
1487 scf%evsum_diff = abs(scf%evsum_out - scf%evsum_in)
1488 scf%evsum_in = scf%evsum_out
1489
1490 class default
1491 assert(.false.)
1492 end select
1495 end subroutine scf_update_diff_quantity
1496
1497 ! ---------------------------------------------------------
1498 subroutine write_dipole(st, hm, space, dipole, iunit, namespace)
1499 type(states_elec_t), intent(in) :: st
1500 type(hamiltonian_elec_t), intent(in) :: hm
1501 type(electron_space_t), intent(in) :: space
1502 real(real64), intent(in) :: dipole(:)
1503 integer, optional, intent(in) :: iunit
1504 type(namespace_t), optional, intent(in) :: namespace
1505
1506 push_sub(write_dipole)
1507
1508 if(mpi_world%is_root()) then
1509 call output_dipole(dipole, space%dim, iunit=iunit, namespace=namespace)
1510
1511 if (space%is_periodic()) then
1512 message(1) = "Defined only up to quantum of polarization (e * lattice vector)."
1513 message(2) = "Single-point Berry's phase method only accurate for large supercells."
1514 call messages_info(2, iunit=iunit, namespace=namespace)
1515
1516 if (hm%kpoints%full%npoints > 1) then
1517 message(1) = &
1518 "WARNING: Single-point Berry's phase method for dipole should not be used when there is more than one k-point."
1519 message(2) = "Instead, finite differences on k-points (not yet implemented) are needed."
1520 call messages_info(2, iunit=iunit, namespace=namespace)
1521 end if
1522
1523 if(.not. smear_is_semiconducting(st%smear)) then
1524 message(1) = "Single-point Berry's phase dipole calculation not correct without integer occupations."
1525 call messages_info(1, iunit=iunit, namespace=namespace)
1526 end if
1527 end if
1528
1529 call messages_info(iunit=iunit, namespace=namespace)
1530 end if
1532 pop_sub(write_dipole)
1533 end subroutine write_dipole
1534
1536 pure subroutine scf_set_lower_bound_is_known(scf, known_lower_bound)
1537 type(scf_t), intent(inout) :: scf
1538 logical, intent(in) :: known_lower_bound
1539
1540 call scf%eigens%set_lower_bound_is_known(known_lower_bound)
1541 end subroutine scf_set_lower_bound_is_known
1542
1543end module scf_oct_m
1544
1545
1546!! Local Variables:
1547!! mode: f90
1548!! coding: utf-8
1549!! 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)
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:1632
subroutine write_dipole(st, hm, space, dipole, iunit, namespace)
Definition: scf.F90:1594
subroutine scf_update_initial_quantity(scf, hm, criterion)
Update the quantity at the begining of a SCF cycle.
Definition: scf.F90:1532
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:1555
subroutine, public scf_state_info(namespace, st)
Definition: scf.F90:1494
subroutine, public scf_print_mem_use(namespace)
Definition: scf.F90:1512
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)