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 /= 2 .and. 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)
284 if (this%what(option__outputmatrixelements__two_body))
then
285 if (st%parallel_in_states)
then
288 if (st%d%kpt%parallel)
then
292 iunit =
io_open(trim(dir)//
'/output_me_two_body', namespace, action=
'write')
293 if (gr%mpi_grp%is_root())
then
294 write(iunit,
'(a)')
'# (n1, k1) (n2, k2) (n3, k3) (n4, k4) (n1-k1, n2-k2|n3-k3, n4-k4)'
297 if (st%parallel_in_states)
then
298 call messages_not_implemented(
"OutputMatrixElements=two_body_exc_k with states parallelization", namespace=namespace)
300 if (st%d%kpt%parallel)
then
301 call messages_not_implemented(
"OutputMatrixElements=two_body_exc_k with k-points parallelization", namespace=namespace)
304 iunit =
io_open(trim(dir)//
'/output_me_two_body_density', namespace, action=
'write')
305 if (gr%mpi_grp%is_root())
then
306 write(iunit,
'(a)')
'#(n1, k1) (n2, k2) (n1-k1, n1-k2|n2-k2, n2-k1)'
310 if (this%what(option__outputmatrixelements__two_body))
then
312 id = st%nik*this%nst*(st%nik*this%nst+1)*(st%nik**2*this%nst**2+st%nik*this%nst+2)/8
314 id = (st%nik*this%nst)**4
317 id = (st%nik*this%nst)**2
324 safe_allocate(iindex(1:2, 1:id))
325 safe_allocate(jindex(1:2, 1:id))
326 safe_allocate(kindex(1:2, 1:id))
327 safe_allocate(lindex(1:2, 1:id))
330 safe_allocate(dtwoint(1:id))
331 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, &
332 iindex, jindex, kindex, lindex, dtwoint)
333 if (gr%mpi_grp%is_root())
then
335 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)
338 safe_deallocate_a(dtwoint)
340 safe_allocate(ztwoint(1:id))
341 if (hm%phase%is_allocated())
then
343 assert(.not. st%d%kpt%parallel)
344 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, iindex, jindex, &
345 kindex, lindex, ztwoint, phase = hm%phase, singularity = singul, &
346 exc_k = (this%what(option__outputmatrixelements__two_body_exc_k)))
348 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, &
349 iindex, jindex, kindex, lindex, ztwoint, exc_k = (this%what(option__outputmatrixelements__two_body_exc_k)))
352 if (gr%mpi_grp%is_root())
then
353 if (this%what(option__outputmatrixelements__two_body))
then
355 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)
359 write(iunit,
'(2(i4,i5),2es22.12)') iindex(1:2,ll), kindex(1:2,ll), ztwoint(ll)
363 safe_deallocate_a(ztwoint)
366 safe_deallocate_a(iindex)
367 safe_deallocate_a(jindex)
368 safe_deallocate_a(kindex)
369 safe_deallocate_a(lindex)
383 type(
grid_t),
intent(in) :: gr
385 type(
space_t),
intent(in) :: space
386 character(len=*),
intent(in) :: fname
389 type(
ions_t),
intent(in) :: ions
390 logical,
optional,
intent(in) :: non_local
392 integer :: ik, ist, is, ns, iunit, idir, dim
393 character(len=80) :: cspin, str_tmp
394 real(real64) :: kpoint(space%dim)
395 real(real64),
allocatable :: momentum(:,:,:)
401 safe_allocate(momentum(1:dim, 1:st%nst, 1:st%nik))
404 call elec_momentum_me(namespace, gr, st, space, hm, ions, momentum, non_local)
406 iunit =
io_open(fname, namespace, action=
'write')
409 if (st%d%nspin == 2) ns = 2
412 write(
message(1),
'(a)')
'Velocity of the KS states [a.u.]:'
414 write(
message(1),
'(a)')
'Momentum of the KS states [a.u.]:'
417 if (st%nik > ns)
then
422 do ik = 1, st%nik, ns
423 kpoint(:) = hm%kpoints%get_point(st%d%get_kpoint_index(ik))
425 if (st%nik > ns)
then
426 write(
message(1),
'(a,i4, a)')
'#k =', ik,
', k = ('
430 if (idir == dim)
then
439 write(
message(1),
'(a4,1x,a5)')
'#st',
' Spin'
442 write(str_tmp,
'(a,a1,a)')
' <v',
index2axis(idir),
'>'
444 write(str_tmp,
'(a,a1,a)')
' <p',
index2axis(idir),
'>'
448 write(str_tmp,
'(4x,a12,1x)')
'Occupation '
455 if (is == 0) cspin =
'up'
456 if (is == 1) cspin =
'dn'
459 write(
message(1),
'(i4,3x,a2,1x)') ist, trim(cspin)
461 write(str_tmp,
'(f12.6)') momentum(idir, ist, ik+is)
464 write(str_tmp,
'(3x,f12.6)') st%occ(ist, ik+is)
476 safe_deallocate_a(momentum)
485 type(
grid_t),
intent(in) :: gr
487 type(
space_t),
intent(in) :: space
488 character(len=*),
intent(in) :: fname
492 integer :: iunit, ik, ist, is, ns, idir, k_start, k_end, k_n, dim, st_start, st_end, nst
493 character(len=80) :: tmp_str(space%dim), cspin
494 real(real64) :: angular(3), lsquare, kpoint(space%dim)
495 real(real64),
allocatable :: ang(:, :, :), ang2(:, :)
499 real(real64),
allocatable :: lang(:, :)
504 if (st%d%nspin == 2) ns = 2
505 assert(space%dim == 3)
508 st_start = st%st_start
512 iunit =
io_open(fname, namespace, action=
'write')
515 write(iunit,
'(a)')
'Warning: When non-local pseudopotentials are used '
516 write(iunit,
'(a)')
' the numbers below may be meaningless. '
517 write(iunit,
'(a)')
' '
518 write(iunit,
'(a)')
'Angular Momentum of the KS states [dimensionless]:'
520 if (st%nik > ns)
then
526 safe_allocate(ang(1:nst, 1:st%nik, 1:3))
527 safe_allocate(ang2(1:nst, 1:st%nik))
532 k_start = st%d%kpt%start
539 if (st%d%kpt%parallel)
then
540 k_n = st%d%kpt%nlocal
542 assert(.not. st%parallel_in_states)
545 safe_allocate(lang(1:st%lnst, 1:k_n))
547 lang(1:st%lnst, 1:k_n) = ang(st_start:st_end, k_start:k_end, idir)
548 call st%d%kpt%mpi_grp%allgatherv(lang, nst*k_n, mpi_double_precision, ang(:, :, idir), &
549 st%d%kpt%num(:)*nst, (st%d%kpt%range(1, :) - 1)*nst, mpi_double_precision)
551 lang(1:st%lnst, 1:k_n) = ang2(st_start:st_end, k_start:k_end)
552 call st%d%kpt%mpi_grp%allgatherv(lang, nst*k_n, mpi_double_precision, ang2, &
553 st%d%kpt%num(:)*nst, (st%d%kpt%range(1, :) - 1)*nst, mpi_double_precision)
554 safe_deallocate_a(lang)
557 if (st%parallel_in_states)
then
558 safe_allocate(lang(1:st%lnst, 1))
561 do ik = 1, st%nik, ns
562 if (st%nik > ns)
then
564 kpoint(:) = kpoints%get_point(st%d%get_kpoint_index(ik))
566 write(
message(1),
'(a,i4, a)')
'#k =', ik,
', k = ('
570 if (idir == dim)
then
580 if (st%parallel_in_states)
then
581 assert(.not. st%d%kpt%parallel)
585 lang(1:st%lnst, 1) = ang(st_start:st_end, ik+is-1, idir)
586 call lmpi_gen_allgatherv(st%lnst, lang(:, 1), tmp, ang(:, ik+is-1, idir), st%mpi_grp)
588 lang(1:st%lnst, 1) = ang2(st_start:st_end, ik+is-1)
589 call lmpi_gen_allgatherv(st%lnst, lang(:, 1), tmp, ang2(:, ik+is-1), st%mpi_grp)
594 write(
message(1),
'(a4,1x,a5,4a12,4x,a12,1x)') &
595 '#st',
' Spin',
' <Lx>',
' <Ly>',
' <Lz>',
' <L2>',
'Occupation '
602 if (is == 0) cspin =
'up'
603 if (is == 1) cspin =
'dn'
606 write(tmp_str(1),
'(i4,3x,a2)') ist, trim(cspin)
607 write(tmp_str(2),
'(1x,4f12.6,3x,f12.6)') &
608 (ang(ist, ik+is, idir), idir = 1, 3), ang2(ist, ik+is), st%occ(ist, ik+is)
609 message(1) = trim(tmp_str(1))//trim(tmp_str(2))
619 write(
message(1),
'(a)')
'Total Angular Momentum L [dimensionless]'
620 write(
message(2),
'(10x,4f12.6)') angular(1:3), lsquare
625 if (st%parallel_in_states)
then
626 safe_deallocate_a(lang)
629 safe_deallocate_a(ang)
630 safe_deallocate_a(ang2)
636 type(
grid_t),
intent(in) :: gr
638 type(
space_t),
intent(in) :: space
639 character(len=*),
intent(in) :: dir
642 type(
ions_t),
intent(in) :: ions
643 integer,
intent(in) :: st_start, st_end
645 integer :: ik, idir, ist, jst, iunit
646 character(len=256) :: fname
647 real(real64),
allocatable :: ddip_elements(:,:,:)
648 complex(real64),
allocatable :: zdip_elements(:,:,:)
653 do ik = st%d%kpt%start, st%d%kpt%end
654 write(fname,
'(i8)') ik
655 write(fname,
'(a)') trim(dir)//
'/ks_me_dipole.k'//trim(adjustl(fname))//
'_'
659 safe_allocate(ddip_elements(1:space%dim, st_start:st_end, st_start:st_end))
661 call dipole_me(gr, st, namespace, hm, ions, ik, st_start, st_end, ddip_elements)
663 do idir = 1, space%dim
665 write(iunit,
'(a)')
'# Dipole matrix elements file: |<Phi_i | r | Phi_j>|'
666 write(iunit,
'(a,i8)')
'# ik =', ik
669 do ist = st_start, st_end
670 do jst = st_start, st_end
672 write(iunit, fmt=
'(a)', advance =
'no')
' '
674 write(iunit,
'(a)')
''
678 safe_deallocate_a(ddip_elements)
681 safe_allocate(zdip_elements(1:space%dim, st_start:st_end, st_start:st_end))
683 call dipole_me(gr, st, namespace, hm, ions, ik, st_start, st_end, zdip_elements)
685 do idir = 1, space%dim
687 write(iunit,
'(a)')
'# Dipole matrix elements file: |<Phi_i | r | Phi_j>|'
688 write(iunit,
'(a,i8)')
'# ik =', ik
691 do ist = st_start, st_end
692 do jst = st_start, st_end
694 write(iunit, fmt=
'(a)', advance =
'no')
' '
696 write(iunit,
'(a)')
''
700 safe_deallocate_a(zdip_elements)
708 type(
grid_t),
intent(in) :: gr
710 type(
space_t),
intent(in) :: space
711 character(len=*),
intent(in) :: dir
715 integer :: id, ll, mm, ik, iunit
716 character(len=256) :: fname
717 real(real64),
allocatable :: delements(:,:)
718 complex(real64),
allocatable :: zelements(:,:)
725 select case (space%dim)
727 do ll = 1, this%ks_multipoles
730 write(fname,
'(i4)') id
731 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
732 iunit =
io_open(fname, namespace, action =
'write')
737 safe_allocate(delements(1:st%nst, 1:st%nst))
740 safe_deallocate_a(delements)
742 safe_allocate(zelements(1:st%nst, 1:st%nst))
745 safe_deallocate_a(zelements)
755 write(fname,
'(i4)') id
756 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
757 iunit =
io_open(fname, namespace, action =
'write')
762 safe_allocate(delements(1:st%nst, 1:st%nst))
765 safe_deallocate_a(delements)
767 safe_allocate(zelements(1:st%nst, 1:st%nst))
770 safe_deallocate_a(zelements)
777 do ll = 1, this%ks_multipoles
779 write(fname,
'(i4)') id
780 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
781 iunit =
io_open(fname, namespace, action =
'write')
786 safe_allocate(delements(1:st%nst, 1:st%nst))
789 safe_deallocate_a(delements)
791 safe_allocate(zelements(1:st%nst, 1:st%nst))
794 safe_deallocate_a(zelements)
808 integer,
intent(in) :: iunit, ll, mm, ik
810 write(iunit, fmt =
'(a)')
'# Multipole matrix elements file: <Phi_i | r**l * Y_{lm}(theta,phi) | Phi_j>'
811 write(iunit, fmt =
'(a,i2,a,i2)')
'# l =', ll,
'; m =', mm
812 write(iunit, fmt =
'(a,i8)')
'# ik =', ik
821 integer,
intent(in) :: iunit, nst
822 real(real64),
intent(in) :: elements(:,:)
823 integer,
optional,
intent(in) :: ll
826 real(real64) :: element
831 write(iunit, fmt=
'(f20.12, a)', advance =
'no') element,
' '
833 write(iunit,
'(a)')
''
838 integer,
intent(in) :: iunit, nst
839 complex(real64),
intent(in) :: elements(:,:)
840 integer,
optional,
intent(in) :: ll
843 complex(real64) :: element
848 write(iunit, fmt=
'(f20.12,a1,f20.12,a)', advance =
'no') real(element),
',',aimag(element),
' '
850 write(iunit,
'(a)')
''
861#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.
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_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.