Octopus
spin_susceptibility.F90
Go to the documentation of this file.
1!! Copyright (C) 2018 N. Tancogne-Dejean
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 global_oct_m
25 use io_oct_m
26 use ions_oct_m
27 use kick_oct_m
29 use math_oct_m
32 use parser_oct_m
35 use unit_oct_m
37
38 implicit none
39
40 private
42
43contains
44
45 subroutine spin_susceptibility_main() bind(c)
46 integer :: in_file, out_file, ref_file, ii, jj, kk, ierr, ib, num_col, num_col_cart
47 integer :: time_steps, time_steps_ref, energy_steps, istart, iend, ntiter, iq
48 real(real64) :: dt, tt, ww, dt_ref
49 real(real64), allocatable :: ftreal(:,:), ftimag(:,:)
50 real(real64), allocatable :: m_cart(:,:), m_cart_ref(:,:), magnetization(:,:,:)
51 type(spectrum_t) :: spectrum
52 type(batch_t) :: vecpotb, ftrealb, ftimagb
53 type(kick_t) :: kick
54 character(len=256) :: header
55 character(len=MAX_PATH_LEN) :: fname, ref_filename
56 complex(real64), allocatable :: chi(:,:)
57
58 ! Initialize stuff
60
61 call getopt_init(ierr)
62 if (ierr == 0) call getopt_dielectric_function()
63 call getopt_end()
64
65 call parser_init()
66
67 call messages_init()
68
69 call io_init()
71
73
74 call spectrum_init(spectrum, global_namespace)
75
76 in_file = io_open('td.general/total_magnetization', global_namespace, action='read', status='old')
77 rewind(in_file)
78 read(in_file,*)
79 read(in_file,*)
80 call kick_read(kick, in_file, global_namespace)
81 call io_skip_header(in_file)
82 call spectrum_count_time_steps(global_namespace, in_file, time_steps, dt)
83
84 time_steps = time_steps + 1
85
86 num_col_cart = 12*kick%nqvec
87 safe_allocate(m_cart(1:time_steps, 1:num_col_cart))
88
89 call io_skip_header(in_file)
90
91 do ii = 1, time_steps
92 read(in_file, *) jj, tt, (m_cart(ii,ib),ib = 1, num_col_cart)
93 end do
94
95 call io_close(in_file)
96
97 if (parse_is_defined(global_namespace, 'TransientMagnetizationReference')) then
98 !%Variable TransientMagnetizationReference
99 !%Type string
100 !%Default "."
101 !%Section Utilities::oct-spin_susceptibility
102 !%Description
103 !% In case of delayed kick, the calculation of the transient spin susceptibility requires
104 !% to substract a reference calculation, containing dynamics of the magnetization without the kick
105 !% This reference must be computed having
106 !% TDOutput = total_magnetization.
107 !% This variables defined the directory in which the reference total_magnetization file is,
108 !% relative to the current folder
109 !%End
110
111 call parse_variable(global_namespace, 'TransientMagnetizationReference', '.', ref_filename)
112 ref_file = io_open(trim(ref_filename)//'/total_magnetization', global_namespace, action='read', status='old')
113 call io_skip_header(ref_file)
114 call spectrum_count_time_steps(global_namespace, ref_file, time_steps_ref, dt_ref)
115 time_steps_ref = time_steps_ref + 1
116
117 if (time_steps_ref < time_steps) then
118 message(1) = "The reference calculation does not contain enought time steps"
119 call messages_fatal(1)
120 end if
121
122 if (.not. is_close(dt_ref, dt)) then
123 message(1) = "The time step of the reference calculation is different from the current calculation"
124 call messages_fatal(1)
125 end if
126
127 !We remove the reference
128 safe_allocate(m_cart_ref(1:time_steps_ref, 1:num_col_cart))
129 call io_skip_header(ref_file)
130 do ii = 1, time_steps_ref
131 read(ref_file, *) jj, tt, (m_cart_ref(ii, kk), kk = 1, num_col_cart)
132 end do
133 call io_close(ref_file)
134 do ii = 1, time_steps
135 do kk = 1, num_col_cart
136 m_cart(ii, kk) = m_cart(ii, kk) - m_cart_ref(ii, kk)
137 end do
138 end do
139 safe_deallocate_a(m_cart_ref)
140 end if
141
142 !We now perform the change of basis to the rotating basis
143 !In this basis we have only m_+(q), m_-(q), and m_z(+/-q)
144 !where z means here along the easy axis
145 num_col = 8
146 safe_allocate(magnetization(1:time_steps, 1:num_col, 1:kick%nqvec))
147
148 do iq = 1, kick%nqvec
149 !Real part of m_x
150 magnetization(:,1,iq) = m_cart(:,(iq-1)*12+1)*kick%trans_vec(1,1) &
151 + m_cart(:,(iq-1)*12+3)*kick%trans_vec(2,1) &
152 + m_cart(:,(iq-1)*12+5)*kick%trans_vec(3,1)
153 !We add -Im(m_y)
154 magnetization(:,1,iq) = magnetization(:,1,iq) -(m_cart(:,(iq-1)*12+2)*kick%trans_vec(1,2) &
155 + m_cart(:,(iq-1)*12+4)*kick%trans_vec(2,2) &
156 + m_cart(:,(iq-1)*12+6)*kick%trans_vec(3,2))
157
158 !Im part of m_x
159 magnetization(:,2,iq) = m_cart(:,(iq-1)*12+2)*kick%trans_vec(1,1) &
160 + m_cart(:,(iq-1)*12+4)*kick%trans_vec(2,1) &
161 + m_cart(:,(iq-1)*12+6)*kick%trans_vec(3,1)
162 !We add +Re(m_y)
163 magnetization(:,2,iq) = magnetization(:,2,iq) +(m_cart(:,(iq-1)*12+1)*kick%trans_vec(1,2) &
164 + m_cart(:,(iq-1)*12+3)*kick%trans_vec(2,2) &
165 + m_cart(:,(iq-1)*12+5)*kick%trans_vec(3,2))
166
167 !Real part of m_x
168 magnetization(:,3,iq) = m_cart(:,(iq-1)*12+7)*kick%trans_vec(1,1) &
169 + m_cart(:,(iq-1)*12+9)*kick%trans_vec(2,1) &
170 + m_cart(:,(iq-1)*12+11)*kick%trans_vec(3,1)
171 !We add +Im(m_y)
172 magnetization(:,3,iq) = magnetization(:,3,iq) +(m_cart(:,(iq-1)*12+8)*kick%trans_vec(1,2) &
173 + m_cart(:,(iq-1)*12+10)*kick%trans_vec(2,2) &
174 + m_cart(:,(iq-1)*12+12)*kick%trans_vec(3,2))
175
176 !Im part of m_x
177 magnetization(:,4,iq) = m_cart(:,(iq-1)*12+8)*kick%trans_vec(1,1) &
178 + m_cart(:,(iq-1)*12+10)*kick%trans_vec(2,1) &
179 + m_cart(:,(iq-1)*12+12)*kick%trans_vec(3,1)
180 !We add -Re(m_y)
181 magnetization(:,4,iq) = magnetization(:,4,iq) -(m_cart(:,(iq-1)*12+7)*kick%trans_vec(1,2) &
182 + m_cart(:,(iq-1)*12+9)*kick%trans_vec(2,2) &
183 + m_cart(:,(iq-1)*12+11)*kick%trans_vec(3,2))
184
185 !Real and Im part of m_z
186 magnetization(:,5,iq) = m_cart(:,(iq-1)*12+1)*kick%easy_axis(1) &
187 + m_cart(:,(iq-1)*12+3)*kick%easy_axis(2) &
188 + m_cart(:,(iq-1)*12+5)*kick%easy_axis(3)
189 magnetization(:,6,iq) = m_cart(:,(iq-1)*12+2)*kick%easy_axis(1) &
190 + m_cart(:,(iq-1)*12+4)*kick%easy_axis(2) &
191 + m_cart(:,(iq-1)*12+6)*kick%easy_axis(3)
192 magnetization(:,7,iq) = m_cart(:,(iq-1)*12+7)*kick%easy_axis(1) &
193 + m_cart(:,(iq-1)*12+9)*kick%easy_axis(2) &
194 + m_cart(:,(iq-1)*12+11)*kick%easy_axis(3)
195 magnetization(:,8,iq) = m_cart(:,(iq-1)*12+8)*kick%easy_axis(1) &
196 + m_cart(:,(iq-1)*12+10)*kick%easy_axis(2) &
197 + m_cart(:,(iq-1)*12+12)*kick%easy_axis(3)
198 end do
199
200 safe_deallocate_a(m_cart)
201
202 write(message(1), '(a, i7, a)') "Info: Read ", time_steps, " steps from file '"// &
203 trim(io_workpath('td.general/total_magnetization', global_namespace))//"'"
204 call messages_info(1)
205
206 write(header, '(9a15)') '# time', 'Re[m_+(q,t)]', 'Im[m_+(q,t)]', &
207 'Re[m_-(-q, t)]', 'Im[m_-(-q,t)]', &
208 'Re[m_z(q,t)]', 'Im[m_z(q,t)]', 'Re[m_z(-q,t)]', 'Im[m_z(-q,t)]'
209
210 do iq = 1, kick%nqvec
211
212 write(fname, '(a,i3.3)') 'td.general/transverse_magnetization_q', iq
213 out_file = io_open(trim(fname), global_namespace, action='write')
214 write(out_file,'(a)') trim(header)
215 do kk = 1, time_steps
216 write(out_file, '(9e15.6)') (kk - 1)*dt, (magnetization(kk,ii,iq), ii = 1,8)
217 end do
218 call io_close(out_file)
219
220
221 ! Find out the iteration numbers corresponding to the time limits.
222 call spectrum_fix_time_limits(spectrum, time_steps, dt, istart, iend, ntiter)
223
224 istart = max(1, istart)
225
226 energy_steps = spectrum_nenergy_steps(spectrum)
227
228 safe_allocate(ftreal(1:energy_steps, 1:num_col))
229 safe_allocate(ftimag(1:energy_steps, 1:num_col))
230
231 call batch_init(vecpotb, 1, 1, num_col, magnetization(:, :, iq))
232 call batch_init(ftrealb, 1, 1, num_col, ftreal)
233 call batch_init(ftimagb, 1, 1, num_col, ftimag)
234
235
236 call spectrum_signal_damp(spectrum%damp, spectrum%damp_factor, istart, iend, spectrum%start_time, dt, vecpotb)
237
238 call spectrum_fourier_transform(spectrum%method, spectrum_transform_cos, spectrum%noise, &
239 istart, iend, spectrum%start_time, dt, vecpotb, spectrum%min_energy, &
240 spectrum%max_energy, spectrum%energy_step, ftrealb)
241
242 call spectrum_fourier_transform(spectrum%method, spectrum_transform_sin, spectrum%noise, &
243 istart, iend, spectrum%start_time, dt, vecpotb, spectrum%min_energy, &
244 spectrum%max_energy, spectrum%energy_step, ftimagb)
245
246
247 call vecpotb%end()
248 call ftrealb%end()
249 call ftimagb%end()
250
251 assert(abs(anint(num_col*m_half) - num_col*m_half) <= m_epsilon)
252 safe_allocate(chi(1:energy_steps, 1:num_col/2))
253 do ii = 1, num_col/2
254 do kk = 1, energy_steps
255 chi(kk,ii) = (ftreal(kk,(ii-1)*2+1) + m_zi*ftimag(kk, (ii-1)*2+1)&
256 -ftimag(kk, (ii-1)*2+2) + m_zi*ftreal(kk, (ii-1)*2+2))/kick%delta_strength
257 end do
258 end do
259
260 safe_deallocate_a(ftreal)
261 safe_deallocate_a(ftimag)
262
263
264 write(header, '(9a18)') '# energy', 'Re[\chi_{+-}(q)]', 'Im[\chi_{+-}(q)]', &
265 'Re[\chi_{-+}(-q)]', 'Im[\chi_{-+}(-q)]', &
266 'Re[\chi_{zz}(q)]', 'Im[\chi_{zz}(q)]', 'Re[\chi_{zz}(-q)]', 'Im[\chi_{zz}(-q)]'
267
268 write(fname, '(a,i3.3)') 'td.general/spin_susceptibility_q', iq
269 out_file = io_open(trim(fname), global_namespace, action='write')
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, '(13e15.6)') ww, &
274 (real(chi(kk,ii), real64), aimag(chi(kk,ii)), ii = 1, num_col/2)
275 end do
276 call io_close(out_file)
277
278 safe_deallocate_a(chi)
279 end do !iq
280
281 safe_deallocate_a(magnetization)
282
283 call kick_end(kick)
284
286 call io_end()
287 call messages_end()
288 call parser_end()
289 call global_end()
290 end subroutine spin_susceptibility_main
292
293!! Local Variables:
294!! mode: f90
295!! coding: utf-8
296!! 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
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
complex(real64), parameter, public m_zi
Definition: global.F90:187
real(real64), parameter, public m_epsilon
Definition: global.F90:189
real(real64), parameter, public m_half
Definition: global.F90:179
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 kick_read(kick, iunit, namespace)
Definition: kick.F90:800
subroutine, public kick_end(kick)
Definition: kick.F90:776
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
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
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:440
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
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
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
subroutine, public spin_susceptibility_main()
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.
subroutine, public unit_system_init(namespace)