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 integer :: in_file, out_file, ref_file, ii, jj, kk, ierr, ib, num_col, num_col_cart
41 integer :: time_steps, time_steps_ref, energy_steps, istart, iend, ntiter, iq
42 real(real64) :: dt, tt, ww, dt_ref
43 real(real64), allocatable :: ftreal(:,:), ftimag(:,:)
44 real(real64), allocatable :: m_cart(:,:), m_cart_ref(:,:), magnetization(:,:,:)
45 type(spectrum_t) :: spectrum
46 type(batch_t) :: vecpotb, ftrealb, ftimagb
47 type(kick_t) :: kick
48 character(len=256) :: header
49 character(len=MAX_PATH_LEN) :: fname, ref_filename
50 complex(real64), allocatable :: chi(:,:)
51
52 ! Initialize stuff
54
55 call getopt_init(ierr)
56 if (ierr == 0) call getopt_dielectric_function()
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 in_file = io_open('td.general/total_magnetization', global_namespace, action='read', status='old')
71 rewind(in_file)
72 read(in_file,*)
73 read(in_file,*)
74 call kick_read(kick, in_file, global_namespace)
75 call io_skip_header(in_file)
76 call spectrum_count_time_steps(global_namespace, in_file, time_steps, dt)
77
78 time_steps = time_steps + 1
79
80 num_col_cart = 12*kick%nqvec
81 safe_allocate(m_cart(1:time_steps, 1:num_col_cart))
82
83 call io_skip_header(in_file)
84
85 do ii = 1, time_steps
86 read(in_file, *) jj, tt, (m_cart(ii,ib),ib = 1, num_col_cart)
87 end do
88
89 call io_close(in_file)
90
91 if (parse_is_defined(global_namespace, 'TransientMagnetizationReference')) then
92 !%Variable TransientMagnetizationReference
93 !%Type string
94 !%Default "."
95 !%Section Utilities::oct-spin_susceptibility
96 !%Description
97 !% In case of delayed kick, the calculation of the transient spin susceptibility requires
98 !% to substract a reference calculation, containing dynamics of the magnetization without the kick
99 !% This reference must be computed having
100 !% TDOutput = total_magnetization.
101 !% This variables defined the directory in which the reference total_magnetization file is,
102 !% relative to the current folder
103 !%End
104
105 call parse_variable(global_namespace, 'TransientMagnetizationReference', '.', ref_filename)
106 ref_file = io_open(trim(ref_filename)//'/total_magnetization', global_namespace, action='read', status='old')
107 call io_skip_header(ref_file)
108 call spectrum_count_time_steps(global_namespace, ref_file, time_steps_ref, dt_ref)
109 time_steps_ref = time_steps_ref + 1
110
111 if (time_steps_ref < time_steps) then
112 message(1) = "The reference calculation does not contain enought time steps"
113 call messages_fatal(1)
114 end if
115
116 if (.not. is_close(dt_ref, dt)) then
117 message(1) = "The time step of the reference calculation is different from the current calculation"
118 call messages_fatal(1)
119 end if
120
121 !We remove the reference
122 safe_allocate(m_cart_ref(1:time_steps_ref, 1:num_col_cart))
123 call io_skip_header(ref_file)
124 do ii = 1, time_steps_ref
125 read(ref_file, *) jj, tt, (m_cart_ref(ii, kk), kk = 1, num_col_cart)
126 end do
127 call io_close(ref_file)
128 do ii = 1, time_steps
129 do kk = 1, num_col_cart
130 m_cart(ii, kk) = m_cart(ii, kk) - m_cart_ref(ii, kk)
131 end do
132 end do
133 safe_deallocate_a(m_cart_ref)
134 end if
135
136 !We now perform the change of basis to the rotating basis
137 !In this basis we have only m_+(q), m_-(q), and m_z(+/-q)
138 !where z means here along the easy axis
139 num_col = 8
140 safe_allocate(magnetization(1:time_steps, 1:num_col, 1:kick%nqvec))
141
142 do iq = 1, kick%nqvec
143 !Real part of m_x
144 magnetization(:,1,iq) = m_cart(:,(iq-1)*12+1)*kick%trans_vec(1,1) &
145 + m_cart(:,(iq-1)*12+3)*kick%trans_vec(2,1) &
146 + m_cart(:,(iq-1)*12+5)*kick%trans_vec(3,1)
147 !We add -Im(m_y)
148 magnetization(:,1,iq) = magnetization(:,1,iq) -(m_cart(:,(iq-1)*12+2)*kick%trans_vec(1,2) &
149 + m_cart(:,(iq-1)*12+4)*kick%trans_vec(2,2) &
150 + m_cart(:,(iq-1)*12+6)*kick%trans_vec(3,2))
151
152 !Im part of m_x
153 magnetization(:,2,iq) = m_cart(:,(iq-1)*12+2)*kick%trans_vec(1,1) &
154 + m_cart(:,(iq-1)*12+4)*kick%trans_vec(2,1) &
155 + m_cart(:,(iq-1)*12+6)*kick%trans_vec(3,1)
156 !We add +Re(m_y)
157 magnetization(:,2,iq) = magnetization(:,2,iq) +(m_cart(:,(iq-1)*12+1)*kick%trans_vec(1,2) &
158 + m_cart(:,(iq-1)*12+3)*kick%trans_vec(2,2) &
159 + m_cart(:,(iq-1)*12+5)*kick%trans_vec(3,2))
160
161 !Real part of m_x
162 magnetization(:,3,iq) = m_cart(:,(iq-1)*12+7)*kick%trans_vec(1,1) &
163 + m_cart(:,(iq-1)*12+9)*kick%trans_vec(2,1) &
164 + m_cart(:,(iq-1)*12+11)*kick%trans_vec(3,1)
165 !We add +Im(m_y)
166 magnetization(:,3,iq) = magnetization(:,3,iq) +(m_cart(:,(iq-1)*12+8)*kick%trans_vec(1,2) &
167 + m_cart(:,(iq-1)*12+10)*kick%trans_vec(2,2) &
168 + m_cart(:,(iq-1)*12+12)*kick%trans_vec(3,2))
169
170 !Im part of m_x
171 magnetization(:,4,iq) = m_cart(:,(iq-1)*12+8)*kick%trans_vec(1,1) &
172 + m_cart(:,(iq-1)*12+10)*kick%trans_vec(2,1) &
173 + m_cart(:,(iq-1)*12+12)*kick%trans_vec(3,1)
174 !We add -Re(m_y)
175 magnetization(:,4,iq) = magnetization(:,4,iq) -(m_cart(:,(iq-1)*12+7)*kick%trans_vec(1,2) &
176 + m_cart(:,(iq-1)*12+9)*kick%trans_vec(2,2) &
177 + m_cart(:,(iq-1)*12+11)*kick%trans_vec(3,2))
178
179 !Real and Im part of m_z
180 magnetization(:,5,iq) = m_cart(:,(iq-1)*12+1)*kick%easy_axis(1) &
181 + m_cart(:,(iq-1)*12+3)*kick%easy_axis(2) &
182 + m_cart(:,(iq-1)*12+5)*kick%easy_axis(3)
183 magnetization(:,6,iq) = m_cart(:,(iq-1)*12+2)*kick%easy_axis(1) &
184 + m_cart(:,(iq-1)*12+4)*kick%easy_axis(2) &
185 + m_cart(:,(iq-1)*12+6)*kick%easy_axis(3)
186 magnetization(:,7,iq) = m_cart(:,(iq-1)*12+7)*kick%easy_axis(1) &
187 + m_cart(:,(iq-1)*12+9)*kick%easy_axis(2) &
188 + m_cart(:,(iq-1)*12+11)*kick%easy_axis(3)
189 magnetization(:,8,iq) = m_cart(:,(iq-1)*12+8)*kick%easy_axis(1) &
190 + m_cart(:,(iq-1)*12+10)*kick%easy_axis(2) &
191 + m_cart(:,(iq-1)*12+12)*kick%easy_axis(3)
192 end do
193
194 safe_deallocate_a(m_cart)
195
196 write(message(1), '(a, i7, a)') "Info: Read ", time_steps, " steps from file '"// &
197 trim(io_workpath('td.general/total_magnetization', global_namespace))//"'"
198 call messages_info(1)
199
200 write(header, '(9a15)') '# time', 'Re[m_+(q,t)]', 'Im[m_+(q,t)]', &
201 'Re[m_-(-q, t)]', 'Im[m_-(-q,t)]', &
202 'Re[m_z(q,t)]', 'Im[m_z(q,t)]', 'Re[m_z(-q,t)]', 'Im[m_z(-q,t)]'
203
204 do iq = 1, kick%nqvec
205
206 write(fname, '(a,i3.3)') 'td.general/transverse_magnetization_q', iq
207 out_file = io_open(trim(fname), global_namespace, action='write')
208 write(out_file,'(a)') trim(header)
209 do kk = 1, time_steps
210 write(out_file, '(9e15.6)') (kk - 1)*dt, (magnetization(kk,ii,iq), ii = 1,8)
211 end do
212 call io_close(out_file)
213
214
215 ! Find out the iteration numbers corresponding to the time limits.
216 call spectrum_fix_time_limits(spectrum, time_steps, dt, istart, iend, ntiter)
217
218 istart = max(1, istart)
219
220 energy_steps = spectrum_nenergy_steps(spectrum)
221
222 safe_allocate(ftreal(1:energy_steps, 1:num_col))
223 safe_allocate(ftimag(1:energy_steps, 1:num_col))
224
225 call batch_init(vecpotb, 1, 1, num_col, magnetization(:, :, iq))
226 call batch_init(ftrealb, 1, 1, num_col, ftreal)
227 call batch_init(ftimagb, 1, 1, num_col, ftimag)
228
229
230 call spectrum_signal_damp(spectrum%damp, spectrum%damp_factor, istart, iend, spectrum%start_time, dt, vecpotb)
231
232 call spectrum_fourier_transform(spectrum%method, spectrum_transform_cos, spectrum%noise, &
233 istart, iend, spectrum%start_time, dt, vecpotb, spectrum%min_energy, &
234 spectrum%max_energy, spectrum%energy_step, ftrealb)
235
236 call spectrum_fourier_transform(spectrum%method, spectrum_transform_sin, spectrum%noise, &
237 istart, iend, spectrum%start_time, dt, vecpotb, spectrum%min_energy, &
238 spectrum%max_energy, spectrum%energy_step, ftimagb)
239
240
241 call vecpotb%end()
242 call ftrealb%end()
243 call ftimagb%end()
244
245 assert(abs(anint(num_col*m_half) - num_col*m_half) <= m_epsilon)
246 safe_allocate(chi(1:energy_steps, 1:num_col/2))
247 do ii = 1, num_col/2
248 do kk = 1, energy_steps
249 chi(kk,ii) = (ftreal(kk,(ii-1)*2+1) + m_zi*ftimag(kk, (ii-1)*2+1)&
250 -ftimag(kk, (ii-1)*2+2) + m_zi*ftreal(kk, (ii-1)*2+2))/kick%delta_strength
251 end do
252 end do
253
254 safe_deallocate_a(ftreal)
255 safe_deallocate_a(ftimag)
256
257
258 write(header, '(9a18)') '# energy', 'Re[\chi_{+-}(q)]', 'Im[\chi_{+-}(q)]', &
259 'Re[\chi_{-+}(-q)]', 'Im[\chi_{-+}(-q)]', &
260 'Re[\chi_{zz}(q)]', 'Im[\chi_{zz}(q)]', 'Re[\chi_{zz}(-q)]', 'Im[\chi_{zz}(-q)]'
261
262 write(fname, '(a,i3.3)') 'td.general/spin_susceptibility_q', iq
263 out_file = io_open(trim(fname), global_namespace, action='write')
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, '(13e15.6)') ww, &
268 (real(chi(kk,ii), real64), aimag(chi(kk,ii)), ii = 1, num_col/2)
269 end do
270 call io_close(out_file)
271
272 safe_deallocate_a(chi)
273 end do !iq
274
275 safe_deallocate_a(magnetization)
276
277 call kick_end(kick)
278
280 call io_end()
281 call messages_end()
282 call parser_end()
283 call global_end()
284
285end program spin_susceptibility
286
287!! Local Variables:
288!! mode: f90
289!! coding: utf-8
290!! End:
initialize a batch with existing memory
Definition: batch.F90:277
This module implements batches of mesh functions.
Definition: batch.F90:135
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:494
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:294
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
Definition: global.F90:432
complex(real64), parameter, public m_zi
Definition: global.F90:214
real(real64), parameter, public m_epsilon
Definition: global.F90:216
real(real64), parameter, public m_half
Definition: global.F90:206
Definition: io.F90:116
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:165
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
subroutine, public io_skip_header(iunit)
Definition: io.F90:646
subroutine, public io_end()
Definition: io.F90:271
character(len=max_path_len) function, public io_workpath(path, namespace)
construct path name from given name and namespace
Definition: io.F90:318
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
subroutine, public kick_read(kick, iunit, namespace)
Definition: kick.F90:820
subroutine, public kick_end(kick)
Definition: kick.F90:796
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
subroutine, public messages_end()
Definition: messages.F90:273
subroutine, public messages_init(output_dir)
Definition: messages.F90:220
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
type(namespace_t), public global_namespace
Definition: namespace.F90:135
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:463
subroutine, public parser_init()
Initialise the Octopus parser.
Definition: parser.F90:410
subroutine, public parser_end()
End the Octopus parser.
Definition: parser.F90:442
subroutine, public profiling_end(namespace)
Definition: profiling.F90:415
subroutine, public profiling_init(namespace)
Create profiling subdirectory.
Definition: profiling.F90:257
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:215
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:173
integer, parameter, public spectrum_transform_sin
Definition: spectrum.F90:173
subroutine, public spectrum_count_time_steps(namespace, iunit, time_steps, dt)
Definition: spectrum.F90:2393
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:134
This module defines the unit system, used for input and output.
subroutine, public unit_system_init(namespace)
program spin_susceptibility