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

Generated by: LCOV version 2.0-1