Octopus
propagation_spectrum.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
23 use debug_oct_m
24 use global_oct_m
25 use io_oct_m
26 use iso_c_binding
27 use kick_oct_m
30 use parser_oct_m
33 use string_oct_m
35
36 implicit none
37
38 private
40
41contains
42
43 subroutine propagation_spectrum_main() bind(c)
44 integer :: in_file(3), out_file(3), ref_file, eq_axes, nspin, &
45 lmax, time_steps, ierr
46 logical :: calculate_tensor, reference_multipoles
47 type(spectrum_t) :: spectrum
48 type(unit_system_t) :: file_units
49 character(len=80) :: refmultipoles
50
51 ! Initialize stuff
53
54 call getopt_init(ierr)
55 refmultipoles = ""
56 if (ierr == 0) call getopt_propagation_spectrum(refmultipoles)
57 call getopt_end()
58
59 call parser_init()
60
61 call messages_init()
62
63 call io_init()
65
67
68 call spectrum_init(spectrum, global_namespace)
69
70 select case (spectrum%spectype)
72 call read_files('multipoles', refmultipoles)
73 call calculate_absorption('cross_section', global_namespace)
74 case (spectrum_p_power)
75 call calculate_dipole_power("multipoles", 'dipole_power')
77 call calculate_ftchd('ftchd', 'dynamic_structure_factor')
79 call calculate_rotatory_strength("angular", "rotatory_strength")
80 case default
81 write(message(1), '(a)') 'No PropagationSpectrumType defined,'
82 write(message(2), '(a)') 'cannot calculate the spectrum.'
83 call messages_warning(2)
84 end select
85
87 call io_end()
88 call messages_end()
89
90 call parser_end()
91
92 call global_end()
94 contains
95
96 subroutine getopt_propagation_spectrum(str)
97 character(len=*), intent(inout) :: str
98
99 character(kind=c_char) :: cstr(len(str)+1)
100
101 interface getopt_propagation_spectrum_low
102 subroutine getopt_propagation_spectrum_low(str) bind(c, name='getopt_propagation_spectrum')
103 use iso_c_binding
104 character(kind=c_char) :: str(*)
105 end subroutine getopt_propagation_spectrum_low
106 end interface getopt_propagation_spectrum_low
107
108 cstr = c_null_char
109 call getopt_propagation_spectrum_low(cstr)
110 call string_c_to_f(cstr, str)
111 end subroutine getopt_propagation_spectrum
112
145 subroutine read_files(fname, reffname)
146 character(len=*), intent(in) :: fname
147 character(len=*), intent(in) :: reffname
148
149 type(kick_t) :: kick
150 real(real64) :: dt
151
152 push_sub(read_files)
153
154 in_file(1) = io_open(trim(fname), global_namespace, action='read', status='old', die=.false.)
155 if (in_file(1) == -1) in_file(1) = io_open('td.general/'//trim(fname), global_namespace, &
156 action='read', status='old', die=.false.)
157 if (in_file(1) /= -1) then
158 write(message(1),'(3a)') 'File "', trim(fname), '" found. This will be the only file to be processed.'
159 write(message(2),'(a)') '(If more than one file is to be used, the files should be called'
160 write(message(3),'(5a)') '"', trim(fname), '.1", "', trim(fname), '.2", etc.)'
161 write(message(4),'(a)')
162 call messages_info(4)
163
164 ! OK, so we only have one file. Now we have to see what it has inside.
165 call spectrum_mult_info(global_namespace, in_file(1), nspin, kick, time_steps, dt, file_units, lmax=lmax)
166 eq_axes = kick%pol_equiv_axes
167 if (eq_axes == 3) then
168 calculate_tensor = .true.
169 write(message(1),'(3a)') 'The file "', trim(fname), '" tells me that the system has three equivalent axes.'
170 write(message(2),'(a)') 'I will calculate the full tensor, written in file "XXXX_tensor".'
171 call messages_info(2)
172 else if (eq_axes == 2) then
173 write(message(1),'(3a)') 'The file "', trim(fname), '" tells me that the system has two equivalent axes.'
174 write(message(2),'(a)') 'However, I am only using this file; cannot calculate the full tensor.'
175 write(message(3),'(a)') 'A file "XXXX_vector" will be generated instead.'
176 call messages_warning(3)
177 calculate_tensor = .false.
178 else
179 write(message(1),'(3a)') 'The file "', trim(fname), '" tells me that the system has no usable symmetry. '
180 write(message(2),'(a)') 'However, I am only using this file; cannot calculate the full tensor.'
181 write(message(3),'(a)') 'A file "XXXX_vector" will be generated instead.'
182 call messages_warning(3)
183 calculate_tensor = .false.
184 end if
185
186 else ! We will try to load more fname.1 files...
187
188 ! In this case, we will always want the full tensor
189 calculate_tensor = .true.
190
191 in_file(1) = io_open(trim(fname)//'.1', global_namespace, action='read', &
192 status='old', die=.false.)
193 if (in_file(1) == -1) in_file(1) = io_open('td.general/'//trim(fname)//'.1', global_namespace, &
194 action='read', status='old', die=.false.)
195 if (in_file(1) == -1) then ! Could not find proper files. Die and complain.
196 write(message(1),'(5a)') 'No "', trim(fname), '" or "', trim(fname), '.1" file found. At least one of those'
197 write(message(2),'(a)') 'should be visible.'
198 call messages_fatal(2)
199 end if
200
201 call spectrum_mult_info(global_namespace, in_file(1), nspin, kick, time_steps, dt, file_units, lmax=lmax)
202 eq_axes = kick%pol_equiv_axes
203
204 if (eq_axes == 3) then
205 write(message(1),'(3a)') 'The file "', trim(fname), '.1" tells me that the system has three equivalent axes.'
206 write(message(2),'(a)') 'I will calculate the full tensor, written in file "cross_section_tensor".'
207 call messages_info(2)
208
209 else if (eq_axes == 2) then
210 in_file(2) = io_open(trim(fname)//'.2', global_namespace, action='read', status='old', die=.false.)
211 if (in_file(2) == -1) in_file(2) = io_open('td.general/'//trim(fname)//'.2', global_namespace, &
212 action='read', status='old', die=.false.)
213 if (in_file(2) == -1) then
214 write(message(1),'(3a)') 'The file "', trim(fname), '.1" tells me that the system has two equivalent axes,'
215 write(message(2),'(3a)') 'but I cannot find a "', trim(fname), '.2".'
216 call messages_fatal(2)
217 end if
218 write(message(1),'(5a)') 'Found two files, "', trim(fname), '.1" and "', trim(fname), '.2".'
219 write(message(2),'(a)') 'Two polarization axes are equivalent. I will generate the full tensor.'
220 call messages_info(2)
221
222 else ! No equivalent axes
223 in_file(2) = io_open(trim(fname)//'.2', global_namespace, action='read', &
224 status='old', die=.false.)
225 if (in_file(2) == -1) in_file(2) = io_open('td.general/'//trim(fname)//'.2', global_namespace, &
226 action='read', status='old', die=.false.)
227 if (in_file(2) == -1) then
228 write(message(1),'(3a)') 'The file "', trim(fname), '.1" tells me that the system has three inequivalent axes,'
229 write(message(2),'(3a)') 'but I cannot find a "', trim(fname), '.2".'
230 call messages_fatal(2)
231 end if
232 in_file(3) = io_open(trim(fname)//'.3', global_namespace, action='read', &
233 status='old', die=.false.)
234 if (in_file(3) == -1) in_file(3) = io_open('td.general/'//trim(fname)//'.3', global_namespace, &
235 action='read', status='old', die=.false.)
236 if (in_file(3) == -1) then
237 write(message(1),'(3a)') 'The file "', trim(fname), '.1" tells me that the system has three inequivalent axes,'
238 write(message(2),'(3a)') 'but I cannot find a "', trim(fname), '.3".'
239 call messages_fatal(2)
240 end if
241 write(message(1),'(7a)') 'Found three files, "', trim(fname), '.1", "', trim(fname), '.2" and "', trim(fname), '.3".'
242 write(message(2),'(a)') 'No symmetry information will be used.'
243 call messages_info(2)
244 end if
245
246 end if
247
248 if (reffname == "") then
249 reference_multipoles = .false.
250 else
251 reference_multipoles = .true.
252 ref_file = io_open(trim(reffname), global_namespace, action='read', status='old')
253 end if
254
255 pop_sub(read_files)
256 end subroutine read_files
257
258
259 !----------------------------------------------------------------------------
260 subroutine calculate_absorption(fname, namespace)
261 character(len=*), intent(in) :: fname
262 type(namespace_t), intent(in) :: namespace
263
264 integer :: ii, jj
265 character(len=150), allocatable :: filename(:)
266
267 push_sub(calculate_absorption)
268
269 if (.not. calculate_tensor) then
270
271 out_file(1) = io_open(trim(fname)//'_vector', global_namespace, action='write')
272 if (.not. reference_multipoles) then
273 call spectrum_cross_section(spectrum, namespace, in_file(1), out_file(1))
274 else
275 call spectrum_cross_section(spectrum, namespace, in_file(1), out_file(1), ref_file)
276 end if
277 call io_close(in_file(1))
278 call io_close(out_file(1))
279
280 else
281 select case (eq_axes)
282 case (0, 1)
283 jj = 3
284 case (2)
285 jj = 2
286 case (3)
287 jj = 1
288 end select
289
290 safe_allocate(filename(1:jj))
291 do ii = 1, jj
292 write(filename(ii),'(2a,i1)') trim(fname), '_vector.',ii
293 out_file(ii) = io_open(trim(filename(ii)), global_namespace, action='write')
294 if (.not. reference_multipoles) then
295 call spectrum_cross_section(spectrum, namespace, in_file(ii), out_file(ii))
296 else
297 call spectrum_cross_section(spectrum, namespace, in_file(ii), out_file(ii), ref_file)
298 end if
299 call io_close(in_file(ii))
300 call io_close(out_file(ii))
301 in_file(ii) = io_open(trim(filename(ii)), global_namespace, action='read', status='old')
302 end do
303
304 out_file(1) = io_open(trim(fname)//'_tensor', global_namespace, action='write')
305 call spectrum_cross_section_tensor(spectrum, namespace, out_file(1), in_file(1:jj))
306 do ii = 1, jj
307 call io_close(in_file(ii))
308 end do
309 call io_close(out_file(1))
310
311 end if
312
313 pop_sub(calculate_absorption)
314 end subroutine calculate_absorption
315
316 !----------------------------------------------------------------------------
317 subroutine calculate_dipole_power(fname_in, fname_out)
318 character(len=*), intent(in) :: fname_in, fname_out
319
320 push_sub(calculate_dipole_power)
321
322 in_file(1) = io_open(trim(fname_in), global_namespace, action='read', status='old', die=.false.)
323 if (in_file(1) < 0) in_file(1) = io_open('td.general/'//trim(fname_in), global_namespace, &
324 action='read', status='old', die=.false.)
325 if (in_file(1) >= 0) then
326 write(message(1),'(3a)') 'File "', trim(fname_in), '" found.'
327 write(message(2),'(a)')
328 call messages_info(2)
329 end if
330
331 out_file(1) = io_open(trim(fname_out), global_namespace, action='write')
332 call spectrum_dipole_power(spectrum, global_namespace, in_file(1), out_file(1))
333
334 call io_close(in_file(1))
335 call io_close(out_file(1))
336
338 end subroutine calculate_dipole_power
339
340 !----------------------------------------------------------------------------
341 subroutine calculate_rotatory_strength(fname_in, fname_out)
342 character(len=*), intent(in) :: fname_in, fname_out
343
345
346 in_file(1) = io_open(trim(fname_in), global_namespace, action='read', status='old', die=.false.)
347 if (in_file(1) < 0) in_file(1) = io_open('td.general/'//trim(fname_in), global_namespace, &
348 action='read', status='old', die=.false.)
349 if (in_file(1) >= 0) then
350 write(message(1),'(3a)') 'File "', trim(fname_in), '" found.'
351 write(message(2),'(a)')
352 call messages_info(2)
353 end if
354
355 out_file(1) = io_open(trim(fname_out), global_namespace, action='write')
356 call spectrum_rotatory_strength(spectrum, global_namespace, in_file(1), out_file(1))
357
358 call io_close(in_file(1))
359 call io_close(out_file(1))
360
362 end subroutine calculate_rotatory_strength
363
364
365 !----------------------------------------------------------------------------
366 subroutine calculate_ftchd(fname_in, fname_out)
367 character(len=*), intent(in) :: fname_in, fname_out
368
369 push_sub(calculate_ftchd)
370
371 ! read files
372 in_file(1) = io_open(trim(fname_in) // '.sin', global_namespace, action='read', status='old', die=.false.)
373 in_file(2) = io_open(trim(fname_in) // '.cos', global_namespace, action='read', status='old', die=.false.)
374
375 out_file(1) = io_open(trim(fname_out), global_namespace, action='write')
376 call spectrum_dyn_structure_factor(spectrum, global_namespace, in_file(1), in_file(2), out_file(1))
377 call io_close(in_file(1))
378 call io_close(out_file(1))
379
380 pop_sub(calculate_ftchd)
381 end subroutine calculate_ftchd
382 end subroutine propagation_spectrum_main
384
385!! Local Variables:
386!! mode: f90
387!! coding: utf-8
388!! End:
void getopt_propagation_spectrum(char *fname)
Definition: getopt_f.c:8611
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
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
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_end()
Definition: io.F90:248
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_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:501
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 propagation_spectrum_main()
subroutine, public spectrum_cross_section(spectrum, namespace, in_file, out_file, ref_file)
Definition: spectrum.F90:694
subroutine, public spectrum_cross_section_tensor(spectrum, namespace, out_file, in_file)
Definition: spectrum.F90:414
subroutine, public spectrum_dyn_structure_factor(spectrum, namespace, in_file_sin, in_file_cos, out_file)
Definition: spectrum.F90:1248
subroutine, public spectrum_init(spectrum, namespace, default_energy_step, default_max_energy)
Definition: spectrum.F90:197
subroutine, public spectrum_mult_info(namespace, iunit, nspin, kick, time_steps, dt, file_units, lmax)
Definition: spectrum.F90:2334
subroutine, public spectrum_dipole_power(spectrum, namespace, in_file, out_file)
Definition: spectrum.F90:1140
integer, parameter, public spectrum_energyloss
Definition: spectrum.F90:155
integer, parameter, public spectrum_rotatory
Definition: spectrum.F90:155
subroutine, public spectrum_rotatory_strength(spectrum, namespace, in_file, out_file)
Definition: spectrum.F90:1403
integer, parameter, public spectrum_absorption
Definition: spectrum.F90:155
integer, parameter, public spectrum_p_power
Definition: spectrum.F90:155
subroutine, public string_c_to_f(c_string, f_string)
convert a C string to a Fortran string
Definition: string.F90:253
This module defines the unit system, used for input and output.
subroutine, public unit_system_init(namespace)
subroutine calculate_ftchd(fname_in, fname_out)
subroutine read_files(fname, reffname)
subroutine calculate_absorption(fname, namespace)
subroutine calculate_dipole_power(fname_in, fname_out)
subroutine calculate_rotatory_strength(fname_in, fname_out)
int true(void)