(git:bb35279)
Loading...
Searching...
No Matches
xc_rho_set_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 contains the structure
10!> \par History
11!> 11.2003 created [fawzi]
12!> \author fawzi
13! **************************************************************************************************
16 USE kinds, ONLY: dp
18 USE pw_methods, ONLY: pw_copy, &
20 USE pw_pool_types, ONLY: &
23 USE pw_types, ONLY: &
33 USE xc_util, ONLY: xc_pw_gradient, &
36#include "../base/base_uses.f90"
37
38 IMPLICIT NONE
39 PRIVATE
40 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .false.
41 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xc_rho_set_types'
42
43 PUBLIC :: xc_rho_set_type
46
47! **************************************************************************************************
48!> \brief represent a density, with all the representation and data needed
49!> to perform a functional evaluation
50!> \param local_bounds the part of the 3d array on which the functional is
51!> computed
52!> \param owns which components are owned by this structure (and should
53!> be deallocated
54!> \param has which components are present and up to date
55!> \param rho the density
56!> \param drho the gradient of the density (x,y and z direction)
57!> \param norm_drho the norm of the gradient of the density
58!> \param rhoa , rhob: spin alpha and beta parts of the density in the LSD case
59!> \param drhoa , drhob: gradient of the spin alpha and beta parts of the density
60!> in the LSD case (x,y and z direction)
61!> \param norm_drhoa , norm_drhob: norm of the gradient of rhoa and rhob
62!> \param rho_ 1_3: rho^(1.0_dp/3.0_dp)
63!> \param rhoa_ 1_3, rhob_1_3: rhoa^(1.0_dp/3.0_dp), rhob^(1.0_dp/3.0_dp)
64!> \param tau the kinetic (KohnSham) part of rho
65!> \param tau_a the kinetic (KohnSham) part of rhoa
66!> \param tau_b the kinetic (KohnSham) part of rhob
67!> \note
68!> the use of 3d arrays is the result of trying to use only basic
69!> types (to be generic and independent from the method), and
70!> avoiding copies using the actual structure.
71!> only the part defined by local bounds is guaranteed to be present,
72!> and it is the only meaningful part.
73!> \par History
74!> 11.2003 created [fawzi & thomas]
75!> 12.2008 added laplace parts [mguidon]
76!> \author fawzi & thomas
77! **************************************************************************************************
79 INTEGER, DIMENSION(2, 3) :: local_bounds = -1
80 REAL(kind=dp) :: rho_cutoff = epsilon(0.0_dp), drho_cutoff = epsilon(0.0_dp), tau_cutoff = epsilon(0.0_dp)
82 ! for spin restricted systems
83 REAL(kind=dp), DIMENSION(:, :, :), CONTIGUOUS, POINTER :: rho => null()
84 TYPE(cp_3d_r_cp_type), DIMENSION(3) :: drho = cp_3d_r_cp_type()
85 REAL(kind=dp), DIMENSION(:, :, :), CONTIGUOUS, POINTER :: norm_drho => null()
86 REAL(kind=dp), DIMENSION(:, :, :), CONTIGUOUS, POINTER :: rho_1_3 => null()
87 REAL(kind=dp), DIMENSION(:, :, :), CONTIGUOUS, POINTER :: tau => null()
88 ! for UNrestricted systems
89 REAL(kind=dp), DIMENSION(:, :, :), CONTIGUOUS, POINTER :: rhoa => null(), rhob => null()
90 TYPE(cp_3d_r_cp_type), DIMENSION(3) :: drhoa = cp_3d_r_cp_type(), &
91 drhob = cp_3d_r_cp_type()
92 REAL(kind=dp), DIMENSION(:, :, :), CONTIGUOUS, POINTER :: norm_drhoa => null(), norm_drhob => null()
93 REAL(kind=dp), DIMENSION(:, :, :), CONTIGUOUS, POINTER :: rhoa_1_3 => null(), rhob_1_3 => null()
94 REAL(kind=dp), DIMENSION(:, :, :), CONTIGUOUS, POINTER :: tau_a => null(), tau_b => null()
95 REAL(kind=dp), DIMENSION(:, :, :), CONTIGUOUS, POINTER :: laplace_rho => null(), laplace_rhoa => null(), &
96 laplace_rhob => null()
97 END TYPE xc_rho_set_type
98
99CONTAINS
100
101! **************************************************************************************************
102!> \brief allocates and does (minimal) initialization of a rho_set
103!> \param rho_set the structure to allocate
104!> \param local_bounds ...
105!> \param rho_cutoff ...
106!> \param drho_cutoff ...
107!> \param tau_cutoff ...
108! **************************************************************************************************
109 SUBROUTINE xc_rho_set_create(rho_set, local_bounds, rho_cutoff, drho_cutoff, &
110 tau_cutoff)
111 TYPE(xc_rho_set_type), INTENT(INOUT) :: rho_set
112 INTEGER, DIMENSION(2, 3), INTENT(in) :: local_bounds
113 REAL(kind=dp), INTENT(in), OPTIONAL :: rho_cutoff, drho_cutoff, tau_cutoff
114
115 IF (PRESENT(rho_cutoff)) rho_set%rho_cutoff = rho_cutoff
116 IF (PRESENT(drho_cutoff)) rho_set%drho_cutoff = drho_cutoff
117 IF (PRESENT(tau_cutoff)) rho_set%tau_cutoff = tau_cutoff
118 rho_set%local_bounds = local_bounds
119 CALL xc_rho_cflags_setall(rho_set%owns, .true.)
120 CALL xc_rho_cflags_setall(rho_set%has, .false.)
121 END SUBROUTINE xc_rho_set_create
122
123! **************************************************************************************************
124!> \brief releases the given rho_set
125!> \param rho_set the structure to release
126!> \param pw_pool the plae where to give back the arrays
127! **************************************************************************************************
128 SUBROUTINE xc_rho_set_release(rho_set, pw_pool)
129 TYPE(xc_rho_set_type), INTENT(INOUT) :: rho_set
130 TYPE(pw_pool_type), OPTIONAL, POINTER :: pw_pool
131
132 INTEGER :: i
133
134 IF (PRESENT(pw_pool)) THEN
135 IF (ASSOCIATED(pw_pool)) THEN
136 CALL xc_rho_set_clean(rho_set, pw_pool)
137 ELSE
138 cpabort("pw_pool must be associated")
139 END IF
140 END IF
141
142 rho_set%local_bounds(1, :) = -huge(0) ! we want to crash...
143 rho_set%local_bounds(1, :) = huge(0)
144 IF (rho_set%owns%rho .AND. ASSOCIATED(rho_set%rho)) THEN
145 DEALLOCATE (rho_set%rho)
146 ELSE
147 NULLIFY (rho_set%rho)
148 END IF
149 IF (rho_set%owns%rho_spin) THEN
150 IF (ASSOCIATED(rho_set%rhoa)) THEN
151 DEALLOCATE (rho_set%rhoa)
152 END IF
153 IF (ASSOCIATED(rho_set%rhob)) THEN
154 DEALLOCATE (rho_set%rhob)
155 END IF
156 ELSE
157 NULLIFY (rho_set%rhoa, rho_set%rhob)
158 END IF
159 IF (rho_set%owns%rho_1_3 .AND. ASSOCIATED(rho_set%rho_1_3)) THEN
160 DEALLOCATE (rho_set%rho_1_3)
161 ELSE
162 NULLIFY (rho_set%rho_1_3)
163 END IF
164 IF (rho_set%owns%rho_spin) THEN
165 IF (ASSOCIATED(rho_set%rhoa_1_3)) THEN
166 DEALLOCATE (rho_set%rhoa_1_3)
167 END IF
168 IF (ASSOCIATED(rho_set%rhob_1_3)) THEN
169 DEALLOCATE (rho_set%rhob_1_3)
170 END IF
171 ELSE
172 NULLIFY (rho_set%rhoa_1_3, rho_set%rhob_1_3)
173 END IF
174 IF (rho_set%owns%drho) THEN
175 DO i = 1, 3
176 IF (ASSOCIATED(rho_set%drho(i)%array)) THEN
177 DEALLOCATE (rho_set%drho(i)%array)
178 END IF
179 END DO
180 ELSE
181 DO i = 1, 3
182 NULLIFY (rho_set%drho(i)%array)
183 END DO
184 END IF
185 IF (rho_set%owns%drho_spin) THEN
186 DO i = 1, 3
187 IF (ASSOCIATED(rho_set%drhoa(i)%array)) THEN
188 DEALLOCATE (rho_set%drhoa(i)%array)
189 END IF
190 IF (ASSOCIATED(rho_set%drhob(i)%array)) THEN
191 DEALLOCATE (rho_set%drhob(i)%array)
192 END IF
193 END DO
194 ELSE
195 DO i = 1, 3
196 NULLIFY (rho_set%drhoa(i)%array, rho_set%drhob(i)%array)
197 END DO
198 END IF
199 IF (rho_set%owns%laplace_rho .AND. ASSOCIATED(rho_set%laplace_rho)) THEN
200 DEALLOCATE (rho_set%laplace_rho)
201 ELSE
202 NULLIFY (rho_set%laplace_rho)
203 END IF
204
205 IF (rho_set%owns%norm_drho .AND. ASSOCIATED(rho_set%norm_drho)) THEN
206 DEALLOCATE (rho_set%norm_drho)
207 ELSE
208 NULLIFY (rho_set%norm_drho)
209 END IF
210 IF (rho_set%owns%laplace_rho_spin) THEN
211 IF (ASSOCIATED(rho_set%laplace_rhoa)) THEN
212 DEALLOCATE (rho_set%laplace_rhoa)
213 END IF
214 IF (ASSOCIATED(rho_set%laplace_rhob)) THEN
215 DEALLOCATE (rho_set%laplace_rhob)
216 END IF
217 ELSE
218 NULLIFY (rho_set%laplace_rhoa, rho_set%laplace_rhob)
219 END IF
220
221 IF (rho_set%owns%norm_drho_spin) THEN
222 IF (ASSOCIATED(rho_set%norm_drhoa)) THEN
223 DEALLOCATE (rho_set%norm_drhoa)
224 END IF
225 IF (ASSOCIATED(rho_set%norm_drhob)) THEN
226 DEALLOCATE (rho_set%norm_drhob)
227 END IF
228 ELSE
229 NULLIFY (rho_set%norm_drhoa, rho_set%norm_drhob)
230 END IF
231 IF (rho_set%owns%tau .AND. ASSOCIATED(rho_set%tau)) THEN
232 DEALLOCATE (rho_set%tau)
233 ELSE
234 NULLIFY (rho_set%tau)
235 END IF
236 IF (rho_set%owns%tau_spin) THEN
237 IF (ASSOCIATED(rho_set%tau_a)) THEN
238 DEALLOCATE (rho_set%tau_a)
239 END IF
240 IF (ASSOCIATED(rho_set%tau_b)) THEN
241 DEALLOCATE (rho_set%tau_b)
242 END IF
243 ELSE
244 NULLIFY (rho_set%tau_a, rho_set%tau_b)
245 END IF
246 END SUBROUTINE xc_rho_set_release
247
248! **************************************************************************************************
249!> \brief returns the various attributes of rho_set
250!> \param rho_set the object you want info about
251!> \param can_return_null if true the object returned can be null,
252!> if false (the default) it stops with an error if a requested
253!> component is not associated
254!> \param rho ...
255!> \param drho ...
256!> \param norm_drho ...
257!> \param rhoa ...
258!> \param rhob ...
259!> \param norm_drhoa ...
260!> \param norm_drhob ...
261!> \param rho_1_3 ...
262!> \param rhoa_1_3 ...
263!> \param rhob_1_3 ...
264!> \param laplace_rho ...
265!> \param laplace_rhoa ...
266!> \param laplace_rhob ...
267!> \param drhoa ...
268!> \param drhob ...
269!> \param rho_cutoff ...
270!> \param drho_cutoff ...
271!> \param tau_cutoff ...
272!> \param tau ...
273!> \param tau_a ...
274!> \param tau_b ...
275!> \param local_bounds ...
276! **************************************************************************************************
277 SUBROUTINE xc_rho_set_get(rho_set, can_return_null, rho, drho, norm_drho, &
278 rhoa, rhob, norm_drhoa, norm_drhob, rho_1_3, rhoa_1_3, &
279 rhob_1_3, laplace_rho, laplace_rhoa, laplace_rhob, drhoa, drhob, rho_cutoff, &
280 drho_cutoff, tau_cutoff, tau, tau_a, tau_b, local_bounds)
281 TYPE(xc_rho_set_type), INTENT(IN) :: rho_set
282 LOGICAL, INTENT(in), OPTIONAL :: can_return_null
283 REAL(kind=dp), DIMENSION(:, :, :), OPTIONAL, &
284 POINTER :: rho
285 TYPE(cp_3d_r_cp_type), DIMENSION(3), OPTIONAL :: drho
286 REAL(kind=dp), DIMENSION(:, :, :), OPTIONAL, &
287 POINTER :: norm_drho, rhoa, rhob, norm_drhoa, &
288 norm_drhob, rho_1_3, rhoa_1_3, &
289 rhob_1_3, laplace_rho, laplace_rhoa, &
290 laplace_rhob
291 TYPE(cp_3d_r_cp_type), DIMENSION(3), OPTIONAL :: drhoa, drhob
292 REAL(kind=dp), INTENT(out), OPTIONAL :: rho_cutoff, drho_cutoff, tau_cutoff
293 REAL(kind=dp), DIMENSION(:, :, :), OPTIONAL, &
294 POINTER :: tau, tau_a, tau_b
295 INTEGER, DIMENSION(2, 3), INTENT(OUT), OPTIONAL :: local_bounds
296
297 INTEGER :: i
298 LOGICAL :: my_can_return_null
299
300 my_can_return_null = .false.
301 IF (PRESENT(can_return_null)) my_can_return_null = can_return_null
302
303 IF (PRESENT(rho)) THEN
304 rho => rho_set%rho
305 cpassert(my_can_return_null .OR. ASSOCIATED(rho))
306 END IF
307 IF (PRESENT(drho)) THEN
308 DO i = 1, 3
309 drho(i)%array => rho_set%drho(i)%array
310 cpassert(my_can_return_null .OR. ASSOCIATED(rho_set%drho(i)%array))
311 END DO
312 END IF
313 IF (PRESENT(norm_drho)) THEN
314 norm_drho => rho_set%norm_drho
315 cpassert(my_can_return_null .OR. ASSOCIATED(norm_drho))
316 END IF
317 IF (PRESENT(laplace_rho)) THEN
318 laplace_rho => rho_set%laplace_rho
319 cpassert(my_can_return_null .OR. ASSOCIATED(laplace_rho))
320 END IF
321 IF (PRESENT(rhoa)) THEN
322 rhoa => rho_set%rhoa
323 cpassert(my_can_return_null .OR. ASSOCIATED(rhoa))
324 END IF
325 IF (PRESENT(rhob)) THEN
326 rhob => rho_set%rhob
327 cpassert(my_can_return_null .OR. ASSOCIATED(rhob))
328 END IF
329 IF (PRESENT(drhoa)) THEN
330 DO i = 1, 3
331 drhoa(i)%array => rho_set%drhoa(i)%array
332 cpassert(my_can_return_null .OR. ASSOCIATED(rho_set%drhoa(i)%array))
333 END DO
334 END IF
335 IF (PRESENT(drhob)) THEN
336 DO i = 1, 3
337 drhob(i)%array => rho_set%drhob(i)%array
338 cpassert(my_can_return_null .OR. ASSOCIATED(rho_set%drhob(i)%array))
339 END DO
340 END IF
341 IF (PRESENT(laplace_rhoa)) THEN
342 laplace_rhoa => rho_set%laplace_rhoa
343 cpassert(my_can_return_null .OR. ASSOCIATED(laplace_rhoa))
344 END IF
345 IF (PRESENT(laplace_rhob)) THEN
346 laplace_rhob => rho_set%laplace_rhob
347 cpassert(my_can_return_null .OR. ASSOCIATED(laplace_rhob))
348 END IF
349 IF (PRESENT(norm_drhoa)) THEN
350 norm_drhoa => rho_set%norm_drhoa
351 cpassert(my_can_return_null .OR. ASSOCIATED(norm_drhoa))
352 END IF
353 IF (PRESENT(norm_drhob)) THEN
354 norm_drhob => rho_set%norm_drhob
355 cpassert(my_can_return_null .OR. ASSOCIATED(norm_drhob))
356 END IF
357 IF (PRESENT(rho_1_3)) THEN
358 rho_1_3 => rho_set%rho_1_3
359 cpassert(my_can_return_null .OR. ASSOCIATED(rho_1_3))
360 END IF
361 IF (PRESENT(rhoa_1_3)) THEN
362 rhoa_1_3 => rho_set%rhoa_1_3
363 cpassert(my_can_return_null .OR. ASSOCIATED(rhoa_1_3))
364 END IF
365 IF (PRESENT(rhob_1_3)) THEN
366 rhob_1_3 => rho_set%rhob_1_3
367 cpassert(my_can_return_null .OR. ASSOCIATED(rhob_1_3))
368 END IF
369 IF (PRESENT(tau)) THEN
370 tau => rho_set%tau
371 cpassert(my_can_return_null .OR. ASSOCIATED(tau))
372 END IF
373 IF (PRESENT(tau_a)) THEN
374 tau_a => rho_set%tau_a
375 cpassert(my_can_return_null .OR. ASSOCIATED(tau_a))
376 END IF
377 IF (PRESENT(tau_b)) THEN
378 tau_b => rho_set%tau_b
379 cpassert(my_can_return_null .OR. ASSOCIATED(tau_b))
380 END IF
381 IF (PRESENT(rho_cutoff)) rho_cutoff = rho_set%rho_cutoff
382 IF (PRESENT(drho_cutoff)) drho_cutoff = rho_set%drho_cutoff
383 IF (PRESENT(tau_cutoff)) tau_cutoff = rho_set%tau_cutoff
384 IF (PRESENT(local_bounds)) local_bounds = rho_set%local_bounds
385 END SUBROUTINE xc_rho_set_get
386
387
388! **************************************************************************************************
389!> \brief Shifts association of the requested array to a pw grid
390!> Requires that the corresponding component of rho_set is associated
391!> If owns_data returns TRUE, the caller has to allocate the data later
392!> It is allowed to task for only one component per call.
393!> In case of drho, the array is allocated if not internally available and calculated from drhoa and drhob.
394!> \param rho_set the object you want info about
395!> \param pw_grid ...
396!> \param pw_pool ...
397!> \param owns_data ...
398!> \param rho ...
399!> \param drho ...
400!> \param norm_drho ...
401!> \param rhoa ...
402!> \param rhob ...
403!> \param norm_drhoa ...
404!> \param norm_drhob ...
405!> \param rho_1_3 ...
406!> \param rhoa_1_3 ...
407!> \param rhob_1_3 ...
408!> \param laplace_rho ...
409!> \param laplace_rhoa ...
410!> \param laplace_rhob ...
411!> \param drhoa ...
412!> \param drhob ...
413!> \param tau ...
414!> \param tau_a ...
415!> \param tau_b ...
416! **************************************************************************************************
417 SUBROUTINE xc_rho_set_recover_pw(rho_set, pw_grid, pw_pool, owns_data, rho, drho, norm_drho, &
418 rhoa, rhob, norm_drhoa, norm_drhob, rho_1_3, rhoa_1_3, &
419 rhob_1_3, laplace_rho, laplace_rhoa, laplace_rhob, drhoa, drhob, &
420 tau, tau_a, tau_b)
421 TYPE(xc_rho_set_type) :: rho_set
422 TYPE(pw_r3d_rs_type), DIMENSION(3), OPTIONAL, INTENT(OUT) :: drho, drhoa, drhob
423 TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: rho, norm_drho, rhoa, rhob, norm_drhoa, &
424 norm_drhob, rho_1_3, rhoa_1_3, &
425 rhob_1_3, laplace_rho, laplace_rhoa, &
426 laplace_rhob, tau, tau_a, tau_b
427 TYPE(pw_grid_type), POINTER, INTENT(IN) :: pw_grid
428 TYPE(pw_pool_type), POINTER, INTENT(IN) :: pw_pool
429 LOGICAL, INTENT(OUT) :: owns_data
430
431 INTEGER :: i
432
433 IF (PRESENT(rho)) THEN
434 NULLIFY (rho)
435 ALLOCATE (rho)
436 CALL xc_rho_set_recover_pw_low(rho, rho_set%rho, pw_grid, pw_pool)
437 NULLIFY (rho_set%rho)
438 owns_data = rho_set%owns%rho
439 END IF
440 IF (PRESENT(drho)) THEN
441 DO i = 1, 3
442 CALL xc_rho_set_recover_pw_low(drho(i), rho_set%drho(i)%array, pw_grid, pw_pool, rho_set%drhoa(i)%array,&
443 & rho_set%drhob(i)%array)
444 END DO
445 owns_data = .true.
446 END IF
447 IF (PRESENT(norm_drho)) THEN
448 NULLIFY (norm_drho)
449 ALLOCATE (norm_drho)
450 CALL xc_rho_set_recover_pw_low(norm_drho, rho_set%norm_drho, pw_grid, pw_pool)
451 NULLIFY (rho_set%norm_drho)
452 owns_data = rho_set%owns%norm_drho
453 END IF
454 IF (PRESENT(rhoa)) THEN
455 NULLIFY (rhoa)
456 ALLOCATE (rhoa)
457 CALL xc_rho_set_recover_pw_low(rhoa, rho_set%rhoa, pw_grid, pw_pool)
458 NULLIFY (rho_set%rhoa)
459 owns_data = rho_set%owns%rho_spin
460 END IF
461 IF (PRESENT(rhob)) THEN
462 NULLIFY (rhob)
463 ALLOCATE (rhob)
464 CALL xc_rho_set_recover_pw_low(rhob, rho_set%rhob, pw_grid, pw_pool)
465 NULLIFY (rho_set%rhob)
466 owns_data = rho_set%owns%rho_spin
467 END IF
468 IF (PRESENT(norm_drhoa)) THEN
469 NULLIFY (norm_drhoa)
470 ALLOCATE (norm_drhoa)
471 CALL xc_rho_set_recover_pw_low(norm_drhoa, rho_set%norm_drhoa, pw_grid, pw_pool)
472 NULLIFY (rho_set%norm_drhoa)
473 owns_data = rho_set%owns%norm_drho_spin
474 END IF
475 IF (PRESENT(norm_drhob)) THEN
476 NULLIFY (norm_drhob)
477 ALLOCATE (norm_drhob)
478 CALL xc_rho_set_recover_pw_low(norm_drhob, rho_set%norm_drhob, pw_grid, pw_pool)
479 NULLIFY (rho_set%norm_drhob)
480 owns_data = rho_set%owns%norm_drho_spin
481 END IF
482 IF (PRESENT(rho_1_3)) THEN
483 NULLIFY (rho_1_3)
484 ALLOCATE (rho_1_3)
485 CALL xc_rho_set_recover_pw_low(rho_1_3, rho_set%rho_1_3, pw_grid, pw_pool)
486 NULLIFY (rho_set%rho_1_3)
487 owns_data = rho_set%owns%rho_1_3
488 END IF
489 IF (PRESENT(rhoa_1_3)) THEN
490 NULLIFY (rhoa_1_3)
491 ALLOCATE (rhoa_1_3)
492 CALL xc_rho_set_recover_pw_low(rhoa_1_3, rho_set%rhoa_1_3, pw_grid, pw_pool)
493 NULLIFY (rho_set%rhoa_1_3)
494 owns_data = rho_set%owns%rho_spin_1_3
495 END IF
496 IF (PRESENT(rhob_1_3)) THEN
497 NULLIFY (rhob_1_3)
498 ALLOCATE (rhob_1_3)
499 CALL xc_rho_set_recover_pw_low(rhob_1_3, rho_set%rhob_1_3, pw_grid, pw_pool)
500 NULLIFY (rho_set%rhob_1_3)
501 owns_data = rho_set%owns%rho_spin_1_3
502 END IF
503 IF (PRESENT(laplace_rho)) THEN
504 NULLIFY (laplace_rho)
505 ALLOCATE (laplace_rho)
506 CALL xc_rho_set_recover_pw_low(laplace_rho, rho_set%laplace_rho, pw_grid, pw_pool)
507 NULLIFY (rho_set%laplace_rho)
508 owns_data = rho_set%owns%laplace_rho
509 END IF
510 IF (PRESENT(laplace_rhoa)) THEN
511 NULLIFY (laplace_rhoa)
512 ALLOCATE (laplace_rhoa)
513 CALL xc_rho_set_recover_pw_low(laplace_rhoa, rho_set%laplace_rhoa, pw_grid, pw_pool)
514 NULLIFY (rho_set%laplace_rhoa)
515 owns_data = rho_set%owns%laplace_rho_spin
516 END IF
517 IF (PRESENT(laplace_rhob)) THEN
518 NULLIFY (laplace_rhob)
519 ALLOCATE (laplace_rhob)
520 CALL xc_rho_set_recover_pw_low(laplace_rhob, rho_set%laplace_rhob, pw_grid, pw_pool)
521 NULLIFY (rho_set%laplace_rhob)
522 owns_data = rho_set%owns%laplace_rho_spin
523 END IF
524 IF (PRESENT(drhoa)) THEN
525 DO i = 1, 3
526 CALL xc_rho_set_recover_pw_low(drhoa(i), rho_set%drhoa(i)%array, pw_grid, pw_pool)
527 END DO
528 owns_data = rho_set%owns%drho_spin
529 END IF
530 IF (PRESENT(drhob)) THEN
531 DO i = 1, 3
532 CALL xc_rho_set_recover_pw_low(drhob(i), rho_set%drhob(i)%array, pw_grid, pw_pool)
533 END DO
534 owns_data = rho_set%owns%drho_spin
535 END IF
536 IF (PRESENT(tau)) THEN
537 NULLIFY (tau)
538 ALLOCATE (tau)
539 CALL xc_rho_set_recover_pw_low(tau, rho_set%tau, pw_grid, pw_pool)
540 NULLIFY (rho_set%tau)
541 owns_data = rho_set%owns%tau
542 END IF
543 IF (PRESENT(tau_a)) THEN
544 NULLIFY (tau_a)
545 ALLOCATE (tau_a)
546 CALL xc_rho_set_recover_pw_low(tau_a, rho_set%tau_a, pw_grid, pw_pool)
547 NULLIFY (rho_set%tau_a)
548 owns_data = rho_set%owns%tau_spin
549 END IF
550 IF (PRESENT(tau_b)) THEN
551 NULLIFY (tau_b)
552 ALLOCATE (tau_b)
553 CALL xc_rho_set_recover_pw_low(tau_b, rho_set%tau_b, pw_grid, pw_pool)
554 NULLIFY (rho_set%tau_b)
555 owns_data = rho_set%owns%tau_spin
556 END IF
557
558 END SUBROUTINE
559
560 SUBROUTINE xc_rho_set_recover_pw_low(rho_pw, rho, pw_grid, pw_pool, rhoa, rhob)
561 TYPE(pw_r3d_rs_type), INTENT(OUT) :: rho_pw
562 REAL(kind=dp), DIMENSION(:, :, :), POINTER, CONTIGUOUS :: rho
563 TYPE(pw_grid_type), POINTER, INTENT(IN) :: pw_grid
564 TYPE(pw_pool_type), POINTER, INTENT(IN) :: pw_pool
565 REAL(kind=dp), DIMENSION(:, :, :), POINTER, OPTIONAL :: rhoa, rhob
566
567 IF (ASSOCIATED(rho)) THEN
568 CALL rho_pw%create(pw_grid=pw_grid, array_ptr=rho)
569 NULLIFY (rho)
570 ELSE IF (PRESENT(rhoa) .AND. PRESENT(rhob)) THEN
571 CALL pw_pool%create_pw(rho_pw)
572!$OMP PARALLEL WORKSHARE DEFAULT(NONE) SHARED(rho_pw,rhoa,rhob)
573 rho_pw%array(:, :, :) = rhoa(:, :, :) + rhob(:, :, :)
574!$OMP END PARALLEL WORKSHARE
575 ELSE
576 CALL cp_abort(__location__, "Either component or its spin parts (if applicable) "// &
577 "have to be associated in rho_set!")
578 END IF
579
580 END SUBROUTINE
581
582! **************************************************************************************************
583!> \brief cleans (releases) most of the data stored in the rho_set giving back
584!> what it can to the pw_pool
585!> \param rho_set the rho_set to be cleaned
586!> \param pw_pool place to give back 3d arrays,...
587!> \author Fawzi Mohamed
588! **************************************************************************************************
589 SUBROUTINE xc_rho_set_clean(rho_set, pw_pool)
590 TYPE(xc_rho_set_type), INTENT(INOUT) :: rho_set
591 TYPE(pw_pool_type), POINTER :: pw_pool
592
593 INTEGER :: idir
594
595 IF (rho_set%owns%rho) THEN
596 CALL pw_pool%give_back_cr3d(rho_set%rho)
597 ELSE
598 NULLIFY (rho_set%rho)
599 END IF
600 IF (rho_set%owns%rho_1_3) THEN
601 CALL pw_pool%give_back_cr3d(rho_set%rho_1_3)
602 ELSE
603 NULLIFY (rho_set%rho_1_3)
604 END IF
605 IF (rho_set%owns%drho) THEN
606 DO idir = 1, 3
607 CALL pw_pool%give_back_cr3d(rho_set%drho(idir)%array)
608 END DO
609 ELSE
610 DO idir = 1, 3
611 NULLIFY (rho_set%drho(idir)%array)
612 END DO
613 END IF
614 IF (rho_set%owns%norm_drho) THEN
615 CALL pw_pool%give_back_cr3d(rho_set%norm_drho)
616 ELSE
617 NULLIFY (rho_set%norm_drho)
618 END IF
619 IF (rho_set%owns%laplace_rho) THEN
620 CALL pw_pool%give_back_cr3d(rho_set%laplace_rho)
621 ELSE
622 NULLIFY (rho_set%laplace_rho)
623 END IF
624 IF (rho_set%owns%tau) THEN
625 CALL pw_pool%give_back_cr3d(rho_set%tau)
626 ELSE
627 NULLIFY (rho_set%tau)
628 END IF
629 IF (rho_set%owns%rho_spin) THEN
630 CALL pw_pool%give_back_cr3d(rho_set%rhoa)
631 CALL pw_pool%give_back_cr3d(rho_set%rhob)
632 ELSE
633 NULLIFY (rho_set%rhoa, rho_set%rhob)
634 END IF
635 IF (rho_set%owns%rho_spin_1_3) THEN
636 CALL pw_pool%give_back_cr3d(rho_set%rhoa_1_3)
637 CALL pw_pool%give_back_cr3d(rho_set%rhob_1_3)
638 ELSE
639 NULLIFY (rho_set%rhoa_1_3, rho_set%rhob_1_3)
640 END IF
641 IF (rho_set%owns%drho_spin) THEN
642 DO idir = 1, 3
643 CALL pw_pool%give_back_cr3d(rho_set%drhoa(idir)%array)
644 CALL pw_pool%give_back_cr3d(rho_set%drhob(idir)%array)
645 END DO
646 ELSE
647 DO idir = 1, 3
648 NULLIFY (rho_set%drhoa(idir)%array, rho_set%drhob(idir)%array)
649 END DO
650 END IF
651 IF (rho_set%owns%laplace_rho_spin) THEN
652 CALL pw_pool%give_back_cr3d(rho_set%laplace_rhoa)
653 CALL pw_pool%give_back_cr3d(rho_set%laplace_rhob)
654 ELSE
655 NULLIFY (rho_set%laplace_rhoa, rho_set%laplace_rhob)
656 END IF
657 IF (rho_set%owns%norm_drho_spin) THEN
658 CALL pw_pool%give_back_cr3d(rho_set%norm_drhoa)
659 CALL pw_pool%give_back_cr3d(rho_set%norm_drhob)
660 ELSE
661 NULLIFY (rho_set%norm_drhoa, rho_set%norm_drhob)
662 END IF
663 IF (rho_set%owns%tau_spin) THEN
664 CALL pw_pool%give_back_cr3d(rho_set%tau_a)
665 CALL pw_pool%give_back_cr3d(rho_set%tau_b)
666 ELSE
667 NULLIFY (rho_set%tau_a, rho_set%tau_b)
668 END IF
669
670 CALL xc_rho_cflags_setall(rho_set%has, .false.)
671 CALL xc_rho_cflags_setall(rho_set%owns, .false.)
672
673 END SUBROUTINE xc_rho_set_clean
674
675! **************************************************************************************************
676!> \brief updates the given rho set with the density given by
677!> rho_r (and rho_g). The rho set will contain the components specified
678!> in needs
679!> \param rho_set the rho_set to update
680!> \param rho_r the new density (in r space)
681!> \param rho_g the new density (in g space, needed for some
682!> derivatives)
683!> \param tau ...
684!> \param needs the components of rho that are needed
685!> \param xc_deriv_method_id ...
686!> \param xc_rho_smooth_id ...
687!> \param pw_pool pool for the allocation of pw and array
688! **************************************************************************************************
689 SUBROUTINE xc_rho_set_update(rho_set, rho_r, rho_g, tau, needs, &
690 xc_deriv_method_id, xc_rho_smooth_id, pw_pool, spinflip)
691 TYPE(xc_rho_set_type), INTENT(INOUT) :: rho_set
692 TYPE(pw_r3d_rs_type), DIMENSION(:), INTENT(IN) :: rho_r
693 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
694 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER, INTENT(IN) :: tau
695 TYPE(xc_rho_cflags_type), INTENT(in) :: needs
696 INTEGER, INTENT(IN) :: xc_deriv_method_id, xc_rho_smooth_id
697 TYPE(pw_pool_type), POINTER :: pw_pool
698 LOGICAL, OPTIONAL :: spinflip
699
700 REAL(kind=dp), PARAMETER :: f13 = (1.0_dp/3.0_dp)
701
702 INTEGER :: i, idir, ispin, j, k, nspins
703 LOGICAL :: gradient_f, my_rho_g_local, &
704 needs_laplace, needs_rho_g, do_sf
705 REAL(kind=dp) :: rho_cutoff
706 TYPE(pw_r3d_rs_type), DIMENSION(2) :: laplace_rho_r
707 TYPE(pw_r3d_rs_type), DIMENSION(3, 2) :: drho_r
708 TYPE(pw_c1d_gs_type) :: my_rho_g, tmp_g
709 TYPE(pw_r3d_rs_type), DIMENSION(2) :: my_rho_r
710
711 do_sf = .false.
712 IF (PRESENT(spinflip)) do_sf = spinflip
713
714 IF (any(rho_set%local_bounds /= pw_pool%pw_grid%bounds_local)) &
715 cpabort("pw_pool cr3d have different size than expected")
716 nspins = SIZE(rho_r)
717 rho_set%local_bounds = rho_r(1)%pw_grid%bounds_local
718 rho_cutoff = 0.5*rho_set%rho_cutoff
719
720 my_rho_g_local = .false.
721 ! some checks
722 SELECT CASE (nspins)
723 CASE (1)
724 IF (.NOT. do_sf) THEN
725 cpassert(.NOT. needs%rho_spin)
726 cpassert(.NOT. needs%drho_spin)
727 cpassert(.NOT. needs%norm_drho_spin)
728 cpassert(.NOT. needs%rho_spin_1_3)
729 cpassert(.NOT. needs%tau_spin)
730 cpassert(.NOT. needs%laplace_rho_spin)
731 ELSE
732 cpassert(.NOT. needs%rho)
733 cpassert(.NOT. needs%drho)
734 cpassert(.NOT. needs%rho_1_3)
735 cpassert(.NOT. needs%tau)
736 cpassert(.NOT. needs%laplace_rho)
737 END IF
738 CASE (2)
739 cpassert(.NOT. needs%rho)
740 cpassert(.NOT. needs%drho)
741 cpassert(.NOT. needs%rho_1_3)
742 cpassert(.NOT. needs%tau)
743 cpassert(.NOT. needs%laplace_rho)
744 CASE default
745 cpabort("Unknown number of spin states")
746 END SELECT
747
748 CALL xc_rho_set_clean(rho_set, pw_pool=pw_pool)
749
750 needs_laplace = (needs%laplace_rho .OR. needs%laplace_rho_spin)
751 gradient_f = (needs%drho_spin .OR. needs%norm_drho_spin .OR. &
752 needs%drho .OR. needs%norm_drho .OR. &
753 needs_laplace)
754 needs_rho_g = ((xc_deriv_method_id == xc_deriv_spline3 .OR. &
755 xc_deriv_method_id == xc_deriv_spline2 .OR. &
756 xc_deriv_method_id == xc_deriv_pw)) .AND. (gradient_f .OR. needs_laplace)
757 IF ((gradient_f .AND. needs_laplace) .AND. &
758 (xc_deriv_method_id /= xc_deriv_pw)) THEN
759 CALL cp_abort(__location__, &
760 "MGGA functionals that require the Laplacian are "// &
761 "only compatible with 'XC_DERIV PW' and 'XC_SMOOTH_RHO NONE'")
762 END IF
763
764 IF (needs_rho_g) THEN
765 CALL pw_pool%create_pw(tmp_g)
766 END IF
767 DO ispin = 1, nspins
768 CALL pw_pool%create_pw(my_rho_r(ispin))
769 ! introduce a smoothing kernel on the density
770 IF (xc_rho_smooth_id == xc_rho_no_smooth) THEN
771 IF (needs_rho_g) THEN
772 IF (ASSOCIATED(rho_g)) THEN
773 my_rho_g_local = .false.
774 my_rho_g = rho_g(ispin)
775 END IF
776 END IF
777
778 CALL pw_copy(rho_r(ispin), my_rho_r(ispin))
779 ELSE
780 CALL xc_pw_smooth(rho_r(ispin), my_rho_r(ispin), xc_rho_smooth_id)
781 END IF
782
783 IF (gradient_f) THEN ! calculate the grad of rho
784 ! normally when you need the gradient you need the whole gradient
785 ! (for the partial integration)
786 ! deriv rho
787 DO idir = 1, 3
788 CALL pw_pool%create_pw(drho_r(idir, ispin))
789 END DO
790 IF (needs_rho_g) THEN
791 IF (.NOT. ASSOCIATED(my_rho_g%pw_grid)) THEN
792 my_rho_g_local = .true.
793 CALL pw_pool%create_pw(my_rho_g)
794 CALL pw_transfer(my_rho_r(ispin), my_rho_g)
795 END IF
796 IF (.NOT. my_rho_g_local .AND. (xc_deriv_method_id == xc_deriv_spline2 .OR. &
797 xc_deriv_method_id == xc_deriv_spline3)) THEN
798 CALL pw_pool%create_pw(my_rho_g)
799 my_rho_g_local = .true.
800 CALL pw_copy(rho_g(ispin), my_rho_g)
801 END IF
802 END IF
803 IF (needs%laplace_rho .OR. needs%laplace_rho_spin) THEN
804 CALL pw_pool%create_pw(laplace_rho_r(ispin))
805 CALL xc_pw_laplace(my_rho_g, pw_pool, xc_deriv_method_id, laplace_rho_r(ispin), tmp_g=tmp_g)
806 END IF
807 CALL xc_pw_gradient(my_rho_r(ispin), my_rho_g, tmp_g, drho_r(:, ispin), xc_deriv_method_id)
808
809 IF (needs_rho_g) THEN
810 IF (my_rho_g_local) THEN
811 my_rho_g_local = .false.
812 CALL pw_pool%give_back_pw(my_rho_g)
813 END IF
814 END IF
815
816 IF (xc_deriv_method_id /= xc_deriv_pw) THEN
817 CALL pw_spline_scale_deriv(drho_r(:, ispin))
818 END IF
819
820 END IF
821
822 END DO
823
824 IF (ASSOCIATED(tmp_g%pw_grid)) THEN
825 CALL pw_pool%give_back_pw(tmp_g)
826 END IF
827
828 SELECT CASE (nspins)
829 CASE (1)
830 IF (.NOT. do_sf) THEN
831 IF (needs%rho_1_3) THEN
832 CALL pw_pool%create_cr3d(rho_set%rho_1_3)
833!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(i,j,k) SHARED(rho_set,my_rho_r)
834 DO k = rho_set%local_bounds(1, 3), rho_set%local_bounds(2, 3)
835 DO j = rho_set%local_bounds(1, 2), rho_set%local_bounds(2, 2)
836 DO i = rho_set%local_bounds(1, 1), rho_set%local_bounds(2, 1)
837 rho_set%rho_1_3(i, j, k) = max(my_rho_r(1)%array(i, j, k), 0.0_dp)**f13
838 END DO
839 END DO
840 END DO
841 rho_set%owns%rho_1_3 = .true.
842 rho_set%has%rho_1_3 = .true.
843 END IF
844 IF (needs%rho) THEN
845 rho_set%rho => my_rho_r(1)%array
846 NULLIFY (my_rho_r(1)%array)
847 rho_set%owns%rho = .true.
848 rho_set%has%rho = .true.
849 END IF
850 IF (needs%norm_drho) THEN
851 CALL pw_pool%create_cr3d(rho_set%norm_drho)
852!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(i,j,k) SHARED(rho_set,drho_r)
853 DO k = rho_set%local_bounds(1, 3), rho_set%local_bounds(2, 3)
854 DO j = rho_set%local_bounds(1, 2), rho_set%local_bounds(2, 2)
855 DO i = rho_set%local_bounds(1, 1), rho_set%local_bounds(2, 1)
856 rho_set%norm_drho(i, j, k) = sqrt( &
857 drho_r(1, 1)%array(i, j, k)**2 + &
858 drho_r(2, 1)%array(i, j, k)**2 + &
859 drho_r(3, 1)%array(i, j, k)**2)
860 END DO
861 END DO
862 END DO
863 rho_set%owns%norm_drho = .true.
864 rho_set%has%norm_drho = .true.
865 END IF
866 IF (needs%laplace_rho) THEN
867 rho_set%laplace_rho => laplace_rho_r(1)%array
868 NULLIFY (laplace_rho_r(1)%array)
869 rho_set%owns%laplace_rho = .true.
870 rho_set%has%laplace_rho = .true.
871 END IF
872
873 IF (needs%drho) THEN
874 DO idir = 1, 3
875 rho_set%drho(idir)%array => drho_r(idir, 1)%array
876 NULLIFY (drho_r(idir, 1)%array)
877 END DO
878 rho_set%owns%drho = .true.
879 rho_set%has%drho = .true.
880 END IF
881 ELSE
882 IF (needs%norm_drho) THEN
883 CALL pw_pool%create_cr3d(rho_set%norm_drho)
884!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(i,j,k) SHARED(rho_set,drho_r)
885 DO k = rho_set%local_bounds(1, 3), rho_set%local_bounds(2, 3)
886 DO j = rho_set%local_bounds(1, 2), rho_set%local_bounds(2, 2)
887 DO i = rho_set%local_bounds(1, 1), rho_set%local_bounds(2, 1)
888 rho_set%norm_drho(i, j, k) = sqrt( &
889 drho_r(1, 1)%array(i, j, k)**2 + &
890 drho_r(2, 1)%array(i, j, k)**2 + &
891 drho_r(3, 1)%array(i, j, k)**2)
892 END DO
893 END DO
894 END DO
895 rho_set%owns%norm_drho = .true.
896 rho_set%has%norm_drho = .true.
897 END IF
898 IF (needs%rho_spin) THEN
899
900 rho_set%rhoa => my_rho_r(1)%array
901 NULLIFY (my_rho_r(1)%array)
902
903 rho_set%owns%rho_spin = .true.
904 rho_set%has%rho_spin = .true.
905 END IF
906 IF (needs%norm_drho_spin) THEN
907 CALL pw_pool%create_cr3d(rho_set%norm_drhoa)
908!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(i,j,k) SHARED(rho_set,drho_r)
909 DO k = rho_set%local_bounds(1, 3), rho_set%local_bounds(2, 3)
910 DO j = rho_set%local_bounds(1, 2), rho_set%local_bounds(2, 2)
911 DO i = rho_set%local_bounds(1, 1), rho_set%local_bounds(2, 1)
912 rho_set%norm_drhoa(i, j, k) = sqrt( &
913 drho_r(1, 1)%array(i, j, k)**2 + &
914 drho_r(2, 1)%array(i, j, k)**2 + &
915 drho_r(3, 1)%array(i, j, k)**2)
916 END DO
917 END DO
918 END DO
919 rho_set%owns%norm_drho_spin = .true.
920 rho_set%has%norm_drho_spin = .true.
921 END IF
922 IF (needs%laplace_rho_spin) THEN
923 rho_set%laplace_rhoa => laplace_rho_r(1)%array
924 NULLIFY (laplace_rho_r(1)%array)
925
926 rho_set%owns%laplace_rho_spin = .true.
927 rho_set%has%laplace_rho_spin = .true.
928 END IF
929 IF (needs%drho_spin) THEN
930 DO idir = 1, 3
931 rho_set%drhoa(idir)%array => drho_r(idir, 1)%array
932 NULLIFY (drho_r(idir, 1)%array)
933 END DO
934 rho_set%owns%drho_spin = .true.
935 rho_set%has%drho_spin = .true.
936 END IF
937 END IF
938 CASE (2)
939 IF (needs%rho_spin_1_3) THEN
940 CALL pw_pool%create_cr3d(rho_set%rhoa_1_3)
941 !assume that the bounds are the same?
942!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(i,j,k) SHARED(rho_set,my_rho_r)
943 DO k = rho_set%local_bounds(1, 3), rho_set%local_bounds(2, 3)
944 DO j = rho_set%local_bounds(1, 2), rho_set%local_bounds(2, 2)
945 DO i = rho_set%local_bounds(1, 1), rho_set%local_bounds(2, 1)
946 rho_set%rhoa_1_3(i, j, k) = max(my_rho_r(1)%array(i, j, k), 0.0_dp)**f13
947 END DO
948 END DO
949 END DO
950 CALL pw_pool%create_cr3d(rho_set%rhob_1_3)
951 !assume that the bounds are the same?
952!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(i,j,k) SHARED(rho_set,my_rho_r)
953 DO k = rho_set%local_bounds(1, 3), rho_set%local_bounds(2, 3)
954 DO j = rho_set%local_bounds(1, 2), rho_set%local_bounds(2, 2)
955 DO i = rho_set%local_bounds(1, 1), rho_set%local_bounds(2, 1)
956 rho_set%rhob_1_3(i, j, k) = max(my_rho_r(2)%array(i, j, k), 0.0_dp)**f13
957 END DO
958 END DO
959 END DO
960 rho_set%owns%rho_spin_1_3 = .true.
961 rho_set%has%rho_spin_1_3 = .true.
962 END IF
963 IF (needs%norm_drho) THEN
964
965 CALL pw_pool%create_cr3d(rho_set%norm_drho)
966!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(i,j,k) SHARED(rho_set,drho_r)
967 DO k = rho_set%local_bounds(1, 3), rho_set%local_bounds(2, 3)
968 DO j = rho_set%local_bounds(1, 2), rho_set%local_bounds(2, 2)
969 DO i = rho_set%local_bounds(1, 1), rho_set%local_bounds(2, 1)
970 rho_set%norm_drho(i, j, k) = sqrt( &
971 (drho_r(1, 1)%array(i, j, k) + drho_r(1, 2)%array(i, j, k))**2 + &
972 (drho_r(2, 1)%array(i, j, k) + drho_r(2, 2)%array(i, j, k))**2 + &
973 (drho_r(3, 1)%array(i, j, k) + drho_r(3, 2)%array(i, j, k))**2)
974 END DO
975 END DO
976 END DO
977
978 rho_set%owns%norm_drho = .true.
979 rho_set%has%norm_drho = .true.
980 END IF
981 IF (needs%rho_spin) THEN
982
983 rho_set%rhoa => my_rho_r(1)%array
984 NULLIFY (my_rho_r(1)%array)
985
986 rho_set%rhob => my_rho_r(2)%array
987 NULLIFY (my_rho_r(2)%array)
988
989 rho_set%owns%rho_spin = .true.
990 rho_set%has%rho_spin = .true.
991 END IF
992 IF (needs%norm_drho_spin) THEN
993
994 CALL pw_pool%create_cr3d(rho_set%norm_drhoa)
995!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(i,j,k) SHARED(rho_set,drho_r)
996 DO k = rho_set%local_bounds(1, 3), rho_set%local_bounds(2, 3)
997 DO j = rho_set%local_bounds(1, 2), rho_set%local_bounds(2, 2)
998 DO i = rho_set%local_bounds(1, 1), rho_set%local_bounds(2, 1)
999 rho_set%norm_drhoa(i, j, k) = sqrt( &
1000 drho_r(1, 1)%array(i, j, k)**2 + &
1001 drho_r(2, 1)%array(i, j, k)**2 + &
1002 drho_r(3, 1)%array(i, j, k)**2)
1003 END DO
1004 END DO
1005 END DO
1006
1007 CALL pw_pool%create_cr3d(rho_set%norm_drhob)
1008 rho_set%owns%norm_drho_spin = .true.
1009!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(i,j,k) SHARED(rho_set,drho_r)
1010 DO k = rho_set%local_bounds(1, 3), rho_set%local_bounds(2, 3)
1011 DO j = rho_set%local_bounds(1, 2), rho_set%local_bounds(2, 2)
1012 DO i = rho_set%local_bounds(1, 1), rho_set%local_bounds(2, 1)
1013 rho_set%norm_drhob(i, j, k) = sqrt( &
1014 drho_r(1, 2)%array(i, j, k)**2 + &
1015 drho_r(2, 2)%array(i, j, k)**2 + &
1016 drho_r(3, 2)%array(i, j, k)**2)
1017 END DO
1018 END DO
1019 END DO
1020
1021 rho_set%owns%norm_drho_spin = .true.
1022 rho_set%has%norm_drho_spin = .true.
1023 END IF
1024 IF (needs%laplace_rho_spin) THEN
1025 rho_set%laplace_rhoa => laplace_rho_r(1)%array
1026 NULLIFY (laplace_rho_r(1)%array)
1027
1028 rho_set%laplace_rhob => laplace_rho_r(2)%array
1029 NULLIFY (laplace_rho_r(2)%array)
1030
1031 rho_set%owns%laplace_rho_spin = .true.
1032 rho_set%has%laplace_rho_spin = .true.
1033 END IF
1034 IF (needs%drho_spin) THEN
1035 DO idir = 1, 3
1036 rho_set%drhoa(idir)%array => drho_r(idir, 1)%array
1037 NULLIFY (drho_r(idir, 1)%array)
1038 rho_set%drhob(idir)%array => drho_r(idir, 2)%array
1039 NULLIFY (drho_r(idir, 2)%array)
1040 END DO
1041 rho_set%owns%drho_spin = .true.
1042 rho_set%has%drho_spin = .true.
1043 END IF
1044 END SELECT
1045 ! post cleanup
1046 DO ispin = 1, nspins
1047 IF (needs%laplace_rho .OR. needs%laplace_rho_spin) THEN
1048 CALL pw_pool%give_back_pw(laplace_rho_r(ispin))
1049 END IF
1050 DO idir = 1, 3
1051 CALL pw_pool%give_back_pw(drho_r(idir, ispin))
1052 END DO
1053 END DO
1054 DO ispin = 1, nspins
1055 CALL pw_pool%give_back_pw(my_rho_r(ispin))
1056 END DO
1057
1058 ! tau part
1059 IF (needs%tau .OR. needs%tau_spin) THEN
1060 cpassert(ASSOCIATED(tau))
1061 DO ispin = 1, nspins
1062 cpassert(ASSOCIATED(tau(ispin)%array))
1063 END DO
1064 END IF
1065 IF (needs%tau) THEN
1066 rho_set%tau => tau(1)%array
1067 rho_set%owns%tau = .false.
1068 rho_set%has%tau = .true.
1069 END IF
1070 IF (needs%tau_spin) THEN
1071 rho_set%tau_a => tau(1)%array
1072 rho_set%tau_b => tau(2)%array
1073 rho_set%owns%tau_spin = .false.
1074 rho_set%has%tau_spin = .true.
1075 END IF
1076
1077 cpassert(xc_rho_cflags_equal(rho_set%has, needs))
1078
1079 END SUBROUTINE xc_rho_set_update
1080
1081 END MODULE xc_rho_set_types
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
different utils that are useful to manipulate splines on the regular grid of a pw
subroutine, public pw_spline_scale_deriv(deriv_vals_r, transpose, scale)
rescales the derivatives from gridspacing=1 to the real derivatives
input constants for xc
integer, parameter, public xc_deriv_pw
integer, parameter, public xc_deriv_spline2
integer, parameter, public xc_deriv_spline3
integer, parameter, public xc_rho_no_smooth
contains the structure
elemental logical function, public xc_rho_cflags_equal(cflags1, cflags2)
return true if the two cflags are equal
elemental subroutine, public xc_rho_cflags_setall(cflags, value)
sets all the flags to the given value
contains the structure
subroutine, public xc_rho_set_create(rho_set, local_bounds, rho_cutoff, drho_cutoff, tau_cutoff)
allocates and does (minimal) initialization of a rho_set
subroutine, public xc_rho_set_release(rho_set, pw_pool)
releases the given rho_set
subroutine, public xc_rho_set_recover_pw(rho_set, pw_grid, pw_pool, owns_data, rho, drho, norm_drho, rhoa, rhob, norm_drhoa, norm_drhob, rho_1_3, rhoa_1_3, rhob_1_3, laplace_rho, laplace_rhoa, laplace_rhob, drhoa, drhob, tau, tau_a, tau_b)
Shifts association of the requested array to a pw grid Requires that the corresponding component of r...
subroutine, public xc_rho_set_update(rho_set, rho_r, rho_g, tau, needs, xc_deriv_method_id, xc_rho_smooth_id, pw_pool, spinflip)
updates the given rho set with the density given by rho_r (and rho_g). The rho set will contain the c...
subroutine, public xc_rho_set_get(rho_set, can_return_null, rho, drho, norm_drho, rhoa, rhob, norm_drhoa, norm_drhob, rho_1_3, rhoa_1_3, rhob_1_3, laplace_rho, laplace_rhoa, laplace_rhob, drhoa, drhob, rho_cutoff, drho_cutoff, tau_cutoff, tau, tau_a, tau_b, local_bounds)
returns the various attributes of rho_set
contains utility functions for the xc package
Definition xc_util.F:14
subroutine, public xc_pw_smooth(pw_in, pw_out, xc_smooth_id)
...
Definition xc_util.F:73
subroutine, public xc_pw_gradient(pw_r, pw_g, tmp_g, gradient, xc_deriv_method_id)
...
Definition xc_util.F:123
represent a pointer to a contiguous 3d array
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
contains a flag for each component of xc_rho_set, so that you can use it to tell which components you...
represent a density, with all the representation and data needed to perform a functional evaluation