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