LCOV - code coverage report
Current view: top level - src/arnoldi - arnoldi_data_methods.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 87.6 % 193 169
Test Date: 2026-11-24 01:22:08 Functions: 88.2 % 17 15

            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 The methods which allow to analyze and manipulate the arnoldi procedure
      10              : !>        The main routine and this should eb the only public access point for the method
      11              : !> \par History
      12              : !>       2014.09 created [Florian Schiffmann]
      13              : !>       2023.12 Removed support for single-precision [Ole Schuett]
      14              : !>       2024.12 Removed support for complex input matrices [Ole Schuett]
      15              : !> \author Florian Schiffmann
      16              : ! **************************************************************************************************
      17              : MODULE arnoldi_data_methods
      18              :    USE arnoldi_types,                   ONLY: &
      19              :         arnoldi_control_type, arnoldi_data_type, arnoldi_env_type, get_control, get_data, &
      20              :         get_evals, get_sel_ind, set_control, set_data
      21              :    USE arnoldi_vector,                  ONLY: create_col_vec_from_matrix,&
      22              :                                               transfer_dbcsr_to_local_array,&
      23              :                                               transfer_local_array_to_dbcsr
      24              :    USE cp_dbcsr_api,                    ONLY: &
      25              :         dbcsr_distribution_get, dbcsr_distribution_type, dbcsr_get_info, dbcsr_get_matrix_type, &
      26              :         dbcsr_mp_grid_setup, dbcsr_p_type, dbcsr_release, dbcsr_type, dbcsr_type_symmetric
      27              :    USE kinds,                           ONLY: dp
      28              :    USE util,                            ONLY: sort
      29              : #include "../base/base_uses.f90"
      30              : 
      31              :    IMPLICIT NONE
      32              : 
      33              :    PRIVATE
      34              : 
      35              :    PUBLIC :: select_evals, get_selected_ritz_val, arnoldi_is_converged, &
      36              :              arnoldi_env_type, get_nrestart, set_arnoldi_initial_vector, &
      37              :              setup_arnoldi_env, deallocate_arnoldi_env, get_selected_ritz_vector
      38              : 
      39              : CONTAINS
      40              : 
      41              : ! **************************************************************************************************
      42              : !> \brief This routine sets the environment for the arnoldi iteration and
      43              : !>        the krylov subspace creation. All simulation parameters have to be given
      44              : !>        at this stage so the rest can run fully automated
      45              : !>        In addition, this routine allocates the data necessary for
      46              : !> \param arnoldi_env this type which gets filled with information and on output contains all
      47              : !>                    information necessary to extract whatever the user desires
      48              : !> \param matrix vector of matrices, only the first gets used to get some dimensions
      49              : !>        and parallel information needed later on
      50              : !> \param max_iter maximum dimension of the krylov subspace
      51              : !> \param threshold convergence threshold, this is used for both subspace and eigenval
      52              : !> \param selection_crit integer defining according to which criterion the
      53              : !>        eigenvalues are selected for the subspace
      54              : !> \param nval_request for some sel_crit useful, how many eV to select
      55              : !> \param nrestarts ...
      56              : !> \param generalized_ev ...
      57              : !> \param iram ...
      58              : ! **************************************************************************************************
      59       138051 :    SUBROUTINE setup_arnoldi_env(arnoldi_env, matrix, max_iter, threshold, selection_crit, &
      60              :                                 nval_request, nrestarts, generalized_ev, iram)
      61              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
      62              :       TYPE(dbcsr_p_type), DIMENSION(:)                   :: matrix
      63              :       INTEGER                                            :: max_iter
      64              :       REAL(dp)                                           :: threshold
      65              :       INTEGER                                            :: selection_crit, nval_request, nrestarts
      66              :       LOGICAL                                            :: generalized_ev, iram
      67              : 
      68              :       CALL setup_arnoldi_control(arnoldi_env, matrix, max_iter, threshold, selection_crit, &
      69       138051 :                                  nval_request, nrestarts, generalized_ev, iram)
      70              : 
      71       138051 :       CALL setup_arnoldi_data(arnoldi_env, matrix, max_iter)
      72              : 
      73       138051 :    END SUBROUTINE setup_arnoldi_env
      74              : 
      75              : ! **************************************************************************************************
      76              : !> \brief Creates the data type for arnoldi, see above for details
      77              : !> \param arnoldi_env ...
      78              : !> \param matrix ...
      79              : !> \param max_iter ...
      80              : ! **************************************************************************************************
      81       138051 :    SUBROUTINE setup_arnoldi_data(arnoldi_env, matrix, max_iter)
      82              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
      83              :       TYPE(dbcsr_p_type), DIMENSION(:)                   :: matrix
      84              :       INTEGER                                            :: max_iter
      85              : 
      86              :       INTEGER                                            :: nrow_local
      87              :       TYPE(arnoldi_data_type), POINTER                   :: ar_data
      88              : 
      89       138051 :       ALLOCATE (ar_data)
      90       138051 :       CALL dbcsr_get_info(matrix=matrix(1)%matrix, nfullrows_local=nrow_local)
      91       359302 :       ALLOCATE (ar_data%f_vec(nrow_local))
      92       221251 :       ALLOCATE (ar_data%x_vec(nrow_local))
      93       552204 :       ALLOCATE (ar_data%Hessenberg(max_iter + 1, max_iter))
      94       497353 :       ALLOCATE (ar_data%local_history(nrow_local, max_iter))
      95              : 
      96       414153 :       ALLOCATE (ar_data%evals(max_iter))
      97       552204 :       ALLOCATE (ar_data%revec(max_iter, max_iter))
      98              : 
      99       138051 :       CALL set_data(arnoldi_env, ar_data)
     100              : 
     101       138051 :    END SUBROUTINE setup_arnoldi_data
     102              : 
     103              : ! **************************************************************************************************
     104              : !> \brief Creates the control type for arnoldi, see above for details
     105              : !> \param arnoldi_env ...
     106              : !> \param matrix ...
     107              : !> \param max_iter ...
     108              : !> \param threshold ...
     109              : !> \param selection_crit ...
     110              : !> \param nval_request ...
     111              : !> \param nrestarts ...
     112              : !> \param generalized_ev ...
     113              : !> \param iram ...
     114              : ! **************************************************************************************************
     115       138051 :    SUBROUTINE setup_arnoldi_control(arnoldi_env, matrix, max_iter, threshold, selection_crit, &
     116              :                                     nval_request, nrestarts, generalized_ev, iram)
     117              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     118              :       TYPE(dbcsr_p_type), DIMENSION(:)                   :: matrix
     119              :       INTEGER                                            :: max_iter
     120              :       REAL(dp)                                           :: threshold
     121              :       INTEGER                                            :: selection_crit, nval_request, nrestarts
     122              :       LOGICAL                                            :: generalized_ev, iram
     123              : 
     124              :       INTEGER                                            :: group_handle, pcol_handle
     125              :       LOGICAL                                            :: subgroups_defined
     126              :       TYPE(arnoldi_control_type), POINTER                :: control
     127              :       TYPE(dbcsr_distribution_type)                      :: distri
     128              : 
     129            0 :       ALLOCATE (control)
     130              :       ! Fill the information which will later control the arnoldi method and allow synchronization.
     131       138051 :       CALL dbcsr_get_info(matrix=matrix(1)%matrix, distribution=distri)
     132       138051 :       CALL dbcsr_mp_grid_setup(distri)
     133              :       CALL dbcsr_distribution_get(distri, &
     134              :                                   group=group_handle, &
     135              :                                   mynode=control%myproc, &
     136              :                                   subgroups_defined=subgroups_defined, &
     137       138051 :                                   pcol_group=pcol_handle)
     138              : 
     139       138051 :       CALL control%mp_group%set_handle(group_handle)
     140       138051 :       CALL control%pcol_group%set_handle(pcol_handle)
     141              : 
     142       138051 :       IF (.NOT. subgroups_defined) THEN
     143            0 :          CPABORT("arnoldi only with subgroups")
     144              :       END IF
     145              : 
     146       138051 :       control%symmetric = .FALSE.
     147              :       ! Will need a fix for complex because there it has to be hermitian
     148       138051 :       IF (SIZE(matrix) == 1) THEN
     149       133436 :          control%symmetric = dbcsr_get_matrix_type(matrix(1)%matrix) == dbcsr_type_symmetric
     150              :       END IF
     151              : 
     152              :       ! Set the control parameters
     153       138051 :       control%max_iter = max_iter
     154       138051 :       control%current_step = 0
     155       138051 :       control%selection_crit = selection_crit
     156       138051 :       control%nval_req = nval_request
     157       138051 :       control%threshold = threshold
     158       138051 :       control%converged = .FALSE.
     159       138051 :       control%has_initial_vector = .FALSE.
     160       138051 :       control%iram = iram
     161       138051 :       control%nrestart = nrestarts
     162       138051 :       control%generalized_ev = generalized_ev
     163              : 
     164       138051 :       IF (control%nval_req > 1 .AND. control%nrestart > 0 .AND. .NOT. control%iram) THEN
     165              :          CALL cp_abort(__LOCATION__, 'with more than one eigenvalue requested '// &
     166            0 :                        'internal restarting with a previous EVEC is a bad idea, set IRAM or nrestsart=0')
     167              :       END IF
     168              : 
     169              :       ! some checks for the generalized EV mode
     170       138051 :       IF (control%generalized_ev .AND. selection_crit == 1) THEN
     171              :          CALL cp_abort(__LOCATION__, &
     172            0 :                        'generalized ev can only highest OR lowest EV')
     173              :       END IF
     174       138051 :       IF (control%generalized_ev .AND. nval_request /= 1) THEN
     175              :          CALL cp_abort(__LOCATION__, &
     176            0 :                        'generalized ev can only compute one EV at the time')
     177              :       END IF
     178       138051 :       IF (control%generalized_ev .AND. control%nrestart == 0) THEN
     179              :          CALL cp_abort(__LOCATION__, &
     180            0 :                        'outer loops are mandatory for generalized EV, set nrestart appropriatly')
     181              :       END IF
     182       138051 :       IF (SIZE(matrix) /= 2 .AND. control%generalized_ev) THEN
     183              :          CALL cp_abort(__LOCATION__, &
     184            0 :                        'generalized ev needs exactly two matrices as input (2nd is the metric)')
     185              :       END IF
     186              : 
     187       414153 :       ALLOCATE (control%selected_ind(max_iter))
     188       138051 :       CALL set_control(arnoldi_env, control)
     189              : 
     190       276102 :    END SUBROUTINE setup_arnoldi_control
     191              : 
     192              : ! **************************************************************************************************
     193              : !> \brief ...
     194              : !> \param arnoldi_env ...
     195              : !> \param ind ...
     196              : !> \param matrix ...
     197              : !> \param vector ...
     198              : ! **************************************************************************************************
     199       143194 :    SUBROUTINE get_selected_ritz_vector(arnoldi_env, ind, matrix, vector)
     200              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     201              :       INTEGER                                            :: ind
     202              :       TYPE(dbcsr_type)                                   :: matrix, vector
     203              : 
     204       143194 :       COMPLEX(dp), ALLOCATABLE, DIMENSION(:)             :: ritz_v
     205              :       INTEGER                                            :: i, myind, sspace_size, vsize
     206       143194 :       INTEGER, DIMENSION(:), POINTER                     :: selected_ind
     207              :       TYPE(arnoldi_control_type), POINTER                :: control
     208              :       TYPE(arnoldi_data_type), POINTER                   :: ar_data
     209              : 
     210       286388 :       control => get_control(arnoldi_env)
     211       143194 :       selected_ind => get_sel_ind(arnoldi_env)
     212       143194 :       ar_data => get_data(arnoldi_env)
     213       143194 :       sspace_size = get_subsp_size(arnoldi_env)
     214       143194 :       vsize = SIZE(ar_data%f_vec)
     215       143194 :       myind = selected_ind(ind)
     216       372594 :       ALLOCATE (ritz_v(vsize))
     217       143194 :       ritz_v = CMPLX(0.0, 0.0, dp)
     218              : 
     219       143194 :       CALL dbcsr_release(vector)
     220       143194 :       CALL create_col_vec_from_matrix(vector, matrix, 1)
     221       143194 :       IF (control%local_comp) THEN
     222       503711 :          DO i = 1, sspace_size
     223      7987098 :             ritz_v(:) = ritz_v(:) + ar_data%local_history(:, i)*ar_data%revec(i, myind)
     224              :          END DO
     225              :          ! is a bit odd but ritz_v is always complex and matrix type determines where it goes
     226              :          ! again I hope the user knows what is required
     227       860308 :          CALL transfer_local_array_to_dbcsr(vector, REAL(ritz_v(1:vsize), KIND=dp), vsize, .TRUE.)
     228              :       END IF
     229              : 
     230       143194 :       DEALLOCATE (ritz_v)
     231              : 
     232       143194 :    END SUBROUTINE get_selected_ritz_vector
     233              : 
     234              : ! **************************************************************************************************
     235              : !> \brief Deallocate the data in arnoldi_env
     236              : !> \param arnoldi_env ...
     237              : ! **************************************************************************************************
     238       138051 :    SUBROUTINE deallocate_arnoldi_env(arnoldi_env)
     239              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     240              : 
     241              :       TYPE(arnoldi_control_type), POINTER                :: control
     242              :       TYPE(arnoldi_data_type), POINTER                   :: ar_data
     243              : 
     244       138051 :       ar_data => get_data(arnoldi_env)
     245       138051 :       IF (ASSOCIATED(ar_data%f_vec)) DEALLOCATE (ar_data%f_vec)
     246       138051 :       IF (ASSOCIATED(ar_data%x_vec)) DEALLOCATE (ar_data%x_vec)
     247       138051 :       IF (ASSOCIATED(ar_data%Hessenberg)) DEALLOCATE (ar_data%Hessenberg)
     248       138051 :       IF (ASSOCIATED(ar_data%local_history)) DEALLOCATE (ar_data%local_history)
     249       138051 :       IF (ASSOCIATED(ar_data%evals)) DEALLOCATE (ar_data%evals)
     250       138051 :       IF (ASSOCIATED(ar_data%revec)) DEALLOCATE (ar_data%revec)
     251       138051 :       DEALLOCATE (ar_data)
     252              : 
     253       138051 :       control => get_control(arnoldi_env)
     254       138051 :       DEALLOCATE (control%selected_ind)
     255       138051 :       DEALLOCATE (control)
     256              : 
     257       138051 :    END SUBROUTINE deallocate_arnoldi_env
     258              : 
     259              : ! **************************************************************************************************
     260              : !> \brief perform the selection of eigenvalues, fills the selected_ind array
     261              : !> \param arnoldi_env ...
     262              : ! **************************************************************************************************
     263       138987 :    SUBROUTINE select_evals(arnoldi_env)
     264              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     265              : 
     266              :       INTEGER                                            :: i, last_el, my_crit, my_ind
     267              :       REAL(dp)                                           :: convergence
     268              :       TYPE(arnoldi_control_type), POINTER                :: control
     269              :       TYPE(arnoldi_data_type), POINTER                   :: ar_data
     270              : 
     271       138987 :       control => get_control(arnoldi_env)
     272       138987 :       ar_data => get_data(arnoldi_env)
     273              : 
     274       138987 :       last_el = control%current_step
     275       138987 :       convergence = REAL(0.0, dp)
     276       138987 :       my_crit = control%selection_crit
     277       138987 :       control%nval_out = MIN(control%nval_req, control%current_step)
     278       128385 :       SELECT CASE (my_crit)
     279              :          ! minimum and maximum real eval
     280              :       CASE (1)
     281       128385 :          CALL index_min_max_real_eval(ar_data%evals, control%current_step, control%selected_ind, control%nval_out)
     282              :          ! n maximum real eval
     283              :       CASE (2)
     284         4843 :          CALL index_nmax_real_eval(ar_data%evals, control%current_step, control%selected_ind, control%nval_out)
     285              :          ! n minimum real eval
     286              :       CASE (3)
     287         5759 :          CALL index_nmin_real_eval(ar_data%evals, control%current_step, control%selected_ind, control%nval_out)
     288              :       CASE DEFAULT
     289       138987 :          CPABORT("unknown selection index")
     290              :       END SELECT
     291              :       ! test whether we are converged
     292       406359 :       DO i = 1, control%nval_out
     293       267372 :          my_ind = control%selected_ind(i)
     294              :          convergence = MAX(convergence, &
     295       406359 :                            ABS(ar_data%revec(last_el, my_ind)*ar_data%Hessenberg(last_el + 1, last_el)))
     296              :       END DO
     297       138987 :       control%converged = convergence < control%threshold
     298              : 
     299       138987 :    END SUBROUTINE select_evals
     300              : 
     301              : ! **************************************************************************************************
     302              : !> \brief set a new selection type, if you notice you didn't like the initial one
     303              : !> \param arnoldi_env ...
     304              : !> \param itype ...
     305              : ! **************************************************************************************************
     306            0 :    SUBROUTINE set_eval_selection(arnoldi_env, itype)
     307              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     308              :       INTEGER                                            :: itype
     309              : 
     310              :       TYPE(arnoldi_control_type), POINTER                :: control
     311              : 
     312            0 :       control => get_control(arnoldi_env)
     313            0 :       control%selection_crit = itype
     314            0 :    END SUBROUTINE set_eval_selection
     315              : 
     316              : ! **************************************************************************************************
     317              : !> \brief returns the number of restarts allowed for arnoldi
     318              : !> \param arnoldi_env ...
     319              : !> \return ...
     320              : ! **************************************************************************************************
     321       137835 :    FUNCTION get_nrestart(arnoldi_env) RESULT(nrestart)
     322              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     323              :       INTEGER                                            :: nrestart
     324              : 
     325              :       TYPE(arnoldi_control_type), POINTER                :: control
     326              : 
     327       137835 :       control => get_control(arnoldi_env)
     328       137835 :       nrestart = control%nrestart
     329              : 
     330       137835 :    END FUNCTION get_nrestart
     331              : 
     332              : ! **************************************************************************************************
     333              : !> \brief get the number of eigenvalues matching the search criterion
     334              : !> \param arnoldi_env ...
     335              : !> \return ...
     336              : ! **************************************************************************************************
     337       266096 :    FUNCTION get_nval_out(arnoldi_env) RESULT(nval_out)
     338              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     339              :       INTEGER                                            :: nval_out
     340              : 
     341              :       TYPE(arnoldi_control_type), POINTER                :: control
     342              : 
     343       266096 :       control => get_control(arnoldi_env)
     344       266096 :       nval_out = control%nval_out
     345              : 
     346       266096 :    END FUNCTION get_nval_out
     347              : 
     348              : ! **************************************************************************************************
     349              : !> \brief get dimension of the krylov space. Can be less than max_iter if subspace converged early
     350              : !> \param arnoldi_env ...
     351              : !> \return ...
     352              : ! **************************************************************************************************
     353       143194 :    FUNCTION get_subsp_size(arnoldi_env) RESULT(current_step)
     354              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     355              :       INTEGER                                            :: current_step
     356              : 
     357              :       TYPE(arnoldi_control_type), POINTER                :: control
     358              : 
     359       143194 :       control => get_control(arnoldi_env)
     360       143194 :       current_step = control%current_step
     361              : 
     362       143194 :    END FUNCTION get_subsp_size
     363              : 
     364              : ! **************************************************************************************************
     365              : !> \brief Find out whether the method with the current search criterion is converged
     366              : !> \param arnoldi_env ...
     367              : !> \return ...
     368              : ! **************************************************************************************************
     369       128477 :    FUNCTION arnoldi_is_converged(arnoldi_env) RESULT(converged)
     370              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     371              :       LOGICAL                                            :: converged
     372              : 
     373              :       TYPE(arnoldi_control_type), POINTER                :: control
     374              : 
     375       128477 :       control => get_control(arnoldi_env)
     376       128477 :       converged = control%converged
     377              : 
     378       128477 :    END FUNCTION arnoldi_is_converged
     379              : 
     380              : ! **************************************************************************************************
     381              : !> \brief get a single specific Ritz value from the set of selected
     382              : !> \param arnoldi_env ...
     383              : !> \param ind ...
     384              : !> \return ...
     385              : ! **************************************************************************************************
     386       266096 :    FUNCTION get_selected_ritz_val(arnoldi_env, ind) RESULT(eval_out)
     387              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     388              :       INTEGER                                            :: ind
     389              :       COMPLEX(dp)                                        :: eval_out
     390              : 
     391       266096 :       COMPLEX(dp), DIMENSION(:), POINTER                 :: evals
     392              :       INTEGER                                            :: ev_ind
     393       266096 :       INTEGER, DIMENSION(:), POINTER                     :: selected_ind
     394              : 
     395       266096 :       IF (ind > get_nval_out(arnoldi_env)) THEN
     396            0 :          CPABORT('outside range of indexed evals')
     397              :       END IF
     398              : 
     399       266096 :       selected_ind => get_sel_ind(arnoldi_env)
     400       266096 :       ev_ind = selected_ind(ind)
     401       266096 :       evals => get_evals(arnoldi_env)
     402       266096 :       eval_out = evals(ev_ind)
     403              : 
     404       266096 :    END FUNCTION get_selected_ritz_val
     405              : 
     406              : ! **************************************************************************************************
     407              : !> \brief Get all Ritz values of the selected set. eval_out has to be allocated
     408              : !>        at least the size of get_neval_out()
     409              : !> \param arnoldi_env ...
     410              : !> \param eval_out ...
     411              : ! **************************************************************************************************
     412            0 :    SUBROUTINE get_all_selected_ritz_val(arnoldi_env, eval_out)
     413              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     414              :       COMPLEX(dp), DIMENSION(:)                          :: eval_out
     415              : 
     416            0 :       COMPLEX(dp), DIMENSION(:), POINTER                 :: evals
     417              :       INTEGER                                            :: ev_ind, ind
     418            0 :       INTEGER, DIMENSION(:), POINTER                     :: selected_ind
     419              : 
     420            0 :       NULLIFY (evals)
     421            0 :       IF (SIZE(eval_out) < get_nval_out(arnoldi_env)) THEN
     422            0 :          CPABORT('array for eval output too small')
     423              :       END IF
     424            0 :       selected_ind => get_sel_ind(arnoldi_env)
     425              : 
     426            0 :       evals => get_evals(arnoldi_env)
     427              : 
     428            0 :       DO ind = 1, get_nval_out(arnoldi_env)
     429            0 :          ev_ind = selected_ind(ind)
     430            0 :          eval_out(ind) = evals(ev_ind)
     431              :       END DO
     432              : 
     433            0 :    END SUBROUTINE get_all_selected_ritz_val
     434              : 
     435              : ! **************************************************************************************************
     436              : !> \brief ...
     437              : !> \param arnoldi_env ...
     438              : !> \param vector ...
     439              : ! **************************************************************************************************
     440        10648 :    SUBROUTINE set_arnoldi_initial_vector(arnoldi_env, vector)
     441              :       TYPE(arnoldi_env_type)                             :: arnoldi_env
     442              :       TYPE(dbcsr_type)                                   :: vector
     443              : 
     444              :       INTEGER                                            :: ncol_local, nrow_local
     445              :       TYPE(arnoldi_control_type), POINTER                :: control
     446              :       TYPE(arnoldi_data_type), POINTER                   :: ar_data
     447              : 
     448         5324 :       control => get_control(arnoldi_env)
     449         5324 :       control%has_initial_vector = .TRUE.
     450         5324 :       ar_data => get_data(arnoldi_env)
     451              : 
     452         5324 :       CALL dbcsr_get_info(matrix=vector, nfullrows_local=nrow_local, nfullcols_local=ncol_local)
     453         5324 :       IF (nrow_local*ncol_local > 0) THEN
     454         4230 :          CALL transfer_dbcsr_to_local_array(vector, ar_data%f_vec, nrow_local, .TRUE.)
     455              :       END IF
     456              : 
     457         5324 :    END SUBROUTINE set_arnoldi_initial_vector
     458              : 
     459              : !!! Here come the methods handling the selection of eigenvalues and eigenvectors !!!
     460              : !!! If you want a personal method, simply created a Subroutine returning the index
     461              : !!! array selected ind which contains as the first nval_out entries the index of the evals
     462              : 
     463              : ! **************************************************************************************************
     464              : !> \brief ...
     465              : !> \param evals ...
     466              : !> \param current_step ...
     467              : !> \param selected_ind ...
     468              : !> \param neval ...
     469              : ! **************************************************************************************************
     470       128385 :    SUBROUTINE index_min_max_real_eval(evals, current_step, selected_ind, neval)
     471              :       COMPLEX(dp), DIMENSION(:)                          :: evals
     472              :       INTEGER, INTENT(IN)                                :: current_step
     473              :       INTEGER, DIMENSION(:)                              :: selected_ind
     474              :       INTEGER                                            :: neval
     475              : 
     476              :       INTEGER                                            :: i
     477       256770 :       INTEGER, DIMENSION(current_step)                   :: indexing
     478       256770 :       REAL(dp), DIMENSION(current_step)                  :: tmp_array
     479              : 
     480       128385 :       neval = 0
     481      4258721 :       selected_ind = 0
     482       597104 :       tmp_array(1:current_step) = REAL(evals(1:current_step), dp)
     483       128385 :       CALL sort(tmp_array, current_step, indexing)
     484       128385 :       DO i = 1, current_step
     485       128385 :          IF (ABS(AIMAG(evals(indexing(i)))) < EPSILON(0.0_dp)) THEN
     486       128385 :             selected_ind(1) = indexing(i)
     487       128385 :             neval = neval + 1
     488       128385 :             EXIT
     489              :          END IF
     490              :       END DO
     491       128385 :       DO i = current_step, 1, -1
     492       128385 :          IF (ABS(AIMAG(evals(indexing(i)))) < EPSILON(0.0_dp)) THEN
     493       128385 :             selected_ind(2) = indexing(i)
     494       128385 :             neval = neval + 1
     495       128385 :             EXIT
     496              :          END IF
     497              :       END DO
     498              : 
     499       128385 :    END SUBROUTINE index_min_max_real_eval
     500              : 
     501              : ! **************************************************************************************************
     502              : !> \brief ...
     503              : !> \param evals ...
     504              : !> \param current_step ...
     505              : !> \param selected_ind ...
     506              : !> \param neval ...
     507              : ! **************************************************************************************************
     508         4843 :    SUBROUTINE index_nmax_real_eval(evals, current_step, selected_ind, neval)
     509              :       COMPLEX(dp), DIMENSION(:)                          :: evals
     510              :       INTEGER, INTENT(IN)                                :: current_step
     511              :       INTEGER, DIMENSION(:)                              :: selected_ind
     512              :       INTEGER                                            :: neval
     513              : 
     514              :       INTEGER                                            :: i, nlimit
     515         9686 :       INTEGER, DIMENSION(current_step)                   :: indexing
     516         9686 :       REAL(dp), DIMENSION(current_step)                  :: tmp_array
     517              : 
     518         4843 :       nlimit = neval; neval = 0
     519       101703 :       selected_ind = 0
     520        24006 :       tmp_array(1:current_step) = REAL(evals(1:current_step), dp)
     521         4843 :       CALL sort(tmp_array, current_step, indexing)
     522         4843 :       DO i = 1, current_step
     523         9686 :          IF (ABS(AIMAG(evals(indexing(current_step + 1 - i)))) < EPSILON(0.0_dp)) THEN
     524         4843 :             selected_ind(i) = indexing(current_step + 1 - i)
     525         4843 :             neval = neval + 1
     526         4843 :             IF (neval == nlimit) EXIT
     527              :          END IF
     528              :       END DO
     529              : 
     530         4843 :    END SUBROUTINE index_nmax_real_eval
     531              : 
     532              : ! **************************************************************************************************
     533              : !> \brief ...
     534              : !> \param evals ...
     535              : !> \param current_step ...
     536              : !> \param selected_ind ...
     537              : !> \param neval ...
     538              : ! **************************************************************************************************
     539         5759 :    SUBROUTINE index_nmin_real_eval(evals, current_step, selected_ind, neval)
     540              :       COMPLEX(dp), DIMENSION(:)                          :: evals
     541              :       INTEGER, INTENT(IN)                                :: current_step
     542              :       INTEGER, DIMENSION(:)                              :: selected_ind
     543              :       INTEGER                                            :: neval
     544              : 
     545              :       INTEGER                                            :: i, nlimit
     546        11518 :       INTEGER, DIMENSION(current_step)                   :: indexing
     547        11518 :       REAL(dp), DIMENSION(current_step)                  :: tmp_array
     548              : 
     549         5759 :       nlimit = neval; neval = 0
     550       120939 :       selected_ind = 0
     551        93484 :       tmp_array(1:current_step) = REAL(evals(1:current_step), dp)
     552         5759 :       CALL sort(tmp_array, current_step, indexing)
     553         5759 :       DO i = 1, current_step
     554        11518 :          IF (ABS(AIMAG(evals(indexing(i)))) < EPSILON(0.0_dp)) THEN
     555         5759 :             selected_ind(i) = indexing(i)
     556         5759 :             neval = neval + 1
     557         5759 :             IF (neval == nlimit) EXIT
     558              :          END IF
     559              :       END DO
     560              : 
     561         5759 :    END SUBROUTINE index_nmin_real_eval
     562              : 
     563              : END MODULE arnoldi_data_methods
        

Generated by: LCOV version 2.0-1