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