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