(git:ed6f26b)
Loading...
Searching...
No Matches
pwdft_environment_types.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief The type definitions for the PWDFT environment
10!> \par History
11!> 07.2018 initial create
12!> \author JHU
13! **************************************************************************************************
15 USE iso_c_binding, ONLY: c_null_ptr, &
16 c_ptr
20 USE kinds, ONLY: dp
21 USE qs_subsys_types, ONLY: qs_subsys_get, &
25
26#if defined(__SIRIUS)
27 USE sirius, ONLY: sirius_free_handler, &
28 sirius_context_handler, &
29 sirius_ground_state_handler, &
30 sirius_kpoint_set_handler
31#endif
32
33#include "./base/base_uses.f90"
34
35 IMPLICIT NONE
36 PRIVATE
37
38 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pwdft_environment_types'
39
40 ! *** Public data types ***
42
43 ! *** Public subroutines ***
44 PUBLIC :: pwdft_env_release, &
48
49! **************************************************************************************************
50!> \brief The PWDFT energy type
51!> \par History
52!> 07.2018 initial create
53!> \author JHU
54! **************************************************************************************************
56 REAL(kind=dp) :: etotal = 0.0_dp
57 REAL(kind=dp) :: entropy = 0.0_dp
58 REAL(kind=dp) :: band_gap = -1.0_dp
59 END TYPE pwdft_energy_type
60
61! **************************************************************************************************
62!> \brief The PWDFT environment type
63!> \par History
64!> 07.2018 initial create
65!> \author JHU
66! **************************************************************************************************
68 TYPE(mp_para_env_type), POINTER :: para_env => null()
69 TYPE(qs_subsys_type), POINTER :: qs_subsys => null()
70 TYPE(section_vals_type), POINTER :: pwdft_input => null()
71 TYPE(section_vals_type), POINTER :: force_env_input => null()
72 TYPE(section_vals_type), POINTER :: xc_input => null()
73 TYPE(pwdft_energy_type), POINTER :: energy => null()
74 REAL(kind=dp), DIMENSION(:, :), POINTER :: forces => null()
75 REAL(kind=dp), DIMENSION(3, 3) :: stress = 0.0_dp
76 LOGICAL :: ignore_convergence_failure = .false.
77! 16 different functionals should be enough
78 CHARACTER(len=80), DIMENSION(16) :: xc_func = ""
79#if defined(__SIRIUS)
80 TYPE(sirius_context_handler) :: sctx
81 TYPE(sirius_ground_state_handler) :: gs_handler
82 TYPE(sirius_kpoint_set_handler) :: ks_handler
83#else
84 TYPE(c_ptr) :: sctx = c_null_ptr
85 TYPE(c_ptr) :: gs_handler = c_null_ptr
86 TYPE(c_ptr) :: ks_handler = c_null_ptr
87#endif
88
90
91CONTAINS
92
93! **************************************************************************************************
94!> \brief Releases the given pwdft environment
95!> \param pwdft_env The pwdft environment to release
96!> \par History
97!> 07.2018 initial create
98!> \author JHU
99! **************************************************************************************************
100 SUBROUTINE pwdft_env_release(pwdft_env)
101
102 TYPE(pwdft_environment_type), INTENT(INOUT) :: pwdft_env
103
104#if defined(__SIRIUS)
105
106 CALL sirius_free_handler(pwdft_env%gs_handler)
107 CALL sirius_free_handler(pwdft_env%ks_handler)
108 CALL sirius_free_handler(pwdft_env%sctx)
109
110 IF (ASSOCIATED(pwdft_env%qs_subsys)) THEN
111 CALL qs_subsys_release(pwdft_env%qs_subsys)
112 DEALLOCATE (pwdft_env%qs_subsys)
113 END IF
114 IF (ASSOCIATED(pwdft_env%energy)) THEN
115 DEALLOCATE (pwdft_env%energy)
116 END IF
117 IF (ASSOCIATED(pwdft_env%forces)) THEN
118 DEALLOCATE (pwdft_env%forces)
119 END IF
120#else
121 mark_used(pwdft_env)
122#endif
123 END SUBROUTINE pwdft_env_release
124
125! **************************************************************************************************
126!> \brief Returns various attributes of the pwdft environment
127!> \param pwdft_env The enquired pwdft environment
128!> \param pwdft_input ...
129!> \param force_env_input ...
130!> \param xc_input ...
131!> \param cp_subsys ...
132!> \param qs_subsys ...
133!> \param para_env ...
134!> \param energy ...
135!> \param forces ...
136!> \param stress ...
137!> \param sctx ...
138!> \param gs_handler ...
139!> \param ks_handler ...
140!> \par History
141!> 07.2018 initial create
142!> \author JHU
143! **************************************************************************************************
144 SUBROUTINE pwdft_env_get(pwdft_env, pwdft_input, force_env_input, xc_input, &
145 cp_subsys, qs_subsys, para_env, energy, forces, stress, &
146 sctx, gs_handler, ks_handler)
147
148 TYPE(pwdft_environment_type), INTENT(IN) :: pwdft_env
149 TYPE(section_vals_type), OPTIONAL, POINTER :: pwdft_input, force_env_input, xc_input
150 TYPE(cp_subsys_type), OPTIONAL, POINTER :: cp_subsys
151 TYPE(qs_subsys_type), OPTIONAL, POINTER :: qs_subsys
152 TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
153 TYPE(pwdft_energy_type), OPTIONAL, POINTER :: energy
154 REAL(kind=dp), DIMENSION(:, :), OPTIONAL, POINTER :: forces
155 REAL(kind=dp), DIMENSION(3, 3), OPTIONAL :: stress
156#if defined(__SIRIUS)
157 TYPE(sirius_context_handler), OPTIONAL :: sctx
158 TYPE(sirius_ground_state_handler), OPTIONAL :: gs_handler
159 TYPE(sirius_kpoint_set_handler), OPTIONAL :: ks_handler
160#else
161 !work around because the contexts are typed.
162 TYPE(c_ptr), OPTIONAL :: sctx
163 TYPE(c_ptr), OPTIONAL :: gs_handler
164 TYPE(c_ptr), OPTIONAL :: ks_handler
165#endif
166
167 IF (PRESENT(pwdft_input)) pwdft_input => pwdft_env%pwdft_input
168 IF (PRESENT(force_env_input)) force_env_input => pwdft_env%force_env_input
169 IF (PRESENT(xc_input)) xc_input => pwdft_env%xc_input
170 IF (PRESENT(qs_subsys)) qs_subsys => pwdft_env%qs_subsys
171 IF (PRESENT(cp_subsys)) THEN
172 CALL qs_subsys_get(pwdft_env%qs_subsys, cp_subsys=cp_subsys)
173 END IF
174 IF (PRESENT(para_env)) para_env => pwdft_env%para_env
175 IF (PRESENT(energy)) energy => pwdft_env%energy
176 IF (PRESENT(forces)) forces => pwdft_env%forces
177 IF (PRESENT(stress)) stress(1:3, 1:3) = pwdft_env%stress(1:3, 1:3)
178 ! it will never be allocated if SIRIUS is not included during compilation
179 IF (PRESENT(sctx)) sctx = pwdft_env%sctx
180 IF (PRESENT(gs_handler)) gs_handler = pwdft_env%gs_handler
181 IF (PRESENT(ks_handler)) ks_handler = pwdft_env%ks_handler
182 END SUBROUTINE pwdft_env_get
183
184! **************************************************************************************************
185!> \brief Sets various attributes of the pwdft environment
186!> \param pwdft_env The enquired pwdft environment
187!> \param pwdft_input ...
188!> \param force_env_input ...
189!> \param xc_input ...
190!> \param qs_subsys ...
191!> \param cp_subsys ...
192!> \param para_env ...
193!> \param energy ...
194!> \param forces ...
195!> \param stress ...
196!> \param sctx ...
197!> \param gs_handler ...
198!> \param ks_handler ...
199!> \par History
200!> 07.2018 initial create
201!> \author JHU
202!> \note
203!> For possible missing arguments see the attributes of pwdft_environment_type
204! **************************************************************************************************
205 SUBROUTINE pwdft_env_set(pwdft_env, pwdft_input, force_env_input, xc_input, &
206 qs_subsys, cp_subsys, para_env, energy, forces, stress, &
207 sctx, gs_handler, ks_handler)
208
209 TYPE(pwdft_environment_type), INTENT(INOUT) :: pwdft_env
210 TYPE(section_vals_type), OPTIONAL, POINTER :: pwdft_input, force_env_input, xc_input
211 TYPE(qs_subsys_type), OPTIONAL, POINTER :: qs_subsys
212 TYPE(cp_subsys_type), OPTIONAL, POINTER :: cp_subsys
213 TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
214 TYPE(pwdft_energy_type), OPTIONAL, POINTER :: energy
215 REAL(kind=dp), DIMENSION(:, :), OPTIONAL, POINTER :: forces
216 REAL(kind=dp), DIMENSION(3, 3), OPTIONAL :: stress
217#if defined(__SIRIUS)
218 TYPE(sirius_context_handler), OPTIONAL :: sctx
219 TYPE(sirius_ground_state_handler), OPTIONAL :: gs_handler
220 TYPE(sirius_kpoint_set_handler), OPTIONAL :: ks_handler
221#else
222!work around because the contexts are typed.
223 TYPE(c_ptr), OPTIONAL :: sctx
224 TYPE(c_ptr), OPTIONAL :: gs_handler
225 TYPE(c_ptr), OPTIONAL :: ks_handler
226#endif
227
228 IF (PRESENT(para_env)) pwdft_env%para_env => para_env
229 IF (PRESENT(pwdft_input)) pwdft_env%pwdft_input => pwdft_input
230 IF (PRESENT(force_env_input)) pwdft_env%force_env_input => force_env_input
231 IF (PRESENT(xc_input)) pwdft_env%xc_input => xc_input
232
233 IF (PRESENT(qs_subsys)) THEN
234 IF (ASSOCIATED(pwdft_env%qs_subsys)) THEN
235 IF (.NOT. ASSOCIATED(pwdft_env%qs_subsys, qs_subsys)) THEN
236 CALL qs_subsys_release(pwdft_env%qs_subsys)
237 DEALLOCATE (pwdft_env%qs_subsys)
238 END IF
239 END IF
240 pwdft_env%qs_subsys => qs_subsys
241 END IF
242 IF (PRESENT(cp_subsys)) THEN
243 CALL qs_subsys_set(pwdft_env%qs_subsys, cp_subsys=cp_subsys)
244 END IF
245
246 IF (PRESENT(energy)) pwdft_env%energy => energy
247 IF (PRESENT(forces)) pwdft_env%forces => forces
248 IF (PRESENT(stress)) pwdft_env%stress(1:3, 1:3) = stress(1:3, 1:3)
249 IF (PRESENT(sctx)) pwdft_env%sctx = sctx
250 IF (PRESENT(gs_handler)) pwdft_env%gs_handler = gs_handler
251 IF (PRESENT(ks_handler)) pwdft_env%ks_handler = ks_handler
252 END SUBROUTINE pwdft_env_set
253
254! **************************************************************************************************
255!> \brief Reinitializes the pwdft environment
256!> \param pwdft_env The pwdft environment to be reinitialized
257!> \par History
258!> 07.2018 initial create
259!> \author JHU
260! **************************************************************************************************
261 SUBROUTINE pwdft_env_clear(pwdft_env)
262
263 TYPE(pwdft_environment_type), INTENT(INOUT) :: pwdft_env
264
265! ------------------------------------------------------------------------
266
267 NULLIFY (pwdft_env%para_env)
268 NULLIFY (pwdft_env%pwdft_input)
269 NULLIFY (pwdft_env%force_env_input)
270 IF (ASSOCIATED(pwdft_env%qs_subsys)) THEN
271 CALL qs_subsys_release(pwdft_env%qs_subsys)
272 DEALLOCATE (pwdft_env%qs_subsys)
273 END IF
274 IF (ASSOCIATED(pwdft_env%energy)) THEN
275 DEALLOCATE (pwdft_env%energy)
276 END IF
277 IF (ASSOCIATED(pwdft_env%forces)) THEN
278 DEALLOCATE (pwdft_env%forces)
279 NULLIFY (pwdft_env%forces)
280 END IF
281 pwdft_env%stress = 0.0_dp
282
283 END SUBROUTINE pwdft_env_clear
284
285! **************************************************************************************************
286!> \brief Creates the pwdft environment
287!> \param pwdft_env The pwdft environment to be created
288!> \par History
289!> 07.2018 initial create
290!> \author JHU
291! **************************************************************************************************
292 SUBROUTINE pwdft_env_create(pwdft_env)
293
294 TYPE(pwdft_environment_type), INTENT(OUT) :: pwdft_env
295
296 CALL pwdft_env_clear(pwdft_env)
297
298 END SUBROUTINE pwdft_env_create
299
types that represent a subsys, i.e. a part of the system
objects that represent the structure of input sections and the data contained in an input section
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
The type definitions for the PWDFT environment.
subroutine, public pwdft_env_get(pwdft_env, pwdft_input, force_env_input, xc_input, cp_subsys, qs_subsys, para_env, energy, forces, stress, sctx, gs_handler, ks_handler)
Returns various attributes of the pwdft environment.
subroutine, public pwdft_env_create(pwdft_env)
Creates the pwdft environment.
subroutine, public pwdft_env_set(pwdft_env, pwdft_input, force_env_input, xc_input, qs_subsys, cp_subsys, para_env, energy, forces, stress, sctx, gs_handler, ks_handler)
Sets various attributes of the pwdft environment.
subroutine, public pwdft_env_release(pwdft_env)
Releases the given pwdft environment.
types that represent a quickstep subsys
subroutine, public qs_subsys_release(subsys)
releases a subsys (see doc/ReferenceCounting.html)
subroutine, public qs_subsys_get(subsys, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...
subroutine, public qs_subsys_set(subsys, cp_subsys, local_particles, local_molecules, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, nelectron_total, nelectron_spin)
...
represents a system: atoms, molecules, their pos,vel,...
stores all the informations relevant to an mpi environment