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