Octopus
casida.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2012-2013 D. Strubbe
3!! Copyright (C) 2017-2018 J. Flick, S. Ohlmann
4!!
5!! This program is free software; you can redistribute it and/or modify
6!! it under the terms of the GNU General Public License as published by
7!! the Free Software Foundation; either version 2, or (at your option)
8!! any later version.
9!!
10!! This program is distributed in the hope that it will be useful,
11!! but WITHOUT ANY WARRANTY; without even the implied warranty of
12!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13!! GNU General Public License for more details.
14!!
15!! You should have received a copy of the GNU General Public License
16!! along with this program; if not, write to the Free Software
17!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18!! 02110-1301, USA.
19!!
20
21#include "global.h"
22
24
25module casida_oct_m
26 use batch_oct_m
29 use comm_oct_m
30 use debug_oct_m
35#ifdef HAVE_ELPA
36 use elpa
37#endif
40 use forces_oct_m
42 use global_oct_m
43 use grid_oct_m
45 use io_oct_m
47 use iso_c_binding
48 use, intrinsic :: iso_fortran_env
53 use lda_u_oct_m
54 use loct_oct_m
56 use mesh_oct_m
59 use mpi_oct_m
63 use parser_oct_m
64 use pblas_oct_m
65 use pcm_oct_m
74 use sort_oct_m
75 use space_oct_m
81 use unit_oct_m
83 use utils_oct_m
85 use v_ks_oct_m
86 use xc_oct_m
87 use xc_sic_oct_m
88 use xc_f03_lib_m
90
91 implicit none
92
93 private
94 public :: casida_run
95
96 integer, parameter :: &
97 CASIDA_EPS_DIFF = 1, &
100 casida_variational = 8, &
101 casida_casida = 16
102
103 integer, parameter :: &
104 SOLVER_ELPA = 1, &
106
108 type casida_t
109 private
110 integer :: type
111 ! !< CASIDA_VARIATIONAL | CASIDA_CASIDA
112
113 logical :: states_are_real
114 integer, allocatable :: n_occ(:)
115 integer, allocatable :: n_unocc(:)
116 integer :: nst
117 integer :: nik
118 integer :: space_dim
119 integer :: el_per_state
120 character(len=80) :: trandens
121 character(len=80) :: print_exst
122 real(real64) :: weight_thresh
123 logical :: triplet
124 logical :: calc_forces
125 logical :: calc_forces_kernel
126 logical :: calc_forces_scf
127 logical :: herm_conj
128 type(restart_t) :: restart_load
129 type(restart_t) :: restart_dump
130
131 logical, allocatable :: is_included(:,:,:)
132 integer :: n_pairs
133 type(states_pair_t), allocatable :: pair(:)
134
135 integer, allocatable :: index(:,:,:)
136 integer, allocatable :: ind(:)
137
138 real(real64), allocatable :: dmat(:,:)
139 real(real64), allocatable :: dmat_save(:,:)
140 complex(real64), allocatable :: zmat(:,:)
141 complex(real64), allocatable :: zmat_save(:,:)
142 real(real64), allocatable :: w(:)
143 real(real64), allocatable :: dtm(:, :)
144 complex(real64), allocatable :: ztm(:, :)
145 real(real64), allocatable :: f(:)
146 real(real64), allocatable :: s(:)
147
148 real(real64), allocatable :: rho(:,:)
149 real(real64), allocatable :: fxc(:,:,:)
150 real(real64) :: kernel_lrc_alpha
151 logical :: gga
152 real(real64), allocatable :: fxc_grad(:,:,:,:,:)
153 real(real64), allocatable :: fxc_grad_spin(:,:,:,:)
154
155 real(real64), allocatable :: dmat2(:,:)
156 complex(real64), allocatable :: zmat2(:,:)
157 real(real64), allocatable :: dlr_hmat2(:,:)
158 complex(real64), allocatable :: zlr_hmat2(:,:)
159 real(real64), allocatable :: forces(:,:,:)
160 real(real64), allocatable :: dw2(:)
161 real(real64), allocatable :: zw2(:)
162
163 ! variables for momentum-transfer-dependent calculation
164 logical :: qcalc
165 real(real64), allocatable :: qvector(:)
166 real(real64), allocatable :: qf(:)
167 real(real64), allocatable :: qf_avg(:)
168 integer :: avg_order
169
170 logical :: parallel_in_eh_pairs
171 logical :: parallel_in_domains
172 logical :: distributed_matrix
173 logical :: write_matrix
174 integer :: parallel_solver
175 type(mpi_grp_t) :: mpi_grp
176 logical :: fromScratch
177 logical :: has_photons
178 integer :: pt_nmodes
179 type(photon_mode_t), pointer :: photon_modes => null()
180
181 integer :: n, nb_rows, nb_cols, block_size
182 type(blacs_proc_grid_t) :: proc_grid
183 integer :: desc(BLACS_DLEN)
184 type(MPI_Datatype) :: darray
185 end type casida_t
186
188 private
189 integer :: qi
190 integer :: qa
191 integer :: qk
192 real(real64), allocatable :: dpot(:)
193 complex(real64), allocatable :: zpot(:)
194 end type casida_save_pot_t
195
196contains
197
198 subroutine casida_run(system, from_scratch)
199 class(*), intent(inout) :: system
200 logical, intent(in) :: from_scratch
201
202 push_sub(casida_run)
204 select type (system)
206 message(1) = "CalculationMode = casida not implemented for multi-system calculations"
207 call messages_fatal(1, namespace=system%namespace)
208 type is (electrons_t)
209 call casida_run_legacy(system, from_scratch)
210 end select
212 pop_sub(casida_run)
213 end subroutine casida_run
215 ! ---------------------------------------------------------
216 subroutine casida_run_legacy(sys, fromScratch)
217 type(electrons_t), intent(inout) :: sys
218 logical, intent(in) :: fromscratch
220 type(casida_t) :: cas
221 type(block_t) :: blk
222 integer :: idir, theorylevel, iatom, ierr, default_int
223 character(len=100) :: restart_filename
224 logical :: is_frac_occ
225 type(restart_t) :: gs_restart
228 call profiling_in('CASIDA')
229
230 if (sys%hm%pcm%run_pcm) then
231 call messages_not_implemented("PCM for CalculationMode /= gs or td", namespace=sys%namespace)
232 end if
234 if (sys%space%is_periodic()) then
235 message(1) = "Casida oscillator strengths will be incorrect in periodic systems."
236 call messages_warning(1, namespace=sys%namespace)
237 end if
239 if (kpoints_number(sys%kpoints) > 1) then
240 ! Hartree matrix elements may not be correct, not tested anyway. --DAS
241 call messages_not_implemented("Casida with k-points", namespace=sys%namespace)
242 end if
243 if (family_is_mgga_with_exc(sys%hm%xc)) then
244 call messages_not_implemented("Casida with MGGA and non-local terms", namespace=sys%namespace)
245 end if
246 if (sys%hm%lda_u_level /= dft_u_none) then
247 call messages_not_implemented("Casida with DFT+U", namespace=sys%namespace)
248 end if
249 if (sys%hm%theory_level == hartree_fock) then
250 call messages_not_implemented("Casida for Hartree-Fock", namespace=sys%namespace)
251 end if
252 if (sys%hm%theory_level == generalized_kohn_sham_dft) then
253 call messages_not_implemented("Casida for generalized Kohn-Sham", namespace=sys%namespace)
254 end if
256 message(1) = 'Info: Starting Casida linear-response calculation.'
257 call messages_info(1, namespace=sys%namespace)
258
259 call messages_print_with_emphasis(msg="XC Kernel level", namespace=sys%namespace)
260 call xc_write_fxc_info(sys%ks%xc, namespace=sys%namespace)
261 call xc_sic_write_info(sys%ks%sic, namespace=sys%namespace)
262 call messages_print_with_emphasis(namespace=sys%namespace)
264
265 call gs_restart%init(sys%namespace, restart_gs, restart_type_load, sys%mc, ierr, mesh=sys%gr, exact=.true.)
266 if (ierr == 0) then
267 call states_elec_look_and_load(gs_restart, sys%namespace, sys%space, sys%st, sys%gr, sys%kpoints, fixed_occ=.true.)
268 call gs_restart%end()
269 else
270 message(1) = "Previous gs calculation is required."
271 call messages_fatal(1, namespace=sys%namespace)
272 end if
274 cas%el_per_state = sys%st%smear%el_per_state
275 cas%nst = sys%st%nst
276 cas%nik = sys%st%nik
277 cas%space_dim = sys%space%dim
278 safe_allocate(cas%n_occ(1:sys%st%nik))
279 safe_allocate(cas%n_unocc(1:sys%st%nik))
280
281 call casida_count_pairs(sys%st, sys%namespace, cas%n_pairs, cas%n_occ, cas%n_unocc, cas%is_included, is_frac_occ)
282 select case (sys%st%d%ispin)
283 case (unpolarized, spinors)
284 write(message(1),'(a,i4,a)') "Info: Found", cas%n_occ(1), " occupied states."
285 write(message(2),'(a,i4,a)') "Info: Found", cas%n_unocc(1), " unoccupied states."
286 call messages_info(2, namespace=sys%namespace)
288 write(message(1),'(a,i4,a)') "Info: Found", cas%n_occ(1), " occupied states with spin up."
289 write(message(2),'(a,i4,a)') "Info: Found", cas%n_unocc(1), " unoccupied states with spin up."
290 write(message(3),'(a,i4,a)') "Info: Found", cas%n_occ(2), " occupied states with spin down."
291 write(message(4),'(a,i4,a)') "Info: Found", cas%n_unocc(2), " unoccupied states with spin down."
292 call messages_info(4, namespace=sys%namespace)
293 end select
294
295
296 ! setup Hamiltonian, without recalculating eigenvalues (use the ones from the restart information)
297 message(1) = 'Info: Setting up Hamiltonian.'
298 call messages_info(1, namespace=sys%namespace)
299 call v_ks_h_setup(sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st, sys%ks, &
300 sys%hm, calc_eigenval=.false.)
301
302 !%Variable CasidaTheoryLevel
303 !%Type flag
304 !%Section Linear Response::Casida
305 !%Default <tt>eps_diff + petersilka + lrtddft_casida</tt>
306 !%Description
307 !% Choose which electron-hole matrix-based theory levels to use in calculating excitation energies.
308 !% More than one may be used to take advantage of the significant commonality between the calculations.
309 !% <tt>variational</tt> and <tt>lrttdft_casida</tt> are not usable with complex wavefunctions.
310 !% Note the restart data saved by each theory level is compatible with all the others.
311 !%Option eps_diff 1
312 !% Difference of eigenvalues, <i>i.e.</i> independent-particle approximation.
313 !%Option petersilka 2
314 !% The Petersilka approximation uses only elements of the Tamm-Dancoff matrix between degenerate
315 !% transitions (if no degeneracy, this is just the diagonal elements). Also called the "single-pole" approximation.
316 !% This is acceptable if there is little mixing between single-particle transitions.
317 !% Ref: M Petersilka, UJ Gossmann, and EKU Gross, <i>Phys. Rev. Lett.</i> <b>76</b>, 1212 (1996);
318 !% T Grabo, M Petersilka,and EKU Gross, <i>Theochem</i> <b>501-502</b> 353 (2000).
319 !%Option tamm_dancoff 4
320 !% The Tamm-Dancoff approximation uses only occupied-unoccupied transitions and not
321 !% unoccupied-occupied transitions.
322 !% Ref: S Hirata and M Head-Gordon, <i>Chem. Phys. Lett.</i> <b>314</b>, 291 (1999).
323 !%Option variational 8
324 !% Second-order constrained variational theory CV(2)-DFT. Only applies to real wavefunctions.
325 !% Ref: T Ziegler, M Seth, M Krykunov, J Autschbach, and F Wang,
326 !% <i>J. Chem. Phys.</i> <b>130</b>, 154102 (2009).
327 !%Option lrtddft_casida 16
328 !% The full Casida method. Only applies to real wavefunctions.
329 !% Ref: C Jamorski, ME Casida, and DR Salahub, <i>J. Chem. Phys.</i> <b>104</b>, 5134 (1996)
330 !% and ME Casida, "Time-dependent density functional response theory for molecules,"
331 !% in <i>Recent Advances in Density Functional Methods</i>, edited by DE Chong, vol. 1
332 !% of <i>Recent Advances in Computational Chemistry</i>, pp. 155-192 (World Scientific,
333 !% Singapore, 1995).
334 !%End
335
336 call parse_variable(sys%namespace, 'CasidaTheoryLevel', casida_eps_diff + casida_petersilka + casida_casida, theorylevel)
337
338 if (states_are_complex(sys%st)) then
339 if ((bitand(theorylevel, casida_variational) /= 0 &
340 .or. bitand(theorylevel, casida_casida) /= 0)) then
341 message(1) = "Variational and full Casida theory levels do not apply to complex wavefunctions."
342 call messages_fatal(1, only_root_writes = .true., namespace=sys%namespace)
343 ! see section II.D of CV(2) paper regarding this assumption. Would be Eq. 30 with complex wfns.
344 end if
345 end if
346
347 ! This variable is documented in xc_oep_init.
348 call parse_variable(sys%namespace, 'EnablePhotons', .false., cas%has_photons)
349 cas%pt_nmodes = 0
350 if (cas%has_photons) then
351 call messages_experimental('EnablePhotons = yes', namespace=sys%namespace)
352 cas%photon_modes => sys%photons%modes
353 call photon_mode_set_n_electrons(cas%photon_modes, sys%st%qtot)
354 write(message(1), '(a,i7,a)') 'INFO: Solving Casida equation with ', &
355 cas%photon_modes%nmodes, ' photon modes.'
356 write(message(2), '(a)') 'as described in ACS Photonics 2019, 6, 11, 2757-2778.'
357 call messages_info(2, namespace=sys%namespace)
358 cas%pt_nmodes = cas%photon_modes%nmodes
359 end if
360
361 !%Variable CasidaTransitionDensities
362 !%Type string
363 !%Section Linear Response::Casida
364 !%Default write none
365 !%Description
366 !% Specifies which transition densities are to be calculated and written down. The
367 !% transition density for the many-body state <i>n</i> will be written to a file called
368 !% <tt>rho_0n</tt> prefixed by the theory level. Format is set by <tt>OutputFormat</tt>.
369 !%
370 !% This variable is a string in list form, <i>i.e.</i> expressions such as "1,2-5,8-15" are
371 !% valid.
372 !%End
373 call parse_variable(sys%namespace, 'CasidaTransitionDensities', "0", cas%trandens)
374
375 if (cas%trandens /= "0") then
376 call io_function_read_what_how_when(sys%namespace, sys%space, sys%outp%what,&
377 sys%outp%how, sys%outp%output_interval)
378 end if
379
380 !%Variable CasidaMomentumTransfer
381 !%Type block
382 !%Section Linear Response::Casida
383 !%Default 0
384 !%Description
385 !% Momentum-transfer vector for the calculation of the dynamic structure
386 !% factor. When this variable is set, the transition rates are determined
387 !% using an exponential operator instead of the normal dipole one.
388 !%End
389
390 safe_allocate(cas%qvector(1:cas%space_dim))
391 if (parse_block(sys%namespace, 'CasidaMomentumTransfer', blk) == 0) then
392 do idir = 1, cas%space_dim
393 call parse_block_float(blk, 0, idir - 1, cas%qvector(idir))
394 end do
395 call parse_block_end(blk)
396 call messages_experimental("IXS/EELS transition rate calculation", namespace=sys%namespace)
397 message(1) = "Info: Calculating IXS/EELS transition rates."
398 call messages_info(1, namespace=sys%namespace)
399 cas%qcalc = .true.
400
401 !%Variable CasidaQuadratureOrder
402 !%Type integer
403 !%Section Linear Response::Casida
404 !%Default 5
405 !%Description
406 !% Only applies if <tt>CasidaMomentumTransfer</tt> is nonzero.
407 !% Directionally averaged dynamic structure factor is calculated by
408 !% averaging over the results from a set of <math>\vec{q}</math>-vectors. The vectors
409 !% are generated using Gauss-Legendre quadrature scheme [see <i>e.g.</i>
410 !% K. Atkinson, <i>J. Austral. Math. Soc.</i> <b>23</b>, 332 (1982)], and this
411 !% variable determines the order of the scheme.
412 !%End
413 call parse_variable(sys%namespace, 'CasidaQuadratureOrder', 5, cas%avg_order)
414 else
415 cas%qvector(:) = m_zero
416 cas%qcalc = .false.
417 end if
418
419 !%Variable CasidaCalcTriplet
420 !%Type logical
421 !%Section Linear Response::Casida
422 !%Default false
423 !%Description
424 !% For a non-spin-polarized ground state, singlet or triplet excitations can be calculated
425 !% using different matrix elements. Default is to calculate singlets. This variable has no
426 !% effect for a spin-polarized calculation.
427 !%End
428 if (sys%st%d%ispin == unpolarized) then
429 call parse_variable(sys%namespace, 'CasidaCalcTriplet', .false., cas%triplet)
430 else
431 cas%triplet = .false.
432 end if
433
434 if (cas%triplet) then
435 message(1) = "Info: Using triplet kernel. Oscillator strengths will be for spin magnetic-dipole field."
436 call messages_info(1, namespace=sys%namespace)
437 end if
438
439 !%Variable CasidaHermitianConjugate
440 !%Type logical
441 !%Section Linear Response::Casida
442 !%Default false
443 !%Description
444 !% The Casida matrix is Hermitian, so it should not matter whether we calculate the upper or
445 !% lower diagonal. Numerical issues may cause small differences however. Use this variable to
446 !% calculate the Hermitian conjugate of the usual matrix, for testing.
447 !%End
448 call parse_variable(sys%namespace, 'CasidaHermitianConjugate', .false., cas%herm_conj)
449
450 !%Variable CasidaDistributedMatrix
451 !%Type logical
452 !%Section Linear Response::Casida
453 !%Default false
454 !%Description
455 !% Large matrices with more than a few thousand rows and columns usually do
456 !% not fit into the memory of one processor anymore. With this option, the
457 !% Casida matrix is distributed in block-cyclic fashion over all cores in the
458 !% ParOther group. The diagonalization is done in parallel using ScaLAPACK
459 !% or ELPA, if available. For very large matrices (>100000), only the
460 !% ParOther strategy should be used because the diagonalization dominates
461 !% the run time of the computation.
462 !%End
463 call parse_variable(sys%namespace, 'CasidaDistributedMatrix', .false., cas%distributed_matrix)
464#ifndef HAVE_SCALAPACK
465 if (cas%distributed_matrix) then
466 message(1) = "ScaLAPACK layout requested, but code not compiled with ScaLAPACK"
467 call messages_fatal(1, namespace=sys%namespace)
468 end if
469#endif
470 call messages_obsolete_variable(sys%namespace, 'CasidaUseScalapackLayout', 'CasidaDistributedMatrix')
471
472 !%Variable CasidaWriteDistributedMatrix
473 !%Type logical
474 !%Section Linear Response::Casida
475 !%Default false
476 !%Description
477 !% Set to true to write out the full distributed Casida matrix to a file
478 !% using MPI-IO.
479 !%End
480 call parse_variable(sys%namespace, 'CasidaWriteDistributedMatrix', .false., cas%write_matrix)
481 if (.not. cas%distributed_matrix .and. cas%write_matrix) then
482 message(1) = "CasidaWriteDistributedMatrix con only be used with CasidaDistributedMatrix"
483 call messages_fatal(1, namespace=sys%namespace)
484 end if
485
486 !%Variable CasidaParallelEigensolver
487 !%Type integer
488 !%Section Linear Response::Casida
489 !%Description
490 !% Choose library to use for solving the parallel eigenproblem
491 !% of the Casida problem. This options is only relevant if a
492 !% distributed matrix is used (CasidaDistributedMatrix=true).
493 !% By default, elpa is chosen if available.
494 !%Option casida_elpa 1
495 !% Use ELPA library as parallel eigensolver
496 !%Option casida_scalapack 2
497 !% Use Scalapack as parallel eigensolver
498 !%End
499#ifdef HAVE_ELPA
500 default_int = solver_elpa
501#else
502 default_int = solver_scalapack
503#endif
504 call parse_variable(sys%namespace, 'CasidaParallelEigensolver', default_int, cas%parallel_solver)
505 if (.not. varinfo_valid_option('CasidaParallelEigensolver', cas%parallel_solver)) then
506 call messages_input_error(sys%namespace, 'CasidaParallelEigensolver')
507 end if
508#ifndef HAVE_ELPA
509 if (cas%distributed_matrix .and. cas%parallel_solver == solver_elpa) then
510 message(1) = "ELPA solver requested, but code not compiled with ELPA"
511 call messages_fatal(1, namespace=sys%namespace)
512 end if
513#endif
514
515 !%Variable CasidaPrintExcitations
516 !%Type string
517 !%Section Linear Response::Casida
518 !%Default write all
519 !%Description
520 !% Specifies which excitations are written at the end of the calculation.
521 !%
522 !% This variable is a string in list form, <i>i.e.</i> expressions such as "1,2-5,8-15" are
523 !% valid.
524 !%End
525 call parse_variable(sys%namespace, 'CasidaPrintExcitations', "all", cas%print_exst)
526 if (cas%distributed_matrix) then
527 ! do not print excited states -> too many files generated!
528 cas%print_exst = "none"
529 message(1) = "Using ScaLAPACK layout, thus disabling output of excited states."
530 message(2) = "This options creates too many files for large Casida matrices."
531 call messages_info(2, namespace=sys%namespace)
532 end if
533
534 !%Variable CasidaWeightThreshold
535 !%Type float
536 !%Section Linear Response::Casida
537 !%Default -1.
538 !%Description
539 !% Specifies the threshold value for which the individual excitations are printed.
540 !% i.e. juste-h pairs with weight larger than this threshold will be printed.
541 !%
542 !% If a negative value (default) is set, all coefficients will be printed.
543 !% For many case, a 0.01 value is a valid option.
544 !%End
545 call parse_variable(sys%namespace, 'CasidaWeightThreshold', -m_one, cas%weight_thresh)
546 if (cas%weight_thresh > m_one) then
547 message(1) = 'Casida coefficients have values between 0 and 1'
548 message(2) = 'Threshold values reset to default value'
549 call messages_warning(2, namespace=sys%namespace)
550 cas%weight_thresh = -m_one
551 end if
552
553 !%Variable CasidaCalcForces
554 !%Type logical
555 !%Section Linear Response::Casida
556 !%Default false
557 !%Description
558 !% (Experimental) Enable calculation of excited-state forces. Requires previous <tt>vib_modes</tt> calculation.
559 !%End
560 call parse_variable(sys%namespace, 'CasidaCalcForces', .false., cas%calc_forces)
561 if (cas%calc_forces) then
562 call messages_experimental("Excited-state forces calculation", namespace=sys%namespace)
563
564 !%Variable CasidaCalcForcesKernel
565 !%Type logical
566 !%Section Linear Response::Casida
567 !%Default true
568 !%Description
569 !% If false, the derivative of the kernel will not be included in the excited-state force calculation.
570 !%End
571 call parse_variable(sys%namespace, 'CasidaCalcForcesKernel', .true., cas%calc_forces_kernel)
572
573 !%Variable CasidaCalcForcesSCF
574 !%Type logical
575 !%Section Linear Response::Casida
576 !%Default false
577 !%Description
578 !% If true, the ground-state forces will be included in the excited-state forces, so they are total forces.
579 !% If false, the excited-state forces that are produced are only the gradients of the excitation energy.
580 !%End
581 call parse_variable(sys%namespace, 'CasidaCalcForcesSCF', .false., cas%calc_forces_scf)
582
583 if (cas%distributed_matrix) then
584 message(1) = "Info: Forces calculation not compatible with ScaLAPACK layout."
585 message(2) = "Using normal layout."
586 call messages_info(2, namespace=sys%namespace)
587 cas%distributed_matrix = .false.
588 end if
589 end if
590
591
592 ! Initialize structure
593 call casida_type_init(cas, sys)
594
595 cas%fromScratch = fromscratch
596
597 if (cas%fromScratch) then ! remove old restart files
598 if (cas%triplet) then
599 call cas%restart_dump%rm('kernel_triplet')
600 else
601 call cas%restart_dump%rm('kernel')
602 end if
603
604 if (cas%calc_forces) then
605 do iatom = 1, sys%ions%natoms
606 do idir = 1, cas%space_dim
607 write(restart_filename,'(a,i6.6,a,i1)') 'lr_kernel_', iatom, '_', idir
608 if (cas%triplet) restart_filename = trim(restart_filename)//'_triplet'
609 call cas%restart_dump%rm(restart_filename)
610
611 write(restart_filename,'(a,i6.6,a,i1)') 'lr_hmat1_', iatom, '_', idir
612 call cas%restart_dump%rm(restart_filename)
613 end do
614 end do
615 end if
616 end if
617
618 ! First, print the differences between KS eigenvalues (first approximation to the excitation energies).
619 if (bitand(theorylevel, casida_eps_diff) /= 0) then
620 message(1) = "Info: Approximating resonance energies through KS eigenvalue differences"
621 call messages_info(1, namespace=sys%namespace)
622 cas%type = casida_eps_diff
623 call casida_work(sys, cas)
624 end if
625
626 if (sys%st%d%ispin /= spinors) then
627
628 if (bitand(theorylevel, casida_tamm_dancoff) /= 0) then
629 call messages_experimental("Tamm-Dancoff calculation", namespace=sys%namespace)
630 message(1) = "Info: Calculating matrix elements in the Tamm-Dancoff approximation"
631 call messages_info(1, namespace=sys%namespace)
632 cas%type = casida_tamm_dancoff
633 call casida_work(sys, cas)
634 end if
635
636 if (bitand(theorylevel, casida_variational) /= 0) then
637 call messages_experimental("CV(2)-DFT calculation", namespace=sys%namespace)
638 message(1) = "Info: Calculating matrix elements with the CV(2)-DFT theory"
639 call messages_info(1, namespace=sys%namespace)
640 cas%type = casida_variational
641 call casida_work(sys, cas)
642 end if
643
644 if (bitand(theorylevel, casida_casida) /= 0) then
645 message(1) = "Info: Calculating matrix elements with the full Casida method"
646 call messages_info(1, namespace=sys%namespace)
647 cas%type = casida_casida
648 call casida_work(sys, cas)
649 end if
650
651 ! Doing this first, if doing the others later, takes longer, because we would use
652 ! each Poisson solution for only one matrix element instead of a whole column.
653 if (bitand(theorylevel, casida_petersilka) /= 0) then
654 message(1) = "Info: Calculating resonance energies via the Petersilka approximation"
655 call messages_info(1, namespace=sys%namespace)
656 cas%type = casida_petersilka
657 call casida_work(sys, cas)
658 end if
659
660 end if
661
662 call casida_type_end(cas)
663
664 call profiling_out('CASIDA')
665 pop_sub(casida_run_legacy)
666 end subroutine casida_run_legacy
667
668 ! ---------------------------------------------------------
670 !
671 subroutine casida_count_pairs(st, namespace, n_pairs, n_occ, n_unocc, is_included, is_frac_occ)
672 type(states_elec_t), intent(in) :: st
673 type(namespace_t), intent(in) :: namespace
674 integer, intent(out) :: n_pairs
675 integer, intent(out) :: n_occ(:)
676 integer, intent(out) :: n_unocc(:)
677 logical, allocatable, intent(out) :: is_included(:,:,:)
679 logical, intent(out) :: is_frac_occ
680
681 integer :: ik, ist, ast, n_filled, n_partially_filled, n_half_filled
682 character(len=80) :: nst_string, default, wfn_list
683 real(real64) :: energy_window
684 real(real64) :: fdiff, delta_e
685 real(real64) :: fdiff_tol
686 real(real64) :: delta_e_tol
687
688 push_sub(casida_count_pairs)
689
690 is_frac_occ = .false.
691 do ik = 1, st%nik
692 call occupied_states(st, namespace, ik, n_filled, n_partially_filled, n_half_filled)
693 if (n_partially_filled > 0 .or. n_half_filled > 0) is_frac_occ = .true.
694 n_occ(ik) = n_filled + n_partially_filled + n_half_filled
695 n_unocc(ik) = st%nst - n_filled
696 ! We implemented fractional occupations, partially occupied levels need to be counted as both occ and unocc.
697 end do
698
699 !%Variable CasidaKSEnergyWindow
700 !%Type float
701 !%Section Linear Response::Casida
702 !%Description
703 !% An alternative to <tt>CasidaKohnShamStates</tt> for specifying which occupied-unoccupied
704 !% transitions will be used: all those whose eigenvalue differences are less than this
705 !% number will be included. If a value less than 0 is supplied, this criterion will not be used.
706 !%End
707
708 call parse_variable(namespace, 'CasidaKSEnergyWindow', -m_one, energy_window, units_inp%energy)
709
710 !%Variable CasidaThresholdOccupation
711 !%Type float
712 !%Default 1e-12
713 !%Section Linear Response::Casida
714 !%Description
715 !%Filters occupation numbers difference depending on user input.
716 !%If undefined, jump into the default value.
717 !%End
718 call parse_variable(namespace, 'CasidaThresholdOccupation', 1.0e-12_real64, fdiff_tol)
719
720 !%Variable CasidaThresholdEnergy
721 !%Type float
722 !%Default 1e-12
723 !%Section Linear Response::Casida
724 !%Description
725 !%Filters energy difference between the transitions.
726 !%If undefined, jump into the default value.
727 !%End
728 call parse_variable(namespace, 'CasidaThresholdEnergy', 1.0e-12_real64, delta_e_tol, units_inp%energy)
729
730 !%Variable CasidaKohnShamStates
731 !%Type string
732 !%Section Linear Response::Casida
733 !%Default all states
734 !%Description
735 !% The calculation of the excitation spectrum of a system in the Casida frequency-domain
736 !% formulation of linear-response time-dependent density functional theory (TDDFT)
737 !% implies the use of a basis set of occupied/unoccupied Kohn-Sham orbitals. This
738 !% basis set should, in principle, include all pairs formed by all occupied states,
739 !% and an infinite number of unoccupied states. In practice, one has to truncate this
740 !% basis set, selecting a number of occupied and unoccupied states that will form the
741 !% pairs. These states are specified with this variable. If there are, say, 15 occupied
742 !% states, and one sets this variable to the value "10-18", this means that occupied
743 !% states from 10 to 15, and unoccupied states from 16 to 18 will be considered.
744 !%
745 !% This variable is a string in list form, <i>i.e.</i> expressions such as "1,2-5,8-15" are
746 !% valid. You should include a non-zero number of unoccupied states and a non-zero number
747 !% of occupied states.
748 !%End
749
750 n_pairs = 0
751 safe_allocate(is_included(st%nst, st%nst , st%nik))
752 is_included(:,:,:) = .false.
753
754 if (energy_window < m_zero) then
755 write(nst_string,'(i6)') st%nst
756 write(default,'(a,a)') "1-", trim(adjustl(nst_string))
757 call parse_variable(namespace, 'CasidaKohnShamStates', default, wfn_list)
758
759 write(message(1),'(a,a)') "Info: States that form the basis: ", trim(wfn_list)
760 call messages_info(1, namespace=namespace)
761
762 ! count pairs
763 n_pairs = 0
764 do ik = 1, st%nik
765 do ast = 1, st%nst
766 if (.not. loct_isinstringlist(ast, wfn_list)) cycle
767 do ist = 1, st%nst
768 if (.not. loct_isinstringlist(ist, wfn_list)) cycle
769 fdiff = st%occ(ist,ik) - st%occ(ast,ik)
770 if (fdiff <= fdiff_tol) cycle
771 n_pairs = n_pairs + 1
772 is_included(ist, ast, ik) = .true.
773 end do
774 end do
775 end do
776
777 else ! using CasidaKSEnergyWindow
778
779 write(message(1),'(a,f12.6,a)') "Info: including transitions with energy < ", &
780 units_from_atomic(units_out%energy, energy_window), trim(units_abbrev(units_out%energy))
781 call messages_info(1, namespace=namespace)
782
783 ! count pairs
784 n_pairs = 0
785 do ik = 1, st%nik
786 do ast = 1, st%nst
787 do ist = 1, st%nst
788 fdiff = st%occ(ist,ik) - st%occ(ast,ik)
789 if (fdiff <= fdiff_tol) cycle
790 delta_e = st%eigenval(ast, ik) - st%eigenval(ist, ik)
791 if (delta_e <= delta_e_tol) cycle
792 if (delta_e >= energy_window) cycle
793 n_pairs = n_pairs + 1
794 is_included(ist, ast, ik) = .true.
795 end do
796 end do
797 end do
798
799 end if
800
801 pop_sub(casida_count_pairs)
802 end subroutine casida_count_pairs
803
804 ! ---------------------------------------------------------
806 subroutine casida_type_init(cas, sys)
807 type(casida_t), intent(inout) :: cas
808 type(electrons_t), intent(in) :: sys
809
810 integer :: ist, ast, jpair, ik, ierr
811#ifdef HAVE_SCALAPACK
812 integer :: np, np_rows, np_cols, ii, info
813
814#endif
815
816 push_sub(casida_type_init)
817
818 cas%kernel_lrc_alpha = sys%ks%xc%lrc%alpha
819 cas%states_are_real = states_are_real(sys%st)
820 if (cas%distributed_matrix .and. .not. cas%states_are_real) then
821 call messages_not_implemented("Complex wavefunctions with ScaLAPACK layout", namespace=sys%namespace)
822 end if
823
824 write(message(1), '(a,i9)') "Number of occupied-unoccupied pairs: ", cas%n_pairs
825 call messages_info(1, namespace=sys%namespace)
826
827 if (cas%n_pairs < 1) then
828 message(1) = "No Casida pairs -- maybe there are no unoccupied states?"
829 call messages_fatal(1, only_root_writes = .true., namespace=sys%namespace)
830 end if
831
832 if (mpi_world%is_root()) write(*, "(1x)")
833
834 ! now let us take care of initializing the parallel stuff
835 cas%parallel_in_eh_pairs = multicomm_strategy_is_parallel(sys%mc, p_strategy_other)
836 if (cas%parallel_in_eh_pairs) then
837 call mpi_grp_init(cas%mpi_grp, sys%mc%group_comm(p_strategy_other))
838 else
839 call mpi_grp_init(cas%mpi_grp, mpi_comm_undefined)
840 end if
841 cas%parallel_in_domains = multicomm_strategy_is_parallel(sys%mc, p_strategy_domains)
842
843 if (cas%distributed_matrix .and. .not. cas%parallel_in_eh_pairs) then
844 message(1) = "ScaLAPACK layout requested, but 'Other' parallelization strategy not available."
845 message(2) = "Please set ParOther to use the ScaLAPACK layout."
846 message(3) = "Continuing without ScaLAPACK layout."
847 call messages_info(3, namespace=sys%namespace)
848 cas%distributed_matrix = .false.
849 end if
850
851 ! dimension of matrix
852 cas%n = cas%n_pairs + cas%pt_nmodes
853
854 ! initialize block-cyclic matrix
855 if (cas%distributed_matrix) then
856#ifdef HAVE_SCALAPACK
857 ! processor layout: always use more processors for rows, this leads to
858 ! better load balancing when computing the matrix elements
859 np = cas%mpi_grp%size
860 np_cols = 1
861 if (np > 3) then
862 do ii = floor(sqrt(real(np))), 2, -1
863 if (mod(np, ii) == 0) then
864 np_cols = ii
865 exit
866 end if
867 end do
868 end if
869 np_rows = np / np_cols
870
871 ! recommended block size: 64, take smaller value for smaller matrices for
872 ! better load balancing
873 cas%block_size = min(64, cas%n / np_rows)
874 ! limit to a minimum block size of 5 for diagonalization efficiency
875 cas%block_size = max(5, cas%block_size)
876 write(message(1), '(A,I5,A,I5,A,I5,A)') 'Parallel layout: using block size of ',&
877 cas%block_size, ' and a processor grid with ', np_rows, 'x', np_cols, &
878 ' processors (rows x cols)'
879 call messages_info(1, namespace=sys%namespace)
880
881 call blacs_proc_grid_init(cas%proc_grid, cas%mpi_grp, procdim = (/np_rows, np_cols/))
882
883 ! get size of local matrices
884 cas%nb_rows = numroc(cas%n, cas%block_size, cas%proc_grid%myrow, 0, cas%proc_grid%nprow)
885 cas%nb_cols = numroc(cas%n, cas%block_size, cas%proc_grid%mycol, 0, cas%proc_grid%npcol)
886
887 ! get ScaLAPACK descriptor
888 call descinit(cas%desc(1), cas%n, cas%n, cas%block_size, cas%block_size, 0, 0, &
889 cas%proc_grid%context, cas%nb_rows, info)
890#endif
891 else
892 ! set to full size
893 cas%nb_rows = cas%n
894 cas%nb_cols = cas%n
895 end if
896
897 ! allocate stuff
898 safe_allocate(cas%pair(1:cas%n))
899 if (cas%states_are_real) then
900 safe_allocate( cas%dmat(1:cas%nb_rows, 1:cas%nb_cols))
901 safe_allocate( cas%dtm(1:cas%n, 1:cas%space_dim))
902 else
903 ! caution: ScaLAPACK layout not yet tested for complex wavefunctions!
904 safe_allocate( cas%zmat(1:cas%nb_rows, 1:cas%nb_cols))
905 safe_allocate( cas%ztm(1:cas%n, 1:cas%space_dim))
906 end if
907 safe_allocate( cas%f(1:cas%n))
908 safe_allocate( cas%s(1:cas%n_pairs))
909 safe_allocate( cas%w(1:cas%n))
910 safe_allocate( cas%index(1:cas%nst, 1:cas%nst, 1:cas%nik))
911 safe_allocate( cas%ind(1:cas%n))
912
913 if (cas%calc_forces) then
914 if (cas%states_are_real) then
915 safe_allocate(cas%dmat_save(1:cas%n_pairs, 1:cas%n_pairs))
916 else
917 safe_allocate(cas%zmat_save(1:cas%n_pairs, 1:cas%n_pairs))
918 end if
919 safe_allocate(cas%forces(1:cas%space_dim, 1:sys%ions%natoms, 1:cas%n_pairs))
920 end if
921
922 if (cas%qcalc) then
923 safe_allocate( cas%qf (1:cas%n_pairs))
924 safe_allocate( cas%qf_avg(1:cas%n_pairs))
925 end if
926
927 cas%index(:,:,:) = 0
928
929 ! create pairs
930 jpair = 1
931 do ik = 1, cas%nik
932 do ast = 1, cas%nst
933 do ist = 1, cas%nst
934 if (.not. cas%is_included(ist, ast, ik)) cycle
935 cas%index(ist, ast, ik) = jpair
936 cas%pair(jpair)%i = ist
937 cas%pair(jpair)%a = ast
938 cas%pair(jpair)%kk = ik
939 jpair = jpair + 1
940 end do
941 end do
942 end do
943 if (jpair - 1 /= cas%n_pairs) then
944 message(1) = "Mismatch in Casida pair counting"
945 call messages_fatal(1, namespace=sys%namespace)
946 end if
947
948 if (cas%has_photons) then
949 ! create pairs for photon modes (negative number refers to photonic excitation)
950 do ik = 1, cas%pt_nmodes
951 cas%pair(cas%n_pairs + ik)%i = 1
952 cas%pair(cas%n_pairs + ik)%a = -ik
953 cas%pair(cas%n_pairs + ik)%kk = -ik
954 end do
955 end if
956
957 safe_deallocate_a(cas%is_included)
958
959 call cas%restart_dump%init(sys%namespace, restart_casida, restart_type_dump, sys%mc, ierr)
960 call cas%restart_load%init(sys%namespace, restart_casida, restart_type_load, sys%mc, ierr)
961
962 pop_sub(casida_type_init)
963 end subroutine casida_type_init
964
965
966 ! ---------------------------------------------------------
967 subroutine casida_type_end(cas)
968 type(casida_t), intent(inout) :: cas
969
970 push_sub(casida_type_end)
971
972 assert(allocated(cas%pair))
973 safe_deallocate_a(cas%pair)
974 safe_deallocate_a(cas%index)
975 if (cas%states_are_real) then
976 safe_deallocate_a(cas%dmat)
977 safe_deallocate_a(cas%dtm)
978 else
979 safe_deallocate_a(cas%zmat)
980 safe_deallocate_a(cas%ztm)
981 end if
982 safe_deallocate_a(cas%s)
983 safe_deallocate_a(cas%f)
984 safe_deallocate_a(cas%w)
985 safe_deallocate_a(cas%ind)
986
987 if (cas%qcalc) then
988 safe_deallocate_a(cas%qf)
989 safe_deallocate_a(cas%qf_avg)
990 end if
991
992 safe_deallocate_a(cas%n_occ)
993 safe_deallocate_a(cas%n_unocc)
994
995 if (cas%calc_forces) then
996 if (cas%states_are_real) then
997 safe_deallocate_a(cas%dmat_save)
998 else
999 safe_deallocate_a(cas%zmat_save)
1000 end if
1001 safe_deallocate_a(cas%forces)
1002 end if
1003
1004 call cas%restart_dump%end()
1005 call cas%restart_load%end()
1006
1007 if (cas%distributed_matrix) then
1008#ifdef HAVE_SCALAPACK
1009 call blacs_proc_grid_end(cas%proc_grid)
1010#endif
1011 end if
1012
1013 safe_deallocate_a(cas%qvector)
1014
1015 pop_sub(casida_type_end)
1016 end subroutine casida_type_end
1017
1018
1019 ! ---------------------------------------------------------
1022 subroutine casida_work(sys, cas)
1023 type(electrons_t), target, intent(inout) :: sys
1024 type(casida_t), intent(inout) :: cas
1025
1026 type(states_elec_t), pointer :: st
1027 type(grid_t), pointer :: gr
1029 real(real64), allocatable :: rho_spin(:, :)
1030 real(real64), allocatable :: fxc_spin(:,:,:), fxc_grad(:,:,:,:,:), fxc_grad_spin(:,:,:,:)
1031 character(len=100) :: restart_filename
1032
1033 push_sub(casida_work)
1034
1035 ! sanity checks
1036 assert(cas%type >= casida_eps_diff .and. cas%type <= casida_casida)
1037
1038 ! some shortcuts
1039 st => sys%st
1040 gr => sys%gr
1041
1042 ! initialize stuff
1043 if (cas%states_are_real) then
1044 cas%dmat = m_zero
1045 cas%dtm = m_zero
1046 else
1047 cas%zmat = m_zero
1048 cas%ztm = m_zero
1049 end if
1050 cas%f = m_zero
1051 cas%w = m_zero
1052 cas%s = m_zero
1053 if (cas%qcalc) then
1054 cas%qf = m_zero
1055 cas%qf_avg = m_zero
1056 end if
1057
1058 if (cas%type /= casida_eps_diff .or. cas%calc_forces) then
1059 ! We calculate here the kernel, since it will be needed later.
1060 safe_allocate(cas%rho(1:gr%np_part, 1:st%d%nspin))
1061 safe_allocate(cas%fxc(1:gr%np, 1:st%d%nspin, 1:st%d%nspin))
1062 cas%gga = in_family(sys%ks%xc%kernel_family, [xc_family_gga])
1063 if (cas%gga) then
1064 safe_allocate(cas%fxc_grad(1:gr%np, 1:gr%der%dim, 1:gr%der%dim, 1:st%d%nspin, 1:st%d%nspin))
1065 if (st%d%ispin == spin_polarized) then
1066 safe_allocate(cas%fxc_grad_spin(1:gr%np, 1:gr%der%dim, 1:st%d%nspin, 1:st%d%nspin))
1067 else
1068 safe_allocate(cas%fxc_grad_spin(0, 0, 0, 0))
1069 end if
1070 else
1071 safe_allocate(cas%fxc_grad(0, 0, 0, 0, 0))
1072 safe_allocate(cas%fxc_grad_spin(0, 0, 0, 0))
1073 end if
1074
1075 call states_elec_total_density(st, gr, cas%rho)
1076 if (cas%triplet) then
1077 safe_allocate(rho_spin(1:gr%np_part, 1:2))
1078 safe_allocate(fxc_spin(1:gr%np, 1:2, 1:2))
1079
1080 rho_spin(:, 1) = m_half * cas%rho(:, 1)
1081 rho_spin(:, 2) = m_half * cas%rho(:, 1)
1082
1083 if (cas%gga) then
1084 safe_allocate(fxc_grad(1:gr%np, 1:gr%der%dim, 1:gr%der%dim, 1:2, 1:2))
1085 safe_allocate(fxc_grad_spin(1:gr%np, 1:gr%der%dim, 1:2, 1:2))
1086 call xc_get_fxc(sys%ks%xc, gr, sys%namespace, rho_spin, spin_polarized, fxc_spin, fxc_grad, fxc_grad_spin)
1087 cas%fxc_grad(:, :, :, 1, 1) = m_half * (fxc_grad(:, :, :, 1, 1) - fxc_grad(:, :, :, 1, 2))
1088 ! For the triplet case, fxc_grad_spin is zero as n_up = n_down
1089 safe_deallocate_a(fxc_grad)
1090 safe_deallocate_a(fxc_grad_spin)
1091 else
1092 call xc_get_fxc(sys%ks%xc, gr, sys%namespace, rho_spin, spin_polarized, fxc_spin)
1093 end if
1094 cas%fxc(:, 1, 1) = m_half * (fxc_spin(:, 1, 1) - fxc_spin(:, 1, 2))
1095
1096 safe_deallocate_a(rho_spin)
1097 safe_deallocate_a(fxc_spin)
1098 else
1099 if (cas%gga) then
1100 call xc_get_fxc(sys%ks%xc, gr, sys%namespace, cas%rho, st%d%ispin, cas%fxc, cas%fxc_grad, &
1101 cas%fxc_grad_spin)
1102 else
1103 call xc_get_fxc(sys%ks%xc, gr, sys%namespace, cas%rho, st%d%ispin, cas%fxc)
1104 end if
1105 end if
1106
1107 if (sys%ks%sic%level == sic_adsic) then
1108 call xc_sic_add_fxc_adsic(sys%namespace, sys%ks%xc, st, gr, cas%rho, cas%fxc, cas%fxc_grad, cas%fxc_grad_spin, cas%triplet)
1109 end if
1110
1111 end if
1112
1113 restart_filename = 'kernel'
1114 if (cas%triplet) restart_filename = trim(restart_filename)//'_triplet'
1115
1116 select case (cas%type)
1117 case (casida_eps_diff)
1118 call solve_eps_diff()
1120 if (cas%states_are_real) then
1121 call dcasida_get_matrix(cas, sys%namespace, sys%hm, st, sys%ks, gr, cas%dmat, cas%fxc, &
1122 cas%fxc_grad, cas%fxc_grad_spin, restart_filename)
1123 call dcasida_solve(cas, sys)
1124 else
1125 call zcasida_get_matrix(cas, sys%namespace, sys%hm, st, sys%ks, gr, cas%zmat, cas%fxc, &
1126 cas%fxc_grad, cas%fxc_grad_spin, restart_filename)
1127 call zcasida_solve(cas, sys)
1128 end if
1129 end select
1130
1131 ! compute oscillator strengths on all processes for the ScaLAPACK layout
1132 if (cas%mpi_grp%is_root() .or. cas%distributed_matrix) then
1133 if (cas%states_are_real) then
1134 call doscillator_strengths(cas, gr, st)
1135 else
1136 call zoscillator_strengths(cas, gr, st)
1137 end if
1138 end if
1139
1140 if (cas%calc_forces) then
1141 if (cas%states_are_real) then
1142 call dcasida_forces(cas, sys, gr, st)
1143 else
1144 call zcasida_forces(cas, sys, gr, st)
1145 end if
1146 end if
1147
1148 if (cas%states_are_real) then
1149 call dcasida_write(cas, sys)
1150 else
1151 call zcasida_write(cas, sys)
1152 end if
1153
1154 ! clean up
1155 if (cas%type /= casida_eps_diff .or. cas%calc_forces) then
1156 safe_deallocate_a(cas%fxc)
1157 safe_deallocate_a(cas%fxc_grad)
1158 safe_deallocate_a(cas%fxc_grad_spin)
1159 safe_deallocate_a(cas%rho)
1160 end if
1161
1162 pop_sub(casida_work)
1163
1164 contains
1165
1166 ! ---------------------------------------------------------
1167 subroutine solve_eps_diff
1168
1169 integer :: ia
1170 real(real64), allocatable :: w(:)
1171
1172 push_sub(casida_work.solve_eps_diff)
1173
1174 ! initialize progress bar
1175 if (mpi_world%is_root()) call loct_progress_bar(-1, cas%n_pairs)
1176
1177 do ia = 1, cas%n_pairs
1178 cas%w(ia) = st%eigenval(cas%pair(ia)%a, cas%pair(ia)%kk) - &
1179 st%eigenval(cas%pair(ia)%i, cas%pair(ia)%kk)
1180 if (cas%w(ia) < -m_epsilon) then
1181 message(1) = "There is a negative unocc-occ KS eigenvalue difference for"
1182 write(message(2),'("states ",I5," and ",I5," of k-point ",I5,".")') cas%pair(ia)%i, cas%pair(ia)%a, cas%pair(ia)%kk
1183 message(3) = "This indicates an inconsistency between gs, unocc, and/or casida calculations."
1184 call messages_fatal(3, only_root_writes = .true., namespace=sys%namespace)
1185 end if
1186 if (mpi_world%is_root()) call loct_progress_bar(ia, cas%n_pairs)
1187 end do
1188
1189 safe_allocate(w(1:size(cas%w)))
1190 w = cas%w
1191 call sort(w, cas%ind)
1192 safe_deallocate_a(w)
1193
1194 if (mpi_world%is_root()) write(*, "(1x)")
1195
1197 end subroutine solve_eps_diff
1198
1199 end subroutine casida_work
1200
1201 ! ---------------------------------------------------------
1202 real(real64) function casida_matrix_factor(cas, sys)
1203 type(casida_t), intent(in) :: cas
1204 type(electrons_t), intent(in) :: sys
1205
1206 push_sub(casida_matrix_factor)
1207
1208 casida_matrix_factor = m_one
1209
1210 if (cas%type == casida_variational) then
1211 casida_matrix_factor = m_two * casida_matrix_factor
1212 end if
1213
1214 if (sys%st%d%ispin == unpolarized) then
1215 casida_matrix_factor = m_two * casida_matrix_factor
1216 end if
1217
1218 pop_sub(casida_matrix_factor)
1219
1220 end function casida_matrix_factor
1221
1222 ! ---------------------------------------------------------
1223 subroutine qcasida_write(cas, namespace)
1224 type(casida_t), intent(in) :: cas
1225 type(namespace_t), intent(in) :: namespace
1226
1227 integer :: iunit, ia
1229 if (.not. mpi_world%is_root()) return
1230
1231 push_sub(qcasida_write)
1232
1233 call io_mkdir(casida_dir, namespace)
1234 iunit = io_open(casida_dir//'q'//trim(theory_name(cas)), namespace, action='write')
1235 write(iunit, '(a1,a14,1x,a24,1x,a24,1x,a10,3es15.8,a2)') '#','E' , '|<f|exp(iq.r)|i>|^2', &
1236 '<|<f|exp(iq.r)|i>|^2>','; q = (',cas%qvector(1:cas%space_dim),')'
1237 write(iunit, '(a1,a14,1x,a24,1x,a24,1x,10x,a15)') '#', trim(units_abbrev(units_out%energy)), &
1238 trim('-'), &
1239 trim('-'), &
1240 trim('a.u.')
1241
1242 if (cas%avg_order == 0) then
1243 do ia = 1, cas%n_pairs
1244 write(iunit, '(es15.8,es15.8)') units_from_atomic(units_out%energy, cas%w(cas%ind(ia))), cas%qf(cas%ind(ia))
1245 end do
1246 else
1247 do ia = 1, cas%n_pairs
1248 write(iunit, '(3es15.8)') units_from_atomic(units_out%energy, cas%w(cas%ind(ia))), &
1249 cas%qf (cas%ind(ia)), &
1250 cas%qf_avg(cas%ind(ia))
1251 end do
1252 end if
1253
1254 call io_close(iunit)
1255
1256 pop_sub(qcasida_write)
1257
1258 end subroutine qcasida_write
1259
1260 ! ---------------------------------------------------------
1261 character(len=80) pure function theory_name(cas)
1262 type(casida_t), intent(in) :: cas
1264 select case (cas%type)
1265 case (casida_eps_diff)
1266 theory_name = "eps_diff"
1267 case (casida_petersilka)
1268 theory_name = "petersilka"
1269 case (casida_tamm_dancoff)
1270 theory_name = "tamm_dancoff"
1271 case (casida_variational)
1272 theory_name = "variational"
1273 case (casida_casida)
1274 theory_name = "casida"
1275 case default
1276 theory_name = "unknown"
1277 end select
1278
1279 end function theory_name
1280
1281 logical function isnt_degenerate(cas, st, ia, jb)
1282 type(casida_t), intent(in) :: cas
1283 type(states_elec_t), intent(in) :: st
1284 integer, intent(in) :: ia
1285 integer, intent(in) :: jb
1286
1287 push_sub(isnt_degenerate)
1288
1289 isnt_degenerate = (abs((st%eigenval(cas%pair(ia)%a, cas%pair(ia)%kk) - st%eigenval(cas%pair(ia)%i, cas%pair(ia)%kk)) &
1290 - (st%eigenval(cas%pair(jb)%a, cas%pair(jb)%kk) - st%eigenval(cas%pair(jb)%i, cas%pair(jb)%kk))) > 1e-8_real64)
1291
1292 pop_sub(isnt_degenerate)
1293 end function isnt_degenerate
1294
1295 integer function get_global_row(cas, jb_local) result(jb)
1296 implicit none
1297 type(casida_t), intent(inout) :: cas
1298 integer, intent(in) :: jb_local
1299
1300 if (.not. cas%distributed_matrix) then
1301 jb = jb_local
1302 else
1303#ifdef HAVE_SCALAPACK
1304 jb = indxl2g(jb_local, cas%block_size, cas%proc_grid%myrow, 0, cas%proc_grid%nprow)
1305#endif
1306 end if
1307 end function get_global_row
1308
1309 integer function get_global_col(cas, ia_local) result(ia)
1310 implicit none
1311 type(casida_t), intent(inout) :: cas
1312 integer, intent(in) :: ia_local
1313
1314 if (.not. cas%distributed_matrix) then
1315 ia = ia_local
1316 else
1317#ifdef HAVE_SCALAPACK
1318 ia = indxl2g(ia_local, cas%block_size, cas%proc_grid%mycol, 0, cas%proc_grid%npcol)
1319#endif
1320 end if
1321 end function get_global_col
1323 subroutine local_indices(cas, ia, jb, on_this_processor, ia_local, jb_local)
1324 implicit none
1325 type(casida_t), intent(in) :: cas
1326 integer, intent(in) :: ia, jb
1327 logical, intent(out) :: on_this_processor
1328 integer, intent(out) :: ia_local, jb_local
1329#ifdef HAVE_SCALAPACK
1330 integer :: ia_proc, jb_proc
1331#endif
1332
1333 if (.not. cas%distributed_matrix) then
1334 on_this_processor = .true.
1335 ia_local = ia
1336 jb_local = jb
1337 else
1338#ifdef HAVE_SCALAPACK
1339 ia_proc = indxg2p(ia, cas%block_size, cas%proc_grid%mycol, 0, cas%proc_grid%npcol)
1340 jb_proc = indxg2p(jb, cas%block_size, cas%proc_grid%myrow, 0, cas%proc_grid%nprow)
1341 if (cas%proc_grid%mycol == ia_proc .and. cas%proc_grid%myrow == jb_proc) then
1342 on_this_processor = .true.
1343 ia_local = indxg2l(ia, cas%block_size, cas%proc_grid%mycol, 0, cas%proc_grid%npcol)
1344 jb_local = indxg2l(jb, cas%block_size, cas%proc_grid%myrow, 0, cas%proc_grid%nprow)
1345 else
1346 on_this_processor = .false.
1347 ia_local = -1
1348 jb_local = -1
1349 end if
1350#endif
1351 end if
1352 end subroutine local_indices
1353
1354#include "undef.F90"
1355#include "real.F90"
1356#include "casida_inc.F90"
1357#include "undef.F90"
1358#include "complex.F90"
1359#include "casida_inc.F90"
1360
1361end module casida_oct_m
1362
1363!! Local Variables:
1364!! mode: f90
1365!! coding: utf-8
1366!! End:
subroutine solve_eps_diff
Definition: casida.F90:1229
This is the common interface to a sorting routine. It performs the shell algorithm,...
Definition: sort.F90:156
double floor(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
Definition: batch.F90:135
This module provides the BLACS processor grid.
subroutine, public blacs_proc_grid_init(this, mpi_grp, procdim)
Initializes a blacs context from an MPI communicator with topological information.
subroutine, public blacs_proc_grid_end(this)
This module handles the calculation mode.
integer, parameter, public p_strategy_other
something else like e-h pairs
integer, parameter, public p_strategy_domains
parallelization in domains
This module implements the Casida equations for excited states.
Definition: casida.F90:120
integer function get_global_col(cas, ia_local)
Definition: casida.F90:1371
integer, parameter solver_scalapack
Definition: casida.F90:198
subroutine casida_count_pairs(st, namespace, n_pairs, n_occ, n_unocc, is_included, is_frac_occ)
number of occupied-unoccupied pairs for Casida
Definition: casida.F90:767
subroutine zoscillator_strengths(cas, mesh, st)
Definition: casida.F90:3381
integer, parameter casida_petersilka
Definition: casida.F90:191
integer, parameter casida_casida
Definition: casida.F90:191
subroutine casida_type_init(cas, sys)
allocates stuff, and constructs the arrays pair_i and pair_j
Definition: casida.F90:902
integer function get_global_row(cas, jb_local)
Definition: casida.F90:1357
integer, parameter casida_eps_diff
Definition: casida.F90:191
character(len=80) pure function theory_name(cas)
Definition: casida.F90:1323
subroutine dcasida_forces(cas, sys, gr, st)
Definition: casida.F90:2664
subroutine dcasida_get_matrix(cas, namespace, hm, st, ks, gr, matrix, fxc, fxc_grad, fxc_grad_spin, restart_file, is_forces)
Definition: casida.F90:1896
subroutine local_indices(cas, ia, jb, on_this_processor, ia_local, jb_local)
Definition: casida.F90:1385
subroutine zcasida_solve(cas, sys)
Definition: casida.F90:4835
subroutine casida_work(sys, cas)
this subroutine calculates electronic excitation energies using the matrix formulation of M....
Definition: casida.F90:1084
subroutine zcasida_get_matrix(cas, namespace, hm, st, ks, gr, matrix, fxc, fxc_grad, fxc_grad_spin, restart_file, is_forces)
Definition: casida.F90:3804
integer, parameter casida_variational
Definition: casida.F90:191
subroutine qcasida_write(cas, namespace)
Definition: casida.F90:1285
subroutine zcasida_write(cas, sys)
Definition: casida.F90:4973
logical function isnt_degenerate(cas, st, ia, jb)
Definition: casida.F90:1343
subroutine, public casida_run(system, from_scratch)
Definition: casida.F90:294
subroutine doscillator_strengths(cas, mesh, st)
Definition: casida.F90:1473
subroutine dcasida_write(cas, sys)
Definition: casida.F90:3065
real(real64) function casida_matrix_factor(cas, sys)
Definition: casida.F90:1264
subroutine casida_run_legacy(sys, fromScratch)
Definition: casida.F90:312
integer, parameter casida_tamm_dancoff
Definition: casida.F90:191
subroutine zcasida_forces(cas, sys, gr, st)
Definition: casida.F90:4572
subroutine casida_type_end(cas)
Definition: casida.F90:1029
subroutine dcasida_solve(cas, sys)
Definition: casida.F90:2927
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
subroutine, public states_elec_total_density(st, mesh, total_rho)
This routine calculates the total electronic density.
Definition: density.F90:892
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
integer, parameter, public hartree_fock
Definition: global.F90:250
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:250
real(real64), parameter, public m_epsilon
Definition: global.F90:216
real(real64), parameter, public m_half
Definition: global.F90:206
real(real64), parameter, public m_one
Definition: global.F90:201
This module implements the underlying real-space grid.
Definition: grid.F90:119
subroutine, public io_function_read_what_how_when(namespace, space, what, how, output_interval, what_tag_in, how_tag_in, output_interval_tag_in, ignore_error)
Definition: io.F90:116
integer pure function, public kpoints_number(this)
Definition: kpoints.F90:1213
A module to handle KS potential, without the external potential.
integer, parameter, public dft_u_none
Definition: lda_u.F90:205
System information (time, memory, sysname)
Definition: loct.F90:117
logical function, public loct_isinstringlist(a, s)
Definition: loct.F90:288
subroutine, public loct_progress_bar(a, maxcount)
A wrapper around the progress bar, such that it can be silenced without needing to dress the call wit...
Definition: loct.F90:276
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:898
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
character(len=512), private msg
Definition: messages.F90:167
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:525
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1000
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:691
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1040
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
Definition: mpi.F90:138
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:272
subroutine mpi_grp_init(grp, comm)
Initialize MPI group instance.
Definition: mpi.F90:341
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
logical pure function, public multicomm_strategy_is_parallel(mc, level)
Definition: multicomm.F90:728
This module implements the basic mulsisystem class, a container system for other systems.
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:623
subroutine, public photon_mode_set_n_electrons(this, qtot)
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
integer, parameter, public restart_casida
Definition: restart.F90:156
integer, parameter, public restart_gs
Definition: restart.F90:156
integer, parameter, public restart_type_dump
Definition: restart.F90:184
integer, parameter, public restart_type_load
Definition: restart.F90:184
This module contains interfaces for ScaLAPACK routines Interfaces are from http:
Definition: scalapack.F90:133
This module is intended to contain "only mathematical" functions and procedures.
Definition: sort.F90:119
pure logical function, public states_are_complex(st)
pure logical function, public states_are_real(st)
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public occupied_states(st, namespace, ik, n_filled, n_partially_filled, n_half_filled, filled, partially_filled, half_filled)
return information about occupied orbitals in many-body state
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_look_and_load(restart, namespace, space, st, mesh, kpoints, fixed_occ, is_complex, packed)
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 v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
Definition: v_ks.F90:654
subroutine, public xc_get_fxc(xcs, gr, namespace, rho, ispin, fxc, fxc_grad, fxc_grad_spin)
Returns the exchange-correlation kernel.
Definition: xc_kernel.F90:172
Definition: xc.F90:120
logical pure function, public family_is_mgga_with_exc(xcs)
Is the xc function part of the mGGA family with an energy functional.
Definition: xc.F90:721
pure logical function, public in_family(family, xc_families)
Definition: xc.F90:749
subroutine, public xc_write_fxc_info(xcs, iunit, namespace)
Definition: xc.F90:294
subroutine, public xc_sic_write_info(sic, iunit, namespace)
Definition: xc_sic.F90:259
integer, parameter, public sic_adsic
Averaged density SIC.
Definition: xc_sic.F90:153
subroutine, public xc_sic_add_fxc_adsic(namespace, xc, st, gr, rho, fxc, fxc_grad, fxc_grad_spin, triplet)
Adds to fxc the ADSIC contribution.
Definition: xc_sic.F90:477
This class contains all parameters, needed for Casida calculations.
Definition: casida.F90:203
Class describing the electron system.
Definition: electrons.F90:222
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
Container class for lists of system_oct_m::system_t.
The states_elec_t class contains all electronic wave functions.
int true(void)