Octopus
dielectric_function.F90
Go to the documentation of this file.
1!! Copyright (C) 2008 X. Andrade
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
30 use batch_oct_m
32 use global_oct_m
33 use io_oct_m
36 use math_oct_m
39 use parser_oct_m
41 use space_oct_m
43 use unit_oct_m
45
46 implicit none
47
48 integer :: ierr
49
50 ! Initialize stuff
52
53 call getopt_init(ierr)
54 if (ierr == 0) call getopt_dielectric_function()
55 call getopt_end()
56
57 call parser_init()
58
59 call messages_init()
60
61 call io_init()
63
65
67
69 call io_end()
70 call messages_end()
71
72 call parser_end()
73 call global_end()
74
75contains
76
78
79 integer :: in_file, out_file, ref_file, ii, jj, kk
80 integer :: time_steps, time_steps_ref, energy_steps, istart, iend, ntiter
81 real(real64) :: dt, dt_ref, tt, ww, norm_Aext
82 real(real64), allocatable :: vecpot(:, :), Aext(:), Eind_real(:, :), Eind_imag(:, :)
83 complex(real64), allocatable :: dielectric(:), chi(:), invdielectric(:)
84 real(real64), allocatable :: vecpot_ref(:, :)
85 type(spectrum_t) :: spectrum
86 type(block_t) :: blk
87 type(space_t) :: space
88 type(lattice_vectors_t) :: latt
89 type(batch_t) :: vecpotb, Eind_realb, Eind_imagb
90 character(len=120) :: header
91 real(real64) :: start_time
92 character(len=MAX_PATH_LEN) :: ref_filename
93 complex(real64),allocatable :: Eind(:)
94
95 call spectrum_init(spectrum, global_namespace)
96
99
100 safe_allocate(aext(1:space%dim))
101 safe_allocate(eind(1:space%dim))
102
103 if (parse_block(global_namespace, 'GaugeVectorField', blk) == 0) then
104
105 do ii = 1, space%dim
106 call parse_block_float(blk, 0, ii - 1, aext(ii))
107 end do
108
109 call parse_block_end(blk)
110
111 else
112
113 message(1) = "Cannot find the GaugeVectorField in the input file"
114 call messages_fatal(1)
115
116 end if
117
118 if(space%dim > 1) then
119 message(1) = "This program assumes that the gauge field is along a "
120 message(2) = "direction for which the dielectric tensor has no off-diagonal terms."
121 message(3) = "If this is not the case the dielectric function and the"
122 message(4) = "susceptibility will be wrong."
123 call messages_warning(4)
124 end if
125
126 start_time = spectrum%start_time
127 call parse_variable(global_namespace, 'GaugeFieldDelay', start_time, spectrum%start_time)
128
129 in_file = io_open('td.general/gauge_field', global_namespace, action='read', status='old', die=.false.)
130 if (in_file < 0) then
131 message(1) = "Cannot open file '"//trim(io_workpath('td.general/gauge_field', global_namespace))//"'"
132 call messages_fatal(1)
133 end if
134
135 ! Get the number of iterations and the time-step
136 call io_skip_header(in_file)
137 call spectrum_count_time_steps(global_namespace, in_file, time_steps, dt)
138
139 ! Fix the correct time at which the kick was applied.
140 ! This guaranties that the first time has exactly a zero vector potential
141 ! If we do not do this, we can get some artifacts for transient absorption.
142 spectrum%start_time = ceiling(spectrum%start_time/dt)*dt
143
144 if (parse_is_defined(global_namespace, 'TransientAbsorptionReference')) then
145 !%Variable TransientAbsorptionReference
146 !%Type string
147 !%Default "."
148 !%Section Utilities::oct-propagation_spectrum
149 !%Description
150 !% In case of delayed kick, the calculation of the transient absorption requires
151 !% to substract a reference calculation, containing the gauge-field without the kick
152 !% This reference must be computed using GaugeFieldPropagate=yes and to have
153 !% TDOutput = gauge_field.
154 !% This variables defined the directory in which the reference gauge_field field is,
155 !% relative to the current folder
156 !%End
157
158 call parse_variable(global_namespace, 'TransientAbsorptionReference', '.', ref_filename)
159 ref_file = io_open(trim(ref_filename)//'/gauge_field', global_namespace, action='read', status='old', die=.false.)
160 if (ref_file < 0) then
161 message(1) = "Cannot open reference file '"// &
162 trim(io_workpath(trim(ref_filename)//'/gauge_field', global_namespace))//"'"
163 call messages_fatal(1)
164 end if
165 call io_skip_header(ref_file)
166 call spectrum_count_time_steps(global_namespace, ref_file, time_steps_ref, dt_ref)
167 if (time_steps_ref < time_steps) then
168 message(1) = "The reference calculation does not contain enought time steps"
169 call messages_fatal(1)
170 end if
171
172 if (.not. is_close(dt_ref, dt)) then
173 message(1) = "The time step of the reference calculation is different from the current calculation"
174 call messages_fatal(1)
175 end if
176
177 end if
178
179 ! Add one as zero is included in the time signal
180 time_steps = time_steps + 1
181
182 safe_allocate(vecpot(1:time_steps, 1:space%dim*3))
183
184 call io_skip_header(in_file)
185
186 do ii = 1, time_steps
187 read(in_file, *) jj, tt, (vecpot(ii, kk), kk = 1, space%dim*3)
188 end do
189
190 call io_close(in_file)
191
192 !We remove the reference
193 if (parse_is_defined(global_namespace, 'TransientAbsorptionReference')) then
194 time_steps_ref = time_steps_ref + 1
195 safe_allocate(vecpot_ref(1:time_steps_ref, 1:space%dim*3))
196 call io_skip_header(ref_file)
197 do ii = 1, time_steps_ref
198 read(ref_file, *) jj, tt, (vecpot_ref(ii, kk), kk = 1, space%dim*3)
199 end do
200 call io_close(ref_file)
201 do ii = 1, time_steps
202 do kk = 1, space%dim*3
203 vecpot(ii, kk) = vecpot(ii, kk) - vecpot_ref(ii, kk)
204 end do
205 end do
206 end if
207
208 write(message(1), '(a, i7, a)') "Info: Read ", time_steps, " steps from file '"// &
209 trim(io_workpath('td.general/gauge_field', global_namespace))//"'"
210 call messages_info(1)
211
212
213 ! Find out the iteration numbers corresponding to the time limits.
214 ! Max time correspond to time_steps-1, as we start from 0.
215 call spectrum_fix_time_limits(spectrum, time_steps-1, dt, istart, iend, ntiter)
216
217 ! We need to fix istart because the damping starts are (istart-1)*dt, which needs to be spectrum%start_time
218 istart = istart + 1
219
220 energy_steps = spectrum_nenergy_steps(spectrum)
221
222 norm_aext = norm2(aext(1:space%dim))
223
224 safe_allocate(eind_real(1:energy_steps, 1:space%dim))
225 safe_allocate(eind_imag(1:energy_steps, 1:space%dim))
226
227 ! We select dA/dt = E
228 call batch_init(vecpotb, 1, 1, space%dim, vecpot(:, space%dim+1:space%dim*2))
229 call batch_init(eind_realb, 1, 1, space%dim, eind_real)
230 call batch_init(eind_imagb, 1, 1, space%dim, eind_imag)
231
232 call spectrum_signal_damp(spectrum%damp, spectrum%damp_factor, istart, iend, spectrum%start_time, dt, vecpotb)
233
234 call spectrum_fourier_transform(spectrum%method, spectrum_transform_cos, spectrum%noise, &
235 istart, iend, spectrum%start_time, dt, vecpotb, spectrum%min_energy, &
236 spectrum%max_energy, spectrum%energy_step, eind_realb)
237
238 call spectrum_fourier_transform(spectrum%method, spectrum_transform_sin, spectrum%noise, &
239 istart, iend, spectrum%start_time, dt, vecpotb, spectrum%min_energy, &
240 spectrum%max_energy, spectrum%energy_step, eind_imagb)
241
242
243 call vecpotb%end()
244 call eind_realb%end()
245 call eind_imagb%end()
246
247 safe_allocate(invdielectric(1:energy_steps))
248 safe_allocate(dielectric(1:energy_steps))
249 safe_allocate(chi(1:energy_steps))
250
251 do kk = 1, energy_steps
252 ww = (kk-1)*spectrum%energy_step + spectrum%min_energy
253
254 ! We compute 1/\epsilon(\omega), see Eq. (4) in Bertsch et al. PRB 62, 7998
255 ! More precisely, we have \epsilon^{-1}_{\alpha\beta} = \frac{E_{tot,\alpha}}{E_{ext,\beta}}
256
257 ! Here we can only assume that the Gauge field is along an axis without off-diagonal terms
258 ! Else, we need several calulations
259 eind = cmplx(eind_real(kk, 1:space%dim), eind_imag(kk, 1:space%dim), real64)
260 invdielectric(kk) = dot_product(aext, aext + eind) /norm_aext**2
261
262 dielectric(kk) = m_one / invdielectric(kk)
263
264 chi(kk) = (dielectric(kk) - m_one)*latt%rcell_volume/(m_four*m_pi)
265 end do
266
267 out_file = io_open('td.general/inverse_dielectric_function', global_namespace, action='write')
268 write(header, '(7a15)') '# energy', 'Re', 'Im'
269
270 write(out_file,'(a)') trim(header)
271 do kk = 1, energy_steps
272 ww = (kk-1)*spectrum%energy_step + spectrum%min_energy
273 write(out_file, '(e15.6)', advance='no') ww
274 write(out_file, '(2e15.6)', advance='no') real(invdielectric(kk), real64), aimag(invdielectric(kk))
275 write(out_file, '()')
276 end do
277 call io_close(out_file)
278
279 out_file = io_open('td.general/dielectric_function', global_namespace, action='write')
280 write(out_file,'(a)') trim(header)
281 do kk = 1, energy_steps
282 ww = (kk-1)*spectrum%energy_step + spectrum%min_energy
283 write(out_file, '(e15.6)', advance='no') ww
284 write(out_file, '(2e15.6)', advance='no') real(dielectric(kk), real64), aimag(dielectric(kk))
285 write(out_file, '()')
286 end do
287 call io_close(out_file)
288
289 out_file = io_open('td.general/chi', global_namespace, action='write')
290 write(out_file,'(a)') trim(header)
291 do kk = 1, energy_steps
292 ww = (kk-1)*spectrum%energy_step + spectrum%min_energy
293 write(out_file, '(e15.6)', advance='no') ww
294 write(out_file, '(2e15.6)', advance='no') real(chi(kk), real64), aimag(chi(kk))
295 write(out_file, '()')
296 end do
297 call io_close(out_file)
298
299 safe_deallocate_a(dielectric)
300 safe_deallocate_a(invdielectric)
301 safe_deallocate_a(chi)
302 safe_deallocate_a(vecpot)
303 safe_deallocate_a(vecpot_ref)
304 safe_deallocate_a(aext)
305 safe_deallocate_a(eind)
306 safe_deallocate_a(eind_real)
307 safe_deallocate_a(eind_imag)
308
309 end subroutine dielectric_function_compute
310
311end program dielectric_function
312
313!! Local Variables:
314!! mode: f90
315!! coding: utf-8
316!! End:
subroutine dielectric_function_compute()
program dielectric_function
A utility used to obtain the dielectric function from a kick calculation using the gauge field approa...
initialize a batch with existing memory
Definition: batch.F90:267
This module implements batches of mesh functions.
Definition: batch.F90:133
subroutine, public getopt_init(ierr)
Initializes the getopt machinery. Must be called before attempting to parse the options....
subroutine, public getopt_end
subroutine, public global_end()
Finalise parser varinfo file, and MPI.
Definition: global.F90:381
real(real64), parameter, public m_four
Definition: global.F90:191
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:185
type(mpi_comm), parameter, public serial_dummy_comm
Alias MPI_COMM_UNDEFINED for the specific use case of initialising Octopus utilities with no MPI supp...
Definition: global.F90:264
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
Definition: global.F90:353
real(real64), parameter, public m_one
Definition: global.F90:188
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
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:115
subroutine, public messages_end()
Definition: messages.F90:277
subroutine, public messages_init(output_dir)
Definition: messages.F90:224
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:543
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
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 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
subroutine, public spectrum_signal_damp(damp_type, damp_factor, time_start, time_end, t0, time_step, time_function)
Definition: spectrum.F90:2552
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
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.
subroutine, public unit_system_init(namespace)