LCOV - code coverage report
Current view: top level - src - rt_propagation_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:42dac4a) Lines: 99.1 % 233 231
Test Date: 2025-07-25 12:55:17 Functions: 61.5 % 13 8

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2025 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Types and set_get for real time propagation
      10              : !>        depending on runtype and diagonalization method different
      11              : !>        matrices are allocated
      12              : !>        exp_H_old, exp_H_new, mos_new, mos_old contain always
      13              : !>        real and imaginary parts of the matrices
      14              : !>        odd index = real part (alpha, beta spin)
      15              : !>        even index= imaginary part (alpha, beta spin)
      16              : !> \par History
      17              : !>      02.2014 switched to dbcsr matrices [Samuel Andermatt]
      18              : !> \author Florian Schiffmann 02.09
      19              : ! **************************************************************************************************
      20              : 
      21              : MODULE rt_propagation_types
      22              : 
      23              :    USE bibliography,                    ONLY: Kunert2003,&
      24              :                                               cite_reference
      25              :    USE cp_control_types,                ONLY: dft_control_type,&
      26              :                                               rtp_control_type
      27              :    USE cp_dbcsr_api,                    ONLY: dbcsr_create,&
      28              :                                               dbcsr_deallocate_matrix,&
      29              :                                               dbcsr_init_p,&
      30              :                                               dbcsr_p_type,&
      31              :                                               dbcsr_type
      32              :    USE cp_dbcsr_operations,             ONLY: dbcsr_allocate_matrix_set,&
      33              :                                               dbcsr_deallocate_matrix_set
      34              :    USE cp_fm_pool_types,                ONLY: cp_fm_pool_p_type,&
      35              :                                               fm_pool_get_el_struct
      36              :    USE cp_fm_struct,                    ONLY: cp_fm_struct_create,&
      37              :                                               cp_fm_struct_get,&
      38              :                                               cp_fm_struct_release,&
      39              :                                               cp_fm_struct_type
      40              :    USE cp_fm_types,                     ONLY: cp_fm_create,&
      41              :                                               cp_fm_release,&
      42              :                                               cp_fm_type
      43              :    USE cp_log_handling,                 ONLY: cp_to_string
      44              :    USE kinds,                           ONLY: dp
      45              :    USE qs_matrix_pools,                 ONLY: mpools_get,&
      46              :                                               qs_matrix_pools_type
      47              :    USE qs_mo_types,                     ONLY: get_mo_set,&
      48              :                                               mo_set_type
      49              : #include "./base/base_uses.f90"
      50              : 
      51              :    IMPLICIT NONE
      52              : 
      53              :    PRIVATE
      54              : 
      55              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'rt_propagation_types'
      56              : 
      57              :    TYPE rtp_rho_type
      58              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: new => NULL()
      59              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: old => NULL()
      60              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: next => NULL()
      61              :    END TYPE rtp_rho_type
      62              : 
      63              :    TYPE rtp_history_type
      64              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:, :)  :: rho_history => NULL()
      65              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: s_history => NULL()
      66              :       TYPE(cp_fm_type), POINTER, DIMENSION(:, :)    :: mo_history => NULL()
      67              :    END TYPE rtp_history_type
      68              : 
      69              :    TYPE rtp_mos_type
      70              :       TYPE(cp_fm_type), POINTER, DIMENSION(:)       :: new => NULL()
      71              :       TYPE(cp_fm_type), POINTER, DIMENSION(:)       :: old => NULL()
      72              :       TYPE(cp_fm_type), POINTER, DIMENSION(:)       :: next => NULL()
      73              :       TYPE(cp_fm_type), POINTER, DIMENSION(:)       :: admm => NULL()
      74              :    END TYPE rtp_mos_type
      75              : 
      76              :    TYPE rt_prop_type
      77              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: exp_H_old => NULL()
      78              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: exp_H_new => NULL()
      79              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: H_last_iter => NULL()
      80              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: propagator_matrix => NULL()
      81              :       TYPE(dbcsr_type), POINTER                     :: S_inv => NULL()
      82              :       TYPE(dbcsr_type), POINTER                     :: S_half => NULL()
      83              :       TYPE(dbcsr_type), POINTER                     :: S_minus_half => NULL()
      84              :       TYPE(dbcsr_type), POINTER                     :: B_mat => NULL()
      85              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: C_mat => NULL()
      86              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: S_der => NULL()
      87              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: SinvH => NULL()
      88              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: SinvH_imag => NULL()
      89              :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:)     :: SinvB => NULL()
      90              :       TYPE(rtp_rho_type), POINTER                   :: rho => NULL()
      91              :       TYPE(rtp_mos_type), POINTER                   :: mos => NULL()
      92              :       REAL(KIND=dp)                                 :: energy_old = 0.0_dp
      93              :       REAL(KIND=dp)                                 :: energy_new = 0.0_dp
      94              :       REAL(KIND=dp)                                 :: dt = 0.0_dp
      95              :       REAL(KIND=dp)                                 :: delta_iter = 0.0_dp
      96              :       REAL(KIND=dp)                                 :: delta_iter_old = 0.0_dp
      97              :       REAL(KIND=dp)                                 :: filter_eps = 0.0_dp
      98              :       REAL(KIND=dp)                                 :: filter_eps_small = 0.0_dp
      99              :       REAL(KIND=dp)                                 :: mixing_factor = 0.0_dp
     100              :       LOGICAL                                       :: mixing = .FALSE.
     101              :       LOGICAL                                       :: do_hfx = .FALSE.
     102              :       LOGICAL                                       :: propagate_complex_ks = .FALSE.
     103              :       LOGICAL                                       :: track_imag_density = .FALSE.
     104              :       INTEGER, DIMENSION(:, :), ALLOCATABLE         :: orders
     105              :       INTEGER                                       :: nsteps = -1
     106              :       INTEGER                                       :: istep = -1
     107              :       INTEGER                                       :: i_start = -1
     108              :       INTEGER                                       :: max_steps = -1
     109              :       INTEGER                                       :: iter = -1
     110              :       INTEGER                                       :: narn_old = -1
     111              :       LOGICAL                                       :: converged = .FALSE.
     112              :       LOGICAL                                       :: matrix_update = .FALSE.
     113              :       LOGICAL                                       :: write_restart = .FALSE.
     114              :       TYPE(rtp_history_type), POINTER               :: history => NULL()
     115              :       TYPE(cp_fm_struct_type), POINTER              :: ao_ao_fmstruct => NULL()
     116              :       INTEGER                                       :: lanzcos_max_iter = -1
     117              :       REAL(KIND=dp)                                 :: lanzcos_threshold = 0.0_dp
     118              :       INTEGER                                       :: newton_schulz_order = -1
     119              :       LOGICAL                                       :: linear_scaling = .FALSE.
     120              :    END TYPE rt_prop_type
     121              : 
     122              : ! *** Public data types ***
     123              : 
     124              :    PUBLIC :: rt_prop_type
     125              : 
     126              : ! *** Public subroutines ***
     127              : 
     128              :    PUBLIC :: rt_prop_create, &
     129              :              rtp_create_SinvH_imag, &
     130              :              rt_prop_create_mos, &
     131              :              get_rtp, &
     132              :              rt_prop_release, &
     133              :              rt_prop_release_mos, &
     134              :              rtp_history_create
     135              : CONTAINS
     136              : 
     137              : ! **************************************************************************************************
     138              : !> \brief ...
     139              : !> \param rtp ...
     140              : !> \param mos ...
     141              : !> \param mpools ...
     142              : !> \param dft_control ...
     143              : !> \param template ...
     144              : !> \param linear_scaling ...
     145              : !> \param mos_aux ...
     146              : ! **************************************************************************************************
     147          198 :    SUBROUTINE rt_prop_create(rtp, mos, mpools, dft_control, template, linear_scaling, mos_aux)
     148              : 
     149              :       TYPE(rt_prop_type), POINTER                        :: rtp
     150              :       TYPE(mo_set_type), DIMENSION(:), INTENT(IN)        :: mos
     151              :       TYPE(qs_matrix_pools_type), POINTER                :: mpools
     152              :       TYPE(dft_control_type), POINTER                    :: dft_control
     153              :       TYPE(dbcsr_type), POINTER                          :: template
     154              :       LOGICAL, INTENT(IN)                                :: linear_scaling
     155              :       TYPE(mo_set_type), DIMENSION(:), OPTIONAL, POINTER :: mos_aux
     156              : 
     157              :       INTEGER                                            :: i, nspin
     158              :       TYPE(rtp_control_type), POINTER                    :: rtp_control
     159              : 
     160          198 :       CALL cite_reference(Kunert2003)
     161              : 
     162          198 :       NULLIFY (rtp_control)
     163              : 
     164          198 :       rtp_control => dft_control%rtp_control
     165              : 
     166          198 :       nspin = dft_control%nspins
     167              : 
     168          198 :       NULLIFY (rtp%mos, rtp%rho)
     169          198 :       rtp%linear_scaling = linear_scaling
     170              : 
     171          198 :       IF (rtp%linear_scaling) THEN
     172           90 :          ALLOCATE (rtp%rho)
     173           90 :          NULLIFY (rtp%rho%old)
     174           90 :          CALL dbcsr_allocate_matrix_set(rtp%rho%old, 2*nspin)
     175           90 :          NULLIFY (rtp%rho%next)
     176           90 :          CALL dbcsr_allocate_matrix_set(rtp%rho%next, 2*nspin)
     177           90 :          NULLIFY (rtp%rho%new)
     178           90 :          CALL dbcsr_allocate_matrix_set(rtp%rho%new, 2*nspin)
     179          346 :          DO i = 1, 2*nspin
     180          256 :             CALL dbcsr_init_p(rtp%rho%old(i)%matrix)
     181          256 :             CALL dbcsr_create(rtp%rho%old(i)%matrix, template=template, matrix_type="N")
     182          256 :             CALL dbcsr_init_p(rtp%rho%next(i)%matrix)
     183          256 :             CALL dbcsr_create(rtp%rho%next(i)%matrix, template=template, matrix_type="N")
     184          256 :             CALL dbcsr_init_p(rtp%rho%new(i)%matrix)
     185          346 :             CALL dbcsr_create(rtp%rho%new(i)%matrix, template=template, matrix_type="N")
     186              :          END DO
     187              :       ELSE
     188          108 :          IF (PRESENT(mos_aux)) THEN
     189           26 :             CALL rt_prop_create_mos(rtp, mos, mpools, dft_control, mos_aux)
     190              :          ELSE
     191           82 :             CALL rt_prop_create_mos(rtp, mos, mpools, dft_control)
     192              :          END IF
     193              :       END IF
     194              : 
     195          198 :       NULLIFY (rtp%exp_H_old)
     196          198 :       NULLIFY (rtp%exp_H_new)
     197          198 :       NULLIFY (rtp%H_last_iter)
     198          198 :       NULLIFY (rtp%propagator_matrix)
     199          198 :       CALL dbcsr_allocate_matrix_set(rtp%exp_H_old, 2*nspin)
     200          198 :       CALL dbcsr_allocate_matrix_set(rtp%exp_H_new, 2*nspin)
     201          198 :       CALL dbcsr_allocate_matrix_set(rtp%H_last_iter, 2*nspin)
     202          198 :       CALL dbcsr_allocate_matrix_set(rtp%propagator_matrix, 2*nspin)
     203          730 :       DO i = 1, 2*nspin
     204          532 :          CALL dbcsr_init_p(rtp%exp_H_old(i)%matrix)
     205          532 :          CALL dbcsr_create(rtp%exp_H_old(i)%matrix, template=template, matrix_type="N")
     206          532 :          CALL dbcsr_init_p(rtp%exp_H_new(i)%matrix)
     207          532 :          CALL dbcsr_create(rtp%exp_H_new(i)%matrix, template=template, matrix_type="N")
     208          532 :          CALL dbcsr_init_p(rtp%H_last_iter(i)%matrix)
     209          532 :          CALL dbcsr_create(rtp%H_last_iter(i)%matrix, template=template, matrix_type="N")
     210          532 :          CALL dbcsr_init_p(rtp%propagator_matrix(i)%matrix)
     211          730 :          CALL dbcsr_create(rtp%propagator_matrix(i)%matrix, template=template, matrix_type="N")
     212              :       END DO
     213          198 :       NULLIFY (rtp%S_inv)
     214          198 :       ALLOCATE (rtp%S_inv)
     215          198 :       CALL dbcsr_create(rtp%S_inv, template=template, matrix_type="S")
     216          198 :       NULLIFY (rtp%S_half)
     217          198 :       ALLOCATE (rtp%S_half)
     218          198 :       CALL dbcsr_create(rtp%S_half, template=template, matrix_type="S")
     219          198 :       NULLIFY (rtp%S_minus_half)
     220          198 :       ALLOCATE (rtp%S_minus_half)
     221          198 :       CALL dbcsr_create(rtp%S_minus_half, template=template, matrix_type="S")
     222          198 :       NULLIFY (rtp%B_mat)
     223          198 :       NULLIFY (rtp%C_mat)
     224          198 :       NULLIFY (rtp%S_der)
     225          198 :       NULLIFY (rtp%SinvH)
     226          198 :       NULLIFY (rtp%SinvB)
     227          198 :       IF (.NOT. rtp_control%fixed_ions) THEN
     228           72 :          ALLOCATE (rtp%B_mat)
     229           72 :          CALL dbcsr_create(rtp%B_mat, template=template, matrix_type="N")
     230           72 :          CALL dbcsr_allocate_matrix_set(rtp%C_mat, 3)
     231           72 :          CALL dbcsr_allocate_matrix_set(rtp%S_der, 9)
     232           72 :          CALL dbcsr_allocate_matrix_set(rtp%SinvH, nspin)
     233           72 :          CALL dbcsr_allocate_matrix_set(rtp%SinvB, nspin)
     234          156 :          DO i = 1, nspin
     235           84 :             CALL dbcsr_init_p(rtp%SinvH(i)%matrix)
     236           84 :             CALL dbcsr_create(rtp%SinvH(i)%matrix, template=template, matrix_type="N")
     237           84 :             CALL dbcsr_init_p(rtp%SinvB(i)%matrix)
     238          156 :             CALL dbcsr_create(rtp%SinvB(i)%matrix, template=template, matrix_type="N")
     239              :          END DO
     240          288 :          DO i = 1, 3
     241          216 :             CALL dbcsr_init_p(rtp%C_mat(i)%matrix)
     242          288 :             CALL dbcsr_create(rtp%C_mat(i)%matrix, template=template, matrix_type="N")
     243              :          END DO
     244          720 :          DO i = 1, 9
     245          648 :             CALL dbcsr_init_p(rtp%S_der(i)%matrix)
     246          720 :             CALL dbcsr_create(rtp%S_der(i)%matrix, template=template, matrix_type="N")
     247              :          END DO
     248              :       END IF
     249          594 :       ALLOCATE (rtp%orders(2, nspin))
     250          198 :       rtp_control%converged = .FALSE.
     251          198 :       rtp%matrix_update = .TRUE.
     252          198 :       rtp%narn_old = 0
     253          198 :       rtp%istep = 0
     254          198 :       rtp%iter = 0
     255          198 :       rtp%do_hfx = .FALSE.
     256          198 :       rtp%track_imag_density = .FALSE.
     257              : 
     258          198 :    END SUBROUTINE rt_prop_create
     259              : 
     260              : ! **************************************************************************************************
     261              : !> \brief Initialize SinvH_imag for rtp
     262              : !> \param rtp ...
     263              : !> \param nspins ...
     264              : ! **************************************************************************************************
     265           22 :    SUBROUTINE rtp_create_SinvH_imag(rtp, nspins)
     266              :       TYPE(rt_prop_type), INTENT(INOUT)                  :: rtp
     267              :       INTEGER                                            :: nspins
     268              : 
     269              :       INTEGER                                            :: i
     270              : 
     271           22 :       NULLIFY (rtp%SinvH_imag)
     272           22 :       CALL dbcsr_allocate_matrix_set(rtp%SinvH_imag, nspins)
     273           46 :       DO i = 1, nspins
     274           24 :          CALL dbcsr_init_p(rtp%SinvH_imag(i)%matrix)
     275           46 :          CALL dbcsr_create(rtp%SinvH_imag(i)%matrix, template=rtp%SinvH(1)%matrix, matrix_type="N")
     276              :       END DO
     277              : 
     278           22 :    END SUBROUTINE rtp_create_SinvH_imag
     279              : 
     280              : ! **************************************************************************************************
     281              : !> \brief Initialize the mos for rtp
     282              : !> \param rtp ...
     283              : !> \param mos ...
     284              : !> \param mpools ...
     285              : !> \param dft_control ...
     286              : !> \param mos_aux ...
     287              : !> \param init_mos_old ...
     288              : !> \param init_mos_new ...
     289              : !> \param init_mos_next ...
     290              : !> \param init_mos_admn ...
     291              : ! **************************************************************************************************
     292          148 :    SUBROUTINE rt_prop_create_mos(rtp, mos, mpools, dft_control, mos_aux, init_mos_old, &
     293              :                                  init_mos_new, init_mos_next, init_mos_admn)
     294              :       TYPE(rt_prop_type), POINTER                        :: rtp
     295              :       TYPE(mo_set_type), DIMENSION(:), INTENT(IN)        :: mos
     296              :       TYPE(qs_matrix_pools_type), POINTER                :: mpools
     297              :       TYPE(dft_control_type), POINTER                    :: dft_control
     298              :       TYPE(mo_set_type), DIMENSION(:), OPTIONAL, POINTER :: mos_aux
     299              :       LOGICAL, OPTIONAL                                  :: init_mos_old, init_mos_new, &
     300              :                                                             init_mos_next, init_mos_admn
     301              : 
     302              :       INTEGER                                            :: i, j, nao, nrow_block, nspin
     303              :       LOGICAL                                            :: my_mos_admn, my_mos_new, my_mos_next, &
     304              :                                                             my_mos_old
     305          148 :       TYPE(cp_fm_pool_p_type), DIMENSION(:), POINTER     :: ao_mo_fm_pools
     306              :       TYPE(cp_fm_struct_type), POINTER                   :: ao_mo_fmstruct
     307              : 
     308          148 :       IF (PRESENT(init_mos_old)) THEN
     309           40 :          my_mos_old = init_mos_old
     310              :       ELSE
     311              :          my_mos_old = .TRUE.
     312              :       END IF
     313              : 
     314          148 :       IF (PRESENT(init_mos_new)) THEN
     315           40 :          my_mos_new = init_mos_new
     316              :       ELSE
     317              :          my_mos_new = .TRUE.
     318              :       END IF
     319              : 
     320          148 :       IF (PRESENT(init_mos_next)) THEN
     321           40 :          my_mos_next = init_mos_next
     322              :       ELSE
     323              :          my_mos_next = .TRUE.
     324              :       END IF
     325              : 
     326          148 :       IF (PRESENT(init_mos_admn)) THEN
     327           40 :          my_mos_admn = init_mos_admn
     328              :       ELSE
     329              :          my_mos_admn = .TRUE.
     330              :       END IF
     331              : 
     332          148 :       nspin = dft_control%nspins
     333          148 :       CALL mpools_get(mpools, ao_mo_fm_pools=ao_mo_fm_pools)
     334          148 :       ao_mo_fmstruct => fm_pool_get_el_struct(ao_mo_fm_pools(1)%pool)
     335          148 :       CALL cp_fm_struct_get(ao_mo_fmstruct, nrow_block=nrow_block)
     336          148 :       CALL get_mo_set(mos(1), nao=nao)
     337              : 
     338              :       CALL cp_fm_struct_create(fmstruct=rtp%ao_ao_fmstruct, &
     339              :                                nrow_block=nrow_block, ncol_block=nrow_block, &
     340              :                                nrow_global=nao, ncol_global=nao, &
     341          148 :                                template_fmstruct=ao_mo_fmstruct)
     342          148 :       IF (.NOT. (ASSOCIATED(rtp%mos))) ALLOCATE (rtp%mos)
     343          852 :       IF (my_mos_old) ALLOCATE (rtp%mos%old(2*nspin))
     344          852 :       IF (my_mos_new) ALLOCATE (rtp%mos%new(2*nspin))
     345          640 :       IF (my_mos_next) ALLOCATE (rtp%mos%next(2*nspin))
     346          148 :       NULLIFY (rtp%mos%admm)
     347          148 :       IF ((dft_control%do_admm) .AND. my_mos_admn) THEN
     348            8 :          IF (PRESENT(mos_aux)) THEN
     349            8 :             CPASSERT(ASSOCIATED(mos_aux))
     350              :          ELSE
     351            0 :             CPABORT("The optional argument mos_aux is missing which is required with ADMM")
     352              :          END IF
     353           40 :          ALLOCATE (rtp%mos%admm(2*nspin))
     354              :       END IF
     355          352 :       DO i = 1, nspin
     356          760 :          DO j = 1, 2
     357          408 :             IF (my_mos_old) CALL cp_fm_create(rtp%mos%old(2*(i - 1) + j), &
     358              :                                               matrix_struct=mos(i)%mo_coeff%matrix_struct, &
     359          408 :                                               name="mos_old"//TRIM(ADJUSTL(cp_to_string(2*(i - 1) + j))))
     360          408 :             IF (my_mos_new) CALL cp_fm_create(rtp%mos%new(2*(i - 1) + j), &
     361              :                                               matrix_struct=mos(i)%mo_coeff%matrix_struct, &
     362          408 :                                               name="mos_new"//TRIM(ADJUSTL(cp_to_string(2*(i - 1) + j))))
     363          408 :             IF (my_mos_next) CALL cp_fm_create(rtp%mos%next(2*(i - 1) + j), &
     364              :                                                matrix_struct=mos(i)%mo_coeff%matrix_struct, &
     365          276 :                                                name="mos_next"//TRIM(ADJUSTL(cp_to_string(2*(i - 1) + j))))
     366          612 :             IF ((dft_control%do_admm) .AND. my_mos_admn) THEN
     367              :                CALL cp_fm_create(rtp%mos%admm(2*(i - 1) + j), &
     368              :                                  matrix_struct=mos_aux(i)%mo_coeff%matrix_struct, &
     369           16 :                                  name="mos_admm"//TRIM(ADJUSTL(cp_to_string(2*(i - 1) + j))))
     370              :             END IF
     371              :          END DO
     372              :       END DO
     373              : 
     374          148 :    END SUBROUTINE rt_prop_create_mos
     375              : 
     376              : ! **************************************************************************************************
     377              : !> \brief ...
     378              : !> \param rtp ...
     379              : !> \param exp_H_old ...
     380              : !> \param exp_H_new ...
     381              : !> \param H_last_iter ...
     382              : !> \param rho_old ...
     383              : !> \param rho_next ...
     384              : !> \param rho_new ...
     385              : !> \param mos ...
     386              : !> \param mos_new ...
     387              : !> \param mos_old ...
     388              : !> \param mos_next ...
     389              : !> \param S_inv ...
     390              : !> \param S_half ...
     391              : !> \param S_minus_half ...
     392              : !> \param B_mat ...
     393              : !> \param C_mat ...
     394              : !> \param propagator_matrix ...
     395              : !> \param mixing ...
     396              : !> \param mixing_factor ...
     397              : !> \param S_der ...
     398              : !> \param dt ...
     399              : !> \param nsteps ...
     400              : !> \param SinvH ...
     401              : !> \param SinvH_imag ...
     402              : !> \param SinvB ...
     403              : !> \param admm_mos ...
     404              : ! **************************************************************************************************
     405        30958 :    SUBROUTINE get_rtp(rtp, exp_H_old, exp_H_new, H_last_iter, rho_old, rho_next, rho_new, mos, mos_new, mos_old, mos_next, &
     406              :                       S_inv, S_half, S_minus_half, B_mat, C_mat, propagator_matrix, mixing, mixing_factor, &
     407              :                       S_der, dt, nsteps, SinvH, SinvH_imag, SinvB, admm_mos)
     408              : 
     409              :       TYPE(rt_prop_type), INTENT(IN)                     :: rtp
     410              :       TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
     411              :          POINTER                                         :: exp_H_old, exp_H_new, H_last_iter, &
     412              :                                                             rho_old, rho_next, rho_new
     413              :       TYPE(rtp_mos_type), OPTIONAL, POINTER              :: mos
     414              :       TYPE(cp_fm_type), DIMENSION(:), OPTIONAL, POINTER  :: mos_new, mos_old, mos_next
     415              :       TYPE(dbcsr_type), OPTIONAL, POINTER                :: S_inv, S_half, S_minus_half, B_mat
     416              :       TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
     417              :          POINTER                                         :: C_mat, propagator_matrix
     418              :       LOGICAL, OPTIONAL                                  :: mixing
     419              :       REAL(dp), INTENT(out), OPTIONAL                    :: mixing_factor
     420              :       TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
     421              :          POINTER                                         :: S_der
     422              :       REAL(dp), INTENT(out), OPTIONAL                    :: dt
     423              :       INTEGER, INTENT(out), OPTIONAL                     :: nsteps
     424              :       TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
     425              :          POINTER                                         :: SinvH, SinvH_imag, SinvB
     426              :       TYPE(cp_fm_type), DIMENSION(:), OPTIONAL, POINTER  :: admm_mos
     427              : 
     428        30958 :       IF (PRESENT(exp_H_old)) exp_H_old => rtp%exp_H_old
     429        30958 :       IF (PRESENT(exp_H_new)) exp_H_new => rtp%exp_H_new
     430        30958 :       IF (PRESENT(H_last_iter)) H_last_iter => rtp%H_last_iter
     431        30958 :       IF (PRESENT(propagator_matrix)) propagator_matrix => rtp%propagator_matrix
     432              : 
     433        30958 :       IF (PRESENT(rho_old)) rho_old => rtp%rho%old
     434        30958 :       IF (PRESENT(rho_next)) rho_next => rtp%rho%next
     435        30958 :       IF (PRESENT(rho_new)) rho_new => rtp%rho%new
     436        30958 :       IF (PRESENT(mos)) mos => rtp%mos
     437        30958 :       IF (PRESENT(mos_old)) mos_old => rtp%mos%old
     438        30958 :       IF (PRESENT(mos_new)) mos_new => rtp%mos%new
     439        30958 :       IF (PRESENT(mos_next)) mos_next => rtp%mos%next
     440        30958 :       IF (PRESENT(admm_mos)) admm_mos => rtp%mos%admm
     441              : 
     442        30958 :       IF (PRESENT(S_inv)) S_inv => rtp%S_inv
     443        30958 :       IF (PRESENT(S_half)) S_half => rtp%S_half
     444        30958 :       IF (PRESENT(S_minus_half)) S_minus_half => rtp%S_minus_half
     445        30958 :       IF (PRESENT(B_mat)) B_mat => rtp%B_mat
     446        30958 :       IF (PRESENT(C_mat)) C_mat => rtp%C_mat
     447        30958 :       IF (PRESENT(SinvH)) SinvH => rtp%SinvH
     448        30958 :       IF (PRESENT(SinvH_imag)) SinvH_imag => rtp%SinvH_imag
     449        30958 :       IF (PRESENT(SinvB)) SinvB => rtp%SinvB
     450        30958 :       IF (PRESENT(S_der)) S_der => rtp%S_der
     451              : 
     452        30958 :       IF (PRESENT(dt)) dt = rtp%dt
     453        30958 :       IF (PRESENT(mixing)) mixing = rtp%mixing
     454        30958 :       IF (PRESENT(mixing_factor)) mixing_factor = rtp%mixing_factor
     455        30958 :       IF (PRESENT(nsteps)) nsteps = rtp%nsteps
     456              : 
     457        30958 :    END SUBROUTINE get_rtp
     458              : 
     459              : ! **************************************************************************************************
     460              : !> \brief ...
     461              : !> \param rtp ...
     462              : ! **************************************************************************************************
     463          198 :    SUBROUTINE rt_prop_release(rtp)
     464              :       TYPE(rt_prop_type), INTENT(inout)                  :: rtp
     465              : 
     466          198 :       CALL dbcsr_deallocate_matrix_set(rtp%exp_H_old)
     467          198 :       CALL dbcsr_deallocate_matrix_set(rtp%exp_H_new)
     468          198 :       CALL dbcsr_deallocate_matrix_set(rtp%H_last_iter)
     469          198 :       CALL dbcsr_deallocate_matrix_set(rtp%propagator_matrix)
     470          198 :       IF (ASSOCIATED(rtp%rho)) THEN
     471           90 :          IF (ASSOCIATED(rtp%rho%old)) &
     472           90 :             CALL dbcsr_deallocate_matrix_set(rtp%rho%old)
     473           90 :          IF (ASSOCIATED(rtp%rho%next)) &
     474           90 :             CALL dbcsr_deallocate_matrix_set(rtp%rho%next)
     475           90 :          IF (ASSOCIATED(rtp%rho%new)) &
     476           90 :             CALL dbcsr_deallocate_matrix_set(rtp%rho%new)
     477           90 :          DEALLOCATE (rtp%rho)
     478              :       END IF
     479              : 
     480          198 :       CALL rt_prop_release_mos(rtp)
     481              : 
     482          198 :       CALL dbcsr_deallocate_matrix(rtp%S_inv)
     483          198 :       CALL dbcsr_deallocate_matrix(rtp%S_half)
     484          198 :       CALL dbcsr_deallocate_matrix(rtp%S_minus_half)
     485          198 :       IF (ASSOCIATED(rtp%B_mat)) &
     486           72 :          CALL dbcsr_deallocate_matrix(rtp%B_mat)
     487          198 :       IF (ASSOCIATED(rtp%C_mat)) &
     488           72 :          CALL dbcsr_deallocate_matrix_set(rtp%C_mat)
     489          198 :       IF (ASSOCIATED(rtp%S_der)) &
     490           72 :          CALL dbcsr_deallocate_matrix_set(rtp%S_der)
     491          198 :       IF (ASSOCIATED(rtp%SinvH)) &
     492           72 :          CALL dbcsr_deallocate_matrix_set(rtp%SinvH)
     493          198 :       IF (ASSOCIATED(rtp%SinvH_imag)) &
     494           22 :          CALL dbcsr_deallocate_matrix_set(rtp%SinvH_imag)
     495          198 :       IF (ASSOCIATED(rtp%SinvB)) &
     496           72 :          CALL dbcsr_deallocate_matrix_set(rtp%SinvB)
     497          198 :       IF (ASSOCIATED(rtp%history)) &
     498          198 :          CALL rtp_history_release(rtp)
     499          198 :       DEALLOCATE (rtp%orders)
     500          198 :    END SUBROUTINE rt_prop_release
     501              : 
     502              : ! **************************************************************************************************
     503              : !> \brief Deallocated the mos for rtp...
     504              : !> \param rtp ...
     505              : ! **************************************************************************************************
     506          238 :    SUBROUTINE rt_prop_release_mos(rtp)
     507              :       TYPE(rt_prop_type), INTENT(inout)                  :: rtp
     508              : 
     509          238 :       IF (ASSOCIATED(rtp%mos)) THEN
     510          148 :          IF (ASSOCIATED(rtp%mos%old)) &
     511          148 :             CALL cp_fm_release(rtp%mos%old)
     512          148 :          IF (ASSOCIATED(rtp%mos%new)) &
     513          148 :             CALL cp_fm_release(rtp%mos%new)
     514          148 :          IF (ASSOCIATED(rtp%mos%next)) &
     515          108 :             CALL cp_fm_release(rtp%mos%next)
     516          148 :          IF (ASSOCIATED(rtp%mos%admm)) &
     517            8 :             CALL cp_fm_release(rtp%mos%admm)
     518          148 :          CALL cp_fm_struct_release(rtp%ao_ao_fmstruct)
     519          148 :          DEALLOCATE (rtp%mos)
     520              :       END IF
     521              : 
     522          238 :    END SUBROUTINE rt_prop_release_mos
     523              : ! **************************************************************************************************
     524              : !> \brief ...
     525              : !> \param rtp ...
     526              : !> \param aspc_order ...
     527              : ! **************************************************************************************************
     528          198 :    SUBROUTINE rtp_history_create(rtp, aspc_order)
     529              :       TYPE(rt_prop_type), INTENT(inout)                  :: rtp
     530              :       INTEGER, INTENT(in)                                :: aspc_order
     531              : 
     532              :       INTEGER                                            :: i, j, nmat
     533              :       TYPE(rtp_history_type), POINTER                    :: history
     534              : 
     535          198 :       NULLIFY (history)
     536          198 :       ALLOCATE (rtp%history)
     537          198 :       history => rtp%history
     538              : 
     539              :       NULLIFY (history%rho_history, history%mo_history, history%s_history)
     540          198 :       IF (aspc_order .GT. 0) THEN
     541          198 :          IF (rtp%linear_scaling) THEN
     542           90 :             nmat = SIZE(rtp%rho%new)
     543           90 :             CALL dbcsr_allocate_matrix_set(history%rho_history, nmat, aspc_order)
     544          346 :             DO i = 1, nmat
     545         1114 :                DO j = 1, aspc_order
     546          768 :                   CALL dbcsr_init_p(history%rho_history(i, j)%matrix)
     547              :                   CALL dbcsr_create(history%rho_history(i, j)%matrix, &
     548              :                                     name="rho_hist"//TRIM(ADJUSTL(cp_to_string(i))), &
     549         1024 :                                     template=rtp%rho%new(1)%matrix)
     550              :                END DO
     551              :             END DO
     552              :          ELSE
     553          108 :             nmat = SIZE(rtp%mos%old)
     554         1584 :             ALLOCATE (history%mo_history(nmat, aspc_order))
     555          384 :             DO i = 1, nmat
     556         1212 :                DO j = 1, aspc_order
     557              :                   CALL cp_fm_create(history%mo_history(i, j), &
     558              :                                     matrix_struct=rtp%mos%new(i)%matrix_struct, &
     559         1104 :                                     name="mo_hist"//TRIM(ADJUSTL(cp_to_string(i))))
     560              :                END DO
     561              :             END DO
     562          648 :             ALLOCATE (history%s_history(aspc_order))
     563          432 :             DO i = 1, aspc_order
     564          432 :                NULLIFY (history%s_history(i)%matrix)
     565              :             END DO
     566              :          END IF
     567              :       END IF
     568              : 
     569          198 :    END SUBROUTINE rtp_history_create
     570              : 
     571              : ! **************************************************************************************************
     572              : !> \brief ...
     573              : !> \param rtp ...
     574              : ! **************************************************************************************************
     575          198 :    SUBROUTINE rtp_history_release(rtp)
     576              :       TYPE(rt_prop_type), INTENT(inout)                  :: rtp
     577              : 
     578              :       INTEGER                                            :: i
     579              : 
     580          198 :       IF (ASSOCIATED(rtp%history%rho_history)) THEN
     581           90 :          CALL dbcsr_deallocate_matrix_set(rtp%history%rho_history)
     582              :       END IF
     583              : 
     584          198 :       CALL cp_fm_release(rtp%history%mo_history)
     585              : 
     586          198 :       IF (ASSOCIATED(rtp%history%s_history)) THEN
     587          432 :          DO i = 1, SIZE(rtp%history%s_history)
     588          324 :             IF (ASSOCIATED(rtp%history%s_history(i)%matrix)) &
     589          316 :                CALL dbcsr_deallocate_matrix(rtp%history%s_history(i)%matrix)
     590              :          END DO
     591          108 :          DEALLOCATE (rtp%history%s_history)
     592              :       END IF
     593          198 :       DEALLOCATE (rtp%history)
     594              : 
     595          198 :    END SUBROUTINE rtp_history_release
     596              : 
     597            0 : END MODULE rt_propagation_types
        

Generated by: LCOV version 2.0-1