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