LCOV - code coverage report
Current view: top level - src/motion - cell_opt.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:262480d) Lines: 39 39 100.0 %
Date: 2024-11-22 07:00:40 Functions: 2 2 100.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 performs CELL optimization
      10             : !> \par History
      11             : !>      03.2008 - Teodoro Laino [tlaino] - University of Zurich - Cell Optimization
      12             : ! **************************************************************************************************
      13             : MODULE cell_opt
      14             :    USE bfgs_optimizer,                  ONLY: geoopt_bfgs
      15             :    USE cg_optimizer,                    ONLY: geoopt_cg
      16             :    USE cp_lbfgs_geo,                    ONLY: geoopt_lbfgs
      17             :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      18             :                                               cp_logger_type
      19             :    USE cp_output_handling,              ONLY: cp_add_iter_level,&
      20             :                                               cp_iterate,&
      21             :                                               cp_rm_iter_level
      22             :    USE force_env_types,                 ONLY: force_env_type
      23             :    USE global_types,                    ONLY: global_environment_type
      24             :    USE gopt_f_methods,                  ONLY: gopt_f_create_x0
      25             :    USE gopt_f_types,                    ONLY: gopt_f_create,&
      26             :                                               gopt_f_release,&
      27             :                                               gopt_f_type
      28             :    USE gopt_param_types,                ONLY: gopt_param_read,&
      29             :                                               gopt_param_type
      30             :    USE input_constants,                 ONLY: default_bfgs_method_id,&
      31             :                                               default_cell_method_id,&
      32             :                                               default_cg_method_id,&
      33             :                                               default_lbfgs_method_id
      34             :    USE input_section_types,             ONLY: section_vals_get_subs_vals,&
      35             :                                               section_vals_type,&
      36             :                                               section_vals_val_get,&
      37             :                                               section_vals_val_set
      38             :    USE kinds,                           ONLY: dp
      39             : #include "../base/base_uses.f90"
      40             : 
      41             :    IMPLICIT NONE
      42             :    PRIVATE
      43             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cell_opt'
      44             : 
      45             :    PUBLIC :: cp_cell_opt
      46             : 
      47             : CONTAINS
      48             : 
      49             : ! **************************************************************************************************
      50             : !> \brief Main driver to perform geometry optimization
      51             : !> \param force_env ...
      52             : !> \param globenv ...
      53             : !> \author Teodoro Laino [tlaino] - University of Zurich - 03.2008
      54             : ! **************************************************************************************************
      55         420 :    SUBROUTINE cp_cell_opt(force_env, globenv)
      56             :       TYPE(force_env_type), POINTER                      :: force_env
      57             :       TYPE(global_environment_type), POINTER             :: globenv
      58             : 
      59             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'cp_cell_opt'
      60             : 
      61             :       INTEGER                                            :: handle, step_start_val
      62         210 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: x0
      63             :       TYPE(cp_logger_type), POINTER                      :: logger
      64             :       TYPE(gopt_f_type), POINTER                         :: gopt_env
      65             :       TYPE(gopt_param_type), POINTER                     :: gopt_param
      66             :       TYPE(section_vals_type), POINTER                   :: force_env_section, geo_section, &
      67             :                                                             root_section
      68             : 
      69         210 :       CALL timeset(routineN, handle)
      70         210 :       logger => cp_get_default_logger()
      71         210 :       CPASSERT(ASSOCIATED(force_env))
      72         210 :       CPASSERT(ASSOCIATED(globenv))
      73         210 :       NULLIFY (gopt_param, force_env_section, gopt_env, x0)
      74         210 :       root_section => force_env%root_section
      75         210 :       force_env_section => force_env%force_env_section
      76         210 :       geo_section => section_vals_get_subs_vals(root_section, "MOTION%CELL_OPT")
      77             : 
      78         210 :       ALLOCATE (gopt_param)
      79         210 :       CALL gopt_param_read(gopt_param, geo_section, type_id=default_cell_method_id)
      80             :       CALL gopt_f_create(gopt_env, gopt_param, force_env=force_env, globenv=globenv, &
      81         210 :                          geo_opt_section=geo_section)
      82         210 :       CALL gopt_f_create_x0(gopt_env, x0)
      83             : 
      84         210 :       CALL section_vals_val_get(geo_section, "STEP_START_VAL", i_val=step_start_val)
      85         210 :       CALL cp_add_iter_level(logger%iter_info, "CELL_OPT")
      86         210 :       CALL cp_iterate(logger%iter_info, iter_nr=step_start_val)
      87             :       CALL cp_cell_opt_low(force_env, globenv, gopt_param, gopt_env, &
      88         210 :                            force_env_section, geo_section, x0)
      89         210 :       CALL cp_rm_iter_level(logger%iter_info, "CELL_OPT")
      90             : 
      91             :       ! Reset counter for next iteration
      92         210 :       CALL section_vals_val_set(geo_section, "STEP_START_VAL", i_val=0)
      93         210 :       DEALLOCATE (x0)
      94         210 :       CALL gopt_f_release(gopt_env)
      95         210 :       DEALLOCATE (gopt_param)
      96         210 :       CALL timestop(handle)
      97             : 
      98         210 :    END SUBROUTINE cp_cell_opt
      99             : 
     100             : ! **************************************************************************************************
     101             : !> \brief call to low level geometry optimizers
     102             : !> \param force_env ...
     103             : !> \param globenv ...
     104             : !> \param gopt_param ...
     105             : !> \param gopt_env ...
     106             : !> \param force_env_section ...
     107             : !> \param geo_section ...
     108             : !> \param x0 ...
     109             : !> \author Teodoro Laino [tlaino] - University of Zurich - 03.2008
     110             : ! **************************************************************************************************
     111         210 :    SUBROUTINE cp_cell_opt_low(force_env, globenv, gopt_param, gopt_env, force_env_section, &
     112             :                               geo_section, x0)
     113             :       TYPE(force_env_type), POINTER                      :: force_env
     114             :       TYPE(global_environment_type), POINTER             :: globenv
     115             :       TYPE(gopt_param_type), POINTER                     :: gopt_param
     116             :       TYPE(gopt_f_type), POINTER                         :: gopt_env
     117             :       TYPE(section_vals_type), POINTER                   :: force_env_section, geo_section
     118             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: x0
     119             : 
     120         210 :       CPASSERT(ASSOCIATED(force_env))
     121         210 :       CPASSERT(ASSOCIATED(globenv))
     122         210 :       CPASSERT(ASSOCIATED(gopt_param))
     123         210 :       CPASSERT(ASSOCIATED(gopt_env))
     124         210 :       CPASSERT(ASSOCIATED(x0))
     125         210 :       CPASSERT(ASSOCIATED(force_env_section))
     126         210 :       CPASSERT(ASSOCIATED(geo_section))
     127             :       MARK_USED(force_env_section)
     128             : 
     129         328 :       SELECT CASE (gopt_param%method_id)
     130             :       CASE (default_bfgs_method_id)
     131             :          CALL geoopt_bfgs(force_env, gopt_param, globenv, &
     132         118 :                           geo_section, gopt_env, x0)
     133             :       CASE (default_lbfgs_method_id)
     134             :          CALL geoopt_lbfgs(force_env, gopt_param, globenv, &
     135          46 :                            geo_section, gopt_env, x0)
     136             :       CASE (default_cg_method_id)
     137             :          CALL geoopt_cg(force_env, gopt_param, globenv, &
     138          46 :                         geo_section, gopt_env, x0)
     139             :       CASE DEFAULT
     140         210 :          CPABORT("")
     141             :       END SELECT
     142             : 
     143         210 :    END SUBROUTINE cp_cell_opt_low
     144             : 
     145             : END MODULE cell_opt

Generated by: LCOV version 1.15