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