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 : MODULE qs_fb_env_types
9 :
10 : USE kinds, ONLY: dp
11 : USE qs_fb_atomic_halo_types, ONLY: fb_atomic_halo_list_associate,&
12 : fb_atomic_halo_list_nullify,&
13 : fb_atomic_halo_list_obj,&
14 : fb_atomic_halo_list_release
15 : USE qs_fb_trial_fns_types, ONLY: fb_trial_fns_associate,&
16 : fb_trial_fns_nullify,&
17 : fb_trial_fns_obj,&
18 : fb_trial_fns_release
19 : #include "./base/base_uses.f90"
20 :
21 : IMPLICIT NONE
22 :
23 : PRIVATE
24 :
25 : ! public types
26 : PUBLIC :: fb_env_obj
27 :
28 : ! public methods
29 : PUBLIC :: fb_env_release, &
30 : fb_env_nullify, &
31 : fb_env_has_data, &
32 : fb_env_create, &
33 : fb_env_get, &
34 : fb_env_set
35 :
36 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_fb_env_types'
37 :
38 : ! **********************************************************************
39 : !> \brief wrapper to the simulation parameters used for filtered basis
40 : !> method
41 : !> \param rcut : cutoff for included filtered basis set centred at
42 : !> each atom. These defines the ranges of the atomic
43 : !> halos. rcut(ikind) gives the range for atom of
44 : !> global kind ikind
45 : !> \param atomic_halos : stores information on the neighbors of each
46 : !> atom ii, which are defined by rcut
47 : !> \param filter_temperature : parameter controlling the smoothness of
48 : !> the filter function during the construction
49 : !> of the filter matrix
50 : !> \param auto_cutoff_scale : scale multiplied to max atomic orbital
51 : !> radii used for automatic construction of
52 : !> rcut
53 : !> \param eps_default : anything less than it is regarded as zero
54 : !> \param collective_com : whether the MPI communications are
55 : !> to be done collectively together
56 : !> at the start and end of each
57 : !> filter matrix calculation. This makes
58 : !> communication more efficient in the
59 : !> expense of larger memory usage
60 : !> \param local_atoms : atoms corresponding to the
61 : !> atomic halos responsible by this processor
62 : !> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
63 : ! **********************************************************************
64 : TYPE fb_env_data
65 : REAL(KIND=dp), DIMENSION(:), POINTER :: rcut => NULL()
66 : TYPE(fb_atomic_halo_list_obj) :: atomic_halos = fb_atomic_halo_list_obj()
67 : TYPE(fb_trial_fns_obj) :: trial_fns = fb_trial_fns_obj()
68 : REAL(KIND=dp) :: filter_temperature = -1.0_dp
69 : REAL(KIND=dp) :: auto_cutoff_scale = -1.0_dp
70 : REAL(KIND=dp) :: eps_default = -1.0_dp
71 : LOGICAL :: collective_com = .FALSE.
72 : INTEGER, DIMENSION(:), POINTER :: local_atoms => NULL()
73 : INTEGER :: nlocal_atoms = -1
74 : END TYPE fb_env_data
75 :
76 : ! **************************************************************************************************
77 : !> \brief the object container which allows for the creation of an array of
78 : !> pointers to fb_env
79 : !> \param obj : pointer to a filtered basis environment
80 : !> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
81 : ! **************************************************************************************************
82 : TYPE fb_env_obj
83 : TYPE(fb_env_data), POINTER, PRIVATE :: obj => NULL()
84 : END TYPE fb_env_obj
85 :
86 : CONTAINS
87 :
88 : ! **********************************************************************
89 : !> \brief releases a given fb_env
90 : !> \brief ...
91 : !> \param fb_env : the fb_env to release
92 : !> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
93 : ! **************************************************************************************************
94 10 : SUBROUTINE fb_env_release(fb_env)
95 : TYPE(fb_env_obj), INTENT(INOUT) :: fb_env
96 :
97 10 : IF (ASSOCIATED(fb_env%obj)) THEN
98 10 : IF (ASSOCIATED(fb_env%obj%rcut)) THEN
99 10 : DEALLOCATE (fb_env%obj%rcut)
100 : END IF
101 10 : IF (ASSOCIATED(fb_env%obj%local_atoms)) THEN
102 10 : DEALLOCATE (fb_env%obj%local_atoms)
103 : END IF
104 10 : CALL fb_atomic_halo_list_release(fb_env%obj%atomic_halos)
105 10 : CALL fb_trial_fns_release(fb_env%obj%trial_fns)
106 10 : DEALLOCATE (fb_env%obj)
107 : ELSE
108 0 : NULLIFY (fb_env%obj)
109 : END IF
110 10 : END SUBROUTINE fb_env_release
111 :
112 : ! **********************************************************************
113 : !> \brief nullifies a fb_env object, note that this does not
114 : !> release the original object. This procedure is used mainly
115 : !> to nullify the pointer inside the object which is used to
116 : !> point to the actual data content of the object.
117 : !> \param fb_env : its content must be a NULL fb_env pointer on input,
118 : !> and the output returns an empty fb_env object
119 : !> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
120 : ! **************************************************************************************************
121 8305 : SUBROUTINE fb_env_nullify(fb_env)
122 : TYPE(fb_env_obj), INTENT(INOUT) :: fb_env
123 :
124 8305 : NULLIFY (fb_env%obj)
125 8305 : END SUBROUTINE fb_env_nullify
126 :
127 : ! **********************************************************************
128 : !> \brief Associates one fb_env object to another
129 : !> \param a the fb_env object to be associated
130 : !> \param b the fb_env object that a is to be associated to
131 : !> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
132 : ! **************************************************************************************************
133 0 : SUBROUTINE fb_env_associate(a, b)
134 : TYPE(fb_env_obj), INTENT(OUT) :: a
135 : TYPE(fb_env_obj), INTENT(IN) :: b
136 :
137 0 : a%obj => b%obj
138 0 : END SUBROUTINE fb_env_associate
139 :
140 : ! **********************************************************************
141 : !> \brief Checks if a fb_env object is associated with an actual
142 : !> data content or not
143 : !> \param fb_env the fb_env object
144 : !> \return ...
145 : !> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
146 : ! **************************************************************************************************
147 8405 : FUNCTION fb_env_has_data(fb_env) RESULT(res)
148 : TYPE(fb_env_obj), INTENT(IN) :: fb_env
149 : LOGICAL :: res
150 :
151 8405 : res = ASSOCIATED(fb_env%obj)
152 8405 : END FUNCTION fb_env_has_data
153 :
154 : ! **********************************************************************
155 : !> \brief creates an empty fb_env object
156 : !> \param fb_env : its content must be a NULL fb_env pointer on input,
157 : !> and the output returns an empty fb_env object
158 : !> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
159 : ! **************************************************************************************************
160 10 : SUBROUTINE fb_env_create(fb_env)
161 : TYPE(fb_env_obj), INTENT(INOUT) :: fb_env
162 :
163 10 : CPASSERT(.NOT. ASSOCIATED(fb_env%obj))
164 10 : ALLOCATE (fb_env%obj)
165 : NULLIFY (fb_env%obj%rcut)
166 10 : CALL fb_atomic_halo_list_nullify(fb_env%obj%atomic_halos)
167 10 : CALL fb_trial_fns_nullify(fb_env%obj%trial_fns)
168 10 : fb_env%obj%filter_temperature = 0.0_dp
169 10 : fb_env%obj%auto_cutoff_scale = 1.0_dp
170 10 : fb_env%obj%eps_default = 0.0_dp
171 10 : fb_env%obj%collective_com = .TRUE.
172 10 : NULLIFY (fb_env%obj%local_atoms)
173 10 : fb_env%obj%nlocal_atoms = 0
174 10 : END SUBROUTINE fb_env_create
175 :
176 : ! **********************************************************************
177 : !> \brief initialises a fb_env object to become empty
178 : !> \brief ...
179 : !> \param fb_env : the fb_env object, which must not be NULL or
180 : !> UNDEFINED upon entry
181 : !> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
182 : ! **************************************************************************************************
183 0 : SUBROUTINE fb_env_init(fb_env)
184 : TYPE(fb_env_obj), INTENT(INOUT) :: fb_env
185 :
186 0 : CPASSERT(ASSOCIATED(fb_env%obj))
187 0 : IF (ASSOCIATED(fb_env%obj%rcut)) THEN
188 0 : DEALLOCATE (fb_env%obj%rcut)
189 : END IF
190 0 : CALL fb_atomic_halo_list_release(fb_env%obj%atomic_halos)
191 0 : CALL fb_trial_fns_release(fb_env%obj%trial_fns)
192 0 : fb_env%obj%filter_temperature = 0.0_dp
193 0 : fb_env%obj%auto_cutoff_scale = 1.0_dp
194 0 : fb_env%obj%eps_default = 0.0_dp
195 0 : fb_env%obj%collective_com = .TRUE.
196 0 : IF (ASSOCIATED(fb_env%obj%local_atoms)) THEN
197 0 : DEALLOCATE (fb_env%obj%local_atoms)
198 : END IF
199 0 : fb_env%obj%nlocal_atoms = 0
200 0 : END SUBROUTINE fb_env_init
201 :
202 : ! **********************************************************************
203 : !> \brief method to get attributes from a given fb_env object
204 : !> \brief ...
205 : !> \param fb_env : the fb_env object in question
206 : !> \param rcut : outputs pointer to rcut attribute of fb_env (optional)
207 : !> \param filter_temperature : outputs filter_temperature attribute
208 : !> of fb_env (optional)
209 : !> \param auto_cutoff_scale : outputs auto_cutoff_scale attribute
210 : !> of fb_env (optional)
211 : !> \param eps_default : outputs eps_default attribute
212 : !> of fb_env (optional)
213 : !> \param atomic_halos : outputs pointer to atomic_halos
214 : !> attribute of fb_env (optional)
215 : !> \param trial_fns : outputs pointer to trial_fns
216 : !> attribute of fb_env (optional, do not release it)
217 : !> \param collective_com : outputs pointer to trial_fns
218 : !> \param local_atoms : outputs pointer to local_atoms
219 : !> \param nlocal_atoms : outputs pointer to nlocal_atoms
220 : !> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
221 : ! **************************************************************************************************
222 280 : SUBROUTINE fb_env_get(fb_env, &
223 : rcut, &
224 : filter_temperature, &
225 : auto_cutoff_scale, &
226 : eps_default, &
227 : atomic_halos, &
228 : trial_fns, &
229 : collective_com, &
230 : local_atoms, &
231 : nlocal_atoms)
232 : TYPE(fb_env_obj), INTENT(IN) :: fb_env
233 : REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER :: rcut
234 : REAL(KIND=dp), INTENT(OUT), OPTIONAL :: filter_temperature, auto_cutoff_scale, &
235 : eps_default
236 : TYPE(fb_atomic_halo_list_obj), INTENT(OUT), &
237 : OPTIONAL :: atomic_halos
238 : TYPE(fb_trial_fns_obj), INTENT(OUT), OPTIONAL :: trial_fns
239 : LOGICAL, INTENT(OUT), OPTIONAL :: collective_com
240 : INTEGER, DIMENSION(:), OPTIONAL, POINTER :: local_atoms
241 : INTEGER, INTENT(OUT), OPTIONAL :: nlocal_atoms
242 :
243 280 : CPASSERT(ASSOCIATED(fb_env%obj))
244 280 : IF (PRESENT(rcut)) THEN
245 30 : rcut => fb_env%obj%rcut
246 : END IF
247 280 : IF (PRESENT(filter_temperature)) THEN
248 90 : filter_temperature = fb_env%obj%filter_temperature
249 : END IF
250 280 : IF (PRESENT(auto_cutoff_scale)) THEN
251 20 : auto_cutoff_scale = fb_env%obj%auto_cutoff_scale
252 : END IF
253 280 : IF (PRESENT(eps_default)) THEN
254 80 : eps_default = fb_env%obj%eps_default
255 : END IF
256 280 : IF (PRESENT(atomic_halos)) THEN
257 80 : CALL fb_atomic_halo_list_associate(atomic_halos, fb_env%obj%atomic_halos)
258 : END IF
259 280 : IF (PRESENT(trial_fns)) THEN
260 80 : trial_fns = fb_env%obj%trial_fns
261 : END IF
262 280 : IF (PRESENT(collective_com)) THEN
263 90 : collective_com = fb_env%obj%collective_com
264 : END IF
265 280 : IF (PRESENT(local_atoms)) THEN
266 10 : local_atoms => fb_env%obj%local_atoms
267 : END IF
268 280 : IF (PRESENT(nlocal_atoms)) THEN
269 10 : nlocal_atoms = fb_env%obj%nlocal_atoms
270 : END IF
271 280 : END SUBROUTINE fb_env_get
272 :
273 : ! **********************************************************************
274 : !> \brief method to set attributes from a given fb_env object
275 : !> \brief ...
276 : !> \param fb_env : the fb_env object in question
277 : !> \param rcut : sets rcut attribute of fb_env (optional)
278 : !> \param filter_temperature : sets filter_temperature attribute of fb_env (optional)
279 : !> \param auto_cutoff_scale : sets auto_cutoff_scale attribute of fb_env (optional)
280 : !> \param eps_default : sets eps_default attribute of fb_env (optional)
281 : !> \param atomic_halos : sets atomic_halos attribute of fb_env (optional)
282 : !> \param trial_fns : sets trial_fns attribute of fb_env (optional)
283 : !> \param collective_com : sets collective_com attribute of fb_env (optional)
284 : !> \param local_atoms : sets local_atoms attribute of fb_env (optional)
285 : !> \param nlocal_atoms : sets nlocal_atoms attribute of fb_env (optional)
286 : !> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
287 : ! **************************************************************************************************
288 150 : SUBROUTINE fb_env_set(fb_env, &
289 : rcut, &
290 : filter_temperature, &
291 : auto_cutoff_scale, &
292 : eps_default, &
293 : atomic_halos, &
294 : trial_fns, &
295 : collective_com, &
296 : local_atoms, &
297 : nlocal_atoms)
298 : TYPE(fb_env_obj), INTENT(INOUT) :: fb_env
299 : REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER :: rcut
300 : REAL(KIND=dp), INTENT(IN), OPTIONAL :: filter_temperature, auto_cutoff_scale, &
301 : eps_default
302 : TYPE(fb_atomic_halo_list_obj), INTENT(IN), &
303 : OPTIONAL :: atomic_halos
304 : TYPE(fb_trial_fns_obj), INTENT(IN), OPTIONAL :: trial_fns
305 : LOGICAL, INTENT(IN), OPTIONAL :: collective_com
306 : INTEGER, DIMENSION(:), OPTIONAL, POINTER :: local_atoms
307 : INTEGER, INTENT(IN), OPTIONAL :: nlocal_atoms
308 :
309 150 : CPASSERT(ASSOCIATED(fb_env%obj))
310 150 : IF (PRESENT(rcut)) THEN
311 10 : IF (ASSOCIATED(fb_env%obj%rcut)) THEN
312 0 : DEALLOCATE (fb_env%obj%rcut)
313 : END IF
314 10 : fb_env%obj%rcut => rcut
315 : END IF
316 150 : IF (PRESENT(filter_temperature)) THEN
317 10 : fb_env%obj%filter_temperature = filter_temperature
318 : END IF
319 150 : IF (PRESENT(auto_cutoff_scale)) THEN
320 10 : fb_env%obj%auto_cutoff_scale = auto_cutoff_scale
321 : END IF
322 150 : IF (PRESENT(eps_default)) THEN
323 10 : fb_env%obj%eps_default = eps_default
324 : END IF
325 150 : IF (PRESENT(atomic_halos)) THEN
326 10 : CALL fb_atomic_halo_list_release(fb_env%obj%atomic_halos)
327 10 : CALL fb_atomic_halo_list_associate(fb_env%obj%atomic_halos, atomic_halos)
328 : END IF
329 150 : IF (PRESENT(trial_fns)) THEN
330 80 : CALL fb_trial_fns_associate(fb_env%obj%trial_fns, trial_fns)
331 : END IF
332 150 : IF (PRESENT(collective_com)) THEN
333 10 : fb_env%obj%collective_com = collective_com
334 : END IF
335 150 : IF (PRESENT(local_atoms)) THEN
336 10 : IF (ASSOCIATED(fb_env%obj%local_atoms)) THEN
337 0 : DEALLOCATE (fb_env%obj%local_atoms)
338 : END IF
339 10 : fb_env%obj%local_atoms => local_atoms
340 : END IF
341 150 : IF (PRESENT(nlocal_atoms)) THEN
342 10 : fb_env%obj%nlocal_atoms = nlocal_atoms
343 : END IF
344 150 : END SUBROUTINE fb_env_set
345 :
346 0 : END MODULE qs_fb_env_types
|