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