Octopus
vibrational.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 ions_oct_m
28 use, intrinsic :: iso_fortran_env
30 use mpi_oct_m
32 use parser_oct_m
35 use unit_oct_m
37
38 implicit none
39
40 private
41 public :: vibrational_main
42
43contains
44
45 subroutine vibrational_main() bind(c)
46 integer :: iunit, ierr, ii, jj, iter, read_iter, ntime, nvaf, nvel, ivel
47 real(real64), allocatable :: vaf(:), time(:), velocities(:, :), ftvaf(:)
48 type(ions_t), pointer :: ions
49 type(spectrum_t) :: spectrum
50 type(batch_t) :: vafb, ftvafb
51 real(real64) :: ww, curtime, vaftime, deltat
52 integer :: ifreq, max_freq
53 integer :: skip
54
55 ! Initialize stuff
57
58 call getopt_init(ierr)
59 call getopt_end()
60
61 call parser_init()
62
63 call messages_init()
64
65 call io_init()
67
69
70 call spectrum_init(spectrum, global_namespace, &
71 default_energy_step = units_to_atomic(unit_invcm, 0.2_real64), &
72 default_max_energy = units_to_atomic(unit_invcm, 5000.0_real64))
73
74 !%Variable VibrationalSpectrumTimeStepFactor
75 !%Type integer
76 !%Default 10
77 !%Section Utilities::oct-vibrational_spectrum
78 !%Description
79 !% In the calculation of the vibrational spectrum, it is not necessary
80 !% to read the velocity at every time step. This variable controls
81 !% the integer factor between the simulation time step and the
82 !% time step used to calculate the vibrational spectrum.
83 !%End
84
85 call messages_obsolete_variable(global_namespace, 'PropagationSpectrumTimeStepFactor', 'VibrationalSpectrumTimeStepFactor')
86 call parse_variable(global_namespace, 'VibrationalSpectrumTimeStepFactor', 10, skip)
87 if (skip <= 0) call messages_input_error(global_namespace, 'VibrationalSpectrumTimeStepFactor')
88
89 max_freq = spectrum_nenergy_steps(spectrum)
90
91 if (spectrum%end_time < m_zero) spectrum%end_time = huge(spectrum%end_time)
92
94
95 ! Opens the coordinates files.
96 iunit = io_open('td.general/coordinates', global_namespace, action='read')
97
98 call io_skip_header(iunit)
99
100 ntime = 1
101 iter = 1
102
103 ! check the number of time steps we will read
104 do
105 read(unit = iunit, iostat = ierr, fmt = *) read_iter, curtime, &
106 ((ions%pos(jj, ii), jj = 1, 3), ii = 1, ions%natoms), &
107 ((ions%vel(jj, ii), jj = 1, 3), ii = 1, ions%natoms)
108
109 curtime = units_to_atomic(units_out%time, curtime)
110
111 if (ierr /= 0 .or. curtime >= spectrum%end_time) then
112 iter = iter - 1 ! last iteration is not valid
113 ntime = ntime - 1
114 exit
115 end if
116
117 if (iter /= read_iter + 1) then
118 call messages_write("Error while reading file 'td.general/coordinates',", new_line = .true.)
119 call messages_write('expected iteration ')
120 call messages_write(iter - 1)
121 call messages_write(', got iteration ')
122 call messages_write(read_iter)
123 call messages_write('.')
124 call messages_fatal()
125 end if
126
127 ! ntime counts how many steps are gonna be used
128 if (curtime >= spectrum%start_time .and. mod(iter, skip) == 0) ntime = ntime + 1
129
130 iter = iter + 1 !counts number of timesteps (with time larger than zero up to SpecEndTime)
131 end do
132
133 call io_close(iunit)
134
135 nvel = ions%natoms*ions%space%dim
136
137 safe_allocate(time(1:ntime))
138 safe_allocate(velocities(1:nvel, 1:ntime))
139
140 ! Opens the coordinates files.
141 iunit = io_open('td.general/coordinates', global_namespace, action='read')
142
143 call io_skip_header(iunit)
144
145 ntime = 1
146 iter = 1
147
148 do
149 read(unit = iunit, iostat = ierr, fmt = *) read_iter, curtime, &
150 ((ions%pos(jj, ii), jj = 1, 3), ii = 1, ions%natoms), &
151 ((ions%vel(jj, ii), jj = 1, 3), ii = 1, ions%natoms)
152
153 curtime = units_to_atomic(units_out%time, curtime)
154
155 if (ierr /= 0 .or. curtime >= spectrum%end_time) then
156 iter = iter - 1 ! last iteration is not valid
157 ntime = ntime - 1
158 exit
159 end if
160
161 assert(iter == read_iter + 1)
162
163 if (curtime >= spectrum%start_time .and. mod(iter, skip) == 0) then
164
165 time(ntime) = curtime
166 ivel = 1
167 do ii = 1, ions%natoms
168 do jj = 1, ions%space%dim
169 velocities(ivel, ntime) = units_to_atomic(units_out%velocity, ions%vel(jj, ii))
170 ivel = ivel + 1
171 end do
172 end do
173
174 ntime = ntime + 1
175 end if
176
177 iter = iter + 1 !counts number of timesteps (with time larger than zero up to SpecEndTime)
178 end do
179
180 call io_close(iunit)
181
182 deltat = time(2) - time(1)
183
184 !%Variable VibrationalSpectrumTime
185 !%Type integer
186 !%Section Utilities::oct-vibrational_spectrum
187 !%Description
188 !% This variable controls the maximum time for the calculation of
189 !% the velocity autocorrelation function. The default is the total
190 !% propagation time.
191 !%End
192 call parse_variable(global_namespace, 'VibrationalSpectrumTime', ntime*deltat, vaftime)
193
194 nvaf = int(vaftime/deltat)
195
196 safe_allocate(vaf(1:ntime))
197
198 call messages_write('Time step = ')
199 call messages_write(deltat, units = units_out%time)
200 call messages_info()
201
202 call messages_new_line()
203 call messages_write('Calculating the velocity autocorrelation function')
204 call messages_info()
205
206 call calculate_vaf(vaf)
207
208 !print the vaf
209 iunit = io_open('td.general/velocity_autocorrelation', global_namespace, action='write')
210
211800 FORMAT(80('#'))
212 write(unit = iunit, iostat = ierr, fmt = 800)
213 write(unit = iunit, iostat = ierr, fmt = '(8a)') '# HEADER'
214 write(unit = iunit, iostat = ierr, fmt = '(a,4x,a6,a7,a1,10x,a10)') &
215 '# Iter', 'time [',units_out%time%abbrev,']', 'VAF [a.u.]'
216 write(unit = iunit, iostat = ierr, fmt = 800)
217
218 do jj = 1, nvaf
219 write(unit = iunit, iostat = ierr, fmt = *) jj, units_from_atomic(units_out%time, (jj - 1)*deltat), vaf(jj)
220 end do
221
222 call io_close(iunit)
223
224
225 safe_allocate(ftvaf(1:max_freq))
226
227 ftvaf = m_one
228
229 call batch_init(vafb, vaf)
230
231 call spectrum_signal_damp(spectrum%damp, spectrum%damp_factor, 1, nvaf, m_zero, deltat, vafb)
232
233 call batch_init(ftvafb, ftvaf)
234
235 call spectrum_fourier_transform(spectrum%method, spectrum_transform_cos, spectrum%noise, &
236 1, nvaf, m_zero, deltat, vafb, spectrum%min_energy, spectrum%max_energy, spectrum%energy_step, ftvafb)
237
238 call vafb%end()
239 call ftvafb%end()
240
241
242 !and print the spectrum
243 iunit = io_open('td.general/vibrational_spectrum', global_namespace, action='write')
244
245 write(unit = iunit, iostat = ierr, fmt = 800)
246 write(unit = iunit, iostat = ierr, fmt = '(8a)') '# HEADER'
247 write(unit = iunit, iostat = ierr, fmt = '(a17,6x,a15)') '# Energy [1/cm]', 'Spectrum [a.u.]'
248 write(unit = iunit, iostat = ierr, fmt = 800)
249
250 do ifreq = 1, max_freq
251 ww = spectrum%energy_step*(ifreq - 1) + spectrum%min_energy
252 write(unit = iunit, iostat = ierr, fmt = '(2e20.10)') units_from_atomic(unit_invcm, ww), ftvaf(ifreq)
253 end do
254
255 call io_close(iunit)
256
257 safe_deallocate_a(vaf)
258
259 safe_deallocate_a(ftvaf)
260
261 safe_deallocate_p(ions)
262
263 safe_deallocate_a(time)
264
265 safe_deallocate_a(velocities)
266
268 call io_end()
269 call messages_end()
270
271 call parser_end()
272 call global_end()
273
274 contains
275
276 subroutine calculate_vaf(vaf)
277 real(real64), contiguous, intent(out) :: vaf(:)
278 integer :: itm, itn
279
280 push_sub(calculate_vaf)
281
282 write (message(1), '(a)') "Read velocities from '"// &
283 trim(io_workpath('td.general/coordinates', global_namespace))//"'"
284 call messages_info(1)
285
286 !calculating the vaf, formula from
287 !
288 ! http://www.timteatro.net/2010/09/29/velocity-autocorrelation-and-vibrational-spectrum-calculation/
289
290 vaf = m_zero
291
292 do itm = 1, ntime
293 vaf(itm) = m_zero
294
295 do itn = 1, ntime - itm + 1
296
297 do ivel = 1, nvel
298 vaf(itm) = vaf(itm) + velocities(ivel, itm + itn - 1)*velocities(ivel, itn)
299 end do
300 end do
301
302 vaf(itm) = vaf(itm)/real(ntime - itm + 1, real64)
303
304 end do
305
306 do itm = 2, ntime
307 vaf(itm) = vaf(itm)/vaf(1)
308 end do
309 vaf(1) = m_one
310
311 pop_sub(calculate_vaf)
312 end subroutine calculate_vaf
313 end subroutine vibrational_main
314end module vibrational_main_oct_m
315
316!! Local Variables:
317!! mode: f90
318!! coding: utf-8
319!! End:
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
real(real64), parameter, public m_one
Definition: global.F90:174
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
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:980
subroutine, public messages_new_line()
Definition: messages.F90:1069
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_input_error(namespace, var, details, row, column)
Definition: messages.F90:671
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:317
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_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:197
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
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)
subroutine, public vibrational_main()
int true(void)
subroutine calculate_vaf(vaf)