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