LCOV - code coverage report
Current view: top level - src - mixed_cdft_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:71c3ab0) Lines: 75.7 % 206 156
Test Date: 2026-07-25 06:35:44 Functions: 36.8 % 19 7

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Types for mixed CDFT calculations
      10              : !> \par   History
      11              : !>                 Separated CDFT routines from mixed_environment_types
      12              : !> \author Nico Holmberg [01.2017]
      13              : ! **************************************************************************************************
      14              : MODULE mixed_cdft_types
      15              :    USE cp_array_utils,                  ONLY: cp_1d_r_p_type
      16              :    USE cp_blacs_env,                    ONLY: cp_blacs_env_release,&
      17              :                                               cp_blacs_env_type
      18              :    USE cp_dbcsr_api,                    ONLY: dbcsr_p_type,&
      19              :                                               dbcsr_release_p,&
      20              :                                               dbcsr_type
      21              :    USE cp_fm_types,                     ONLY: cp_fm_release,&
      22              :                                               cp_fm_type
      23              :    USE cp_log_handling,                 ONLY: cp_logger_p_type,&
      24              :                                               cp_logger_release
      25              :    USE kinds,                           ONLY: dp
      26              :    USE pw_env_types,                    ONLY: pw_env_release,&
      27              :                                               pw_env_type
      28              :    USE qs_cdft_types,                   ONLY: cdft_control_release,&
      29              :                                               cdft_control_type
      30              :    USE qs_kind_types,                   ONLY: deallocate_qs_kind_set,&
      31              :                                               qs_kind_type
      32              : #include "./base/base_uses.f90"
      33              : 
      34              :    IMPLICIT NONE
      35              :    PRIVATE
      36              : 
      37              : ! **************************************************************************************************
      38              : !> \brief Container for results related to a mixed CDFT calculation
      39              : ! **************************************************************************************************
      40              :    TYPE mixed_cdft_result_type
      41              :       ! CDFT electronic couplings calculated with different methods
      42              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)         :: lowdin, nonortho, &
      43              :                                                           rotation, wfn
      44              :       ! Energies of the CDFT states
      45              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)         :: energy
      46              :       ! Lagrangian multipliers of the CDFT constraints
      47              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)      :: strength
      48              :       ! Reliability metric for CDFT electronic couplings
      49              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)      :: metric
      50              :       ! The mixed CDFT Hamiltonian matrix
      51              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)      :: H
      52              :       ! Overlaps between CDFT states
      53              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)      :: S
      54              :       ! S^(-1/2)
      55              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)      :: S_minushalf
      56              :       ! Off-diagonal elements of the weight function matrices <Psi_j | w_i(r) | Psi_i>
      57              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)      :: Wad, Wda
      58              :       ! Diagonal elements of the weight function matrices, i.e., the constraint values
      59              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)      :: W_diagonal
      60              :    END TYPE mixed_cdft_result_type
      61              : 
      62              : ! **************************************************************************************************
      63              : !> \brief Container for mixed CDFT matrices
      64              : ! **************************************************************************************************
      65              :    TYPE mixed_cdft_work_type
      66              :       ! Matrix representations of the CDFT weight functions
      67              :       TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER       :: w_matrix => NULL()
      68              :       ! AO overlap matrix
      69              :       TYPE(dbcsr_type), POINTER                          :: mixed_matrix_s => NULL()
      70              :       ! MO coefficients of each CDFT state
      71              :       TYPE(cp_fm_type), DIMENSION(:, :), POINTER         :: mixed_mo_coeff => NULL()
      72              :       ! Density matrices of the CDFT states
      73              :       TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER       :: density_matrix => NULL()
      74              :    END TYPE mixed_cdft_work_type
      75              : 
      76              : ! **************************************************************************************************
      77              : !> \brief Buffers for load balancing
      78              : !> \param rank indices of the processors the data in this buffer should be sent to
      79              : !> \param tag mpi tags for the messages to send
      80              : !> \param cavity the cavity to send
      81              : !> \param weight the weight to send
      82              : !> \param gradients the gradients to send
      83              : ! **************************************************************************************************
      84              :    TYPE buffers
      85              :       INTEGER                                          :: rank(2) = -1, tag(2) = -1
      86              :       REAL(KIND=dp), POINTER, &
      87              :          DIMENSION(:, :, :)                            :: cavity => NULL(), weight => NULL()
      88              :       REAL(KIND=dp), POINTER, &
      89              :          DIMENSION(:, :, :, :)                         :: gradients => NULL()
      90              :    END TYPE buffers
      91              : ! **************************************************************************************************
      92              : !> \brief To build array of buffers
      93              : !> \param buffs the pointer to the buffers type
      94              : ! **************************************************************************************************
      95              :    TYPE p_buffers
      96              :       TYPE(buffers), DIMENSION(:), POINTER             :: buffs => NULL()
      97              :    END TYPE p_buffers
      98              : ! **************************************************************************************************
      99              : !> \brief Information about load balancing
     100              : !> \param matrix_info size of the target_list array to receive and grid point bounds of the data
     101              : !> \param target_list the target_list array of the processor that sends me data
     102              : ! **************************************************************************************************
     103              :    TYPE repl_info
     104              :       INTEGER, DIMENSION(:), POINTER                   :: matrix_info => NULL()
     105              :       INTEGER, DIMENSION(:, :), POINTER                :: target_list => NULL()
     106              :    END TYPE repl_info
     107              : ! **************************************************************************************************
     108              : !> \brief Load balancing control for mixed CDFT calculation
     109              : !> \param my_source index of the processor which will send this processor data
     110              : !> \param distributed bounds that determine which grid points this processor will compute after
     111              : !>                    applying load balancing (is_special = .FALSE.)
     112              : !> \param my_dest_repl the dest_list arrays of all processors which send additional work to this
     113              : !>                     processor (indices of the processors where the redistributed slices should be
     114              : !>                     returned)
     115              : !> \param dest_tags_repl tags for the send messages (is_special = .FALSE.)
     116              : !> \param more_work allow heavily overloaded processors to redistribute more_work slices
     117              : !> \param bo bounds of the data that this processor will send to other processors which tells the
     118              : !>           receivers how to rearrange the data correctly
     119              : !> \param expected_work a list of the estimated work per processor
     120              : !> \param prediction_error the difference between the estimated and actual work per processor
     121              : !> \param target_list a list of processors to send data and the size of data to send
     122              : !> \param recv_work flag that determines if this processor will receive data from others
     123              : !> \param send_work flag that determines if this processor will send data to others
     124              : !> \param recv_work_repl list of processor indices where this processor will send data during load
     125              : !>                       balancing
     126              : !> \param load_scale allow underloaded processors to accept load_scale additional work
     127              : !> \param very_overloaded value to determine which processors are heavily overloaded
     128              : !> \param cavity the cavity that this processor builds in addition to its own cavity defined
     129              : !>               on the grid points which were redistributed to this processor
     130              : !> \param weight the weight that this processor builds in addition to its own weight
     131              : !> \param gradients the gradients that this processor builds in addition to its own gradients
     132              : !> \param sendbuffer buffer to hold the data this processor will send
     133              : !> \param sendbuffer buffer to hold the data this processor will receive
     134              : !> \param recv_info additional information on the data this processor will receive
     135              : ! **************************************************************************************************
     136              :    TYPE mixed_cdft_dlb_type
     137              :       INTEGER                                          :: my_source = -1, distributed(2) = -1, &
     138              :                                                           my_dest_repl(2) = -1, dest_tags_repl(2) = -1, &
     139              :                                                           more_work = -1
     140              :       INTEGER, DIMENSION(:), POINTER                   :: bo => NULL(), expected_work => NULL(), &
     141              :                                                           prediction_error => NULL()
     142              :       INTEGER, DIMENSION(:, :), POINTER                :: target_list => NULL()
     143              :       LOGICAL                                          :: recv_work = .FALSE., send_work = .FALSE.
     144              :       LOGICAL, DIMENSION(:), POINTER                   :: recv_work_repl => NULL()
     145              :       REAL(KIND=dp)                                    :: load_scale = 0.0_dp, very_overloaded = 0.0_dp
     146              :       REAL(KIND=dp), POINTER, &
     147              :          DIMENSION(:, :, :)                            :: cavity => NULL(), weight => NULL()
     148              :       REAL(KIND=dp), POINTER, &
     149              :          DIMENSION(:, :, :, :)                         :: gradients => NULL()
     150              :       ! Should convert to TYPE(p_buffers), POINTER
     151              :       TYPE(buffers), DIMENSION(:), POINTER             :: sendbuff => NULL()
     152              :       TYPE(p_buffers), DIMENSION(:), POINTER           :: recvbuff => NULL()
     153              :       TYPE(repl_info), DIMENSION(:), POINTER           :: recv_info => NULL()
     154              :    END TYPE mixed_cdft_dlb_type
     155              : ! **************************************************************************************************
     156              : !> \brief Main mixed CDFT control type
     157              : !> \param sim_step              counter to keep track of the simulation step for MD
     158              : !> \param multiplicity          spin multiplicity
     159              : !> \param nconstraint           the number of constraints
     160              : !> \param run_type              what type of mixed CDFT simulation to perform
     161              : !> \param source_list           a list of processors which will send this processor data
     162              : !> \param dest_list             a list of processors which this processor will send data to
     163              : !> \param recv_bo               bounds of the data which this processor will receive (is_special = .FALSE.)
     164              : !> \param source_list_save      permanent copy of source_list which might get reallocated during
     165              : !>                              load balancing
     166              : !> \param dest_list_save        permanent copy of dest_list which might get reallocated during
     167              : !>                              load balancing
     168              : !> \param source_list_bo        bounds of the data which this processor will receive (is_special = .TRUE.)
     169              : !> \param dest_list_bo          bounds of the data this processor will send (is_special = .TRUE.)
     170              : !> \param source_bo_save        permanent copy of source_list_bo
     171              : !> \param deset_bo_save         permanent copy of dest_list_bo
     172              : !> \param is_pencil             flag controlling which scheme to use for constraint replication
     173              : !> \param dlb                   flag to enable dynamic load balancing
     174              : !> \param is_special            another flag controlling which scheme to use for constraint replication
     175              : !> \param first_iteration       flag to mark the first iteration e.g. during MD to output information
     176              : !> \param calculate_metric      flag which determines if the coupling reliability metric should be computed
     177              : !> \param wnf_ovelap_method     flag to enable the wavefunction overlap method for computing the coupling
     178              : !> \param has_unit_metric       flag to determine if the basis set has unit metric
     179              : !> \param use_lowdin            flag which determines if Lowdin orthogonalization is used to compute the coupling
     180              : !> \param do_ci                 flag which determines if a CDFT-CI calculation was requested
     181              : !> \param nonortho_coupling     flag which determines if the nonorthogonal CDFT interaction energies
     182              : !>                              should be printed out
     183              : !> \param identical_constraints flag which determines if the constraint definitions are identical
     184              : !>                              across all CDFT states
     185              : !> \param block_diagonalize     flag which determines if the CDFT Hamiltonian should be block
     186              : !>                              diagonalized
     187              : !> \param constraint_type       list of integers which determine what type of constraint should be applied
     188              : !>                              to each constraint group
     189              : !> \param eps_rho_rspace        threshold to determine when the realspace density can be considered zero
     190              : !> \param sim_dt                timestep of the MD simulation
     191              : !> \param eps_svd               value that controls which matrix inversion method to use
     192              : !> \param weight                the constraint weight function
     193              : !> \param cavity                the confinement cavity: the weight function is nonzero only within the cavity
     194              : !> \param cdft_control          container for cdft_control_type
     195              : !> \param sendbuff              buffer that holds the data to be replicated
     196              : !> \param blacs_env             the blacs_env needed to redistribute arrays during a coupling calculation
     197              : !> \param results               container for mixed CDFT results
     198              : !> \param matrix                container for mixed CDFT work matrices
     199              : !> \param dlb_control           container for load balancing structures
     200              : !> \param qs_kind_set           the qs_kind_set needed to setup a confinement cavity
     201              : !> \param pw_env                the pw_env that holds the fully distributed realspace grid
     202              : !> \param occupations           occupation numbers in case non-uniform occupation
     203              : ! **************************************************************************************************
     204              :    TYPE mixed_cdft_type
     205              :       INTEGER                                          :: sim_step = -1, multiplicity = -1, &
     206              :                                                           nconstraint = -1, &
     207              :                                                           run_type = -1
     208              :       INTEGER, DIMENSION(:, :), ALLOCATABLE            :: constraint_type
     209              :       INTEGER, POINTER, DIMENSION(:)                   :: source_list => NULL(), dest_list => NULL(), &
     210              :                                                           recv_bo => NULL(), source_list_save => NULL(), &
     211              :                                                           dest_list_save => NULL()
     212              :       INTEGER, POINTER, DIMENSION(:, :)                :: source_list_bo => NULL(), dest_list_bo => NULL(), &
     213              :                                                           source_bo_save => NULL(), dest_bo_save => NULL()
     214              :       LOGICAL                                          :: is_pencil = .FALSE., dlb = .FALSE., &
     215              :                                                           is_special = .FALSE., first_iteration = .FALSE., &
     216              :                                                           calculate_metric = .FALSE., &
     217              :                                                           wfn_overlap_method = .FALSE., &
     218              :                                                           has_unit_metric = .FALSE., &
     219              :                                                           use_lowdin = .FALSE., &
     220              :                                                           do_ci = .FALSE., nonortho_coupling = .FALSE., &
     221              :                                                           identical_constraints = .FALSE., &
     222              :                                                           block_diagonalize = .FALSE.
     223              :       REAL(KIND=dp)                                    :: eps_rho_rspace = 0.0_dp, sim_dt = 0.0_dp, &
     224              :                                                           eps_svd = 0.0_dp
     225              :       REAL(KIND=dp), POINTER, DIMENSION(:, :, :)       :: weight => NULL(), cavity => NULL()
     226              :       TYPE(cdft_control_type), POINTER                 :: cdft_control => NULL()
     227              :       TYPE(buffers), DIMENSION(:), POINTER             :: sendbuff => NULL()
     228              :       TYPE(cp_1d_r_p_type), ALLOCATABLE, &
     229              :          DIMENSION(:, :)                               :: occupations
     230              :       TYPE(cp_blacs_env_type), POINTER                 :: blacs_env => NULL()
     231              :       TYPE(cp_logger_p_type), DIMENSION(:), POINTER    :: sub_logger => NULL()
     232              :       TYPE(mixed_cdft_result_type)                     :: results = mixed_cdft_result_type()
     233              :       TYPE(mixed_cdft_work_type)                       :: matrix = mixed_cdft_work_type()
     234              :       TYPE(mixed_cdft_dlb_type), POINTER               :: dlb_control => NULL()
     235              :       TYPE(pw_env_type), POINTER                       :: pw_env => NULL()
     236              :       TYPE(qs_kind_type), DIMENSION(:), &
     237              :          POINTER                                       :: qs_kind_set => NULL()
     238              :    END TYPE mixed_cdft_type
     239              : 
     240              : ! **************************************************************************************************
     241              : !> \brief Container for constraint settings to check consistency of force_evals
     242              : ! **************************************************************************************************
     243              :    TYPE mixed_cdft_settings_type
     244              :       LOGICAL                                            :: is_spherical = .FALSE., &
     245              :                                                             is_odd = .FALSE.
     246              :       LOGICAL, DIMENSION(:, :), POINTER                  :: sb => NULL()
     247              :       INTEGER                                            :: ncdft = -1, &
     248              :                                                             max_nkinds = -1
     249              :       INTEGER, DIMENSION(2, 3)                           :: bo = -1
     250              :       INTEGER, DIMENSION(:), POINTER                     :: grid_span => NULL(), &
     251              :                                                             spherical => NULL(), &
     252              :                                                             odd => NULL()
     253              :       INTEGER, DIMENSION(:, :), POINTER                  :: si => NULL(), &
     254              :                                                             rs_dims => NULL(), &
     255              :                                                             atoms => NULL(), &
     256              :                                                             npts => NULL()
     257              :       REAL(KIND=dp)                                      :: radius = 0.0_dp
     258              :       REAL(KIND=dp), DIMENSION(:), POINTER               :: cutoff => NULL(), &
     259              :                                                             rel_cutoff => NULL()
     260              :       REAL(KIND=dp), DIMENSION(:, :), POINTER            :: sr => NULL(), &
     261              :                                                             coeffs => NULL(), &
     262              :                                                             cutoffs => NULL(), &
     263              :                                                             radii => NULL()
     264              :    END TYPE mixed_cdft_settings_type
     265              : 
     266              : ! *** Public data types ***
     267              : 
     268              :    PUBLIC :: mixed_cdft_type, &
     269              :              mixed_cdft_settings_type
     270              : 
     271              : ! *** Public subroutines ***
     272              : 
     273              :    PUBLIC :: mixed_cdft_type_create, &
     274              :              mixed_cdft_type_release, &
     275              :              mixed_cdft_result_type_set, &
     276              :              mixed_cdft_result_type_release, &
     277              :              mixed_cdft_work_type_init, &
     278              :              mixed_cdft_work_type_release
     279              : 
     280              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'mixed_cdft_types'
     281              : 
     282              : CONTAINS
     283              : 
     284              : ! **************************************************************************************************
     285              : !> \brief inits the given mixed_cdft_type
     286              : !> \param cdft_control the object to init
     287              : !> \author Nico Holmberg [01.2017]
     288              : ! **************************************************************************************************
     289           78 :    SUBROUTINE mixed_cdft_type_create(cdft_control)
     290              :       TYPE(mixed_cdft_type), POINTER                     :: cdft_control
     291              : 
     292           78 :       NULLIFY (cdft_control%pw_env, cdft_control%blacs_env, cdft_control%qs_kind_set)
     293           78 :       NULLIFY (cdft_control%dlb_control, cdft_control%dest_list_bo, cdft_control%dest_list)
     294           78 :       NULLIFY (cdft_control%dest_bo_save, cdft_control%dest_list_save, cdft_control%source_list)
     295           78 :       NULLIFY (cdft_control%source_list_save, cdft_control%source_bo_save, cdft_control%source_list_bo)
     296           78 :       NULLIFY (cdft_control%cavity, cdft_control%weight, cdft_control%sendbuff)
     297           78 :       NULLIFY (cdft_control%cdft_control, cdft_control%recv_bo)
     298           78 :       NULLIFY (cdft_control%sub_logger)
     299              : 
     300           78 :    END SUBROUTINE mixed_cdft_type_create
     301              : 
     302              : ! **************************************************************************************************
     303              : !> \brief releases the given mixed_cdft_type
     304              : !> \param cdft_control the object to release
     305              : !> \author Nico Holmberg [01.2017]
     306              : ! **************************************************************************************************
     307           78 :    SUBROUTINE mixed_cdft_type_release(cdft_control)
     308              :       TYPE(mixed_cdft_type), POINTER                     :: cdft_control
     309              : 
     310              :       INTEGER                                            :: i, j
     311              : 
     312           78 :       CALL pw_env_release(cdft_control%pw_env)
     313           78 :       IF (ASSOCIATED(cdft_control%dest_list)) THEN
     314           24 :          DEALLOCATE (cdft_control%dest_list)
     315              :       END IF
     316           78 :       IF (ASSOCIATED(cdft_control%dest_list_save)) THEN
     317            0 :          DEALLOCATE (cdft_control%dest_list_save)
     318              :       END IF
     319           78 :       IF (ASSOCIATED(cdft_control%dest_list_bo)) THEN
     320            0 :          DEALLOCATE (cdft_control%dest_list_bo)
     321              :       END IF
     322           78 :       IF (ASSOCIATED(cdft_control%dest_bo_save)) THEN
     323            0 :          DEALLOCATE (cdft_control%dest_bo_save)
     324              :       END IF
     325           78 :       IF (ASSOCIATED(cdft_control%source_list)) THEN
     326           24 :          DEALLOCATE (cdft_control%source_list)
     327              :       END IF
     328           78 :       IF (ASSOCIATED(cdft_control%source_list_save)) THEN
     329            0 :          DEALLOCATE (cdft_control%source_list_save)
     330              :       END IF
     331           78 :       IF (ASSOCIATED(cdft_control%source_list_bo)) THEN
     332            0 :          DEALLOCATE (cdft_control%source_list_bo)
     333              :       END IF
     334           78 :       IF (ASSOCIATED(cdft_control%source_bo_save)) THEN
     335            0 :          DEALLOCATE (cdft_control%source_bo_save)
     336              :       END IF
     337           78 :       IF (ASSOCIATED(cdft_control%recv_bo)) THEN
     338           24 :          DEALLOCATE (cdft_control%recv_bo)
     339              :       END IF
     340           78 :       IF (ASSOCIATED(cdft_control%weight)) THEN
     341            0 :          DEALLOCATE (cdft_control%weight)
     342              :       END IF
     343           78 :       IF (ASSOCIATED(cdft_control%cavity)) THEN
     344            0 :          DEALLOCATE (cdft_control%cavity)
     345              :       END IF
     346           78 :       IF (ALLOCATED(cdft_control%constraint_type)) THEN
     347           78 :          DEALLOCATE (cdft_control%constraint_type)
     348              :       END IF
     349           78 :       IF (ALLOCATED(cdft_control%occupations)) THEN
     350            0 :          DO i = 1, SIZE(cdft_control%occupations, 1)
     351            0 :             DO j = 1, SIZE(cdft_control%occupations, 2)
     352            0 :                IF (ASSOCIATED(cdft_control%occupations(i, j)%array)) THEN
     353            0 :                   DEALLOCATE (cdft_control%occupations(i, j)%array)
     354              :                END IF
     355              :             END DO
     356              :          END DO
     357            0 :          DEALLOCATE (cdft_control%occupations)
     358              :       END IF
     359           78 :       IF (ASSOCIATED(cdft_control%dlb_control)) THEN
     360            4 :          CALL mixed_cdft_dlb_release(cdft_control%dlb_control)
     361              :       END IF
     362           78 :       IF (ASSOCIATED(cdft_control%sendbuff)) THEN
     363            0 :          DO i = 1, SIZE(cdft_control%sendbuff)
     364            0 :             CALL mixed_cdft_buffers_release(cdft_control%sendbuff(i))
     365              :          END DO
     366            0 :          DEALLOCATE (cdft_control%sendbuff)
     367              :       END IF
     368           78 :       IF (ASSOCIATED(cdft_control%cdft_control)) THEN
     369           24 :          CALL cdft_control_release(cdft_control%cdft_control)
     370           24 :          DEALLOCATE (cdft_control%cdft_control)
     371              :       END IF
     372           78 :       IF (ASSOCIATED(cdft_control%blacs_env)) THEN
     373           78 :          CALL cp_blacs_env_release(cdft_control%blacs_env)
     374              :       END IF
     375           78 :       IF (ASSOCIATED(cdft_control%qs_kind_set)) THEN
     376           28 :          CALL deallocate_qs_kind_set(cdft_control%qs_kind_set)
     377              :       END IF
     378           78 :       IF (ASSOCIATED(cdft_control%sub_logger)) THEN
     379          132 :          DO i = 1, SIZE(cdft_control%sub_logger)
     380          132 :             CALL cp_logger_release(cdft_control%sub_logger(i)%p)
     381              :          END DO
     382           54 :          DEALLOCATE (cdft_control%sub_logger)
     383              :       END IF
     384           78 :       CALL mixed_cdft_result_type_release(cdft_control%results)
     385           78 :       CALL mixed_cdft_work_type_release(cdft_control%matrix)
     386           78 :       DEALLOCATE (cdft_control)
     387              : 
     388           78 :    END SUBROUTINE mixed_cdft_type_release
     389              : 
     390              : ! **************************************************************************************************
     391              : !> \brief releases the given load balancing control
     392              : !> \param dlb_control the object to release
     393              : !> \author Nico Holmberg [01.2017]
     394              : ! **************************************************************************************************
     395            4 :    SUBROUTINE mixed_cdft_dlb_release(dlb_control)
     396              :       TYPE(mixed_cdft_dlb_type), POINTER                 :: dlb_control
     397              : 
     398              :       INTEGER                                            :: i
     399              : 
     400            4 :       IF (ASSOCIATED(dlb_control%recv_work_repl)) THEN
     401            0 :          DEALLOCATE (dlb_control%recv_work_repl)
     402              :       END IF
     403            4 :       IF (ASSOCIATED(dlb_control%sendbuff)) THEN
     404            0 :          DO i = 1, SIZE(dlb_control%sendbuff)
     405            0 :             CALL mixed_cdft_buffers_release(dlb_control%sendbuff(i))
     406              :          END DO
     407            0 :          DEALLOCATE (dlb_control%sendbuff)
     408              :       END IF
     409            4 :       IF (ASSOCIATED(dlb_control%recvbuff)) THEN
     410            0 :          DO i = 1, SIZE(dlb_control%recvbuff)
     411            0 :             CALL mixed_cdft_p_buffers_release(dlb_control%recvbuff(i))
     412              :          END DO
     413            0 :          DEALLOCATE (dlb_control%recvbuff)
     414              :       END IF
     415            4 :       IF (ASSOCIATED(dlb_control%recv_info)) THEN
     416            0 :          DO i = 1, SIZE(dlb_control%recv_info)
     417            0 :             IF (ASSOCIATED(dlb_control%recv_info(i)%matrix_info)) THEN
     418            0 :                DEALLOCATE (dlb_control%recv_info(i)%matrix_info)
     419              :             END IF
     420            0 :             IF (ASSOCIATED(dlb_control%recv_info(i)%target_list)) THEN
     421            0 :                DEALLOCATE (dlb_control%recv_info(i)%target_list)
     422              :             END IF
     423              :          END DO
     424            0 :          DEALLOCATE (dlb_control%recv_info)
     425              :       END IF
     426            4 :       IF (ASSOCIATED(dlb_control%bo)) THEN
     427            0 :          DEALLOCATE (dlb_control%bo)
     428              :       END IF
     429            4 :       IF (ASSOCIATED(dlb_control%expected_work)) THEN
     430            0 :          DEALLOCATE (dlb_control%expected_work)
     431              :       END IF
     432            4 :       IF (ASSOCIATED(dlb_control%prediction_error)) THEN
     433            4 :          DEALLOCATE (dlb_control%prediction_error)
     434              :       END IF
     435            4 :       IF (ASSOCIATED(dlb_control%target_list)) THEN
     436            0 :          DEALLOCATE (dlb_control%target_list)
     437              :       END IF
     438            4 :       IF (ASSOCIATED(dlb_control%cavity)) THEN
     439            0 :          DEALLOCATE (dlb_control%cavity)
     440              :       END IF
     441            4 :       IF (ASSOCIATED(dlb_control%weight)) THEN
     442            0 :          DEALLOCATE (dlb_control%weight)
     443              :       END IF
     444            4 :       IF (ASSOCIATED(dlb_control%gradients)) THEN
     445            0 :          DEALLOCATE (dlb_control%gradients)
     446              :       END IF
     447            4 :       DEALLOCATE (dlb_control)
     448              : 
     449            4 :    END SUBROUTINE mixed_cdft_dlb_release
     450              : 
     451              : ! **************************************************************************************************
     452              : !> \brief releases the given buffers
     453              : !> \param buffer the object to release
     454              : !> \author Nico Holmberg [01.2017]
     455              : ! **************************************************************************************************
     456            0 :    SUBROUTINE mixed_cdft_buffers_release(buffer)
     457              :       TYPE(buffers)                                      :: buffer
     458              : 
     459            0 :       IF (ASSOCIATED(buffer%cavity)) THEN
     460            0 :          DEALLOCATE (buffer%cavity)
     461              :       END IF
     462            0 :       IF (ASSOCIATED(buffer%weight)) THEN
     463            0 :          DEALLOCATE (buffer%weight)
     464              :       END IF
     465            0 :       IF (ASSOCIATED(buffer%gradients)) THEN
     466            0 :          DEALLOCATE (buffer%gradients)
     467              :       END IF
     468              : 
     469            0 :    END SUBROUTINE mixed_cdft_buffers_release
     470              : 
     471              : ! **************************************************************************************************
     472              : !> \brief releases the given pointer of buffers
     473              : !> \param p_buffer the object to release
     474              : !> \author Nico Holmberg [01.2017]
     475              : ! **************************************************************************************************
     476            0 :    SUBROUTINE mixed_cdft_p_buffers_release(p_buffer)
     477              :       TYPE(p_buffers)                                    :: p_buffer
     478              : 
     479              :       INTEGER                                            :: i
     480              : 
     481            0 :       IF (ASSOCIATED(p_buffer%buffs)) THEN
     482            0 :          DO i = 1, SIZE(p_buffer%buffs)
     483            0 :             CALL mixed_cdft_buffers_release(p_buffer%buffs(i))
     484              :          END DO
     485            0 :          DEALLOCATE (p_buffer%buffs)
     486              :       END IF
     487              : 
     488            0 :    END SUBROUTINE mixed_cdft_p_buffers_release
     489              : 
     490              : ! **************************************************************************************************
     491              : !> \brief Updates arrays within the mixed CDFT result container
     492              : !> \param results      the array container
     493              : !> \param lowdin       CDFT electronic couplings from Lowdin orthogonalization
     494              : !> \param wfn          CDFT electronic couplings from wavefunction overlap method
     495              : !> \param nonortho     CDFT electronic couplings (interaction energies) before orthogonalization
     496              : !> \param metric       Reliability metric for CDFT electronic couplings
     497              : !> \param rotation     CDFT electronic couplings using the weight function matrix for orthogonalization
     498              : !> \param H            The mixed CDFT Hamiltonian
     499              : !> \param S            The overlap matrix between CDFT states
     500              : !> \param Wad          Integrals of type <Psi_a | w_d(r) | Psi_d>
     501              : !> \param Wda          Integrals of type <Psi_d | w_a(r) | Psi_a>
     502              : !> \param W_diagonal   Values of the CDFT constraints
     503              : !> \param energy       Energies of the CDFT states
     504              : !> \param strength     Lagrangian multipliers of the CDFT states
     505              : !> \param S_minushalf  S^(-1/2)
     506              : !> \author Nico Holmberg [11.2017]
     507              : ! **************************************************************************************************
     508         1136 :    SUBROUTINE mixed_cdft_result_type_set(results, lowdin, wfn, nonortho, metric, rotation, &
     509         1136 :                                          H, S, Wad, Wda, W_diagonal, energy, strength, S_minushalf)
     510              :       TYPE(mixed_cdft_result_type)                       :: results
     511              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL              :: lowdin, wfn, nonortho
     512              :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL           :: metric
     513              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL              :: rotation
     514              :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL           :: H, S, Wad, Wda, W_diagonal
     515              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL              :: energy
     516              :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL           :: strength, S_minushalf
     517              : 
     518          568 :       IF (PRESENT(lowdin)) THEN
     519           20 :          IF (ALLOCATED(results%lowdin)) DEALLOCATE (results%lowdin)
     520           60 :          ALLOCATE (results%lowdin(SIZE(lowdin)))
     521           40 :          results%lowdin(:) = lowdin(:)
     522              :       END IF
     523          568 :       IF (PRESENT(wfn)) THEN
     524            8 :          IF (ALLOCATED(results%wfn)) DEALLOCATE (results%wfn)
     525           24 :          ALLOCATE (results%wfn(SIZE(wfn)))
     526           20 :          results%wfn(:) = wfn(:)
     527              :       END IF
     528          568 :       IF (PRESENT(nonortho)) THEN
     529           18 :          IF (ALLOCATED(results%nonortho)) DEALLOCATE (results%nonortho)
     530           54 :          ALLOCATE (results%nonortho(SIZE(nonortho)))
     531          118 :          results%nonortho(:) = nonortho(:)
     532              :       END IF
     533          568 :       IF (PRESENT(rotation)) THEN
     534           96 :          IF (ALLOCATED(results%rotation)) DEALLOCATE (results%rotation)
     535          288 :          ALLOCATE (results%rotation(SIZE(rotation)))
     536          274 :          results%rotation(:) = rotation(:)
     537              :       END IF
     538          568 :       IF (PRESENT(energy)) THEN
     539          100 :          IF (ALLOCATED(results%energy)) DEALLOCATE (results%energy)
     540          300 :          ALLOCATE (results%energy(SIZE(energy)))
     541          324 :          results%energy(:) = energy(:)
     542              :       END IF
     543          568 :       IF (PRESENT(strength)) THEN
     544          100 :          IF (ALLOCATED(results%strength)) DEALLOCATE (results%strength)
     545          400 :          ALLOCATE (results%strength(SIZE(strength, 1), SIZE(strength, 2)))
     546          552 :          results%strength(:, :) = strength(:, :)
     547              :       END IF
     548          568 :       IF (PRESENT(metric)) THEN
     549           14 :          IF (ALLOCATED(results%metric)) DEALLOCATE (results%metric)
     550           56 :          ALLOCATE (results%metric(SIZE(metric, 1), SIZE(metric, 2)))
     551           78 :          results%metric(:, :) = metric(:, :)
     552              :       END IF
     553          568 :       IF (PRESENT(H)) THEN
     554          110 :          IF (ALLOCATED(results%H)) DEALLOCATE (results%H)
     555          440 :          ALLOCATE (results%H(SIZE(H, 1), SIZE(H, 2)))
     556         1038 :          results%H(:, :) = H(:, :)
     557              :       END IF
     558          568 :       IF (PRESENT(S)) THEN
     559          110 :          IF (ALLOCATED(results%S)) DEALLOCATE (results%S)
     560          440 :          ALLOCATE (results%S(SIZE(S, 1), SIZE(S, 2)))
     561         1038 :          results%S(:, :) = S(:, :)
     562              :       END IF
     563          568 :       IF (PRESENT(S_minushalf)) THEN
     564          100 :          IF (ALLOCATED(results%S_minushalf)) DEALLOCATE (results%S_minushalf)
     565          400 :          ALLOCATE (results%S_minushalf(SIZE(S_minushalf, 1), SIZE(S_minushalf, 2)))
     566          912 :          results%S_minushalf(:, :) = S_minushalf(:, :)
     567              :       END IF
     568          568 :       IF (PRESENT(Wad)) THEN
     569            2 :          IF (ALLOCATED(results%Wad)) DEALLOCATE (results%Wad)
     570            8 :          ALLOCATE (results%Wad(SIZE(Wad, 1), SIZE(Wad, 2)))
     571            6 :          results%Wad(:, :) = Wad(:, :)
     572              :       END IF
     573          568 :       IF (PRESENT(Wda)) THEN
     574          100 :          IF (ALLOCATED(results%Wda)) DEALLOCATE (results%Wda)
     575          400 :          ALLOCATE (results%Wda(SIZE(Wda, 1), SIZE(Wda, 2)))
     576          466 :          results%Wda(:, :) = Wda(:, :)
     577              :       END IF
     578          568 :       IF (PRESENT(W_diagonal)) THEN
     579          100 :          IF (ALLOCATED(results%W_diagonal)) DEALLOCATE (results%W_diagonal)
     580          400 :          ALLOCATE (results%W_diagonal(SIZE(W_diagonal, 1), SIZE(W_diagonal, 2)))
     581          552 :          results%W_diagonal(:, :) = W_diagonal(:, :)
     582              :       END IF
     583              : 
     584          568 :    END SUBROUTINE mixed_cdft_result_type_set
     585              : 
     586              : ! **************************************************************************************************
     587              : !> \brief Releases all arrays within the mixed CDFT result container
     588              : !> \param results the container
     589              : !> \author Nico Holmberg [11.2017]
     590              : ! **************************************************************************************************
     591          178 :    SUBROUTINE mixed_cdft_result_type_release(results)
     592              :       TYPE(mixed_cdft_result_type)                       :: results
     593              : 
     594          178 :       IF (ALLOCATED(results%lowdin)) DEALLOCATE (results%lowdin)
     595          178 :       IF (ALLOCATED(results%wfn)) DEALLOCATE (results%wfn)
     596          178 :       IF (ALLOCATED(results%metric)) DEALLOCATE (results%metric)
     597          178 :       IF (ALLOCATED(results%nonortho)) DEALLOCATE (results%nonortho)
     598          178 :       IF (ALLOCATED(results%rotation)) DEALLOCATE (results%rotation)
     599          178 :       IF (ALLOCATED(results%H)) DEALLOCATE (results%H)
     600          178 :       IF (ALLOCATED(results%S)) DEALLOCATE (results%S)
     601          178 :       IF (ALLOCATED(results%S_minushalf)) DEALLOCATE (results%S_minushalf)
     602          178 :       IF (ALLOCATED(results%Wad)) DEALLOCATE (results%Wad)
     603          178 :       IF (ALLOCATED(results%Wda)) DEALLOCATE (results%Wda)
     604          178 :       IF (ALLOCATED(results%W_diagonal)) DEALLOCATE (results%W_diagonal)
     605          178 :       IF (ALLOCATED(results%energy)) DEALLOCATE (results%energy)
     606          178 :       IF (ALLOCATED(results%strength)) DEALLOCATE (results%strength)
     607              : 
     608          178 :    END SUBROUTINE mixed_cdft_result_type_release
     609              : 
     610              : ! **************************************************************************************************
     611              : !> \brief Initializes the mixed_cdft_work_type
     612              : !> \param matrix the type to initialize
     613              : !> \author Nico Holmberg [01.2017]
     614              : ! **************************************************************************************************
     615          100 :    SUBROUTINE mixed_cdft_work_type_init(matrix)
     616              :       TYPE(mixed_cdft_work_type)                         :: matrix
     617              : 
     618          100 :       NULLIFY (matrix%w_matrix)
     619          100 :       NULLIFY (matrix%mixed_matrix_s)
     620          100 :       NULLIFY (matrix%mixed_mo_coeff)
     621          100 :       NULLIFY (matrix%density_matrix)
     622              : 
     623          100 :    END SUBROUTINE mixed_cdft_work_type_init
     624              : 
     625              : ! **************************************************************************************************
     626              : !> \brief Releases arrays within the mixed CDFT work matrix container
     627              : !> \param matrix the container
     628              : !> \author Nico Holmberg [01.2017]
     629              : ! **************************************************************************************************
     630          178 :    SUBROUTINE mixed_cdft_work_type_release(matrix)
     631              :       TYPE(mixed_cdft_work_type)                         :: matrix
     632              : 
     633              :       INTEGER                                            :: i, j
     634              : 
     635          178 :       IF (ASSOCIATED(matrix%w_matrix)) THEN
     636          202 :          DO i = 1, SIZE(matrix%w_matrix, 2)
     637          430 :             DO j = 1, SIZE(matrix%w_matrix, 1)
     638          330 :                CALL dbcsr_release_p(matrix%w_matrix(j, i)%matrix)
     639              :             END DO
     640              :          END DO
     641          100 :          DEALLOCATE (matrix%w_matrix)
     642              :       END IF
     643          178 :       IF (ASSOCIATED(matrix%mixed_matrix_s)) THEN
     644          100 :          CALL dbcsr_release_p(matrix%mixed_matrix_s)
     645              :       END IF
     646          178 :       IF (ASSOCIATED(matrix%mixed_mo_coeff)) THEN
     647          294 :          DO i = 1, SIZE(matrix%mixed_mo_coeff, 2)
     648          730 :             DO j = 1, SIZE(matrix%mixed_mo_coeff, 1)
     649          630 :                CALL cp_fm_release(matrix%mixed_mo_coeff(j, i))
     650              :             END DO
     651              :          END DO
     652          100 :          DEALLOCATE (matrix%mixed_mo_coeff)
     653              :       END IF
     654          178 :       IF (ASSOCIATED(matrix%density_matrix)) THEN
     655           42 :          DO i = 1, SIZE(matrix%density_matrix, 2)
     656          102 :             DO j = 1, SIZE(matrix%density_matrix, 1)
     657           88 :                CALL dbcsr_release_p(matrix%density_matrix(j, i)%matrix)
     658              :             END DO
     659              :          END DO
     660           14 :          DEALLOCATE (matrix%density_matrix)
     661              :       END IF
     662              : 
     663          178 :    END SUBROUTINE mixed_cdft_work_type_release
     664              : 
     665            0 : END MODULE mixed_cdft_types
        

Generated by: LCOV version 2.0-1