LCOV - code coverage report
Current view: top level - src/common - cp_iter_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:3db43b4) Lines: 90.0 % 50 45
Test Date: 2026-04-03 06:55:30 Functions: 80.0 % 5 4

            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 Collection of routines to handle the iteration info
      10              : ! **************************************************************************************************
      11              : MODULE cp_iter_types
      12              :    USE kinds,                           ONLY: default_path_length,&
      13              :                                               default_string_length
      14              : #include "../base/base_uses.f90"
      15              : 
      16              :    IMPLICIT NONE
      17              :    PRIVATE
      18              : 
      19              :    ! iteration_info
      20              :    PUBLIC :: cp_iteration_info_type, &
      21              :              cp_iteration_info_create, &
      22              :              cp_iteration_info_retain, &
      23              :              cp_iteration_info_release, &
      24              :              cp_iteration_info_copy_iter
      25              : 
      26              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_iter_types'
      27              :    LOGICAL, PRIVATE, PARAMETER          :: debug_this_module = .FALSE.
      28              : 
      29              :    ! When adding a new iteration level PLEASE update the following list with the proper name!
      30              :    CHARACTER(LEN=default_path_length), PARAMETER, PUBLIC, DIMENSION(19) :: each_possible_labels = [ &
      31              :                                                                            "__ROOT__          ", &
      32              :                                                                            "JUST_ENERGY       ", &
      33              :                                                                            "POWELL_OPT        ", &
      34              :                                                                            "QS_SCF            ", &
      35              :                                                                            "XAS_SCF           ", &
      36              :                                                                            "MD                ", &
      37              :                                                                            "PINT              ", &
      38              :                                                                            "METADYNAMICS      ", &
      39              :                                                                            "GEO_OPT           ", &
      40              :                                                                            "ROT_OPT           ", &
      41              :                                                                            "CELL_OPT          ", &
      42              :                                                                            "BAND              ", &
      43              :                                                                            "EP_LIN_SOLVER     ", &
      44              :                                                                            "SPLINE_FIND_COEFFS", &
      45              :                                                                            "REPLICA_EVAL      ", &
      46              :                                                                            "BSSE              ", &
      47              :                                                                            "SHELL_OPT         ", &
      48              :                                                                            "TDDFT_SCF         ", &
      49              :                                                                            "NEGF_SCF          "]
      50              : 
      51              :    CHARACTER(LEN=default_path_length), PARAMETER, PUBLIC, DIMENSION(19) ::  each_desc_labels = [ &
      52              :                                                 "Iteration level for __ROOT__ (fictitious iteration level)                      ", &
      53              :                                                 "Iteration level for an ENERGY/ENERGY_FORCE calculation.                        ", &
      54              :                                                 "Iteration level for POWELL based optimization steps.                           ", &
      55              :                                                 "Iteration level for the SCF steps.                                             ", &
      56              :                                                 "Iteration level for the X-Ray Absorption Spectroscopy (XAS) SCF steps.         ", &
      57              :                                                 "Iteration level for the MD steps.                                              ", &
      58              :                                                 "Iteration level for the Path integral md steps.                                ", &
      59              :                                                 "Iteration level for the METADYNAMICS steps (number of hills added).            ", &
      60              :                                                 "Iteration level for the Geometry optimization steps.                           ", &
      61              :                                                 "Iteration level for the Rotational optimization steps in the Dimer calculation.", &
      62              :                                                 "Iteration level for the Cell optimization steps.                               ", &
      63              :                                                 "Iteration level for the BAND calculation steps                                 ", &
      64              :                                                 "Iteration level for the Energy Perturbation (EP) linear solver                 ", &
      65              :                                                 "Iteration level for the solution of the coefficients of the splines            ", &
      66              :                                                 "Iteration level for the evaluation of the Replica Environment                  ", &
      67              :                                                 "Iteration level for the Basis Set Superposition Error (BSSE) calculation       ", &
      68              :                                                 "Iteration level for the Shell-Core distances optimization steps                ", &
      69              :                                                 "Iteration level for the Time-Dependent Density Functional Theory SCF steps.    ", &
      70              :                                                   "Iteration level for the NEGF SCF steps.                                        "]
      71              : 
      72              : ! **************************************************************************************************
      73              : !> \brief contains the information about the current state of the program
      74              : !>      to be able to decide if output is necessary
      75              : !> \author fawzi
      76              : ! **************************************************************************************************
      77              :    TYPE cp_iteration_info_type
      78              :       INTEGER                              :: ref_count = -1
      79              :       INTEGER                              :: print_level = -1, n_rlevel = -1
      80              :       INTEGER, DIMENSION(:), POINTER       :: iteration => NULL()
      81              :       LOGICAL, DIMENSION(:), POINTER       :: last_iter => NULL()
      82              :       CHARACTER(len=default_string_length) :: project_name = ""
      83              :       CHARACTER(LEN=default_string_length), &
      84              :          DIMENSION(:), POINTER           :: level_name => NULL()
      85              :    END TYPE cp_iteration_info_type
      86              : 
      87              : CONTAINS
      88              : 
      89              : ! **************************************************************************************************
      90              : !> \brief creates an output info object
      91              : !> \param iteration_info the object to create
      92              : !> \param project_name name of the project, used to create the filenames
      93              : !> \author fawzi
      94              : ! **************************************************************************************************
      95        21650 :    PURE SUBROUTINE cp_iteration_info_create(iteration_info, project_name)
      96              :       TYPE(cp_iteration_info_type), POINTER              :: iteration_info
      97              :       CHARACTER(len=*), INTENT(in)                       :: project_name
      98              : 
      99            0 :       ALLOCATE (iteration_info)
     100              : 
     101        21650 :       iteration_info%ref_count = 1
     102        21650 :       iteration_info%print_level = 2
     103        21650 :       iteration_info%n_rlevel = 1
     104        21650 :       iteration_info%project_name = project_name
     105        64950 :       ALLOCATE (iteration_info%iteration(iteration_info%n_rlevel))
     106        64950 :       ALLOCATE (iteration_info%level_name(iteration_info%n_rlevel))
     107        64950 :       ALLOCATE (iteration_info%last_iter(iteration_info%n_rlevel))
     108        21650 :       iteration_info%iteration(iteration_info%n_rlevel) = 1
     109        21650 :       iteration_info%level_name(iteration_info%n_rlevel) = "__ROOT__"
     110        21650 :       iteration_info%last_iter(iteration_info%n_rlevel) = .FALSE.
     111              : 
     112        21650 :    END SUBROUTINE cp_iteration_info_create
     113              : 
     114              : ! **************************************************************************************************
     115              : !> \brief retains the iteration_info (see doc/ReferenceCounting.html)
     116              : !> \param iteration_info the iteration_info to retain
     117              : !> \author fawzi
     118              : ! **************************************************************************************************
     119        41833 :    SUBROUTINE cp_iteration_info_retain(iteration_info)
     120              :       TYPE(cp_iteration_info_type), INTENT(INOUT)        :: iteration_info
     121              : 
     122              :       CHARACTER(len=*), PARAMETER :: routineN = 'cp_iteration_info_retain', &
     123              :          routineP = moduleN//':'//routineN
     124              : 
     125        41833 :       IF (iteration_info%ref_count <= 0) THEN
     126            0 :          CPABORT(routineP//" iteration_info%ref_counf<=0")
     127              :       END IF
     128        41833 :       iteration_info%ref_count = iteration_info%ref_count + 1
     129        41833 :    END SUBROUTINE cp_iteration_info_retain
     130              : 
     131              : ! **************************************************************************************************
     132              : !> \brief releases the iteration_info (see doc/ReferenceCounting.html)
     133              : !> \param iteration_info the iteration_info to release
     134              : !> \author fawzi
     135              : ! **************************************************************************************************
     136        63483 :    SUBROUTINE cp_iteration_info_release(iteration_info)
     137              :       TYPE(cp_iteration_info_type), POINTER              :: iteration_info
     138              : 
     139              :       CHARACTER(len=*), PARAMETER :: routineN = 'cp_iteration_info_release', &
     140              :          routineP = moduleN//':'//routineN
     141              : 
     142        63483 :       IF (ASSOCIATED(iteration_info)) THEN
     143        63483 :          IF (iteration_info%ref_count <= 0) THEN
     144            0 :             CPABORT(routineP//" iteration_info%ref_counf<=0")
     145              :          END IF
     146        63483 :          iteration_info%ref_count = iteration_info%ref_count - 1
     147        63483 :          IF (iteration_info%ref_count == 0) THEN
     148        21650 :             IF (ASSOCIATED(iteration_info%iteration)) THEN
     149        21650 :                DEALLOCATE (iteration_info%iteration)
     150              :             END IF
     151        21650 :             IF (ASSOCIATED(iteration_info%last_iter)) THEN
     152        21650 :                DEALLOCATE (iteration_info%last_iter)
     153              :             END IF
     154        21650 :             IF (ASSOCIATED(iteration_info%level_name)) THEN
     155        21650 :                DEALLOCATE (iteration_info%level_name)
     156              :             END IF
     157        21650 :             DEALLOCATE (iteration_info)
     158              :          END IF
     159              :       END IF
     160        63483 :    END SUBROUTINE cp_iteration_info_release
     161              : 
     162              : ! **************************************************************************************************
     163              : !> \brief Copies iterations info of an iteration info into another iteration info
     164              : !> \param iteration_info_in the iteration_info to be copied
     165              : !> \param iteration_info_out the iteration_info results of the copy
     166              : !> \author Teodoro Laino [tlaino]
     167              : ! **************************************************************************************************
     168          738 :    SUBROUTINE cp_iteration_info_copy_iter(iteration_info_in, iteration_info_out)
     169              :       TYPE(cp_iteration_info_type), INTENT(INOUT)        :: iteration_info_in, iteration_info_out
     170              : 
     171              :       CHARACTER(len=*), PARAMETER :: routineN = 'cp_iteration_info_copy_iter', &
     172              :          routineP = moduleN//':'//routineN
     173              : 
     174              :       INTEGER                                            :: i
     175              : 
     176          738 :       IF (iteration_info_in%ref_count <= 0) THEN
     177            0 :          CPABORT(routineP//" iteration_info_in%ref_counf<=0")
     178              :       END IF
     179              : 
     180          738 :       iteration_info_out%n_rlevel = iteration_info_in%n_rlevel
     181              : 
     182          738 :       DEALLOCATE (iteration_info_out%iteration)
     183          738 :       i = SIZE(iteration_info_in%iteration)
     184         2214 :       ALLOCATE (iteration_info_out%iteration(i))
     185         2214 :       iteration_info_out%iteration = iteration_info_in%iteration
     186              : 
     187          738 :       DEALLOCATE (iteration_info_out%last_iter)
     188          738 :       i = SIZE(iteration_info_in%last_iter)
     189         2214 :       ALLOCATE (iteration_info_out%last_iter(i))
     190         2214 :       iteration_info_out%last_iter = iteration_info_in%last_iter
     191              : 
     192          738 :       DEALLOCATE (iteration_info_out%level_name)
     193          738 :       i = SIZE(iteration_info_in%level_name)
     194         2214 :       ALLOCATE (iteration_info_out%level_name(i))
     195         2214 :       iteration_info_out%level_name = iteration_info_in%level_name
     196              : 
     197          738 :    END SUBROUTINE cp_iteration_info_copy_iter
     198              : 
     199            0 : END MODULE cp_iter_types
     200              : 
        

Generated by: LCOV version 2.0-1