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