Octopus
td_write.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
21module td_write_oct_m
22 use blas_oct_m
23 use comm_oct_m
25 use debug_oct_m
33 use global_oct_m
34 use grid_oct_m
35 use output_oct_m
44 use io_oct_m
46 use ions_oct_m
47 use kick_oct_m
48 use, intrinsic :: iso_fortran_env
50 use lasers_oct_m
53 use lda_u_oct_m
56 use math_oct_m
59 use mesh_oct_m
62 use mpi_oct_m
67 use parser_oct_m
73 use space_oct_m
83 use types_oct_m
84 use unit_oct_m
86 use utils_oct_m
88 use v_ks_oct_m
90
91 implicit none
92
93 private
94 public :: &
95 td_write_t, &
106
108 integer, parameter, public :: &
109 OUT_MULTIPOLES = 1, &
110 out_angular = 2, &
111 out_spin = 3, &
112 out_populations = 4, &
113 out_coords = 5, &
114 out_acc = 6, &
115 out_laser = 7, &
116 out_energy = 8, &
117 out_proj = 9, &
118 out_magnets = 10, &
119 out_gauge_field = 11, &
120 out_temperature = 12, &
121 out_ftchd = 13, &
122 out_vel = 14, &
123 out_eigs = 15, &
124 out_ion_ch = 16, &
125 out_total_current = 17, &
126 out_partial_charges = 18, &
127 out_kp_proj = 19, &
128 out_floquet = 20, &
129 out_n_ex = 21, &
130 out_separate_coords = 22, &
132 out_separate_forces = 24, &
134 out_tot_m = 26, &
135 out_q = 27, &
136 out_mxll_field = 28, &
137 out_norm_ks = 29, &
138 out_cell_parameters = 30, &
139 ! This constant should always equal the last integer above
140 ! as it defines the total numer of output options
141 out_max = 30
142
143
145 ! Entries must be consistent with the ordering above
146 character(len=100) :: td_file_name(OUT_MAX) = [character(100) :: &
147 "NULL", & ! Do not include OUT_MULTIPOLES (extension is a function of state index)
148 "angular", &
149 "spin", &
150 "populations", &
151 "coordinates", &
152 "acceleration", &
153 "NULL", & ! Do not include OUT_LASER
154 "energy", &
155 "projections", &
156 "magnetic_moments", &
157 "gauge_field", &
158 "temperature", &
159 "NULL", & ! Do not include OUT_FTCHD
160 "velocity", &
161 "eigenvalues", &
162 "ion_ch", &
163 "total_current", &
164 "partial_charges", &
165 "projections", &
166 "floquet_bands", &
167 "n_ex", &
168 "onlyCoordinates", &
169 "onlyVelocities", &
170 "onlyForces", &
171 "total_heat_current", &
172 "total_magnetization", &
173 "photons_q", &
174 "maxwell_dipole_field", &
175 "norm_wavefunctions", &
176 "cell_parameters"]
177
178 integer, parameter :: &
179 OUT_DFTU_EFFECTIVE_U = 1, &
180 out_dftu_max = 1
181
182
183 integer, parameter :: &
184 OUT_MAXWELL_TOTAL_E_FIELD = 1, &
190 out_maxwell_energy = 19, &
197
198 integer, parameter, public :: &
199 OUT_MAXWELL_MAX = 25
200
201 integer, parameter :: &
203 maxwell_long_field = 2, &
205
206 integer, parameter :: &
207 maxwell_e_field = 1, &
209
211 type td_write_prop_t
212 type(c_ptr) :: handle
213 type(c_ptr), allocatable :: mult_handles(:)
214 type(mpi_grp_t) :: mpi_grp
215 integer :: hand_start
216 integer :: hand_end
217 logical :: write = .false.
218 logical :: resolve_states = .false.
219 end type td_write_prop_t
220
224 type td_write_t
225 private
226 type(td_write_prop_t), public :: out(out_max)
227 type(td_write_prop_t) :: out_dftu(out_dftu_max)
228
229 integer :: lmax
230 real(real64) :: lmm_r
231 type(states_elec_t) :: gs_st
232 ! calculate the projections(s) onto it.
233 integer :: n_excited_states
234 type(excited_states_t), allocatable :: excited_st(:)
235 integer :: compute_interval
236 end type td_write_t
237
238contains
240
241 subroutine td_write_kick(outp, namespace, space, mesh, kick, ions, iter)
242 type(output_t), intent(in) :: outp
243 type(namespace_t), intent(in) :: namespace
244 type(electron_space_t), intent(in) :: space
245 class(mesh_t), intent(in) :: mesh
246 type(kick_t), intent(in) :: kick
247 type(ions_t), intent(in) :: ions
248 integer, intent(in) :: iter
249
250 complex(real64), allocatable :: kick_function(:)
251 character(len=256) :: filename
252 integer :: err
253
254 push_sub(td_write_kick)
255
256 write(filename, '(a,i7.7)') "td.", iter ! name of directory
257 if (outp%what(option__output__delta_perturbation)) then
258 safe_allocate(kick_function(1:mesh%np))
259 call kick_function_get(space, mesh, kick, kick_function, 1)
260 call zio_function_output(outp%how(option__output__delta_perturbation), filename, "kick_function", namespace, &
261 space, mesh, kick_function(:), units_out%energy, err, pos=ions%pos, atoms=ions%atom)
262 safe_deallocate_a(kick_function)
263 end if
264
265 pop_sub(td_write_kick)
266 end subroutine td_write_kick
267
268
278 subroutine td_write_init(writ, namespace, space, outp, gr, st, hm, ions, ext_partners, ks, ions_move, &
279 with_gauge_field, kick, iter, max_iter, dt, mc)
280 type(td_write_t), target, intent(out) :: writ
281 type(namespace_t), intent(in) :: namespace
282 type(electron_space_t), intent(in) :: space
283 type(output_t), intent(inout) :: outp
284 type(grid_t), intent(in) :: gr
285 type(states_elec_t), intent(inout) :: st
286 type(hamiltonian_elec_t), intent(inout) :: hm
287 type(ions_t), intent(in) :: ions
288 type(partner_list_t), intent(in) :: ext_partners
289 type(v_ks_t), intent(inout) :: ks
290 logical, intent(in) :: ions_move
291 logical, intent(in) :: with_gauge_field
292 type(kick_t), intent(in) :: kick
293 integer, intent(in) :: iter
294 integer, intent(in) :: max_iter
295 real(real64), intent(in) :: dt
296 type(multicomm_t), intent(in) :: mc
297
298 real(real64) :: rmin
299 integer :: ierr, first, ii, ist, jj, flags, iout, default, ifile
300 logical :: output_options(max_output_types)
301 integer :: output_interval(0:max_output_types)
302 integer(int64) :: how(0:max_output_types)
303 type(block_t) :: blk
304 character(len=MAX_PATH_LEN) :: filename
306 logical :: resolve_states
307 logical, allocatable :: skip(:)
311 !%Variable TDOutput
312 !%Type block
313 !%Default multipoles + energy (+ others depending on other options)
314 !%Section Time-Dependent::TD Output
315 !%Description
316 !% Defines what should be output during the time-dependent
317 !% simulation. Many of the options can increase the computational
318 !% cost of the simulation, so only use the ones that you need. In
319 !% most cases the default value is enough, as it is adapted to the
320 !% details of the TD run. If the ions are allowed to be moved, additionally
321 !% the geometry and the temperature are output. If a laser is
322 !% included it will output by default.
323 !%
324 !% Note: the output files generated by this option are updated
325 !% every <tt>RestartWriteInterval</tt> steps.
326 !%
327 !% Example:
328 !% <br><br><tt>%TDOutput
329 !% <br>&nbsp;&nbsp;multipoles
330 !% <br>&nbsp;&nbsp;energy
331 !% <br>%<br></tt>
332 !%
333 !%Option multipoles 1
334 !% Outputs the (electric) multipole moments of the density to the file <tt>td.general/multipoles</tt>.
335 !% This is required to, <i>e.g.</i>, calculate optical absorption spectra of finite systems. The
336 !% maximum value of <math>l</math> can be set with the variable <tt>TDMultipoleLmax</tt>.
337 !%Option angular 2
338 !% Outputs the orbital angular momentum of the system to <tt>td.general/angular</tt>.
339 !% This can be used to calculate circular dicrhoism. Not implemented for periodic systems.
340 !% In case of a nonlocal pseudopotential, the gauge used can be specified using
341 !% the variable <tt>MagneticGaugeCorrection</tt>.
342 !%Option spin 3
343 !% (Experimental) Outputs the expectation value of the spin, which can be used to calculate magnetic
344 !% circular dichroism.
345 !%Option populations 4
346 !% (Experimental) Outputs the projection of the time-dependent
347 !% Kohn-Sham Slater determinant onto the ground state (or
348 !% approximations to the excited states) to the file
349 !% <tt>td.general/populations</tt>. Note that the calculation of
350 !% populations is expensive in memory and computer time, so it
351 !% should only be used if it is really needed. See <tt>TDExcitedStatesToProject</tt>.
352 !%Option geometry 5
353 !% If set (and if the atoms are allowed to move), outputs the coordinates, velocities,
354 !% and forces of the atoms to the the file <tt>td.general/coordinates</tt>. On by default if <tt>MoveIons = yes</tt>.
355 !%Option dipole_acceleration 6
356 !% When set, outputs the acceleration of the electronic dipole, calculated from the Ehrenfest theorem,
357 !% in the file <tt>td.general/acceleration</tt>. This file can then be
358 !% processed by the utility <tt>oct-harmonic-spectrum</tt> in order to obtain the harmonic spectrum.
359 !%Option laser 7
360 !% If set, outputs the laser field to the file <tt>td.general/laser</tt>.
361 !% On by default if <tt>TDExternalFields</tt> is set.
362 !%Option energy 8
363 !% If set, <tt>octopus</tt> outputs the different components of the energy
364 !% to the file <tt>td.general/energy</tt>. Will be zero except for every <tt>TDEnergyUpdateIter</tt> iterations.
365 !%Option td_occup 9
366 !% (Experimental) If set, outputs the projections of the
367 !% time-dependent Kohn-Sham wavefunctions onto the static
368 !% (zero-time) wavefunctions to the file
369 !% <tt>td.general/projections.XXX</tt>. Only use this option if
370 !% you really need it, as it might be computationally expensive. See <tt>TDProjStateStart</tt>.
371 !% The output interval of this quantity is controled by the variable <tt>TDOutputComputeInterval</tt>
372 !% In case of states parallelization, all the ground-state states are stored by each task.
373 !%Option local_mag_moments 10
374 !% If set, outputs the local magnetic moments, integrated in sphere centered around each atom.
375 !% The radius of the sphere can be set with <tt>LocalMagneticMomentsSphereRadius</tt>.
376 !%Option gauge_field 11
377 !% If set, outputs the vector gauge field corresponding to a spatially uniform (but time-dependent)
378 !% external electrical potential. This is only useful in a time-dependent periodic run.
379 !% On by default if <tt>GaugeVectorField</tt> is set.
380 !%Option temperature 12
381 !% If set, the ionic temperature at each step is printed. On by default if <tt>MoveIons = yes</tt>.
382 !%Option ftchd 13
383 !% Write Fourier transform of the electron density to the file <tt>ftchd.X</tt>,
384 !% where X depends on the kick (e.g. with sin-shaped perturbation X=sin).
385 !% This is needed for calculating the dynamic structure factor.
386 !% In the case that the kick mode is qbessel, the written quantity is integral over
387 !% density, multiplied by spherical Bessel function times real spherical harmonic.
388 !% On by default if <tt>TDMomentumTransfer</tt> is set.
389 !%Option dipole_velocity 14
390 !% When set, outputs the dipole velocity, calculated from the Ehrenfest theorem,
391 !% in the file <tt>td.general/velocity</tt>. This file can then be
392 !% processed by the utility <tt>oct-harmonic-spectrum</tt> in order to obtain the harmonic spectrum.
393 !%Option eigenvalues 15
394 !% Write the KS eigenvalues.
395 !%Option ionization_channels 16
396 !% Write the multiple-ionization channels using the KS orbital densities as proposed in
397 !% C. Ullrich, Journal of Molecular Structure: THEOCHEM 501, 315 (2000).
398 !%Option total_current 17
399 !% Output the total current (integral of the current density over the cell).
400 !%Option partial_charges 18
401 !% Bader and Hirshfeld partial charges. The output file is called 'td.general/partial_charges'.
402 !%Option td_kpoint_occup 19
403 !% Project propagated Kohn-Sham states to the states at t=0 given in the directory
404 !% restart_proj (see %RestartOptions). This is an alternative to the option
405 !% td_occup, with a formating more suitable for k-points and works only in
406 !% k- and/or state parallelization
407 !%Option td_floquet 20
408 !% Compute non-interacting Floquet bandstructure according to further options:
409 !% TDFloquetFrequency, TDFloquetSample, TDFloquetDimension.
410 !% This is done only once per td-run at t=0.
411 !% works only in k- and/or state parallelization
412 !%Option n_excited_el 21
413 !% Output the number of excited electrons, based on the projections
414 !% of the time evolved wave-functions on the ground-state wave-functions.
415 !% The output interval of this quantity is controled by the variable <tt>TDOutputComputeInterval</tt>
416 !% Note that if one sets RecalculateGSDuringEvolution=yes,
417 !% the code will recompute the GS states
418 !% and use them for the computing the number of excited electrons.
419 !% This is useful if ions are moving or if one wants to get the number of excited electrons in the basis
420 !% of the instantaneous eigenvalues of the Hamiltonian (Houston states).
421 !%Option coordinates_sep 22
422 !% Writes geometries in a separate file.
423 !%Option velocities_sep 23
424 !% Writes velocities in a separate file.
425 !%Option forces_sep 24
426 !% Writes forces in a separate file.
427 !%Option total_heat_current 25
428 !% Output the total heat current (integral of the heat current density over the cell).
429 !%Option total_magnetization 26
430 !% Writes the total magnetization, where the total magnetization is calculated at the momentum
431 !% defined by <tt>TDMomentumTransfer</tt>.
432 !% This is used to extract the magnon frequency in case of a magnon kick.
433 !%Option photons_q 27
434 !% Writes photons_q in a separate file.
435 !%Option maxwell_field 28
436 !% Writes total electric field (if coupling is in length_geuge) or vector potential
437 !% (if coupling is in velocity_gauge) coming from the interaction with Maxwell systems
438 !% (only if Maxwell-TDDFT coupling is in dipole).
439 !%Option norm_ks_orbitals 29
440 !% Writes the norm of each Kohn-Sham orbital.
441 !% The data is ordered per row as:
442 !% Iteration time (state 1 kpoint 1) (state2 kpoint1) ... (state-Nstates kpoint1) (state1 kpoint2) ... (state-Nstates kpoint-nkpt)
443 !% noting that the kpoint index will also include the spin index for spin-polarised calculations.
444 !%Option cell_parameters 30
445 !% Writes the cell parameters (lattice parameter lengths, angles, Cartesian coordinates).
446 !%End
447
448 !defaults
449 output_options = .false.
450 output_options(out_multipoles) = .true.
451 output_options(out_energy) = .true.
452 if (ions_move) then
453 output_options(out_coords) = .true.
454 output_options(out_temperature) = .true.
455 end if
456 if (with_gauge_field) output_options(out_gauge_field) = .true.
457 if (list_has_lasers(ext_partners)) output_options(out_laser) = .true.
458 if (kick%qkick_mode /= qkickmode_none) output_options(out_ftchd) = .true.
459
460 call io_function_read_what_how_when(namespace, space, output_options, how, output_interval, &
461 'TDOutput')
462
463 ! Define which files to write
464 do iout = 1, out_max
465 writ%out(iout)%write = output_options(iout)
466 end do
467
468 ! experimental stuff
469 if (writ%out(out_spin)%write) call messages_experimental('TDOutput = spin', namespace=namespace)
470 if (writ%out(out_populations)%write) call messages_experimental('TDOutput = populations', namespace=namespace)
471 if (writ%out(out_proj)%write) call messages_experimental('TDOutput = td_occup', namespace=namespace)
472 if (writ%out(out_ion_ch)%write) call messages_experimental('TDOutput = ionization_channels', namespace=namespace)
473 if (writ%out(out_partial_charges)%write) call messages_experimental('TDOutput = partial_charges', namespace=namespace)
474 if (writ%out(out_kp_proj)%write) call messages_experimental('TDOutput = td_kpoint_occup', namespace=namespace)
475 if (writ%out(out_floquet)%write) call messages_experimental('TDOutput = td_floquet', namespace=namespace)
476 if (writ%out(out_n_ex)%write) call messages_experimental('TDOutput = n_excited_el', namespace=namespace)
477 if (writ%out(out_q)%write) call messages_experimental('TDOutput = photons_q', namespace=namespace)
478 if (writ%out(out_mxll_field)%write) call messages_experimental('TDOutput = maxwell_field', namespace=namespace)
479
480 if (space%is_periodic() .and. writ%out(out_angular)%write) then
481 call messages_not_implemented("TDOutput angular for periodic systems", namespace=namespace)
482 end if
483
484 if (writ%out(out_cell_parameters)%write .and. space%dim /= 3) then
485 call messages_not_implemented("TDOutput cell_parameters for Dimensions /= 3", namespace=namespace)
486 end if
487
488 !See comment in zstates_elec_mpdotp
489 if (space%is_periodic() .and. writ%out(out_populations)%write) then
490 call messages_not_implemented("TDOutput populations for periodic systems", namespace=namespace)
491 end if
492
493 if (writ%out(out_kp_proj)%write.or.writ%out(out_floquet)%write) then
494 ! make sure this is not domain distributed
495 if (gr%np /= gr%np_global) then
496 message(1) = "TDOutput option td_kpoint_occup and td_floquet do not work with domain parallelization"
497 call messages_fatal(1, namespace=namespace)
498 end if
499 end if
500
501 if ((writ%out(out_separate_forces)%write .or. writ%out(out_coords)%write) .and. space%periodic_dim == 1) then
502 call messages_input_error(namespace, 'TDOutput', &
503 'Forces for systems periodic in 1D are not currently implemented and options that output the forces are not allowed.')
504 end if
505
506 ! NTD: The implementation of the option should be really redone properly
507 if (writ%out(out_kp_proj)%write .and. hm%kpoints%nik_skip == 0) then
508 message(1) = "TDOutput option td_kpoint_occup only work with zero-weight k-points at the moment."
509 call messages_fatal(1, namespace=namespace)
510 end if
511
512 !%Variable TDOutputResolveStates
513 !%Type logical
514 !%Default No
515 !%Section Time-Dependent::TD Output
516 !%Description
517 !% Defines whether the output should be resolved by states.
518 !%
519 !% So far only TDOutput = multipoles is supported.
520 !%
521 !%End
522 call parse_variable(namespace, 'TDOutputResolveStates', .false., resolve_states)
523 if (.not. writ%out(out_multipoles)%write) then
524 write(message(1),'(a)') "TDOutputResolveStates works only for TDOutput = multipoles."
525 call messages_warning(1, namespace=namespace)
526 end if
527
528 !%Variable TDMultipoleLmax
529 !%Type integer
530 !%Default 1
531 !%Section Time-Dependent::TD Output
532 !%Description
533 !% Maximum electric multipole of the density output to the file <tt>td.general/multipoles</tt>
534 !% during a time-dependent simulation. Must be non-negative.
535 !%End
536 call parse_variable(namespace, 'TDMultipoleLmax', 1, writ%lmax)
537 if (writ%lmax < 0) then
538 write(message(1), '(a,i6,a)') "Input: '", writ%lmax, "' is not a valid TDMultipoleLmax."
539 message(2) = '(Must be TDMultipoleLmax >= 0 )'
540 call messages_fatal(2, namespace=namespace)
541 end if
542 call messages_obsolete_variable(namespace, 'TDDipoleLmax', 'TDMultipoleLmax')
543
544 ! Compatibility test
545 if ((writ%out(out_acc)%write) .and. ions_move) then
546 message(1) = 'If harmonic spectrum is to be calculated, atoms should not be allowed to move.'
547 call messages_fatal(1, namespace=namespace)
548 end if
549
550 if ((writ%out(out_q)%write) .and. .not.(ks%has_photons)) then
551 message(1) = 'If q(t) is to be calculated, you need to allow for photon modes.'
552 call messages_fatal(1, namespace=namespace)
553 end if
554
555 if ((writ%out(out_mxll_field)%write) .and. .not. (hm%mxll%coupling_mode == velocity_gauge_dipole &
556 .or. hm%mxll%add_electric_dip)) then
557 message(1) = 'If the dipolar field has to be written, MaxwellCouplingMode has to be'
558 message(2) = '"lenght_gauge_dipole" or "velocity_gauge_dipole" and at least one Maxwell system'
559 message(3) = 'must be present.'
560 call messages_fatal(3, namespace=namespace)
561 end if
562
563 rmin = ions%min_distance()
564
565 ! This variable is documented in scf/scf.F90
566 call parse_variable(namespace, 'LocalMagneticMomentsSphereRadius', min(m_half*rmin, lmm_r_single_atom), writ%lmm_r, &
567 unit=units_inp%length)
568
569 if (writ%out(out_proj)%write .or. writ%out(out_populations)%write &
570 .or.writ%out(out_kp_proj)%write .or. writ%out(out_n_ex)%write) then
571
572 if (st%parallel_in_states .and. writ%out(out_populations)%write) then
573 message(1) = "Option TDOutput = populations is not implemented for parallel in states."
574 call messages_fatal(1, namespace=namespace)
575 end if
576
577 if (writ%out(out_proj)%write .or. writ%out(out_populations)%write) then
578 call states_elec_copy(writ%gs_st, st, exclude_wfns = .true., exclude_eigenval = .true.)
579 else
580 ! we want the same layout of gs_st as st
581 call states_elec_copy(writ%gs_st, st, special=.true.)
582 end if
583
584 ! clean up all the stuff we have to reallocate
585 safe_deallocate_a(writ%gs_st%node)
586
587 call restart_init(restart_gs, namespace, restart_proj, restart_type_load, mc, ierr, mesh=gr)
588
589 if (writ%out(out_proj)%write .or. writ%out(out_populations)%write) then
590 if (ierr == 0) then
591 call states_elec_look(restart_gs, ii, jj, writ%gs_st%nst, ierr)
592 end if
593 writ%gs_st%st_end = writ%gs_st%nst
594 if (ierr /= 0) then
595 message(1) = "Unable to read states information."
596 call messages_fatal(1, namespace=namespace)
597 end if
598
599 writ%gs_st%st_start = 1
600 ! do this only when not calculating populations, since all states are needed then
601 if (.not. writ%out(out_populations)%write) then
602 ! We will store the ground-state Kohn-Sham system for all processors.
603 !%Variable TDProjStateStart
604 !%Type integer
605 !%Default 1
606 !%Section Time-Dependent::TD Output
607 !%Description
608 !% To be used with <tt>TDOutput = td_occup</tt>. Not available if <tt>TDOutput = populations</tt>.
609 !% Only output projections to states above <tt>TDProjStateStart</tt>. Usually one is only interested
610 !% in particle-hole projections around the HOMO, so there is no need to calculate (and store)
611 !% the projections of all TD states onto all static states. This sets a lower limit. The upper limit
612 !% is set by the number of states in the propagation and the number of unoccupied states
613 !% available.
614 !%End
615 call parse_variable(namespace, 'TDProjStateStart', 1, writ%gs_st%st_start)
616
617 if (st%parallel_in_states .and. writ%out(out_proj)%write .and. writ%gs_st%st_start > 1) then
618 call messages_not_implemented("TDOutput = td_occup for parallel in states with TDProjStateStart > 1", &
619 namespace=namespace)
620 end if
621 end if
622
623 writ%gs_st%lnst = writ%gs_st%st_end - writ%gs_st%st_start + 1
624
625 call states_elec_deallocate_wfns(writ%gs_st)
626
627 writ%gs_st%parallel_in_states = .false.
628
629 ! allocate memory
630 safe_allocate(writ%gs_st%occ(1:writ%gs_st%nst, 1:writ%gs_st%nik))
631 safe_allocate(writ%gs_st%eigenval(1:writ%gs_st%nst, 1:writ%gs_st%nik))
632
633 !We want all the task to have all the states
634 !States can be distibuted for the states we propagate.
635 safe_allocate(writ%gs_st%node(1:writ%gs_st%nst))
636 writ%gs_st%node(:) = 0
637
638 writ%gs_st%eigenval = huge(writ%gs_st%eigenval)
639 writ%gs_st%occ = m_zero
640 if (writ%gs_st%d%ispin == spinors) then
641 safe_deallocate_a(writ%gs_st%spin)
642 safe_allocate(writ%gs_st%spin(1:3, 1:writ%gs_st%nst, 1:writ%gs_st%nik))
643 end if
644
645 safe_allocate(skip(1:writ%gs_st%nst))
646 skip = .false.
647 skip(1:writ%gs_st%st_start-1) = .true.
648
649 call states_elec_allocate_wfns(writ%gs_st, gr, type_cmplx, packed=.true., skip=skip)
650
651 safe_deallocate_a(skip)
652 end if
653
654 call states_elec_load(restart_gs, namespace, space, writ%gs_st, gr, hm%kpoints, ierr, label = ': gs for TDOutput')
655
656 if (ierr /= 0 .and. ierr /= (writ%gs_st%st_end-writ%gs_st%st_start+1)*writ%gs_st%nik &
657 *writ%gs_st%d%dim*writ%gs_st%mpi_grp%size) then
658 message(1) = "Unable to read wavefunctions for TDOutput."
659 call messages_fatal(1, namespace=namespace)
660 end if
662 end if
663
664 ! Build the excited states...
665 if (writ%out(out_populations)%write) then
666 !%Variable TDExcitedStatesToProject
667 !%Type block
668 !%Section Time-Dependent::TD Output
669 !%Description
670 !% <b>[WARNING: This is a *very* experimental feature]</b>
671 !% To be used with <tt>TDOutput = populations</tt>.
672 !% The population of the excited states
673 !% (as defined by <Phi_I|Phi(t)> where |Phi(t)> is the many-body time-dependent state at
674 !% time <i>t</i>, and |Phi_I> is the excited state of interest) can be approximated -- it is not clear
675 !% how well -- by substituting for those real many-body states the time-dependent Kohn-Sham
676 !% determinant and some modification of the Kohn-Sham ground-state determinant (<i>e.g.</i>,
677 !% a simple HOMO-LUMO substitution, or the Casida ansatz for excited states in linear-response
678 !% theory. If you set <tt>TDOutput</tt> to contain <tt>populations</tt>, you may ask for these approximated
679 !% populations for a number of excited states, which will be described in the files specified
680 !% in this block: each line should be the name of a file that contains one excited state.
681 !%
682 !% This file structure is the one written by the casida run mode, in the files in the directory <tt>*_excitations</tt>.
683 !% The file describes the "promotions" from occupied
684 !% to unoccupied levels that change the initial Slater determinant
685 !% structure specified in ground_state. These promotions are a set
686 !% of electron-hole pairs. Each line in the file, after an optional header, has four
687 !% columns:
688 !%
689 !% <i>i a <math>\sigma</math> weight</i>
690 !%
691 !% where <i>i</i> should be an occupied state, <i>a</i> an unoccupied one, and <math>\sigma</math>
692 !% the spin of the corresponding orbital. This pair is then associated with a
693 !% creation-annihilation pair <math>a^{\dagger}_{a,\sigma} a_{i,\sigma}</math>, so that the
694 !% excited state will be a linear combination in the form:
695 !%
696 !% <math>\left|{\rm ExcitedState}\right> =
697 !% \sum weight(i,a,\sigma) a^{\dagger}_{a,\sigma} a_{i,\sigma} \left|{\rm GroundState}\right></math>
698 !%
699 !% where <i>weight</i> is the number in the fourth column.
700 !% These weights should be normalized to one; otherwise the routine
701 !% will normalize them, and write a warning.
702 !%End
703 if (parse_block(namespace, 'TDExcitedStatesToProject', blk) == 0) then
704 writ%n_excited_states = parse_block_n(blk)
705 safe_allocate(writ%excited_st(1:writ%n_excited_states))
706 do ist = 1, writ%n_excited_states
707 call parse_block_string(blk, ist-1, 0, filename)
708 call excited_states_init(writ%excited_st(ist), writ%gs_st, trim(filename), namespace)
709 end do
710 else
711 writ%n_excited_states = 0
712 end if
713 end if
714
715 !%Variable TDOutputComputeInterval
716 !%Type integer
717 !%Default 50
718 !%Section Time-Dependent::TD Output
719 !%Description
720 !% The TD output requested are computed
721 !% when the iteration number is a multiple of the <tt>TDOutputComputeInterval</tt> variable.
722 !% Must be >= 0. If it is 0, then no output is written.
723 !% Implemented only for projections and number of excited electrons for the moment.
724 !%End
725 call parse_variable(namespace, 'TDOutputComputeInterval', 50, writ%compute_interval)
726 if (writ%compute_interval < 0) then
727 message(1) = "TDOutputComputeInterval must be >= 0."
728 call messages_fatal(1, namespace=namespace)
729 end if
730
731 ! ----------------------------------------------
732 ! Initialize write file handlers
733 ! ----------------------------------------------
734
735 ! Step
736 if (iter == 0) then
737 first = 0
738 else
739 first = iter + 1
740 end if
741
742 ! Root dir for TD files
743 call io_mkdir('td.general', namespace)
744
745 ! ----------------------------------------------
746 ! Initialize write that are MPI agnostic
747 ! ----------------------------------------------
748
749 ! Default
750 writ%out(:)%mpi_grp = mpi_world
751
752 if (mpi_grp_is_root(mpi_world)) then
753
754 do ifile = 1, out_max
755 ! Exceptions that are handled later
756 if (any([out_multipoles, out_laser, out_ftchd] == ifile)) cycle
757
758 if (writ%out(ifile)%write) then
759 call write_iter_init(writ%out(ifile)%handle, &
760 first, &
761 units_from_atomic(units_out%time, dt), &
762 trim(io_workpath("td.general/"//trim(td_file_name(ifile)), namespace)))
763 end if
764
765 enddo
766
767 ! Exceptions
768
769 ! Multipoles, when MPI is not state-parallel
770 if (writ%out(out_multipoles)%write .and. .not. resolve_states) then
771 call write_iter_init(writ%out(out_multipoles)%handle, &
772 first, units_from_atomic(units_out%time, dt), &
773 trim(io_workpath("td.general/multipoles", namespace)))
774 end if
775
776 if (writ%out(out_ftchd)%write) then
777 select case (kick%qkick_mode)
778 case (qkickmode_sin)
779 write(filename, '(a)') 'td.general/ftchd.sin'
780 case (qkickmode_cos)
781 write(filename, '(a)') 'td.general/ftchd.cos'
782 case (qkickmode_bessel)
783 write(filename, '(a, SP, I0.3, a, I0.3)') 'td.general/ftchd.l', kick%qbessel_l, '_m', kick%qbessel_m
784 case default
785 write(filename, '(a)') 'td.general/ftchd'
786 end select
787 call write_iter_init(writ%out(out_ftchd)%handle, &
788 first, units_from_atomic(units_out%time, dt), trim(io_workpath(filename, namespace)))
789 end if
790
791 if (writ%out(out_laser)%write) then
792 if(associated(list_get_lasers(ext_partners))) then
793 ! The laser file is written for the full propagation in one go, so that
794 ! the user can check that the laser is correct and as intended before letting
795 ! the code run for a possibly large period of time. This is done even after
796 ! a restart, so that it takes into account any changes to max_iter.
797 call io_rm("td.general/laser", namespace=namespace)
798 call write_iter_init(writ%out(out_laser)%handle, 0, &
799 units_from_atomic(units_out%time, dt), &
800 trim(io_workpath("td.general/laser", namespace)))
801 do ii = 0, max_iter
802 call td_write_laser(writ%out(out_laser)%handle, space, list_get_lasers(ext_partners), dt, ii)
803 end do
804 call write_iter_end(writ%out(out_laser)%handle)
805 end if
806 end if
807
808 end if ! mpi_grp_is_root(mpi_world)
809
810 ! ----------------------------------------------
811 ! Initialize write that are MPI group-specific
812 ! ----------------------------------------------
813
814 if (writ%out(out_multipoles)%write .and. resolve_states) then
815 !resolve state contribution on multipoles
816 writ%out(out_multipoles)%hand_start = st%st_start
817 writ%out(out_multipoles)%hand_end = st%st_end
818 writ%out(out_multipoles)%resolve_states = .true.
819 writ%out(out_multipoles)%mpi_grp = gr%mpi_grp
820
821 safe_allocate(writ%out(out_multipoles)%mult_handles(st%st_start:st%st_end))
822
823 if (mpi_grp_is_root(writ%out(out_multipoles)%mpi_grp)) then
824 do ist = st%st_start, st%st_end
825 write(filename, '(a,i4.4)') 'td.general/multipoles-ist', ist
826 call write_iter_init(writ%out(out_multipoles)%mult_handles(ist), &
827 first, units_from_atomic(units_out%time, dt), &
828 trim(io_workpath(filename, namespace)))
829 end do
830 end if
831 end if
832
833 ! Misc operations
834
835 if (writ%out(out_total_current)%write .or. writ%out(out_total_heat_current)%write) then
836 !TODO: we should only compute the current here, not v_ks
837 call v_ks_calculate_current(ks, .true.)
838 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
839 calc_eigenval=.false., time = iter*dt, calc_energy = .false.)
840 end if
841
842 if (writ%out(out_n_ex)%write .and. writ%compute_interval > 0) then
843 call io_mkdir(outp%iter_dir, namespace)
844 end if
845
846 if (all(outp%how == 0) .and. writ%out(out_n_ex)%write) then
847 call io_function_read_what_how_when(namespace, space, outp%what, outp%how, outp%output_interval)
848 end if
849
850 ! --------------------------------------------------------
851 ! All steps of the above routine, but specific to DFT+U
852 ! --------------------------------------------------------
853
854 !%Variable TDOutputDFTU
855 !%Type flag
856 !%Default none
857 !%Section Time-Dependent::TD Output
858 !%Description
859 !% Defines what should be output during the time-dependent
860 !% simulation, related to DFT+U.
861 !%
862 !% Note: the output files generated by this option are updated
863 !% every <tt>RestartWriteInterval</tt> steps.
864 !%Option effective_u 1
865 !% Writes the effective U for each orbital set as a function of time.
866 !%End
867 default = 0
868 if (hm%lda_u_level == dft_u_acbn0) default = default + 2**(out_dftu_effective_u - 1)
869 call parse_variable(namespace, 'TDOutputDFTU', default, flags)
870
871 if (.not. varinfo_valid_option('TDOutputDFTU', flags, is_flag = .true.)) then
872 call messages_input_error(namespace, 'TDOutputDFTU')
873 end if
874
875 do iout = 1, out_dftu_max
876 writ%out_dftu(iout)%write = (iand(flags, 2**(iout - 1)) /= 0)
877 end do
878
879 if (mpi_grp_is_root(mpi_world)) then
880 if (writ%out_dftu(out_dftu_effective_u)%write) then
881 call write_iter_init(writ%out_dftu(out_dftu_effective_u)%handle, &
882 first, units_from_atomic(units_out%time, dt), &
883 trim(io_workpath("td.general/effectiveU", namespace)))
884 end if
885 end if
886
887 pop_sub(td_write_init)
888 end subroutine td_write_init
889
890
891 ! ---------------------------------------------------------
892 subroutine td_write_end(writ)
893 type(td_write_t), intent(inout) :: writ
894
895 integer :: ist, iout
896
897 push_sub(td_write_end)
898
899 do iout = 1, out_max
900 if (iout == out_laser) cycle
901 if (writ%out(iout)%write) then
902 if (mpi_grp_is_root(writ%out(iout)%mpi_grp)) then
903 if (writ%out(iout)%resolve_states) then
904 do ist = writ%out(iout)%hand_start, writ%out(iout)%hand_end
905 call write_iter_end(writ%out(iout)%mult_handles(ist))
906 end do
907 safe_deallocate_a(writ%out(iout)%mult_handles)
908 else
909 call write_iter_end(writ%out(iout)%handle)
910 end if
911 end if
912 end if
913 end do
914
915 if (mpi_grp_is_root(mpi_world)) then
916 do iout = 1, out_dftu_max
917 if (writ%out_dftu(iout)%write) call write_iter_end(writ%out_dftu(iout)%handle)
918 end do
919
920 end if
921
922 if (writ%out(out_populations)%write) then
923 do ist = 1, writ%n_excited_states
924 call excited_states_kill(writ%excited_st(ist))
925 end do
926 writ%n_excited_states = 0
927 end if
928
929 if (writ%out(out_proj)%write .or. writ%out(out_populations)%write &
930 .or. writ%out(out_n_ex)%write .or. writ%out(out_kp_proj)%write) then
931 call states_elec_end(writ%gs_st)
932 end if
933
934 pop_sub(td_write_end)
935 end subroutine td_write_end
936
937
938 ! ---------------------------------------------------------
939 subroutine td_write_iter(writ, namespace, space, outp, gr, st, hm, ions, ext_partners, kick, ks, dt, iter, mc, recalculate_gs)
940 type(td_write_t), intent(inout) :: writ
941 type(namespace_t), intent(in) :: namespace
942 class(space_t), intent(in) :: space
943 type(output_t), intent(in) :: outp
944 type(grid_t), intent(in) :: gr
945 type(states_elec_t), intent(inout) :: st
946 type(hamiltonian_elec_t), intent(inout) :: hm
947 type(ions_t), intent(inout) :: ions
948 type(partner_list_t), intent(in) :: ext_partners
949 type(kick_t), intent(in) :: kick
950 type(v_ks_t), intent(in) :: ks
951 real(real64), intent(in) :: dt
952 integer, intent(in) :: iter
953 type(multicomm_t), intent(in) :: mc
954 logical, intent(in) :: recalculate_gs
955
956 type(gauge_field_t), pointer :: gfield
957 integer :: ierr
958 type(restart_t) :: restart_gs
959
960 push_sub_with_profile(td_write_iter)
961
962 if (writ%out(out_multipoles)%write) then
963 call td_write_multipole(writ%out(out_multipoles), space, gr, ions, st, writ%lmax, kick, iter)
964 end if
965
966 if (writ%out(out_ftchd)%write) then
967 call td_write_ftchd(writ%out(out_ftchd)%handle, space, gr, st, kick, iter)
968 end if
969
970 if (writ%out(out_angular)%write) then
971 call td_write_angular(writ%out(out_angular)%handle, namespace, space, gr, ions, hm, st, kick, iter)
972 end if
973
974 if (writ%out(out_spin)%write) then
975 call td_write_spin(writ%out(out_spin)%handle, gr, st, iter)
976 end if
977
978 if (writ%out(out_magnets)%write) then
979 call td_write_local_magnetic_moments(writ%out(out_magnets)%handle, gr, st, ions, writ%lmm_r, iter)
980 end if
981
982 if (writ%out(out_tot_m)%write) then
983 call td_write_tot_mag(writ%out(out_tot_m)%handle, gr, st, kick, iter)
984 end if
986 if (writ%out(out_proj)%write .and. mod(iter, writ%compute_interval) == 0) then
987 if (mpi_grp_is_root(mpi_world)) call write_iter_set(writ%out(out_proj)%handle, iter)
988 call td_write_proj(writ%out(out_proj)%handle, space, gr, ions, st, writ%gs_st, kick, iter)
989 end if
990
991 if (writ%out(out_floquet)%write) then
992 call td_write_floquet(namespace, space, hm, ext_partners, gr, st, iter)
993 end if
994
995 if (writ%out(out_kp_proj)%write .and. mod(iter, writ%compute_interval) == 0) then
996 call td_write_proj_kp(gr, hm%kpoints, st, writ%gs_st, namespace, iter)
997 end if
998
999 if (writ%out(out_coords)%write) then
1000 call td_write_coordinates(writ%out(out_coords)%handle, ions%natoms, ions%space, &
1001 ions%pos, ions%vel, ions%tot_force, iter)
1002 end if
1003
1004 if (writ%out(out_separate_coords)%write) then
1005 call td_write_sep_coordinates(writ%out(out_separate_coords)%handle, ions%natoms, ions%space, &
1006 ions%pos, ions%vel, ions%tot_force, iter, 1)
1007 end if
1008
1009 if (writ%out(out_separate_velocity)%write) then
1010 call td_write_sep_coordinates(writ%out(out_separate_velocity)%handle, ions%natoms, ions%space, &
1011 ions%pos, ions%vel, ions%tot_force, iter, 2)
1012 end if
1013
1014 if (writ%out(out_separate_forces)%write) then
1015 call td_write_sep_coordinates(writ%out(out_separate_forces)%handle, ions%natoms, ions%space, &
1016 ions%pos, ions%vel, ions%tot_force, iter, 3)
1017 end if
1018
1019 if (writ%out(out_temperature)%write) then
1020 call td_write_temperature(writ%out(out_temperature)%handle, ions, iter)
1021 end if
1022
1023 if (writ%out(out_populations)%write) then
1024 call td_write_populations(writ%out(out_populations)%handle, namespace, space, gr, st, writ, dt, iter)
1025 end if
1026
1027 if (writ%out(out_acc)%write) then
1028 call td_write_acc(writ%out(out_acc)%handle, namespace, space, gr, ions, st, hm, ext_partners, dt, iter)
1029 end if
1030
1031 if (writ%out(out_vel)%write) then
1032 call td_write_vel(writ%out(out_vel)%handle, gr, st, space, hm%kpoints, iter)
1033 end if
1034
1035 ! td_write_laser no longer called here, because the whole laser is printed
1036 ! out at the beginning.
1037
1038 if (writ%out(out_energy)%write) then
1039 call td_write_energy(writ%out(out_energy)%handle, hm, iter, ions%kinetic_energy)
1040 end if
1041
1042 if (writ%out(out_gauge_field)%write) then
1043 gfield => list_get_gauge_field(ext_partners)
1044 if(associated(gfield)) then
1045 call gauge_field_output_write(gfield, writ%out(out_gauge_field)%handle, iter)
1046 end if
1047 end if
1048
1049 if (writ%out(out_eigs)%write) then
1050 call td_write_eigs(writ%out(out_eigs)%handle, st, iter)
1051 end if
1052
1053 if (writ%out(out_ion_ch)%write) then
1054 call td_write_ionch(writ%out(out_ion_ch)%handle, gr, st, iter)
1055 end if
1056
1057 if (writ%out(out_total_current)%write) then
1058 call td_write_total_current(writ%out(out_total_current)%handle, space, gr, st, iter)
1059 end if
1060
1061 if (writ%out(out_total_heat_current)%write) then
1062 call td_write_total_heat_current(writ%out(out_total_heat_current)%handle, space, hm, gr, st, iter)
1063 end if
1064
1065 if (writ%out(out_partial_charges)%write) then
1066 call td_write_partial_charges(writ%out(out_partial_charges)%handle, gr, st, &
1067 ions, iter)
1068 end if
1069
1070 if (writ%out(out_n_ex)%write .and. mod(iter, writ%compute_interval) == 0) then
1071 if (mpi_grp_is_root(mpi_world)) call write_iter_set(writ%out(out_n_ex)%handle, iter)
1072 if (recalculate_gs) then ! Load recomputed GS states
1073 call restart_init(restart_gs, namespace, restart_proj, restart_type_load, mc, ierr, mesh=gr)
1074 call states_elec_load(restart_gs, namespace, space, writ%gs_st, gr, hm%kpoints, &
1075 ierr, label = ': Houston states for TDOutput')
1077 end if
1078
1079 call td_write_n_ex(writ%out(out_n_ex)%handle, outp, namespace, gr, hm%kpoints, st, writ%gs_st, iter)
1080 end if
1081
1082 if (writ%out(out_norm_ks)%write) then
1083 call td_write_norm_ks_orbitals(writ%out(out_norm_ks)%handle, gr, hm%kpoints, st, iter)
1084 end if
1085
1086 if (writ%out(out_cell_parameters)%write) then
1087 call td_write_cell_parameters(writ%out(out_cell_parameters)%handle, ions, iter)
1088 end if
1089
1090 !DFT+U outputs
1091 if (writ%out_dftu(out_dftu_effective_u)%write) then
1092 call td_write_effective_u(writ%out_dftu(out_dftu_effective_u)%handle, hm%lda_u, iter)
1093 end if
1094
1095 if (writ%out(out_q)%write .and. ks%has_photons) then
1096 call td_write_q(writ%out(out_q)%handle, space, ks, iter)
1097 end if
1098
1099 if (writ%out(out_mxll_field)%write .and. hm%mxll%calc_field_dip) then
1100 call td_write_mxll_field(writ%out(out_mxll_field)%handle, space, hm, dt, iter)
1101 end if
1102
1103 pop_sub_with_profile(td_write_iter)
1104 end subroutine td_write_iter
1105
1106
1107 ! ---------------------------------------------------------
1108 subroutine td_write_data(writ)
1109 type(td_write_t), intent(inout) :: writ
1110
1111 integer :: iout, ii
1112
1113 push_sub(td_write_data)
1114 call profiling_in("TD_WRITE_DATA")
1115
1116 do iout = 1, out_max
1117 if (iout == out_laser) cycle
1118 if (writ%out(iout)%write) then
1119 if (mpi_grp_is_root(writ%out(iout)%mpi_grp)) then
1120 if (writ%out(iout)%resolve_states) then
1121 do ii = writ%out(iout)%hand_start, writ%out(iout)%hand_end
1122 call write_iter_flush(writ%out(iout)%mult_handles(ii))
1123 end do
1124 else
1125 call write_iter_flush(writ%out(iout)%handle)
1126 end if
1127 end if
1128 end if
1129 end do
1130
1131 if (mpi_grp_is_root(mpi_world)) then
1132 do iout = 1, out_dftu_max
1133 if (writ%out_dftu(iout)%write) call write_iter_flush(writ%out_dftu(iout)%handle)
1134 end do
1135 end if
1136
1137 call profiling_out("TD_WRITE_DATA")
1138 pop_sub(td_write_data)
1139 end subroutine td_write_data
1140
1141 ! ---------------------------------------------------------
1142 subroutine td_write_output(namespace, space, gr, st, hm, ks, outp, ions, ext_partners, iter, dt)
1143 type(namespace_t), intent(in) :: namespace
1144 type(electron_space_t), intent(in) :: space
1145 type(grid_t), intent(in) :: gr
1146 type(states_elec_t), intent(inout) :: st
1147 type(hamiltonian_elec_t), intent(inout) :: hm
1148 type(v_ks_t), intent(inout) :: ks
1149 type(output_t), intent(in) :: outp
1150 type(ions_t), intent(in) :: ions
1151 type(partner_list_t), intent(in) :: ext_partners
1152 integer, intent(in) :: iter
1153 real(real64), optional, intent(in) :: dt
1154
1155 character(len=256) :: filename
1156
1157 push_sub(td_write_output)
1158 call profiling_in("TD_WRITE_OUTPUT")
1159
1160 ! TODO this now overwrites wf inside st. If this is not wanted need to add an optional overwrite=no flag
1161 if (st%modelmbparticles%nparticle > 0) then
1162 call modelmb_sym_all_states(space, gr, st)
1163 end if
1164
1165 ! now write down the rest
1166 write(filename, '(a,a,i7.7)') trim(outp%iter_dir),"td.", iter ! name of directory
1167
1168 call output_all(outp, namespace, space, filename, gr, ions, iter, st, hm, ks)
1169
1170 call output_modelmb(outp, namespace, space, filename, gr, ions, iter, st)
1171
1172 if (present(dt)) then
1173 call output_scalar_pot(outp, namespace, space, filename, gr, ions, ext_partners, iter*dt)
1174 else
1175 if (iter == 0) call output_scalar_pot(outp, namespace, space, filename, gr, ions, ext_partners)
1176 end if
1177
1178 call profiling_out("TD_WRITE_OUTPUT")
1179 pop_sub(td_write_output)
1180 end subroutine td_write_output
1181
1182 ! ---------------------------------------------------------
1183 subroutine td_write_spin(out_spin, mesh, st, iter)
1184 type(c_ptr), intent(inout) :: out_spin
1185 class(mesh_t), intent(in) :: mesh
1186 type(states_elec_t), intent(in) :: st
1187 integer, intent(in) :: iter
1188
1189 character(len=130) :: aux
1190 real(real64) :: spin(3)
1191
1192 push_sub(td_write_spin)
1193
1194 ! The expectation value of the spin operator is half the total magnetic moment
1195 ! This has to be calculated by all nodes
1196 call magnetic_moment(mesh, st, st%rho, spin)
1197 spin = m_half*spin
1198
1199 if (mpi_grp_is_root(mpi_world)) then ! only first node outputs
1200
1201 if (iter == 0) then
1203
1204 !second line -> columns name
1206 if (st%d%ispin == spinors) then
1207 write(aux, '(a2,18x)') 'Sx'
1208 call write_iter_header(out_spin, aux)
1209 write(aux, '(a2,18x)') 'Sy'
1210 call write_iter_header(out_spin, aux)
1211 end if
1212 write(aux, '(a2,18x)') 'Sz'
1213 call write_iter_header(out_spin, aux)
1215
1217 end if
1218
1220 select case (st%d%ispin)
1221 case (spin_polarized)
1222 call write_iter_double(out_spin, spin(3), 1)
1223 case (spinors)
1224 call write_iter_double(out_spin, spin(1:3), 3)
1225 end select
1227
1228 end if
1229
1230 pop_sub(td_write_spin)
1231 end subroutine td_write_spin
1232
1233
1234 ! ---------------------------------------------------------
1235 subroutine td_write_local_magnetic_moments(out_magnets, gr, st, ions, lmm_r, iter)
1236 type(c_ptr), intent(inout) :: out_magnets
1237 type(grid_t), intent(in) :: gr
1238 type(states_elec_t), intent(in) :: st
1239 type(ions_t), intent(in) :: ions
1240 real(real64), intent(in) :: lmm_r
1241 integer, intent(in) :: iter
1242
1243 integer :: ia
1244 character(len=50) :: aux
1245 real(real64), allocatable :: lmm(:,:)
1246
1248
1249 !get the atoms` magnetization. This has to be calculated by all nodes
1250 safe_allocate(lmm(1:3, 1:ions%natoms))
1251 call magnetic_local_moments(gr, st, ions, gr%der%boundaries, st%rho, lmm_r, lmm)
1252
1253 if (mpi_grp_is_root(mpi_world)) then ! only first node outputs
1254
1255 if (iter == 0) then
1257
1258 !second line -> columns name
1260 do ia = 1, ions%natoms
1261 if (st%d%ispin == spinors) then
1262 write(aux, '(a2,i2.2,16x)') 'mx', ia
1264 write(aux, '(a2,i2.2,16x)') 'my', ia
1266 end if
1267 write(aux, '(a2,i2.2,16x)') 'mz', ia
1269 end do
1271
1273 end if
1274
1276 do ia = 1, ions%natoms
1277 select case (st%d%ispin)
1278 case (spin_polarized)
1279 call write_iter_double(out_magnets, lmm(3, ia), 1)
1280 case (spinors)
1281 call write_iter_double(out_magnets, lmm(1:3, ia), 3)
1282 end select
1283 end do
1285 safe_deallocate_a(lmm)
1286 end if
1287
1289 end subroutine td_write_local_magnetic_moments
1290
1291 ! ---------------------------------------------------------
1292 subroutine td_write_tot_mag(out_magnets, mesh, st, kick, iter)
1293 type(c_ptr), intent(inout) :: out_magnets
1294 class(mesh_t), intent(in) :: mesh
1295 type(states_elec_t), intent(in) :: st
1296 type(kick_t), intent(in) :: kick
1297 integer, intent(in) :: iter
1298
1299 complex(real64), allocatable :: tm(:,:)
1300 integer :: ii, iq
1301
1302 push_sub(td_write_tot_mag)
1303
1304 safe_allocate(tm(1:6,1:kick%nqvec))
1305
1306 do iq = 1, kick%nqvec
1307 call magnetic_total_magnetization(mesh, st, kick%qvector(:,iq), tm(1:6,iq))
1308 end do
1309
1310 if (mpi_grp_is_root(mpi_world)) then ! only first node outputs
1311
1312 if (iter == 0) then
1313 call td_write_print_header_init(out_magnets)
1314 call kick_write(kick, out = out_magnets)
1315
1316 !second line -> columns name
1317 call write_iter_header_start(out_magnets)
1318 call write_iter_header(out_magnets, 'Re[m_x(q)]')
1319 call write_iter_header(out_magnets, 'Im[m_x(q)]')
1320 call write_iter_header(out_magnets, 'Re[m_y(q)]')
1321 call write_iter_header(out_magnets, 'Im[m_y(q)]')
1322 call write_iter_header(out_magnets, 'Re[m_z(q)]')
1323 call write_iter_header(out_magnets, 'Im[m_z(q)]')
1324 call write_iter_header(out_magnets, 'Re[m_x(-q)]')
1325 call write_iter_header(out_magnets, 'Im[m_x(-q)]')
1326 call write_iter_header(out_magnets, 'Re[m_y(-q)]')
1327 call write_iter_header(out_magnets, 'Im[m_y(-q)]')
1328 call write_iter_header(out_magnets, 'Re[m_z(-q)]')
1329 call write_iter_header(out_magnets, 'Im[m_z(-q)]')
1330 call write_iter_nl(out_magnets)
1331
1332 call td_write_print_header_end(out_magnets)
1333 end if
1334
1335 call write_iter_start(out_magnets)
1336 do iq = 1, kick%nqvec
1337 do ii = 1, 6
1338 call write_iter_double(out_magnets, real(tm(ii, iq), real64), 1)
1339 call write_iter_double(out_magnets, aimag(tm(ii, iq)), 1)
1340 end do
1341 end do
1342 call write_iter_nl(out_magnets)
1343 end if
1344
1345 safe_deallocate_a(tm)
1346
1347 pop_sub(td_write_tot_mag)
1348 end subroutine td_write_tot_mag
1349
1350
1351 ! ---------------------------------------------------------
1359 subroutine td_write_angular(out_angular, namespace, space, gr, ions, hm, st, kick, iter)
1360 type(c_ptr), intent(inout) :: out_angular
1361 type(namespace_t), intent(in) :: namespace
1362 class(space_t), intent(in) :: space
1363 type(grid_t), intent(in) :: gr
1364 type(ions_t), intent(inout) :: ions
1365 type(hamiltonian_elec_t), intent(inout) :: hm
1366 type(states_elec_t), intent(inout) :: st
1367 type(kick_t), intent(in) :: kick
1368 integer, intent(in) :: iter
1369
1370 integer :: idir
1371 character(len=130) :: aux
1372 real(real64) :: angular(3)
1373 class(perturbation_magnetic_t), pointer :: angular_momentum
1374
1375 push_sub(td_write_angular)
1376
1377 angular_momentum => perturbation_magnetic_t(namespace, ions)
1378 do idir = 1, 3
1379 call angular_momentum%setup_dir(idir)
1380 !we have to multiply by 2, because the perturbation returns L/2
1381 angular(idir) = &
1382 m_two*real(angular_momentum%zstates_elec_expectation_value(namespace, space, gr, hm, st), real64)
1383 end do
1384 safe_deallocate_p(angular_momentum)
1386 if (mpi_grp_is_root(mpi_world)) then ! Only first node outputs
1387
1388 if (iter == 0) then
1389 call td_write_print_header_init(out_angular)
1390
1391 write(aux, '(a15,i2)') '# nspin ', st%d%nspin
1392 call write_iter_string(out_angular, aux)
1393 call write_iter_nl(out_angular)
1394
1395 call kick_write(kick, out = out_angular)
1396
1397 !second line -> columns name
1398 call write_iter_header_start(out_angular)
1399 write(aux, '(a4,18x)') '<Lx>'
1400 call write_iter_header(out_angular, aux)
1401 write(aux, '(a4,18x)') '<Ly>'
1402 call write_iter_header(out_angular, aux)
1403 write(aux, '(a4,18x)') '<Lz>'
1404 call write_iter_header(out_angular, aux)
1405 call write_iter_nl(out_angular)
1406
1407 !third line -> should hold the units.
1408 call write_iter_string(out_angular, '#[Iter n.]')
1409 call write_iter_header(out_angular, '[' // trim(units_abbrev(units_out%time)) // ']')
1410 call write_iter_header(out_angular, '[hbar]')
1411 call write_iter_header(out_angular, '[hbar]')
1412 call write_iter_header(out_angular, '[hbar]')
1413 call write_iter_nl(out_angular)
1414
1415 call td_write_print_header_end(out_angular)
1416 end if
1417
1418 call write_iter_start(out_angular)
1419 call write_iter_double(out_angular, angular(1:3), 3)
1420 call write_iter_nl(out_angular)
1421
1422 end if
1423
1424 pop_sub(td_write_angular)
1425 end subroutine td_write_angular
1426
1427
1430 subroutine td_write_multipole(out_multip, space, gr, ions, st, lmax, kick, iter)
1431 type(td_write_prop_t), intent(inout) :: out_multip
1432 class(space_t), intent(in) :: space
1433 type(grid_t), intent(in) :: gr
1434 type(ions_t), intent(in) :: ions
1435 type(states_elec_t), intent(in) :: st
1436 integer, intent(in) :: lmax
1437 type(kick_t), intent(in) :: kick
1438 integer, intent(in) :: iter
1439
1440 integer :: ist
1441 real(real64), allocatable :: rho(:,:)
1442
1443 push_sub(td_write_multipole)
1444
1445 if (out_multip%resolve_states) then
1446 safe_allocate(rho(1:gr%np_part, 1:st%d%nspin))
1447 rho(:,:) = m_zero
1448
1449 do ist = st%st_start, st%st_end
1450 call density_calc(st, gr, rho, istin = ist)
1451 call td_write_multipole_r(out_multip%mult_handles(ist), space, gr, ions, st, lmax, kick, rho, iter, &
1452 mpi_grp = out_multip%mpi_grp)
1453 end do
1454
1455 safe_deallocate_a(rho)
1456
1457 else
1458 if (allocated(st%frozen_rho)) then
1459 safe_allocate(rho(1:gr%np, 1:st%d%nspin))
1460 call lalg_copy(gr%np, st%d%nspin, st%rho, rho)
1461 call lalg_axpy(gr%np, st%d%nspin, m_one, st%frozen_rho, rho)
1462
1463 call td_write_multipole_r(out_multip%handle, space, gr, ions, st, lmax, kick, rho, iter)
1464
1465 safe_deallocate_a(rho)
1466 else
1467 call td_write_multipole_r(out_multip%handle, space, gr, ions, st, lmax, kick, st%rho, iter)
1468 end if
1469
1470 end if
1471
1472 pop_sub(td_write_multipole)
1473 end subroutine td_write_multipole
1474
1475
1477 subroutine td_write_multipole_r(out_multip, space, mesh, ions, st, lmax, kick, rho, iter, mpi_grp)
1478 type(c_ptr), intent(inout) :: out_multip
1479 class(space_t), intent(in) :: space
1480 class(mesh_t), intent(in) :: mesh
1481 type(ions_t), intent(in) :: ions
1482 type(states_elec_t), intent(in) :: st
1483 integer, intent(in) :: lmax
1484 type(kick_t), intent(in) :: kick
1485 real(real64), intent(in) :: rho(:,:)
1486 integer, intent(in) :: iter
1487 type(mpi_grp_t), optional, intent(in) :: mpi_grp
1488
1489
1490 integer :: is, idir, ll, mm, add_lm
1491 character(len=120) :: aux
1492 real(real64) :: ionic_dipole(ions%space%dim)
1493 real(real64), allocatable :: multipole(:,:)
1494 type(mpi_grp_t) :: mpi_grp_
1495
1496 push_sub(td_write_multipole_r)
1497
1498 ! We cannot output multipoles beyond the dipole for higher dimensions
1499 assert(.not. (lmax > 1 .and. space%dim > 3))
1500
1501 mpi_grp_ = mpi_world
1502 if (present(mpi_grp)) mpi_grp_ = mpi_grp
1503
1504 if (mpi_grp_is_root(mpi_grp_).and.iter == 0) then
1505 call td_write_print_header_init(out_multip)
1506
1507 write(aux, '(a15,i2)') '# nspin ', st%d%nspin
1508 call write_iter_string(out_multip, aux)
1509 call write_iter_nl(out_multip)
1510
1511 write(aux, '(a15,i2)') '# lmax ', lmax
1512 call write_iter_string(out_multip, aux)
1513 call write_iter_nl(out_multip)
1514
1515 call kick_write(kick, out = out_multip)
1516
1517 call write_iter_header_start(out_multip)
1518
1519 do is = 1, st%d%nspin
1520 write(aux,'(a18,i1,a1)') 'Electronic charge(', is,')'
1521 call write_iter_header(out_multip, aux)
1522 if (lmax > 0) then
1523 do idir = 1, space%dim
1524 write(aux, '(4a1,i1,a1)') '<', index2axis(idir), '>', '(', is,')'
1525 call write_iter_header(out_multip, aux)
1526 end do
1527 end if
1528 do ll = 2, lmax
1529 do mm = -ll, ll
1530 write(aux, '(a2,i2,a4,i2,a2,i1,a1)') 'l=', ll, ', m=', mm, ' (', is,')'
1531 call write_iter_header(out_multip, aux)
1532 end do
1533 end do
1534 end do
1535 call write_iter_nl(out_multip)
1536
1537 ! units
1538 call write_iter_string(out_multip, '#[Iter n.]')
1539 call write_iter_header(out_multip, '[' // trim(units_abbrev(units_out%time)) // ']')
1540
1541 do is = 1, st%d%nspin
1542 call write_iter_header(out_multip, 'Electrons')
1543 if (lmax > 0) then
1544 do idir = 1, space%dim
1545 call write_iter_header(out_multip, '[' // trim(units_abbrev(units_out%length)) // ']')
1546 end do
1547 end if
1548 do ll = 2, lmax
1549 do mm = -ll, ll
1550 write(aux, '(a,a2,i1)') trim(units_abbrev(units_out%length)), "**", ll
1551 call write_iter_header(out_multip, '[' // trim(aux) // ']')
1552 end do
1553 end do
1554 end do
1555 call write_iter_nl(out_multip)
1556
1557 call td_write_print_header_end(out_multip)
1558 end if
1559
1560 if (space%dim > 3 .and. lmax == 1) then
1561 ! For higher dimensions we can only have up to the dipole
1562 safe_allocate(multipole(1:space%dim+1, 1:st%d%nspin))
1563 else
1564 safe_allocate(multipole(1:(lmax + 1)**2, 1:st%d%nspin))
1565 end if
1566 multipole(:,:) = m_zero
1567
1568 do is = 1, st%d%nspin
1569 call dmf_multipoles(mesh, rho(:,is), lmax, multipole(:,is))
1570 end do
1571
1572 if (lmax > 0) then
1573 ionic_dipole = ions%dipole()
1574 do is = 1, st%d%nspin
1575 multipole(2:space%dim+1, is) = -ionic_dipole(1:space%dim)/st%d%nspin - multipole(2:space%dim+1, is)
1576 end do
1577 end if
1578
1579 if (mpi_grp_is_root(mpi_grp_)) then
1580 call write_iter_start(out_multip)
1581 do is = 1, st%d%nspin
1582 call write_iter_double(out_multip, units_from_atomic(units_out%length**0, multipole(1, is)), 1)
1583 if (lmax > 0) then
1584 do idir = 1, space%dim
1585 call write_iter_double(out_multip, units_from_atomic(units_out%length, multipole(1+idir, is)), 1)
1586 end do
1587 end if
1588 add_lm = space%dim + 2
1589 do ll = 2, lmax
1590 do mm = -ll, ll
1591 call write_iter_double(out_multip, units_from_atomic(units_out%length**ll, multipole(add_lm, is)), 1)
1592 add_lm = add_lm + 1
1593 end do
1594 end do
1595 end do
1596 call write_iter_nl(out_multip)
1597 end if
1598
1599 safe_deallocate_a(multipole)
1600 pop_sub(td_write_multipole_r)
1601 end subroutine td_write_multipole_r
1602
1603 ! ---------------------------------------------------------
1604 subroutine td_write_ftchd(out_ftchd, space, mesh, st, kick, iter)
1605 type(c_ptr), intent(inout) :: out_ftchd
1606 class(space_t), intent(in) :: space
1607 class(mesh_t), intent(in) :: mesh
1608 type(states_elec_t), intent(in) :: st
1609 type(kick_t), intent(in) :: kick
1610 integer, intent(in) :: iter
1611
1612 integer :: is, ip, idir
1613 character(len=120) :: aux, aux2
1614 real(real64) :: ftchd_bessel
1615 complex(real64) :: ftchd
1616 real(real64) :: ylm
1617 real(real64), allocatable :: integrand_bessel(:)
1618 complex(real64), allocatable :: integrand(:)
1619
1620 push_sub(td_write_ftchd)
1621
1622 if (mpi_grp_is_root(mpi_world).and.iter == 0) then
1623 call td_write_print_header_init(out_ftchd)
1624
1625 write(aux,'(a15, i2)') '# qkickmode ', kick%qkick_mode
1626 call write_iter_string(out_ftchd, aux)
1627 call write_iter_nl(out_ftchd)
1628
1629 if (kick%qkick_mode == qkickmode_bessel) then
1630 write(aux,'(a15, i0.3, 1x, i0.3)') '# ll, mm ', kick%qbessel_l, kick%qbessel_m
1631 call write_iter_string(out_ftchd, aux)
1632 call write_iter_nl(out_ftchd)
1633 end if
1634
1635 if (kick%qkick_mode == qkickmode_bessel) then
1636 write(aux, '(a15, f9.6)') '# qlength ', kick%qlength
1637 else ! sin or cos
1638 write(aux, '(a15)') '# qvector '
1639 do idir = 1, space%dim
1640 write(aux2, '(f9.5)') kick%qvector(idir,1)
1641 aux = trim(aux) // trim(aux2)
1642 end do
1643 end if
1644 call write_iter_string(out_ftchd, aux)
1645 call write_iter_nl(out_ftchd)
1646
1647 write(aux, '(a15,f18.12)') '# kick strength', kick%delta_strength
1648 call write_iter_string(out_ftchd, aux)
1649 call write_iter_nl(out_ftchd)
1650
1651 call write_iter_header_start(out_ftchd)
1652 if (kick%qkick_mode == qkickmode_bessel) then
1653 write(aux,'(a17)') 'int(j_l*Y_lm*rho)'
1654 else
1655 write(aux,'(a12)') 'Real, Imag'
1656 end if
1657 call write_iter_header(out_ftchd, aux)
1658 call write_iter_nl(out_ftchd)
1659
1660 ! units
1661 call write_iter_string(out_ftchd, '#[Iter n.]')
1662 call write_iter_header(out_ftchd, '[' // trim(units_abbrev(units_out%time)) // ']')
1663 call write_iter_nl(out_ftchd)
1664 call td_write_print_header_end(out_ftchd)
1665
1666 end if
1667
1668 ftchd = m_zero
1669
1670 ! If kick mode is exp, sin, or cos, apply the normal Fourier transform
1671 if (kick%qkick_mode /= qkickmode_bessel) then
1672 safe_allocate(integrand(1:mesh%np))
1673 integrand = m_zero
1674 do is = 1, st%d%nspin
1675 do ip = 1, mesh%np
1676 integrand(ip) = integrand(ip) + st%rho(ip, is) * exp(-m_zi*sum(mesh%x(ip, 1:space%dim)*kick%qvector(1:space%dim, 1)))
1677 end do
1678 end do
1679 ftchd = zmf_integrate(mesh, integrand)
1680 safe_deallocate_a(integrand)
1681 else
1682 ftchd_bessel = m_zero
1683 safe_allocate(integrand_bessel(1:mesh%np))
1684 integrand_bessel = m_zero
1685 do is = 1, st%d%nspin
1686 do ip = 1, mesh%np
1687 call ylmr_real(mesh%x(ip, 1:3), kick%qbessel_l, kick%qbessel_m, ylm)
1688 integrand_bessel(ip) = integrand_bessel(ip) + st%rho(ip, is) * &
1689 loct_sph_bessel(kick%qbessel_l, kick%qlength*norm2(mesh%x(ip, :)))*ylm
1690 end do
1691 end do
1692 ftchd_bessel = dmf_integrate(mesh, integrand_bessel)
1693 safe_deallocate_a(integrand_bessel)
1694 end if
1695
1696 if (mpi_grp_is_root(mpi_world)) then
1697 call write_iter_start(out_ftchd)
1698 if (kick%qkick_mode == qkickmode_bessel) then
1699 call write_iter_double(out_ftchd, ftchd_bessel, 1)
1700 else ! exp, sin, cos
1701 call write_iter_double(out_ftchd, real(ftchd), 1)
1702 call write_iter_double(out_ftchd, aimag(ftchd), 1)
1703 end if
1704 call write_iter_nl(out_ftchd)
1705 end if
1706
1707 pop_sub(td_write_ftchd)
1708 end subroutine td_write_ftchd
1709
1710 ! ---------------------------------------------------------
1711 subroutine td_write_temperature(out_temperature, ions, iter)
1712 type(c_ptr), intent(inout) :: out_temperature
1713 type(ions_t), intent(in) :: ions
1714 integer, intent(in) :: iter
1715
1716 if (.not. mpi_grp_is_root(mpi_world)) return ! only first node outputs
1717
1718 push_sub(td_write_temperature)
1719
1720 if (iter == 0) then
1721 call td_write_print_header_init(out_temperature)
1722
1723 ! first line: column names
1724 call write_iter_header_start(out_temperature)
1725 call write_iter_header(out_temperature, 'Temperature')
1726 call write_iter_nl(out_temperature)
1727
1728 ! second line: units
1729 call write_iter_string(out_temperature, '#[Iter n.]')
1730 call write_iter_header(out_temperature, '[' // trim(units_abbrev(units_out%time)) // ']')
1731 call write_iter_string(out_temperature, ' [K]')
1732 call write_iter_nl(out_temperature)
1733
1734 call td_write_print_header_end(out_temperature)
1735 end if
1736
1737 call write_iter_start(out_temperature)
1738
1740
1741 call write_iter_nl(out_temperature)
1742
1743 pop_sub(td_write_temperature)
1744 end subroutine td_write_temperature
1745
1746
1747 ! ---------------------------------------------------------
1748 subroutine td_write_populations(out_populations, namespace, space, mesh, st, writ, dt, iter)
1749 type(c_ptr), intent(inout) :: out_populations
1750 type(namespace_t), intent(in) :: namespace
1751 class(space_t), intent(in) :: space
1752 class(mesh_t), intent(in) :: mesh
1753 type(states_elec_t), intent(inout) :: st
1754 type(td_write_t), intent(in) :: writ
1755 real(real64), intent(in) :: dt
1756 integer, intent(in) :: iter
1757
1758 integer :: ist
1759 character(len=6) :: excited_name
1760 complex(real64) :: gsp
1761 complex(real64), allocatable :: excited_state_p(:)
1762 complex(real64), allocatable :: dotprodmatrix(:, :, :)
1763
1764
1765 push_sub(td_write_populations)
1766
1767 safe_allocate(dotprodmatrix(1:writ%gs_st%nst, 1:st%nst, 1:st%nik))
1768 call zstates_elec_matrix(writ%gs_st, st, mesh, dotprodmatrix)
1769
1770
1771 !See comment in zstates_elec_mpdotp
1772 assert(.not. space%is_periodic())
1773
1774 ! all processors calculate the projection
1775 gsp = zstates_elec_mpdotp(namespace, mesh, writ%gs_st, st, dotprodmatrix)
1776
1777 if (writ%n_excited_states > 0) then
1778 safe_allocate(excited_state_p(1:writ%n_excited_states))
1779 do ist = 1, writ%n_excited_states
1780 excited_state_p(ist) = zstates_elec_mpdotp(namespace, mesh, writ%excited_st(ist), st, dotprodmatrix)
1781 end do
1782 end if
1783
1784 if (mpi_grp_is_root(mpi_world)) then
1785 if (iter == 0) then
1786 call td_write_print_header_init(out_populations)
1787
1788 ! first line -> column names
1789 call write_iter_header_start(out_populations)
1790 call write_iter_header(out_populations, 'Re<Phi_gs|Phi(t)>')
1791 call write_iter_header(out_populations, 'Im<Phi_gs|Phi(t)>')
1792 do ist = 1, writ%n_excited_states
1793 write(excited_name,'(a2,i3,a1)') 'P(', ist,')'
1794 call write_iter_header(out_populations, 'Re<'//excited_name//'|Phi(t)>')
1795 call write_iter_header(out_populations, 'Im<'//excited_name//'|Phi(t)>')
1796 end do
1797 call write_iter_nl(out_populations)
1798
1799 ! second line -> units
1800 call write_iter_string(out_populations, '#[Iter n.]')
1801 call write_iter_header(out_populations, '[' // trim(units_abbrev(units_out%time)) // ']')
1802 call write_iter_nl(out_populations)
1803
1804 call td_write_print_header_end(out_populations)
1805 end if
1806
1807 ! cannot call write_iter_start, for the step is not 1
1808 call write_iter_int(out_populations, iter, 1)
1809 call write_iter_double(out_populations, units_from_atomic(units_out%time, iter*dt), 1)
1810 call write_iter_double(out_populations, real(gsp), 1)
1811 call write_iter_double(out_populations, aimag(gsp), 1)
1812 do ist = 1, writ%n_excited_states
1813 call write_iter_double(out_populations, real(excited_state_p(ist)), 1)
1814 call write_iter_double(out_populations, aimag(excited_state_p(ist)), 1)
1815 end do
1816 call write_iter_nl(out_populations)
1817 end if
1818
1819 if (writ%n_excited_states > 0) then
1820 safe_deallocate_a(excited_state_p)
1821 end if
1822 safe_deallocate_a(dotprodmatrix)
1823 pop_sub(td_write_populations)
1824 end subroutine td_write_populations
1825
1826
1827 ! ---------------------------------------------------------
1828 subroutine td_write_acc(out_acc, namespace, space, gr, ions, st, hm, ext_partners, dt, iter)
1829 type(c_ptr), intent(inout) :: out_acc
1830 type(namespace_t), intent(in) :: namespace
1831 class(space_t), intent(in) :: space
1832 type(grid_t), intent(in) :: gr
1833 type(ions_t), intent(inout) :: ions
1834 type(states_elec_t), intent(inout) :: st
1835 type(hamiltonian_elec_t), intent(inout) :: hm
1836 type(partner_list_t), intent(in) :: ext_partners
1837 real(real64), intent(in) :: dt
1838 integer, intent(in) :: iter
1839
1840 integer :: idim
1841 character(len=7) :: aux
1842 real(real64) :: acc(space%dim)
1843
1844 push_sub(td_write_acc)
1845
1846 if (iter == 0 .and. mpi_grp_is_root(mpi_world)) then
1847 call td_write_print_header_init(out_acc)
1848
1849 ! first line -> column names
1850 call write_iter_header_start(out_acc)
1851 do idim = 1, space%dim
1852 write(aux, '(a4,i1,a1)') 'Acc(', idim, ')'
1853 call write_iter_header(out_acc, aux)
1854 end do
1855 call write_iter_nl(out_acc)
1856
1857 ! second line: units
1858 call write_iter_string(out_acc, '#[Iter n.]')
1859 call write_iter_header(out_acc, '[' // trim(units_abbrev(units_out%time)) // ']')
1860 do idim = 1, space%dim
1861 call write_iter_header(out_acc, '[' // trim(units_abbrev(units_out%acceleration)) // ']')
1862 end do
1863 call write_iter_nl(out_acc)
1864 call td_write_print_header_end(out_acc)
1865 end if
1866
1867 call td_calc_tacc(namespace, space, gr, ions, ext_partners, st, hm, acc, dt*iter)
1868
1869 if (mpi_grp_is_root(mpi_world)) then
1870 call write_iter_start(out_acc)
1871 acc = units_from_atomic(units_out%acceleration, acc)
1872 call write_iter_double(out_acc, acc, space%dim)
1873 call write_iter_nl(out_acc)
1874 end if
1875
1876 pop_sub(td_write_acc)
1877 end subroutine td_write_acc
1878
1879 ! ---------------------------------------------------------
1880 subroutine td_write_vel(out_vel, gr, st, space, kpoints, iter)
1881 type(c_ptr), intent(inout) :: out_vel
1882 type(grid_t), intent(in) :: gr
1883 type(states_elec_t), intent(in) :: st
1884 type(space_t), intent(in) :: space
1885 type(kpoints_t), intent(in) :: kpoints
1886 integer, intent(in) :: iter
1887
1888 integer :: idim
1889 character(len=7) :: aux
1890 real(real64) :: vel(space%dim)
1891
1892 push_sub(td_write_vel)
1893
1894 if (iter == 0 .and. mpi_grp_is_root(mpi_world)) then
1895 call td_write_print_header_init(out_vel)
1896
1897 ! first line -> column names
1898 call write_iter_header_start(out_vel)
1899 do idim = 1, space%dim
1900 write(aux, '(a4,i1,a1)') 'Vel(', idim, ')'
1901 call write_iter_header(out_vel, aux)
1902 end do
1903 call write_iter_nl(out_vel)
1904
1905 ! second line: units
1906 call write_iter_string(out_vel, '#[Iter n.]')
1907 call write_iter_header(out_vel, '[' // trim(units_abbrev(units_out%time)) // ']')
1908 do idim = 1, space%dim
1909 call write_iter_header(out_vel, '[' // trim(units_abbrev(units_out%velocity)) // ']')
1910 end do
1911 call write_iter_nl(out_vel)
1912 call td_write_print_header_end(out_vel)
1913 end if
1914
1915 call td_calc_tvel(gr, st, space, kpoints, vel)
1916
1917 if (mpi_grp_is_root(mpi_world)) then
1918 call write_iter_start(out_vel)
1919 vel = units_from_atomic(units_out%velocity, vel)
1920 call write_iter_double(out_vel, vel, space%dim)
1921 call write_iter_nl(out_vel)
1922 end if
1923
1924 pop_sub(td_write_vel)
1925 end subroutine td_write_vel
1926
1927
1928 ! ---------------------------------------------------------
1929 subroutine td_write_laser(out_laser, space, lasers, dt, iter)
1930 type(c_ptr), intent(inout) :: out_laser
1931 class(space_t), intent(in) :: space
1932 type(lasers_t), intent(inout) :: lasers
1933 real(real64), intent(in) :: dt
1934 integer, intent(in) :: iter
1935
1936 integer :: il, idir
1937 real(real64) :: field(space%dim)
1938 real(real64) :: ndfield(space%dim)
1939 character(len=80) :: aux
1940
1941 if (.not. mpi_grp_is_root(mpi_world)) return ! only first node outputs
1942
1943 ! no PUSH SUB, called too often
1944
1945 if (iter == 0) then
1946 call td_write_print_header_init(out_laser)
1947
1948 ! first line
1949 write(aux, '(a7,e20.12,3a)') '# dt = ', units_from_atomic(units_out%time, dt), &
1950 " [", trim(units_abbrev(units_out%time)), "]"
1951 call write_iter_string(out_laser, aux)
1952 call write_iter_nl(out_laser)
1953
1954 call write_iter_header_start(out_laser)
1955 do il = 1, lasers%no_lasers
1956 select case (laser_kind(lasers%lasers(il)))
1957 case (e_field_electric)
1958 do idir = 1, space%dim
1959 write(aux, '(a,i1,a)') 'E(', idir, ')'
1960 call write_iter_header(out_laser, aux)
1961 end do
1962 case (e_field_magnetic)
1963 do idir = 1, space%dim
1964 write(aux, '(a,i1,a)') 'B(', idir, ')'
1965 call write_iter_header(out_laser, aux)
1966 end do
1968 do idir = 1, space%dim
1969 write(aux, '(a,i1,a)') 'A(', idir, ')'
1970 call write_iter_header(out_laser, aux)
1971 end do
1973 write(aux, '(a,i1,a)') 'e(t)'
1974 call write_iter_header(out_laser, aux)
1975 end select
1976 end do
1977
1978 if (lasers_with_nondipole_field(lasers)) then
1979 do idir = 1, space%dim
1980 write(aux, '(a,i1,a)') 'A^M(', idir, ')'
1981 call write_iter_header(out_laser, aux)
1982 end do
1983 end if
1984 call write_iter_nl(out_laser)
1985
1986 call write_iter_string(out_laser, '#[Iter n.]')
1987 call write_iter_header(out_laser, '[' // trim(units_abbrev(units_out%time)) // ']')
1988
1989 ! Note that we do not print out units of E, B, or A, but rather units of e*E, e*B, e*A.
1990 ! (force, force, and energy, respectively). The reason is that the units of E, B or A
1991 ! are ugly.
1992 do il = 1, lasers%no_lasers
1993 select case (laser_kind(lasers%lasers(il)))
1995 aux = '[' // trim(units_abbrev(units_out%force)) // ']'
1996 do idir = 1, space%dim
1997 call write_iter_header(out_laser, aux)
1998 end do
2000 aux = '[' // trim(units_abbrev(units_out%energy)) // ']'
2001 do idir = 1, space%dim
2002 call write_iter_header(out_laser, aux)
2003 end do
2005 aux = '[adim]'
2006 call write_iter_header(out_laser, aux)
2007 end select
2008 end do
2009
2010 if (lasers_with_nondipole_field(lasers)) then
2011 aux = '[' // trim(units_abbrev(units_out%energy)) // ']'
2012 do idir = 1, space%dim
2013 call write_iter_header(out_laser, aux)
2014 end do
2015 end if
2016
2017
2018 call write_iter_nl(out_laser)
2019
2020 call td_write_print_header_end(out_laser)
2021 end if
2023 call write_iter_start(out_laser)
2024
2025 do il = 1, lasers%no_lasers
2026 field = m_zero
2027 call laser_field(lasers%lasers(il), field(1:space%dim), iter*dt)
2028 select case (laser_kind(lasers%lasers(il)))
2030 field = units_from_atomic(units_out%force, field)
2031 call write_iter_double(out_laser, field, space%dim)
2033 field = units_from_atomic(units_out%energy, field)
2034 call write_iter_double(out_laser, field, space%dim)
2036 call write_iter_double(out_laser, field(1), 1)
2037 end select
2038 end do
2039
2040 if (lasers_with_nondipole_field(lasers)) then
2041 call lasers_nondipole_laser_field_step(lasers, ndfield, iter*dt)
2042 call lasers_set_nondipole_parameters(lasers, ndfield, iter*dt)
2043 call write_iter_double(out_laser, ndfield, space%dim)
2044 end if
2045 call write_iter_nl(out_laser)
2046
2047 end subroutine td_write_laser
2048
2049
2050 ! ---------------------------------------------------------
2051 subroutine td_write_energy(out_energy, hm, iter, ke)
2052 type(c_ptr), intent(inout) :: out_energy
2053 type(hamiltonian_elec_t), intent(in) :: hm
2054 integer, intent(in) :: iter
2055 real(real64), intent(in) :: ke
2056
2057 integer :: ii
2058
2059 integer :: n_columns
2060
2061 if (.not. mpi_grp_is_root(mpi_world)) return ! only first node outputs
2062
2063 push_sub(td_write_energy)
2064
2065 n_columns = 9
2066
2067 if (iter == 0) then
2068 call td_write_print_header_init(out_energy)
2069
2070 ! first line -> column names
2071 call write_iter_header_start(out_energy)
2072 call write_iter_header(out_energy, 'Total')
2073 call write_iter_header(out_energy, 'Kinetic (ions)')
2074 call write_iter_header(out_energy, 'Ion-Ion')
2075 call write_iter_header(out_energy, 'Electronic')
2076 call write_iter_header(out_energy, 'Eigenvalues')
2077 call write_iter_header(out_energy, 'Hartree')
2078 call write_iter_header(out_energy, 'Int[n v_xc]')
2079 call write_iter_header(out_energy, 'Exchange')
2080 call write_iter_header(out_energy, 'Correlation')
2081
2082 if (hm%pcm%run_pcm) then
2083 call write_iter_header(out_energy, 'E_M-solvent')
2084 n_columns = n_columns + 1
2085 end if
2086
2087 if (hm%lda_u_level /= dft_u_none) then
2088 call write_iter_header(out_energy, 'Hubbard')
2089 n_columns = n_columns + 1
2090 end if
2091
2092 call write_iter_nl(out_energy)
2093
2094 ! units
2095
2096 call write_iter_string(out_energy, '#[Iter n.]')
2097 call write_iter_header(out_energy, '[' // trim(units_abbrev(units_out%time)) // ']')
2098
2099 do ii = 1, n_columns
2100 call write_iter_header(out_energy, '[' // trim(units_abbrev(units_out%energy)) // ']')
2101 end do
2102 call write_iter_nl(out_energy)
2103
2104
2105 call td_write_print_header_end(out_energy)
2106 end if
2107
2108 call write_iter_start(out_energy)
2109 call write_iter_double(out_energy, units_from_atomic(units_out%energy, hm%energy%total+ke), 1)
2110 call write_iter_double(out_energy, units_from_atomic(units_out%energy, ke), 1)
2111 call write_iter_double(out_energy, units_from_atomic(units_out%energy, hm%ep%eii), 1)
2112 call write_iter_double(out_energy, units_from_atomic(units_out%energy, hm%energy%total-hm%ep%eii), 1)
2113 call write_iter_double(out_energy, units_from_atomic(units_out%energy, hm%energy%eigenvalues), 1)
2114 call write_iter_double(out_energy, units_from_atomic(units_out%energy, hm%energy%hartree), 1)
2115 call write_iter_double(out_energy, units_from_atomic(units_out%energy, hm%energy%intnvxc), 1)
2116 call write_iter_double(out_energy, units_from_atomic(units_out%energy, hm%energy%exchange), 1)
2117 call write_iter_double(out_energy, units_from_atomic(units_out%energy, hm%energy%correlation), 1)
2118
2119 !adding the molecule-solvent electrostatic interaction
2120 if (hm%pcm%run_pcm) call write_iter_double(out_energy, &
2121 units_from_atomic(units_out%energy, hm%energy%int_ee_pcm + hm%energy%int_en_pcm + &
2122 hm%energy%int_nn_pcm + hm%energy%int_ne_pcm), 1)
2123
2124 if (hm%lda_u_level /= dft_u_none) then
2125 call write_iter_double(out_energy, units_from_atomic(units_out%energy, hm%energy%dft_u), 1)
2126 end if
2127
2128 call write_iter_nl(out_energy)
2129
2130 pop_sub(td_write_energy)
2131 end subroutine td_write_energy
2132
2133 ! ---------------------------------------------------------
2134 subroutine td_write_eigs(out_eigs, st, iter)
2135 type(c_ptr), intent(inout) :: out_eigs
2136 type(states_elec_t), intent(in) :: st
2137 integer, intent(in) :: iter
2138
2139 integer :: ii, is
2140 character(len=68) :: buf
2141
2142 push_sub(td_write_eigs)
2143
2145 pop_sub(td_write_eigs)
2146 return ! only first node outputs
2147 end if
2148
2149
2150 if (iter == 0) then
2151 call td_write_print_header_init(out_eigs)
2152
2153 write(buf, '(a15,i2)') '# nst ', st%nst
2154 call write_iter_string(out_eigs, buf)
2155 call write_iter_nl(out_eigs)
2156
2157 write(buf, '(a15,i2)') '# nspin ', st%d%nspin
2158 call write_iter_string(out_eigs, buf)
2159 call write_iter_nl(out_eigs)
2160
2161 ! first line -> column names
2162 call write_iter_header_start(out_eigs)
2163 do is = 1, st%d%kpt%nglobal
2164 do ii = 1, st%nst
2165 write(buf, '(a,i4)') 'Eigenvalue ',ii
2166 call write_iter_header(out_eigs, buf)
2167 end do
2168 end do
2169 call write_iter_nl(out_eigs)
2170
2171 ! second line: units
2172 call write_iter_string(out_eigs, '#[Iter n.]')
2173 call write_iter_header(out_eigs, '[' // trim(units_abbrev(units_out%time)) // ']')
2174 do is = 1, st%d%kpt%nglobal
2175 do ii = 1, st%nst
2176 call write_iter_header(out_eigs, '[' // trim(units_abbrev(units_out%energy)) // ']')
2177 end do
2178 end do
2179 call write_iter_nl(out_eigs)
2180 call td_write_print_header_end(out_eigs)
2181 end if
2182
2183 call write_iter_start(out_eigs)
2184 do is = 1, st%d%kpt%nglobal
2185 do ii =1 , st%nst
2186 call write_iter_double(out_eigs, units_from_atomic(units_out%energy, st%eigenval(ii,is)), 1)
2187 end do
2188 end do
2189 call write_iter_nl(out_eigs)
2190
2191 pop_sub(td_write_eigs)
2192 end subroutine td_write_eigs
2193
2194 ! ---------------------------------------------------------
2195 subroutine td_write_ionch(out_ionch, mesh, st, iter)
2196 type(c_ptr), intent(inout) :: out_ionch
2197 class(mesh_t), intent(in) :: mesh
2198 type(states_elec_t), intent(in) :: st
2199 integer, intent(in) :: iter
2200
2201 integer :: ii, ist, Nch, ik, idim
2202 character(len=68) :: buf
2203 real(real64), allocatable :: ch(:), occ(:)
2204 real(real64), allocatable :: occbuf(:)
2205
2206 push_sub(td_write_ionch)
2207
2208
2209 nch = st%nst * st%d%kpt%nglobal * st%d%dim
2210 safe_allocate(ch(0: nch))
2211 safe_allocate(occ(0: nch))
2212
2213 occ(:) = m_zero
2214 ii = 1
2215 do ik = 1, st%nik
2216 do ist = 1, st%nst
2217 do idim = 1, st%d%dim
2218 if (st%st_start <= ist .and. ist <= st%st_end .and. &
2219 st%d%kpt%start <= ik .and. ik <= st%d%kpt%end) then
2220 occ(ii) = st%occ(ist, ik)
2221 end if
2222 ii = ii+1
2223 end do
2224 end do
2225 end do
2226
2228 if (st%parallel_in_states) then
2229 safe_allocate(occbuf(0: nch))
2230 occbuf(:) = m_zero
2231 call st%mpi_grp%allreduce(occ(0), occbuf(0), nch+1, mpi_double_precision, mpi_sum)
2232 occ(:) = occbuf(:)
2233 safe_deallocate_a(occbuf)
2234 end if
2235
2236 !Calculate the channels
2237 call td_calc_ionch(mesh, st, ch, nch)
2238
2239
2240 if (.not. mpi_grp_is_root(mpi_world)) then
2241 safe_deallocate_a(ch)
2242 pop_sub(td_write_ionch)
2243 return ! only first node outputs
2244 end if
2245
2246
2247 if (iter == 0) then
2248 call td_write_print_header_init(out_ionch)
2249
2250 ! first line -> column names
2251 call write_iter_header_start(out_ionch)
2252
2253 do ii = 0, nch
2254 if (occ(ii)>m_zero .or. ii == 0) then
2255 write(buf, '(a,f4.1,a)') 'Pion(',occ(ii)*ii,'+, t)'
2256 call write_iter_header(out_ionch, buf)
2257 end if
2258 end do
2259 call write_iter_nl(out_ionch)
2260
2261 ! second line: units
2262 call write_iter_string(out_ionch, '#[Iter n.]')
2263 call write_iter_header(out_ionch, '[' // trim(units_abbrev(units_out%time)) // ']')
2264 do ii = 0, nch
2265 if (occ(ii)>m_zero .or. ii == 0) then
2266 call write_iter_header(out_ionch, '[' // trim(units_abbrev(unit_one)) // ']')
2267 end if
2268 end do
2269 call write_iter_nl(out_ionch)
2270 call td_write_print_header_end(out_ionch)
2271 end if
2272
2273 call write_iter_start(out_ionch)
2274 do ii =0 , nch
2275 if (occ(ii)>m_zero .or. ii == 0) then
2276 call write_iter_double(out_ionch, units_from_atomic(unit_one, ch(ii)), 1)
2277 end if
2278 end do
2279 call write_iter_nl(out_ionch)
2280
2281 safe_deallocate_a(ch)
2282 safe_deallocate_a(occ)
2283
2284 pop_sub(td_write_ionch)
2285 end subroutine td_write_ionch
2286
2287 ! ---------------------------------------------------------
2288 subroutine td_write_proj(out_proj, space, mesh, ions, st, gs_st, kick, iter)
2289 type(c_ptr), intent(inout) :: out_proj
2290 class(space_t), intent(in) :: space
2291 class(mesh_t), intent(in) :: mesh
2292 type(ions_t), intent(in) :: ions
2293 type(states_elec_t), intent(inout) :: st
2294 type(states_elec_t), intent(in) :: gs_st
2295 type(kick_t), intent(in) :: kick
2296 integer, intent(in) :: iter
2297
2298 complex(real64), allocatable :: projections(:,:,:)
2299 character(len=80) :: aux
2300 integer :: ik, ist, uist, idir
2301
2302 push_sub(td_write_proj)
2303
2304 if (iter == 0) then
2305 if (mpi_grp_is_root(mpi_world)) then
2306 call td_write_print_header_init(out_proj)
2307
2308 write(aux, '(a15,i2)') '# nspin ', st%d%nspin
2309 call write_iter_string(out_proj, aux)
2310 call write_iter_nl(out_proj)
2311
2312 call kick_write(kick, out = out_proj)
2313
2314 call write_iter_string(out_proj, "#%")
2315 call write_iter_nl(out_proj)
2316
2317 write(aux, '(a,i8)') "# nik ", st%nik
2318 call write_iter_string(out_proj, aux)
2319 call write_iter_nl(out_proj)
2320
2321 write(aux, '(a,2i8)') "# st ", gs_st%st_start, st%nst
2322 call write_iter_string(out_proj, aux)
2323 call write_iter_nl(out_proj)
2324
2325 write(aux, '(a,2i8)') "# ust ", gs_st%st_start, gs_st%st_end
2326 call write_iter_string(out_proj, aux)
2327 call write_iter_nl(out_proj)
2328
2329 do ik = 1, st%nik
2330 call write_iter_string(out_proj, "# w(ik)*occ(ist,ik) ")
2331 do ist = gs_st%st_start, st%nst
2332 call write_iter_double(out_proj, st%kweights(ik)*st%occ(ist, ik), 1)
2333 end do
2334 call write_iter_nl(out_proj)
2335 end do
2336
2337 call write_iter_header_start(out_proj)
2338 do ik = 1, st%nik
2339 do ist = gs_st%st_start, st%nst
2340 do uist = gs_st%st_start, gs_st%st_end
2341 write(aux, '(i4,a,i4)') ist, ' -> ', uist
2342 call write_iter_header(out_proj, 'Re {'//trim(aux)//'}')
2343 call write_iter_header(out_proj, 'Im {'//trim(aux)//'}')
2344 end do
2345 end do
2346 end do
2347 call write_iter_nl(out_proj)
2348
2349 end if
2350
2351 !The dipole matrix elements cannot be computed like that for solids
2352 if (.not. space%is_periodic()) then
2353
2354 safe_allocate(projections(1:st%nst, gs_st%st_start:gs_st%st_end, 1:st%nik))
2355 do idir = 1, space%dim
2356 projections = m_z0
2357
2358 call dipole_matrix_elements(idir)
2359
2360 if (mpi_grp_is_root(mpi_world)) then
2361 write(aux, '(a,i1,a)') "<i|x_", idir, "|a>"
2362 call write_iter_string(out_proj, "# ------")
2363 call write_iter_header(out_proj, aux)
2364 do ik = 1, st%nik
2365 do ist = gs_st%st_start, st%st_end
2366 do uist = gs_st%st_start, gs_st%st_end
2367 call write_iter_double(out_proj, real(projections(ist, uist, ik), real64), 1)
2368 call write_iter_double(out_proj, aimag(projections(ist, uist, ik)), 1)
2369 end do
2370 end do
2371 end do
2372 call write_iter_nl(out_proj)
2373
2374 end if
2375 end do
2376 safe_deallocate_a(projections)
2377
2378 end if
2379
2380 if (mpi_grp_is_root(mpi_world)) then
2382 end if
2383
2384 end if
2385
2386 safe_allocate(projections(1:st%nst, gs_st%st_start:gs_st%st_end, 1:st%nik))
2387 projections(:,:,:) = m_z0
2388 call calc_projections(mesh, st, gs_st, projections)
2389
2390 if (mpi_grp_is_root(mpi_world)) then
2391 call write_iter_start(out_proj)
2392 do ik = 1, st%nik
2393 do ist = gs_st%st_start, st%nst
2394 do uist = gs_st%st_start, gs_st%st_end
2395 call write_iter_double(out_proj, real(projections(ist, uist, ik), real64), 1)
2396 call write_iter_double(out_proj, aimag(projections(ist, uist, ik)), 1)
2397 end do
2398 end do
2399 end do
2400 call write_iter_nl(out_proj)
2401 end if
2402
2403 safe_deallocate_a(projections)
2404 pop_sub(td_write_proj)
2405
2406 contains
2407 ! ---------------------------------------------------------
2408 subroutine dipole_matrix_elements(dir)
2409 integer, intent(in) :: dir
2410
2411 integer :: uist, ist, ik, idim
2412 real(real64) :: n_dip(space%dim)
2413 complex(real64), allocatable :: xpsi(:,:)
2414 complex(real64), allocatable :: psi(:, :), gspsi(:, :)
2415
2417
2418 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
2419 safe_allocate(gspsi(1:mesh%np, 1:st%d%dim))
2420 safe_allocate(xpsi(1:mesh%np, 1:st%d%dim))
2421
2422 do ik = st%d%kpt%start, st%d%kpt%end
2423 do ist = st%st_start, st%st_end
2424 call states_elec_get_state(st, mesh, ist, ik, psi)
2425 do uist = gs_st%st_start, gs_st%st_end
2426 call states_elec_get_state(gs_st, mesh, uist, ik, gspsi)
2427
2428 do idim = 1, st%d%dim
2429 xpsi(1:mesh%np, idim) = mesh%x(1:mesh%np, dir)*gspsi(1:mesh%np, idim)
2430 end do
2431 projections(ist, uist, ik) = -zmf_dotp(mesh, st%d%dim, psi, xpsi, reduce = .false.)
2432
2433 end do
2434 end do
2435 end do
2436
2437 safe_deallocate_a(xpsi)
2438 safe_deallocate_a(gspsi)
2439 safe_deallocate_a(psi)
2440
2441 call comm_allreduce(st%dom_st_kpt_mpi_grp, projections)
2442
2443 ! n_dip is not defined for more than space%dim
2444 n_dip = ions%dipole()
2445 do ik = 1, st%nik
2446 do ist = gs_st%st_start, st%nst
2447 do uist = gs_st%st_start, gs_st%st_end
2448 projections(ist, uist, ik) = projections(ist, uist, ik) - n_dip(dir)
2449 end do
2450 end do
2451 end do
2452
2453
2455 end subroutine dipole_matrix_elements
2456
2457 end subroutine td_write_proj
2458
2459 ! ---------------------------------------------------------
2463 ! ---------------------------------------------------------
2464 subroutine td_write_n_ex(out_nex, outp, namespace, mesh, kpoints, st, gs_st, iter)
2465 type(c_ptr), intent(inout) :: out_nex
2466 type(output_t), intent(in) :: outp
2467 type(namespace_t), intent(in) :: namespace
2468 class(mesh_t), intent(in) :: mesh
2469 type(kpoints_t), intent(in) :: kpoints
2470 type(states_elec_t), intent(inout) :: st
2471 type(states_elec_t), intent(inout) :: gs_st
2472 integer, intent(in) :: iter
2473
2474 complex(real64), allocatable :: projections(:,:)
2475 character(len=80) :: aux, dir
2476 integer :: ik, ikpt, ist, uist, err
2477 real(real64) :: Nex, weight
2478 integer :: gs_nst
2479 real(real64), allocatable :: Nex_kpt(:)
2480
2481
2482 push_sub(td_write_n_ex)
2483
2484 if (iter == 0) then
2485 if (mpi_grp_is_root(mpi_world)) then
2486 call td_write_print_header_init(out_nex)
2487
2488 write(aux, '(a15,i2)') '# nspin ', st%d%nspin
2489 call write_iter_string(out_nex, aux)
2490 call write_iter_nl(out_nex)
2491
2492 call write_iter_string(out_nex, "#%")
2493 call write_iter_nl(out_nex)
2494
2495 write(aux, '(a,i8)') "# nik ", st%nik
2496 call write_iter_string(out_nex, aux)
2497 call write_iter_nl(out_nex)
2498
2499 write(aux, '(a,2i8)') "# st ", gs_st%st_start, st%nst
2500 call write_iter_string(out_nex, aux)
2501 call write_iter_nl(out_nex)
2502
2503 write(aux, '(a,2i8)') "# ust ", gs_st%st_start, gs_st%st_end
2504 call write_iter_string(out_nex, aux)
2505 call write_iter_nl(out_nex)
2506
2507 call write_iter_header_start(out_nex)
2508 call write_iter_header(out_nex, '# iter t Nex(t)')
2509 call write_iter_nl(out_nex)
2510
2511 end if
2512
2513 if (mpi_grp_is_root(mpi_world)) then
2514 call td_write_print_header_end(out_nex)
2515 end if
2516
2517 end if
2518
2519 !We only need the occupied GS states
2520 gs_nst = 1
2521 do ik = 1, st%nik
2522 do ist = 1, gs_st%nst
2523 if (gs_st%occ(ist, ik) > m_min_occ .and. ist > gs_nst) gs_nst = ist
2524 end do
2525 end do
2526
2527 safe_allocate(projections(1:gs_nst, 1:st%nst))
2528
2529 safe_allocate(nex_kpt(1:st%nik))
2530 nex_kpt = m_zero
2531 do ik = st%d%kpt%start, st%d%kpt%end
2532 ikpt = st%d%get_kpoint_index(ik)
2533 call zstates_elec_calc_projections(st, gs_st, namespace, mesh, ik, projections, gs_nst)
2534 do ist = 1, gs_nst
2535 weight = st%kweights(ik) * gs_st%occ(ist, ik)/ st%smear%el_per_state
2536 do uist = st%st_start, st%st_end
2537 nex_kpt(ikpt) = nex_kpt(ikpt) - weight * st%occ(uist, ik) * abs(projections(ist, uist))**2
2538 end do
2539 end do
2540 nex_kpt(ikpt) = nex_kpt(ikpt) + sum(st%occ(st%st_start:st%st_end, ik))*st%kweights(ik)
2541 end do
2542
2543 if (st%parallel_in_states .or. st%d%kpt%parallel) then
2544 call comm_allreduce(st%st_kpt_mpi_grp, nex_kpt)
2545 end if
2546
2547 nex = sum(nex_kpt)
2548
2549 if (mpi_grp_is_root(mpi_world)) then
2550 call write_iter_start(out_nex)
2551 call write_iter_double(out_nex, nex, 1)
2552 call write_iter_nl(out_nex)
2553
2554 ! now write down the k-resolved part
2555 write(dir, '(a,a,i7.7)') trim(outp%iter_dir),"td.", iter ! name of directory
2556
2557 call io_function_output_global_bz(outp%how(option__output__current_kpt) &
2558 + outp%how(option__output__density_kpt), dir, "n_excited_el_kpt", namespace, &
2559 kpoints, nex_kpt, unit_one, err)
2560 end if
2561
2562 safe_deallocate_a(projections)
2563 safe_deallocate_a(nex_kpt)
2564
2565 pop_sub(td_write_n_ex)
2566 end subroutine td_write_n_ex
2567
2568 ! ---------------------------------------------------------
2573 ! ---------------------------------------------------------
2574 subroutine calc_projections(mesh, st, gs_st, projections)
2575 class(mesh_t), intent(in) :: mesh
2576 type(states_elec_t), intent(inout) :: st
2577 type(states_elec_t), intent(in) :: gs_st
2578 complex(real64), intent(inout) :: projections(1:st%nst, gs_st%st_start:gs_st%nst, 1:st%nik)
2579
2580 integer :: uist, ist, ik
2581 complex(real64), allocatable :: psi(:, :), gspsi(:, :)
2582 push_sub(calc_projections)
2583
2584 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
2585 safe_allocate(gspsi(1:mesh%np, 1:st%d%dim))
2586
2587 projections(:,:,:) = m_zero
2588
2589 do ik = st%d%kpt%start, st%d%kpt%end
2590 do ist = st%st_start, st%st_end
2591 call states_elec_get_state(st, mesh, ist, ik, psi)
2592 do uist = gs_st%st_start, gs_st%nst
2593 call states_elec_get_state(gs_st, mesh, uist, ik, gspsi)
2594 projections(ist, uist, ik) = zmf_dotp(mesh, st%d%dim, psi, gspsi, reduce = .false.)
2595 end do
2596 end do
2597 end do
2598
2599 safe_deallocate_a(psi)
2600 safe_deallocate_a(gspsi)
2601
2602 call comm_allreduce(st%dom_st_kpt_mpi_grp, projections)
2603
2604 pop_sub(calc_projections)
2605 end subroutine calc_projections
2606
2607
2608 subroutine td_write_proj_kp(mesh, kpoints, st, gs_st, namespace, iter)
2609 class(mesh_t), intent(in) :: mesh
2610 type(kpoints_t), intent(in) :: kpoints
2611 type(states_elec_t), intent(in) :: st
2612 type(states_elec_t), intent(inout) :: gs_st
2613 type(namespace_t), intent(in) :: namespace
2614 integer, intent(in) :: iter
2615
2616 complex(real64), allocatable :: proj(:,:), psi(:,:,:), gs_psi(:,:,:), temp_state(:,:)
2617 character(len=80) :: filename1, filename2
2618 integer :: ik,ist, jst, file, idim, nk_proj
2619
2620 push_sub(td_write_proj_kp)
2621
2622 write(filename1,'(I10)') iter
2623 filename1 = 'td.general/projections_iter_'//trim(adjustl(filename1))
2624 file = 9845623
2625
2626 safe_allocate(proj(1:gs_st%nst, 1:gs_st%nst))
2627 safe_allocate(psi(1:gs_st%nst,1:gs_st%d%dim,1:mesh%np))
2628 safe_allocate(gs_psi(1:gs_st%nst,1:gs_st%d%dim,1:mesh%np))
2629 safe_allocate(temp_state(1:mesh%np,1:gs_st%d%dim))
2630
2631 ! Project only k-points that have a zero weight.
2632 ! Why? It is unlikely that one is interested in the projections
2633 ! of the Monkhorst-Pack kpoints, but instead we assume that
2634 ! the user has specified a k-path with zero weights
2635 nk_proj = kpoints%nik_skip
2636
2637 do ik = kpoints%reduced%npoints-nk_proj+1, kpoints%reduced%npoints
2638 ! reset arrays
2639 psi(1:gs_st%nst, 1:gs_st%d%dim, 1:mesh%np)= m_zero
2640 gs_psi(1:gs_st%nst, 1:gs_st%d%dim, 1:mesh%np)= m_zero
2641 ! open file for writing
2642 if (mpi_world%rank == 0) then
2643 write(filename2,'(I10)') ik
2644 filename2 = trim(adjustl(filename1))//'_ik_'//trim(adjustl(filename2))
2645 file = io_open(filename2, namespace, action='write')
2646 end if
2647 ! get all states at ik that are locally stored (ground state and td-states)
2648 do ist=gs_st%st_start,gs_st%st_end
2649 if (state_kpt_is_local(gs_st, ist, ik)) then
2650 call states_elec_get_state(st, mesh, ist, ik,temp_state)
2651 do idim = 1,gs_st%d%dim
2652 psi(ist,idim,1:mesh%np) = temp_state(1:mesh%np,idim)
2653 end do
2654 call states_elec_get_state(gs_st, mesh, ist, ik, temp_state)
2655 do idim = 1,gs_st%d%dim
2656 gs_psi(ist,idim,1:mesh%np) = temp_state(1:mesh%np,idim)
2657 end do
2658 end if
2659 end do
2660 ! collect states at ik from all processes in one array
2661 call comm_allreduce(mpi_world, psi)
2662 call comm_allreduce(mpi_world, gs_psi)
2663
2664 ! compute the overlaps as a matrix product
2665 assert(mesh%np_global*gs_st%d%dim < huge(0_int32))
2666 proj(1:gs_st%nst, 1:gs_st%nst) = m_zero
2667 call zgemm('n', &
2668 'c', &
2669 gs_st%nst, &
2670 gs_st%nst, &
2671 i8_to_i4(mesh%np_global*gs_st%d%dim), &
2672 cmplx(mesh%volume_element, m_zero, real64) , &
2673 psi(1, 1, 1), &
2674 ubound(psi, dim = 1), &
2675 gs_psi(1, 1, 1), &
2676 ubound(gs_psi, dim = 1), &
2677 m_z0, &
2678 proj(1, 1), &
2679 ubound(proj, dim = 1))
2680
2681 ! write to file
2682 if (mpi_world%rank == 0) then
2683 do ist = 1, gs_st%nst
2684 do jst = 1, gs_st%nst
2685 write(file,'(I3,1x,I3,1x,e13.6,1x,e13.6,2x)') ist, jst, proj(ist,jst)
2686 end do
2687 end do
2688 call io_close(file)
2689 end if
2690
2691 end do! ik
2692
2693 safe_deallocate_a(proj)
2694 safe_deallocate_a(psi)
2695 safe_deallocate_a(gs_psi)
2696 safe_deallocate_a(temp_state)
2697
2698 pop_sub(td_write_proj_kp)
2699 end subroutine td_write_proj_kp
2700
2701 !---------------------------------------
2702 subroutine td_write_floquet(namespace, space, hm, ext_partners, mesh, st, iter)
2703 type(namespace_t), intent(in) :: namespace
2704 class(space_t), intent(in) :: space
2705 type(hamiltonian_elec_t), intent(inout) :: hm
2706 type(partner_list_t), intent(in) :: ext_partners
2707 class(mesh_t), intent(in) :: mesh
2708 type(states_elec_t), intent(inout) :: st
2709 integer, intent(in) :: iter
2710
2711 complex(real64), allocatable :: hmss(:,:), psi(:,:,:), hpsi(:,:,:), temp_state1(:,:)
2712 complex(real64), allocatable :: HFloquet(:,:,:), HFloq_eff(:,:), temp(:,:)
2713 real(real64), allocatable :: eigenval(:), bands(:,:)
2714 character(len=80) :: filename
2715 integer :: it, nT, ik, ist, in, im, file, idim, nik, ik_count
2716 integer :: Forder, Fdim, m0, n0, n1, nst, ii, jj, lim_nst
2717 logical :: downfolding
2718 type(states_elec_t) :: hm_st
2719
2720 real(real64) :: dt, Tcycle, omega
2721
2722 push_sub(td_write_floquet)
2723
2724 downfolding = .false.
2725
2726 ! this does not depend on propagation, so we do it only once
2727 if (.not. iter == 0) then
2728 pop_sub(td_write_floquet)
2729 return
2730 end if
2731
2732 nst = st%nst
2733
2734 !for now no domain distributionallowed
2735 assert(mesh%np == mesh%np_global)
2736
2737 ! this is used to initialize the hpsi (more effiecient ways?)
2738 call states_elec_copy(hm_st, st)
2739
2740 !%Variable TDFloquetFrequency
2741 !%Type float
2742 !%Default 0
2743 !%Section Time-Dependent::TD Output
2744 !%Description
2745 !% Frequency for the Floquet analysis, this should be the carrier frequency or integer multiples of it.
2746 !% Other options will work, but likely be nonsense.
2747 !%
2748 !%End
2749 call parse_variable(namespace, 'TDFloquetFrequency', m_zero, omega, units_inp%energy)
2750 call messages_print_var_value('Frequency used for Floquet analysis', omega, namespace=namespace)
2751 if (abs(omega) <= m_epsilon) then
2752 message(1) = "Please give a non-zero value for TDFloquetFrequency"
2753 call messages_fatal(1, namespace=namespace)
2754 end if
2755
2756 ! get time of one cycle
2757 tcycle = m_two * m_pi / omega
2758
2759 !%Variable TDFloquetSample
2760 !%Type integer
2761 !%Default 20
2762 !%Section Time-Dependent::TD Output
2763 !%Description
2764 !% Number of points on which one Floquet cycle is sampled in the time-integral of the Floquet analysis.
2765 !%
2766 !%End
2767 call parse_variable(namespace, 'TDFloquetSample',20 ,nt)
2768 call messages_print_var_value('Number of Floquet time-sampling points', nt, namespace=namespace)
2769 dt = tcycle/real(nt, real64)
2770
2771 !%Variable TDFloquetDimension
2772 !%Type integer
2773 !%Default -1
2774 !%Section Time-Dependent::TD Output
2775 !%Description
2776 !% Order of Floquet Hamiltonian. If negative number is given, downfolding is performed.
2777 !%End
2778 call parse_variable(namespace, 'TDFloquetDimension',-1,forder)
2779 if (forder .ge. 0) then
2780 call messages_print_var_value('Order of multiphoton Floquet-Hamiltonian', forder, namespace=namespace)
2781 !Dimension of multiphoton Floquet-Hamiltonian
2782 fdim = 2 * forder + 1
2783 else
2784 message(1) = 'Floquet-Hamiltonian is downfolded'
2785 call messages_info(1, namespace=namespace)
2786 downfolding = .true.
2787 forder = 1
2788 fdim = 3
2789 end if
2790
2791 dt = tcycle/real(nt, real64)
2792
2793 ! we are only interested for k-point with zero weight
2794 nik = hm%kpoints%nik_skip
2796 safe_allocate(hmss(1:nst,1:nst))
2797 safe_allocate( psi(1:nst,1:st%d%dim,1:mesh%np))
2798 safe_allocate(hpsi(1:nst,1:st%d%dim,1:mesh%np))
2799 safe_allocate(temp_state1(1:mesh%np,1:st%d%dim))
2800
2801 ! multiphoton Floquet Hamiltonian, layout:
2802 ! (H_{-n,-m} ... H_{-n,0} ... H_{-n,m})
2803 ! ( . . . . . )
2804 ! H = (H_{0,-m} ... H_{0,0} ... H_{0,m} )
2805 ! ( . . . . . )
2806 ! (H_{n,-m} ... H_{n,0} ... H_{n,m} )
2807 safe_allocate(hfloquet(1:nik,1:nst*fdim, 1:nst*fdim))
2808 hfloquet(1:nik,1:nst*fdim, 1:nst*fdim) = m_zero
2809
2810 ! perform time-integral over one cycle
2811 do it = 1, nt
2812 ! get non-interacting Hamiltonian at time (offset by one cycle to allow for ramp)
2813 call hm%update(mesh, namespace, space, ext_partners, time=tcycle+it*dt)
2814 ! get hpsi
2815 call zhamiltonian_elec_apply_all(hm, namespace, mesh, st, hm_st)
2816
2817 ! project Hamiltonian into grounstates for zero weight k-points
2818 ik_count = 0
2819
2820 do ik = hm%kpoints%reduced%npoints-nik+1, hm%kpoints%reduced%npoints
2821 ik_count = ik_count + 1
2822
2823 psi(1:nst, 1:st%d%dim, 1:mesh%np)= m_zero
2824 hpsi(1:nst, 1:st%d%dim, 1:mesh%np)= m_zero
2825
2826 do ist = st%st_start, st%st_end
2827 if (state_kpt_is_local(st, ist, ik)) then
2828 call states_elec_get_state(st, mesh, ist, ik,temp_state1)
2829 do idim = 1, st%d%dim
2830 psi(ist, idim, 1:mesh%np) = temp_state1(1:mesh%np,idim)
2831 end do
2832 call states_elec_get_state(hm_st, mesh, ist, ik,temp_state1)
2833 do idim = 1, st%d%dim
2834 hpsi(ist, idim,1:mesh%np) = temp_state1(1:mesh%np,idim)
2835 end do
2836 end if
2837 end do
2838 call comm_allreduce(mpi_world, psi)
2839 call comm_allreduce(mpi_world, hpsi)
2840 assert(mesh%np_global*st%d%dim < huge(0_int32))
2841 hmss(1:nst,1:nst) = m_zero
2842 call zgemm( 'n', &
2843 'c', &
2844 nst, &
2845 nst, &
2846 i8_to_i4(mesh%np_global*st%d%dim), &
2847 cmplx(mesh%volume_element, m_zero, real64) , &
2848 hpsi(1, 1, 1), &
2849 ubound(hpsi, dim = 1), &
2850 psi(1, 1, 1), &
2851 ubound(psi, dim = 1), &
2852 m_z0, &
2853 hmss(1, 1), &
2854 ubound(hmss, dim = 1))
2855
2856 hmss(1:nst,1:nst) = conjg(hmss(1:nst,1:nst))
2857
2858 ! accumulate the Floqeut integrals
2859 do in = -forder, forder
2860 do im = -forder, forder
2861 ii = (in+forder) * nst
2862 jj = (im+forder) * nst
2863 hfloquet(ik_count, ii+1:ii+nst, jj+1:jj+nst) = &
2864 hfloquet(ik_count, ii+1:ii+nst, jj+1:jj+nst) + hmss(1:nst, 1:nst) * exp(-(in-im)*m_zi*omega*it*dt)
2865 ! diagonal term
2866 if (in == im) then
2867 do ist = 1, nst
2868 hfloquet(ik_count, ii+ist, ii+ist) = hfloquet(ik_count, ii+ist, ii+ist) + in*omega
2869 end do
2870 end if
2871 end do
2872 end do
2873 end do !ik
2874
2875 end do ! it
2876
2877 hfloquet(:,:,:) = m_one/nt*hfloquet(:,:,:)
2878
2879 ! diagonalize Floquet Hamiltonian
2880 if (downfolding) then
2881 ! here perform downfolding
2882 safe_allocate(hfloq_eff(1:nst,1:nst))
2883 safe_allocate(eigenval(1:nst))
2884 safe_allocate(bands(1:nik,1:nst))
2885
2886 hfloq_eff(1:nst,1:nst) = m_zero
2887 do ik = 1, nik
2888 ! the HFloquet blocks are copied directly out of the super matrix
2889 m0 = nst ! the m=0 start position
2890 n0 = nst ! the n=0 start postion
2891 n1 = 2*nst ! the n=+1 start postion
2892 hfloq_eff(1:nst, 1:nst) = hfloquet(ik, n0+1:n0+nst, m0+1:m0+nst) + &
2893 m_one/omega*(matmul(hfloquet(ik, 1:nst, m0+1:m0+nst), hfloquet(ik, n1+1:n1+nst, m0+1:m0+nst))- &
2894 matmul(hfloquet(ik, n1+1:n1+nst, m0+1:m0+nst), hfloquet(ik, 1:nst, m0+1:m0+nst)))
2895
2896 call lalg_eigensolve(nst, hfloq_eff, eigenval)
2897 bands(ik,1:nst) = eigenval(1:nst)
2898 end do
2899 safe_deallocate_a(hfloq_eff)
2900 else
2901 ! the full Floquet
2902 safe_allocate(eigenval(1:nst*fdim))
2903 safe_allocate(bands(1:nik,1:nst*fdim))
2904 safe_allocate(temp(1:nst*fdim, 1:nst*fdim))
2905
2906 do ik = 1, nik
2907 temp(1:nst*fdim, 1:nst*fdim) = hfloquet(ik, 1:nst*fdim, 1:nst*fdim)
2908 call lalg_eigensolve(nst*fdim, temp, eigenval)
2909 bands(ik, 1:nst*fdim) = eigenval(1:nst*fdim)
2910 end do
2911 end if
2912
2913 !write bandstructure to file
2914 if (downfolding) then
2915 lim_nst = nst
2916 filename = "downfolded_floquet_bands"
2917 else
2918 lim_nst = nst*fdim
2919 filename = "floquet_bands"
2920 end if
2921 ! write bands (full or downfolded)
2922 if (mpi_world%rank == 0) then
2923 file = 987254
2924 file = io_open(filename, namespace, action = 'write')
2925 do ik = 1,nik
2926 do ist = 1,lim_nst
2927 write(file,'(e13.6, 1x)',advance='no') bands(ik,ist)
2928 end do
2929 write(file,'(1x)')
2930 end do
2931 call io_close(file)
2932 end if
2933
2934 if (.not. downfolding) then
2935 ! for the full Floquet case compute also the trivially shifted
2936 ! Floquet bands for reference (i.e. setting H_{nm}=0 for n!=m)
2937 bands(1:nik, 1:nst*fdim) = m_zero
2938 do ik = 1, nik
2939 temp(1:nst*fdim,1:nst*fdim) = m_zero
2940 do jj = 0, fdim - 1
2941 ii = jj * nst
2942 temp(ii+1:ii+nst, ii+1:ii+nst) = hfloquet(ik, ii+1:ii+nst, ii+1:ii+nst)
2943 end do
2944 call lalg_eigensolve(nst*fdim, temp, eigenval)
2945 bands(ik, 1:nst*fdim) = eigenval(1:nst*fdim)
2946 end do
2947
2948 if (mpi_world%rank == 0) then
2949 filename = 'trivial_floquet_bands'
2950 file = io_open(filename, namespace, action = 'write')
2951 do ik=1,nik
2952 do ist = 1,lim_nst
2953 write(file,'(e13.6, 1x)', advance='no') bands(ik,ist)
2954 end do
2955 write(file,'(1x)')
2956 end do
2957 call io_close(file)
2958 end if
2959 end if
2960
2961 ! reset time in Hamiltonian
2962 call hm%update(mesh, namespace, space, ext_partners, time=m_zero)
2963
2964 safe_deallocate_a(hmss)
2965 safe_deallocate_a(psi)
2966 safe_deallocate_a(hpsi)
2967 safe_deallocate_a(temp_state1)
2968 safe_deallocate_a(hfloquet)
2969 safe_deallocate_a(eigenval)
2970 safe_deallocate_a(bands)
2971 safe_deallocate_a(temp)
2972
2973 pop_sub(td_write_floquet)
2974
2975 end subroutine td_write_floquet
2976
2977 ! ---------------------------------------------------------
2978 subroutine td_write_total_current(out_total_current, space, mesh, st, iter)
2979 type(c_ptr), intent(inout) :: out_total_current
2980 class(space_t), intent(in) :: space
2981 class(mesh_t), intent(in) :: mesh
2982 type(states_elec_t), intent(in) :: st
2983 integer, intent(in) :: iter
2984
2985 integer :: idir, ispin
2986 character(len=50) :: aux
2987 real(real64) :: total_current(space%dim), abs_current(space%dim)
2988
2989 push_sub(td_write_total_current)
2990
2991 if (mpi_grp_is_root(mpi_world) .and. iter == 0) then
2992 call td_write_print_header_init(out_total_current)
2993
2994 ! first line: column names
2995 call write_iter_header_start(out_total_current)
2996
2997 do idir = 1, space%dim
2998 write(aux, '(a2,a1,a1)') 'I(', index2axis(idir), ')'
2999 call write_iter_header(out_total_current, aux)
3000 end do
3001
3002 do idir = 1, space%dim
3003 write(aux, '(a10,a1,a1)') 'IntAbs(j)(', index2axis(idir), ')'
3004 call write_iter_header(out_total_current, aux)
3005 end do
3006
3007 do ispin = 1, st%d%nspin
3008 do idir = 1, space%dim
3009 write(aux, '(a4,i1,a1,a1,a1)') 'I-sp', ispin, '(', index2axis(idir), ')'
3010 call write_iter_header(out_total_current, aux)
3011 end do
3012 end do
3013
3014 call write_iter_nl(out_total_current)
3015
3016 call td_write_print_header_end(out_total_current)
3017 end if
3018
3019 assert(allocated(st%current))
3020
3021 if (mpi_grp_is_root(mpi_world)) then
3022 call write_iter_start(out_total_current)
3023 end if
3024
3025 total_current = 0.0_real64
3026 do idir = 1, space%dim
3027 do ispin = 1, st%d%spin_channels
3028 total_current(idir) = total_current(idir) + dmf_integrate(mesh, st%current(:, idir, ispin), reduce = .false.)
3029 end do
3030 total_current(idir) = units_from_atomic(units_out%length/units_out%time, total_current(idir))
3031 end do
3032 call mesh%allreduce(total_current, dim = space%dim)
3033
3034 abs_current = 0.0_real64
3035 do idir = 1, space%dim
3036 do ispin = 1, st%d%spin_channels
3037 abs_current(idir) = abs_current(idir) + dmf_integrate(mesh, abs(st%current(:, idir, ispin)), reduce = .false.)
3038 end do
3039 abs_current(idir) = units_from_atomic(units_out%length/units_out%time, abs_current(idir))
3040 end do
3041 call mesh%allreduce(abs_current, dim = space%dim)
3042
3043 if (mpi_grp_is_root(mpi_world)) then
3044 call write_iter_double(out_total_current, total_current, space%dim)
3045 call write_iter_double(out_total_current, abs_current, space%dim)
3046 end if
3047
3048 do ispin = 1, st%d%nspin
3049 total_current = units_from_atomic(units_out%length/units_out%time, dmf_integrate(mesh, space%dim, st%current(:, :, ispin)))
3050
3051 if (mpi_grp_is_root(mpi_world)) then
3052 call write_iter_double(out_total_current, total_current, space%dim)
3053 end if
3054 end do
3055
3056 if (mpi_grp_is_root(mpi_world)) then
3057 call write_iter_nl(out_total_current)
3058 end if
3059
3060 pop_sub(td_write_total_current)
3061 end subroutine td_write_total_current
3062
3063 ! ---------------------------------------------------------
3064
3065 subroutine td_write_total_heat_current(write_obj, space, hm, gr, st, iter)
3066 type(c_ptr), intent(inout) :: write_obj
3067 class(space_t), intent(in) :: space
3068 type(hamiltonian_elec_t), intent(inout) :: hm
3069 type(grid_t), intent(in) :: gr
3070 type(states_elec_t), intent(in) :: st
3071 integer, intent(in) :: iter
3072
3073 integer :: idir, ispin
3074 character(len=50) :: aux
3075 real(real64), allocatable :: heat_current(:, :, :)
3076 real(real64) :: total_current(space%dim)
3077
3078 push_sub(td_write_total_current)
3079
3080 if (mpi_grp_is_root(mpi_world) .and. iter == 0) then
3081 call td_write_print_header_init(write_obj)
3082
3083 ! first line: column names
3084 call write_iter_header_start(write_obj)
3085
3086 do idir = 1, space%dim
3087 write(aux, '(a2,i1,a1)') 'Jh(', idir, ')'
3088 call write_iter_header(write_obj, aux)
3089 end do
3090
3091 call write_iter_nl(write_obj)
3092
3093 call td_write_print_header_end(write_obj)
3094 end if
3095
3096 safe_allocate(heat_current(1:gr%np, 1:space%dim, 1:st%d%nspin))
3097
3098 call current_heat_calculate(space, gr%der, hm, st, heat_current)
3099
3100 if (mpi_grp_is_root(mpi_world)) call write_iter_start(write_obj)
3101
3102 total_current = 0.0_real64
3103 do idir = 1, space%dim
3104 do ispin = 1, st%d%spin_channels
3105 total_current(idir) = total_current(idir) + dmf_integrate(gr, heat_current(:, idir, ispin))
3106 end do
3107 total_current(idir) = units_from_atomic(units_out%energy*units_out%length/units_out%time, total_current(idir))
3108 end do
3109
3110 safe_deallocate_a(heat_current)
3111
3112 if (mpi_grp_is_root(mpi_world)) call write_iter_double(write_obj, total_current, space%dim)
3113
3114 if (mpi_grp_is_root(mpi_world)) call write_iter_nl(write_obj)
3115
3116 pop_sub(td_write_total_current)
3117 end subroutine td_write_total_heat_current
3118
3119
3120 ! ---------------------------------------------------------
3121 subroutine td_write_partial_charges(out_partial_charges, mesh, st, ions, iter)
3122 type(c_ptr), intent(inout) :: out_partial_charges
3123 class(mesh_t), intent(in) :: mesh
3124 type(states_elec_t), intent(in) :: st
3125 type(ions_t), intent(in) :: ions
3126 integer, intent(in) :: iter
3127
3128 integer :: idir
3129 character(len=50) :: aux
3130 real(real64), allocatable :: hirshfeld_charges(:)
3131
3132 push_sub(td_write_partial_charges)
3133
3134 safe_allocate(hirshfeld_charges(1:ions%natoms))
3135
3136 call partial_charges_calculate(mesh, st, ions, hirshfeld_charges)
3137
3138 if (mpi_grp_is_root(mpi_world)) then
3139
3140 if (iter == 0) then
3141
3142 call td_write_print_header_init(out_partial_charges)
3143
3144 ! first line: column names
3145 call write_iter_header_start(out_partial_charges)
3146
3147 do idir = 1, ions%natoms
3148 write(aux, '(a13,i3,a1)') 'hirshfeld(atom=', idir, ')'
3149 call write_iter_header(out_partial_charges, aux)
3150 end do
3151
3152 call write_iter_nl(out_partial_charges)
3153
3154 call td_write_print_header_end(out_partial_charges)
3155 end if
3156
3157 call write_iter_start(out_partial_charges)
3159 call write_iter_double(out_partial_charges, hirshfeld_charges, ions%natoms)
3160
3161 call write_iter_nl(out_partial_charges)
3162 end if
3163
3164 safe_deallocate_a(hirshfeld_charges)
3165
3167 end subroutine td_write_partial_charges
3168
3169 ! ---------------------------------------------------------
3170 subroutine td_write_q(out_q, space, ks, iter)
3171 type(c_ptr), intent(inout) :: out_q
3172 class(space_t), intent(in) :: space
3173 type(v_ks_t), intent(in) :: ks
3174 integer, intent(in) :: iter
3175
3176 integer :: ii
3177 character(len=50) :: aux
3178
3179 push_sub(td_write_q)
3180
3181 if (mpi_grp_is_root(mpi_world)) then
3182 if (iter == 0) then
3183 call td_write_print_header_init(out_q)
3184 call write_iter_header_start(out_q)
3185 do ii = 1, ks%pt%nmodes
3186 write(aux, '(a1,i3,a3)') 'q', ii, '(t)'
3187 call write_iter_header(out_q, aux)
3188 end do
3189 do ii = 1, ks%pt%nmodes
3190 write(aux, '(a1,i3,a3)') 'p', ii, '(t)'
3191 call write_iter_header(out_q, aux)
3192 end do
3193 do ii = 1, space%dim
3194 write(aux, '(a3,i3,a3)') 'f_pt', ii, '(t)'
3195 call write_iter_header(out_q, aux)
3196 end do
3197 call write_iter_nl(out_q)
3198 call td_write_print_header_end(out_q)
3199 end if
3200
3201 call write_iter_start(out_q)
3202 call write_iter_double(out_q, ks%pt_mx%pt_q, ks%pt%nmodes)
3203 call write_iter_double(out_q, ks%pt_mx%pt_p, ks%pt%nmodes)
3204 call write_iter_double(out_q, ks%pt_mx%fmf, space%dim)
3205 call write_iter_nl(out_q)
3206 end if
3207
3208 pop_sub(td_write_q)
3209 end subroutine td_write_q
3210
3211
3212 ! ---------------------------------------------------------
3213 subroutine td_write_mxll_field(out_mxll, space, hm, dt, iter)
3214 type(c_ptr), intent(inout) :: out_mxll
3215 class(space_t), intent(in) :: space
3216 type(hamiltonian_elec_t),intent(in) :: hm
3217 real(real64), intent(in) :: dt
3218 integer, intent(in) :: iter
3219
3220 integer :: idir
3221 real(real64) :: field(space%dim)
3222 character(len=80) :: aux
3223 character(len=1) :: field_char
3224
3225 push_sub(td_write_mxll_field)
3226
3227 if (.not. mpi_grp_is_root(mpi_world)) then
3228 pop_sub(td_write_mxll_field)
3229 return ! only first node outputs
3230 end if
3231
3232 if (iter == 0) then
3233 call td_write_print_header_init(out_mxll)
3234
3235 write(aux, '(a7,e20.12,3a)') '# dt = ', units_from_atomic(units_out%time, dt), &
3236 " [", trim(units_abbrev(units_out%time)), "]"
3237 call write_iter_string(out_mxll, aux)
3238 call write_iter_nl(out_mxll)
3239
3240 call write_iter_header_start(out_mxll)
3241 select case (hm%mxll%coupling_mode)
3242 case (length_gauge_dipole, multipolar_expansion)
3243 if (hm%mxll%add_electric_dip) field_char = 'E'
3244 if (hm%mxll%add_magnetic_dip) field_char = 'B'
3245 do idir = 1, space%dim
3246 write(aux, '(a,i1,a)') field_char // '(', idir, ')'
3247 call write_iter_header(out_mxll, aux)
3248 end do
3249 case (velocity_gauge_dipole)
3250 do idir = 1, space%dim
3251 write(aux, '(a,i1,a)') 'A(', idir, ')'
3252 call write_iter_header(out_mxll, aux)
3253 end do
3254 end select
3255 call write_iter_nl(out_mxll)
3256
3257 call write_iter_string(out_mxll, '#[Iter n.]')
3258 call write_iter_header(out_mxll, '[' // trim(units_abbrev(units_out%time)) // ']')
3259
3260 ! Note that we do not print out units of E, A or B, but rather units of e*E, e*A or e*B
3261 ! (force, energy and magnetic flux density, respectively).
3262 select case (hm%mxll%coupling_mode)
3263 case (length_gauge_dipole, multipolar_expansion)
3264 if (hm%mxll%add_electric_dip) aux = '[' // trim(units_abbrev(units_out%force)) // ']'
3265 if (hm%mxll%add_magnetic_dip) aux = '[' // trim(units_abbrev(unit_one/units_out%length**2)) // ']'
3266 do idir = 1, space%dim
3267 call write_iter_header(out_mxll, aux)
3268 end do
3269 case (velocity_gauge_dipole)
3270 aux = '[' // trim(units_abbrev(units_out%energy)) // ']'
3271 do idir = 1, space%dim
3272 call write_iter_header(out_mxll, aux)
3273 end do
3274 end select
3275 call write_iter_nl(out_mxll)
3276 call td_write_print_header_end(out_mxll)
3277 end if
3278
3279 call write_iter_start(out_mxll)
3280
3281 field = m_zero
3282 select case (hm%mxll%coupling_mode)
3283 case (length_gauge_dipole, multipolar_expansion)
3284 if (hm%mxll%add_electric_dip) field = units_from_atomic(units_out%force, hm%mxll%e_field_dip)
3285 if (hm%mxll%add_magnetic_dip) field = units_from_atomic(unit_one/units_out%length**2, hm%mxll%b_field_dip)
3286 call write_iter_double(out_mxll, field, space%dim)
3287 case (velocity_gauge_dipole)
3288 field = units_from_atomic(units_out%energy, hm%mxll%vec_pot_dip)
3289 call write_iter_double(out_mxll, field, space%dim)
3290 end select
3291 call write_iter_nl(out_mxll)
3292
3293 pop_sub(td_write_mxll_field)
3294 end subroutine td_write_mxll_field
3295
3296
3297 ! ---------------------------------------------------------
3298 subroutine td_write_effective_u(out_coords, lda_u, iter)
3299 type(c_ptr), intent(inout) :: out_coords
3300 type(lda_u_t), intent(in) :: lda_u
3301 integer, intent(in) :: iter
3302
3303 integer :: ios, inn
3304 character(len=50) :: aux
3305
3306 if (.not. mpi_grp_is_root(mpi_world)) return ! only first node outputs
3307
3308 push_sub(td_write_effective_u)
3309
3310 if (iter == 0) then
3311 call td_write_print_header_init(out_coords)
3312
3313 ! first line: column names
3314 call write_iter_header_start(out_coords)
3315
3316 do ios = 1, lda_u%norbsets
3317 write(aux, '(a2,i3,a1)') 'Ueff(', ios, ')'
3318 call write_iter_header(out_coords, aux)
3319 end do
3320
3321 do ios = 1, lda_u%norbsets
3322 write(aux, '(a2,i3,a1)') 'U(', ios, ')'
3323 call write_iter_header(out_coords, aux)
3324 end do
3325
3326 do ios = 1, lda_u%norbsets
3327 write(aux, '(a2,i3,a1)') 'J(', ios, ')'
3328 call write_iter_header(out_coords, aux)
3329 end do
3330
3331 if (lda_u%intersite) then
3332 do ios = 1, lda_u%norbsets
3333 do inn = 1, lda_u%orbsets(ios)%nneighbors
3334 write(aux, '(a2,i3,a1,i3,a1)') 'V(', ios,'-', inn, ')'
3335 call write_iter_header(out_coords, aux)
3336 end do
3337 end do
3338 end if
3339
3340
3341 call write_iter_nl(out_coords)
3342
3343 ! second line: units
3344 call write_iter_string(out_coords, '#[Iter n.]')
3345 call write_iter_header(out_coords, '[' // trim(units_abbrev(units_out%time)) // ']')
3346 call write_iter_string(out_coords, &
3347 'Effective U ' // trim(units_abbrev(units_out%energy)) // &
3348 ', U in '// trim(units_abbrev(units_out%energy)) // &
3349 ', J in ' // trim(units_abbrev(units_out%energy)))
3350 call write_iter_nl(out_coords)
3351
3352 call td_write_print_header_end(out_coords)
3353 end if
3354
3355 call write_iter_start(out_coords)
3356
3357 do ios = 1, lda_u%norbsets
3358 call write_iter_double(out_coords, units_from_atomic(units_out%energy, &
3359 lda_u%orbsets(ios)%Ueff), 1)
3360 end do
3361
3362 do ios = 1, lda_u%norbsets
3363 call write_iter_double(out_coords, units_from_atomic(units_out%energy, &
3364 lda_u%orbsets(ios)%Ubar), 1)
3365 end do
3366
3367 do ios = 1, lda_u%norbsets
3368 call write_iter_double(out_coords, units_from_atomic(units_out%energy, &
3369 lda_u%orbsets(ios)%Jbar), 1)
3370 end do
3371
3372 if (lda_u%intersite) then
3373 do ios = 1, lda_u%norbsets
3374 do inn = 1, lda_u%orbsets(ios)%nneighbors
3375 call write_iter_double(out_coords, units_from_atomic(units_out%energy, &
3376 lda_u%orbsets(ios)%V_ij(inn,0)), 1)
3377 end do
3378 end do
3379 end if
3380
3381 call write_iter_nl(out_coords)
3382
3383 pop_sub(td_write_effective_u)
3384 end subroutine td_write_effective_u
3385
3387 subroutine td_write_norm_ks_orbitals(file_handle, grid, kpoints, st, iter)
3388 type(c_ptr), intent(inout) :: file_handle
3389 type(grid_t), intent(in) :: grid
3390 type(kpoints_t), intent(in) :: kpoints
3391 type(states_elec_t), intent(in) :: st
3392 integer, intent(in) :: iter
3393
3394 integer :: ik_ispin, ist
3395 character(len=7) :: nkpt_str, nst_str
3396 character(len=7) :: ik_str, ist_str
3397 real(real64), allocatable :: norm_ks(:, :)
3398 real(real64) :: n_electrons
3399
3401
3402 safe_allocate(norm_ks(1:st%nst, 1:st%nik))
3403 call states_elec_calc_norms(grid, kpoints, st, norm_ks)
3404
3405 if (mpi_grp_is_root(mpi_world)) then
3406 ! Header
3407 if (iter == 0) then
3408 call td_write_print_header_init(file_handle)
3409
3410 ! Line 1
3411 write(nkpt_str, '(I7)') st%nik
3412 write(nst_str, '(I7)') st%nst
3413 call write_iter_string(file_handle, '# Dimensions. (nstates, nkpt * nspin):')
3414 call write_iter_string(file_handle, trim(adjustl(nst_str)) // ' ' // trim(adjustl(nkpt_str)))
3415 call write_iter_nl(file_handle)
3416
3417 ! Line 2
3418 call write_iter_string(file_handle, '# Norm ordering: (istate, ikpoint_spin)')
3419 call write_iter_nl(file_handle)
3420
3421 ! Line 3
3422 call write_iter_header_start(file_handle)
3423 call write_iter_header(file_handle, 'N_electrons')
3424 do ik_ispin = 1, st%nik
3425 do ist = 1, st%nst
3426 write(ik_str, '(I7)') ik_ispin
3427 write(ist_str, '(I7)') ist
3428 call write_iter_header(file_handle, &
3429 'Norm (' // trim(ist_str) // ',' // trim(ik_str) // ')')
3430 enddo
3431 enddo
3432 call write_iter_nl(file_handle)
3433 call td_write_print_header_end(file_handle)
3434 end if
3435
3436 n_electrons = sum(st%occ * norm_ks**2)
3437
3438 ! Output norms for time step `iter`
3439 call write_iter_start(file_handle)
3440 call write_iter_double(file_handle, n_electrons, 1)
3441 do ik_ispin = 1, st%nik
3442 call write_iter_double(file_handle, norm_ks(:, ik_ispin), size(norm_ks, 1))
3443 enddo
3444 call write_iter_nl(file_handle)
3445
3446 end if
3447
3448 safe_deallocate_a(norm_ks)
3449
3451
3452 end subroutine td_write_norm_ks_orbitals
3453
3454 ! ---------------------------------------------------------
3456 subroutine td_write_cell_parameters(file_handle, ions, iter)
3457 type(c_ptr), intent(inout) :: file_handle
3458 type(ions_t), intent(in) :: ions
3459 integer, intent(in) :: iter
3460
3461 integer :: idir
3462 real(real64) :: tmp(3)
3463
3464 if (.not. mpi_grp_is_root(mpi_world)) return ! only first task outputs
3465
3466 push_sub(td_write_cell_parameters)
3467
3468 assert(ions%space%dim == 3)
3469
3470 if (iter == 0) then
3471 call td_write_print_header_init(file_handle)
3472
3473 ! first line: column names
3474 call write_iter_header_start(file_handle)
3475
3476 call write_iter_string(file_handle, '# Iter, a, b, c, volume, alpha, beta, gamma, ' &
3477 // 'a_x, a_y, a_z, b_x, b_y, b_z, c_x, c_y, c_z')
3478
3479 ! second line: units
3480 call write_iter_string(file_handle, '#[Iter n.]')
3481 call write_iter_header(file_handle, '[' // trim(units_abbrev(units_out%time)) // ']')
3482 call write_iter_string(file_handle, &
3483 'Lengths in ' // trim(units_abbrev(units_out%length)) // &
3484 ', Volume in ' // trim(units_abbrev(units_out%length**3)) // &
3485 ', Angles in degree, Lattice vectors in '// trim(units_abbrev(units_out%length)))
3486 call write_iter_nl(file_handle)
3487
3488 call td_write_print_header_end(file_handle)
3489 end if
3490
3491 call write_iter_start(file_handle)
3492
3493 ! Length of the lattice vectors
3494 do idir = 1, 3
3495 tmp(idir) = units_from_atomic(units_out%length, norm2(ions%latt%rlattice(1:3, idir)))
3496 end do
3497 call write_iter_double(file_handle, tmp, 3)
3498
3499 ! Cell volume
3500 tmp(1) = units_from_atomic(units_out%length**3, ions%latt%rcell_volume)
3501 call write_iter_double(file_handle, tmp(1), 1)
3502
3503 ! Lattice angles
3504 call write_iter_double(file_handle, ions%latt%alpha, 1)
3505 call write_iter_double(file_handle, ions%latt%beta, 1)
3506 call write_iter_double(file_handle, ions%latt%gamma, 1)
3507
3508 !Lattice vectors
3509 do idir = 1, 3
3510 tmp(1:3) = units_from_atomic(units_out%length, ions%latt%rlattice(:, idir))
3511 call write_iter_double(file_handle, tmp, 3)
3512 end do
3513 call write_iter_nl(file_handle)
3514
3516 end subroutine td_write_cell_parameters
3517
3518
3519 ! ---------------------------------------------------------
3520 subroutine td_write_mxll_init(writ, namespace, iter, dt)
3521 type(td_write_t), intent(out) :: writ
3522 type(namespace_t), intent(in) :: namespace
3523 integer, intent(in) :: iter
3524 real(real64), intent(in) :: dt
3525
3526 integer :: default, flags, iout, first
3527
3528 push_sub(td_write_mxll_init)
3529
3530 !%Variable MaxwellTDOutput
3531 !%Type flag
3532 !%Default maxwell_energy
3533 !%Section Maxwell::Output
3534 !%Description
3535 !% Defines what should be output during the time-dependent
3536 !% Maxwell simulation. Many of the options can increase the computational
3537 !% cost of the simulation, so only use the ones that you need. In
3538 !% most cases the default value is enough, as it is adapted to the
3539 !% details of the TD run.
3540 !% WARNING: the calculation of the longitudinal or transverse E and B fields
3541 !% can be very expensive, so please consider using the MaxwellOutput block
3542 !% to calculate and output these quantities at certain timesteps.
3543 !%Option maxwell_total_e_field 1
3544 !% Output of the total (longitudinal plus transverse) electric field at
3545 !% the points specified in the MaxwellFieldsCoordinate block
3546 !%Option maxwell_total_b_field 8
3547 !% Output of the total (longitudinal plus transverse) magnetic field at
3548 !% the points specified in the MaxwellFieldsCoordinate block
3549 !%Option maxwell_longitudinal_e_field 64
3550 !% Output of the longitudinal electric field at the points
3551 !% specified in the MaxwellFieldsCoordinate block (can slow down the run)
3552 !%Option maxwell_longitudinal_b_field 512
3553 !% Output of the longitudinal magnetic field at the points
3554 !% specified in the MaxwellFieldsCoordinate block (can slow down the run)
3555 !%Option maxwell_transverse_e_field 4096
3556 !% Output of the transverse electric field at the points
3557 !% specified in the MaxwellFieldsCoordinate block (can slow down the run)
3558 !%Option maxwell_transverse_b_field 32768
3559 !% Output of the transverse magnetic field at the points
3560 !% specified in the MaxwellFieldsCoordinate block (can slow down the run)
3561 !%Option maxwell_energy 262144
3562 !% Output of the electromagnetic field energy into the folder <tt>td.general/maxwell</tt>.
3563 !% WARNING: the transverse and longitudinal energies will be correct only if you request
3564 !% the longitudinal and transverse E or B fields as output. Otherwise they will be set to
3565 !% zero.
3566 !%Option e_field_surface_x 524288
3567 !% Output of the E field sliced along the plane x=0 for each field component
3568 !%Option e_field_surface_y 1048576
3569 !% Output of the E field sliced along the plane y=0 for each field component
3570 !%Option e_field_surface_z 2097152
3571 !% Output of the E field sliced along the plane z=0 for each field component
3572 !%Option b_field_surface_x 4194304
3573 !% Output of the B field sliced along the plane x=0 for each field component
3574 !%Option b_field_surface_y 8388608
3575 !% Output of the B field sliced along the plane y=0 for each field component
3576 !%Option b_field_surface_z 16777216
3577 !% Output of the B field sliced along the plane z=0 for each field component
3578 !%End
3579
3580 default = 2**(out_maxwell_energy - 1)
3581 call parse_variable(namespace, 'MaxwellTDOutput', default, flags)
3582
3583 if (.not. varinfo_valid_option('MaxwellTDOutput', flags, is_flag = .true.)) then
3584 call messages_input_error(namespace, 'MaxwellTDOutput')
3585 end if
3586
3588 writ%out(iout)%write = (iand(flags, 2**(iout - 1)) /= 0)
3589 if (writ%out(iout)%write) then
3590 writ%out(iout + 1)%write = .true.
3591 writ%out(iout + 2)%write = .true.
3592 end if
3593 end do
3594
3596 writ%out(iout)%write = (iand(flags, 2**(iout - 1)) /= 0)
3597 end do
3598
3599 if (iter == 0) then
3600 first = 0
3601 else
3602 first = iter + 1
3603 end if
3604
3605 call io_mkdir('td.general', namespace)
3606
3607 ! total E field
3608 if (writ%out(out_maxwell_total_e_field)%write) then
3609 call write_iter_init(writ%out(out_maxwell_total_e_field)%handle, first, &
3610 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/total_e_field_x", namespace)))
3611 call write_iter_init(writ%out(out_maxwell_total_e_field + 1)%handle, first, &
3612 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/total_e_field_y", namespace)))
3613 call write_iter_init(writ%out(out_maxwell_total_e_field + 2)%handle, first, &
3614 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/total_e_field_z", namespace)))
3615 end if
3616
3617 ! total B field
3618 if (writ%out(out_maxwell_total_b_field)%write) then
3619 call write_iter_init(writ%out(out_maxwell_total_b_field)%handle, first, &
3620 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/total_b_field_x", namespace)))
3621 call write_iter_init(writ%out(out_maxwell_total_b_field + 1)%handle, first, &
3622 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/total_b_field_y", namespace)))
3623 call write_iter_init(writ%out(out_maxwell_total_b_field + 2)%handle, first, &
3624 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/total_b_field_z", namespace)))
3625 end if
3626
3627 ! longitudinal E field
3628 if (writ%out(out_maxwell_long_e_field)%write) then
3629 call write_iter_init(writ%out(out_maxwell_long_e_field)%handle, first, &
3630 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/longitudinal_e_field_x", namespace)))
3631 call write_iter_init(writ%out(out_maxwell_long_e_field + 1)%handle, first, &
3632 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/longitudinal_e_field_y", namespace)))
3633 call write_iter_init(writ%out(out_maxwell_long_e_field + 2)%handle, first, &
3634 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/longitudinal_e_field_z", namespace)))
3635 end if
3636
3637 ! longitudinal B field
3638 if (writ%out(out_maxwell_long_b_field)%write) then
3639 call write_iter_init(writ%out(out_maxwell_long_b_field)%handle, first, &
3640 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/longitudinal_b_field_x", namespace)))
3641 call write_iter_init(writ%out(out_maxwell_long_b_field + 1)%handle, first, &
3642 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/longitudinal_b_field_y", namespace)))
3643 call write_iter_init(writ%out(out_maxwell_long_b_field + 2)%handle, first, &
3644 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/longitudinal_b_field_z", namespace)))
3645 end if
3646
3647 ! transverse E field
3648 if (writ%out(out_maxwell_trans_e_field)%write) then
3649 call write_iter_init(writ%out(out_maxwell_trans_e_field)%handle, first, &
3650 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/transverse_e_field_x", namespace)))
3651 call write_iter_init(writ%out(out_maxwell_trans_e_field + 1)%handle, first, &
3652 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/transverse_e_field_y", namespace)))
3653 call write_iter_init(writ%out(out_maxwell_trans_e_field + 2)%handle, first, &
3654 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/transverse_e_field_z", namespace)))
3655 end if
3656
3657 ! transverse B field
3658 if (writ%out(out_maxwell_trans_b_field)%write) then
3659 call write_iter_init(writ%out(out_maxwell_trans_b_field)%handle, first, &
3660 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/transverse_b_field_x", namespace)))
3661 call write_iter_init(writ%out(out_maxwell_trans_b_field + 1)%handle, first, &
3662 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/transverse_b_field_y", namespace)))
3663 call write_iter_init(writ%out(out_maxwell_trans_b_field + 2)%handle, first, &
3664 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/transverse_b_field_z", namespace)))
3665 end if
3666
3667 ! Maxwell energy
3668 if (writ%out(out_maxwell_energy)%write) then
3669 call write_iter_init(writ%out(out_maxwell_energy)%handle, first, &
3670 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/maxwell_energy", namespace)))
3671 end if
3672
3673 if (writ%out(out_e_field_surface_x)%write) then
3674 call write_iter_init(writ%out(out_e_field_surface_x)%handle, first, &
3675 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/electric_field_surface-x", namespace)))
3676 end if
3677
3678 if (writ%out(out_e_field_surface_y)%write) then
3679 call write_iter_init(writ%out(out_e_field_surface_y)%handle, first, &
3680 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/electric_field_surface-y", namespace)))
3681 end if
3682
3683 if (writ%out(out_e_field_surface_z)%write) then
3684 call write_iter_init(writ%out(out_e_field_surface_z)%handle, first, &
3685 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/electric_field_surface-z", namespace)))
3686 end if
3687
3688 if (writ%out(out_b_field_surface_x)%write) then
3689 call write_iter_init(writ%out(out_b_field_surface_x)%handle, first, &
3690 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/magnetic_field_surface-x", namespace)))
3691 end if
3692
3693 if (writ%out(out_b_field_surface_y)%write) then
3694 call write_iter_init(writ%out(out_b_field_surface_y)%handle, first, &
3695 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/magnetic_field_surface-y", namespace)))
3696 end if
3697
3698 if (writ%out(out_b_field_surface_z)%write) then
3699 call write_iter_init(writ%out(out_b_field_surface_z)%handle, first, &
3700 units_from_atomic(units_out%time, dt), trim(io_workpath("td.general/magnetic_field_surface-z", namespace)))
3701 end if
3702
3703 pop_sub(td_write_mxll_init)
3704 end subroutine td_write_mxll_init
3705
3706
3707 ! ---------------------------------------------------------
3708 subroutine td_write_mxll_end(writ)
3709 type(td_write_t), intent(inout) :: writ
3710
3711 integer :: iout
3712
3713 push_sub(td_write_mxll_end)
3714
3715 do iout = 1, out_maxwell_max
3716 if (writ%out(iout)%write) call write_iter_end(writ%out(iout)%handle)
3717 end do
3718
3719 pop_sub(td_write_mxll_end)
3720 end subroutine td_write_mxll_end
3721
3722
3723 ! ---------------------------------------------------------
3724 subroutine td_write_mxll_iter(writ, space, gr, st, hm, helmholtz, dt, iter, namespace)
3725 type(td_write_t), intent(inout) :: writ
3726 class(space_t), intent(in) :: space
3727 type(grid_t), intent(inout) :: gr
3728 type(states_mxll_t), intent(inout) :: st
3729 type(hamiltonian_mxll_t), intent(inout) :: hm
3730 type(helmholtz_decomposition_t), intent(inout) :: helmholtz
3731 real(real64), intent(in) :: dt
3732 integer, intent(in) :: iter
3733 type(namespace_t), intent(in) :: namespace
3734
3735
3736 push_sub(td_write_mxll_iter)
3737
3738 call profiling_in("TD_WRITE_ITER_MAXWELL")
3739
3740 if (writ%out(out_maxwell_trans_e_field)%write .or. writ%out(out_maxwell_trans_b_field)%write) then
3741 call helmholtz%get_trans_field(namespace, st%rs_state_trans, total_field=st%rs_state)
3742 call get_rs_state_at_point(st%selected_points_rs_state_trans(:,:), st%rs_state_trans, &
3743 st%selected_points_coordinate(:,:), st, gr)
3744 !TODO: calculate transverse energy
3745 else
3746 hm%energy%energy_trans = m_zero
3747 end if
3748
3749 if (writ%out(out_maxwell_long_e_field)%write .or. writ%out(out_maxwell_long_b_field)%write) then
3750 call helmholtz%get_long_field(namespace, st%rs_state_long, total_field=st%rs_state)
3751 call get_rs_state_at_point(st%selected_points_rs_state_long(:,:), st%rs_state_long, &
3752 st%selected_points_coordinate(:,:), st, gr)
3753 !TODO: calculate longitudinal energy
3754 else
3755 hm%energy%energy_long = m_zero
3756 end if
3757
3758 ! total E field
3759 if (writ%out(out_maxwell_total_e_field)%write) then
3760 call td_write_fields(writ%out(out_maxwell_total_e_field)%handle, space, st, iter, dt, &
3762 call td_write_fields(writ%out(out_maxwell_total_e_field + 1)%handle, space, st, iter, dt, &
3764 call td_write_fields(writ%out(out_maxwell_total_e_field + 2)%handle, space, st, iter, dt, &
3766 end if
3767
3768 ! total B field
3769 if (writ%out(out_maxwell_total_b_field)%write) then
3770 call td_write_fields(writ%out(out_maxwell_total_b_field)%handle, space, st, iter, dt, &
3772 call td_write_fields(writ%out(out_maxwell_total_b_field + 1)%handle, space, st, iter, dt, &
3774 call td_write_fields(writ%out(out_maxwell_total_b_field + 2)%handle, space, st, iter, dt, &
3776 end if
3777
3778 ! Longitudinal E field
3779 if (writ%out(out_maxwell_long_e_field)%write) then
3780 call td_write_fields(writ%out(out_maxwell_long_e_field)%handle, space, st, iter, dt, &
3782 call td_write_fields(writ%out(out_maxwell_long_e_field + 1)%handle, space, st, iter, dt, &
3784 call td_write_fields(writ%out(out_maxwell_long_e_field + 2)%handle, space, st, iter, dt, &
3786 end if
3787
3788 ! Longitudinal B field
3789 if (writ%out(out_maxwell_long_b_field)%write) then
3790 call td_write_fields(writ%out(out_maxwell_long_b_field)%handle, space, st, iter, dt, &
3792 call td_write_fields(writ%out(out_maxwell_long_b_field + 1)%handle, space, st, iter, dt, &
3794 call td_write_fields(writ%out(out_maxwell_long_b_field + 2)%handle, space, st, iter, dt, &
3796 end if
3797
3798 ! Transverse E field
3799 if (writ%out(out_maxwell_trans_e_field)%write) then
3800 call td_write_fields(writ%out(out_maxwell_trans_e_field)%handle, space, st, iter, dt, &
3802 call td_write_fields(writ%out(out_maxwell_trans_e_field + 1)%handle, space, st, iter, dt, &
3804 call td_write_fields(writ%out(out_maxwell_trans_e_field + 2)%handle, space, st, iter, dt, &
3806 end if
3807
3808 ! Transverse B field
3809 if (writ%out(out_maxwell_trans_b_field)%write) then
3810 call td_write_fields(writ%out(out_maxwell_trans_b_field)%handle, space, st, iter, dt, &
3812 call td_write_fields(writ%out(out_maxwell_trans_b_field + 1)%handle, space, st, iter, dt, &
3814 call td_write_fields(writ%out(out_maxwell_trans_b_field + 2)%handle, space, st, iter, dt, &
3816 end if
3818 ! Maxwell energy
3819 if (writ%out(out_maxwell_energy)%write) then
3820 call td_write_maxwell_energy(writ%out(out_maxwell_energy)%handle, hm, iter)
3821 end if
3822
3823 if (writ%out(out_e_field_surface_x)%write) then
3824 call td_write_electric_field_box_surface(writ%out(out_e_field_surface_x)%handle, st, 1, iter)
3825 end if
3826
3827 if (writ%out(out_e_field_surface_y)%write) then
3828 call td_write_electric_field_box_surface(writ%out(out_e_field_surface_y)%handle, st, 2, iter)
3829 end if
3830
3831 if (writ%out(out_e_field_surface_z)%write) then
3832 call td_write_electric_field_box_surface(writ%out(out_e_field_surface_z)%handle, st, 3, iter)
3833 end if
3834
3835 if (writ%out(out_b_field_surface_x)%write) then
3836 call td_write_magnetic_field_box_surface(writ%out(out_b_field_surface_x)%handle, st, 1, iter)
3837 end if
3838
3839 if (writ%out(out_b_field_surface_y)%write) then
3840 call td_write_magnetic_field_box_surface(writ%out(out_b_field_surface_y)%handle, st, 2, iter)
3841 end if
3842
3843 if (writ%out(out_b_field_surface_z)%write) then
3844 call td_write_magnetic_field_box_surface(writ%out(out_b_field_surface_z)%handle, st, 3, iter)
3845 end if
3846
3847 call profiling_out("TD_WRITE_ITER_MAXWELL")
3848
3849 pop_sub(td_write_mxll_iter)
3850 end subroutine td_write_mxll_iter
3851
3852
3853 ! ---------------------------------------------------------
3854 subroutine td_write_maxwell_energy(out_maxwell_energy, hm, iter)
3855 type(c_ptr), intent(inout) :: out_maxwell_energy
3856 type(hamiltonian_mxll_t), intent(in) :: hm
3857 integer, intent(in) :: iter
3858
3859 integer :: ii
3860
3861 integer :: n_columns
3862
3863 if (.not. mpi_grp_is_root(mpi_world)) return ! only first node outputs
3864
3865 push_sub(td_write_maxwell_energy)
3866
3867 n_columns = 8
3868
3869 if (iter == 0) then
3870 call td_write_print_header_init(out_maxwell_energy)
3871
3872 ! first line -> column names
3873 call write_iter_header_start(out_maxwell_energy)
3874 call write_iter_header(out_maxwell_energy, 'Total')
3875 call write_iter_header(out_maxwell_energy, 'E**2')
3876 call write_iter_header(out_maxwell_energy, 'B**2')
3877 call write_iter_header(out_maxwell_energy, 'Total+Boundaries')
3878 call write_iter_header(out_maxwell_energy, 'Boundaries')
3879 call write_iter_header(out_maxwell_energy, 'Transversal')
3880 call write_iter_header(out_maxwell_energy, 'Longitudinal')
3881 call write_iter_header(out_maxwell_energy, 'Incident Waves')
3882
3883 call write_iter_nl(out_maxwell_energy)
3884
3885 ! units
3886
3887 call write_iter_string(out_maxwell_energy, '#[Iter n.]')
3888 call write_iter_header(out_maxwell_energy, '[' // trim(units_abbrev(units_out%time)) // ']')
3889
3890 do ii = 1, n_columns
3891 call write_iter_header(out_maxwell_energy, '[' // trim(units_abbrev(units_out%energy)) // ']')
3892 end do
3893 call write_iter_nl(out_maxwell_energy)
3894
3895 call td_write_print_header_end(out_maxwell_energy)
3896 end if
3897
3898 call write_iter_start(out_maxwell_energy)
3899 call write_iter_double(out_maxwell_energy, units_from_atomic(units_out%energy, hm%energy%energy), 1)
3900 call write_iter_double(out_maxwell_energy, units_from_atomic(units_out%energy, hm%energy%e_energy), 1)
3901 call write_iter_double(out_maxwell_energy, units_from_atomic(units_out%energy, hm%energy%b_energy), 1)
3902 call write_iter_double(out_maxwell_energy, units_from_atomic(units_out%energy, &
3903 hm%energy%energy+hm%energy%boundaries), 1)
3904 call write_iter_double(out_maxwell_energy, units_from_atomic(units_out%energy, hm%energy%boundaries), 1)
3905 call write_iter_double(out_maxwell_energy, units_from_atomic(units_out%energy, hm%energy%energy_trans), 1)
3906 call write_iter_double(out_maxwell_energy, units_from_atomic(units_out%energy, hm%energy%energy_long), 1)
3907 call write_iter_double(out_maxwell_energy, units_from_atomic(units_out%energy, hm%energy%energy_plane_waves), 1)
3908 call write_iter_nl(out_maxwell_energy)
3909
3911 end subroutine td_write_maxwell_energy
3912
3913
3914 ! ---------------------------------------------------------
3915 subroutine td_write_electric_field_box_surface(out_field_surf, st, dim, iter)
3916 type(c_ptr), intent(inout) :: out_field_surf
3917 type(states_mxll_t), intent(in) :: st
3918 integer, intent(in) :: dim
3919 integer, intent(in) :: iter
3920
3921 integer :: ii
3922
3923 integer :: n_columns
3924
3925 if (.not. mpi_grp_is_root(mpi_world)) return ! only first node outputs
3926
3928
3929 n_columns = 12
3930
3931 if (iter == 0) then
3932 call td_write_print_header_init(out_field_surf)
3933
3934 ! first line -> column names
3935 call write_iter_header_start(out_field_surf)
3936 call write_iter_header(out_field_surf, '- x direction')
3937 call write_iter_header(out_field_surf, '+ x direction')
3938 call write_iter_header(out_field_surf, '- y direction')
3939 call write_iter_header(out_field_surf, '+ y direction')
3940 call write_iter_header(out_field_surf, '- z direction')
3941 call write_iter_header(out_field_surf, '+ z direction')
3942 call write_iter_header(out_field_surf, '- x dir. p. w.')
3943 call write_iter_header(out_field_surf, '+ x dir. p. w.')
3944 call write_iter_header(out_field_surf, '- y dir. p. w.')
3945 call write_iter_header(out_field_surf, '+ y dir. p. w.')
3946 call write_iter_header(out_field_surf, '- z dir. p. w.')
3947 call write_iter_header(out_field_surf, '+ z dir. p. w.')
3948
3949 call write_iter_nl(out_field_surf)
3950
3951 ! units
3952 call write_iter_string(out_field_surf, '#[Iter n.]')
3953 call write_iter_header(out_field_surf, '[' // trim(units_abbrev(units_out%time)) // ']')
3954
3955 do ii = 1, n_columns
3956 call write_iter_header(out_field_surf, '[' // trim(units_abbrev(units_out%energy/units_out%length)) // ']')
3957 end do
3958 call write_iter_nl(out_field_surf)
3959
3960 call td_write_print_header_end(out_field_surf)
3961 end if
3962
3963 call write_iter_start(out_field_surf)
3964 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3965 st%electric_field_box_surface(1,1,dim)), 1)
3966 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3967 st%electric_field_box_surface(2,1,dim)), 1)
3968 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3969 st%electric_field_box_surface(1,2,dim)), 1)
3970 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3971 st%electric_field_box_surface(2,2,dim)), 1)
3972 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3973 st%electric_field_box_surface(1,3,dim)), 1)
3974 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3975 st%electric_field_box_surface(2,3,dim)), 1)
3976 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3977 st%electric_field_box_surface_plane_waves(1,1,dim)), 1)
3978 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3979 st%electric_field_box_surface_plane_waves(2,1,dim)), 1)
3980 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3981 st%electric_field_box_surface_plane_waves(1,2,dim)), 1)
3982 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3983 st%electric_field_box_surface_plane_waves(2,2,dim)), 1)
3984 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3985 st%electric_field_box_surface_plane_waves(1,3,dim)), 1)
3986 call write_iter_double(out_field_surf, units_from_atomic(units_out%energy/units_out%length, &
3987 st%electric_field_box_surface_plane_waves(2,3,dim)), 1)
3988 call write_iter_nl(out_field_surf)
3989
3992
3993
3994 ! ---------------------------------------------------------
3995 subroutine td_write_magnetic_field_box_surface(out_field_surf, st, dim, iter)
3996 type(c_ptr), intent(inout) :: out_field_surf
3997 type(states_mxll_t), intent(in) :: st
3998 integer, intent(in) :: dim
3999 integer, intent(in) :: iter
4000
4001 integer :: ii
4002
4003 integer :: n_columns
4004
4005 if (.not. mpi_grp_is_root(mpi_world)) return ! only first node outputs
4006
4009 n_columns = 12
4010
4011 if (iter == 0) then
4012 call td_write_print_header_init(out_field_surf)
4013
4014 ! first line -> column names
4015 call write_iter_header_start(out_field_surf)
4016 call write_iter_header(out_field_surf, '- x direction')
4017 call write_iter_header(out_field_surf, '+ x direction')
4018 call write_iter_header(out_field_surf, '- y direction')
4019 call write_iter_header(out_field_surf, '+ y direction')
4020 call write_iter_header(out_field_surf, '- z direction')
4021 call write_iter_header(out_field_surf, '+ z direction')
4022 call write_iter_header(out_field_surf, '- x dir. p. w.')
4023 call write_iter_header(out_field_surf, '+ x dir. p. w.')
4024 call write_iter_header(out_field_surf, '- y dir. p. w.')
4025 call write_iter_header(out_field_surf, '+ y dir. p. w.')
4026 call write_iter_header(out_field_surf, '- z dir. p. w.')
4027 call write_iter_header(out_field_surf, '+ z dir. p. w.')
4028
4029 call write_iter_nl(out_field_surf)
4030
4031 ! units
4032 call write_iter_string(out_field_surf, '#[Iter n.]')
4033 call write_iter_header(out_field_surf, '[' // trim(units_abbrev(units_out%time)) // ']')
4034
4035 do ii = 1, n_columns
4036 call write_iter_header(out_field_surf, '[' // trim(units_abbrev(unit_one/units_out%length**2)) // ']')
4037 end do
4038 call write_iter_nl(out_field_surf)
4039
4040 call td_write_print_header_end(out_field_surf)
4041 end if
4042
4043 call write_iter_start(out_field_surf)
4044 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4045 st%magnetic_field_box_surface(1,1,dim)), 1)
4046 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4047 st%magnetic_field_box_surface(2,1,dim)), 1)
4048 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4049 st%magnetic_field_box_surface(1,2,dim)), 1)
4050 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4051 st%magnetic_field_box_surface(2,2,dim)), 1)
4052 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4053 st%magnetic_field_box_surface(1,3,dim)), 1)
4054 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4055 st%magnetic_field_box_surface(2,3,dim)), 1)
4056 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4057 st%magnetic_field_box_surface_plane_waves(1,1,dim)), 1)
4058 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4059 st%magnetic_field_box_surface_plane_waves(2,1,dim)), 1)
4060 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4061 st%magnetic_field_box_surface_plane_waves(1,2,dim)), 1)
4062 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4063 st%magnetic_field_box_surface_plane_waves(2,2,dim)), 1)
4064 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4065 st%magnetic_field_box_surface_plane_waves(1,3,dim)), 1)
4066 call write_iter_double(out_field_surf, units_from_atomic(unit_one/units_out%length**2, &
4067 st%magnetic_field_box_surface_plane_waves(2,3,dim)), 1)
4068 call write_iter_nl(out_field_surf)
4069
4072
4073 ! ---------------------------------------------------------
4074 subroutine td_write_fields(out_fields, space, st, iter, dt, e_or_b_field, field_type, idir)
4075 type(c_ptr), intent(inout) :: out_fields
4076 class(space_t), intent(in) :: space
4077 type(states_mxll_t), intent(in) :: st
4078 integer, intent(in) :: iter
4079 real(real64), intent(in) :: dt
4080 integer, intent(in) :: e_or_b_field
4081 integer, intent(in) :: field_type
4082 integer, intent(in) :: idir
4083
4084
4085 integer :: id
4086 real(real64) :: field(space%dim), selected_field
4087 character(len=80) :: aux
4089 if (.not. mpi_grp_is_root(mpi_world)) return ! only first node outputs
4090
4091 push_sub(td_write_fields)
4092
4093 if (iter == 0) then
4094 call td_write_print_header_init(out_fields)
4095
4096 ! first line
4097 write(aux, '(a7,e20.12,3a)') '# dt = ', units_from_atomic(units_out%time, dt), &
4098 " [", trim(units_abbrev(units_out%time)), "]"
4099 call write_iter_string(out_fields, aux)
4100 call write_iter_nl(out_fields)
4101
4102 call write_iter_header_start(out_fields)
4103
4104 do id = 1, st%selected_points_number
4105 select case (e_or_b_field)
4106 case (maxwell_e_field)
4107 write(aux, '(a,i1,a)') 'E(', id, ')'
4108 case (maxwell_b_field)
4109 write(aux, '(a,i1,a)') 'B(', id, ')'
4110 end select
4111 call write_iter_header(out_fields, aux)
4112 end do
4113
4114 call write_iter_nl(out_fields)
4115 call write_iter_string(out_fields, '#[Iter n.]')
4116 call write_iter_header(out_fields, ' [' // trim(units_abbrev(units_out%time)) // ']')
4117
4118 ! Note that we do not print out units of E, B, or A, but rather units of e*E, e*B, e*A.
4119 ! (force, force, and energy, respectively). The reason is that the units of E, B or A
4120 ! are ugly.
4121 aux = ' [' // trim(units_abbrev(units_out%force)) // ']'
4122 do id = 1, st%selected_points_number
4123 call write_iter_header(out_fields, aux)
4124 end do
4125 call write_iter_nl(out_fields)
4126 call td_write_print_header_end(out_fields)
4127 end if
4128
4129 call write_iter_start(out_fields)
4130
4131 do id = 1, st%selected_points_number
4132 select case (e_or_b_field)
4133 case (maxwell_e_field)
4134 ! Output of electric field at selected point
4135 select case (field_type)
4136 case (maxwell_total_field)
4137 call get_electric_field_vector(st%selected_points_rs_state(:,id), field(1:st%dim))
4138 case (maxwell_long_field)
4139 call get_electric_field_vector(st%selected_points_rs_state_long(:,id), field(1:st%dim))
4140 case (maxwell_trans_field)
4141 call get_electric_field_vector(st%selected_points_rs_state_trans(:,id), field(1:st%dim))
4142 end select
4143 selected_field = units_from_atomic(units_out%energy/units_out%length, field(idir))
4144 case (maxwell_b_field)
4145 ! Output of magnetic field at selected point
4146 select case (field_type)
4147 case (maxwell_total_field)
4148 call get_magnetic_field_vector(st%selected_points_rs_state(:,id), st%rs_sign, field(1:st%dim))
4149 case (maxwell_long_field)
4150 call get_magnetic_field_vector(st%selected_points_rs_state_long(:,id), st%rs_sign, field(1:st%dim))
4151 case (maxwell_trans_field)
4152 call get_magnetic_field_vector(st%selected_points_rs_state_trans(:,id), st%rs_sign, field(1:st%dim))
4153 end select
4154 selected_field = units_from_atomic(unit_one/units_out%length**2, field(idir))
4155 end select
4156 call write_iter_double(out_fields, selected_field, 1)
4157 end do
4158
4159 call write_iter_nl(out_fields)
4160
4161 pop_sub(td_write_fields)
4162 end subroutine td_write_fields
4163
4164
4165 !----------------------------------------------------------
4166 subroutine td_write_mxll_free_data(writ, namespace, space, gr, st, hm, helmholtz, outp, iter, time)
4167 type(td_write_t), intent(inout) :: writ
4168 type(namespace_t), intent(in) :: namespace
4169 class(space_t), intent(in) :: space
4170 type(grid_t), intent(inout) :: gr
4171 type(states_mxll_t), intent(inout) :: st
4172 type(hamiltonian_mxll_t), intent(inout) :: hm
4173 type(helmholtz_decomposition_t), intent(inout) :: helmholtz
4174 type(output_t), intent(in) :: outp
4175 integer, intent(in) :: iter
4176 real(real64), intent(in) :: time
4177
4178 character(len=256) :: filename
4179
4180 push_sub(td_write_maxwell_free_data)
4181 call profiling_in("TD_WRITE_MAXWELL_DATA")
4182
4183 ! now write down the rest
4184 write(filename, '(a,a,i7.7)') trim(outp%iter_dir),"td.", iter ! name of directory
4185
4186 call output_mxll(outp, namespace, space, gr, st, hm, helmholtz, time, filename)
4187
4188 call profiling_out("TD_WRITE_MAXWELL_DATA")
4189 pop_sub(td_write_maxwell_free_data)
4190 end subroutine td_write_mxll_free_data
4191
4192end module td_write_oct_m
4193
4194!! Local Variables:
4195!! mode: f90
4196!! coding: utf-8
4197!! End:
ssize_t ssize_t write(int __fd, const void *__buf, size_t __n) __attribute__((__access__(__read_only__
constant times a vector plus a vector
Definition: lalg_basic.F90:171
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:186
Sets the iteration number to the C object.
Definition: write_iter.F90:174
Writes to the corresponding file and adds one to the iteration. Must be called after write_iter_init(...
Definition: write_iter.F90:167
double exp(double __x) __attribute__((__nothrow__
This module contains interfaces for BLAS routines You should not use these routines directly....
Definition: blas.F90:118
This module implements a calculator for the density and defines related functions.
Definition: density.F90:120
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:609
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
integer, parameter, public spinors
integer, parameter, public spin_polarized
subroutine, public excited_states_kill(excited_state)
Kills an excited_state structure.
subroutine, public excited_states_init(excited_state, ground_state, filename, namespace)
Fills in an excited_state structure, by reading a file called "filename". This file describes the "pr...
type(gauge_field_t) function, pointer, public list_get_gauge_field(partners)
logical function, public list_has_lasers(partners)
type(lasers_t) function, pointer, public list_get_lasers(partners)
subroutine, public gauge_field_output_write(this, out_gauge, iter)
real(real64), parameter, public m_two
Definition: global.F90:190
real(real64), parameter, public m_zero
Definition: global.F90:188
complex(real64), parameter, public m_z0
Definition: global.F90:198
real(real64), parameter, public lmm_r_single_atom
Default local magnetic moments sphere radius for an isolated system.
Definition: global.F90:216
complex(real64), parameter, public m_zi
Definition: global.F90:202
integer, parameter, public max_output_types
Definition: global.F90:148
real(real64), parameter, public m_half
Definition: global.F90:194
real(real64), parameter, public m_one
Definition: global.F90:189
real(real64), parameter, public m_min_occ
Minimal occupation that is considered to be non-zero.
Definition: global.F90:211
This module implements the underlying real-space grid.
Definition: grid.F90:117
The Helmholtz decomposition is intended to contain "only mathematical" functions and procedures to co...
This module defines classes and functions for interaction partners.
subroutine, public zio_function_output(how, dir, fname, namespace, space, mesh, ff, unit, ierr, pos, atoms, grp, root)
Top-level IO routine for functions defined on the mesh.
subroutine, public io_function_read_what_how_when(namespace, space, what, how, output_interval, what_tag_in, how_tag_in, output_interval_tag_in, ignore_error)
Definition: io.F90:114
subroutine, public io_close(iunit, grp)
Definition: io.F90:418
character(len=max_path_len) function, public io_workpath(path, namespace)
Definition: io.F90:270
subroutine, public io_rm(fname, namespace)
Definition: io.F90:342
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:311
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:352
real(real64) function, public ion_dynamics_temperature(ions)
This function returns the ionic temperature in energy units.
integer, parameter, public qkickmode_cos
Definition: kick.F90:169
integer, parameter, public qkickmode_none
Definition: kick.F90:169
integer, parameter, public qkickmode_sin
Definition: kick.F90:169
subroutine, public kick_function_get(space, mesh, kick, kick_function, iq, to_interpolate)
Definition: kick.F90:993
subroutine, public kick_write(kick, iunit, out)
Definition: kick.F90:891
integer, parameter, public qkickmode_bessel
Definition: kick.F90:169
subroutine, public lasers_nondipole_laser_field_step(this, field, time)
Retrieves the NDSFA vector_potential correction. The nondipole field is obtained for consecutive time...
Definition: lasers.F90:1150
subroutine, public lasers_set_nondipole_parameters(this, ndfield, nd_integration_time)
Set parameters for nondipole SFA calculation.
Definition: lasers.F90:752
logical function, public lasers_with_nondipole_field(lasers)
Check if a nondipole SFA correction should be computed for the given laser.
Definition: lasers.F90:739
integer, parameter, public e_field_electric
Definition: lasers.F90:177
integer, parameter, public e_field_vector_potential
Definition: lasers.F90:177
integer, parameter, public e_field_scalar_potential
Definition: lasers.F90:177
integer pure elemental function, public laser_kind(laser)
Definition: lasers.F90:715
subroutine, public laser_field(laser, field, time)
Retrieves the value of either the electric or the magnetic field. If the laser is given by a scalar p...
Definition: lasers.F90:1115
integer, parameter, public e_field_magnetic
Definition: lasers.F90:177
integer, parameter, public dft_u_none
Definition: lda_u.F90:201
integer, parameter, public dft_u_acbn0
Definition: lda_u.F90:201
subroutine, public magnetic_local_moments(mesh, st, ions, boundaries, rho, rr, lmm)
Definition: magnetic.F90:259
subroutine, public magnetic_moment(mesh, st, rho, mm)
Definition: magnetic.F90:183
subroutine, public magnetic_total_magnetization(mesh, st, qq, trans_mag)
Definition: magnetic.F90:326
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:115
subroutine, public ylmr_real(xx, li, mi, ylm)
This is a Numerical Recipes-based subroutine computes real spherical harmonics ylm at position (x,...
Definition: math.F90:375
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:116
This module defines various routines, operating on mesh functions.
subroutine, public dmf_multipoles(mesh, ff, lmax, multipole, mask)
This routine calculates the multipoles of a function ff.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1113
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:537
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1045
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:414
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:713
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1085
subroutine, public modelmb_sym_all_states(space, mesh, st)
This module contains some common usage patterns of MPI routines.
Definition: mpi_lib.F90:115
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
Definition: mpi.F90:430
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:266
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:145
integer, parameter, public velocity_gauge_dipole
this module contains the low-level part of the output system
Definition: output_low.F90:115
subroutine, public output_modelmb(outp, namespace, space, dir, gr, ions, iter, st)
this module contains the output system
Definition: output.F90:115
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
Definition: output.F90:496
subroutine, public output_scalar_pot(outp, namespace, space, dir, mesh, ions, ext_partners, time)
Definition: output.F90:2475
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:618
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:623
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:552
integer, parameter, public restart_gs
Definition: restart.F90:200
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
Definition: restart.F90:516
integer, parameter, public restart_proj
Definition: restart.F90:200
integer, parameter, public restart_type_load
Definition: restart.F90:245
subroutine, public restart_end(restart)
Definition: restart.F90:722
subroutine, public zstates_elec_matrix(st1, st2, mesh, aa)
subroutine, public zstates_elec_calc_projections(st, gs_st, namespace, mesh, ik, proj, gs_nst)
This routine computes the projection between two set of states.
This module handles spin dimensions of the states and the k-point distribution.
logical function, public state_kpt_is_local(st, ist, ik)
check whether a given state (ist, ik) is on the local node
subroutine, public states_elec_end(st)
finalize the states_elec_t object
subroutine, public states_elec_deallocate_wfns(st)
Deallocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special)
make a (selective) copy of a states_elec_t object
subroutine, public states_elec_look(restart, nik, dim, nst, ierr)
Reads the 'states' file in the restart directory, and finds out the nik, dim, and nst contained in it...
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_load(restart, namespace, space, st, mesh, kpoints, ierr, iter, lr, lowest_missing, label, verbose, skip)
returns in ierr: <0 => Fatal error, or nothing read =0 => read all wavefunctions >0 => could only rea...
subroutine, public td_calc_tacc(namespace, space, gr, ions, ext_partners, st, hm, acc, time)
Electronic acceleration (to calculate harmonic spectrum...) It is calculated as:
Definition: td_calc.F90:165
subroutine, public td_calc_ionch(mesh, st, ch, Nch)
Multiple ionization probabilities calculated form the KS orbital densities C. Ullrich,...
Definition: td_calc.F90:319
subroutine, public td_calc_tvel(gr, st, space, kpoints, vel)
Electronic velocity (to calculate harmonic spectrum...) It is calculated as:
Definition: td_calc.F90:287
subroutine, public td_write_coordinates(out_coords, natoms, space, pos, vel, tot_forces, iter)
subroutine, public td_write_sep_coordinates(out_coords, natoms, space, pos, vel, tot_forces, iter, which)
subroutine, public td_write_print_header_init(out)
subroutine, public td_write_print_header_end(out)
subroutine td_write_magnetic_field_box_surface(out_field_surf, st, dim, iter)
Definition: td_write.F90:4089
integer, parameter, public out_total_current
Definition: td_write.F90:201
integer, parameter maxwell_b_field
Definition: td_write.F90:299
integer, parameter, public out_maxwell_max
Definition: td_write.F90:291
subroutine td_write_proj(out_proj, space, mesh, ions, st, gs_st, kick, iter)
Definition: td_write.F90:2382
integer, parameter, public out_q
Definition: td_write.F90:201
integer, parameter, public out_mxll_field
Definition: td_write.F90:201
subroutine calc_projections(mesh, st, gs_st, projections)
This subroutine calculates:
Definition: td_write.F90:2668
integer, parameter out_b_field_surface_y
Definition: td_write.F90:276
subroutine td_write_ionch(out_ionch, mesh, st, iter)
Definition: td_write.F90:2289
integer, parameter, public out_tot_m
Definition: td_write.F90:201
integer, parameter, public out_norm_ks
Definition: td_write.F90:201
integer, parameter out_maxwell_trans_b_field
Definition: td_write.F90:276
integer, parameter, public out_cell_parameters
Definition: td_write.F90:201
subroutine td_write_multipole_r(out_multip, space, mesh, ions, st, lmax, kick, rho, iter, mpi_grp)
Write multipoles to the corresponding file.
Definition: td_write.F90:1571
integer, parameter, public out_proj
Definition: td_write.F90:201
integer, parameter, public out_partial_charges
Definition: td_write.F90:201
integer, parameter, public out_separate_coords
Definition: td_write.F90:201
subroutine td_write_total_current(out_total_current, space, mesh, st, iter)
Definition: td_write.F90:3072
subroutine, public td_write_output(namespace, space, gr, st, hm, ks, outp, ions, ext_partners, iter, dt)
Definition: td_write.F90:1236
subroutine td_write_effective_u(out_coords, lda_u, iter)
Definition: td_write.F90:3392
integer, parameter maxwell_trans_field
Definition: td_write.F90:294
subroutine td_write_acc(out_acc, namespace, space, gr, ions, st, hm, ext_partners, dt, iter)
Definition: td_write.F90:1922
subroutine, public td_write_mxll_init(writ, namespace, iter, dt)
Definition: td_write.F90:3614
subroutine, public td_write_mxll_end(writ)
Definition: td_write.F90:3802
subroutine td_write_mxll_field(out_mxll, space, hm, dt, iter)
Definition: td_write.F90:3307
integer, parameter out_b_field_surface_x
Definition: td_write.F90:276
integer, parameter out_maxwell_long_e_field
Definition: td_write.F90:276
integer, parameter, public out_kp_proj
Definition: td_write.F90:201
integer, parameter, public out_magnets
Definition: td_write.F90:201
subroutine td_write_multipole(out_multip, space, gr, ions, st, lmax, kick, iter)
Top-level routine that write multipoles to file, or files depending on whether a state-resolved outpu...
Definition: td_write.F90:1524
subroutine td_write_electric_field_box_surface(out_field_surf, st, dim, iter)
Definition: td_write.F90:4009
integer, parameter out_e_field_surface_y
Definition: td_write.F90:276
integer, parameter, public out_angular
Definition: td_write.F90:201
subroutine td_write_populations(out_populations, namespace, space, mesh, st, writ, dt, iter)
Definition: td_write.F90:1842
integer, parameter, public out_max
Definition: td_write.F90:201
integer, parameter out_maxwell_long_b_field
Definition: td_write.F90:276
integer, parameter, public out_energy
Definition: td_write.F90:201
integer, parameter, public out_spin
Definition: td_write.F90:201
subroutine td_write_ftchd(out_ftchd, space, mesh, st, kick, iter)
Definition: td_write.F90:1698
subroutine td_write_partial_charges(out_partial_charges, mesh, st, ions, iter)
Definition: td_write.F90:3215
integer, parameter out_dftu_max
For the Maxwell fields we increment in steps of 3 to leave room for x, y, and z output.
Definition: td_write.F90:271
subroutine td_write_laser(out_laser, space, lasers, dt, iter)
Definition: td_write.F90:2023
integer, parameter out_maxwell_total_b_field
Definition: td_write.F90:276
integer, parameter, public out_ftchd
Definition: td_write.F90:201
integer, parameter, public out_separate_velocity
Definition: td_write.F90:201
subroutine td_write_tot_mag(out_magnets, mesh, st, kick, iter)
Definition: td_write.F90:1386
subroutine td_write_q(out_q, space, ks, iter)
Definition: td_write.F90:3264
integer, parameter, public out_floquet
Definition: td_write.F90:201
integer, parameter, public out_acc
Definition: td_write.F90:201
integer, parameter, public out_ion_ch
Definition: td_write.F90:201
integer, parameter maxwell_long_field
Definition: td_write.F90:294
integer, parameter, public out_n_ex
Definition: td_write.F90:201
integer, parameter out_b_field_surface_z
Definition: td_write.F90:276
subroutine td_write_proj_kp(mesh, kpoints, st, gs_st, namespace, iter)
Definition: td_write.F90:2702
integer, parameter, public out_temperature
Definition: td_write.F90:201
subroutine td_write_norm_ks_orbitals(file_handle, grid, kpoints, st, iter)
Write the norm of the KS orbitals to file as a function of time step.
Definition: td_write.F90:3481
subroutine, public td_write_data(writ)
Definition: td_write.F90:1202
subroutine, public td_write_mxll_free_data(writ, namespace, space, gr, st, hm, helmholtz, outp, iter, time)
Definition: td_write.F90:4260
subroutine td_write_total_heat_current(write_obj, space, hm, gr, st, iter)
Definition: td_write.F90:3159
integer, parameter out_e_field_surface_z
Definition: td_write.F90:276
integer, parameter maxwell_total_field
Definition: td_write.F90:294
integer, parameter, public out_coords
Definition: td_write.F90:201
integer, parameter out_maxwell_total_e_field
Definition: td_write.F90:276
integer, parameter, public out_laser
Definition: td_write.F90:201
integer, parameter, public out_eigs
Definition: td_write.F90:201
subroutine td_write_vel(out_vel, gr, st, space, kpoints, iter)
Definition: td_write.F90:1974
subroutine td_write_floquet(namespace, space, hm, ext_partners, mesh, st, iter)
Definition: td_write.F90:2796
integer, parameter, public out_total_heat_current
Definition: td_write.F90:201
integer, parameter out_e_field_surface_x
Definition: td_write.F90:276
subroutine, public td_write_kick(outp, namespace, space, mesh, kick, ions, iter)
Definition: td_write.F90:335
subroutine, public td_write_end(writ)
Definition: td_write.F90:986
subroutine td_write_angular(out_angular, namespace, space, gr, ions, hm, st, kick, iter)
Computes and outputs the orbital angular momentum defined by.
Definition: td_write.F90:1453
subroutine td_write_eigs(out_eigs, st, iter)
Definition: td_write.F90:2228
subroutine, public td_write_iter(writ, namespace, space, outp, gr, st, hm, ions, ext_partners, kick, ks, dt, iter, mc, recalculate_gs)
Definition: td_write.F90:1033
subroutine td_write_n_ex(out_nex, outp, namespace, mesh, kpoints, st, gs_st, iter)
This routine computes the total number of excited electrons based on projections on the GS orbitals T...
Definition: td_write.F90:2558
subroutine td_write_fields(out_fields, space, st, iter, dt, e_or_b_field, field_type, idir)
Definition: td_write.F90:4168
subroutine td_write_spin(out_spin, mesh, st, iter)
Definition: td_write.F90:1277
integer, parameter, public out_vel
Definition: td_write.F90:201
integer, parameter, public out_gauge_field
Definition: td_write.F90:201
subroutine td_write_temperature(out_temperature, ions, iter)
Definition: td_write.F90:1805
integer, parameter maxwell_e_field
Definition: td_write.F90:299
integer, parameter, public out_populations
Definition: td_write.F90:201
subroutine, public td_write_mxll_iter(writ, space, gr, st, hm, helmholtz, dt, iter, namespace)
Definition: td_write.F90:3818
subroutine td_write_cell_parameters(file_handle, ions, iter)
Write the cell parameters as a function of time.
Definition: td_write.F90:3550
subroutine td_write_local_magnetic_moments(out_magnets, gr, st, ions, lmm_r, iter)
Definition: td_write.F90:1329
subroutine, public td_write_init(writ, namespace, space, outp, gr, st, hm, ions, ext_partners, ks, ions_move, with_gauge_field, kick, iter, max_iter, dt, mc)
Initialize files to write when prograting in time.
Definition: td_write.F90:373
integer, parameter out_maxwell_energy
Definition: td_write.F90:276
subroutine td_write_energy(out_energy, hm, iter, ke)
Definition: td_write.F90:2145
subroutine td_write_maxwell_energy(out_maxwell_energy, hm, iter)
Definition: td_write.F90:3948
integer, parameter, public out_separate_forces
Definition: td_write.F90:201
integer, parameter out_maxwell_trans_e_field
Definition: td_write.F90:276
type(type_t), public type_cmplx
Definition: types.F90:134
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:132
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:223
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_t), public unit_kelvin
For converting energies into temperatures.
type(unit_system_t), public units_inp
the units systems for reading and writing
type(unit_t), public unit_one
some special units required for particular quantities
This module is intended to contain simple general-purpose utility functions and procedures.
Definition: utils.F90:118
character pure function, public index2axis(idir)
Definition: utils.F90:202
subroutine, public v_ks_calculate_current(this, calc_cur)
Definition: v_ks.F90:1454
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
Definition: v_ks.F90:744
Explicit interfaces to C functions, defined in write_iter_low.cc.
Definition: write_iter.F90:114
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:168
Describes mesh distribution to nodes.
Definition: mesh.F90:186
This is defined even when running serial.
Definition: mpi.F90:142
Stores all communicators and groups.
Definition: multicomm.F90:206
output handler class
Definition: output_low.F90:164
The states_elec_t class contains all electronic wave functions.
Time-dependent Write Properties.
Definition: td_write.F90:317
int true(void)
subroutine dipole_matrix_elements(dir)
Definition: td_write.F90:2502