(git:374b731)
Loading...
Searching...
No Matches
optimize_basis_types.F
Go to the documentation of this file.
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!--------------------------------------------------------------------------------------------------!
8
9 USE kinds, ONLY: default_path_length,&
11 dp
12 USE powell, ONLY: opt_state_type
13#include "./base/base_uses.f90"
14
15 IMPLICIT NONE
16 PRIVATE
17
18 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'optimize_basis_types'
19
22
23 ! constraint information for a single constraing. boundary is translateed into a fermi function
24 ! like setting as for variational limited case
25 TYPE exp_constraint_type
26 INTEGER :: const_type
27 REAL(KIND=dp) :: llim, ulim
28 REAL(KIND=dp) :: init, var_fac
29 END TYPE
30
31 ! Subset of a basis+ additional information on what to optimize.
32 ! *_x_ind maps to the index in the optimization vector
33 ! opt_* logical whether quantity ahould be optimized
34 ! *_const information for exponents used to constrain them
36 INTEGER :: lmin, lmax, nexp
37 INTEGER :: n, ncon_tot, nl
38 INTEGER, DIMENSION(:), ALLOCATABLE :: l
39 REAL(kind=dp), DIMENSION(:, :), ALLOCATABLE :: coeff
40 LOGICAL, DIMENSION(:, :), ALLOCATABLE :: opt_coeff
41 INTEGER, DIMENSION(:, :), ALLOCATABLE :: coeff_x_ind
42 REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: exps
43 LOGICAL, DIMENSION(:), ALLOCATABLE :: opt_exps
44 INTEGER, DIMENSION(:), ALLOCATABLE :: exp_x_ind
45 LOGICAL, DIMENSION(:), ALLOCATABLE :: exp_has_const
46 TYPE(exp_constraint_type), DIMENSION(:), &
47 ALLOCATABLE :: exp_const
48 END TYPE
49
50 ! Top level information for basis sets+ vector subset with the real information
52 CHARACTER(LEN=default_string_length) :: basis_name
53 INTEGER :: nopt
54 INTEGER :: nsets
55 TYPE(subset_type), DIMENSION(:), ALLOCATABLE :: subset
56 END TYPE
57
58 ! information for optimization: whether coeff has to be optimized or not
59 TYPE use_contr_type
60 LOGICAL, DIMENSION(:), ALLOCATABLE :: in_use
61 END TYPE
62
63 ! information about how to generate the derived basis sets
65 CHARACTER(LEN=default_string_length) :: basis_name
66 INTEGER :: reference_set
67 INTEGER, DIMENSION(:, :), ALLOCATABLE :: remove_contr
68 INTEGER :: nsets, ncontr
69 INTEGER, DIMENSION(:), ALLOCATABLE :: remove_set
70 LOGICAL, DIMENSION(:), ALLOCATABLE :: in_use_set
71 TYPE(use_contr_type), DIMENSION(:), ALLOCATABLE :: use_contr
72 END TYPE
73
74 ! some usual stuff for basis information and an info type containing the
75 ! the translated input on how to genrate the derived basis sets
76 ! a flexible basis type for every derived basis
77 ! ATTENTION: both vectors go from 0:nbasis_deriv. entry 0 is the one specified
78 ! in the template basis file
79 TYPE kind_basis_type
80 CHARACTER(LEN=default_string_length) :: basis_name
81 CHARACTER(LEN=default_string_length) :: element
82 INTEGER :: nbasis_deriv
83 TYPE(derived_basis_info), DIMENSION(:), &
84 ALLOCATABLE :: deriv_info
85 TYPE(flex_basis_type), DIMENSION(:), ALLOCATABLE :: flex_basis
86 END TYPE
87
88 ! vector of length nparallel_groups containing the id's of the calculations in the group
89 TYPE comp_group_type
90 INTEGER, DIMENSION(:), ALLOCATABLE :: member_list
91 END TYPE
92
93! **************************************************************************************************
94!> \brief type containing all information needed for basis matching
95!> \author Florian Schiffmann
96! **************************************************************************************************
98 TYPE(comp_group_type), DIMENSION(:), ALLOCATABLE :: comp_group
99 INTEGER :: ntraining_sets
100 INTEGER :: ncombinations
101 LOGICAL :: use_condition_number
102 INTEGER, DIMENSION(:), POINTER :: group_partition
103 INTEGER :: n_groups_created
104 INTEGER, DIMENSION(:), ALLOCATABLE :: sub_sources
105 INTEGER, DIMENSION(:, :), ALLOCATABLE :: combination
106 REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: fval_weight
107 REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: condition_weight
108 INTEGER :: nkind
109 INTEGER :: write_frequency
110 INTEGER :: nbasis_deriv_types
111 REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: x_opt
112 TYPE(opt_state_type) :: powell_param
113 CHARACTER(LEN=default_path_length), DIMENSION(:), ALLOCATABLE :: training_input
114 CHARACTER(LEN=default_path_length), DIMENSION(:), ALLOCATABLE :: training_dir
115 CHARACTER(LEN=default_path_length) :: work_basis_file
116 CHARACTER(LEN=default_path_length) :: output_basis_file
117 CHARACTER(LEN=default_path_length) :: template_basis_file
118 TYPE(kind_basis_type), DIMENSION(:), ALLOCATABLE :: kind_basis
119 INTEGER :: opt_id
120 END TYPE
121
122CONTAINS
123
124! **************************************************************************************************
125!> \brief Deallocate everything which was allocated before.
126!> Note not all arrays are used depending on the type of basis
127!> i.e derived or reference basis set
128!> \param opt_bas ...
129!> \author Florian Schiffmann
130! **************************************************************************************************
131
133 TYPE(basis_optimization_type) :: opt_bas
134
135 INTEGER :: igroup, ikind
136
137 IF (ASSOCIATED(opt_bas%group_partition)) DEALLOCATE (opt_bas%group_partition)
138 IF (ALLOCATED(opt_bas%sub_sources)) DEALLOCATE (opt_bas%sub_sources)
139 IF (ALLOCATED(opt_bas%combination)) DEALLOCATE (opt_bas%combination)
140 IF (ALLOCATED(opt_bas%x_opt)) DEALLOCATE (opt_bas%x_opt)
141 IF (ALLOCATED(opt_bas%training_input)) DEALLOCATE (opt_bas%training_input)
142 IF (ALLOCATED(opt_bas%training_dir)) DEALLOCATE (opt_bas%training_dir)
143 IF (ALLOCATED(opt_bas%fval_weight)) DEALLOCATE (opt_bas%fval_weight)
144 IF (ALLOCATED(opt_bas%condition_weight)) DEALLOCATE (opt_bas%condition_weight)
145
146 IF (ALLOCATED(opt_bas%comp_group)) THEN
147 DO igroup = 1, SIZE(opt_bas%comp_group)
148 IF (ALLOCATED(opt_bas%comp_group(igroup)%member_list)) DEALLOCATE (opt_bas%comp_group(igroup)%member_list)
149 END DO
150 DEALLOCATE (opt_bas%comp_group)
151 END IF
152
153 IF (ALLOCATED(opt_bas%kind_basis)) THEN
154 DO ikind = 1, SIZE(opt_bas%kind_basis)
155 CALL deallocate_kind_basis(opt_bas%kind_basis(ikind))
156 END DO
157 DEALLOCATE (opt_bas%kind_basis)
158 END IF
159
161
162! **************************************************************************************************
163!> \brief Some more deallocation of the subtypes of optimize_absis type
164!> \param kind ...
165!> \author Florian Schiffmann
166! **************************************************************************************************
167
168 SUBROUTINE deallocate_kind_basis(kind)
169 TYPE(kind_basis_type) :: kind
170
171 INTEGER :: ibasis, icont, iinfo, iset
172
173 IF (ALLOCATED(kind%deriv_info)) THEN
174 DO iinfo = 0, SIZE(kind%deriv_info) - 1
175 IF (ALLOCATED(kind%deriv_info(iinfo)%remove_contr)) DEALLOCATE (kind%deriv_info(iinfo)%remove_contr)
176 IF (ALLOCATED(kind%deriv_info(iinfo)%remove_set)) DEALLOCATE (kind%deriv_info(iinfo)%remove_set)
177 IF (ALLOCATED(kind%deriv_info(iinfo)%in_use_set)) DEALLOCATE (kind%deriv_info(iinfo)%in_use_set)
178 IF (ALLOCATED(kind%deriv_info(iinfo)%use_contr)) THEN
179 DO icont = 1, SIZE(kind%deriv_info(iinfo)%use_contr)
180 IF (ALLOCATED(kind%deriv_info(iinfo)%use_contr(icont)%in_use)) &
181 DEALLOCATE (kind%deriv_info(iinfo)%use_contr(icont)%in_use)
182 END DO
183 DEALLOCATE (kind%deriv_info(iinfo)%use_contr)
184 END IF
185 END DO
186 DEALLOCATE (kind%deriv_info)
187 END IF
188
189 IF (ALLOCATED(kind%flex_basis)) THEN
190 DO ibasis = 0, SIZE(kind%flex_basis) - 1
191 IF (ALLOCATED(kind%flex_basis(ibasis)%subset)) THEN
192 DO iset = 1, SIZE(kind%flex_basis(ibasis)%subset)
193 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%l)) &
194 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%l)
195 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%coeff)) &
196 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%coeff)
197 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%opt_coeff)) &
198 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%opt_coeff)
199 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%coeff_x_ind)) &
200 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%coeff_x_ind)
201 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%exps)) &
202 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%exps)
203 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%opt_exps)) &
204 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%opt_exps)
205 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%exp_x_ind)) &
206 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%exp_x_ind)
207 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%exp_const)) &
208 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%exp_const)
209 END DO
210 DEALLOCATE (kind%flex_basis(ibasis)%subset)
211 END IF
212 END DO
213 DEALLOCATE (kind%flex_basis)
214 END IF
215
216 END SUBROUTINE deallocate_kind_basis
217
218END MODULE optimize_basis_types
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
subroutine, public deallocate_basis_optimization_type(opt_bas)
Deallocate everything which was allocated before. Note not all arrays are used depending on the type ...
Definition powell.F:9
type containing all information needed for basis matching