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