LCOV - code coverage report
Current view: top level - src - preconditioner_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4dc10b3) Lines: 45 49 91.8 %
Date: 2024-11-21 06:45:46 Functions: 3 5 60.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief types of  preconditioners
      10             : !> \par History
      11             : !>      Separate types from construction and application
      12             : !> \author Joost VandeVondele (09.2002)
      13             : ! **************************************************************************************************
      14             : MODULE preconditioner_types
      15             :    USE cp_blacs_env,                    ONLY: cp_blacs_env_release,&
      16             :                                               cp_blacs_env_type
      17             :    USE cp_dbcsr_api,                    ONLY: dbcsr_deallocate_matrix,&
      18             :                                               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 input_constants,                 ONLY: cholesky_reduce,&
      24             :                                               ot_precond_solver_default
      25             :    USE kinds,                           ONLY: dp
      26             :    USE message_passing,                 ONLY: mp_para_env_release,&
      27             :                                               mp_para_env_type
      28             : #include "./base/base_uses.f90"
      29             : 
      30             :    IMPLICIT NONE
      31             : 
      32             :    PRIVATE
      33             : 
      34             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'preconditioner_types'
      35             : 
      36             :    PUBLIC  :: preconditioner_type, preconditioner_p_type
      37             :    PUBLIC  :: init_preconditioner
      38             :    PUBLIC  :: preconditioner_in_use
      39             :    PUBLIC  :: destroy_preconditioner
      40             : 
      41             : ! **************************************************************************************************
      42             :    TYPE preconditioner_type
      43             : !    PRIVATE
      44             :       TYPE(dbcsr_type), POINTER :: sparse_matrix => NULL()
      45             :       TYPE(cp_fm_type), POINTER :: fm => NULL()
      46             :       TYPE(dbcsr_type), POINTER           :: dbcsr_matrix => NULL()
      47             :       TYPE(dbcsr_type), POINTER           :: max_ev_vector => NULL()
      48             :       TYPE(dbcsr_type), POINTER           :: min_ev_vector => NULL()
      49             :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:) :: inverse_history => NULL()
      50             :       TYPE(mp_para_env_type), POINTER   :: para_env => NULL()
      51             :       TYPE(cp_blacs_env_type), POINTER   :: ctxt => NULL()
      52             :       INTEGER :: in_use = -1, solver = -1, ihistory = -1, cholesky_use = -1
      53             :       REAL(KIND=dp), DIMENSION(:), POINTER :: occ_evals => NULL(), full_evals => NULL()
      54             :       REAL(KIND=dp) :: energy_gap = -1.0_dp
      55             :       REAL(KIND=dp) :: condition_num = -1.0_dp
      56             :    END TYPE preconditioner_type
      57             : 
      58             : ! **************************************************************************************************
      59             :    TYPE preconditioner_p_type
      60             :       TYPE(preconditioner_type), POINTER :: preconditioner => NULL()
      61             :    END TYPE preconditioner_p_type
      62             : 
      63             : CONTAINS
      64             : 
      65             : ! **************************************************************************************************
      66             : 
      67             : ! **************************************************************************************************
      68             : !> \brief ...
      69             : !> \param preconditioner ...
      70             : !> \return ...
      71             : ! **************************************************************************************************
      72         294 :    FUNCTION preconditioner_in_use(preconditioner)
      73             :       TYPE(preconditioner_type)                          :: preconditioner
      74             :       LOGICAL                                            :: preconditioner_in_use
      75             : 
      76         294 :       preconditioner_in_use = .NOT. (preconditioner%in_use .EQ. 0)
      77         294 :    END FUNCTION
      78             : 
      79             : ! **************************************************************************************************
      80             : !> \brief ...
      81             : !> \param preconditioner_env ...
      82             : !> \param para_env ...
      83             : !> \param blacs_env ...
      84             : ! **************************************************************************************************
      85        5966 :    SUBROUTINE init_preconditioner(preconditioner_env, para_env, blacs_env)
      86             : 
      87             :       TYPE(preconditioner_type)                          :: preconditioner_env
      88             :       TYPE(mp_para_env_type), POINTER                    :: para_env
      89             :       TYPE(cp_blacs_env_type), POINTER                   :: blacs_env
      90             : 
      91        5966 :       NULLIFY (preconditioner_env%sparse_matrix)
      92        5966 :       NULLIFY (preconditioner_env%fm)
      93        5966 :       NULLIFY (preconditioner_env%dbcsr_matrix)
      94        5966 :       NULLIFY (preconditioner_env%occ_evals)
      95        5966 :       NULLIFY (preconditioner_env%full_evals)
      96        5966 :       NULLIFY (preconditioner_env%inverse_history)
      97        5966 :       NULLIFY (preconditioner_env%max_ev_vector)
      98        5966 :       NULLIFY (preconditioner_env%min_ev_vector)
      99        5966 :       preconditioner_env%solver = ot_precond_solver_default
     100        5966 :       preconditioner_env%para_env => para_env
     101        5966 :       preconditioner_env%ctxt => blacs_env
     102             :       !inverse is used for filtering in update set it to something huge to
     103             :       ! avoid filtering if the information is not available
     104        5966 :       preconditioner_env%condition_num = -1.0_dp
     105        5966 :       preconditioner_env%ihistory = 0
     106             : 
     107        5966 :       CALL preconditioner_env%para_env%retain()
     108        5966 :       CALL preconditioner_env%ctxt%retain()
     109             : 
     110        5966 :    END SUBROUTINE init_preconditioner
     111             : 
     112             : ! **************************************************************************************************
     113             : !> \brief ...
     114             : !> \param preconditioner_env ...
     115             : ! **************************************************************************************************
     116        5966 :    SUBROUTINE destroy_preconditioner(preconditioner_env)
     117             : 
     118             :       TYPE(preconditioner_type)                          :: preconditioner_env
     119             : 
     120             :       CHARACTER(len=*), PARAMETER :: routineN = 'destroy_preconditioner'
     121             : 
     122             :       INTEGER                                            :: handle, i
     123             : 
     124        5966 :       CALL timeset(routineN, handle)
     125             : 
     126        5966 :       IF (ASSOCIATED(preconditioner_env%sparse_matrix)) THEN
     127           2 :          CALL dbcsr_deallocate_matrix(preconditioner_env%sparse_matrix)
     128           2 :          NULLIFY (preconditioner_env%sparse_matrix)
     129             :       END IF
     130             : 
     131        5966 :       IF (ASSOCIATED(preconditioner_env%fm)) THEN
     132        1438 :          CALL cp_fm_release(preconditioner_env%fm)
     133        1438 :          DEALLOCATE (preconditioner_env%fm)
     134             :          NULLIFY (preconditioner_env%fm)
     135             :       END IF
     136        5966 :       IF (ASSOCIATED(preconditioner_env%dbcsr_matrix)) THEN
     137        3968 :          CALL dbcsr_release_p(preconditioner_env%dbcsr_matrix)
     138             :       END IF
     139        5966 :       IF (ASSOCIATED(preconditioner_env%max_ev_vector)) THEN
     140        1709 :          CALL dbcsr_release_p(preconditioner_env%max_ev_vector)
     141             :       END IF
     142        5966 :       IF (ASSOCIATED(preconditioner_env%min_ev_vector)) THEN
     143        1709 :          CALL dbcsr_release_p(preconditioner_env%min_ev_vector)
     144             :       END IF
     145        5966 :       IF (ASSOCIATED(preconditioner_env%occ_evals)) THEN
     146        3012 :          DEALLOCATE (preconditioner_env%occ_evals)
     147             :       END IF
     148        5966 :       IF (ASSOCIATED(preconditioner_env%full_evals)) THEN
     149        3012 :          DEALLOCATE (preconditioner_env%full_evals)
     150             :       END IF
     151        5966 :       IF (ASSOCIATED(preconditioner_env%inverse_history)) THEN
     152           0 :          DO i = 1, SIZE(preconditioner_env%inverse_history)
     153           0 :             CALL dbcsr_release_p(preconditioner_env%inverse_history(i)%matrix)
     154             :          END DO
     155           0 :          DEALLOCATE (preconditioner_env%inverse_history)
     156             :       END IF
     157        5966 :       CALL mp_para_env_release(preconditioner_env%para_env)
     158        5966 :       CALL cp_blacs_env_release(preconditioner_env%ctxt)
     159             : 
     160        5966 :       preconditioner_env%in_use = 0
     161        5966 :       preconditioner_env%cholesky_use = cholesky_reduce
     162             : 
     163        5966 :       CALL timestop(handle)
     164             : 
     165        5966 :    END SUBROUTINE destroy_preconditioner
     166             : 
     167           0 : END MODULE preconditioner_types
     168             : 

Generated by: LCOV version 1.15