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 states_elec_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 subroutine casida_type_init(cas, sys)
671 type(casida_t), intent(inout) :: cas
672 type(electrons_t), intent(in) :: sys
673
674 integer :: ist, ast, jpair, ik, ierr
675#ifdef HAVE_SCALAPACK
676 integer :: np, np_rows, np_cols, ii, info
677
678#endif
679
680 push_sub(casida_type_init)
681
682 cas%kernel_lrc_alpha = sys%ks%xc%lrc%alpha
683 cas%states_are_real = states_are_real(sys%st)
684 if (cas%distributed_matrix .and. .not. cas%states_are_real) then
685 call messages_not_implemented("Complex wavefunctions with ScaLAPACK layout", namespace=sys%namespace)
686 end if
687
688 write(message(1), '(a,i9)') "Number of occupied-unoccupied pairs: ", cas%n_pairs
689 call messages_info(1, namespace=sys%namespace)
690
691 if (cas%n_pairs < 1) then
692 message(1) = "No Casida pairs -- maybe there are no unoccupied states?"
693 call messages_fatal(1, only_root_writes = .true., namespace=sys%namespace)
694 end if
695
696 if (mpi_world%is_root()) write(*, "(1x)")
697
698 ! now let us take care of initializing the parallel stuff
699 cas%parallel_in_eh_pairs = multicomm_strategy_is_parallel(sys%mc, p_strategy_other)
700 if (cas%parallel_in_eh_pairs) then
701 call mpi_grp_init(cas%mpi_grp, sys%mc%group_comm(p_strategy_other))
702 else
703 call mpi_grp_init(cas%mpi_grp, mpi_comm_undefined)
704 end if
705 cas%parallel_in_domains = multicomm_strategy_is_parallel(sys%mc, p_strategy_domains)
706
707 if (cas%distributed_matrix .and. .not. cas%parallel_in_eh_pairs) then
708 message(1) = "ScaLAPACK layout requested, but 'Other' parallelization strategy not available."
709 message(2) = "Please set ParOther to use the ScaLAPACK layout."
710 message(3) = "Continuing without ScaLAPACK layout."
711 call messages_info(3, namespace=sys%namespace)
712 cas%distributed_matrix = .false.
713 end if
714
715 ! dimension of matrix
716 cas%n = cas%n_pairs + cas%pt_nmodes
717
718 ! initialize block-cyclic matrix
719 if (cas%distributed_matrix) then
720#ifdef HAVE_SCALAPACK
721 ! processor layout: always use more processors for rows, this leads to
722 ! better load balancing when computing the matrix elements
723 np = cas%mpi_grp%size
724 np_cols = 1
725 if (np > 3) then
726 do ii = floor(sqrt(real(np))), 2, -1
727 if (mod(np, ii) == 0) then
728 np_cols = ii
729 exit
730 end if
731 end do
732 end if
733 np_rows = np / np_cols
734
735 ! recommended block size: 64, take smaller value for smaller matrices for
736 ! better load balancing
737 cas%block_size = min(64, cas%n / np_rows)
738 ! limit to a minimum block size of 5 for diagonalization efficiency
739 cas%block_size = max(5, cas%block_size)
740 write(message(1), '(A,I5,A,I5,A,I5,A)') 'Parallel layout: using block size of ',&
741 cas%block_size, ' and a processor grid with ', np_rows, 'x', np_cols, &
742 ' processors (rows x cols)'
743 call messages_info(1, namespace=sys%namespace)
744
745 call blacs_proc_grid_init(cas%proc_grid, cas%mpi_grp, procdim = (/np_rows, np_cols/))
746
747 ! get size of local matrices
748 cas%nb_rows = numroc(cas%n, cas%block_size, cas%proc_grid%myrow, 0, cas%proc_grid%nprow)
749 cas%nb_cols = numroc(cas%n, cas%block_size, cas%proc_grid%mycol, 0, cas%proc_grid%npcol)
750
751 ! get ScaLAPACK descriptor
752 call descinit(cas%desc(1), cas%n, cas%n, cas%block_size, cas%block_size, 0, 0, &
753 cas%proc_grid%context, cas%nb_rows, info)
754#endif
755 else
756 ! set to full size
757 cas%nb_rows = cas%n
758 cas%nb_cols = cas%n
759 end if
760
761 ! allocate stuff
762 safe_allocate(cas%pair(1:cas%n))
763 if (cas%states_are_real) then
764 safe_allocate( cas%dmat(1:cas%nb_rows, 1:cas%nb_cols))
765 safe_allocate( cas%dtm(1:cas%n, 1:cas%space_dim))
766 else
767 ! caution: ScaLAPACK layout not yet tested for complex wavefunctions!
768 safe_allocate( cas%zmat(1:cas%nb_rows, 1:cas%nb_cols))
769 safe_allocate( cas%ztm(1:cas%n, 1:cas%space_dim))
770 end if
771 safe_allocate( cas%f(1:cas%n))
772 safe_allocate( cas%s(1:cas%n_pairs))
773 safe_allocate( cas%w(1:cas%n))
774 safe_allocate( cas%index(1:cas%nst, 1:cas%nst, 1:cas%nik))
775 safe_allocate( cas%ind(1:cas%n))
776
777 if (cas%calc_forces) then
778 if (cas%states_are_real) then
779 safe_allocate(cas%dmat_save(1:cas%n_pairs, 1:cas%n_pairs))
780 else
781 safe_allocate(cas%zmat_save(1:cas%n_pairs, 1:cas%n_pairs))
782 end if
783 safe_allocate(cas%forces(1:cas%space_dim, 1:sys%ions%natoms, 1:cas%n_pairs))
784 end if
785
786 if (cas%qcalc) then
787 safe_allocate( cas%qf (1:cas%n_pairs))
788 safe_allocate( cas%qf_avg(1:cas%n_pairs))
789 end if
790
791 cas%index(:,:,:) = 0
792
793 ! create pairs
794 jpair = 1
795 do ik = 1, cas%nik
796 do ast = 1, cas%nst
797 do ist = 1, cas%nst
798 if (.not. cas%is_included(ist, ast, ik)) cycle
799 cas%index(ist, ast, ik) = jpair
800 cas%pair(jpair)%i = ist
801 cas%pair(jpair)%a = ast
802 cas%pair(jpair)%kk = ik
803 jpair = jpair + 1
804 end do
805 end do
806 end do
807 if (jpair - 1 /= cas%n_pairs) then
808 message(1) = "Mismatch in Casida pair counting"
809 call messages_fatal(1, namespace=sys%namespace)
810 end if
811
812 if (cas%has_photons) then
813 ! create pairs for photon modes (negative number refers to photonic excitation)
814 do ik = 1, cas%pt_nmodes
815 cas%pair(cas%n_pairs + ik)%i = 1
816 cas%pair(cas%n_pairs + ik)%a = -ik
817 cas%pair(cas%n_pairs + ik)%kk = -ik
818 end do
819 end if
820
821 safe_deallocate_a(cas%is_included)
822
823 call cas%restart_dump%init(sys%namespace, restart_casida, restart_type_dump, sys%mc, ierr)
824 call cas%restart_load%init(sys%namespace, restart_casida, restart_type_load, sys%mc, ierr)
825
826 pop_sub(casida_type_init)
827 end subroutine casida_type_init
828
829
830 ! ---------------------------------------------------------
831 subroutine casida_type_end(cas)
832 type(casida_t), intent(inout) :: cas
833
834 push_sub(casida_type_end)
835
836 assert(allocated(cas%pair))
837 safe_deallocate_a(cas%pair)
838 safe_deallocate_a(cas%index)
839 if (cas%states_are_real) then
840 safe_deallocate_a(cas%dmat)
841 safe_deallocate_a(cas%dtm)
842 else
843 safe_deallocate_a(cas%zmat)
844 safe_deallocate_a(cas%ztm)
845 end if
846 safe_deallocate_a(cas%s)
847 safe_deallocate_a(cas%f)
848 safe_deallocate_a(cas%w)
849 safe_deallocate_a(cas%ind)
850
851 if (cas%qcalc) then
852 safe_deallocate_a(cas%qf)
853 safe_deallocate_a(cas%qf_avg)
854 end if
855
856 safe_deallocate_a(cas%n_occ)
857 safe_deallocate_a(cas%n_unocc)
858
859 if (cas%calc_forces) then
860 if (cas%states_are_real) then
861 safe_deallocate_a(cas%dmat_save)
862 else
863 safe_deallocate_a(cas%zmat_save)
864 end if
865 safe_deallocate_a(cas%forces)
866 end if
867
868 call cas%restart_dump%end()
869 call cas%restart_load%end()
870
871 if (cas%distributed_matrix) then
872#ifdef HAVE_SCALAPACK
873 call blacs_proc_grid_end(cas%proc_grid)
874#endif
875 end if
876
877 safe_deallocate_a(cas%qvector)
878
879 pop_sub(casida_type_end)
880 end subroutine casida_type_end
881
882
883 ! ---------------------------------------------------------
886 subroutine casida_work(sys, cas)
887 type(electrons_t), target, intent(inout) :: sys
888 type(casida_t), intent(inout) :: cas
889
890 type(states_elec_t), pointer :: st
891 type(grid_t), pointer :: gr
893 real(real64), allocatable :: rho_spin(:, :)
894 real(real64), allocatable :: fxc_spin(:,:,:)
895 character(len=100) :: restart_filename
896
897 push_sub(casida_work)
898
899 ! sanity checks
900 assert(cas%type >= casida_eps_diff .and. cas%type <= casida_casida)
901
902 ! some shortcuts
903 st => sys%st
904 gr => sys%gr
905
906 ! initialize stuff
907 if (cas%states_are_real) then
908 cas%dmat = m_zero
909 cas%dtm = m_zero
910 else
911 cas%zmat = m_zero
912 cas%ztm = m_zero
913 end if
914 cas%f = m_zero
915 cas%w = m_zero
916 cas%s = m_zero
917 if (cas%qcalc) then
918 cas%qf = m_zero
919 cas%qf_avg = m_zero
920 end if
921
922 if (cas%type /= casida_eps_diff .or. cas%calc_forces) then
923 ! We calculate here the kernel, since it will be needed later.
924 safe_allocate(cas%rho(1:gr%np_part, 1:st%d%nspin))
925 safe_allocate(cas%fxc(1:gr%np, 1:st%d%nspin, 1:st%d%nspin))
926 cas%gga = in_family(sys%ks%xc%kernel_family, [xc_family_gga])
927 if (cas%gga) then
928 safe_allocate(cas%fxc_grad(1:gr%np, 1:gr%der%dim, 1:gr%der%dim, 1:st%d%nspin, 1:st%d%nspin))
929 if (st%d%ispin == spin_polarized) then
930 safe_allocate(cas%fxc_grad_spin(1:gr%np, 1:gr%der%dim, 1:st%d%nspin, 1:st%d%nspin))
931 else
932 safe_allocate(cas%fxc_grad_spin(0, 0, 0, 0))
933 end if
934 else
935 safe_allocate(cas%fxc_grad(0, 0, 0, 0, 0))
936 safe_allocate(cas%fxc_grad_spin(0, 0, 0, 0))
937 end if
938
939 call states_elec_total_density(st, gr, cas%rho)
940 if (cas%triplet) then
941 safe_allocate(rho_spin(1:gr%np_part, 1:2))
942 safe_allocate(fxc_spin(1:gr%np, 1:2, 1:2))
943
944 rho_spin(:, 1) = m_half * cas%rho(:, 1)
945 rho_spin(:, 2) = m_half * cas%rho(:, 1)
946
947 call xc_get_fxc(sys%ks%xc, gr, sys%namespace, rho_spin, spin_polarized, fxc_spin)
948 cas%fxc(:, 1, 1) = m_half * (fxc_spin(:, 1, 1) - fxc_spin(:, 1, 2))
949
950 safe_deallocate_a(rho_spin)
951 safe_deallocate_a(fxc_spin)
952 else
953 if (cas%gga) then
954 call xc_get_fxc(sys%ks%xc, gr, sys%namespace, cas%rho, st%d%ispin, cas%fxc, cas%fxc_grad, &
955 cas%fxc_grad_spin)
956 else
957 call xc_get_fxc(sys%ks%xc, gr, sys%namespace, cas%rho, st%d%ispin, cas%fxc)
958 end if
959 end if
960
961 if (sys%ks%sic%level == sic_adsic) then
962 if (cas%triplet) then
963 message(1) = "Casida calculation with ADSIC not implemented for triplet excitations."
964 call messages_fatal(1, namespace=sys%namespace)
965 end if
966 call xc_sic_add_fxc_adsic(sys%namespace, sys%ks%xc, st, gr, cas%rho, cas%fxc)
967 end if
968
969 end if
970
971 restart_filename = 'kernel'
972 if (cas%triplet) restart_filename = trim(restart_filename)//'_triplet'
973
974 select case (cas%type)
975 case (casida_eps_diff)
976 call solve_eps_diff()
978 if (cas%states_are_real) then
979 call dcasida_get_matrix(cas, sys%namespace, sys%hm, st, sys%ks, gr, cas%dmat, cas%fxc, &
980 cas%fxc_grad, cas%fxc_grad_spin, restart_filename)
981 call dcasida_solve(cas, sys)
982 else
983 call zcasida_get_matrix(cas, sys%namespace, sys%hm, st, sys%ks, gr, cas%zmat, cas%fxc, &
984 cas%fxc_grad, cas%fxc_grad_spin, restart_filename)
985 call zcasida_solve(cas, sys)
986 end if
987 end select
988
989 ! compute oscillator strengths on all processes for the ScaLAPACK layout
990 if (cas%mpi_grp%is_root() .or. cas%distributed_matrix) then
991 if (cas%states_are_real) then
992 call doscillator_strengths(cas, gr, st)
993 else
994 call zoscillator_strengths(cas, gr, st)
995 end if
996 end if
997
998 if (cas%calc_forces) then
999 if (cas%states_are_real) then
1000 call dcasida_forces(cas, sys, gr, st)
1001 else
1002 call zcasida_forces(cas, sys, gr, st)
1003 end if
1004 end if
1005
1006 if (cas%states_are_real) then
1007 call dcasida_write(cas, sys)
1008 else
1009 call zcasida_write(cas, sys)
1010 end if
1011
1012 ! clean up
1013 if (cas%type /= casida_eps_diff .or. cas%calc_forces) then
1014 safe_deallocate_a(cas%fxc)
1015 safe_deallocate_a(cas%fxc_grad)
1016 safe_deallocate_a(cas%fxc_grad_spin)
1017 safe_deallocate_a(cas%rho)
1018 end if
1019
1020 pop_sub(casida_work)
1021
1022 contains
1023
1024 ! ---------------------------------------------------------
1025 subroutine solve_eps_diff
1026
1027 integer :: ia
1028 real(real64), allocatable :: w(:)
1029
1030 push_sub(casida_work.solve_eps_diff)
1031
1032 ! initialize progress bar
1033 if (mpi_world%is_root()) call loct_progress_bar(-1, cas%n_pairs)
1034
1035 do ia = 1, cas%n_pairs
1036 cas%w(ia) = st%eigenval(cas%pair(ia)%a, cas%pair(ia)%kk) - &
1037 st%eigenval(cas%pair(ia)%i, cas%pair(ia)%kk)
1038 if (cas%w(ia) < -m_epsilon) then
1039 message(1) = "There is a negative unocc-occ KS eigenvalue difference for"
1040 write(message(2),'("states ",I5," and ",I5," of k-point ",I5,".")') cas%pair(ia)%i, cas%pair(ia)%a, cas%pair(ia)%kk
1041 message(3) = "This indicates an inconsistency between gs, unocc, and/or casida calculations."
1042 call messages_fatal(3, only_root_writes = .true., namespace=sys%namespace)
1043 end if
1044 if (mpi_world%is_root()) call loct_progress_bar(ia, cas%n_pairs)
1045 end do
1046
1047 safe_allocate(w(1:size(cas%w)))
1048 w = cas%w
1049 call sort(w, cas%ind)
1050 safe_deallocate_a(w)
1051
1052 if (mpi_world%is_root()) write(*, "(1x)")
1053
1055 end subroutine solve_eps_diff
1056
1057 end subroutine casida_work
1058
1059 ! ---------------------------------------------------------
1060 real(real64) function casida_matrix_factor(cas, sys)
1061 type(casida_t), intent(in) :: cas
1062 type(electrons_t), intent(in) :: sys
1063
1064 push_sub(casida_matrix_factor)
1065
1066 casida_matrix_factor = m_one
1067
1068 if (cas%type == casida_variational) then
1069 casida_matrix_factor = m_two * casida_matrix_factor
1070 end if
1071
1072 if (sys%st%d%ispin == unpolarized) then
1073 casida_matrix_factor = m_two * casida_matrix_factor
1074 end if
1075
1076 pop_sub(casida_matrix_factor)
1077
1078 end function casida_matrix_factor
1079
1080 ! ---------------------------------------------------------
1081 subroutine qcasida_write(cas, namespace)
1082 type(casida_t), intent(in) :: cas
1083 type(namespace_t), intent(in) :: namespace
1084
1085 integer :: iunit, ia
1087 if (.not. mpi_world%is_root()) return
1088
1089 push_sub(qcasida_write)
1090
1091 call io_mkdir(casida_dir, namespace)
1092 iunit = io_open(casida_dir//'q'//trim(theory_name(cas)), namespace, action='write')
1093 write(iunit, '(a1,a14,1x,a24,1x,a24,1x,a10,3es15.8,a2)') '#','E' , '|<f|exp(iq.r)|i>|^2', &
1094 '<|<f|exp(iq.r)|i>|^2>','; q = (',cas%qvector(1:cas%space_dim),')'
1095 write(iunit, '(a1,a14,1x,a24,1x,a24,1x,10x,a15)') '#', trim(units_abbrev(units_out%energy)), &
1096 trim('-'), &
1097 trim('-'), &
1098 trim('a.u.')
1099
1100 if (cas%avg_order == 0) then
1101 do ia = 1, cas%n_pairs
1102 write(iunit, '(es15.8,es15.8)') units_from_atomic(units_out%energy, cas%w(cas%ind(ia))), cas%qf(cas%ind(ia))
1103 end do
1104 else
1105 do ia = 1, cas%n_pairs
1106 write(iunit, '(3es15.8)') units_from_atomic(units_out%energy, cas%w(cas%ind(ia))), &
1107 cas%qf (cas%ind(ia)), &
1108 cas%qf_avg(cas%ind(ia))
1109 end do
1110 end if
1111
1112 call io_close(iunit)
1113
1114 pop_sub(qcasida_write)
1115
1116 end subroutine qcasida_write
1117
1118 ! ---------------------------------------------------------
1119 character(len=80) pure function theory_name(cas)
1120 type(casida_t), intent(in) :: cas
1122 select case (cas%type)
1123 case (casida_eps_diff)
1124 theory_name = "eps_diff"
1125 case (casida_petersilka)
1126 theory_name = "petersilka"
1127 case (casida_tamm_dancoff)
1128 theory_name = "tamm_dancoff"
1129 case (casida_variational)
1130 theory_name = "variational"
1131 case (casida_casida)
1132 theory_name = "casida"
1133 case default
1134 theory_name = "unknown"
1135 end select
1136
1137 end function theory_name
1138
1139 logical function isnt_degenerate(cas, st, ia, jb)
1140 type(casida_t), intent(in) :: cas
1141 type(states_elec_t), intent(in) :: st
1142 integer, intent(in) :: ia
1143 integer, intent(in) :: jb
1144
1145 push_sub(isnt_degenerate)
1146
1147 isnt_degenerate = (abs((st%eigenval(cas%pair(ia)%a, cas%pair(ia)%kk) - st%eigenval(cas%pair(ia)%i, cas%pair(ia)%kk)) &
1148 - (st%eigenval(cas%pair(jb)%a, cas%pair(jb)%kk) - st%eigenval(cas%pair(jb)%i, cas%pair(jb)%kk))) > 1e-8_real64)
1149
1150 pop_sub(isnt_degenerate)
1151 end function isnt_degenerate
1152
1153 integer function get_global_row(cas, jb_local) result(jb)
1154 implicit none
1155 type(casida_t), intent(inout) :: cas
1156 integer, intent(in) :: jb_local
1157
1158 if (.not. cas%distributed_matrix) then
1159 jb = jb_local
1160 else
1161#ifdef HAVE_SCALAPACK
1162 jb = indxl2g(jb_local, cas%block_size, cas%proc_grid%myrow, 0, cas%proc_grid%nprow)
1163#endif
1164 end if
1165 end function get_global_row
1166
1167 integer function get_global_col(cas, ia_local) result(ia)
1168 implicit none
1169 type(casida_t), intent(inout) :: cas
1170 integer, intent(in) :: ia_local
1171
1172 if (.not. cas%distributed_matrix) then
1173 ia = ia_local
1174 else
1175#ifdef HAVE_SCALAPACK
1176 ia = indxl2g(ia_local, cas%block_size, cas%proc_grid%mycol, 0, cas%proc_grid%npcol)
1177#endif
1178 end if
1179 end function get_global_col
1181 subroutine local_indices(cas, ia, jb, on_this_processor, ia_local, jb_local)
1182 implicit none
1183 type(casida_t), intent(in) :: cas
1184 integer, intent(in) :: ia, jb
1185 logical, intent(out) :: on_this_processor
1186 integer, intent(out) :: ia_local, jb_local
1187#ifdef HAVE_SCALAPACK
1188 integer :: ia_proc, jb_proc
1189#endif
1190
1191 if (.not. cas%distributed_matrix) then
1192 on_this_processor = .true.
1193 ia_local = ia
1194 jb_local = jb
1195 else
1196#ifdef HAVE_SCALAPACK
1197 ia_proc = indxg2p(ia, cas%block_size, cas%proc_grid%mycol, 0, cas%proc_grid%npcol)
1198 jb_proc = indxg2p(jb, cas%block_size, cas%proc_grid%myrow, 0, cas%proc_grid%nprow)
1199 if (cas%proc_grid%mycol == ia_proc .and. cas%proc_grid%myrow == jb_proc) then
1200 on_this_processor = .true.
1201 ia_local = indxg2l(ia, cas%block_size, cas%proc_grid%mycol, 0, cas%proc_grid%npcol)
1202 jb_local = indxg2l(jb, cas%block_size, cas%proc_grid%myrow, 0, cas%proc_grid%nprow)
1203 else
1204 on_this_processor = .false.
1205 ia_local = -1
1206 jb_local = -1
1207 end if
1208#endif
1209 end if
1210 end subroutine local_indices
1211
1212#include "undef.F90"
1213#include "real.F90"
1214#include "casida_inc.F90"
1215#include "undef.F90"
1216#include "complex.F90"
1217#include "casida_inc.F90"
1218
1219end module casida_oct_m
1220
1221!! Local Variables:
1222!! mode: f90
1223!! coding: utf-8
1224!! End:
subroutine solve_eps_diff
Definition: casida.F90:1087
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:1229
integer, parameter solver_scalapack
Definition: casida.F90:198
subroutine zoscillator_strengths(cas, mesh, st)
Definition: casida.F90:3201
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:766
integer function get_global_row(cas, jb_local)
Definition: casida.F90:1215
integer, parameter casida_eps_diff
Definition: casida.F90:191
character(len=80) pure function theory_name(cas)
Definition: casida.F90:1181
subroutine dcasida_forces(cas, sys, gr, st)
Definition: casida.F90:2484
subroutine dcasida_get_matrix(cas, namespace, hm, st, ks, gr, matrix, fxc, fxc_grad, fxc_grad_spin, restart_file, is_forces)
Definition: casida.F90:1754
subroutine local_indices(cas, ia, jb, on_this_processor, ia_local, jb_local)
Definition: casida.F90:1243
subroutine zcasida_solve(cas, sys)
Definition: casida.F90:4617
subroutine casida_work(sys, cas)
this subroutine calculates electronic excitation energies using the matrix formulation of M....
Definition: casida.F90:948
subroutine zcasida_get_matrix(cas, namespace, hm, st, ks, gr, matrix, fxc, fxc_grad, fxc_grad_spin, restart_file, is_forces)
Definition: casida.F90:3624
integer, parameter casida_variational
Definition: casida.F90:191
subroutine qcasida_write(cas, namespace)
Definition: casida.F90:1143
subroutine zcasida_write(cas, sys)
Definition: casida.F90:4755
logical function isnt_degenerate(cas, st, ia, jb)
Definition: casida.F90:1201
subroutine, public casida_run(system, from_scratch)
Definition: casida.F90:294
subroutine doscillator_strengths(cas, mesh, st)
Definition: casida.F90:1331
subroutine dcasida_write(cas, sys)
Definition: casida.F90:2885
real(real64) function casida_matrix_factor(cas, sys)
Definition: casida.F90:1122
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:4354
subroutine casida_type_end(cas)
Definition: casida.F90:893
subroutine dcasida_solve(cas, sys)
Definition: casida.F90:2747
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
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 states_elec_count_pairs(st, namespace, n_pairs, n_occ, n_unocc, is_included, is_frac_occ)
number of occupied-unoccupied pairs for Casida
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
This module defines the unit system, used for input and output.
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:700
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)
Adds to fxc the ADSIC contribution.
Definition: xc_sic.F90:469
This class contains all parameters, needed for Casida calculations.
Definition: casida.F90:203
Class describing the electron system.
Definition: electrons.F90:221
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)