Octopus
infrared.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
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
22 use batch_oct_m
24 use debug_oct_m
25 use global_oct_m
26 use io_oct_m
27 use, intrinsic :: iso_fortran_env
30 use parser_oct_m
32 use space_oct_m
34 use unit_oct_m
36
37 implicit none
38
39 private
40 public :: infrared_main
41
42contains
43
44 subroutine infrared_main() bind(c)
45 integer :: iunit, ierr, ii, jj, iter, read_iter
46 real(real64), allocatable :: dipole(:,:)
47 complex(real64), allocatable :: ftdipole(:,:)
48 type(space_t) :: space
49 real(real64) :: ww, irtotal, dt
50 integer :: ifreq, idir, istart, iend, time_steps, energy_steps, ntiter
51 type(spectrum_t) :: spectrum
52
53 ! Initialize stuff
55
56 call getopt_init(ierr)
57
58 call getopt_end()
59
60 call parser_init()
61
62 call messages_init()
63
64 call io_init()
66
68
69 call spectrum_init(spectrum, global_namespace, &
70 default_max_energy = units_to_atomic(unit_invcm, 10000.0_real64))
71
73
74 call read_dipole(dipole)
75
76 safe_allocate(ftdipole(1:energy_steps, 1:space%dim))
77 call fourier(dipole, ftdipole)
78
79 !and print the spectrum
80 iunit = io_open('td.general/infrared', global_namespace, action='write')
81
82100 FORMAT(100('#'))
83
84 write(unit = iunit, iostat = ierr, fmt = 100)
85 write(unit = iunit, iostat = ierr, fmt = '(8a)') '# HEADER'
86 write(unit = iunit, iostat = ierr, fmt = '(a25,a1,a1,a10)') &
87 '# all absorptions are in ',units_out%length%abbrev,'*',units_out%time%abbrev
88 write(unit = iunit, iostat = ierr, fmt = '(a1)') '#'
89 write(unit = iunit, iostat = ierr, fmt = '(a19,41x,a17)') '# Energy ', 'absorption'
90 write(unit = iunit, iostat = ierr, fmt = '(a15,13x,a5,15x,a7,13x,a7,13x,a7)') &
91 '# [1/cm]','total','FT(<x>)','FT(<y>)','FT(<z>)'
92 write(unit = iunit, iostat = ierr, fmt = 0100)
94 do ifreq = 1, energy_steps
95 ww = (ifreq-1)*spectrum%energy_step + spectrum%min_energy
96 irtotal = norm2(abs(ftdipole(ifreq, 1:3)))
97 write(unit = iunit, iostat = ierr, fmt = '(5e20.10)') &
98 units_from_atomic(unit_invcm, ww), units_from_atomic(units_out%length*units_out%time, ww*irtotal), &
99 (units_from_atomic(units_out%length*units_out%time, ww*abs(ftdipole(ifreq, idir))), idir = 1, 3)
100 end do
101 call io_close(iunit)
102
103 safe_deallocate_a(dipole)
104 safe_deallocate_a(ftdipole)
105
107 call io_end()
108 call messages_end()
109
110 call parser_end()
111 call global_end()
112
113 contains
114
115 subroutine read_dipole(dipole)
116 real(real64), allocatable, intent(inout) :: dipole(:, :)
117 character(len=100) :: ioerrmsg
118 real(real64) :: charge, time
119
120 push_sub(read_dipole)
121
122 ! Opens the coordinates files.
123 iunit = io_open('td.general/multipoles', global_namespace, action='read', status='old')
124 call io_skip_header(iunit)
125 call spectrum_count_time_steps(global_namespace, iunit, time_steps, dt)
126 time_steps = time_steps + 1
127
128 ! Find out the iteration numbers corresponding to the time limits.
129 call spectrum_fix_time_limits(spectrum, time_steps, dt, istart, iend, ntiter)
130 istart = max(1, istart)
131 energy_steps = spectrum_nenergy_steps(spectrum)
132
133 safe_allocate(dipole(1:time_steps, 1:space%dim))
134
135 call io_skip_header(iunit)
136
137 do iter = 1, time_steps
138 read(unit = iunit, iostat = ierr, iomsg=ioerrmsg, fmt = *) read_iter, time, &
139 charge, (dipole(iter, idir), idir=1, space%dim)
140
141 !dipole moment has unit of charge*length, charge has the same unit in both systems
142 do ii = 1, space%dim
143 dipole(iter, ii) = units_to_atomic(units_out%length, dipole(iter, ii))
144 end do
145
146 if (ierr /= 0) then
147 exit
148 end if
149 end do
150
151 if (ierr == 0) then
152 write (message(1), '(a)') "Read dipole moment from '"// &
153 trim(io_workpath('td.general/multipoles', global_namespace))//"'."
154 call messages_info(1)
155 else
156 message(1) = "Error reading file '"//trim(io_workpath('td.general/multipoles', global_namespace))//"'"
157 message(2) = ioerrmsg
158 call messages_fatal(2)
159 end if
160
161 call io_close(iunit)
162
163 pop_sub(read_dipole)
164 end subroutine read_dipole
165
166 ! -------------------------------------------------
167 subroutine fourier(fi, ftfi)
168 implicit none
169 real(real64), contiguous, intent(inout) :: fi(:,:)
170 complex(real64), intent(out) :: ftfi(:,:)
171
172 real(real64) :: av
173 integer :: ifreq
174 type(batch_t) :: dipoleb, ftrealb, ftimagb
175 real(real64), allocatable :: ftreal(:,:), ftimag(:,:)
176
177 push_sub(fourier)
178
179 call batch_init(dipoleb, 1, 1, space%dim, fi)
180
181 !apply an envelope
182 call spectrum_signal_damp(spectrum_damp_sin, spectrum%damp_factor, istart, iend, spectrum%start_time, dt, dipoleb)
183
184 !remove the DC component
185 do idir = 1, space%dim
186 av = sum(fi(istart:iend, idir)) / (iend - istart + 1)
187 !$omp parallel do
188 do jj = istart, iend
189 fi(jj, idir) = fi(jj, idir) - av
190 end do
191 end do
192
193 write (message(1), '(a)') "Taking the Fourier transform."
194 call messages_info(1)
195
196 safe_allocate(ftreal(1:energy_steps, 1:space%dim))
197 safe_allocate(ftimag(1:energy_steps, 1:space%dim))
198 call batch_init(ftrealb, 1, 1, space%dim, ftreal)
199 call batch_init(ftimagb, 1, 1, space%dim, ftimag)
200
201 !now calculate the FT
203 istart, iend, spectrum%start_time, dt, dipoleb, spectrum%min_energy, spectrum%max_energy, spectrum%energy_step, ftrealb)
204
206 istart, iend, spectrum%start_time, dt, dipoleb, spectrum%min_energy, spectrum%max_energy, spectrum%energy_step, ftimagb)
207
208 do idir = 1, space%dim
209 !$omp parallel do
210 do ifreq = 1, energy_steps
211 ftfi(ifreq, idir) = cmplx(ftreal(ifreq, idir), ftimag(ifreq, idir), real64)
212 end do
213 end do
214
215 call dipoleb%end()
216 call ftrealb%end()
217 call ftimagb%end()
218 safe_deallocate_a(ftreal)
219 safe_deallocate_a(ftimag)
220
221 write (message(1), '(a)') "Done."
222 call messages_info(1)
223
224 pop_sub(fourier)
225 end subroutine fourier
226 end subroutine infrared_main
227end module infrared_main_oct_m
228
229!! Local Variables:
230!! mode: f90
231!! coding: utf-8
232!! End:
subroutine read_dipole(dipole)
Definition: infrared.F90:188
subroutine fourier(fi, ftfi)
Definition: infrared.F90:240
initialize a batch with existing memory
Definition: batch.F90:278
This module implements batches of mesh functions.
Definition: batch.F90:112
This module provides an interface to the getopt C library, so that the command line arguments can be ...
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:500
real(real64), parameter, public m_zero
Definition: global.F90:173
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:268
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
Definition: global.F90:438
subroutine, public infrared_main()
Definition: infrared.F90:117
Definition: io.F90:93
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:142
subroutine, public io_close(iunit, grp)
Definition: io.F90:444
subroutine, public io_skip_header(iunit)
Definition: io.F90:623
subroutine, public io_end()
Definition: io.F90:248
character(len=max_path_len) function, public io_workpath(path, namespace)
construct path name from given name and namespace
Definition: io.F90:295
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:379
subroutine, public messages_end()
Definition: messages.F90:249
subroutine, public messages_init(output_dir)
Definition: messages.F90:196
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
type(namespace_t), public global_namespace
Definition: namespace.F90:112
subroutine, public parser_init()
Initialise the Octopus parser.
Definition: parser.F90:387
subroutine, public parser_end()
End the Octopus parser.
Definition: parser.F90:419
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public profiling_end(namespace)
Definition: profiling.F90:455
subroutine, public profiling_init(namespace)
Create profiling subdirectory.
Definition: profiling.F90:264
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
integer, parameter, public spectrum_damp_sin
Definition: spectrum.F90:143
subroutine, public spectrum_init(spectrum, namespace, default_energy_step, default_max_energy)
Definition: spectrum.F90:197
integer, parameter, public spectrum_fourier
Definition: spectrum.F90:161
subroutine, public spectrum_signal_damp(damp_type, damp_factor, time_start, time_end, t0, time_step, time_function)
Definition: spectrum.F90:2559
integer, parameter, public spectrum_transform_cos
Definition: spectrum.F90:150
integer, parameter, public spectrum_transform_sin
Definition: spectrum.F90:150
subroutine, public spectrum_count_time_steps(namespace, iunit, time_steps, dt)
Definition: spectrum.F90:2380
pure integer function, public spectrum_nenergy_steps(spectrum)
Definition: spectrum.F90:2956
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:111
This module defines the unit system, used for input and output.
type(unit_t), public unit_invcm
For vibrational frequencies.
type(unit_system_t), public units_out
subroutine, public unit_system_init(namespace)
Class defining batches of mesh functions.
Definition: batch.F90:142