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 performs CELL optimization
10 : !> \par History
11 : !> 03.2008 - Teodoro Laino [tlaino] - University of Zurich - Cell Optimization
12 : ! **************************************************************************************************
13 : MODULE cell_opt
14 : USE cp_log_handling, ONLY: cp_get_default_logger,&
15 : cp_logger_type
16 : USE cp_output_handling, ONLY: cp_add_iter_level,&
17 : cp_iterate,&
18 : cp_rm_iter_level
19 : USE force_env_types, ONLY: force_env_type
20 : USE geo_opt, ONLY: gopt_dispatch_optimizer
21 : USE global_types, ONLY: global_environment_type
22 : USE gopt_f_methods, ONLY: gopt_f_create_x0
23 : USE gopt_f_types, ONLY: gopt_f_create,&
24 : gopt_f_release,&
25 : gopt_f_type
26 : USE gopt_param_types, ONLY: gopt_param_read,&
27 : gopt_param_type
28 : USE input_constants, ONLY: default_cell_method_id
29 : USE input_section_types, ONLY: section_vals_get_subs_vals,&
30 : section_vals_type,&
31 : section_vals_val_get,&
32 : section_vals_val_set
33 : USE kinds, ONLY: dp
34 : #include "../base/base_uses.f90"
35 :
36 : IMPLICIT NONE
37 : PRIVATE
38 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cell_opt'
39 :
40 : PUBLIC :: cp_cell_opt
41 :
42 : CONTAINS
43 :
44 : ! **************************************************************************************************
45 : !> \brief Main driver to perform geometry optimization
46 : !> \param force_env ...
47 : !> \param globenv ...
48 : !> \author Teodoro Laino [tlaino] - University of Zurich - 03.2008
49 : ! **************************************************************************************************
50 468 : SUBROUTINE cp_cell_opt(force_env, globenv)
51 : TYPE(force_env_type), POINTER :: force_env
52 : TYPE(global_environment_type), POINTER :: globenv
53 :
54 : CHARACTER(len=*), PARAMETER :: routineN = 'cp_cell_opt'
55 :
56 : INTEGER :: handle, step_start_val
57 234 : REAL(KIND=dp), DIMENSION(:), POINTER :: x0
58 : TYPE(cp_logger_type), POINTER :: logger
59 : TYPE(gopt_f_type), POINTER :: gopt_env
60 : TYPE(gopt_param_type), POINTER :: gopt_param
61 : TYPE(section_vals_type), POINTER :: geo_section, root_section
62 :
63 234 : CALL timeset(routineN, handle)
64 234 : logger => cp_get_default_logger()
65 234 : CPASSERT(ASSOCIATED(force_env))
66 234 : CPASSERT(ASSOCIATED(globenv))
67 234 : NULLIFY (gopt_param, gopt_env, x0)
68 234 : root_section => force_env%root_section
69 234 : geo_section => section_vals_get_subs_vals(root_section, "MOTION%CELL_OPT")
70 :
71 234 : ALLOCATE (gopt_param)
72 234 : CALL gopt_param_read(gopt_param, geo_section, type_id=default_cell_method_id)
73 : CALL gopt_f_create(gopt_env, gopt_param, force_env=force_env, globenv=globenv, &
74 234 : geo_opt_section=geo_section)
75 234 : CALL gopt_f_create_x0(gopt_env, x0)
76 :
77 234 : CALL section_vals_val_get(geo_section, "STEP_START_VAL", i_val=step_start_val)
78 234 : CALL cp_add_iter_level(logger, "CELL_OPT")
79 234 : CALL cp_iterate(logger%iter_info, iter_nr=step_start_val)
80 : CALL gopt_dispatch_optimizer(force_env, globenv, gopt_param, gopt_env, &
81 234 : geo_section, x0)
82 234 : CALL cp_rm_iter_level(logger, "CELL_OPT")
83 :
84 : ! Reset counter for next iteration
85 234 : CALL section_vals_val_set(geo_section, "STEP_START_VAL", i_val=0)
86 234 : DEALLOCATE (x0)
87 234 : CALL gopt_f_release(gopt_env)
88 234 : DEALLOCATE (gopt_param)
89 234 : CALL timestop(handle)
90 :
91 234 : END SUBROUTINE cp_cell_opt
92 :
93 : END MODULE cell_opt
|