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