Octopus
tdtdm.F90
Go to the documentation of this file.
1!! Copyright (C) 2019-2021 N. Tancogne-Dejean
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use batch_oct_m
24 use comm_oct_m
25 use debug_oct_m
28 use fft_oct_m
29 use global_oct_m
30 use grid_oct_m
32 use io_oct_m
37 use mesh_oct_m
39 use mpi_oct_m
42 use parser_oct_m
51 use types_oct_m
52 use unit_oct_m
54 use xc_oct_m
55
56 implicit none
57
58 private
59 public :: tdtdm_main
60
61contains
62
63 subroutine tdtdm_main() bind(c)
64 integer :: in_file, ii, jj, kk, ierr, ip_h, irow, ifreq, nrow, it
65 integer :: ik, ist, uist, istep, ikpoint, irep, out_file, iop, idim
66 integer :: time_steps, energy_steps, istart, iend, ntiter, Nreplica, Ntrans
67 real(real64) :: dt, tt, weight, kpoint(3), kpoint_sym(3), kred(3), kred_sym(3)
68 real(real64) :: xx_h_sym(3)
69 integer :: irep_h, ip_h_sym, rankmin
70 real(real64) :: start_time, dmin
71 real(real64), allocatable :: Et(:), ftreal(:, :, :), ftimag(:, :, :), tmp(:), omega(:)
72 complex(real64), allocatable :: Xiak(:,:,:), Yiak(:,:,:)
73 real(real64), allocatable :: proj_r(:,:,:,:), proj_i(:,:,:,:)
74 real(real64), allocatable :: proj_r_corr(:,:), proj_i_corr(:,:), centers(:,:)
75 complex(real64), allocatable :: tdm(:,:), tdm_1D(:,:,:,:)
76 complex(real64), allocatable, target :: psi(:,:), upsi(:,:)
77 complex(real64), allocatable :: phase(:,:,:), ftcmplx(:,:)
78 complex(real64), contiguous, pointer :: psi_sym(:,:), upsi_sym(:,:)
79 type(spectrum_t) :: spectrum
80 type(electrons_t), pointer :: sys
81 type(batch_t) :: projb_r, projb_i, ftrealb, ftimagb
82 character(len=MAX_PATH_LEN) :: fname
83 type(states_elec_t), pointer :: st
84 type(states_elec_t) :: gs_st
85 type(restart_t) :: restart
86 type(unit_t) :: fn_unit
87 integer :: kpt_start, kpt_end, supercell(3), nomega, ncols
88 type(block_t) :: blk
89 real(real64) :: pos_h(3), norm
90
91 ! Initializion
92 call global_init()
93 call parser_init()
94
95 call messages_init()
96 call io_init()
97
99
100 call messages_experimental("oct-tdtdm utility")
103
104 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
106
107 call spectrum_init(spectrum, global_namespace)
108
109 st => sys%st
110
111 if(sys%st%d%ispin == spinors) then
112 call messages_not_implemented('oct-tdtdm with spinors')
113 end if
115 if(st%parallel_in_states) then
116 call messages_not_implemented("oct-tdtdm with states parallelization")
117 end if
118
119 if(sys%gr%parallel_in_domains) then
120 call messages_not_implemented("oct-tdtdm with domain parallelization")
121 end if
122
123 !%Variable TDTDMFrequencies
124 !%Type block
125 !%Section Utilities::oct-tdtdm
126 !%Description
127 !% This block defines for which frequencies the analysis is performed.
128 !%
129 !% Each row of the block indicates a frequency.
130 !%End
131 if (parse_block(global_namespace, 'TDTDMFrequencies', blk) == 0) then
132
133 nrow = parse_block_n(blk)
134 nomega = nrow
135
136 safe_allocate(omega(1:nrow))
137 !read frequencies
138 do irow = 0, nrow-1
139 call parse_block_float(blk, irow, 0, omega(irow+1))
140 end do
141
142 call parse_block_end(blk)
143 else
144 message(1) = "oct-tdtdm: TDTDMFrequencies must be defined."
145 call messages_fatal(1)
146 end if
147
148 ! We check that the resonant and antiresonant transitions are contained in the
149 ! energy range of the Fourier transforms
150 if(any(omega > spectrum%max_energy)) then
151 message(1) = "One requested frequecy is larger than PropagationSpectrumMaxEnergy."
152 message(2) = "Please increase the value of PropagationSpectrumMaxEnergy."
153 call messages_fatal(2)
154 end if
155 if(any(omega > -spectrum%min_energy)) then
156 message(1) = "One requested frequency is larger than -PropagationSpectrumMinEnergy."
157 message(2) = "Please decrease the value of PropagationSpectrumMinEnergy."
158 call messages_fatal(2)
159 end if
160
161
162 call states_elec_copy(gs_st, st, exclude_wfns = .true., exclude_eigenval = .true.)
163
164 safe_deallocate_a(gs_st%node)
165
166 call restart%init(global_namespace, restart_proj, restart_type_load, sys%mc, ierr, mesh=sys%gr)
167 if(ierr == 0) call states_elec_look(restart, ii, jj, gs_st%nst, ierr)
168 if(ierr /= 0) then
169 message(1) = "oct-tdtdm: Unable to read states information."
170 call messages_fatal(1)
171 end if
172
173 ! allocate memory
174 safe_allocate(gs_st%occ(1:gs_st%nst, 1:gs_st%nik))
175 safe_allocate(gs_st%eigenval(1:gs_st%nst, 1:gs_st%nik))
176
177 ! We want all the task to have all the states
178 ! States can be distibuted for the states we propagate.
179 safe_allocate(gs_st%node(1:gs_st%nst))
180 gs_st%node(:) = 0
181 call kpoints_distribute(gs_st, sys%mc)
183
184 kpt_start = gs_st%d%kpt%start
185 kpt_end = gs_st%d%kpt%end
186
187 kpoint = m_zero
188
189 gs_st%eigenval = huge(gs_st%eigenval)
190 gs_st%occ = m_zero
191 if(gs_st%d%ispin == spinors) then
192 safe_deallocate_a(gs_st%spin)
193 safe_allocate(gs_st%spin(1:3, 1:gs_st%nst, 1:gs_st%nik))
194 end if
195
196 call states_elec_allocate_wfns(gs_st, sys%gr, type_cmplx)
197 call states_elec_load(restart, global_namespace, sys%space, gs_st, sys%gr, sys%kpoints, fixed_occ=.true., ierr=ierr)
198 if(ierr /= 0 .and. ierr /= (gs_st%st_end-gs_st%st_start+1)*(kpt_end-kpt_start+1)*gs_st%d%dim) then
199 message(1) = "oct-tdtdm: Unable to read wavefunctions for TDOutput."
200 call messages_fatal(1)
201 end if
202 call restart%end()
203
204
205 in_file = io_open('td.general/projections', action='read', status='old')
206 call io_skip_header(in_file)
207 call spectrum_count_time_steps(global_namespace, in_file, time_steps, dt)
208 dt = units_to_atomic(units_out%time, dt)
209
210
211 safe_allocate(tmp(1:st%nst*gs_st%nst*st%nik*2))
212 safe_allocate(proj_r(1:time_steps, 1:gs_st%nst, 1:st%nst, 1:st%nik))
213 safe_allocate(proj_i(1:time_steps, 1:gs_st%nst, 1:st%nst, 1:st%nik))
214
215
216 call io_skip_header(in_file)
217
218 do ii = 1, time_steps
219 read(in_file, *) jj, tt, (tmp(kk), kk = 1, st%nst*gs_st%nst*st%nik*2)
220 do ik = 1, st%nik
221 do ist = 1, st%nst
222 do uist = 1, gs_st%nst
223 jj = (ik-1)*st%nst*gs_st%nst + (ist-1)*gs_st%nst + uist
224 proj_r(ii, uist, ist, ik) = tmp((jj-1)*2+1)
225 ! Here we add a minus sign, as we want to get <\phi_0 | \psi(t)>
226 ! and td_occup computes the complex conjugaute of this
227 proj_i(ii, uist, ist, ik) = -tmp((jj-1)*2+2)
228 end do
229 end do
230 end do
231 end do
232 safe_deallocate_a(tmp)
233
234 call io_close(in_file)
235
236 write(message(1), '(a, i7, a)') "oct-tdtdm: Read ", time_steps, " steps from file '"// &
237 trim(io_workpath('td.general/projections'))//"'"
238 call messages_info(1)
239
240 start_time = spectrum%start_time
241
242 ! Phase correction of the projections before doing the Fourier transforms
243 ! See Eq. (5) of Williams et al., JCTC 17, 1795 (2021)
244 ! We need to multiply C_ik(t)e^{-ie_kt} (the projection of \phi_i(t) on \phi_k^GS)
245 ! by e^{ie_it}, which is obtained by the cc of the projection of \phi_i(t) on \phi_i^GS
246 ! Here we only care about optical transitions (so TD occupied to GS unocc)
247 safe_allocate(proj_r_corr(1:time_steps, 1:gs_st%nst*st%nst*(kpt_end-kpt_start+1)))
248 safe_allocate(proj_i_corr(1:time_steps, 1:gs_st%nst*st%nst*(kpt_end-kpt_start+1)))
249 proj_r_corr = m_zero
250 proj_i_corr = m_zero
251 do ik = kpt_start, kpt_end
252 do ist = 1, st%nst
253 do uist = ist+1, gs_st%nst
254 jj = (ik-kpt_start)*st%nst*gs_st%nst+(ist-1)*gs_st%nst+uist
255 do ii = 1, time_steps
256 norm = hypot(proj_r(ii, ist, ist, ik),proj_i(ii, ist, ist, ik))
257 if (norm > m_epsilon) then
258 proj_r_corr(ii, jj) = (proj_r(ii, uist, ist, ik) * proj_r(ii, ist, ist, ik) &
259 + proj_i(ii, uist, ist, ik) * proj_i(ii, ist, ist, ik))/norm
260 proj_i_corr(ii, jj) =(-proj_r(ii, uist, ist, ik) * proj_i(ii, ist, ist, ik) &
261 + proj_i(ii, uist, ist, ik) * proj_r(ii, ist, ist, ik))/norm
262 else
263 proj_r_corr(ii, jj) = m_zero
264 proj_i_corr(ii, jj) = m_zero
265 end if
266 end do
267 end do
268 end do
269 end do
270
271 safe_deallocate_a(proj_r)
272 safe_deallocate_a(proj_i)
273
274 ! Find out the iteration numbers corresponding to the time limits.
275 call spectrum_fix_time_limits(spectrum, time_steps, dt, istart, iend, ntiter)
276 istart = max(1, istart)
277 energy_steps = spectrum_nenergy_steps(spectrum)
278
279 safe_allocate(ftreal(1:energy_steps, 1:st%nst*gs_st%nst*(kpt_end-kpt_start+1), 1:2))
280 safe_allocate(ftimag(1:energy_steps, 1:st%nst*gs_st%nst*(kpt_end-kpt_start+1), 1:2))
281
282 call batch_init(projb_r, 1, 1, st%nst*gs_st%nst*(kpt_end-kpt_start+1), proj_r_corr)
283 call batch_init(projb_i, 1, 1, st%nst*gs_st%nst*(kpt_end-kpt_start+1), proj_i_corr)
284 call batch_init(ftrealb, 1, 1, st%nst*gs_st%nst*(kpt_end-kpt_start+1), ftreal(:,:,1))
285 call batch_init(ftimagb, 1, 1, st%nst*gs_st%nst*(kpt_end-kpt_start+1), ftimag(:,:,1))
286
287 write(message(1), '(a)') "oct-tdtdm: Fourier transforming real part of the projections"
288 call messages_info(1)
289
290 call spectrum_fourier_transform(spectrum%method, spectrum_transform_cos, spectrum%noise, &
291 istart, iend, spectrum%start_time, dt, projb_r, spectrum%min_energy, spectrum%max_energy, spectrum%energy_step, ftrealb)
292
293 call spectrum_fourier_transform(spectrum%method, spectrum_transform_sin, spectrum%noise, &
294 istart, iend, spectrum%start_time, dt, projb_r, spectrum%min_energy, spectrum%max_energy, spectrum%energy_step, ftimagb)
295
296 call ftrealb%end()
297 call ftimagb%end()
298
299 safe_allocate(ftcmplx(1:energy_steps, 1:st%nst*gs_st%nst*(kpt_end-kpt_start+1)))
300 do ii = 1, st%nst*gs_st%nst*(kpt_end-kpt_start+1)
301 ftcmplx(1:energy_steps,ii) = cmplx(ftreal(1:energy_steps,ii,1), ftimag(1:energy_steps,ii,1), real64)
302 end do
303
304 write(message(1), '(a)') "oct-tdtdm: Fourier transforming imaginary part of the projections"
305 call messages_info(1)
306
307 call batch_init(ftrealb, 1, 1, st%nst*gs_st%nst*(kpt_end-kpt_start+1), ftreal(:,:,2))
308 call batch_init(ftimagb, 1, 1, st%nst*gs_st%nst*(kpt_end-kpt_start+1), ftimag(:,:,2))
309
310 call spectrum_fourier_transform(spectrum%method, spectrum_transform_cos, spectrum%noise, &
311 istart, iend, spectrum%start_time, dt, projb_i, spectrum%min_energy, spectrum%max_energy, spectrum%energy_step, ftrealb)
312
313 call spectrum_fourier_transform(spectrum%method, spectrum_transform_sin, spectrum%noise, &
314 istart, iend, spectrum%start_time, dt, projb_i, spectrum%min_energy, spectrum%max_energy, spectrum%energy_step, ftimagb)
315
316 call projb_i%end()
317 call projb_r%end()
318 call ftrealb%end()
319 call ftimagb%end()
320 safe_deallocate_a(proj_r_corr)
321 safe_deallocate_a(proj_i_corr)
322
323 do ii = 1, st%nst*gs_st%nst*(kpt_end-kpt_start+1)
324 ftcmplx(1:energy_steps,ii) = ftcmplx(1:energy_steps,ii) + m_zi*ftreal(1:energy_steps,ii,2) - ftimag(1:energy_steps,ii,2)
325 end do
326
327 safe_deallocate_a(ftreal)
328 safe_deallocate_a(ftimag)
329
330 write(message(1), '(a)') "oct-tdtdm: Constructing the two-particle wavefunctions."
331 call messages_info(1)
332
333 !%Variable SupercellDimensions
334 !%Type block
335 !%Default KPointsGrid
336 !%Section Utilities::oct-tdtdm
337 !%Description
338 !% This block allows to specify the size of the supercell used to plot excitonic wavefunctions.
339 !% If not specified, the code uses the number of k-points for defining the size of the supercell.
340 !%End
341 if (parse_is_defined(sys%namespace, 'SupercellDimensions')) then
342 if (parse_block(sys%namespace, 'SupercellDimensions', blk) == 0) then
343 ncols = parse_block_cols(blk, 0)
344 if (ncols /= sys%space%dim) then
345 write(message(1),'(a,i3,a,i3)') 'SupercellDimensions has ', ncols, ' columns but must have ', sys%space%dim
346 call messages_fatal(1, namespace=sys%namespace)
347 end if
348 do ii = 1, sys%space%dim
349 call parse_block_integer(blk, 0, ii - 1, supercell(ii))
350 end do
351
352 call parse_block_end(blk)
353 end if
354 else
355 supercell(1:sys%space%dim) = sys%kpoints%nik_axis(1:sys%space%dim)
356 end if
357
358 nreplica = product(supercell(1:sys%space%dim))
359
360 ! The center of each replica of the unit cell
361 safe_allocate(centers(1:sys%space%dim, 1:nreplica))
362 irep = 1
363 do ii = 0, supercell(1)-1
364 do jj = 0, supercell(2)-1
365 do kk = 0, supercell(3)-1
366 centers(1, irep) = -floor((supercell(1)-1)/m_two)+ii
367 centers(2, irep) = -floor((supercell(2)-1)/m_two)+jj
368 centers(3, irep) = -floor((supercell(3)-1)/m_two)+kk
369 centers(:, irep) = matmul(sys%ions%latt%rlattice, centers(:, irep))
370 irep = irep + 1
371 end do
372 end do
373 end do
374
375 ! The phase for each center
376 irep = 0
377 do ik = kpt_start, kpt_end
378 ikpoint = gs_st%d%get_kpoint_index(ik)
379 irep = max(irep, kpoints_get_num_symmetry_ops(sys%kpoints, ikpoint))
380 end do
381 safe_allocate(phase(kpt_start:kpt_end, 1:irep, 1:nreplica))
382 do irep = 1, nreplica
383 do ik = kpt_start, kpt_end
384 ikpoint = gs_st%d%get_kpoint_index(ik)
385 kpoint(1:sys%space%dim) = sys%kpoints%get_point(ikpoint)
386 do ii = 1, kpoints_get_num_symmetry_ops(sys%kpoints, ikpoint)
387 iop = kpoints_get_symmetry_ops(sys%kpoints, ikpoint, ii)
388
389 if (sys%kpoints%use_symmetries) then !We apply the symmetry
390 call kpoints_to_reduced(sys%kpoints%latt, kpoint, kred)
391 call symmetries_apply_kpoint_red(sys%kpoints%symm, iop, kred, kred_sym)
392 call kpoints_to_absolute(sys%kpoints%latt, kred_sym, kpoint_sym)
393 else
394 kpoint_sym = kpoint
395 end if
396 phase(ik, ii, irep) = exp(-m_zi*sum(kpoint_sym(1:sys%space%dim)*centers(:, irep)))
397 end do
398 end do
399 end do
400
401 ! Position of the hole, here assumed to be on top of the first atom
402 ! To be obtained from the input file
403 if(sys%space%dim > 1) then
404 call tdtdm_get_hole_position(pos_h, ip_h)
405 end if
406
407 ntrans = 0
408 ! Here we assume that there is a clear gap, so the information at Gamma is enough
409 do ist = 1, gs_st%nst
410 if(abs(gs_st%occ(ist, 1)) < m_min_occ) cycle
411
412 do uist = 1, gs_st%nst
413 if(abs(gs_st%occ(uist, 1)) > m_min_occ) cycle
414 weight = gs_st%kweights(1) * (gs_st%occ(ist, 1)-gs_st%occ(uist, 1))
415 if(abs(weight) < m_min_occ) cycle
416 ntrans = ntrans + 1
417 end do
418 end do
419 if(ntrans == 0) then
420 write(message(1), '(a)') "oct-tdtdm: No transition found."
421 write(message(2), '(a)') "Please check that unoccupied states are included in the ground state calculation."
422 call messages_fatal(2)
423 end if
424
425 safe_allocate(xiak(1:st%nst, 1:gs_st%nst, 1:st%nik))
426 safe_allocate(yiak(1:st%nst, 1:gs_st%nst, 1:st%nik))
427 safe_allocate(et(1:ntrans*st%nik))
428 safe_allocate(psi(1:sys%gr%np, 1:gs_st%d%dim))
429 safe_allocate(upsi(1:sys%gr%np, 1:gs_st%d%dim))
430
431 if(sys%kpoints%use_symmetries) then
432 safe_allocate(psi_sym(1:sys%gr%np, 1:st%d%dim))
433 safe_allocate(upsi_sym(1:sys%gr%np, 1:st%d%dim))
434 end if
435
436 select case(sys%space%dim)
437 case(2,3)
438 safe_allocate(tdm(1:sys%gr%np, 1:nreplica))
439 case(1)
440 safe_allocate(tdm_1d(1:sys%gr%np, 1:sys%gr%np, 1:nreplica, 1:nreplica))
441 end select
442
443 do ifreq = 1, nomega
444
445 write(message(1), '(a, f6.4, a)') "oct-tdtdm: Constructing the two-particle wavefunction at ", omega(ifreq), " Ha."
446 call messages_info(1)
447
448 select case(sys%space%dim)
449 case(2,3)
450 tdm = m_z0
451 case(1)
452 tdm_1d = m_z0
453 end select
454
455 et = m_zero
456 xiak = m_z0
457 yiak = m_z0
458
459 ! Local transition index
460 it = (kpt_start-1)*ntrans + 1
461
462 do ik = kpt_start, kpt_end
463 ikpoint = st%d%get_kpoint_index(ik)
464
465 do ist = 1, st%nst
466 if(abs(gs_st%occ(ist, ik)) < m_min_occ) cycle
467
468 call states_elec_get_state(gs_st, sys%gr, ist, ik, psi)
469 if (sys%hm%phase%is_allocated()) then
470 call sys%hm%phase%apply_to_single(psi, sys%gr%np, gs_st%d%dim, ik, .false.)
471 end if
472
473 do uist = 1, gs_st%nst
474 if(abs(gs_st%occ(uist, ik)) > m_min_occ) cycle
475
476 ! For a given requested frequency, we get the corresponding values of Xia and Yia
477 ! One correspond to the +\Omega frequency, the other one to the -\Omega frequency
478 ! For Xiak, we use the fact that TF[f*](\Omega) = (TF[f](-\Omega))^*
479 jj = (ik-kpt_start)*st%nst*gs_st%nst+(ist-1)*gs_st%nst+uist
480 istep = int((+omega(ifreq)-spectrum%min_energy)/spectrum%energy_step)
481 xiak(ist, uist, ik) = conjg(ftcmplx(istep, jj))
482 istep = int((+omega(ifreq)-spectrum%min_energy)/spectrum%energy_step)
483 yiak(ist, uist, ik) = ftcmplx(istep, jj)
484
485
486 weight = gs_st%kweights(ik) * (gs_st%occ(ist, ik)-gs_st%occ(uist, ik)) &
487 / kpoints_get_num_symmetry_ops(sys%kpoints, ikpoint)
488 if(abs(weight) < m_epsilon) cycle
489
490 call states_elec_get_state(gs_st, sys%gr, uist, ik, upsi)
491 if(sys%hm%phase%is_allocated()) then
492 call sys%hm%phase%apply_to_single(upsi, sys%gr%np, st%d%dim, ik, .false.)
493 end if
494
495 do ii = 1, kpoints_get_num_symmetry_ops(sys%kpoints, ikpoint)
496 iop = kpoints_get_symmetry_ops(sys%kpoints, ikpoint, ii)
497
498 if(sys%kpoints%use_symmetries) then
499 do idim = 1, st%d%dim
500 call zgrid_symmetrize_single(sys%gr, iop, psi(:,idim), psi_sym(:,idim))
501 call zgrid_symmetrize_single(sys%gr, iop, upsi(:,idim), upsi_sym(:,idim))
502 end do
503
504 ! We need to get the position of the hole after applying the symmetry operation too
505 xx_h_sym = symm_op_apply_cart(sys%kpoints%symm%ops(iop), pos_h)
506 xx_h_sym = sys%ions%latt%fold_into_cell(xx_h_sym)
507 ! At the moment, we ignore rankmin
508 assert(.not.sys%gr%parallel_in_domains)
509 ip_h_sym = mesh_nearest_point(sys%gr, xx_h_sym, dmin, rankmin)
510 else
511 psi_sym => psi
512 upsi_sym => upsi
513 ip_h_sym = ip_h
514 end if
515
516 ! We now compute the single mode TDTDM
517 ! See Eq. (5) of Williams et al., JCTC 17, 1795 (2021)
518 ! We take here the complex conjugate of the 2-body wavefunction
519 select case(sys%space%dim)
520 case(2,3)
521 do irep = 1, nreplica
522 call lalg_axpy(sys%gr%np, phase(ik, ii, irep) * weight &
523 * conjg(xiak(ist,uist,ik))*conjg(psi_sym(ip_h_sym,1)), upsi_sym(:, 1), tdm(:,irep))
524 call lalg_axpy(sys%gr%np, phase(ik, ii, irep) * weight &
525 * yiak(ist,uist,ik)*conjg(upsi_sym(ip_h_sym,1)), psi_sym(:, 1), tdm(:,irep))
526 end do
527 case(1)
528 ! In the 1D case, we contruct the full TDTDM of r_e, r_h
529 do irep_h = 1, nreplica
530 do irep = 1, nreplica
531 do ip_h = 1, sys%gr%np
532 call lalg_axpy(sys%gr%np, phase(ik, ii, irep) * conjg(phase(ik, ii, irep_h)) &
533 * weight * conjg(xiak(ist,uist,ik)) * conjg(psi_sym(ip_h,1)), &
534 upsi_sym(:, 1), tdm_1d(:, ip_h, irep, irep_h))
535 call lalg_axpy(sys%gr%np, phase(ik, ii, irep) * conjg(phase(ik, ii, irep_h)) &
536 * weight * conjg(yiak(ist,uist,ik)) * conjg(upsi_sym(ip_h,1)), &
537 psi_sym(:, 1), tdm_1d(:, ip_h, irep, irep_h))
538 end do
539 end do
540 end do
541 end select
542
543 end do ! ii
544
545 et(it) = gs_st%eigenval(uist, ik) - gs_st%eigenval(ist, ik)
546 it = it + 1
547 end do
548 end do
549 end do
550
551 if(gs_st%d%kpt%parallel) then
552 if(sys%space%dim > 1) then
553 call comm_allreduce(gs_st%d%kpt%mpi_grp, tdm)
554 else
555 call comm_allreduce(gs_st%d%kpt%mpi_grp, tdm_1d)
556 end if
557 call comm_allreduce(gs_st%d%kpt%mpi_grp, et)
558 call comm_allreduce(gs_st%d%kpt%mpi_grp, xiak)
559 call comm_allreduce(gs_st%d%kpt%mpi_grp, yiak)
560 end if
561
563
565
566 end do ! ifreq
567
568 safe_deallocate_a(et)
569 safe_deallocate_a(xiak)
570 safe_deallocate_a(yiak)
571 safe_deallocate_a(tdm)
572 safe_deallocate_a(tdm_1d)
573
574 safe_deallocate_a(psi)
575 safe_deallocate_a(upsi)
576 if(sys%kpoints%use_symmetries) then
577 safe_deallocate_p(psi_sym)
578 safe_deallocate_p(upsi_sym)
579 end if
580 safe_deallocate_a(ftcmplx)
581 safe_deallocate_a(centers)
582 safe_deallocate_a(phase)
583 safe_deallocate_a(omega)
584
585 safe_deallocate_p(sys)
586 call states_elec_end(gs_st)
587 call fft_all_end()
588 call io_end()
590 call messages_end()
591 call parser_end()
592 call global_end()
593
594 contains
595
596 ! -----------------------------------------------------------------
597 ! Determines the position of the hole, either from the input or using the
598 ! first atom in the cell.
599 ! This returns the index of the point in the mesh closest to the position.
600 subroutine tdtdm_get_hole_position(xx_h, ip_h)
601 real(real64), intent(out) :: xx_h(1:sys%space%dim)
602 integer, intent(out) :: ip_h
603
604 real(real64) :: dmin
605 integer :: idir, rankmin
606
608
609 !%Variable TDTDMHoleCoordinates
610 !%Type float
611 !%Section Utilities::oct-tdtdm
612 !%Description
613 !% The position of the hole used to compute the TDTDM,
614 !% in Cartesian coordinates.
615 !% Note that the code will use the closest grid point.
616 !%
617 !% The coordinates of the hole are specified in the following way
618 !% <tt>%TDTDMHoleCoordinates
619 !% <br>&nbsp;&nbsp;hole_x | hole_y | hole_z
620 !% <br>%</tt>
621 !%
622 !% If TDTDMHoleCoordinates or TDTDMHoleReducedCoordinates are not specified,
623 !% the code will use the coordinate of the first atom in the cell.
624 !%End
625
626 if(parse_block(global_namespace, 'TDTDMHoleCoordinates', blk) == 0) then
627 if(parse_block_cols(blk,0) < sys%space%dim) then
628 call messages_input_error(global_namespace, 'TDTDMHoleCoordinates')
629 end if
630 do idir = 1, sys%space%dim
631 call parse_block_float(blk, 0, idir - 1, xx_h(idir), units_inp%length)
632 end do
633 call parse_block_end(blk)
634 else
635 !%Variable TDTDMHoleReducedCoordinates
636 !%Type float
637 !%Section Utilities::oct-tdtdm
638 !%Description
639 !% Same as TDTDMHoleCoordinates, except that coordinates are given in reduced coordinates
640 !%End
641
642 if(parse_block(global_namespace, 'TDTDMHoleReducedCoordinates', blk) == 0) then
643 if(parse_block_cols(blk,0) < sys%space%dim) then
644 call messages_input_error(global_namespace, 'TDTDMHoleReducedCoordinates')
645 end if
646 do idir = 1, sys%space%dim
647 call parse_block_float(blk, 0, idir - 1, xx_h(idir))
648 end do
649 call parse_block_end(blk)
650 xx_h = sys%ions%latt%red_to_cart(xx_h)
651 else
652 xx_h(1:sys%space%dim) = sys%ions%pos(1:sys%space%dim, 1)
653 end if
654 end if
655
656 ! We bring back the hole into the cell
657 xx_h = sys%ions%latt%fold_into_cell(xx_h)
658
659 ! At the moment, we ignore rankmin
660 assert(.not.sys%gr%parallel_in_domains)
661 ip_h = mesh_nearest_point(sys%gr, xx_h, dmin, rankmin)
662 write(message(1), '(a, 3(1x,f7.4,a))') "oct-tdtdm: Requesting the hole at (", xx_h(1), &
663 ",", xx_h(2), ",", xx_h(3), ")."
664 call mesh_r(sys%gr, ip_h, dmin, coords=xx_h)
665 write(message(2), '(a, 3(1x,f7.4,a))') "oct-tdtdm: Setting the hole at (", xx_h(1), &
666 ",", xx_h(2), ",", xx_h(3), ")."
667
668 call messages_info(2)
669
671 end subroutine tdtdm_get_hole_position
672
673 subroutine tdtdm_output_density()
674 real(real64), allocatable :: den(:,:), den_1d(:,:,:,:)
675 real(real64) :: norm, xx(3), xx_h(3)
676 integer :: iunit
677
678 push_sub(tdtdm_output_density)
679
680 ! We compute the TDM density
681 select case(sys%space%dim)
682 case(2,3)
683 safe_allocate(den(1:sys%gr%np, 1:nreplica))
684 do irep = 1, nreplica
685 do ii = 1, sys%gr%np
686 den(ii, irep) = real(tdm(ii, irep)*conjg(tdm(ii, irep)), real64)
687 end do
688 end do
689
690 ! Here we renormalize to avoid too small numbers in the outputs
691 norm = maxval(den)
692 call lalg_scal(sys%gr%np, nreplica, m_one/norm, den)
694 case(1)
695 safe_allocate(den_1d(1:sys%gr%np, 1:sys%gr%np, 1:nreplica, 1:nreplica))
696 do irep_h = 1, nreplica
697 do irep = 1, nreplica
698 do ip_h = 1, sys%gr%np
699 do ii = 1, sys%gr%np
700 tdm_1d(ii, ip_h, irep, irep_h) = conjg(tdm_1d(ii, ip_h, irep, irep_h))
701 den_1d(ii, ip_h, irep, irep_h) = real(tdm_1d(ii, ip_h, irep, irep_h)*conjg(tdm_1d(ii,ip_h, irep, irep_h)), real64)
702 end do
703 end do
704 end do
705 end do
706 end select
707
708 fn_unit = units_out%length**(-sys%space%dim)
709
710 select case(sys%space%dim)
711 case(2,3)
712 write(fname, '(a, f0.4)') 'tdm_density-0', omega(ifreq)
713 call io_function_output_supercell(io_function_fill_how("XCrySDen"), "td.general", fname, &
714 sys%gr, sys%space, sys%ions%latt, den, centers, supercell, fn_unit, &
715 ierr, global_namespace, pos=sys%ions%pos, atoms=sys%ions%atom, grp = st%dom_st_kpt_mpi_grp, extra_atom=pos_h)
716
717 call io_function_output_supercell(io_function_fill_how("PlaneZ"), "td.general", fname, &
718 sys%gr, sys%space, sys%ions%latt, den, centers, supercell, fn_unit, &
719 ierr, global_namespace, grp = st%dom_st_kpt_mpi_grp)
720
721 safe_deallocate_a(den)
722
723 case(1)
724
725 call tdtdm_get_hole_position(pos_h, ip_h)
726 irep_h = floor(supercell(1)/m_two)
727
728 write(fname, '(a, f0.4)') 'tdm_density-0', omega(ifreq)
729 call io_function_output_supercell(io_function_fill_how("AxisX"), "td.general", fname, &
730 sys%gr, sys%space, sys%ions%latt, &
731 den_1d(:,ip_h,:,irep_h), centers, supercell, fn_unit, ierr, global_namespace, &
732 grp = st%dom_st_kpt_mpi_grp)
733
734 write(fname, '(a, f0.4)') 'tdm_wfn-0', omega(ifreq)
735 call io_function_output_supercell(io_function_fill_how("AxisX"), "td.general", fname, &
736 sys%gr, sys%space, sys%ions%latt, &
737 tdm_1d(:,ip_h,:,irep_h), centers, supercell, fn_unit, ierr, global_namespace, &
738 grp = st%dom_st_kpt_mpi_grp)
739
740 assert(.not.sys%gr%parallel_in_domains)
741 if (mpi_world%is_root()) then
742 write(fname, '(a, f0.4)') 'td.general/tdm_density-0', omega(ifreq)
743 iunit = io_open(fname, action='write')
744 write(iunit, '(a)', iostat=ierr) '# r_e r_h Re(\Psi(r_e,r_h)) Im(\Psi(r_e,r_h)) |\Psi(r_e,r_h)|^2'
745
746 do irep_h = 1, nreplica
747 do ip_h = 1, sys%gr%np
748 xx_h = units_from_atomic(units_out%length, mesh_x_global(sys%gr, i4_to_i8(ip_h)) &
749 + centers(1:sys%space%dim, irep_h))
750
751 do irep = 1, nreplica
752 do ii = 1, sys%gr%np
753 xx = units_from_atomic(units_out%length, mesh_x_global(sys%gr, i4_to_i8(ii)) &
754 + centers(1:sys%space%dim, irep))
755 write(iunit, '(5es23.14E3)', iostat=ierr) xx(1), xx_h(1), &
756 real(units_from_atomic(fn_unit, tdm_1D(ii, ip_h, irep, irep_h)), real64) ,&
757 aimag(units_from_atomic(fn_unit, tdm_1D(ii, ip_h, irep, irep_h))), &
758 units_from_atomic(fn_unit, den_1D(ii, ip_h, irep, irep_h))
759 end do
760 end do
761 end do
762 end do
763 end if
764
765 safe_deallocate_a(den_1d)
766 end select
767
768
769 pop_sub(tdtdm_output_density)
770 end subroutine tdtdm_output_density
771
772 subroutine tdtdm_excitonic_weight()
773 real(real64), allocatable :: weight(:,:)
774
775 if (.not. mpi_world%is_root()) return
776
777 push_sub(tdtdm_excitonic_weight)
778
779 safe_allocate(weight(1:st%nik, 1:gs_st%nst))
780 weight = m_zero
781
782 do ik = 1, st%nik
783 do ist = 1, st%nst
784 if(abs(gs_st%occ(ist, ik)) < m_min_occ) cycle
785
786 do uist = ist+1, gs_st%nst
787 if(abs(gs_st%occ(uist, ik)) > m_min_occ) cycle
788
789 weight(ik, ist) = weight(ik, ist) + abs(xiak(ist, uist, ik))**2
790 weight(ik, uist) = weight(ik,uist) + abs(yiak(ist, uist, ik))**2
791 end do
792 end do
793 end do
794
795 write(fname, '(a, f0.4)') 'td.general/tdm_weights-0', omega(ifreq)
796 out_file = io_open(fname, action='write')
797 write(out_file, '(a)') '# ik - kx - ky - kz - sum weights - eigenval and weights(ist,ik) '
798 do ik = 1, st%nik
799 ikpoint = st%d%get_kpoint_index(ik)
800 kpoint(1:sys%space%dim) = sys%kpoints%reduced%point1BZ(1:sys%space%dim,ikpoint)
801 write(out_file, '(i4,4e15.6)', advance='no') ik, kpoint(1:3), sum(weight(ik, 1:gs_st%nst))
802 do uist = 1, gs_st%nst-1
803 write(out_file, '(2e15.6)', advance='no') gs_st%eigenval(uist, ik), weight(ik, uist)
804 end do
805 write(out_file, '(e15.6)') weight(ik, uist)
806 end do
807 call io_close(out_file)
808
809 safe_deallocate_a(weight)
810
812 end subroutine tdtdm_excitonic_weight
813 end subroutine tdtdm_main
814end module tdtdm_main_oct_m
815
816!! Local Variables:
817!! mode: f90
818!! coding: utf-8
819!! End:
initialize a batch with existing memory
Definition: batch.F90:294
constant times a vector plus a vector
Definition: lalg_basic.F90:192
scales a vector by a constant
Definition: lalg_basic.F90:168
double hypot(double __x, double __y) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
double floor(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
Definition: batch.F90:133
This module handles the calculation mode.
type(calc_mode_par_t), public calc_mode_par
Singleton instance of parallel calculation mode.
integer, parameter, public p_strategy_states
parallelization in states
integer, parameter, public spinors
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:118
subroutine, public fft_all_init(namespace)
initialize the table
Definition: fft.F90:301
subroutine, public fft_all_end()
delete all plans
Definition: fft.F90:427
real(real64), parameter, public m_two
Definition: global.F90:200
subroutine, public global_end()
Finalise parser varinfo file, and MPI.
Definition: global.F90:493
real(real64), parameter, public m_zero
Definition: global.F90:198
complex(real64), parameter, public m_z0
Definition: global.F90:208
complex(real64), parameter, public m_zi
Definition: global.F90:212
real(real64), parameter, public m_epsilon
Definition: global.F90:214
subroutine, public global_init(communicator)
Initialise Octopus.
Definition: global.F90:374
real(real64), parameter, public m_one
Definition: global.F90:199
real(real64), parameter, public m_min_occ
Minimal occupation that is considered to be non-zero.
Definition: global.F90:225
This module implements the underlying real-space grid.
Definition: grid.F90:117
subroutine, public zgrid_symmetrize_single(gr, iop, field, symm_field)
Definition: grid.F90:873
integer(int64) function, public io_function_fill_how(where)
Use this function to quickly plot functions for debugging purposes: call dio_function_output(io_funct...
Definition: io.F90:114
subroutine, public io_init(defaults)
If the argument defaults is present and set to true, then the routine will not try to read anything f...
Definition: io.F90:163
subroutine, public io_close(iunit, grp)
Definition: io.F90:465
subroutine, public io_skip_header(iunit)
Definition: io.F90:644
subroutine, public io_end()
Definition: io.F90:269
character(len=max_path_len) function, public io_workpath(path, namespace)
construct path name from given name and namespace
Definition: io.F90:316
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:400
integer pure function, public kpoints_get_num_symmetry_ops(this, ik)
Definition: kpoints.F90:1743
integer pure function, public kpoints_get_symmetry_ops(this, ik, index)
Definition: kpoints.F90:1756
subroutine, public kpoints_to_reduced(latt, kin, kout)
Definition: kpoints.F90:1158
subroutine, public kpoints_to_absolute(latt, kin, kout)
Definition: kpoints.F90:1145
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
integer function, public mesh_nearest_point(mesh, pos, dmin, rankmin)
Returns the index of the point which is nearest to a given vector position pos.
Definition: mesh.F90:389
pure subroutine, public mesh_r(mesh, ip, rr, origin, coords)
return the distance to the origin for a given grid point
Definition: mesh.F90:345
real(real64) function, dimension(1:mesh%box%dim), public mesh_x_global(mesh, ipg)
Given a global point index, this function returns the coordinates of the point.
Definition: mesh.F90:824
subroutine, public messages_end()
Definition: messages.F90:271
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1066
subroutine, public messages_init(output_dir)
Definition: messages.F90:218
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:408
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:689
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1038
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:592
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:338
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:145
type(namespace_t), public global_namespace
Definition: namespace.F90:133
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:461
subroutine, public parser_init()
Initialise the Octopus parser.
Definition: parser.F90:408
subroutine, public parser_end()
End the Octopus parser.
Definition: parser.F90:440
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:621
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:143
subroutine, public profiling_end(namespace)
Definition: profiling.F90:476
subroutine, public profiling_init(namespace)
Create profiling subdirectory.
Definition: profiling.F90:285
integer, parameter, public restart_proj
Definition: restart.F90:154
integer, parameter, public restart_type_load
Definition: restart.F90:182
subroutine, public spectrum_fix_time_limits(spectrum, time_steps, dt, istart, iend, ntiter)
Definition: spectrum.F90:2536
subroutine, public spectrum_fourier_transform(method, transform, noise, time_start, time_end, t0, time_step, time_function, energy_start, energy_end, energy_step, energy_function)
Computes the sine, cosine, (or "exponential") Fourier transform of the real function given in the tim...
Definition: spectrum.F90:2666
subroutine, public spectrum_init(spectrum, namespace, default_energy_step, default_max_energy)
Definition: spectrum.F90:218
integer default
Definition: spectrum.F90:207
integer, parameter, public spectrum_transform_cos
Definition: spectrum.F90:171
integer, parameter, public spectrum_transform_sin
Definition: spectrum.F90:171
subroutine, public spectrum_count_time_steps(namespace, iunit, time_steps, dt)
Definition: spectrum.F90:2401
pure integer function, public spectrum_nenergy_steps(spectrum)
Definition: spectrum.F90:2977
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public states_elec_distribute_nodes(st, namespace, mc)
Distribute states over the processes for states parallelization.
subroutine, public states_elec_end(st)
finalize the states_elec_t object
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special, dest_type, copy_data)
make a (selective) copy of a states_elec_t object
subroutine, public kpoints_distribute(this, mc)
distribute k-points over the nodes in the corresponding communicator
subroutine, public states_elec_look(restart, nik, dim, nst, ierr)
Reads the 'states' file in the restart directory, and finds out the nik, dim, and nst contained in it...
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_load(restart, namespace, space, st, mesh, kpoints, fixed_occ, ierr, iter, lr, lowest_missing, label, verbose, skip)
returns in ierr: <0 => Fatal error, or nothing read =0 => read all wavefunctions >0 => could only rea...
subroutine, public symmetries_apply_kpoint_red(this, iop, aa, bb)
Definition: symmetries.F90:575
subroutine, public tdtdm_main()
Definition: tdtdm.F90:157
type(type_t), parameter, public type_cmplx
Definition: types.F90:135
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_out
subroutine, public unit_system_init(namespace)
type(unit_system_t), public units_inp
the units systems for reading and writing
Definition: xc.F90:118
Class describing the electron system.
Definition: electrons.F90:220
int true(void)
subroutine tdtdm_excitonic_weight()
Definition: tdtdm.F90:866
subroutine tdtdm_output_density()
Definition: tdtdm.F90:767
subroutine tdtdm_get_hole_position(xx_h, ip_h)
Definition: tdtdm.F90:694