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