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)
116 'OutputMatrixElements')
118 if (st%parallel_in_states)
then
119 if (this%what(option__outputmatrixelements__two_body))
then
123 if (this%what(option__outputmatrixelements__dipole))
then
129 if (space%dim /= 2 .and. space%dim /= 3) this%what(option__outputmatrixelements__ang_momentum) = .false.
131 if (this%what(option__outputmatrixelements__ks_multipoles))
then
152 call parse_variable(namespace,
'OutputMEMultipoles', 1, this%ks_multipoles)
164 assert(this%st_start > 0 .and. this%st_start <= nst)
175 assert(this%st_end > 0 .and. this%st_end <= nst)
176 assert(this%st_start <= this%st_end)
177 this%nst = this%st_end - this%st_start +1
184 subroutine output_me(this, namespace, space, dir, st, gr, ions, hm)
187 class(
space_t),
intent(in) :: space
188 character(len=*),
intent(in) :: dir
190 type(
grid_t),
intent(in) :: gr
191 type(
ions_t),
intent(in) :: ions
194 integer :: id, ll, iunit
195 character(len=256) :: fname
196 real(real64),
allocatable :: doneint(:), dtwoint(:)
197 complex(real64),
allocatable :: zoneint(:), ztwoint(:)
198 integer,
allocatable :: iindex(:,:), jindex(:,:), kindex(:,:), lindex(:,:)
203 if (this%what(option__outputmatrixelements__momentum))
then
204 write(fname,
'(2a)') trim(dir),
'/ks_me_momentum'
208 if (this%what(option__outputmatrixelements__ang_momentum))
then
209 write(fname,
'(2a)') trim(dir),
'/ks_me_angular_momentum'
213 if (this%what(option__outputmatrixelements__ks_multipoles))
then
217 if (this%what(option__outputmatrixelements__dipole))
then
218 assert(.not. st%parallel_in_states)
222 if (this%what(option__outputmatrixelements__one_body))
then
223 message(1) =
"Computing one-body matrix elements"
226 if (st%parallel_in_states)
call messages_not_implemented(
"OutputMatrixElements=one_body with states parallelization", &
228 if (st%d%kpt%parallel)
call messages_not_implemented(
"OutputMatrixElements=one_body with k-points parallelization", &
230 if (family_is_mgga_with_exc(hm%xc))
then
234 iunit =
io_open(trim(dir)//
'/output_me_one_body', namespace, action=
'write')
236 id = st%nst*(st%nst+1)/2
238 safe_allocate(iindex(1:id,1))
239 safe_allocate(jindex(1:id,1))
242 safe_allocate(doneint(1:id))
243 call one_body_me(gr, st, namespace, hm, iindex(:,1), jindex(:,1), doneint)
246 write(iunit, *) iindex(ll,1), jindex(ll,1), doneint(ll)
249 safe_deallocate_a(doneint)
251 safe_allocate(zoneint(1:id))
252 call one_body_me(gr, st, namespace, hm, iindex(:,1), jindex(:,1), zoneint)
255 write(iunit, *) iindex(ll,1), jindex(ll,1), zoneint(ll)
258 safe_deallocate_a(zoneint)
261 safe_deallocate_a(iindex)
262 safe_deallocate_a(jindex)
266 if (this%what(option__outputmatrixelements__two_body) .or. this%what(option__outputmatrixelements__two_body_exc_k))
then
267 message(1) =
"Computing two-body matrix elements"
270 assert(.not. st%parallel_in_states)
271 if (this%what(option__outputmatrixelements__two_body))
then
272 if (st%parallel_in_states)
then
275 if (st%d%kpt%parallel)
then
279 iunit =
io_open(trim(dir)//
'/output_me_two_body', namespace, action=
'write')
281 write(iunit,
'(a)')
'# (n1, k1) (n2, k2) (n3, k3) (n4, k4) (n1-k1, n2-k2|n3-k3, n4-k4)'
284 if (st%parallel_in_states)
then
285 call messages_not_implemented(
"OutputMatrixElements=two_body_exc_k with states parallelization", namespace=namespace)
287 if (st%d%kpt%parallel)
then
288 call messages_not_implemented(
"OutputMatrixElements=two_body_exc_k with k-points parallelization", namespace=namespace)
291 iunit =
io_open(trim(dir)//
'/output_me_two_body_density', namespace, action=
'write')
293 write(iunit,
'(a)')
'#(n1, k1) (n2, k2) (n1-k1, n1-k2|n2-k2, n2-k1)'
297 if (this%what(option__outputmatrixelements__two_body))
then
299 id = st%nik*this%nst*(st%nik*this%nst+1)*(st%nik**2*this%nst**2+st%nik*this%nst+2)/8
301 id = (st%nik*this%nst)**4
304 id = (st%nik*this%nst)**2
311 safe_allocate(iindex(1:2, 1:id))
312 safe_allocate(jindex(1:2, 1:id))
313 safe_allocate(kindex(1:2, 1:id))
314 safe_allocate(lindex(1:2, 1:id))
317 safe_allocate(dtwoint(1:id))
318 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, &
319 iindex, jindex, kindex, lindex, dtwoint)
322 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)
325 safe_deallocate_a(dtwoint)
327 safe_allocate(ztwoint(1:id))
328 if (hm%phase%is_allocated())
then
330 assert(.not. st%d%kpt%parallel)
331 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, iindex, jindex, &
332 kindex, lindex, ztwoint, phase = hm%phase, singularity = singul, &
333 exc_k = (this%what(option__outputmatrixelements__two_body_exc_k)))
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, ztwoint, exc_k = (this%what(option__outputmatrixelements__two_body_exc_k)))
340 if (this%what(option__outputmatrixelements__two_body))
then
342 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)
346 write(iunit,
'(2(i4,i5),2es22.12)') iindex(1:2,ll), kindex(1:2,ll), ztwoint(ll)
350 safe_deallocate_a(ztwoint)
353 safe_deallocate_a(iindex)
354 safe_deallocate_a(jindex)
355 safe_deallocate_a(kindex)
356 safe_deallocate_a(lindex)
370 type(
grid_t),
intent(in) :: gr
372 type(
space_t),
intent(in) :: space
373 character(len=*),
intent(in) :: fname
377 integer :: ik, ist, is, ns, iunit, idir, dim
378 character(len=80) :: cspin, str_tmp
379 real(real64) :: kpoint(space%dim)
380 real(real64),
allocatable :: momentum(:,:,:)
386 safe_allocate(momentum(1:dim, 1:st%nst, 1:st%nik))
391 iunit =
io_open(fname, namespace, action=
'write')
394 if (st%d%nspin == 2) ns = 2
396 write(
message(1),
'(a)')
'Momentum of the KS states [a.u.]:'
398 if (st%nik > ns)
then
403 do ik = 1, st%nik, ns
404 kpoint(:) = kpoints%get_point(st%d%get_kpoint_index(ik))
406 if (st%nik > ns)
then
407 write(
message(1),
'(a,i4, a)')
'#k =', ik,
', k = ('
411 if (idir == dim)
then
420 write(
message(1),
'(a4,1x,a5)')
'#st',
' Spin'
422 write(str_tmp,
'(a,a1,a)')
' <p',
index2axis(idir),
'>'
425 write(str_tmp,
'(4x,a12,1x)')
'Occupation '
432 if (is == 0) cspin =
'up'
433 if (is == 1) cspin =
'dn'
436 write(
message(1),
'(i4,3x,a2,1x)') ist, trim(cspin)
438 write(str_tmp,
'(f12.6)') momentum(idir, ist, ik+is)
441 write(str_tmp,
'(3x,f12.6)') st%occ(ist, ik+is)
453 safe_deallocate_a(momentum)
464 type(
space_t),
intent(in) :: space
465 character(len=*),
intent(in) :: fname
469 integer :: iunit, ik, ist, is, ns, idir, k_start, k_end, k_n, dim, st_start, st_end, nst
470 character(len=80) :: tmp_str(space%dim), cspin
471 real(real64) :: angular(3), lsquare, kpoint(space%dim)
472 real(real64),
allocatable :: ang(:, :, :), ang2(:, :)
476 real(real64),
allocatable :: lang(:, :)
481 if (st%d%nspin == 2) ns = 2
482 assert(space%dim == 3)
485 st_start = st%st_start
489 iunit =
io_open(fname, namespace, action=
'write')
492 write(iunit,
'(a)')
'Warning: When non-local pseudopotentials are used '
493 write(iunit,
'(a)')
' the numbers below may be meaningless. '
494 write(iunit,
'(a)')
' '
495 write(iunit,
'(a)')
'Angular Momentum of the KS states [dimensionless]:'
497 if (st%nik > ns)
then
503 safe_allocate(ang(1:nst, 1:st%nik, 1:3))
504 safe_allocate(ang2(1:nst, 1:st%nik))
509 k_start = st%d%kpt%start
516 if (st%d%kpt%parallel)
then
517 k_n = st%d%kpt%nlocal
519 assert(.not. st%parallel_in_states)
522 safe_allocate(lang(1:st%lnst, 1:k_n))
524 lang(1:st%lnst, 1:k_n) = ang(st_start:st_end, k_start:k_end, idir)
525 call st%d%kpt%mpi_grp%allgatherv(lang, nst*k_n, mpi_double_precision, ang(:, :, idir), &
526 st%d%kpt%num(:)*nst, (st%d%kpt%range(1, :) - 1)*nst, mpi_double_precision)
528 lang(1:st%lnst, 1:k_n) = ang2(st_start:st_end, k_start:k_end)
529 call st%d%kpt%mpi_grp%allgatherv(lang, nst*k_n, mpi_double_precision, ang2, &
530 st%d%kpt%num(:)*nst, (st%d%kpt%range(1, :) - 1)*nst, mpi_double_precision)
531 safe_deallocate_a(lang)
534 if (st%parallel_in_states)
then
535 safe_allocate(lang(1:st%lnst, 1))
538 do ik = 1, st%nik, ns
539 if (st%nik > ns)
then
541 kpoint(:) = kpoints%get_point(st%d%get_kpoint_index(ik))
543 write(
message(1),
'(a,i4, a)')
'#k =', ik,
', k = ('
547 if (idir == dim)
then
557 if (st%parallel_in_states)
then
558 assert(.not. st%d%kpt%parallel)
562 lang(1:st%lnst, 1) = ang(st_start:st_end, ik+is-1, idir)
565 lang(1:st%lnst, 1) = ang2(st_start:st_end, ik+is-1)
571 write(
message(1),
'(a4,1x,a5,4a12,4x,a12,1x)') &
572 '#st',
' Spin',
' <Lx>',
' <Ly>',
' <Lz>',
' <L2>',
'Occupation '
579 if (is == 0) cspin =
'up'
580 if (is == 1) cspin =
'dn'
583 write(tmp_str(1),
'(i4,3x,a2)') ist, trim(cspin)
584 write(tmp_str(2),
'(1x,4f12.6,3x,f12.6)') &
585 (ang(ist, ik+is, idir), idir = 1, 3), ang2(ist, ik+is), st%occ(ist, ik+is)
586 message(1) = trim(tmp_str(1))//trim(tmp_str(2))
596 write(
message(1),
'(a)')
'Total Angular Momentum L [dimensionless]'
597 write(
message(2),
'(10x,4f12.6)') angular(1:3), lsquare
602 if (st%parallel_in_states)
then
603 safe_deallocate_a(lang)
606 safe_deallocate_a(ang)
607 safe_deallocate_a(ang2)
613 type(
grid_t),
intent(in) :: gr
615 type(
space_t),
intent(in) :: space
616 character(len=*),
intent(in) :: dir
619 type(
ions_t),
intent(in) :: ions
620 integer,
intent(in) :: st_start, st_end
622 integer :: ik, idir, ist, jst, iunit
623 character(len=256) :: fname
624 real(real64),
allocatable :: ddip_elements(:,:,:)
625 complex(real64),
allocatable :: zdip_elements(:,:,:)
630 do ik = st%d%kpt%start, st%d%kpt%end
631 write(fname,
'(i8)') ik
632 write(fname,
'(a)') trim(dir)//
'/ks_me_dipole.k'//trim(adjustl(fname))//
'_'
636 safe_allocate(ddip_elements(1:space%dim, st_start:st_end, st_start:st_end))
638 call dipole_me(gr, st, namespace, hm, ions, ik, st_start, st_end, ddip_elements)
640 do idir = 1, space%dim
642 write(iunit,
'(a)')
'# Dipole matrix elements file: |<Phi_i | r | Phi_j>|'
643 write(iunit,
'(a,i8)')
'# ik =', ik
646 do ist = st_start, st_end
647 do jst = st_start, st_end
649 write(iunit, fmt=
'(a)', advance =
'no')
' '
651 write(iunit,
'(a)')
''
655 safe_deallocate_a(ddip_elements)
658 safe_allocate(zdip_elements(1:space%dim, st_start:st_end, st_start:st_end))
660 call dipole_me(gr, st, namespace, hm, ions, ik, st_start, st_end, zdip_elements)
662 do idir = 1, space%dim
664 write(iunit,
'(a)')
'# Dipole matrix elements file: |<Phi_i | r | Phi_j>|'
665 write(iunit,
'(a,i8)')
'# ik =', ik
668 do ist = st_start, st_end
669 do jst = st_start, st_end
671 write(iunit, fmt=
'(a)', advance =
'no')
' '
673 write(iunit,
'(a)')
''
677 safe_deallocate_a(zdip_elements)
685 type(
grid_t),
intent(in) :: gr
687 type(
space_t),
intent(in) :: space
688 character(len=*),
intent(in) :: dir
692 integer :: id, ll, mm, ik, iunit
693 character(len=256) :: fname
694 real(real64),
allocatable :: delements(:,:)
695 complex(real64),
allocatable :: zelements(:,:)
702 select case (space%dim)
704 do ll = 1, this%ks_multipoles
707 write(fname,
'(i4)') id
708 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
709 iunit =
io_open(fname, namespace, action =
'write')
714 safe_allocate(delements(1:st%nst, 1:st%nst))
717 safe_deallocate_a(delements)
719 safe_allocate(zelements(1:st%nst, 1:st%nst))
722 safe_deallocate_a(zelements)
732 write(fname,
'(i4)') id
733 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
734 iunit =
io_open(fname, namespace, action =
'write')
739 safe_allocate(delements(1:st%nst, 1:st%nst))
742 safe_deallocate_a(delements)
744 safe_allocate(zelements(1:st%nst, 1:st%nst))
747 safe_deallocate_a(zelements)
754 do ll = 1, this%ks_multipoles
756 write(fname,
'(i4)') id
757 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
758 iunit =
io_open(fname, namespace, action =
'write')
763 safe_allocate(delements(1:st%nst, 1:st%nst))
766 safe_deallocate_a(delements)
768 safe_allocate(zelements(1:st%nst, 1:st%nst))
771 safe_deallocate_a(zelements)
785 integer,
intent(in) :: iunit, ll, mm, ik
787 write(iunit, fmt =
'(a)')
'# Multipole matrix elements file: <Phi_i | r**l * Y_{lm}(theta,phi) | Phi_j>'
788 write(iunit, fmt =
'(a,i2,a,i2)')
'# l =', ll,
'; m =', mm
789 write(iunit, fmt =
'(a,i8)')
'# ik =', ik
798 integer,
intent(in) :: iunit, nst
799 real(real64),
intent(in) :: elements(:,:)
800 integer,
optional,
intent(in) :: ll
803 real(real64) :: element
808 write(iunit, fmt=
'(f20.12, a)', advance =
'no') element,
' '
810 write(iunit,
'(a)')
''
815 integer,
intent(in) :: iunit, nst
816 complex(real64),
intent(in) :: elements(:,:)
817 integer,
optional,
intent(in) :: ll
820 complex(real64) :: element
825 write(iunit, fmt=
'(f20.12,a1,f20.12,a)', advance =
'no') real(element),
',',aimag(element),
' '
827 write(iunit,
'(a)')
''
838#include "complex.F90"
subroutine, public elec_angular_momentum_me(gr, st, space, ll, l2)
subroutine, public elec_momentum_me(gr, st, space, kpoints, momentum)
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_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
This module contains some common usage patterns of MPI routines.
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
type(mpi_grp_t), public mpi_world
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_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, 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)
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.