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 The environment for the empirical interatomic potential methods.
10 : !> \par History
11 : !> 03.2006 initial create [tdk]
12 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
13 : ! **************************************************************************************************
14 : MODULE eip_environment_types
15 : USE atomic_kind_list_types, ONLY: atomic_kind_list_create,&
16 : atomic_kind_list_release,&
17 : atomic_kind_list_type
18 : USE atomic_kind_types, ONLY: atomic_kind_type
19 : USE cell_types, ONLY: cell_release,&
20 : cell_retain,&
21 : cell_type
22 : USE cp_subsys_types, ONLY: cp_subsys_get,&
23 : cp_subsys_release,&
24 : cp_subsys_set,&
25 : cp_subsys_type
26 : USE distribution_1d_types, ONLY: distribution_1d_type
27 : USE input_section_types, ONLY: section_vals_release,&
28 : section_vals_type
29 : USE kinds, ONLY: dp
30 : USE molecule_kind_list_types, ONLY: molecule_kind_list_create,&
31 : molecule_kind_list_release,&
32 : molecule_kind_list_type
33 : USE molecule_kind_types, ONLY: molecule_kind_type
34 : USE molecule_list_types, ONLY: molecule_list_create,&
35 : molecule_list_release,&
36 : molecule_list_type
37 : USE molecule_types, ONLY: molecule_type
38 : USE particle_list_types, ONLY: particle_list_create,&
39 : particle_list_release,&
40 : particle_list_type
41 : USE particle_types, ONLY: particle_type
42 : USE virial_types, ONLY: virial_type
43 : #include "./base/base_uses.f90"
44 :
45 : IMPLICIT NONE
46 : PRIVATE
47 :
48 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'eip_environment_types'
49 :
50 : ! *** Public data types ***
51 : PUBLIC :: eip_environment_type
52 :
53 : ! *** Public subroutines ***
54 : PUBLIC :: eip_env_release, &
55 : eip_env_set, &
56 : eip_env_get, &
57 : eip_env_create
58 :
59 : ! **************************************************************************************************
60 : !> \brief The empirical interatomic potential environment
61 : !> \param eip_model Specifies which EIP model is in use.
62 : !> \param eip_kinetic_energy The EIP kinetic energy
63 : !> \param eip_potential_energy The EIP potential energy
64 : !> \param eip_energy The total eip energy
65 : !> \param eip_energy_var Variance of the energy/atom
66 : !> \param eip_forces The final eip forces [eV/A]
67 : !> \param coord_avg The average coordination number
68 : !> \param coord_var The variance of the coordination number
69 : !> \param count Counts how often the empirical interatomic potential function
70 : !> is called. Don't ask why this is a real!
71 : !> \param subsystem the particles, molecules,... of this environment
72 : !> \param eip_input Pointer to the EIP input section
73 : !> \param force_env_input Pointer to the force_env input section
74 : !> \param cell The simulation cell
75 : !> \param cell_ref The reference simulation cell
76 : !> \param use_ref_cell Logical which indicates if reference
77 : !> simulation cell is used
78 : !> \param virial Dummy virial pointer
79 : !> \par History
80 : !> 03.2006 initial create [tdk]
81 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
82 : ! **************************************************************************************************
83 : TYPE eip_environment_type
84 : INTEGER :: eip_model = 0
85 : REAL(KIND=dp) :: eip_energy = 0.0_dp, &
86 : eip_kinetic_energy = 0.0_dp, &
87 : eip_potential_energy = 0.0_dp, &
88 : eip_energy_var = 0.0_dp
89 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: eip_forces => Null()
90 : REAL(KIND=dp) :: coord_avg = 0.0_dp, &
91 : coord_var = 0.0_dp, &
92 : count = 0.0_dp
93 : TYPE(cp_subsys_type), POINTER :: subsys => Null()
94 : TYPE(section_vals_type), POINTER :: eip_input => Null(), &
95 : force_env_input => Null()
96 : TYPE(cell_type), POINTER :: cell_ref => Null()
97 : LOGICAL :: use_ref_cell = .FALSE.
98 : END TYPE eip_environment_type
99 :
100 : CONTAINS
101 :
102 : ! **************************************************************************************************
103 : !> \brief Releases the given eip environment (see doc/ReferenceCounting.html)
104 : !> \param eip_env The eip environment to release
105 : !> \par History
106 : !> 03.2006 initial create [tdk]
107 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
108 : ! **************************************************************************************************
109 2 : SUBROUTINE eip_env_release(eip_env)
110 :
111 : TYPE(eip_environment_type), INTENT(INOUT) :: eip_env
112 :
113 2 : IF (ASSOCIATED(eip_env%eip_forces)) THEN
114 2 : DEALLOCATE (eip_env%eip_forces)
115 : END IF
116 2 : IF (ASSOCIATED(eip_env%subsys)) THEN
117 2 : CALL cp_subsys_release(eip_env%subsys)
118 : END IF
119 2 : IF (ASSOCIATED(eip_env%subsys)) THEN
120 0 : CALL cp_subsys_release(eip_env%subsys)
121 : END IF
122 : !IF (ASSOCIATED(eip_env%eip_input)) THEN
123 : ! CALL section_vals_release(eip_env%eip_input)
124 : !END IF
125 : !IF (ASSOCIATED(eip_env%force_env_input)) THEN
126 : ! CALL section_vals_release(eip_env%force_env_input)
127 : !END IF
128 2 : IF (ASSOCIATED(eip_env%cell_ref)) THEN
129 2 : CALL cell_release(eip_env%cell_ref)
130 : END IF
131 2 : END SUBROUTINE eip_env_release
132 :
133 : ! **************************************************************************************************
134 : !> \brief Returns various attributes of the eip environment
135 : !> \param eip_env The enquired eip environment
136 : !> \param eip_model Specifies which EIP model is in use.
137 : !> \param eip_energy The total eip energy
138 : !> \param eip_energy_var Variance of the energy/atom
139 : !> \param eip_forces The final eip forces [eV/A]
140 : !> \param coord_avg The average coordination number
141 : !> \param coord_var The variance of the coordination number
142 : !> \param count Counts how often the empirical interatomic potential function
143 : !> is called. Don't ask why this is a real!
144 : !> \param subsys the particles, molecules,... of this environment
145 : !> \param atomic_kind_set The set of all atomic kinds involved
146 : !> \param particle_set The set of all particles
147 : !> \param local_particles All particles on this particular node
148 : !> \param molecule_kind_set The set of all different molecule kinds involved
149 : !> \param molecule_set The set of all molecules
150 : !> \param local_molecules All molecules on this particular node
151 : !> \param eip_input the pointer to the EIP input section
152 : !> \param force_env_input Pointer to the force_env input section
153 : !> \param cell The simulation cell
154 : !> \param cell_ref The reference simulation cell
155 : !> \param use_ref_cell Logical which indicates if reference
156 : !> simulation cell is used
157 : !> \param eip_kinetic_energy The EIP kinetic energy
158 : !> \param eip_potential_energy The EIP potential energy
159 : !> \param virial Dummy virial pointer
160 : !>
161 : !> For possible missing arguments see the attributes of
162 : !> eip_environment_type
163 : !> \par History
164 : !> 03.2006 initial create [tdk]
165 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
166 : ! **************************************************************************************************
167 624 : SUBROUTINE eip_env_get(eip_env, eip_model, eip_energy, eip_energy_var, &
168 : eip_forces, coord_avg, coord_var, count, subsys, &
169 : atomic_kind_set, particle_set, local_particles, &
170 : molecule_kind_set, molecule_set, local_molecules, &
171 : eip_input, force_env_input, cell, cell_ref, &
172 : use_ref_cell, eip_kinetic_energy, eip_potential_energy, &
173 : virial)
174 :
175 : TYPE(eip_environment_type), INTENT(IN) :: eip_env
176 : INTEGER, INTENT(OUT), OPTIONAL :: eip_model
177 : REAL(KIND=dp), INTENT(OUT), OPTIONAL :: eip_energy, eip_energy_var
178 : REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER :: eip_forces
179 : REAL(KIND=dp), INTENT(OUT), OPTIONAL :: coord_avg, coord_var, count
180 : TYPE(cp_subsys_type), OPTIONAL, POINTER :: subsys
181 : TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
182 : POINTER :: atomic_kind_set
183 : TYPE(particle_type), DIMENSION(:), OPTIONAL, &
184 : POINTER :: particle_set
185 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles
186 : TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
187 : POINTER :: molecule_kind_set
188 : TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
189 : POINTER :: molecule_set
190 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_molecules
191 : TYPE(section_vals_type), OPTIONAL, POINTER :: eip_input, force_env_input
192 : TYPE(cell_type), OPTIONAL, POINTER :: cell, cell_ref
193 : LOGICAL, INTENT(OUT), OPTIONAL :: use_ref_cell
194 : REAL(KIND=dp), INTENT(OUT), OPTIONAL :: eip_kinetic_energy, eip_potential_energy
195 : TYPE(virial_type), OPTIONAL, POINTER :: virial
196 :
197 : TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
198 : TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
199 : TYPE(molecule_list_type), POINTER :: molecules
200 : TYPE(particle_list_type), POINTER :: particles
201 :
202 : ! ------------------------------------------------------------------------
203 :
204 624 : NULLIFY (atomic_kinds, particles, molecules, molecule_kinds)
205 :
206 624 : IF (PRESENT(eip_model)) eip_model = eip_env%eip_model
207 624 : IF (PRESENT(eip_kinetic_energy)) THEN
208 600 : eip_kinetic_energy = eip_env%eip_kinetic_energy
209 : END IF
210 624 : IF (PRESENT(eip_potential_energy)) THEN
211 600 : eip_potential_energy = eip_env%eip_potential_energy
212 : END IF
213 624 : IF (PRESENT(eip_energy)) eip_energy = eip_env%eip_energy
214 624 : IF (PRESENT(eip_energy_var)) eip_energy_var = eip_env%eip_energy_var
215 624 : IF (PRESENT(eip_forces)) eip_forces = eip_env%eip_forces
216 624 : IF (PRESENT(coord_avg)) coord_avg = eip_env%coord_avg
217 624 : IF (PRESENT(coord_var)) coord_var = eip_env%coord_var
218 624 : IF (PRESENT(count)) count = eip_env%count
219 624 : IF (PRESENT(subsys)) subsys => eip_env%subsys
220 : CALL cp_subsys_get(eip_env%subsys, &
221 : atomic_kinds=atomic_kinds, &
222 : particles=particles, &
223 : molecule_kinds=molecule_kinds, &
224 : molecules=molecules, &
225 : local_molecules=local_molecules, &
226 : local_particles=local_particles, &
227 : virial=virial, &
228 624 : cell=cell)
229 624 : IF (PRESENT(atomic_kind_set)) atomic_kind_set => atomic_kinds%els
230 624 : IF (PRESENT(particle_set)) particle_set => particles%els
231 624 : IF (PRESENT(molecule_kind_set)) molecule_kind_set => molecule_kinds%els
232 624 : IF (PRESENT(molecule_set)) molecule_set => molecules%els
233 :
234 624 : IF (PRESENT(eip_input)) eip_input => eip_env%eip_input
235 624 : IF (PRESENT(force_env_input)) force_env_input => eip_env%force_env_input
236 624 : IF (PRESENT(cell_ref)) cell_ref => eip_env%cell_ref
237 624 : IF (PRESENT(use_ref_cell)) use_ref_cell = eip_env%use_ref_cell
238 :
239 624 : END SUBROUTINE eip_env_get
240 :
241 : ! **************************************************************************************************
242 : !> \brief Sets various attributes of the eip environment
243 : !> \param eip_env The enquired eip environment
244 : !> \param eip_model Specifies which EIP model is in use
245 : !> \param eip_energy The total eip energy
246 : !> \param eip_energy_var Variance of the energy/atom
247 : !> \param eip_forces The final eip forces [eV/A]
248 : !> \param coord_avg The average coordination number
249 : !> \param coord_var The variance of the coordination number
250 : !> \param count Counts how often the empirical interatomic potential function
251 : !> is called. Don't ask why this is a real!
252 : !> \param subsys the particles, molecules,... of this environment
253 : !> \param atomic_kind_set The set of all atomic kinds involved
254 : !> \param particle_set The set of all particles
255 : !> \param local_particles All particles on this particular node
256 : !> \param molecule_kind_set The set of all different molecule kinds involved
257 : !> \param molecule_set The set of all molecules
258 : !> \param local_molecules All molecules on this particular node
259 : !> \param eip_input the pointer to the EIP input section
260 : !> \param force_env_input Pointer to the force_env input section
261 : !> \param cell_ref The reference simulation cell
262 : !> \param use_ref_cell Logical which indicates if reference
263 : !> simulation cell is used
264 : !> \param eip_kinetic_energy The EIP kinetic energy
265 : !> \param eip_potential_energy The EIP potential energy
266 : !> \par History
267 : !> 03.2006 initial create [tdk]
268 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
269 : !> \note
270 : !> For possible missing arguments see the attributes of eip_environment_type
271 : ! **************************************************************************************************
272 4 : SUBROUTINE eip_env_set(eip_env, eip_model, eip_energy, eip_energy_var, &
273 : eip_forces, coord_avg, coord_var, count, subsys, &
274 : atomic_kind_set, particle_set, local_particles, &
275 : molecule_kind_set, molecule_set, local_molecules, &
276 : eip_input, force_env_input, cell_ref, &
277 : use_ref_cell, eip_kinetic_energy, eip_potential_energy)
278 :
279 : TYPE(eip_environment_type), INTENT(INOUT) :: eip_env
280 : INTEGER, INTENT(IN), OPTIONAL :: eip_model
281 : REAL(KIND=dp), INTENT(IN), OPTIONAL :: eip_energy, eip_energy_var
282 : REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER :: eip_forces
283 : REAL(KIND=dp), INTENT(IN), OPTIONAL :: coord_avg, coord_var, count
284 : TYPE(cp_subsys_type), OPTIONAL, POINTER :: subsys
285 : TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
286 : POINTER :: atomic_kind_set
287 : TYPE(particle_type), DIMENSION(:), OPTIONAL, &
288 : POINTER :: particle_set
289 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles
290 : TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
291 : POINTER :: molecule_kind_set
292 : TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
293 : POINTER :: molecule_set
294 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_molecules
295 : TYPE(section_vals_type), OPTIONAL, POINTER :: eip_input, force_env_input
296 : TYPE(cell_type), OPTIONAL, POINTER :: cell_ref
297 : LOGICAL, INTENT(IN), OPTIONAL :: use_ref_cell
298 : REAL(KIND=dp), INTENT(IN), OPTIONAL :: eip_kinetic_energy, eip_potential_energy
299 :
300 : TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
301 : TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
302 : TYPE(molecule_list_type), POINTER :: molecules
303 : TYPE(particle_list_type), POINTER :: particles
304 :
305 4 : IF (PRESENT(eip_model)) eip_env%eip_model = eip_model
306 4 : IF (PRESENT(eip_kinetic_energy)) THEN
307 0 : eip_env%eip_kinetic_energy = eip_kinetic_energy
308 : END IF
309 4 : IF (PRESENT(eip_potential_energy)) THEN
310 0 : eip_env%eip_potential_energy = eip_potential_energy
311 : END IF
312 4 : IF (PRESENT(eip_energy)) eip_env%eip_energy = eip_energy
313 4 : IF (PRESENT(eip_energy_var)) eip_env%eip_energy_var = eip_energy_var
314 4 : IF (PRESENT(eip_forces)) eip_env%eip_forces = eip_forces
315 4 : IF (PRESENT(coord_avg)) eip_env%coord_avg = coord_avg
316 4 : IF (PRESENT(coord_var)) eip_env%coord_var = coord_var
317 4 : IF (PRESENT(count)) eip_env%count = count
318 4 : IF (PRESENT(subsys)) THEN
319 2 : IF (ASSOCIATED(eip_env%subsys)) THEN
320 0 : IF (.NOT. ASSOCIATED(eip_env%subsys, subsys)) THEN
321 0 : CALL cp_subsys_release(eip_env%subsys)
322 : END IF
323 : END IF
324 2 : eip_env%subsys => subsys
325 : END IF
326 4 : IF (PRESENT(atomic_kind_set)) THEN
327 0 : CALL atomic_kind_list_create(atomic_kinds, els_ptr=atomic_kind_set)
328 0 : CALL cp_subsys_set(eip_env%subsys, atomic_kinds=atomic_kinds)
329 0 : CALL atomic_kind_list_release(atomic_kinds)
330 : END IF
331 4 : IF (PRESENT(particle_set)) THEN
332 0 : CALL particle_list_create(particles, els_ptr=particle_set)
333 0 : CALL cp_subsys_set(eip_env%subsys, particles=particles)
334 0 : CALL particle_list_release(particles)
335 : END IF
336 4 : IF (PRESENT(molecule_kind_set)) THEN
337 0 : CALL molecule_kind_list_create(molecule_kinds, els_ptr=molecule_kind_set)
338 0 : CALL cp_subsys_set(eip_env%subsys, molecule_kinds=molecule_kinds)
339 0 : CALL molecule_kind_list_release(molecule_kinds)
340 : END IF
341 4 : IF (PRESENT(molecule_set)) THEN
342 0 : CALL molecule_list_create(molecules, els_ptr=molecule_set)
343 0 : CALL cp_subsys_set(eip_env%subsys, molecules=molecules)
344 0 : CALL molecule_list_release(molecules)
345 : END IF
346 4 : IF (PRESENT(local_particles)) THEN
347 2 : CALL cp_subsys_set(eip_env%subsys, local_particles=local_particles)
348 : END IF
349 4 : IF (PRESENT(local_molecules)) THEN
350 2 : CALL cp_subsys_set(eip_env%subsys, local_molecules=local_molecules)
351 : END IF
352 :
353 4 : IF (PRESENT(eip_input)) eip_env%eip_input => eip_input
354 4 : IF (PRESENT(force_env_input)) THEN
355 2 : eip_env%force_env_input => force_env_input
356 : END IF
357 4 : IF (PRESENT(cell_ref)) THEN
358 2 : CALL cell_retain(cell_ref)
359 2 : CALL cell_release(eip_env%cell_ref)
360 2 : eip_env%cell_ref => cell_ref
361 : END IF
362 4 : IF (PRESENT(use_ref_cell)) eip_env%use_ref_cell = use_ref_cell
363 4 : END SUBROUTINE eip_env_set
364 :
365 : ! **************************************************************************************************
366 : !> \brief Reinitializes the eip environment
367 : !> \param eip_env The eip environment to be reinitialized
368 : !> \par History
369 : !> 03.2006 initial create [tdk]
370 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
371 : ! **************************************************************************************************
372 2 : SUBROUTINE eip_env_clear(eip_env)
373 :
374 : TYPE(eip_environment_type), INTENT(INOUT) :: eip_env
375 :
376 2 : eip_env%eip_model = 0
377 2 : eip_env%eip_kinetic_energy = 0.0_dp
378 2 : eip_env%eip_potential_energy = 0.0_dp
379 2 : eip_env%eip_energy = 0.0_dp
380 2 : eip_env%eip_energy_var = 0.0_dp
381 2 : eip_env%coord_avg = 0.0_dp
382 2 : eip_env%coord_var = 0.0_dp
383 2 : eip_env%count = 0.0_dp
384 2 : IF (ASSOCIATED(eip_env%eip_forces)) THEN
385 0 : eip_env%eip_forces(:, :) = 0.0_dp
386 : END IF
387 2 : IF (ASSOCIATED(eip_env%subsys)) THEN
388 0 : CALL cp_subsys_release(eip_env%subsys)
389 : END IF
390 2 : IF (ASSOCIATED(eip_env%eip_input)) THEN
391 0 : CALL section_vals_release(eip_env%eip_input)
392 : END IF
393 2 : IF (ASSOCIATED(eip_env%force_env_input)) THEN
394 0 : CALL section_vals_release(eip_env%force_env_input)
395 : END IF
396 2 : IF (ASSOCIATED(eip_env%cell_ref)) THEN
397 0 : CALL cell_release(eip_env%cell_ref)
398 : END IF
399 2 : END SUBROUTINE eip_env_clear
400 :
401 : ! **************************************************************************************************
402 : !> \brief Creates the eip environment
403 : !> \param eip_env The eip environment to be created
404 : !> \par History
405 : !> 03.2006 initial create [tdk]
406 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
407 : ! **************************************************************************************************
408 2 : SUBROUTINE eip_env_create(eip_env)
409 :
410 : TYPE(eip_environment_type), INTENT(OUT) :: eip_env
411 :
412 : NULLIFY (eip_env%eip_forces)
413 : NULLIFY (eip_env%subsys)
414 : NULLIFY (eip_env%eip_input)
415 : NULLIFY (eip_env%force_env_input)
416 : NULLIFY (eip_env%cell_ref)
417 :
418 : eip_env%use_ref_cell = .FALSE.
419 2 : CALL eip_env_clear(eip_env)
420 2 : END SUBROUTINE eip_env_create
421 :
422 0 : END MODULE eip_environment_types
|