28 use,
intrinsic :: iso_fortran_env
50 integer :: iunit, ierr, ii, jj, iter, read_iter, ntime, nvel, ivel
51 integer :: istart, iend, energy_steps, out_file
52 real(real64),
allocatable :: time(:), velocities(:, :)
53 real(real64),
allocatable :: total_current(:, :), ftcurr(:, :, :), curr(:, :)
54 real(real64),
allocatable :: heat_current(:,:), ftheatcurr(:,:,:), heatcurr(:,:)
55 complex(real64),
allocatable :: invdielectric(:, :)
56 type(ions_t),
pointer :: ions
57 type(space_t) :: space
58 type(spectrum_t) :: spectrum
60 type(batch_t) :: currb, ftcurrb, heatcurrb, ftheatcurrb
61 real(real64) :: ww, curtime, deltat, v0
62 character(len=MAX_PATH_LEN) :: ref_filename
63 integer :: ref_file, time_steps_ref, kk
64 real(real64),
allocatable :: velcm(:), vel0(:), current(:), current_ref(:, :)
65 real(real64) :: dt_ref, tt, start_time
66 integer :: ifreq, max_freq
67 integer :: skip, smearing
68 logical :: from_forces
69 character(len=120) :: header
70 real(real64) :: excess_charge, qtot, javerage
120 if (spectrum%end_time <
m_zero) spectrum%end_time = huge(spectrum%end_time)
126 qtot = -(ions%val_charge() + excess_charge)
128 if (from_forces)
then
130 call messages_write(
'Info: Reading coordinates from td.general/coordinates')
140 nvel = ions%natoms*ions%space%dim
142 safe_allocate(time(1:ntime))
143 safe_allocate(velocities(1:nvel, 1:ntime))
154 read(unit = iunit, iostat = ierr, fmt = *) read_iter, curtime, &
155 ((ions%pos(jj, ii), jj = 1, 3), ii = 1, ions%natoms), &
156 ((ions%vel(jj, ii), jj = 1, 3), ii = 1, ions%natoms)
160 if (ierr /= 0 .or. curtime >= spectrum%end_time)
then
166 assert(iter == read_iter + 1)
168 if (curtime >= spectrum%start_time .and. mod(iter, skip) == 0)
then
170 time(ntime) = curtime
172 do ii = 1, ions%natoms
173 do jj = 1, ions%space%dim
192 call messages_write(
'Info: Reading total current from td.general/total_current')
197 if (iunit /= -1)
then
206 safe_allocate(total_current(1:space%dim, 1:ntime))
207 safe_allocate(heat_current(1:space%dim, 1:ntime))
208 safe_allocate(time(1:ntime))
211 read(iunit, *) read_iter, time(iter), (total_current(ii, iter), ii = 1, space%dim)
222 ref_file =
io_open(trim(ref_filename)//
'/total_current', action=
'read', status=
'old')
226 if (time_steps_ref < ntime)
then
227 message(1) =
"The reference calculation does not contain enought time steps"
231 if (.not.
is_close(dt_ref, time(2)-time(1)))
then
232 message(1) =
"The time step of the reference calculation is different from the current calculation"
237 time_steps_ref = time_steps_ref + 1
238 safe_allocate(current_ref(1:space%dim, 1:time_steps_ref))
240 do ii = 1, time_steps_ref
241 read(ref_file, *) jj, tt, (current_ref(kk, ii), kk = 1, space%dim)
246 total_current(kk, iter) = total_current(kk, iter) - current_ref(kk, iter)
249 safe_deallocate_a(current_ref)
251 start_time = spectrum%start_time
262 javerage = javerage + total_current(kk, iter)
264 javerage = javerage/ntime
266 total_current(kk, iter) = total_current(kk, iter) - javerage
273 call messages_write(
"Cannot find the 'td.general/total_current' file.")
279 safe_allocate(total_current(1:space%dim, 1:ntime))
280 safe_allocate(heat_current(1:space%dim, 1:ntime))
281 safe_allocate(time(1:ntime))
283 total_current(1:space%dim, 1:ntime) =
m_zero
289 if (iunit /= -1)
then
300 read(iunit, *) read_iter, time(iter), (heat_current(ii, iter), ii = 1, space%dim)
307 call messages_write(
"Cannot find the 'td.general/heat_current' file.")
311 call messages_write(
"Check ConductivityFromForces to possibly compute it from forces.")
314 heat_current(1:space%dim, 1:ntime) =
m_zero
320 safe_allocate(curr(ntime, 1:space%dim))
321 safe_allocate(heatcurr(ntime, 1:space%dim))
322 safe_allocate(vel0(1:space%dim))
324 safe_allocate(velcm(1:space%dim))
325 safe_allocate(current(1:space%dim))
331 if (from_forces)
then
335 do ii = 1, ions%natoms
337 vel0(jj) = vel0(jj) + velocities(ivel, iter)/real(ions%natoms, real64)
347 do ii = 1, ions%natoms
349 velcm(jj) = velcm(jj) + velocities(ivel, iter)/real(ions%natoms, real64)
350 current(jj) = current(jj) + &
351 ions%mass(ii)/ions%latt%rcell_volume*(velocities(ivel, iter) - vel0(jj))
356 curr(iter, 1:space%dim) = vel0(1:space%dim)*qtot/ions%latt%rcell_volume + current(1:space%dim)
359 curr(iter, 1:space%dim) = total_current(1:space%dim, iter)/ions%latt%rcell_volume
360 heatcurr(iter,1:space%dim) = heat_current(1:space%dim, iter)/ions%latt%rcell_volume
363 if (from_forces)
write(iunit,*) iter, iter*deltat, curr(iter, 1:space%dim)
367 safe_deallocate_a(velcm)
368 safe_deallocate_a(current)
371 if (from_forces)
call io_close(iunit)
375 istart = max(1, istart)
378 safe_allocate(ftcurr(1:energy_steps, 1:space%dim, 1:2))
381 call spectrum_signal_damp(spectrum%damp, spectrum%damp_factor, istart, iend, spectrum%start_time, deltat, currb)
383 call batch_init(ftcurrb, 1, 1, space%dim, ftcurr(:, :, 1))
385 istart, iend, spectrum%start_time, deltat, currb, spectrum%min_energy, spectrum%max_energy, &
386 spectrum%energy_step, ftcurrb)
389 call batch_init(ftcurrb, 1, 1, space%dim, ftcurr(:, :, 2))
391 istart, iend, spectrum%start_time, deltat, currb, spectrum%min_energy, spectrum%max_energy, &
392 spectrum%energy_step, ftcurrb)
402 write(unit = iunit, iostat = ierr, fmt =
'(a)') &
403 '###########################################################################################################################'
404 write(unit = iunit, iostat = ierr, fmt =
'(8a)')
'# HEADER'
405 write(unit = iunit, iostat = ierr, fmt =
'(a,a,a)') &
407 write(unit = iunit, iostat = ierr, fmt =
'(a)') &
408 '###########################################################################################################################'
410 v0 = norm2(vel0(1:space%dim))
411 if (.not. from_forces .or. v0 < epsilon(v0)) v0 =
m_one
420 vel0(1:space%dim) = vel0(1:space%dim) /
p_c
421 v0 = norm2(vel0(1:space%dim))
425 do ifreq = 1, energy_steps
426 ww = spectrum%energy_step*(ifreq - 1) + spectrum%min_energy
428 transpose(ftcurr(ifreq, 1:space%dim, 1:2)/v0)
437 safe_allocate(invdielectric(1:space%dim, 1:energy_steps))
438 do ifreq = 1, energy_steps
439 ww = max((ifreq-1)*spectrum%energy_step + spectrum%min_energy,
m_epsilon)
441 invdielectric(1:space%dim, ifreq) = (vel0(1:space%dim) +
m_four *
m_pi * &
442 cmplx(ftcurr(ifreq, 1:space%dim, 2),-ftcurr(ifreq, 1:space%dim, 1), real64) / ww) / v0
447 select case (space%dim)
449 write(header,
'(3a15)')
'# energy',
'Re x',
'Im x'
451 write(header,
'(5a15)')
'# energy',
'Re x',
'Im x',
'Re y',
'Im y'
453 write(header,
'(7a15)')
'# energy',
'Re x',
'Im x',
'Re y',
'Im y',
'Re z',
'Im z'
455 write(out_file,
'(a)') trim(header)
456 do ifreq = 1, energy_steps
457 ww = (ifreq-1)*spectrum%energy_step + spectrum%min_energy
458 select case (space%dim)
460 write(out_file,
'(3e15.6)') ww, &
461 real(invdielectric(1, ifreq), real64), aimag(invdielectric(1, ifreq))
463 write(out_file,
'(5e15.6)') ww, &
464 real(invdielectric(1, ifreq), real64), aimag(invdielectric(1, ifreq)), &
465 real(invdielectric(2, ifreq), real64), aimag(invdielectric(2, ifreq))
467 write(out_file,
'(7e15.6)') ww, &
468 real(invdielectric(1, ifreq), real64), aimag(invdielectric(1, ifreq)), &
469 real(invdielectric(2, ifreq), real64), aimag(invdielectric(2, ifreq)), &
470 real(invdielectric(3, ifreq), real64), aimag(invdielectric(3, ifreq))
475 safe_deallocate_a(ftcurr)
476 safe_deallocate_a(invdielectric)
480 if (from_forces)
then
481 safe_allocate(ftheatcurr(1:energy_steps, 1:space%dim, 1:2))
485 call batch_init(heatcurrb, 1, 1, space%dim, heatcurr)
489 call batch_init(ftheatcurrb, 1, 1, space%dim, ftheatcurr(:, :, 1))
491 1, ntime,
m_zero, deltat, heatcurrb, spectrum%min_energy, spectrum%max_energy, spectrum%energy_step, ftheatcurrb)
492 call ftheatcurrb%end()
494 call batch_init(ftheatcurrb, 1, 1, space%dim, ftheatcurr(:, :, 2))
496 1, ntime,
m_zero, deltat, heatcurrb, spectrum%min_energy, spectrum%max_energy, spectrum%energy_step, ftheatcurrb)
497 call ftheatcurrb%end()
506 write(unit = iunit, iostat = ierr, fmt =
'(a)') &
507 '###########################################################################################################################'
508 write(unit = iunit, iostat = ierr, fmt =
'(8a)')
'# HEADER'
509 write(unit = iunit, iostat = ierr, fmt =
'(a,a,a)') &
511 write(unit = iunit, iostat = ierr, fmt =
'(a)') &
512 '###########################################################################################################################'
514 v0 = norm2(vel0(1:space%dim))
515 if (.not. from_forces .or. v0 < epsilon(v0)) v0 =
m_one
517 do ifreq = 1, energy_steps
518 ww = spectrum%energy_step*(ifreq - 1) + spectrum%min_energy
520 transpose(ftheatcurr(ifreq, 1:space%dim, 1:2)/v0)
526 safe_deallocate_a(ftheatcurr)
531 safe_deallocate_a(vel0)
532 safe_deallocate_p(ions)
534 safe_deallocate_a(total_current)
535 safe_deallocate_a(heat_current)
536 safe_deallocate_a(curr)
537 safe_deallocate_a(heatcurr)
538 safe_deallocate_a(time)
initialize a batch with existing memory
This module implements batches of mesh functions.
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 conductivity_main()
subroutine, public global_end()
Finalise parser varinfo file, and MPI.
real(real64), parameter, public m_zero
real(real64), parameter, public m_four
real(real64), parameter, public m_pi
some mathematical constants
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...
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
real(real64), parameter, public m_epsilon
real(real64), parameter, public p_c
Electron gyromagnetic ratio, see Phys. Rev. Lett. 130, 071801 (2023)
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
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...
subroutine, public io_close(iunit, grp)
subroutine, public io_skip_header(iunit)
subroutine, public io_end()
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
This module is intended to contain "only mathematical" functions and procedures.
subroutine, public messages_end()
subroutine, public messages_init(output_dir)
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_obsolete_variable(namespace, name, rep)
subroutine, public messages_new_line()
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_experimental(name, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
type(mpi_grp_t), public mpi_world
type(namespace_t), public global_namespace
logical function, public parse_is_defined(namespace, name)
subroutine, public parser_init()
Initialise the Octopus parser.
subroutine, public parser_end()
End the Octopus parser.
integer function, public parse_block(namespace, name, blk, check_varinfo_)
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
subroutine, public profiling_end(namespace)
subroutine, public profiling_init(namespace)
Create profiling subdirectory.
integer, parameter, public smear_semiconductor
subroutine, public spectrum_fix_time_limits(spectrum, time_steps, dt, istart, iend, ntiter)
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...
subroutine, public spectrum_init(spectrum, namespace, default_energy_step, default_max_energy)
subroutine, public spectrum_signal_damp(damp_type, damp_factor, time_start, time_end, t0, time_step, time_function)
integer, parameter, public spectrum_transform_cos
integer, parameter, public spectrum_transform_sin
subroutine, public spectrum_count_time_steps(namespace, iunit, time_steps, dt)
pure integer function, public spectrum_nenergy_steps(spectrum)
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
character(len=20) pure function, public units_abbrev(this)
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
subroutine, public unit_system_init(namespace)