62 type(output_me_t),
intent(out) :: this
63 type(namespace_t),
intent(in) :: namespace
64 class(space_t),
intent(in) :: space
65 type(states_elec_t),
intent(in) :: st
66 type(grid_t),
intent(in) :: gr
67 integer,
intent(in) :: nst
69 integer(int64) :: how(0:MAX_OUTPUT_TYPES)
70 integer :: output_interval(0:MAX_OUTPUT_TYPES)
122 'OutputMatrixElements')
124 if (st%parallel_in_states)
then
125 if (this%what(option__outputmatrixelements__two_body))
then
129 if (this%what(option__outputmatrixelements__dipole))
then
135 if (space%dim /= 3) this%what(option__outputmatrixelements__ang_momentum) = .false.
137 if (this%what(option__outputmatrixelements__ks_multipoles))
then
158 call parse_variable(namespace,
'OutputMEMultipoles', 1, this%ks_multipoles)
170 assert(this%st_start > 0 .and. this%st_start <= nst)
181 if (this%st_end <= 0 .or. this%st_end > nst .or. this%st_start > this%st_end)
then
182 message(1) =
"OutputMEEnd must be positive, smaller or equal to the number of states, and larger than OutputMEStart"
185 this%nst = this%st_end - this%st_start +1
192 subroutine output_me(this, namespace, space, dir, st, gr, ions, hm)
195 class(
space_t),
intent(in) :: space
196 character(len=*),
intent(in) :: dir
198 type(
grid_t),
intent(in) :: gr
199 type(
ions_t),
intent(in) :: ions
202 integer :: id, ll, iunit
203 character(len=256) :: fname
204 real(real64),
allocatable :: doneint(:), dtwoint(:)
205 complex(real64),
allocatable :: zoneint(:), ztwoint(:)
206 integer,
allocatable :: iindex(:,:), jindex(:,:), kindex(:,:), lindex(:,:)
211 if (this%what(option__outputmatrixelements__momentum))
then
212 write(fname,
'(2a)') trim(dir),
'/ks_me_momentum'
216 if (this%what(option__outputmatrixelements__velocity))
then
217 write(fname,
'(2a)') trim(dir),
'/ks_me_velocity'
221 if (this%what(option__outputmatrixelements__ang_momentum))
then
222 write(fname,
'(2a)') trim(dir),
'/ks_me_angular_momentum'
226 if (this%what(option__outputmatrixelements__ks_multipoles))
then
230 if (this%what(option__outputmatrixelements__dipole))
then
231 assert(.not. st%parallel_in_states)
235 if (this%what(option__outputmatrixelements__one_body))
then
236 message(1) =
"Computing one-body matrix elements"
239 if (st%parallel_in_states)
call messages_not_implemented(
"OutputMatrixElements=one_body with states parallelization", &
241 if (st%d%kpt%parallel)
call messages_not_implemented(
"OutputMatrixElements=one_body with k-points parallelization", &
247 iunit =
io_open(trim(dir)//
'/output_me_one_body', namespace, action=
'write')
249 id = st%nst*(st%nst+1)/2
251 safe_allocate(iindex(1:id,1))
252 safe_allocate(jindex(1:id,1))
255 safe_allocate(doneint(1:id))
256 call one_body_me(gr, st, namespace, hm, iindex(:,1), jindex(:,1), doneint)
257 if (gr%mpi_grp%is_root())
then
259 write(iunit, *) iindex(ll,1), jindex(ll,1), doneint(ll)
262 safe_deallocate_a(doneint)
264 safe_allocate(zoneint(1:id))
265 call one_body_me(gr, st, namespace, hm, iindex(:,1), jindex(:,1), zoneint)
266 if (gr%mpi_grp%is_root())
then
268 write(iunit, *) iindex(ll,1), jindex(ll,1), zoneint(ll)
271 safe_deallocate_a(zoneint)
274 safe_deallocate_a(iindex)
275 safe_deallocate_a(jindex)
279 if (this%what(option__outputmatrixelements__two_body) .or. this%what(option__outputmatrixelements__two_body_exc_k))
then
280 message(1) =
"Computing two-body matrix elements"
283 assert(.not. st%parallel_in_states)
285 if (hm%exxop%compute_single_precision)
then
288 if (this%what(option__outputmatrixelements__two_body))
then
289 if (st%parallel_in_states)
then
292 if (st%d%kpt%parallel)
then
296 iunit =
io_open(trim(dir)//
'/output_me_two_body', namespace, action=
'write')
297 if (gr%mpi_grp%is_root())
then
298 write(iunit,
'(a)')
'# (n1, k1) (n2, k2) (n3, k3) (n4, k4) (n1-k1, n2-k2|n3-k3, n4-k4)'
301 if (st%parallel_in_states)
then
302 call messages_not_implemented(
"OutputMatrixElements=two_body_exc_k with states parallelization", namespace=namespace)
304 if (st%d%kpt%parallel)
then
305 call messages_not_implemented(
"OutputMatrixElements=two_body_exc_k with k-points parallelization", namespace=namespace)
308 iunit =
io_open(trim(dir)//
'/output_me_two_body_density', namespace, action=
'write')
309 if (gr%mpi_grp%is_root())
then
310 write(iunit,
'(a)')
'#(n1, k1) (n2, k2) (n1-k1, n1-k2|n2-k2, n2-k1)'
314 if (this%what(option__outputmatrixelements__two_body))
then
316 id = st%nik*this%nst*(st%nik*this%nst+1)*(st%nik**2*this%nst**2+st%nik*this%nst+2)/8
318 id = (st%nik*this%nst)**4
321 id = (st%nik*this%nst)**2
328 safe_allocate(iindex(1:2, 1:id))
329 safe_allocate(jindex(1:2, 1:id))
330 safe_allocate(kindex(1:2, 1:id))
331 safe_allocate(lindex(1:2, 1:id))
334 safe_allocate(dtwoint(1:id))
335 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, &
336 iindex, jindex, kindex, lindex, dtwoint)
337 if (gr%mpi_grp%is_root())
then
339 write(iunit,
'(4(i4,i5,1x),es22.12)') iindex(1:2,ll), jindex(1:2,ll), kindex(1:2,ll), lindex(1:2,ll), dtwoint(ll)
342 safe_deallocate_a(dtwoint)
344 safe_allocate(ztwoint(1:id))
345 if (hm%phase%is_allocated())
then
347 assert(.not. st%d%kpt%parallel)
348 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, iindex, jindex, &
349 kindex, lindex, ztwoint, phase = hm%phase, singularity = singul, &
350 exc_k = (this%what(option__outputmatrixelements__two_body_exc_k)))
352 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, &
353 iindex, jindex, kindex, lindex, ztwoint, exc_k = (this%what(option__outputmatrixelements__two_body_exc_k)))
356 if (gr%mpi_grp%is_root())
then
357 if (this%what(option__outputmatrixelements__two_body))
then
359 write(iunit,
'(4(i4,i5,1x),2es22.12)') iindex(1:2,ll), jindex(1:2,ll), kindex(1:2,ll), lindex(1:2,ll), ztwoint(ll)
363 write(iunit,
'(2(i4,i5),2es22.12)') iindex(1:2,ll), kindex(1:2,ll), ztwoint(ll)
367 safe_deallocate_a(ztwoint)
370 safe_deallocate_a(iindex)
371 safe_deallocate_a(jindex)
372 safe_deallocate_a(kindex)
373 safe_deallocate_a(lindex)
387 type(
grid_t),
intent(in) :: gr
389 type(
space_t),
intent(in) :: space
390 character(len=*),
intent(in) :: fname
393 type(
ions_t),
intent(in) :: ions
394 logical,
optional,
intent(in) :: non_local
396 integer :: ik, ist, is, ns, iunit, idir, dim
397 character(len=80) :: cspin, str_tmp
398 real(real64) :: kpoint(space%dim)
399 real(real64),
allocatable :: momentum(:,:,:)
405 safe_allocate(momentum(1:dim, 1:st%nst, 1:st%nik))
408 call elec_momentum_me(namespace, gr, st, space, hm, ions, momentum, non_local)
410 iunit =
io_open(fname, namespace, action=
'write')
413 if (st%d%nspin == 2) ns = 2
416 write(
message(1),
'(a)')
'Velocity of the KS states [a.u.]:'
418 write(
message(1),
'(a)')
'Momentum of the KS states [a.u.]:'
421 if (st%nik > ns)
then
426 do ik = 1, st%nik, ns
427 kpoint(:) = hm%kpoints%get_point(st%d%get_kpoint_index(ik))
429 if (st%nik > ns)
then
430 write(
message(1),
'(a,i4, a)')
'#k =', ik,
', k = ('
434 if (idir == dim)
then
443 write(
message(1),
'(a4,1x,a5)')
'#st',
' Spin'
446 write(str_tmp,
'(a,a1,a)')
' <v',
index2axis(idir),
'>'
448 write(str_tmp,
'(a,a1,a)')
' <p',
index2axis(idir),
'>'
452 write(str_tmp,
'(4x,a12,1x)')
'Occupation '
459 if (is == 0) cspin =
'up'
460 if (is == 1) cspin =
'dn'
463 write(
message(1),
'(i4,3x,a2,1x)') ist, trim(cspin)
465 write(str_tmp,
'(f12.6)') momentum(idir, ist, ik+is)
468 write(str_tmp,
'(3x,f12.6)') st%occ(ist, ik+is)
480 safe_deallocate_a(momentum)
489 type(
grid_t),
intent(in) :: gr
491 type(
space_t),
intent(in) :: space
492 character(len=*),
intent(in) :: fname
496 integer :: iunit, ik, ist, is, ns, idir, k_start, k_end, k_n, dim, st_start, st_end, nst
497 character(len=80) :: tmp_str(space%dim), cspin
498 real(real64) :: angular(3), lsquare, kpoint(space%dim)
499 real(real64),
allocatable :: ang(:, :, :), ang2(:, :)
503 real(real64),
allocatable :: lang(:, :)
508 if (st%d%nspin == 2) ns = 2
509 assert(space%dim == 3)
512 st_start = st%st_start
516 iunit =
io_open(fname, namespace, action=
'write')
518 if (st%system_grp%is_root())
then
519 write(iunit,
'(a)')
'Warning: When non-local pseudopotentials are used '
520 write(iunit,
'(a)')
' the numbers below may be meaningless. '
521 write(iunit,
'(a)')
' '
522 write(iunit,
'(a)')
'Angular Momentum of the KS states [dimensionless]:'
524 if (st%nik > ns)
then
530 safe_allocate(ang(1:nst, 1:st%nik, 1:3))
531 safe_allocate(ang2(1:nst, 1:st%nik))
536 k_start = st%d%kpt%start
543 if (st%d%kpt%parallel)
then
544 k_n = st%d%kpt%nlocal()
546 assert(.not. st%parallel_in_states)
549 safe_allocate(lang(1:st%lnst, 1:k_n))
551 lang(1:st%lnst, 1:k_n) = ang(st_start:st_end, k_start:k_end, idir)
552 call st%d%kpt%mpi_grp%allgatherv(lang, nst*k_n, mpi_double_precision, ang(:, :, idir), &
553 st%d%kpt%num(:)*nst, (st%d%kpt%range(1, :) - 1)*nst, mpi_double_precision)
555 lang(1:st%lnst, 1:k_n) = ang2(st_start:st_end, k_start:k_end)
556 call st%d%kpt%mpi_grp%allgatherv(lang, nst*k_n, mpi_double_precision, ang2, &
557 st%d%kpt%num(:)*nst, (st%d%kpt%range(1, :) - 1)*nst, mpi_double_precision)
558 safe_deallocate_a(lang)
561 if (st%parallel_in_states)
then
562 safe_allocate(lang(1:st%lnst, 1))
565 do ik = 1, st%nik, ns
566 if (st%nik > ns)
then
568 kpoint(:) = kpoints%get_point(st%d%get_kpoint_index(ik))
570 write(
message(1),
'(a,i4, a)')
'#k =', ik,
', k = ('
574 if (idir == dim)
then
584 if (st%parallel_in_states)
then
585 assert(.not. st%d%kpt%parallel)
589 lang(1:st%lnst, 1) = ang(st_start:st_end, ik+is-1, idir)
590 call lmpi_gen_allgatherv(st%lnst, lang(:, 1), tmp, ang(:, ik+is-1, idir), st%mpi_grp)
592 lang(1:st%lnst, 1) = ang2(st_start:st_end, ik+is-1)
593 call lmpi_gen_allgatherv(st%lnst, lang(:, 1), tmp, ang2(:, ik+is-1), st%mpi_grp)
598 write(
message(1),
'(a4,1x,a5,4a12,4x,a12,1x)') &
599 '#st',
' Spin',
' <Lx>',
' <Ly>',
' <Lz>',
' <L2>',
'Occupation '
602 if (st%system_grp%is_root())
then
606 if (is == 0) cspin =
'up'
607 if (is == 1) cspin =
'dn'
610 write(tmp_str(1),
'(i4,3x,a2)') ist, trim(cspin)
611 write(tmp_str(2),
'(1x,4f12.6,3x,f12.6)') &
612 (ang(ist, ik+is, idir), idir = 1, 3), ang2(ist, ik+is), st%occ(ist, ik+is)
613 message(1) = trim(tmp_str(1))//trim(tmp_str(2))
623 write(
message(1),
'(a)')
'Total Angular Momentum L [dimensionless]'
624 write(
message(2),
'(10x,4f12.6)') angular(1:3), lsquare
629 if (st%parallel_in_states)
then
630 safe_deallocate_a(lang)
633 safe_deallocate_a(ang)
634 safe_deallocate_a(ang2)
640 type(
grid_t),
intent(in) :: gr
642 type(
space_t),
intent(in) :: space
643 character(len=*),
intent(in) :: dir
646 type(
ions_t),
intent(in) :: ions
647 integer,
intent(in) :: st_start, st_end
649 integer :: ik, idir, ist, jst, iunit
650 character(len=256) :: fname
651 real(real64),
allocatable :: ddip_elements(:,:,:)
652 complex(real64),
allocatable :: zdip_elements(:,:,:)
657 do ik = st%d%kpt%start, st%d%kpt%end
658 write(fname,
'(i8)') ik
659 write(fname,
'(a)') trim(dir)//
'/ks_me_dipole.k'//trim(adjustl(fname))//
'_'
663 safe_allocate(ddip_elements(1:space%dim, st_start:st_end, st_start:st_end))
665 call dipole_me(gr, st, namespace, hm, ions, ik, st_start, st_end, ddip_elements)
667 do idir = 1, space%dim
669 write(iunit,
'(a)')
'# Dipole matrix elements file: |<Phi_i | r | Phi_j>|'
670 write(iunit,
'(a,i8)')
'# ik =', ik
673 do ist = st_start, st_end
674 do jst = st_start, st_end
676 write(iunit, fmt=
'(a)', advance =
'no')
' '
678 write(iunit,
'(a)')
''
682 safe_deallocate_a(ddip_elements)
685 safe_allocate(zdip_elements(1:space%dim, st_start:st_end, st_start:st_end))
687 call dipole_me(gr, st, namespace, hm, ions, ik, st_start, st_end, zdip_elements)
689 do idir = 1, space%dim
691 write(iunit,
'(a)')
'# Dipole matrix elements file: |<Phi_i | r | Phi_j>|'
692 write(iunit,
'(a,i8)')
'# ik =', ik
695 do ist = st_start, st_end
696 do jst = st_start, st_end
698 write(iunit, fmt=
'(a)', advance =
'no')
' '
700 write(iunit,
'(a)')
''
704 safe_deallocate_a(zdip_elements)
712 type(
grid_t),
intent(in) :: gr
714 type(
space_t),
intent(in) :: space
715 character(len=*),
intent(in) :: dir
719 integer :: id, ll, mm, ik, iunit
720 character(len=256) :: fname
721 real(real64),
allocatable :: delements(:,:)
722 complex(real64),
allocatable :: zelements(:,:)
730 select case (space%dim)
732 do ll = 1, this%ks_multipoles
735 write(fname,
'(i4)') id
736 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
737 iunit =
io_open(fname, namespace, action =
'write')
742 safe_allocate(delements(1:st%nst, 1:st%nst))
745 safe_deallocate_a(delements)
747 safe_allocate(zelements(1:st%nst, 1:st%nst))
750 safe_deallocate_a(zelements)
761 write(fname,
'(i4)') id
762 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
763 iunit =
io_open(fname, namespace, action =
'write')
768 safe_allocate(delements(1:st%nst, 1:st%nst))
771 safe_deallocate_a(delements)
773 safe_allocate(zelements(1:st%nst, 1:st%nst))
776 safe_deallocate_a(zelements)
783 do ll = 1, this%ks_multipoles
786 write(fname,
'(i4)') id
787 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
788 iunit =
io_open(fname, namespace, action =
'write')
793 safe_allocate(delements(1:st%nst, 1:st%nst))
796 safe_deallocate_a(delements)
798 safe_allocate(zelements(1:st%nst, 1:st%nst))
801 safe_deallocate_a(zelements)
815 integer,
intent(in) :: iunit, ll, mm, ik
817 write(iunit, fmt =
'(a)')
'# Multipole matrix elements file: <Phi_i | r**l * Y_{lm}(theta,phi) | Phi_j>'
818 write(iunit, fmt =
'(a,i2,a,i2)')
'# l =', ll,
'; m =', mm
819 write(iunit, fmt =
'(a,i8)')
'# ik =', ik
828 integer,
intent(in) :: iunit, nst
829 real(real64),
contiguous,
intent(in) :: elements(:,:)
830 integer,
optional,
intent(in) :: ll
833 real(real64) :: element
838 write(iunit, fmt=
'(f20.12, a)', advance =
'no') element,
' '
840 write(iunit,
'(a)')
''
845 integer,
intent(in) :: iunit, nst
846 complex(real64),
contiguous,
intent(in) :: elements(:,:)
847 integer,
optional,
intent(in) :: ll
850 complex(real64) :: element
855 write(iunit, fmt=
'(f20.12,a1,f20.12,a)', advance =
'no') real(element),
',',aimag(element),
' '
857 write(iunit,
'(a)')
''
868#include "complex.F90"
subroutine, public elec_angular_momentum_me(gr, st, space, ll, l2)
subroutine, public elec_momentum_me(namespace, gr, st, space, hm, ions, momentum, non_local)
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
This module implements the underlying real-space grid.
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)
subroutine, public io_close(iunit, grp)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
subroutine, public messages_not_implemented(feature, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
This module contains some common usage patterns of MPI routines.
this module contains the low-level part of the output system
subroutine output_me_out_ang_momentum(gr, st, space, fname, namespace, kpoints)
subroutine output_me_out_dipole(gr, st, space, dir, namespace, hm, ions, st_start, st_end)
subroutine, public output_me_init(this, namespace, space, st, gr, nst)
subroutine, public output_me(this, namespace, space, dir, st, gr, ions, hm)
subroutine output_me_out_ks_multipoles(gr, st, space, dir, this, namespace)
subroutine output_me_out_momentum(gr, st, space, fname, namespace, hm, ions, non_local)
subroutine, public singularity_end(this)
subroutine, public singularity_init(this, namespace, space, st, kpoints)
pure logical function, public states_are_complex(st)
pure logical function, public states_are_real(st)
This module handles spin dimensions of the states and the k-point distribution.
real(real64) function, public states_elec_eigenvalues_sum(st, alt_eig)
function to calculate the eigenvalues sum using occupations as weights
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
character(len=20) pure function, public units_abbrev(this)
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
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.
character pure function, public index2axis(idir)
logical pure function, public family_is_mgga_with_exc(xcs)
Is the xc function part of the mGGA family with an energy functional.
subroutine print_ks_multipole_header(iunit, ll, mm, ik)
subroutine zprint_ks_multipole(iunit, nst, elements, ll)
subroutine dprint_ks_multipole(iunit, nst, elements, ll)
Description of the grid, containing information on derivatives, stencil, and symmetries.
Output information for matrix elements.
The states_elec_t class contains all electronic wave functions.