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