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
180 call this%elec_me%init(gr, space, st, this%st_start, this%st_end)
187 subroutine output_me(this, namespace, space, dir, st, gr, ions, hm)
190 class(
space_t),
intent(in) :: space
191 character(len=*),
intent(in) :: dir
193 type(
grid_t),
intent(in) :: gr
194 type(
ions_t),
intent(in) :: ions
197 integer :: id, ll, iunit
198 character(len=256) :: fname
199 real(real64),
allocatable :: doneint(:), dtwoint(:)
200 complex(real64),
allocatable :: zoneint(:), ztwoint(:)
201 integer,
allocatable :: iindex(:,:), jindex(:,:), kindex(:,:), lindex(:,:)
206 if (this%what(option__outputmatrixelements__momentum))
then
207 write(fname,
'(2a)') trim(dir),
'/ks_me_momentum'
211 if (this%what(option__outputmatrixelements__ang_momentum))
then
212 write(fname,
'(2a)') trim(dir),
'/ks_me_angular_momentum'
216 if (this%what(option__outputmatrixelements__ks_multipoles))
then
220 if (this%what(option__outputmatrixelements__dipole))
then
221 assert(.not. st%parallel_in_states)
225 if (this%what(option__outputmatrixelements__one_body))
then
226 message(1) =
"Computing one-body matrix elements"
229 if (st%parallel_in_states)
call messages_not_implemented(
"OutputMatrixElements=one_body with states parallelization", &
231 if (st%d%kpt%parallel)
call messages_not_implemented(
"OutputMatrixElements=one_body with k-points parallelization", &
237 iunit =
io_open(trim(dir)//
'/output_me_one_body', namespace, action=
'write')
239 id = st%nst*(st%nst+1)/2
241 safe_allocate(iindex(1:id,1))
242 safe_allocate(jindex(1:id,1))
245 safe_allocate(doneint(1:id))
246 call this%elec_me%one_body_me(namespace, hm, iindex(:,1), jindex(:,1), doneint)
249 write(iunit, *) iindex(ll,1), jindex(ll,1), doneint(ll)
252 safe_deallocate_a(doneint)
254 safe_allocate(zoneint(1:id))
255 call this%elec_me%one_body_me(namespace, hm, iindex(:,1), jindex(:,1), zoneint)
258 write(iunit, *) iindex(ll,1), jindex(ll,1), zoneint(ll)
261 safe_deallocate_a(zoneint)
264 safe_deallocate_a(iindex)
265 safe_deallocate_a(jindex)
269 if (this%what(option__outputmatrixelements__two_body) .or. this%what(option__outputmatrixelements__two_body_exc_k))
then
270 message(1) =
"Computing two-body matrix elements"
273 assert(.not. st%parallel_in_states)
274 if (this%what(option__outputmatrixelements__two_body))
then
275 if (st%parallel_in_states)
then
278 if (st%d%kpt%parallel)
then
282 iunit =
io_open(trim(dir)//
'/output_me_two_body', namespace, action=
'write')
284 write(iunit,
'(a)')
'# (n1, k1) (n2, k2) (n3, k3) (n4, k4) (n1-k1, n2-k2|n3-k3, n4-k4)'
287 if (st%parallel_in_states)
then
288 call messages_not_implemented(
"OutputMatrixElements=two_body_exc_k with states parallelization", namespace=namespace)
290 if (st%d%kpt%parallel)
then
291 call messages_not_implemented(
"OutputMatrixElements=two_body_exc_k with k-points parallelization", namespace=namespace)
294 iunit =
io_open(trim(dir)//
'/output_me_two_body_density', namespace, action=
'write')
296 write(iunit,
'(a)')
'#(n1, k1) (n2, k2) (n1-k1, n1-k2|n2-k2, n2-k1)'
300 if (this%what(option__outputmatrixelements__two_body))
then
302 id = st%nik*this%nst*(st%nik*this%nst+1)*(st%nik**2*this%nst**2+st%nik*this%nst+2)/8
304 id = (st%nik*this%nst)**4
307 id = (st%nik*this%nst)**2
314 safe_allocate(iindex(1:2, 1:id))
315 safe_allocate(jindex(1:2, 1:id))
316 safe_allocate(kindex(1:2, 1:id))
317 safe_allocate(lindex(1:2, 1:id))
320 safe_allocate(dtwoint(1:id))
321 call this%elec_me%two_body_me(namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, &
322 iindex, jindex, kindex, lindex, dtwoint)
325 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)
328 safe_deallocate_a(dtwoint)
330 safe_allocate(ztwoint(1:id))
331 if (hm%phase%is_allocated())
then
333 assert(.not. st%d%kpt%parallel)
334 call this%elec_me%two_body_me(namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, iindex, jindex, &
335 kindex, lindex, ztwoint, phase = hm%phase, singularity = singul, &
336 exc_k = (this%what(option__outputmatrixelements__two_body_exc_k)))
338 call this%elec_me%two_body_me(namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, &
339 iindex, jindex, kindex, lindex, ztwoint, exc_k = (this%what(option__outputmatrixelements__two_body_exc_k)))
343 if (this%what(option__outputmatrixelements__two_body))
then
345 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)
349 write(iunit,
'(2(i4,i5),2es22.12)') iindex(1:2,ll), kindex(1:2,ll), ztwoint(ll)
353 safe_deallocate_a(ztwoint)
356 safe_deallocate_a(iindex)
357 safe_deallocate_a(jindex)
358 safe_deallocate_a(kindex)
359 safe_deallocate_a(lindex)
373 character(len=*),
intent(in) :: fname
378 integer :: ik, ist, is, ns, iunit, idir, dim
379 character(len=80) :: cspin, str_tmp
380 real(real64) :: kpoint(elec_me%space%dim)
381 real(real64),
allocatable :: momentum(:,:,:)
385 dim = elec_me%space%dim
387 safe_allocate(momentum(1:dim, 1:elec_me%states%nst, 1:elec_me%states%nik))
390 call elec_me%momentum_me(kpoints, momentum)
392 iunit =
io_open(fname, namespace, action=
'write')
395 if (elec_me%states%d%nspin == 2) ns = 2
397 write(
message(1),
'(a)')
'Momentum of the KS states [a.u.]:'
399 if (elec_me%states%nik > ns)
then
404 do ik = 1, elec_me%states%nik, ns
405 kpoint(:) = kpoints%get_point(elec_me%states%d%get_kpoint_index(ik))
407 if (elec_me%states%nik > ns)
then
408 write(
message(1),
'(a,i4, a)')
'#k =', ik,
', k = ('
412 if (idir == dim)
then
421 write(
message(1),
'(a4,1x,a5)')
'#st',
' Spin'
423 write(str_tmp,
'(a,a1,a)')
' <p',
index2axis(idir),
'>'
426 write(str_tmp,
'(4x,a12,1x)')
'Occupation '
430 do ist = 1, elec_me%states%nst
433 if (is == 0) cspin =
'up'
434 if (is == 1) cspin =
'dn'
435 if (elec_me%states%d%ispin ==
unpolarized .or. elec_me%states%d%ispin ==
spinors) cspin =
'--'
437 write(
message(1),
'(i4,3x,a2,1x)') ist, trim(cspin)
439 write(str_tmp,
'(f12.6)') momentum(idir, ist, ik+is)
442 write(str_tmp,
'(3x,f12.6)') elec_me%states%occ(ist, ik+is)
454 safe_deallocate_a(momentum)
463 character(len=*),
intent(in) :: fname
468 integer :: iunit, ik, ist, is, ns, idir, k_start, k_end, k_n, dim, st_start, st_end, nst
469 character(len=80) :: tmp_str(elec_me%space%dim), cspin
470 real(real64) :: angular(3), lsquare, kpoint(elec_me%space%dim)
471 real(real64),
allocatable :: ang(:, :, :), ang2(:, :)
475 real(real64),
allocatable :: lang(:, :)
480 if (elec_me%states%d%nspin == 2) ns = 2
481 assert(elec_me%space%dim == 3)
483 dim = elec_me%space%dim
484 st_start = elec_me%states%st_start
485 st_end = elec_me%states%st_end
486 nst = elec_me%states%nst
488 iunit =
io_open(fname, namespace, action=
'write')
491 write(iunit,
'(a)')
'Warning: When non-local pseudopotentials are used '
492 write(iunit,
'(a)')
' the numbers below may be meaningless. '
493 write(iunit,
'(a)')
' '
494 write(iunit,
'(a)')
'Angular Momentum of the KS states [dimensionless]:'
496 if (elec_me%states%nik > ns)
then
502 safe_allocate(ang(1:nst, 1:elec_me%states%nik, 1:3))
503 safe_allocate(ang2(1:nst, 1:elec_me%states%nik))
506 call elec_me%angular_momentum_me(ang, ang2)
508 k_start = elec_me%states%d%kpt%start
509 k_end = elec_me%states%d%kpt%end
515 if (elec_me%states%d%kpt%parallel)
then
516 k_n = elec_me%states%d%kpt%nlocal
518 assert(.not. elec_me%states%parallel_in_states)
521 safe_allocate(lang(1:elec_me%states%lnst, 1:k_n))
523 lang(1:elec_me%states%lnst, 1:k_n) = ang(st_start:st_end, k_start:k_end, idir)
524 call elec_me%states%d%kpt%mpi_grp%allgatherv(lang, nst*k_n, mpi_double_precision, ang(:, :, idir), &
525 elec_me%states%d%kpt%num(:)*nst, (elec_me%states%d%kpt%range(1, :) - 1)*nst, mpi_double_precision)
527 lang(1:elec_me%states%lnst, 1:k_n) = ang2(st_start:st_end, k_start:k_end)
528 call elec_me%states%d%kpt%mpi_grp%allgatherv(lang, nst*k_n, mpi_double_precision, ang2, &
529 elec_me%states%d%kpt%num(:)*nst, (elec_me%states%d%kpt%range(1, :) - 1)*nst, mpi_double_precision)
530 safe_deallocate_a(lang)
533 if (elec_me%states%parallel_in_states)
then
534 safe_allocate(lang(1:elec_me%states%lnst, 1))
537 do ik = 1, elec_me%states%nik, ns
538 if (elec_me%states%nik > ns)
then
540 kpoint(:) = kpoints%get_point(elec_me%states%d%get_kpoint_index(ik))
542 write(
message(1),
'(a,i4, a)')
'#k =', ik,
', k = ('
546 if (idir == dim)
then
556 if (elec_me%states%parallel_in_states)
then
557 assert(.not. elec_me%states%d%kpt%parallel)
561 lang(1:elec_me%states%lnst, 1) = ang(st_start:st_end, ik+is-1, idir)
562 call lmpi_gen_allgatherv(elec_me%states%lnst, lang(:, 1), tmp, ang(:, ik+is-1, idir), elec_me%states%mpi_grp)
564 lang(1:elec_me%states%lnst, 1) = ang2(st_start:st_end, ik+is-1)
565 call lmpi_gen_allgatherv(elec_me%states%lnst, lang(:, 1), tmp, ang2(:, ik+is-1), elec_me%states%mpi_grp)
570 write(
message(1),
'(a4,1x,a5,4a12,4x,a12,1x)') &
571 '#st',
' Spin',
' <Lx>',
' <Ly>',
' <Lz>',
' <L2>',
'Occupation '
578 if (is == 0) cspin =
'up'
579 if (is == 1) cspin =
'dn'
580 if (elec_me%states%d%ispin ==
unpolarized .or. elec_me%states%d%ispin ==
spinors) cspin =
'--'
582 write(tmp_str(1),
'(i4,3x,a2)') ist, trim(cspin)
583 write(tmp_str(2),
'(1x,4f12.6,3x,f12.6)') &
584 (ang(ist, ik+is, idir), idir = 1, 3), ang2(ist, ik+is), elec_me%states%occ(ist, ik+is)
585 message(1) = trim(tmp_str(1))//trim(tmp_str(2))
595 write(
message(1),
'(a)')
'Total Angular Momentum L [dimensionless]'
596 write(
message(2),
'(10x,4f12.6)') angular(1:3), lsquare
601 if (elec_me%states%parallel_in_states)
then
602 safe_deallocate_a(lang)
605 safe_deallocate_a(ang)
606 safe_deallocate_a(ang2)
612 character(len=*),
intent(in) :: dir
616 type(
ions_t),
intent(in) :: ions
618 integer :: ik, idir, ist, jst, iunit
619 character(len=256) :: fname
620 real(real64),
allocatable :: ddip_elements(:,:,:)
621 complex(real64),
allocatable :: zdip_elements(:,:,:)
626 do ik = elec_me%states%d%kpt%start, elec_me%states%d%kpt%end
627 write(fname,
'(i8)') ik
628 write(fname,
'(a)') trim(dir)//
'/ks_me_dipole.k'//trim(adjustl(fname))//
'_'
632 safe_allocate(ddip_elements(1:elec_me%space%dim, elec_me%st_start:elec_me%st_end, elec_me%st_start:elec_me%st_end))
634 call elec_me%dipole_me(namespace, hm, ions, ik, ddip_elements)
636 do idir = 1, elec_me%space%dim
638 write(iunit,
'(a)')
'# Dipole matrix elements file: |<Phi_i | r | Phi_j>|'
639 write(iunit,
'(a,i8)')
'# ik =', ik
642 do ist = elec_me%st_start, elec_me%st_end
643 do jst = elec_me%st_start, elec_me%st_end
645 write(iunit, fmt=
'(a)', advance =
'no')
' '
647 write(iunit,
'(a)')
''
651 safe_deallocate_a(ddip_elements)
654 safe_allocate(zdip_elements(1:elec_me%space%dim, elec_me%st_start:elec_me%st_end, elec_me%st_start:elec_me%st_end))
656 call elec_me%dipole_me(namespace, hm, ions, ik, zdip_elements)
658 do idir = 1, elec_me%space%dim
660 write(iunit,
'(a)')
'# Dipole matrix elements file: |<Phi_i | r | Phi_j>|'
661 write(iunit,
'(a,i8)')
'# ik =', ik
664 do ist = elec_me%st_start, elec_me%st_end
665 do jst = elec_me%st_start, elec_me%st_end
667 write(iunit, fmt=
'(a)', advance =
'no')
' '
669 write(iunit,
'(a)')
''
673 safe_deallocate_a(zdip_elements)
681 character(len=*),
intent(in) :: dir
686 integer :: id, ll, mm, ik, iunit
687 character(len=256) :: fname
688 real(real64),
allocatable :: delements(:,:)
689 complex(real64),
allocatable :: zelements(:,:)
695 do ik = 1, elec_me%states%nik
696 select case (elec_me%space%dim)
698 do ll = 1, this%ks_multipoles
701 write(fname,
'(i4)') id
702 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
703 iunit =
io_open(fname, namespace, action =
'write')
708 safe_allocate(delements(1:elec_me%states%nst, 1:elec_me%states%nst))
709 call elec_me%ks_multipoles_3d(ll, mm, ik, delements)
711 safe_deallocate_a(delements)
713 safe_allocate(zelements(1:elec_me%states%nst, 1:elec_me%states%nst))
714 call elec_me%ks_multipoles_3d(ll, mm, ik, zelements)
716 safe_deallocate_a(zelements)
726 write(fname,
'(i4)') id
727 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
728 iunit =
io_open(fname, namespace, action =
'write')
733 safe_allocate(delements(1:elec_me%states%nst, 1:elec_me%states%nst))
734 call elec_me%ks_multipoles_2d(ll, ik, delements)
736 safe_deallocate_a(delements)
738 safe_allocate(zelements(1:elec_me%states%nst, 1:elec_me%states%nst))
739 call elec_me%ks_multipoles_2d(ll, ik, zelements)
741 safe_deallocate_a(zelements)
748 do ll = 1, this%ks_multipoles
750 write(fname,
'(i4)') id
751 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
752 iunit =
io_open(fname, namespace, action =
'write')
757 safe_allocate(delements(1:elec_me%states%nst, 1:elec_me%states%nst))
758 call elec_me%ks_multipoles_1d(ll, ik, delements)
760 safe_deallocate_a(delements)
762 safe_allocate(zelements(1:elec_me%states%nst, 1:elec_me%states%nst))
763 call elec_me%ks_multipoles_1d(ll, ik, zelements)
765 safe_deallocate_a(zelements)
779 integer,
intent(in) :: iunit, ll, mm, ik
781 write(iunit, fmt =
'(a)')
'# Multipole matrix elements file: <Phi_i | r**l * Y_{lm}(theta,phi) | Phi_j>'
782 write(iunit, fmt =
'(a,i2,a,i2)')
'# l =', ll,
'; m =', mm
783 write(iunit, fmt =
'(a,i8)')
'# ik =', ik
792 integer,
intent(in) :: iunit, nst
793 real(real64),
intent(in) :: elements(:,:)
794 integer,
optional,
intent(in) :: ll
797 real(real64) :: element
802 write(iunit, fmt=
'(f20.12, a)', advance =
'no') element,
' '
804 write(iunit,
'(a)')
''
809 integer,
intent(in) :: iunit, nst
810 complex(real64),
intent(in) :: elements(:,:)
811 integer,
optional,
intent(in) :: ll
814 complex(real64) :: element
819 write(iunit, fmt=
'(f20.12,a1,f20.12,a)', advance =
'no') real(element),
',',aimag(element),
' '
821 write(iunit,
'(a)')
''
832#include "complex.F90"
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 output system
subroutine output_me_out_momentum(fname, elec_me, namespace, kpoints)
subroutine output_me_out_ks_multipoles(dir, this, elec_me, namespace)
subroutine output_me_out_ang_momentum(fname, elec_me, namespace, kpoints)
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_dipole(dir, elec_me, namespace, hm, ions)
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.
The states_elec_t class contains all electronic wave functions.