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