(git:b6ef100)
Loading...
Searching...
No Matches
xc_libxc.F
Go to the documentation of this file.
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! **************************************************************************************************
9!> \brief calculates a functional from libxc and its derivatives
10!> \note
11!> LibXC:
12!> (Marques, Oliveira, Burnus, CPC 183, 2272 (2012)).
13!>
14!> WARNING: In the subroutine libxc_spin_polarized_calc, it could be that the
15!> ordering for the 1st index of v2lapltau, v2rholapl, v2rhotau,
16!> v2sigmalapl and v2sigmatau is not correct. For the moment it does not
17!> matter since the calculation of the 2nd derivatives for meta-GGA
18!> functionals is not implemented in CP2K.
19!>
20!> \par History
21!> 01.2013 created [F. Tran]
22!> 07.2014 updates to versions 2.1 [JGH]
23!> 08.2015 refactoring [A. Gloess (agloess)]
24!> 01.2018 refactoring [A. Gloess (agloess)]
25!> 10.2018/04.2019 added hyb_mgga [S. Simko, included by F. Stein]
26!> \author F. Tran
27! **************************************************************************************************
29 USE bibliography, ONLY: lehtola2018, &
31 cite_reference
39 USE kinds, ONLY: default_string_length, &
40 dp
48#if defined (__LIBXC)
52 USE iso_c_binding, ONLY: c_size_t, c_int, c_double
53 USE xc_derivative_desc, ONLY: &
57 USE xc_libxc_wrap, ONLY: xc_f03_func_t, &
58 xc_f03_func_init, &
59 xc_f03_func_end, &
60 xc_f03_func_info_t, &
61 xc_f03_functional_get_name, &
62 xc_f03_func_get_info, &
63 xc_f03_func_info_get_family, &
64 xc_f03_func_info_get_kind, &
65 xc_f03_func_info_get_n_ext_params, &
66 xc_f03_func_info_get_name, &
67 xc_f03_available_functional_numbers, &
68 xc_f03_available_functional_names, &
69 xc_f03_maximum_name_length, &
70 xc_f03_number_of_functionals, &
71 xc_f03_func_info_get_ext_params_name, &
72 xc_f03_func_info_get_ext_params_description, &
73 xc_f03_func_info_get_ext_params_default_value, &
74 xc_f03_gga_exc, &
75 xc_f03_gga_exc_vxc, &
76 xc_f03_gga_exc_vxc_fxc, &
77 xc_f03_gga_fxc, &
78 xc_f03_gga_vxc, &
79 xc_f03_gga_vxc_fxc, &
80 xc_f03_lda, &
81 xc_f03_lda_exc, &
82 xc_f03_lda_exc_vxc, &
83 xc_f03_lda_exc_vxc_fxc, &
84 xc_f03_lda_fxc, &
85 xc_f03_lda_kxc, &
86 xc_f03_lda_vxc, &
87 xc_f03_mgga, &
88 xc_f03_mgga_exc, &
89 xc_f03_mgga_exc_vxc, &
90 xc_f03_mgga_fxc, &
91 xc_f03_mgga_vxc, &
92 xc_f03_mgga_vxc_fxc, &
93 xc_polarized, &
94 xc_unpolarized, &
95 xc_family_lda, &
96 xc_family_gga, &
97 xc_family_mgga, &
98 xc_family_hyb_lda, &
99 xc_family_hyb_gga, &
100 xc_family_hyb_mgga, &
101 xc_correlation, &
102 xc_exchange, &
103 xc_exchange_correlation, &
104 xc_kinetic, &
105 xc_libxc_wrap_info_refs, &
106 xc_libxc_wrap_version, &
107 xc_libxc_wrap_library_reference, &
108 xc_libxc_wrap_functional_get_number, &
109 xc_libxc_wrap_info_needs_laplace, &
110 xc_libxc_wrap_info_no_exc, &
111 xc_libxc_wrap_set_thresholds, &
112 xc_f03_func_set_ext_params, &
113 xc_libxc_wrap_is_under_development, &
114 xc_libxc_get_reference_length, &
115 xc_libxc_check_functional
116#endif
117!$ USE OMP_LIB, ONLY: omp_get_max_threads, &
118!$ omp_get_num_threads, &
119!$ omp_get_thread_num
120
121#include "../base/base_uses.f90"
122
123 IMPLICIT NONE
124 PRIVATE
125
126 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xc_libxc'
127
133
134#if defined (__LIBXC)
135 ! Number of grid points handed to LibXC in a single call. LibXC amortizes its
136 ! per-call work (argument checks, output initialization and, for functionals
137 ! built by mixing components, a full allocate/free cycle of the component
138 ! buffers) over the points in the call, so evaluating point by point paid that
139 ! cost once per point. Blocking rather than passing the whole grid keeps the
140 ! staging buffers inside the cache; the timing is flat between roughly 128 and
141 ! 2048 points, so the exact value is not critical.
142 INTEGER, PARAMETER, PRIVATE :: libxc_block_size = 512
143
144! **************************************************************************************************
145!> \brief One LibXC functional object plus the buffers used to hand it a block of
146!> grid points. One of these is kept per OpenMP thread so that neither the
147!> functional object nor the buffers are rebuilt between batches.
148! **************************************************************************************************
149 TYPE libxc_worker_type
150 TYPE(xc_f03_func_t) :: func = xc_f03_func_t()
151 TYPE(xc_f03_func_info_t) :: info = xc_f03_func_info_t()
152 LOGICAL :: is_init = .false.
153 ! staging buffers, dimensioned (component, point)
154 REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: rho, sigma, lapl, tau
155 ! the floored gradient norms the spin-polarized chain rule is written in
156 REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: nd, nda, ndb
157 REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: exc
158 REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: vrho, vsigma, vlapl, vtau
159 REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: v2rho2, v2rhosigma, v2sigma2, &
160 v2rholapl, v2rhotau, v2sigmalapl, &
161 v2sigmatau, v2lapl2, v2lapltau, v2tau2
162 REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: v3rho3
163 END TYPE libxc_worker_type
164
165! **************************************************************************************************
166!> \brief All threads' workers for one distinct functional setup, together with
167!> the key that identifies that setup.
168! **************************************************************************************************
169 TYPE libxc_worker_set_type
170 INTEGER :: func_id = -1
171 INTEGER :: nspin = -1
172 INTEGER :: family = -1
173 LOGICAL :: has_laplace = .false.
174 LOGICAL :: no_exc = .false.
175 LOGICAL :: has_params = .false.
176 REAL(KIND=dp) :: epsilon_rho = -1.0_dp
177 REAL(KIND=dp) :: epsilon_tau = -1.0_dp
178 REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: params
179 CHARACTER(LEN=128), DIMENSION(:), ALLOCATABLE :: param_names
180 TYPE(libxc_worker_type), DIMENSION(:), ALLOCATABLE :: worker
181 END TYPE libxc_worker_set_type
182
183 ! Workers are acquired from a serial region only (see libxc_get_workers), so
184 ! the cache itself needs no locking.
185 TYPE(libxc_worker_set_type), DIMENSION(:), ALLOCATABLE, TARGET, PRIVATE, SAVE :: libxc_cache
186
187 ! Stands in for the derivative arrays a given evaluation does not produce.
188 ! Those arguments still have to be associated with something, but they are
189 ! never read or written; pointing them at the density instead would make an
190 ! output argument alias a read-only input. Grown on demand and kept for the
191 ! run rather than allocated per evaluation, and like the cache above it is
192 ! only ever touched from a serial region.
193 REAL(KIND=dp), DIMENSION(:), ALLOCATABLE, TARGET, PRIVATE, SAVE :: libxc_unused
194#endif
195
196CONTAINS
197
198! **************************************************************************************************
199!> \brief This function checks whether a functional name belongs to LibXC
200!> \param libxc_params (possible) LibXC input section
201!> \return exists whether the functional exists in LibXC
202! **************************************************************************************************
203 FUNCTION libxc_check_existence_in_libxc(libxc_params) RESULT(exists)
204
205 TYPE(section_vals_type), POINTER, INTENT(IN) :: libxc_params
206 LOGICAL :: exists
207
208#if defined (__LIBXC)
209
210 exists = xc_libxc_check_functional(libxc_params%section%name)
211#else
212 mark_used(libxc_params)
213 exists = .false.
214#endif
215
217
218! **************************************************************************************************
219!> \brief This function returns the maximum length of the reference string for a given LibXC functional
220!> \param libxc_params LibXC input section
221!> \param lsd spin polarized calculation
222!> \return maximum length of the string
223! **************************************************************************************************
224 FUNCTION libxc_get_reference_length(libxc_params, lsd) RESULT(length)
225
226 TYPE(section_vals_type), POINTER, INTENT(IN) :: libxc_params
227 LOGICAL, INTENT(IN) :: lsd
228 INTEGER :: length
229
230#if defined (__LIBXC)
231 CHARACTER(len=*), PARAMETER :: routinen = 'libxc_get_reference_length'
232
233 CHARACTER(LEN=default_string_length) :: func_name
234 INTEGER :: func_id, handle
235 TYPE(xc_f03_func_t) :: xc_func
236 TYPE(xc_f03_func_info_t) :: xc_info
237
238 CALL timeset(routinen, handle)
239
240 func_name = libxc_params%section%name
241
242 func_id = xc_libxc_wrap_functional_get_number(func_name)
243 IF (lsd) THEN
244 CALL xc_f03_func_init(xc_func, func_id, xc_polarized)
245 ELSE
246 CALL xc_f03_func_init(xc_func, func_id, xc_unpolarized)
247 END IF
248 xc_info = xc_f03_func_get_info(xc_func)
249
250 length = xc_libxc_get_reference_length(xc_info)
251
252 CALL xc_f03_func_end(xc_func)
253
254 CALL timestop(handle)
255#else
256 mark_used(libxc_params)
257 mark_used(lsd)
258 length = 0
259 cpabort("In order to use LibXC you have to download and install it!")
260#endif
261
262 END FUNCTION libxc_get_reference_length
263
264! **************************************************************************************************
265!> \brief ...
266!> \param section ...
267! **************************************************************************************************
268 SUBROUTINE libxc_add_sections(section)
269
270 TYPE(section_type), POINTER, INTENT(IN) :: section
271
272#if defined (__LIBXC)
273 CHARACTER(len=*), PARAMETER :: routinen = 'libxc_add_sections'
274
275 TYPE(section_type), POINTER :: subsection
276 TYPE(keyword_type), POINTER :: keyword
277 INTEGER :: handle, no_func, len_name, ii, func_id, n_param, iparam
278 REAL(kind=c_double) :: default_val
279 CHARACTER(LEN=128) :: func_name, param_name, param_descr, description
280 CHARACTER(LEN=2*default_string_length) :: warning
281 INTEGER(KIND=C_INT), DIMENSION(:), ALLOCATABLE :: func_ids
282 TYPE(xc_f03_func_t) :: xc_func
283 TYPE(xc_f03_func_info_t) :: xc_info
284
285 CALL timeset(routinen, handle)
286
287 cpassert(ASSOCIATED(section))
288 NULLIFY (subsection, keyword)
289
290 no_func = xc_f03_number_of_functionals()
291 len_name = xc_f03_maximum_name_length()
292
293 ALLOCATE (func_ids(no_func))
294
295 CALL xc_f03_available_functional_numbers(func_ids)
296
297 DO ii = 1, no_func
298
299 func_id = func_ids(ii)
300 IF (ii > 1) THEN
301 IF (func_id == func_ids(ii - 1)) cycle
302 END IF
303 CALL xc_f03_func_init(xc_func, func_id, xc_unpolarized)
304 xc_info = xc_f03_func_get_info(xc_func)
305
306 func_name = xc_f03_functional_get_name(func_id)
307 description = xc_f03_func_info_get_name(xc_info)
308 n_param = xc_f03_func_info_get_n_ext_params(xc_info)
309
310 NULLIFY (subsection)
311 CALL section_create(subsection, __location__, name=trim(func_name), description=trim(description), &
312 n_keywords=2 + n_param, n_subsections=0, repeats=.false.)
313
314 IF (description(1:1) == "_") THEN
315 warning = " This parameter is an internal parameter of the functional. Changing this "// &
316 "parameter effectively changes the functional."
317 ELSE
318 warning = " "
319 END IF
320
321 NULLIFY (keyword)
322 CALL keyword_create(keyword, __location__, name="_SECTION_PARAMETERS_", &
323 description="Activates the functional."//trim(warning), &
324 lone_keyword_l_val=.true., default_l_val=.false.)
325 CALL section_add_keyword(subsection, keyword)
326 CALL keyword_release(keyword)
327
328 CALL keyword_create(keyword, __location__, name="SCALE", description="Scales this functional", &
329 default_r_val=1.0_dp)
330 CALL section_add_keyword(subsection, keyword)
331 CALL keyword_release(keyword)
332
333 DO iparam = 1, n_param
334 param_name = xc_f03_func_info_get_ext_params_name(xc_info, iparam - 1)
335 param_descr = xc_f03_func_info_get_ext_params_description(xc_info, iparam - 1)
336 default_val = xc_f03_func_info_get_ext_params_default_value(xc_info, iparam - 1)
337 NULLIFY (keyword)
338 CALL keyword_create(keyword, __location__, name=trim(param_name), &
339 description=trim(param_descr), default_r_val=default_val)
340 CALL section_add_keyword(subsection, keyword)
341 CALL keyword_release(keyword)
342 END DO
343
344 CALL section_add_subsection(section, subsection)
345 CALL section_release(subsection)
346
347 CALL xc_f03_func_end(xc_func)
348
349 END DO
350
351 DEALLOCATE (func_ids)
352
353 CALL timestop(handle)
354#else
355 mark_used(section)
356
357#endif
358
359 END SUBROUTINE libxc_add_sections
360
361! **************************************************************************************************
362!> \brief info about the functional from libxc
363!> \param libxc_params input parameter (functional name, scaling and parameters)
364!> \param reference string with the reference of the actual functional
365!> \param shortform string with the shortform of the functional name
366!> \param needs the components needed by this functional are set to
367!> true (does not set the unneeded components to false)
368!> \param max_deriv maximum implemented derivative of the xc functional
369!> \param print_warn whether to print warning about development status of a functional
370!> \param func_name_override optional LibXC functional name overriding the section name
371!> \author F. Tran
372! **************************************************************************************************
373 SUBROUTINE libxc_spin_unpolarized_info(libxc_params, reference, shortform, needs, max_deriv, print_warn, &
374 func_name_override)
375
376 TYPE(section_vals_type), POINTER :: libxc_params
377 CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: reference, shortform
378 TYPE(xc_rho_cflags_type), &
379 INTENT(inout), OPTIONAL :: needs
380 INTEGER, INTENT(out), OPTIONAL :: max_deriv
381 LOGICAL, INTENT(IN), OPTIONAL :: print_warn
382 CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: func_name_override
383
384#if defined (__LIBXC)
385 CHARACTER(LEN=128) :: s1, s2
386 CHARACTER(LEN=default_string_length) :: func_name
387 INTEGER :: func_id
388 REAL(kind=dp) :: func_scale
389 TYPE(xc_f03_func_t) :: xc_func
390 TYPE(xc_f03_func_info_t) :: xc_info
391
392 IF (PRESENT(func_name_override)) THEN
393 func_name = func_name_override
394 func_scale = 1.0_dp
395 ELSE
396 func_name = libxc_params%section%name
397 CALL section_vals_val_get(libxc_params, "scale", r_val=func_scale)
398 END IF
399
400 CALL cite_reference(marques2012)
401 CALL cite_reference(lehtola2018)
402
403 IF (abs(func_scale - 1.0_dp) < 1.0e-10_dp) func_scale = 1.0_dp
404
405 func_id = xc_libxc_wrap_functional_get_number(func_name)
406 CALL xc_f03_func_init(xc_func, func_id, xc_unpolarized)
407 xc_info = xc_f03_func_get_info(xc_func)
408
409 s1 = xc_f03_func_info_get_name(xc_info)
410 SELECT CASE (xc_f03_func_info_get_kind(xc_info))
411 CASE (xc_exchange); WRITE (s2, '(a)') "exchange"
412 CASE (xc_correlation); WRITE (s2, '(a)') "correlation"
413 CASE (xc_exchange_correlation); WRITE (s2, '(a)') "exchange-correlation"
414 CASE (xc_kinetic); WRITE (s2, '(a)') "kinetic"
415 CASE default
416 cpabort(trim(func_name)//": this XC_KIND is currently not supported.")
417 END SELECT
418 IF (PRESENT(shortform)) THEN
419 shortform = trim(s1)//' ('//trim(s2)//')'
420 END IF
421 IF (PRESENT(reference)) THEN
422 CALL xc_libxc_wrap_info_refs(xc_info, xc_unpolarized, func_scale, reference)
423 END IF
424 IF (PRESENT(needs)) THEN
425 SELECT CASE (xc_f03_func_info_get_family(xc_info))
426 CASE (xc_family_lda, xc_family_hyb_lda)
427 needs%rho = .true.
428 CASE (xc_family_gga, xc_family_hyb_gga)
429 needs%rho = .true.
430 needs%norm_drho = .true.
431 CASE (xc_family_mgga, xc_family_hyb_mgga)
432 needs%rho = .true.
433 needs%norm_drho = .true.
434 needs%tau = .true.
435 needs%laplace_rho = xc_libxc_wrap_info_needs_laplace(xc_info)
436 CASE default
437 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
438 END SELECT
439 END IF
440 IF (PRESENT(max_deriv)) THEN
441 SELECT CASE (xc_f03_func_info_get_family(xc_info))
442 CASE (xc_family_lda, xc_family_hyb_lda)
443 max_deriv = 3
444 CASE (xc_family_gga, xc_family_hyb_gga)
445 max_deriv = 2
446 CASE (xc_family_mgga, xc_family_hyb_mgga)
447 max_deriv = 2
448 CASE default
449 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
450 END SELECT
451 END IF
452 IF (PRESENT(print_warn)) THEN
453 IF (print_warn .AND. xc_libxc_wrap_is_under_development(xc_info)) THEN
454 cpwarn(trim(func_name)//" is under development. Use with caution.")
455 END IF
456 END IF
457
458 CALL xc_f03_func_end(xc_func)
459#else
460 mark_used(libxc_params)
461 mark_used(reference)
462 mark_used(shortform)
463 mark_used(needs)
464 mark_used(max_deriv)
465 mark_used(print_warn)
466 mark_used(func_name_override)
467
468 CALL cp_abort(__location__, "Unknown functional! If you are asking "// &
469 "for a functional of the LibXC library, "// &
470 "you have to download and install the library!")
471#endif
472
473 END SUBROUTINE libxc_spin_unpolarized_info
474
475! **************************************************************************************************
476!> \brief info about the functional from libxc
477!> \param libxc_params input parameter (functional name, scaling and parameters)
478!> \param reference string with the reference of the actual functional
479!> \param shortform string with the shortform of the functional name
480!> \param needs the components needed by this functional are set to
481!> true (does not set the unneeded components to false)
482!> \param max_deriv maximum implemented derivative of the xc functional
483!> \param print_warn whether to print warning about development status of a functional
484!> \param func_name_override optional LibXC functional name overriding the section name
485!> \author F. Tran
486! **************************************************************************************************
487 SUBROUTINE libxc_spin_polarized_info(libxc_params, reference, shortform, needs, max_deriv, print_warn, &
488 func_name_override)
489
490 TYPE(section_vals_type), POINTER :: libxc_params
491 CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: reference, shortform
492 TYPE(xc_rho_cflags_type), &
493 INTENT(inout), OPTIONAL :: needs
494 INTEGER, INTENT(out), OPTIONAL :: max_deriv
495 LOGICAL, INTENT(IN), OPTIONAL :: print_warn
496 CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: func_name_override
497
498#if defined (__LIBXC)
499 CHARACTER(LEN=128) :: s1, s2
500 CHARACTER(LEN=default_string_length) :: func_name
501 INTEGER :: func_id
502 REAL(kind=dp) :: func_scale
503 TYPE(xc_f03_func_t) :: xc_func
504 TYPE(xc_f03_func_info_t) :: xc_info
505
506 IF (PRESENT(func_name_override)) THEN
507 func_name = func_name_override
508 func_scale = 1.0_dp
509 ELSE
510 func_name = libxc_params%section%name
511 CALL section_vals_val_get(libxc_params, "scale", r_val=func_scale)
512 END IF
513
514 CALL cite_reference(marques2012)
515 CALL cite_reference(lehtola2018)
516
517 IF (abs(func_scale - 1.0_dp) < 1.0e-10_dp) func_scale = 1.0_dp
518
519 func_id = xc_libxc_wrap_functional_get_number(func_name)
520 CALL xc_f03_func_init(xc_func, func_id, xc_polarized)
521 xc_info = xc_f03_func_get_info(xc_func)
522
523 s1 = xc_f03_func_info_get_name(xc_info)
524 SELECT CASE (xc_f03_func_info_get_kind(xc_info))
525 CASE (xc_exchange); WRITE (s2, '(a)') "exchange"
526 CASE (xc_correlation); WRITE (s2, '(a)') "correlation"
527 CASE (xc_exchange_correlation); WRITE (s2, '(a)') "exchange-correlation"
528 CASE (xc_kinetic); WRITE (s2, '(a)') "kinetic"
529 CASE default
530 cpabort(trim(func_name)//": this XC_KIND is currently not supported.")
531 END SELECT
532 IF (PRESENT(shortform)) THEN
533 shortform = trim(s1)//' ('//trim(s2)//')'
534 END IF
535 IF (PRESENT(reference)) THEN
536 CALL xc_libxc_wrap_info_refs(xc_info, xc_polarized, func_scale, reference)
537 END IF
538 IF (PRESENT(needs)) THEN
539 SELECT CASE (xc_f03_func_info_get_family(xc_info))
540 CASE (xc_family_lda, xc_family_hyb_lda)
541 needs%rho_spin = .true.
542 CASE (xc_family_gga, xc_family_hyb_gga)
543 needs%rho_spin = .true.
544 needs%norm_drho = .true.
545 needs%norm_drho_spin = .true.
546 CASE (xc_family_mgga, xc_family_hyb_mgga)
547 needs%rho_spin = .true.
548 needs%norm_drho = .true.
549 needs%norm_drho_spin = .true.
550 needs%tau_spin = .true.
551 needs%laplace_rho_spin = xc_libxc_wrap_info_needs_laplace(xc_info)
552 CASE default
553 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
554 END SELECT
555 END IF
556 IF (PRESENT(max_deriv)) THEN
557 SELECT CASE (xc_f03_func_info_get_family(xc_info))
558 CASE (xc_family_lda, xc_family_hyb_lda)
559 max_deriv = 3
560 CASE (xc_family_gga, xc_family_hyb_gga)
561 max_deriv = 2
562 CASE (xc_family_mgga, xc_family_hyb_mgga)
563 max_deriv = 2
564 CASE default
565 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
566 END SELECT
567 END IF
568 IF (PRESENT(print_warn)) THEN
569 IF (print_warn .AND. xc_libxc_wrap_is_under_development(xc_info)) THEN
570 cpwarn(trim(func_name)//" is under development. Use with caution.")
571 END IF
572 END IF
573
574 CALL xc_f03_func_end(xc_func)
575#else
576 mark_used(libxc_params)
577 mark_used(reference)
578 mark_used(shortform)
579 mark_used(needs)
580 mark_used(max_deriv)
581 mark_used(print_warn)
582 mark_used(func_name_override)
583
584 CALL cp_abort(__location__, "Unknown functional! If you are "// &
585 "asking for a functional of the LibXC library, "// &
586 "you have to download and install the library!")
587#endif
588
589 END SUBROUTINE libxc_spin_polarized_info
590
591! **************************************************************************************************
592!> \brief info about the LibXC version
593!> \param version version string reported by the library at run time
594!> \param compiled_version version of the LibXC headers CP2K was compiled against
595!> \author A. Gloess (agloess)
596! **************************************************************************************************
597 SUBROUTINE libxc_version_info(version, compiled_version)
598 CHARACTER(LEN=*), INTENT(OUT) :: version ! the string that is output
599 CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: compiled_version
600
601#if defined (__LIBXC)
602 CALL xc_libxc_wrap_version(version, compiled_version)
603#else
604 version = "none"
605 IF (PRESENT(compiled_version)) compiled_version = "none"
606 cpabort("In order to use libxc you need to download and install it")
607#endif
608
609 END SUBROUTINE libxc_version_info
610
611! **************************************************************************************************
612!> \brief Returns the citation LibXC asks for the library itself.
613!> \param reference bibliographic reference
614!> \param doi digital object identifier of that reference
615!> \author S. Lehtola
616! **************************************************************************************************
617 SUBROUTINE libxc_library_reference(reference, doi)
618 CHARACTER(LEN=*), INTENT(OUT) :: reference, doi
619
620#if defined (__LIBXC)
621 CALL xc_libxc_wrap_library_reference(reference, doi)
622#else
623 reference = "none"
624 doi = "none"
625 cpabort("In order to use libxc you need to download and install it")
626#endif
627
628 END SUBROUTINE libxc_library_reference
629
630! **************************************************************************************************
631!> \brief Reads the external parameters of a LibXC functional from its input section.
632!> \param libxc_params LibXC input section
633!> \param param_names names of the external parameters, as reported by LibXC
634!> \param params values read from the input
635!> \author S. Lehtola
636! **************************************************************************************************
637#if defined (__LIBXC)
638 SUBROUTINE libxc_read_params(libxc_params, param_names, params)
639 TYPE(section_vals_type), INTENT(IN), POINTER :: libxc_params
640 CHARACTER(LEN=128), DIMENSION(:), INTENT(IN) :: param_names
641 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: params
642
643 INTEGER :: i
644
645 DO i = 1, SIZE(param_names)
646 CALL section_vals_val_get(libxc_params, trim(param_names(i)), r_val=params(i))
647 END DO
648
649 END SUBROUTINE libxc_read_params
650
651! **************************************************************************************************
652!> \brief Allocates the staging buffers of a single worker.
653!> \param worker the worker
654!> \param family LibXC functional family
655!> \param nspin XC_UNPOLARIZED or XC_POLARIZED
656!> \author S. Lehtola
657!> \note The buffers follow LibXC's own layout, i.e. the leading dimension is the
658!> number of components of the quantity and the points run along the second
659!> dimension. They are allocated once per worker and reused for every batch.
660! **************************************************************************************************
661 SUBROUTINE libxc_worker_alloc(worker, family, nspin)
662 TYPE(libxc_worker_type), INTENT(INOUT) :: worker
663 INTEGER, INTENT(IN) :: family, nspin
664
665 INTEGER :: nb, nl, np, ns
666
667 nb = libxc_block_size
668 ! number of components per point, cf. the LibXC manual
669 IF (nspin == xc_polarized) THEN
670 np = 2 ! rho, vrho, lapl, tau, vlapl, vtau
671 ns = 3 ! sigma, vsigma, v2rho2, v2lapl2, v2tau2
672 nl = 4 ! v2rholapl, v2rhotau, v2lapltau, v3rho3
673 ELSE
674 np = 1
675 ns = 1
676 nl = 1
677 END IF
678
679 ALLOCATE (worker%rho(np, nb))
680 ALLOCATE (worker%exc(nb))
681 ALLOCATE (worker%vrho(np, nb))
682 ALLOCATE (worker%v2rho2(ns, nb))
683 ALLOCATE (worker%v3rho3(nl, nb))
684
685 SELECT CASE (family)
686 CASE (xc_family_gga, xc_family_hyb_gga, xc_family_mgga, xc_family_hyb_mgga)
687 ALLOCATE (worker%sigma(ns, nb))
688 ALLOCATE (worker%vsigma(ns, nb))
689 IF (nspin == xc_polarized) THEN
690 ALLOCATE (worker%nd(nb), worker%nda(nb), worker%ndb(nb))
691 END IF
692 ALLOCATE (worker%v2rhosigma(merge(6, 1, nspin == xc_polarized), nb))
693 ALLOCATE (worker%v2sigma2(merge(6, 1, nspin == xc_polarized), nb))
694 END SELECT
695
696 SELECT CASE (family)
697 CASE (xc_family_mgga, xc_family_hyb_mgga)
698 ALLOCATE (worker%lapl(np, nb))
699 ALLOCATE (worker%tau(np, nb))
700 ALLOCATE (worker%vlapl(np, nb))
701 ALLOCATE (worker%vtau(np, nb))
702 ALLOCATE (worker%v2rholapl(nl, nb))
703 ALLOCATE (worker%v2rhotau(nl, nb))
704 ALLOCATE (worker%v2sigmalapl(merge(6, 1, nspin == xc_polarized), nb))
705 ALLOCATE (worker%v2sigmatau(merge(6, 1, nspin == xc_polarized), nb))
706 ALLOCATE (worker%v2lapl2(ns, nb))
707 ALLOCATE (worker%v2lapltau(nl, nb))
708 ALLOCATE (worker%v2tau2(ns, nb))
709 ! LibXC leaves vlapl untouched for functionals that do not use the
710 ! Laplacian, and CP2K then ignores it; zero it once so it never holds
711 ! uninitialized memory.
712 worker%vlapl = 0.0_dp
713 END SELECT
714
715 END SUBROUTINE libxc_worker_alloc
716
717! **************************************************************************************************
718!> \brief Makes sure the placeholder for unproduced derivatives holds npoints values.
719!> \param npoints number of grid points in this evaluation
720!> \author S. Lehtola
721! **************************************************************************************************
722 SUBROUTINE libxc_reserve_unused(npoints)
723 INTEGER, INTENT(IN) :: npoints
724
725 IF (ALLOCATED(libxc_unused)) THEN
726 IF (SIZE(libxc_unused) >= npoints) RETURN
727 DEALLOCATE (libxc_unused)
728 END IF
729 ALLOCATE (libxc_unused(npoints))
730
731 END SUBROUTINE libxc_reserve_unused
732
733! **************************************************************************************************
734!> \brief Returns the cache slot holding the per-thread workers for a functional.
735!> \param func_name LibXC functional name
736!> \param nspin XC_UNPOLARIZED or XC_POLARIZED
737!> \param libxc_params LibXC input section, or null when no parameters are to be set
738!> \param epsilon_rho density cutoff
739!> \param epsilon_tau kinetic energy density cutoff
740!> \return index into libxc_cache
741!> \author S. Lehtola
742!> \note Must be called from a serial region: it is the only writer of the cache,
743!> and keeping it serial is what makes the cache lock-free. The workers it
744!> returns are then used concurrently, one per thread.
745! **************************************************************************************************
746 FUNCTION libxc_get_workers(func_name, nspin, libxc_params, epsilon_rho, epsilon_tau) RESULT(idx)
747 CHARACTER(LEN=*), INTENT(IN) :: func_name
748 INTEGER, INTENT(IN) :: nspin
749 TYPE(section_vals_type), INTENT(IN), POINTER :: libxc_params
750 REAL(kind=dp), INTENT(IN) :: epsilon_rho, epsilon_tau
751 INTEGER :: idx
752
753 CHARACTER(LEN=*), PARAMETER :: routinen = 'libxc_get_workers'
754
755 INTEGER :: func_id, handle, i, ithread, n_params, &
756 nthreads
757 LOGICAL :: has_params
758 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: params
759 TYPE(libxc_worker_set_type), ALLOCATABLE, &
760 DIMENSION(:) :: tmp_cache
761
762 CALL timeset(routinen, handle)
763
764 func_id = xc_libxc_wrap_functional_get_number(func_name)
765 has_params = ASSOCIATED(libxc_params)
766
767 nthreads = 1
768!$ nthreads = omp_get_max_threads()
769
770 IF (.NOT. ALLOCATED(libxc_cache)) ALLOCATE (libxc_cache(0))
771
772 idx = 0
773 DO i = 1, SIZE(libxc_cache)
774 IF (libxc_cache(i)%func_id == func_id .AND. &
775 libxc_cache(i)%nspin == nspin .AND. &
776 (libxc_cache(i)%has_params .EQV. has_params)) THEN
777 IF (libxc_cache(i)%epsilon_rho == epsilon_rho .AND. &
778 libxc_cache(i)%epsilon_tau == epsilon_tau .AND. &
779 SIZE(libxc_cache(i)%worker) >= nthreads) THEN
780 idx = i
781 EXIT
782 END IF
783 END IF
784 END DO
785
786 IF (idx == 0) THEN
787 ! Grow the cache by one slot and build the workers for it.
788 CALL move_alloc(libxc_cache, tmp_cache)
789 ALLOCATE (libxc_cache(SIZE(tmp_cache) + 1))
790 DO i = 1, SIZE(tmp_cache)
791 CALL libxc_move_worker_set(tmp_cache(i), libxc_cache(i))
792 END DO
793 DEALLOCATE (tmp_cache)
794 idx = SIZE(libxc_cache)
795
796 associate(ws => libxc_cache(idx))
797 ws%func_id = func_id
798 ws%nspin = nspin
799 ws%has_params = has_params
800 ws%epsilon_rho = epsilon_rho
801 ws%epsilon_tau = epsilon_tau
802 ALLOCATE (ws%worker(nthreads))
803
804 DO ithread = 1, nthreads
805 CALL xc_f03_func_init(ws%worker(ithread)%func, func_id, nspin)
806 ws%worker(ithread)%info = xc_f03_func_get_info(ws%worker(ithread)%func)
807 ws%worker(ithread)%is_init = .true.
808 END DO
809
810 ws%family = xc_f03_func_info_get_family(ws%worker(1)%info)
811 ws%has_laplace = xc_libxc_wrap_info_needs_laplace(ws%worker(1)%info)
812 ws%no_exc = xc_libxc_wrap_info_no_exc(ws%worker(1)%info)
813
814 ! Remember the parameter names so that later evaluations can re-read
815 ! the input without another functional object to ask for them.
816 n_params = 0
817 IF (has_params) n_params = xc_f03_func_info_get_n_ext_params(ws%worker(1)%info)
818 ALLOCATE (ws%params(n_params))
819 ALLOCATE (ws%param_names(n_params))
820 DO i = 1, n_params
821 ws%param_names(i) = xc_f03_func_info_get_ext_params_name(ws%worker(1)%info, i - 1)
822 END DO
823 IF (n_params > 0) THEN
824 CALL libxc_read_params(libxc_params, ws%param_names, ws%params)
825 DO ithread = 1, nthreads
826 CALL xc_f03_func_set_ext_params(ws%worker(ithread)%func, ws%params)
827 END DO
828 END IF
829
830 DO ithread = 1, nthreads
831 CALL xc_libxc_wrap_set_thresholds(ws%worker(ithread)%func, ws%worker(ithread)%info, &
832 epsilon_rho, epsilon_tau)
833 CALL libxc_worker_alloc(ws%worker(ithread), ws%family, nspin)
834 END DO
835 END associate
836 ELSE
837 ! Cached slot: the input section may in principle carry different
838 ! parameter values than the ones the workers were last set up with, so
839 ! re-read them and push them through only when they actually changed.
840 associate(ws => libxc_cache(idx))
841 n_params = SIZE(ws%params)
842 IF (n_params > 0) THEN
843 ALLOCATE (params(n_params))
844 CALL libxc_read_params(libxc_params, ws%param_names, params)
845 IF (any(params /= ws%params)) THEN
846 ws%params(:) = params(:)
847 DO ithread = 1, SIZE(ws%worker)
848 CALL xc_f03_func_set_ext_params(ws%worker(ithread)%func, ws%params)
849 ! re-assert the cutoffs: setting parameters runs the
850 ! functional's own callback, which is free to rebuild the
851 ! component functionals a mixed functional is made of
852 CALL xc_libxc_wrap_set_thresholds(ws%worker(ithread)%func, &
853 ws%worker(ithread)%info, &
854 ws%epsilon_rho, ws%epsilon_tau)
855 END DO
856 END IF
857 DEALLOCATE (params)
858 END IF
859 END associate
860 END IF
861
862 CALL timestop(handle)
863
864 END FUNCTION libxc_get_workers
865
866! **************************************************************************************************
867!> \brief Moves a worker set to a new cache slot without touching LibXC.
868!> \param from source slot, left empty
869!> \param to destination slot
870!> \author S. Lehtola
871!> \note Used when the cache array grows. The LibXC objects are opaque handles, so
872!> they survive being moved; only the Fortran allocatables need transferring.
873! **************************************************************************************************
874 SUBROUTINE libxc_move_worker_set(from, to)
875 TYPE(libxc_worker_set_type), INTENT(INOUT) :: from, to
876
877 to%func_id = from%func_id
878 to%nspin = from%nspin
879 to%family = from%family
880 to%has_laplace = from%has_laplace
881 to%no_exc = from%no_exc
882 to%has_params = from%has_params
883 to%epsilon_rho = from%epsilon_rho
884 to%epsilon_tau = from%epsilon_tau
885 IF (ALLOCATED(from%params)) CALL move_alloc(from%params, to%params)
886 IF (ALLOCATED(from%param_names)) CALL move_alloc(from%param_names, to%param_names)
887 IF (ALLOCATED(from%worker)) CALL move_alloc(from%worker, to%worker)
888
889 END SUBROUTINE libxc_move_worker_set
890#endif
891
892! **************************************************************************************************
893!> \brief Destroys all cached LibXC functional objects.
894!> \author S. Lehtola
895!> \note Call once at the end of a run. The workers are deliberately kept alive
896!> across SCF steps and across calculations, so nothing else releases them.
897! **************************************************************************************************
899
900#if defined (__LIBXC)
901 INTEGER :: i, ithread
902
903 IF (.NOT. ALLOCATED(libxc_cache)) RETURN
904
905 DO i = 1, SIZE(libxc_cache)
906 IF (.NOT. ALLOCATED(libxc_cache(i)%worker)) cycle
907 DO ithread = 1, SIZE(libxc_cache(i)%worker)
908 IF (libxc_cache(i)%worker(ithread)%is_init) THEN
909 CALL xc_f03_func_end(libxc_cache(i)%worker(ithread)%func)
910 libxc_cache(i)%worker(ithread)%is_init = .false.
911 END IF
912 END DO
913 END DO
914 DEALLOCATE (libxc_cache)
915 IF (ALLOCATED(libxc_unused)) DEALLOCATE (libxc_unused)
916#endif
917
918 END SUBROUTINE libxc_release_workers
919
920! **************************************************************************************************
921!> \brief evaluates the functional from libxc
922!> \param rho_set the density where you want to evaluate the functional
923!> \param deriv_set place where to store the functional derivatives (they are
924!> added to the derivatives)
925!> \param grad_deriv degree of the derivative that should be evaluated;
926!> all derivatives up to the given degree are evaluated, in a single
927!> LibXC call per block of grid points
928!> \param libxc_params input parameter (functional name, scaling and parameters)
929!> \param func_name_override optional LibXC functional name overriding the section name
930!> \author F. Tran
931! **************************************************************************************************
932 SUBROUTINE libxc_spin_unpolarized_eval(rho_set, deriv_set, grad_deriv, libxc_params, func_name_override)
933
934 TYPE(xc_rho_set_type), INTENT(IN) :: rho_set
935 TYPE(xc_derivative_set_type), INTENT(IN) :: deriv_set
936 INTEGER, INTENT(in) :: grad_deriv
937 TYPE(section_vals_type), POINTER :: libxc_params
938 CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: func_name_override
939
940#if defined (__LIBXC)
941 CHARACTER(len=*), PARAMETER :: routinen = 'libxc_spin_unpolarized_eval'
942
943 CHARACTER(LEN=default_string_length) :: func_name
944 INTEGER :: handle, iw, npoints
945 INTEGER, DIMENSION(2, 3) :: bo
946 LOGICAL :: has_laplace
947 REAL(kind=dp) :: epsilon_rho, epsilon_tau, func_scale
948 TYPE(libxc_worker_set_type), POINTER :: workers
949 TYPE(section_vals_type), POINTER :: no_params
950 REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :, :), POINTER :: dummy, e_0, e_laplace_rho, &
951 e_laplace_rho_laplace_rho, e_laplace_rho_tau, e_ndrho, &
952 e_ndrho_laplace_rho, e_ndrho_ndrho, e_ndrho_rho, e_ndrho_tau, e_rho, &
953 e_rho_laplace_rho, e_rho_rho, e_rho_rho_rho, e_rho_tau, e_tau, &
954 e_tau_tau, laplace_rho, norm_drho, rho, tau
955 TYPE(xc_derivative_type), POINTER :: deriv
956 TYPE(xc_f03_func_info_t) :: xc_info
957
958 CALL timeset(routinen, handle)
959
960 ! Only "everything up to grad_deriv" is supported. Asking for a single
961 ! derivative order in isolation is rejected here rather than further down,
962 ! where it would quietly evaluate nothing at all.
963 IF (grad_deriv < 0) THEN
964 cpabort("Evaluating a single derivative order is not supported.")
965 END IF
966 IF (grad_deriv > 3) THEN
967 cpabort("derivatives larger than 3 not implemented")
968 END IF
969
970 has_laplace = .false.
971 NULLIFY (dummy)
972 NULLIFY (workers)
973 NULLIFY (rho, norm_drho, laplace_rho, tau)
974
975 IF (PRESENT(func_name_override)) THEN
976 func_name = func_name_override
977 func_scale = 1.0_dp
978 ELSE
979 func_name = libxc_params%section%name
980 CALL section_vals_val_get(libxc_params, "scale", r_val=func_scale)
981 END IF
982
983 IF (abs(func_scale - 1.0_dp) < 1.0e-10_dp) func_scale = 1.0_dp
984
985 CALL xc_rho_set_get(rho_set, can_return_null=.true., &
986 rho=rho, norm_drho=norm_drho, laplace_rho=laplace_rho, &
987 rho_cutoff=epsilon_rho, tau_cutoff=epsilon_tau, &
988 tau=tau, local_bounds=bo)
989
990 npoints = (bo(2, 1) - bo(1, 1) + 1)*(bo(2, 2) - bo(1, 2) + 1)*(bo(2, 3) - bo(1, 3) + 1)
991
992 ! One functional object per thread, kept across calls. The cutoffs are part
993 ! of the worker setup because LibXC does the screening itself.
994 IF (PRESENT(func_name_override)) THEN
995 ! an overriding name carries no input section, so no parameters are set
996 NULLIFY (no_params)
997 iw = libxc_get_workers(func_name, xc_unpolarized, no_params, epsilon_rho, epsilon_tau)
998 ELSE
999 iw = libxc_get_workers(func_name, xc_unpolarized, libxc_params, epsilon_rho, epsilon_tau)
1000 END IF
1001 workers => libxc_cache(iw)
1002 xc_info = workers%worker(1)%info
1003 has_laplace = workers%has_laplace
1004
1005 ! see libxc_unused: the arguments the requested order does not produce are
1006 ! never touched, but they still have to point somewhere
1007 CALL libxc_reserve_unused(npoints)
1008 dummy(bo(1, 1):bo(2, 1), bo(1, 2):bo(2, 2), bo(1, 3):bo(2, 3)) => libxc_unused(1:npoints)
1009
1010 ! due to assumed shape array usage in next routine
1011 IF (.NOT. ASSOCIATED(norm_drho)) norm_drho => rho
1012 IF (.NOT. ASSOCIATED(tau)) tau => rho
1013
1014 ! only some MGGA functionals really need the Laplacian,
1015 ! all others can work with rho (read-only) as dummy
1016 IF (.NOT. has_laplace) laplace_rho => rho
1017
1018 e_0 => dummy
1019 e_rho => dummy
1020 e_ndrho => dummy
1021 e_laplace_rho => dummy
1022 e_tau => dummy
1023 e_rho_rho => dummy
1024 e_ndrho_rho => dummy
1025 e_ndrho_ndrho => dummy
1026 e_rho_laplace_rho => dummy
1027 e_rho_tau => dummy
1028 e_ndrho_laplace_rho => dummy
1029 e_ndrho_tau => dummy
1030 e_laplace_rho_laplace_rho => dummy
1031 e_laplace_rho_tau => dummy
1032 e_tau_tau => dummy
1033 e_rho_rho_rho => dummy
1034
1035 IF (grad_deriv >= 0) THEN
1036 deriv => xc_dset_get_derivative(deriv_set, [INTEGER::], &
1037 allocate_deriv=.true.)
1038 CALL xc_derivative_get(deriv, deriv_data=e_0)
1039 END IF
1040 IF (grad_deriv >= 1) THEN
1041 SELECT CASE (xc_f03_func_info_get_family(xc_info))
1042 CASE (xc_family_lda, xc_family_hyb_lda)
1043 deriv => xc_dset_get_derivative(deriv_set, [deriv_rho], &
1044 allocate_deriv=.true.)
1045 CALL xc_derivative_get(deriv, deriv_data=e_rho)
1046 CASE (xc_family_gga, xc_family_hyb_gga)
1047 deriv => xc_dset_get_derivative(deriv_set, [deriv_rho], &
1048 allocate_deriv=.true.)
1049 CALL xc_derivative_get(deriv, deriv_data=e_rho)
1050 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho], &
1051 allocate_deriv=.true.)
1052 CALL xc_derivative_get(deriv, deriv_data=e_ndrho)
1053 CASE (xc_family_mgga, xc_family_hyb_mgga)
1054 deriv => xc_dset_get_derivative(deriv_set, [deriv_rho], &
1055 allocate_deriv=.true.)
1056 CALL xc_derivative_get(deriv, deriv_data=e_rho)
1057 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho], &
1058 allocate_deriv=.true.)
1059 CALL xc_derivative_get(deriv, deriv_data=e_ndrho)
1060 deriv => xc_dset_get_derivative(deriv_set, [deriv_tau], &
1061 allocate_deriv=.true.)
1062 CALL xc_derivative_get(deriv, deriv_data=e_tau)
1063 IF (has_laplace) THEN
1064 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rho], &
1065 allocate_deriv=.true.)
1066 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rho)
1067 END IF
1068 CASE default
1069 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
1070 END SELECT
1071 END IF
1072 IF (grad_deriv >= 2) THEN
1073 SELECT CASE (xc_f03_func_info_get_family(xc_info))
1074 CASE (xc_family_lda, xc_family_hyb_lda)
1075 deriv => xc_dset_get_derivative(deriv_set, [deriv_rho, deriv_rho], &
1076 allocate_deriv=.true.)
1077 CALL xc_derivative_get(deriv, deriv_data=e_rho_rho)
1078 CASE (xc_family_gga, xc_family_hyb_gga)
1079 deriv => xc_dset_get_derivative(deriv_set, [deriv_rho, deriv_rho], &
1080 allocate_deriv=.true.)
1081 CALL xc_derivative_get(deriv, deriv_data=e_rho_rho)
1082 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_rho], &
1083 allocate_deriv=.true.)
1084 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_rho)
1085 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_norm_drho], &
1086 allocate_deriv=.true.)
1087 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrho)
1088 CASE (xc_family_mgga, xc_family_hyb_mgga)
1089 ! not implemented ...
1090
1091 deriv => xc_dset_get_derivative(deriv_set, [deriv_rho, deriv_rho], &
1092 allocate_deriv=.true.)
1093 CALL xc_derivative_get(deriv, deriv_data=e_rho_rho)
1094 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_rho], &
1095 allocate_deriv=.true.)
1096 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_rho)
1097 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_norm_drho], &
1098 allocate_deriv=.true.)
1099 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrho)
1100 deriv => xc_dset_get_derivative(deriv_set, [deriv_rho, deriv_tau], &
1101 allocate_deriv=.true.)
1102 CALL xc_derivative_get(deriv, deriv_data=e_rho_tau)
1103 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_tau], &
1104 allocate_deriv=.true.)
1105 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_tau)
1106 deriv => xc_dset_get_derivative(deriv_set, [deriv_tau, deriv_tau], &
1107 allocate_deriv=.true.)
1108 CALL xc_derivative_get(deriv, deriv_data=e_tau_tau)
1109 IF (has_laplace) THEN
1110 deriv => xc_dset_get_derivative(deriv_set, [deriv_rho, deriv_laplace_rho], &
1111 allocate_deriv=.true.)
1112 CALL xc_derivative_get(deriv, deriv_data=e_rho_laplace_rho)
1113 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_laplace_rho], &
1114 allocate_deriv=.true.)
1115 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_laplace_rho)
1116 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rho, deriv_laplace_rho], &
1117 allocate_deriv=.true.)
1118 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rho_laplace_rho)
1119 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rho, deriv_tau], &
1120 allocate_deriv=.true.)
1121 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rho_tau)
1122 END IF
1123 CASE default
1124 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
1125 END SELECT
1126 END IF
1127 IF (grad_deriv >= 3) THEN
1128 SELECT CASE (xc_f03_func_info_get_family(xc_info))
1129 CASE (xc_family_lda, xc_family_hyb_lda)
1130 deriv => xc_dset_get_derivative(deriv_set, [deriv_rho, deriv_rho, deriv_rho], &
1131 allocate_deriv=.true.)
1132 CALL xc_derivative_get(deriv, deriv_data=e_rho_rho_rho)
1133 CASE (xc_family_gga, xc_family_hyb_gga, xc_family_mgga, xc_family_hyb_mgga)
1134 cpabort("derivatives larger than 2 not implemented")
1135 CASE default
1136 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
1137 END SELECT
1138 END IF
1139
1140!$OMP PARALLEL DEFAULT(NONE), &
1141!$OMP SHARED(rho,norm_drho,laplace_rho,tau,e_0,e_rho,e_ndrho,e_laplace_rho),&
1142!$OMP SHARED(e_tau,e_rho_rho,e_ndrho_rho,e_ndrho_ndrho,e_rho_laplace_rho),&
1143!$OMP SHARED(e_rho_tau,e_ndrho_laplace_rho,e_ndrho_tau,e_laplace_rho_laplace_rho),&
1144!$OMP SHARED(e_laplace_rho_tau,e_tau_tau,e_rho_rho_rho),&
1145!$OMP SHARED(grad_deriv,npoints),&
1146!$OMP SHARED(func_name,func_scale,workers)
1147
1148 CALL libxc_spin_unpolarized_calc(rho=rho, norm_drho=norm_drho, &
1149 laplace_rho=laplace_rho, tau=tau, &
1150 e_0=e_0, e_rho=e_rho, e_ndrho=e_ndrho, e_laplace_rho=e_laplace_rho, &
1151 e_tau=e_tau, e_rho_rho=e_rho_rho, e_ndrho_rho=e_ndrho_rho, &
1152 e_ndrho_ndrho=e_ndrho_ndrho, e_rho_laplace_rho=e_rho_laplace_rho, &
1153 e_rho_tau=e_rho_tau, e_ndrho_laplace_rho=e_ndrho_laplace_rho, &
1154 e_ndrho_tau=e_ndrho_tau, e_laplace_rho_laplace_rho=e_laplace_rho_laplace_rho, &
1155 e_laplace_rho_tau=e_laplace_rho_tau, e_tau_tau=e_tau_tau, &
1156 e_rho_rho_rho=e_rho_rho_rho, &
1157 grad_deriv=grad_deriv, npoints=npoints, &
1158 func_name=func_name, sc=func_scale, workers=workers)
1159
1160!$OMP END PARALLEL
1161
1162 NULLIFY (dummy)
1163 NULLIFY (workers)
1164
1165 CALL timestop(handle)
1166#else
1167 mark_used(rho_set)
1168 mark_used(deriv_set)
1169 mark_used(grad_deriv)
1170 mark_used(libxc_params)
1171 mark_used(func_name_override)
1172 CALL cp_abort(__location__, "Unknown functional! If you are asking "// &
1173 "for a functional of the LibXC library, "// &
1174 "you have to download and install the library!")
1175#endif
1176 END SUBROUTINE libxc_spin_unpolarized_eval
1177
1178! **************************************************************************************************
1179!> \brief evaluates the functional from libxc
1180!> \param rho_set the density where you want to evaluate the functional
1181!> \param deriv_set place where to store the functional derivatives (they are
1182!> added to the derivatives)
1183!> \param grad_deriv degree of the derivative that should be evaluated;
1184!> all derivatives up to the given degree are evaluated, in a single
1185!> LibXC call per block of grid points
1186!> \param libxc_params input parameter (functional name, scaling and parameters)
1187!> \param func_name_override optional LibXC functional name overriding the section name
1188!> \author F. Tran
1189! **************************************************************************************************
1190 SUBROUTINE libxc_spin_polarized_eval(rho_set, deriv_set, grad_deriv, libxc_params, func_name_override)
1191
1192 TYPE(xc_rho_set_type), INTENT(IN) :: rho_set
1193 TYPE(xc_derivative_set_type), INTENT(IN) :: deriv_set
1194 INTEGER, INTENT(in) :: grad_deriv
1195 TYPE(section_vals_type), POINTER :: libxc_params
1196 CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: func_name_override
1197
1198#if defined (__LIBXC)
1199 CHARACTER(len=*), PARAMETER :: routinen = 'libxc_spin_polarized_eval'
1200
1201 CHARACTER(LEN=default_string_length) :: func_name
1202 INTEGER :: handle, iw, npoints
1203 INTEGER, DIMENSION(2, 3) :: bo
1204 LOGICAL :: has_laplace
1205 REAL(kind=dp) :: epsilon_rho, epsilon_tau, func_scale
1206 TYPE(libxc_worker_set_type), POINTER :: workers
1207 TYPE(section_vals_type), POINTER :: no_params
1208 REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :, :), POINTER :: dummy, e_0, e_laplace_rhoa, &
1209 e_laplace_rhoa_laplace_rhoa, e_laplace_rhoa_laplace_rhob, &
1210 e_laplace_rhoa_tau_a, e_laplace_rhoa_tau_b, e_laplace_rhob, &
1211 e_laplace_rhob_laplace_rhob, e_laplace_rhob_tau_a, &
1212 e_laplace_rhob_tau_b, e_ndrho, e_ndrho_laplace_rhoa, &
1213 e_ndrho_laplace_rhob, e_ndrho_ndrho, e_ndrho_ndrhoa, e_ndrho_ndrhob, &
1214 e_ndrho_rhoa, e_ndrho_rhob, e_ndrho_tau_a, e_ndrho_tau_b, e_ndrhoa, &
1215 e_ndrhoa_laplace_rhoa, e_ndrhoa_laplace_rhob, e_ndrhoa_ndrhoa, &
1216 e_ndrhoa_ndrhob, e_ndrhoa_rhoa, e_ndrhoa_rhob, e_ndrhoa_tau_a, &
1217 e_ndrhoa_tau_b, e_ndrhob
1218 REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :, :), POINTER :: e_ndrhob_laplace_rhoa, &
1219 e_ndrhob_laplace_rhob, e_ndrhob_ndrhob, e_ndrhob_rhoa, e_ndrhob_rhob, &
1220 e_ndrhob_tau_a, e_ndrhob_tau_b, e_rhoa, e_rhoa_laplace_rhoa, &
1221 e_rhoa_laplace_rhob, e_rhoa_rhoa, e_rhoa_rhoa_rhoa, e_rhoa_rhoa_rhob, &
1222 e_rhoa_rhob, e_rhoa_rhob_rhob, e_rhoa_tau_a, e_rhoa_tau_b, e_rhob, &
1223 e_rhob_laplace_rhoa, e_rhob_laplace_rhob, e_rhob_rhob, &
1224 e_rhob_rhob_rhob, e_rhob_tau_a, e_rhob_tau_b, e_tau_a, e_tau_a_tau_a, &
1225 e_tau_a_tau_b, e_tau_b, e_tau_b_tau_b, laplace_rhoa, laplace_rhob, &
1226 norm_drho, norm_drhoa, norm_drhob, rhoa, rhob, tau_a, tau_b
1227 TYPE(xc_derivative_type), POINTER :: deriv
1228 TYPE(xc_f03_func_info_t) :: xc_info
1229
1230 CALL timeset(routinen, handle)
1231
1232 ! Only "everything up to grad_deriv" is supported. Asking for a single
1233 ! derivative order in isolation is rejected here rather than further down,
1234 ! where it would quietly evaluate nothing at all.
1235 IF (grad_deriv < 0) THEN
1236 cpabort("Evaluating a single derivative order is not supported.")
1237 END IF
1238 IF (grad_deriv > 3) THEN
1239 cpabort("derivatives larger than 3 not implemented")
1240 END IF
1241
1242 NULLIFY (dummy)
1243 NULLIFY (workers)
1244 NULLIFY (rhoa, rhob, norm_drho, norm_drhoa, norm_drhob, laplace_rhoa, &
1245 laplace_rhob, tau_a, tau_b)
1246
1247 IF (PRESENT(func_name_override)) THEN
1248 func_name = func_name_override
1249 func_scale = 1.0_dp
1250 ELSE
1251 func_name = libxc_params%section%name
1252 CALL section_vals_val_get(libxc_params, "scale", r_val=func_scale)
1253 END IF
1254
1255 IF (abs(func_scale - 1.0_dp) < 1.0e-10_dp) func_scale = 1.0_dp
1256
1257 CALL xc_rho_set_get(rho_set, can_return_null=.true., &
1258 rhoa=rhoa, rhob=rhob, norm_drho=norm_drho, &
1259 norm_drhoa=norm_drhoa, norm_drhob=norm_drhob, &
1260 laplace_rhoa=laplace_rhoa, laplace_rhob=laplace_rhob, &
1261 rho_cutoff=epsilon_rho, tau_cutoff=epsilon_tau, &
1262 tau_a=tau_a, tau_b=tau_b, local_bounds=bo)
1263
1264 npoints = (bo(2, 1) - bo(1, 1) + 1)*(bo(2, 2) - bo(1, 2) + 1)*(bo(2, 3) - bo(1, 3) + 1)
1265
1266 ! One functional object per thread, kept across calls. The cutoffs are part
1267 ! of the worker setup because LibXC does the screening itself.
1268 IF (PRESENT(func_name_override)) THEN
1269 ! an overriding name carries no input section, so no parameters are set
1270 NULLIFY (no_params)
1271 iw = libxc_get_workers(func_name, xc_polarized, no_params, epsilon_rho, epsilon_tau)
1272 ELSE
1273 iw = libxc_get_workers(func_name, xc_polarized, libxc_params, epsilon_rho, epsilon_tau)
1274 END IF
1275 workers => libxc_cache(iw)
1276 xc_info = workers%worker(1)%info
1277 has_laplace = workers%has_laplace
1278
1279 ! see libxc_unused: the arguments the requested order does not produce are
1280 ! never touched, but they still have to point somewhere
1281 CALL libxc_reserve_unused(npoints)
1282 dummy(bo(1, 1):bo(2, 1), bo(1, 2):bo(2, 2), bo(1, 3):bo(2, 3)) => libxc_unused(1:npoints)
1283
1284 ! due to assumed shape array usage in next routine
1285 IF (.NOT. ASSOCIATED(norm_drho)) norm_drho => rhoa
1286 IF (.NOT. ASSOCIATED(norm_drhoa)) norm_drhoa => rhoa
1287 IF (.NOT. ASSOCIATED(norm_drhob)) norm_drhob => rhoa
1288 IF (.NOT. ASSOCIATED(tau_a)) tau_a => rhoa
1289 IF (.NOT. ASSOCIATED(tau_b)) tau_b => rhoa
1290
1291 ! only some MGGA functionals really need the Laplacian,
1292 ! all others can work with rhoa (read-only) as dummy
1293 IF (.NOT. has_laplace) laplace_rhoa => rhoa
1294 IF (.NOT. has_laplace) laplace_rhob => rhoa
1295
1296 e_0 => dummy
1297 e_rhoa => dummy
1298 e_rhob => dummy
1299 e_ndrho => dummy
1300 e_ndrhoa => dummy
1301 e_ndrhob => dummy
1302 e_laplace_rhoa => dummy
1303 e_laplace_rhob => dummy
1304 e_tau_a => dummy
1305 e_tau_b => dummy
1306 e_rhoa_rhoa => dummy
1307 e_rhoa_rhob => dummy
1308 e_rhob_rhob => dummy
1309 e_ndrho_rhoa => dummy
1310 e_ndrho_rhob => dummy
1311 e_ndrhoa_rhoa => dummy
1312 e_ndrhoa_rhob => dummy
1313 e_ndrhob_rhoa => dummy
1314 e_ndrhob_rhob => dummy
1315 e_ndrho_ndrho => dummy
1316 e_ndrho_ndrhoa => dummy
1317 e_ndrho_ndrhob => dummy
1318 e_ndrhoa_ndrhoa => dummy
1319 e_ndrhoa_ndrhob => dummy
1320 e_ndrhob_ndrhob => dummy
1321 e_rhoa_laplace_rhoa => dummy
1322 e_rhoa_laplace_rhob => dummy
1323 e_rhob_laplace_rhoa => dummy
1324 e_rhob_laplace_rhob => dummy
1325 e_rhoa_tau_a => dummy
1326 e_rhoa_tau_b => dummy
1327 e_rhob_tau_a => dummy
1328 e_rhob_tau_b => dummy
1329 e_ndrho_laplace_rhoa => dummy
1330 e_ndrho_laplace_rhob => dummy
1331 e_ndrhoa_laplace_rhoa => dummy
1332 e_ndrhoa_laplace_rhob => dummy
1333 e_ndrhob_laplace_rhoa => dummy
1334 e_ndrhob_laplace_rhob => dummy
1335 e_ndrho_tau_a => dummy
1336 e_ndrho_tau_b => dummy
1337 e_ndrhoa_tau_a => dummy
1338 e_ndrhoa_tau_b => dummy
1339 e_ndrhob_tau_a => dummy
1340 e_ndrhob_tau_b => dummy
1341 e_laplace_rhoa_laplace_rhoa => dummy
1342 e_laplace_rhoa_laplace_rhob => dummy
1343 e_laplace_rhob_laplace_rhob => dummy
1344 e_laplace_rhoa_tau_a => dummy
1345 e_laplace_rhoa_tau_b => dummy
1346 e_laplace_rhob_tau_a => dummy
1347 e_laplace_rhob_tau_b => dummy
1348 e_tau_a_tau_a => dummy
1349 e_tau_a_tau_b => dummy
1350 e_tau_b_tau_b => dummy
1351 e_rhoa_rhoa_rhoa => dummy
1352 e_rhoa_rhoa_rhob => dummy
1353 e_rhoa_rhob_rhob => dummy
1354 e_rhob_rhob_rhob => dummy
1355
1356 IF (grad_deriv >= 0) THEN
1357 deriv => xc_dset_get_derivative(deriv_set, [INTEGER::], &
1358 allocate_deriv=.true.)
1359 CALL xc_derivative_get(deriv, deriv_data=e_0)
1360 END IF
1361 IF (grad_deriv >= 1) THEN
1362 SELECT CASE (xc_f03_func_info_get_family(xc_info))
1363 CASE (xc_family_lda, xc_family_hyb_lda)
1364 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa], &
1365 allocate_deriv=.true.)
1366 CALL xc_derivative_get(deriv, deriv_data=e_rhoa)
1367 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob], &
1368 allocate_deriv=.true.)
1369 CALL xc_derivative_get(deriv, deriv_data=e_rhob)
1370 CASE (xc_family_gga, xc_family_hyb_gga)
1371 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa], &
1372 allocate_deriv=.true.)
1373 CALL xc_derivative_get(deriv, deriv_data=e_rhoa)
1374 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob], &
1375 allocate_deriv=.true.)
1376 CALL xc_derivative_get(deriv, deriv_data=e_rhob)
1377 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho], &
1378 allocate_deriv=.true.)
1379 CALL xc_derivative_get(deriv, deriv_data=e_ndrho)
1380 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa], &
1381 allocate_deriv=.true.)
1382 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa)
1383 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob], &
1384 allocate_deriv=.true.)
1385 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob)
1386 CASE (xc_family_mgga, xc_family_hyb_mgga)
1387 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa], &
1388 allocate_deriv=.true.)
1389 CALL xc_derivative_get(deriv, deriv_data=e_rhoa)
1390 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob], &
1391 allocate_deriv=.true.)
1392 CALL xc_derivative_get(deriv, deriv_data=e_rhob)
1393 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho], &
1394 allocate_deriv=.true.)
1395 CALL xc_derivative_get(deriv, deriv_data=e_ndrho)
1396 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa], &
1397 allocate_deriv=.true.)
1398 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa)
1399 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob], &
1400 allocate_deriv=.true.)
1401 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob)
1402 deriv => xc_dset_get_derivative(deriv_set, [deriv_tau_a], &
1403 allocate_deriv=.true.)
1404 CALL xc_derivative_get(deriv, deriv_data=e_tau_a)
1405 deriv => xc_dset_get_derivative(deriv_set, [deriv_tau_b], &
1406 allocate_deriv=.true.)
1407 CALL xc_derivative_get(deriv, deriv_data=e_tau_b)
1408 IF (has_laplace) THEN
1409 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhoa], &
1410 allocate_deriv=.true.)
1411 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhoa)
1412 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhob], &
1413 allocate_deriv=.true.)
1414 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhob)
1415 END IF
1416 CASE default
1417 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
1418 END SELECT
1419 END IF
1420 IF (grad_deriv >= 2) THEN
1421 SELECT CASE (xc_f03_func_info_get_family(xc_info))
1422 CASE (xc_family_lda, xc_family_hyb_lda)
1423 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_rhoa], &
1424 allocate_deriv=.true.)
1425 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_rhoa)
1426 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_rhob], &
1427 allocate_deriv=.true.)
1428 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_rhob)
1429 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob, deriv_rhob], &
1430 allocate_deriv=.true.)
1431 CALL xc_derivative_get(deriv, deriv_data=e_rhob_rhob)
1432 CASE (xc_family_gga, xc_family_hyb_gga)
1433 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_rhoa], &
1434 allocate_deriv=.true.)
1435 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_rhoa)
1436 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_rhob], &
1437 allocate_deriv=.true.)
1438 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_rhob)
1439 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob, deriv_rhob], &
1440 allocate_deriv=.true.)
1441 CALL xc_derivative_get(deriv, deriv_data=e_rhob_rhob)
1442 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_rhoa], &
1443 allocate_deriv=.true.)
1444 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_rhoa)
1445 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_rhob], &
1446 allocate_deriv=.true.)
1447 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_rhob)
1448 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_rhoa], &
1449 allocate_deriv=.true.)
1450 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_rhoa)
1451 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_rhob], &
1452 allocate_deriv=.true.)
1453 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_rhob)
1454 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob, deriv_rhoa], &
1455 allocate_deriv=.true.)
1456 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob_rhoa)
1457 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob, deriv_rhob], &
1458 allocate_deriv=.true.)
1459 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob_rhob)
1460 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_norm_drho], &
1461 allocate_deriv=.true.)
1462 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrho)
1463 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_norm_drhoa], &
1464 allocate_deriv=.true.)
1465 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrhoa)
1466 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_norm_drhob], &
1467 allocate_deriv=.true.)
1468 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrhob)
1469 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_norm_drhoa], &
1470 allocate_deriv=.true.)
1471 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_ndrhoa)
1472 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_norm_drhob], &
1473 allocate_deriv=.true.)
1474 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_ndrhob)
1475 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob, deriv_norm_drhob], &
1476 allocate_deriv=.true.)
1477 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob_ndrhob)
1478 CASE (xc_family_mgga, xc_family_hyb_mgga)
1479
1480 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_rhoa], &
1481 allocate_deriv=.true.)
1482 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_rhoa)
1483 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_rhob], &
1484 allocate_deriv=.true.)
1485 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_rhob)
1486 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob, deriv_rhob], &
1487 allocate_deriv=.true.)
1488 CALL xc_derivative_get(deriv, deriv_data=e_rhob_rhob)
1489 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_rhoa], &
1490 allocate_deriv=.true.)
1491 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_rhoa)
1492 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_rhob], &
1493 allocate_deriv=.true.)
1494 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_rhob)
1495 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_rhoa], &
1496 allocate_deriv=.true.)
1497 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_rhoa)
1498 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_rhob], &
1499 allocate_deriv=.true.)
1500 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_rhob)
1501 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob, deriv_rhoa], &
1502 allocate_deriv=.true.)
1503 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob_rhoa)
1504 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob, deriv_rhob], &
1505 allocate_deriv=.true.)
1506 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob_rhob)
1507 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_norm_drho], &
1508 allocate_deriv=.true.)
1509 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrho)
1510 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_norm_drhoa], &
1511 allocate_deriv=.true.)
1512 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrhoa)
1513 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_norm_drhob], &
1514 allocate_deriv=.true.)
1515 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrhob)
1516 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_norm_drhoa], &
1517 allocate_deriv=.true.)
1518 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_ndrhoa)
1519 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_norm_drhob], &
1520 allocate_deriv=.true.)
1521 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_ndrhob)
1522 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob, deriv_norm_drhob], &
1523 allocate_deriv=.true.)
1524 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob_ndrhob)
1525 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_tau_a], &
1526 allocate_deriv=.true.)
1527 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_tau_a)
1528 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_tau_b], &
1529 allocate_deriv=.true.)
1530 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_tau_b)
1531 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob, deriv_tau_a], &
1532 allocate_deriv=.true.)
1533 CALL xc_derivative_get(deriv, deriv_data=e_rhob_tau_a)
1534 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob, deriv_tau_b], &
1535 allocate_deriv=.true.)
1536 CALL xc_derivative_get(deriv, deriv_data=e_rhob_tau_b)
1537 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_tau_a], &
1538 allocate_deriv=.true.)
1539 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_tau_a)
1540 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_tau_b], &
1541 allocate_deriv=.true.)
1542 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_tau_b)
1543 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_tau_a], &
1544 allocate_deriv=.true.)
1545 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_tau_a)
1546 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_tau_b], &
1547 allocate_deriv=.true.)
1548 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_tau_b)
1549 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob, deriv_tau_a], &
1550 allocate_deriv=.true.)
1551 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob_tau_a)
1552 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob, deriv_tau_b], &
1553 allocate_deriv=.true.)
1554 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob_tau_b)
1555 deriv => xc_dset_get_derivative(deriv_set, [deriv_tau_a, deriv_tau_a], &
1556 allocate_deriv=.true.)
1557 CALL xc_derivative_get(deriv, deriv_data=e_tau_a_tau_a)
1558 deriv => xc_dset_get_derivative(deriv_set, [deriv_tau_a, deriv_tau_b], &
1559 allocate_deriv=.true.)
1560 CALL xc_derivative_get(deriv, deriv_data=e_tau_a_tau_b)
1561 deriv => xc_dset_get_derivative(deriv_set, [deriv_tau_b, deriv_tau_b], &
1562 allocate_deriv=.true.)
1563 CALL xc_derivative_get(deriv, deriv_data=e_tau_b_tau_b)
1564 IF (has_laplace) THEN
1565 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_laplace_rhoa], &
1566 allocate_deriv=.true.)
1567 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_laplace_rhoa)
1568 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_laplace_rhob], &
1569 allocate_deriv=.true.)
1570 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_laplace_rhob)
1571 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob, deriv_laplace_rhoa], &
1572 allocate_deriv=.true.)
1573 CALL xc_derivative_get(deriv, deriv_data=e_rhob_laplace_rhoa)
1574 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob, deriv_laplace_rhob], &
1575 allocate_deriv=.true.)
1576 CALL xc_derivative_get(deriv, deriv_data=e_rhob_laplace_rhob)
1577 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_laplace_rhoa], &
1578 allocate_deriv=.true.)
1579 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_laplace_rhoa)
1580 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho, deriv_laplace_rhob], &
1581 allocate_deriv=.true.)
1582 CALL xc_derivative_get(deriv, deriv_data=e_ndrho_laplace_rhob)
1583 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_laplace_rhoa], &
1584 allocate_deriv=.true.)
1585 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_laplace_rhoa)
1586 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa, deriv_laplace_rhob], &
1587 allocate_deriv=.true.)
1588 CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa_laplace_rhob)
1589 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob, deriv_laplace_rhoa], &
1590 allocate_deriv=.true.)
1591 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob_laplace_rhoa)
1592 deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob, deriv_laplace_rhob], &
1593 allocate_deriv=.true.)
1594 CALL xc_derivative_get(deriv, deriv_data=e_ndrhob_laplace_rhob)
1595 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhoa, deriv_laplace_rhoa], &
1596 allocate_deriv=.true.)
1597 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhoa_laplace_rhoa)
1598 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhoa, deriv_laplace_rhob], &
1599 allocate_deriv=.true.)
1600 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhoa_laplace_rhob)
1601 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhob, deriv_laplace_rhob], &
1602 allocate_deriv=.true.)
1603 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhob_laplace_rhob)
1604 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhoa, deriv_tau_a], &
1605 allocate_deriv=.true.)
1606 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhoa_tau_a)
1607 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhoa, deriv_tau_b], &
1608 allocate_deriv=.true.)
1609 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhoa_tau_b)
1610 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhob, deriv_tau_a], &
1611 allocate_deriv=.true.)
1612 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhob_tau_a)
1613 deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhob, deriv_tau_b], &
1614 allocate_deriv=.true.)
1615 CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhob_tau_b)
1616 END IF
1617 CASE default
1618 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
1619 END SELECT
1620 END IF
1621 IF (grad_deriv >= 3) THEN
1622 SELECT CASE (xc_f03_func_info_get_family(xc_info))
1623 CASE (xc_family_lda, xc_family_hyb_lda)
1624 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_rhoa, deriv_rhoa], &
1625 allocate_deriv=.true.)
1626 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_rhoa_rhoa)
1627 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_rhoa, deriv_rhob], &
1628 allocate_deriv=.true.)
1629 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_rhoa_rhob)
1630 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa, deriv_rhob, deriv_rhob], &
1631 allocate_deriv=.true.)
1632 CALL xc_derivative_get(deriv, deriv_data=e_rhoa_rhob_rhob)
1633 deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob, deriv_rhob, deriv_rhob], &
1634 allocate_deriv=.true.)
1635 CALL xc_derivative_get(deriv, deriv_data=e_rhob_rhob_rhob)
1636 CASE (xc_family_gga, xc_family_hyb_gga, xc_family_mgga, xc_family_hyb_mgga)
1637 cpabort("derivatives larger than 2 not implemented")
1638 CASE default
1639 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
1640 END SELECT
1641 END IF
1642
1643!$OMP PARALLEL DEFAULT(NONE), &
1644!$OMP SHARED(rhoa,rhob,norm_drho,norm_drhoa,norm_drhob),&
1645!$OMP SHARED(laplace_rhoa,laplace_rhob,tau_a,tau_b),&
1646!$OMP SHARED(e_0,e_rhoa,e_rhob,e_ndrho,e_ndrhoa,e_ndrhob),&
1647!$OMP SHARED(e_laplace_rhoa,e_laplace_rhob,e_tau_a,e_tau_b),&
1648!$OMP SHARED(e_rhoa_rhoa,e_rhoa_rhob,e_rhob_rhob),&
1649!$OMP SHARED(e_ndrho_rhoa,e_ndrho_rhob),&
1650!$OMP SHARED(e_ndrhoa_rhoa,e_ndrhoa_rhob,e_ndrhob_rhoa,e_ndrhob_rhob),&
1651!$OMP SHARED(e_ndrho_ndrho,e_ndrho_ndrhoa,e_ndrho_ndrhob),&
1652!$OMP SHARED(e_ndrhoa_ndrhoa,e_ndrhoa_ndrhob,e_ndrhob_ndrhob),&
1653!$OMP SHARED(e_rhoa_laplace_rhoa,e_rhoa_laplace_rhob,e_rhob_laplace_rhoa,e_rhob_laplace_rhob),&
1654!$OMP SHARED(e_rhoa_tau_a,e_rhoa_tau_b,e_rhob_tau_a,e_rhob_tau_b),&
1655!$OMP SHARED(e_ndrho_laplace_rhoa,e_ndrho_laplace_rhob),&
1656!$OMP SHARED(e_ndrhoa_laplace_rhoa,e_ndrhoa_laplace_rhob,e_ndrhob_laplace_rhoa,e_ndrhob_laplace_rhob),&
1657!$OMP SHARED(e_ndrho_tau_a,e_ndrho_tau_b),&
1658!$OMP SHARED(e_ndrhoa_tau_a,e_ndrhoa_tau_b,e_ndrhob_tau_a,e_ndrhob_tau_b),&
1659!$OMP SHARED(e_laplace_rhoa_laplace_rhoa,e_laplace_rhoa_laplace_rhob,e_laplace_rhob_laplace_rhob),&
1660!$OMP SHARED(e_laplace_rhoa_tau_a,e_laplace_rhoa_tau_b,e_laplace_rhob_tau_a,e_laplace_rhob_tau_b),&
1661!$OMP SHARED(e_tau_a_tau_a,e_tau_a_tau_b,e_tau_b_tau_b),&
1662!$OMP SHARED(e_rhoa_rhoa_rhoa,e_rhoa_rhoa_rhob,e_rhoa_rhob_rhob,e_rhob_rhob_rhob),&
1663!$OMP SHARED(grad_deriv,npoints),&
1664!$OMP SHARED(func_name,func_scale,workers)
1665
1666 CALL libxc_spin_polarized_calc(rhoa=rhoa, rhob=rhob, norm_drho=norm_drho, &
1667 norm_drhoa=norm_drhoa, norm_drhob=norm_drhob, laplace_rhoa=laplace_rhoa, &
1668 laplace_rhob=laplace_rhob, tau_a=tau_a, tau_b=tau_b, &
1669 e_0=e_0, e_rhoa=e_rhoa, e_rhob=e_rhob, e_ndrho=e_ndrho, &
1670 e_ndrhoa=e_ndrhoa, e_ndrhob=e_ndrhob, e_laplace_rhoa=e_laplace_rhoa, &
1671 e_laplace_rhob=e_laplace_rhob, e_tau_a=e_tau_a, e_tau_b=e_tau_b, &
1672 e_rhoa_rhoa=e_rhoa_rhoa, e_rhoa_rhob=e_rhoa_rhob, e_rhob_rhob=e_rhob_rhob, &
1673 e_ndrho_rhoa=e_ndrho_rhoa, e_ndrho_rhob=e_ndrho_rhob, &
1674 e_ndrhoa_rhoa=e_ndrhoa_rhoa, e_ndrhoa_rhob=e_ndrhoa_rhob, &
1675 e_ndrhob_rhoa=e_ndrhob_rhoa, e_ndrhob_rhob=e_ndrhob_rhob, &
1676 e_ndrho_ndrho=e_ndrho_ndrho, e_ndrho_ndrhoa=e_ndrho_ndrhoa, &
1677 e_ndrho_ndrhob=e_ndrho_ndrhob, e_ndrhoa_ndrhoa=e_ndrhoa_ndrhoa, &
1678 e_ndrhoa_ndrhob=e_ndrhoa_ndrhob, e_ndrhob_ndrhob=e_ndrhob_ndrhob, &
1679 e_rhoa_laplace_rhoa=e_rhoa_laplace_rhoa, &
1680 e_rhoa_laplace_rhob=e_rhoa_laplace_rhob, &
1681 e_rhob_laplace_rhoa=e_rhob_laplace_rhoa, &
1682 e_rhob_laplace_rhob=e_rhob_laplace_rhob, &
1683 e_rhoa_tau_a=e_rhoa_tau_a, e_rhoa_tau_b=e_rhoa_tau_b, &
1684 e_rhob_tau_a=e_rhob_tau_a, e_rhob_tau_b=e_rhob_tau_b, &
1685 e_ndrho_laplace_rhoa=e_ndrho_laplace_rhoa, &
1686 e_ndrho_laplace_rhob=e_ndrho_laplace_rhob, &
1687 e_ndrhoa_laplace_rhoa=e_ndrhoa_laplace_rhoa, &
1688 e_ndrhoa_laplace_rhob=e_ndrhoa_laplace_rhob, &
1689 e_ndrhob_laplace_rhoa=e_ndrhob_laplace_rhoa, &
1690 e_ndrhob_laplace_rhob=e_ndrhob_laplace_rhob, &
1691 e_ndrho_tau_a=e_ndrho_tau_a, e_ndrho_tau_b=e_ndrho_tau_b, &
1692 e_ndrhoa_tau_a=e_ndrhoa_tau_a, e_ndrhoa_tau_b=e_ndrhoa_tau_b, &
1693 e_ndrhob_tau_a=e_ndrhob_tau_a, e_ndrhob_tau_b=e_ndrhob_tau_b, &
1694 e_laplace_rhoa_laplace_rhoa=e_laplace_rhoa_laplace_rhoa, &
1695 e_laplace_rhoa_laplace_rhob=e_laplace_rhoa_laplace_rhob, &
1696 e_laplace_rhob_laplace_rhob=e_laplace_rhob_laplace_rhob, &
1697 e_laplace_rhoa_tau_a=e_laplace_rhoa_tau_a, &
1698 e_laplace_rhoa_tau_b=e_laplace_rhoa_tau_b, &
1699 e_laplace_rhob_tau_a=e_laplace_rhob_tau_a, &
1700 e_laplace_rhob_tau_b=e_laplace_rhob_tau_b, &
1701 e_tau_a_tau_a=e_tau_a_tau_a, &
1702 e_tau_a_tau_b=e_tau_a_tau_b, &
1703 e_tau_b_tau_b=e_tau_b_tau_b, &
1704 e_rhoa_rhoa_rhoa=e_rhoa_rhoa_rhoa, &
1705 e_rhoa_rhoa_rhob=e_rhoa_rhoa_rhob, &
1706 e_rhoa_rhob_rhob=e_rhoa_rhob_rhob, &
1707 e_rhob_rhob_rhob=e_rhob_rhob_rhob, &
1708 grad_deriv=grad_deriv, npoints=npoints, &
1709 func_name=func_name, sc=func_scale, workers=workers)
1710
1711!$OMP END PARALLEL
1712
1713 NULLIFY (dummy)
1714 NULLIFY (workers)
1715
1716 CALL timestop(handle)
1717#else
1718 mark_used(rho_set)
1719 mark_used(deriv_set)
1720 mark_used(grad_deriv)
1721 mark_used(libxc_params)
1722 mark_used(func_name_override)
1723
1724 CALL cp_abort(__location__, "Unknown functional! If you are asking "// &
1725 "for a functional of the LibXC library, "// &
1726 "you have to download and install the library!")
1727#endif
1728 END SUBROUTINE libxc_spin_polarized_eval
1729
1730! **************************************************************************************************
1731!> \brief libxc exchange-correlation functionals
1732!> \param rho density
1733!> \param norm_drho norm of the gradient of the density
1734!> \param laplace_rho laplacian of the density
1735!> \param tau kinetic-energy density
1736!> \param e_0 energy density
1737!> \param e_rho derivative of the energy density with respect to rho
1738!> \param e_ndrho derivative of the energy density with respect to ndrho
1739!> \param e_laplace_rho derivative of the energy density with respect to laplace_rho
1740!> \param e_tau derivative of the energy density with respect to tau
1741!> \param e_rho_rho derivative of the energy density with respect to rho_rho
1742!> \param e_ndrho_rho derivative of the energy density with respect to ndrho_rho
1743!> \param e_ndrho_ndrho derivative of the energy density with respect to ndrho_ndrho
1744!> \param e_rho_laplace_rho derivative of the energy density with respect to rho_laplace_rho
1745!> \param e_rho_tau derivative of the energy density with respect to rho_tau
1746!> \param e_ndrho_laplace_rho derivative of the energy density with respect to ndrho_laplace_rho
1747!> \param e_ndrho_tau derivative of the energy density with respect to ndrho_tau
1748!> \param e_laplace_rho_laplace_rho derivative of the energy density with respect to laplace_rho_laplace_rho
1749!> \param e_laplace_rho_tau derivative of the energy density with respect to laplace_rho_tau
1750!> \param e_tau_tau derivative of the energy density with respect to tau_tau
1751!> \param e_rho_rho_rho derivative of the energy density with respect to rho_rho_rho
1752!> \param grad_deriv degree of the derivative that should be evaluated;
1753!> all derivatives up to the given degree are evaluated, in a single
1754!> LibXC call per block of grid points
1755!> \param npoints number of points on the grid
1756!> \param func_name name of the functional
1757!> \param sc scaling factor of the functional
1758!> \param workers cached LibXC functional objects and staging buffers, one per thread
1759!> \author F. Tran
1760! **************************************************************************************************
1761#if defined (__LIBXC)
1762 SUBROUTINE libxc_spin_unpolarized_calc(rho, norm_drho, laplace_rho, tau, &
1763 e_0, e_rho, e_ndrho, e_laplace_rho, e_tau, e_rho_rho, e_ndrho_rho, &
1764 e_ndrho_ndrho, e_rho_laplace_rho, e_rho_tau, e_ndrho_laplace_rho, &
1765 e_ndrho_tau, e_laplace_rho_laplace_rho, e_laplace_rho_tau, &
1766 e_tau_tau, e_rho_rho_rho, &
1767 grad_deriv, npoints, func_name, sc, workers)
1768
1769 REAL(kind=dp), DIMENSION(*), INTENT(IN) :: rho, norm_drho, laplace_rho, tau
1770 REAL(kind=dp), DIMENSION(*), INTENT(INOUT) :: e_0, e_rho, e_ndrho, e_laplace_rho, e_tau, &
1771 e_rho_rho, e_ndrho_rho, e_ndrho_ndrho, e_rho_laplace_rho, e_rho_tau, e_ndrho_laplace_rho, &
1772 e_ndrho_tau, e_laplace_rho_laplace_rho, e_laplace_rho_tau, e_tau_tau, e_rho_rho_rho
1773 INTEGER, INTENT(in) :: grad_deriv, npoints
1774 CHARACTER(LEN=default_string_length), INTENT(IN) :: func_name
1775 REAL(kind=dp), INTENT(in) :: sc
1776 TYPE(libxc_worker_set_type), INTENT(INOUT) :: workers
1777
1778 INTEGER :: bsize, family, i, i0, ib, ii, ithread, &
1779 nb, nblocks, nthreads
1780 INTEGER(C_SIZE_T) :: np
1781 LOGICAL :: is_gga, is_mgga
1782
1783 ithread = 0
1784 nthreads = 1
1785!$ ithread = omp_get_thread_num()
1786!$ nthreads = omp_get_num_threads()
1787 cpassert(ithread < SIZE(workers%worker))
1788
1789 ! Blocks are capped by libxc_block_size, which is what the staging buffers
1790 ! were allocated for, but shrunk when there are too few points to give every
1791 ! thread a block of its own: small atomic grids would otherwise all be
1792 ! evaluated by thread 0.
1793 bsize = max(1, min(libxc_block_size, (npoints + nthreads - 1)/nthreads))
1794 nblocks = (npoints + bsize - 1)/bsize
1795
1796 family = workers%family
1797 SELECT CASE (family)
1798 CASE (xc_family_lda, xc_family_hyb_lda)
1799 is_gga = .false.
1800 is_mgga = .false.
1801 CASE (xc_family_gga, xc_family_hyb_gga)
1802 is_gga = .true.
1803 is_mgga = .false.
1804 CASE (xc_family_mgga, xc_family_hyb_mgga)
1805 is_gga = .true.
1806 is_mgga = .true.
1807 CASE default
1808 is_gga = .false.
1809 is_mgga = .false.
1810 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
1811 END SELECT
1812
1813 ! Points below the density cutoff need no test here. The cutoffs were handed
1814 ! to the functional object in xc_libxc_wrap_set_thresholds, and LibXC leaves
1815 ! the outputs of the points it screens at zero, so accumulating them is a
1816 ! no-op.
1817 associate(w => workers%worker(ithread + 1), has_laplace => workers%has_laplace, &
1818 no_exc => workers%no_exc, eps_rho => workers%epsilon_rho, &
1819 eps_tau => workers%epsilon_tau)
1820!$OMP DO
1821 DO ib = 1, nblocks
1822 i0 = (ib - 1)*bsize
1823 nb = min(bsize, npoints - i0)
1824 np = int(nb, kind=c_size_t)
1825
1826 ! stage this block's inputs in LibXC's layout
1827 DO i = 1, nb
1828 w%rho(1, i) = rho(i0 + i)
1829 END DO
1830 IF (is_gga) THEN
1831 DO i = 1, nb
1832 w%sigma(1, i) = norm_drho(i0 + i)**2
1833 END DO
1834 END IF
1835 IF (is_mgga) THEN
1836 DO i = 1, nb
1837 ii = i0 + i
1838 w%lapl(1, i) = laplace_rho(ii)
1839 w%tau(1, i) = tau(ii)
1840 END DO
1841 ! Meta-GGAs are screened on the kinetic energy density as well as on the
1842 ! density, and LibXC only screens on the latter. A point failing the tau
1843 ! test is handed over with zero density, which makes LibXC screen it out
1844 ! and leave its outputs at zero: what skipping it used to achieve. The
1845 ! Fermi hole curvature bound tau >= sigma/(8*rho) follows in the same pass,
1846 ! with the denominator floored at the cutoff so the division stays defined
1847 ! for the points that are about to be screened.
1848 DO i = 1, nb
1849 IF (w%tau(1, i) <= eps_tau) w%rho(1, i) = 0.0_dp
1850 w%tau(1, i) = max(w%tau(1, i), &
1851 w%sigma(1, i)/(8.0_dp*max(w%rho(1, i), eps_rho)))
1852 END DO
1853 END IF
1854
1855 ! one LibXC call for the whole block
1856 IF (is_mgga) THEN
1857 SELECT CASE (grad_deriv)
1858 CASE (0)
1859 CALL xc_f03_mgga_exc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%lapl(1, 1), w%tau(1, 1), w%exc(1))
1860 CASE (1)
1861 IF (no_exc) THEN
1862 CALL xc_f03_mgga_vxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%lapl(1, 1), w%tau(1, 1), &
1863 w%vrho(1, 1), w%vsigma(1, 1), w%vlapl(1, 1), w%vtau(1, 1))
1864 w%exc(1:nb) = 0.0_dp
1865 ELSE
1866 CALL xc_f03_mgga_exc_vxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%lapl(1, 1), w%tau(1, 1), &
1867 w%exc(1), w%vrho(1, 1), w%vsigma(1, 1), w%vlapl(1, 1), w%vtau(1, 1))
1868 END IF
1869 CASE (2)
1870 IF (no_exc) THEN
1871 CALL xc_f03_mgga_vxc_fxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%lapl(1, 1), w%tau(1, 1), &
1872 w%vrho(1, 1), w%vsigma(1, 1), w%vlapl(1, 1), w%vtau(1, 1), &
1873 w%v2rho2(1, 1), w%v2rhosigma(1, 1), w%v2rholapl(1, 1), &
1874 w%v2rhotau(1, 1), w%v2sigma2(1, 1), w%v2sigmalapl(1, 1), &
1875 w%v2sigmatau(1, 1), w%v2lapl2(1, 1), w%v2lapltau(1, 1), w%v2tau2(1, 1))
1876 w%exc(1:nb) = 0.0_dp
1877 ELSE
1878 CALL xc_f03_mgga(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%lapl(1, 1), w%tau(1, 1), &
1879 w%exc(1), w%vrho(1, 1), w%vsigma(1, 1), w%vlapl(1, 1), w%vtau(1, 1), &
1880 w%v2rho2(1, 1), w%v2rhosigma(1, 1), w%v2rholapl(1, 1), &
1881 w%v2rhotau(1, 1), w%v2sigma2(1, 1), w%v2sigmalapl(1, 1), &
1882 w%v2sigmatau(1, 1), w%v2lapl2(1, 1), w%v2lapltau(1, 1), w%v2tau2(1, 1))
1883 END IF
1884 END SELECT
1885 ELSE IF (is_gga) THEN
1886 SELECT CASE (grad_deriv)
1887 CASE (0)
1888 CALL xc_f03_gga_exc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%exc(1))
1889 CASE (1)
1890 IF (no_exc) THEN
1891 CALL xc_f03_gga_vxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%vrho(1, 1), w%vsigma(1, 1))
1892 w%exc(1:nb) = 0.0_dp
1893 ELSE
1894 CALL xc_f03_gga_exc_vxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), &
1895 w%exc(1), w%vrho(1, 1), w%vsigma(1, 1))
1896 END IF
1897 CASE (2)
1898 IF (no_exc) THEN
1899 CALL xc_f03_gga_vxc_fxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), &
1900 w%vrho(1, 1), w%vsigma(1, 1), &
1901 w%v2rho2(1, 1), w%v2rhosigma(1, 1), w%v2sigma2(1, 1))
1902 w%exc(1:nb) = 0.0_dp
1903 ELSE
1904 CALL xc_f03_gga_exc_vxc_fxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), &
1905 w%exc(1), w%vrho(1, 1), w%vsigma(1, 1), &
1906 w%v2rho2(1, 1), w%v2rhosigma(1, 1), w%v2sigma2(1, 1))
1907 END IF
1908 END SELECT
1909 ELSE
1910 SELECT CASE (grad_deriv)
1911 CASE (0)
1912 CALL xc_f03_lda_exc(w%func, np, w%rho(1, 1), w%exc(1))
1913 CASE (1)
1914 CALL xc_f03_lda_exc_vxc(w%func, np, w%rho(1, 1), w%exc(1), w%vrho(1, 1))
1915 CASE (2)
1916 CALL xc_f03_lda_exc_vxc_fxc(w%func, np, w%rho(1, 1), &
1917 w%exc(1), w%vrho(1, 1), w%v2rho2(1, 1))
1918 CASE (3)
1919 CALL xc_f03_lda(w%func, np, w%rho(1, 1), &
1920 w%exc(1), w%vrho(1, 1), w%v2rho2(1, 1), w%v3rho3(1, 1))
1921 END SELECT
1922 END IF
1923
1924 ! accumulate; each derivative is added by exactly one loop, selected by
1925 ! the order requested and the family, not by a per-branch copy of the whole
1926 ! block scaffolding
1927 IF (grad_deriv >= 0) THEN
1928 DO i = 1, nb
1929 ii = i0 + i
1930 e_0(ii) = e_0(ii) + sc*w%exc(i)*rho(ii)
1931 END DO
1932 END IF
1933 IF (grad_deriv >= 1) THEN
1934 DO i = 1, nb
1935 ii = i0 + i
1936 e_rho(ii) = e_rho(ii) + sc*w%vrho(1, i)
1937 END DO
1938 IF (is_gga) THEN
1939 DO i = 1, nb
1940 ii = i0 + i
1941 e_ndrho(ii) = e_ndrho(ii) + sc*2.0_dp*w%vsigma(1, i)*norm_drho(ii)
1942 END DO
1943 END IF
1944 IF (is_mgga) THEN
1945 DO i = 1, nb
1946 ii = i0 + i
1947 e_tau(ii) = e_tau(ii) + sc*w%vtau(1, i)
1948 END DO
1949 END IF
1950 IF (is_mgga .AND. has_laplace) THEN
1951 DO i = 1, nb
1952 ii = i0 + i
1953 e_laplace_rho(ii) = e_laplace_rho(ii) + sc*w%vlapl(1, i)
1954 END DO
1955 END IF
1956 END IF
1957 IF (grad_deriv >= 2) THEN
1958 DO i = 1, nb
1959 ii = i0 + i
1960 e_rho_rho(ii) = e_rho_rho(ii) + sc*w%v2rho2(1, i)
1961 END DO
1962 IF (is_gga) THEN
1963 DO i = 1, nb
1964 ii = i0 + i
1965 e_ndrho_rho(ii) = e_ndrho_rho(ii) + sc*2.0_dp*w%v2rhosigma(1, i)*norm_drho(ii)
1966 e_ndrho_ndrho(ii) = e_ndrho_ndrho(ii) + &
1967 sc*2.0_dp*(2.0_dp*w%sigma(1, i)*w%v2sigma2(1, i) + w%vsigma(1, i))
1968 END DO
1969 END IF
1970 IF (is_mgga) THEN
1971 DO i = 1, nb
1972 ii = i0 + i
1973 e_rho_tau(ii) = e_rho_tau(ii) + sc*w%v2rhotau(1, i)
1974 e_ndrho_tau(ii) = e_ndrho_tau(ii) + sc*2.0_dp*w%v2sigmatau(1, i)*norm_drho(ii)
1975 e_tau_tau(ii) = e_tau_tau(ii) + sc*w%v2tau2(1, i)
1976 END DO
1977 END IF
1978 IF (is_mgga .AND. has_laplace) THEN
1979 DO i = 1, nb
1980 ii = i0 + i
1981 e_rho_laplace_rho(ii) = e_rho_laplace_rho(ii) + sc*w%v2rholapl(1, i)
1982 e_ndrho_laplace_rho(ii) = e_ndrho_laplace_rho(ii) + &
1983 sc*2.0_dp*w%v2sigmalapl(1, i)*norm_drho(ii)
1984 e_laplace_rho_laplace_rho(ii) = e_laplace_rho_laplace_rho(ii) + sc*w%v2lapl2(1, i)
1985 e_laplace_rho_tau(ii) = e_laplace_rho_tau(ii) + sc*w%v2lapltau(1, i)
1986 END DO
1987 END IF
1988 END IF
1989 IF (grad_deriv >= 3) THEN
1990 DO i = 1, nb
1991 ii = i0 + i
1992 e_rho_rho_rho(ii) = e_rho_rho_rho(ii) + sc*w%v3rho3(1, i)
1993 END DO
1994 END IF
1995 END DO
1996!$OMP END DO
1997 END associate
1998
1999 END SUBROUTINE libxc_spin_unpolarized_calc
2000#endif
2001
2002! **************************************************************************************************
2003!> \brief libxc exchange-correlation functionals
2004!> \param rhoa alpha density
2005!> \param rhob beta density
2006!> \param norm_drho ...
2007!> \param norm_drhoa norm of the gradient of the alpha density
2008!> \param norm_drhob norm of the gradient of the beta density
2009!> \param laplace_rhoa laplacian of the alpha density
2010!> \param laplace_rhob laplacian of the beta density
2011!> \param tau_a alpha kinetic-energy density
2012!> \param tau_b beta kinetic-energy density
2013!> \param e_0 energy density
2014!> \param e_rhoa derivative of the energy density with respect to rhoa
2015!> \param e_rhob derivative of the energy density with respect to rhob
2016!> \param e_ndrho derivative of the energy density with respect to ndrho
2017!> \param e_ndrhoa derivative of the energy density with respect to ndrhoa
2018!> \param e_ndrhob derivative of the energy density with respect to ndrhob
2019!> \param e_laplace_rhoa derivative of the energy density with respect to laplace_rhoa
2020!> \param e_laplace_rhob derivative of the energy density with respect to laplace_rhob
2021!> \param e_tau_a derivative of the energy density with respect to tau_a
2022!> \param e_tau_b derivative of the energy density with respect to tau_b
2023!> \param e_rhoa_rhoa derivative of the energy density with respect to rhoa_rhoa
2024!> \param e_rhoa_rhob derivative of the energy density with respect to rhoa_rhob
2025!> \param e_rhob_rhob derivative of the energy density with respect to rhob_rhob
2026!> \param e_ndrho_rhoa derivative of the energy density with respect to ndrho_rhoa
2027!> \param e_ndrho_rhob derivative of the energy density with respect to ndrho_rhob
2028!> \param e_ndrhoa_rhoa derivative of the energy density with respect to ndrhoa_rhoa
2029!> \param e_ndrhoa_rhob derivative of the energy density with respect to ndrhoa_rhob
2030!> \param e_ndrhob_rhoa derivative of the energy density with respect to ndrhob_rhoa
2031!> \param e_ndrhob_rhob derivative of the energy density with respect to ndrhob_rhob
2032!> \param e_ndrho_ndrho derivative of the energy density with respect to ndrho_ndrho
2033!> \param e_ndrho_ndrhoa derivative of the energy density with respect to ndrho_ndrhoa
2034!> \param e_ndrho_ndrhob derivative of the energy density with respect to ndrho_ndrhob
2035!> \param e_ndrhoa_ndrhoa derivative of the energy density with respect to ndrhoa_ndrhoa
2036!> \param e_ndrhoa_ndrhob derivative of the energy density with respect to ndrhoa_ndrhob
2037!> \param e_ndrhob_ndrhob derivative of the energy density with respect to ndrhob_ndrhob
2038!> \param e_rhoa_laplace_rhoa derivative of the energy density with respect to rhoa_laplace_rhoa
2039!> \param e_rhoa_laplace_rhob derivative of the energy density with respect to rhoa_laplace_rhob
2040!> \param e_rhob_laplace_rhoa derivative of the energy density with respect to rhob_laplace_rhoa
2041!> \param e_rhob_laplace_rhob derivative of the energy density with respect to rhob_laplace_rhob
2042!> \param e_rhoa_tau_a derivative of the energy density with respect to rhoa_tau_a
2043!> \param e_rhoa_tau_b derivative of the energy density with respect to rhoa_tau_b
2044!> \param e_rhob_tau_a derivative of the energy density with respect to rhob_tau_a
2045!> \param e_rhob_tau_b derivative of the energy density with respect to rhob_tau_b
2046!> \param e_ndrho_laplace_rhoa derivative of the energy density with respect to ndrho_laplace_rhoa
2047!> \param e_ndrho_laplace_rhob derivative of the energy density with respect to ndrho_laplace_rhob
2048!> \param e_ndrhoa_laplace_rhoa derivative of the energy density with respect to ndrhoa_laplace_rhoa
2049!> \param e_ndrhoa_laplace_rhob derivative of the energy density with respect to ndrhoa_laplace_rhob
2050!> \param e_ndrhob_laplace_rhoa derivative of the energy density with respect to ndrhob_laplace_rhoa
2051!> \param e_ndrhob_laplace_rhob derivative of the energy density with respect to ndrhob_laplace_rhob
2052!> \param e_ndrho_tau_a derivative of the energy density with respect to ndrho_tau_a
2053!> \param e_ndrho_tau_b derivative of the energy density with respect to ndrho_tau_b
2054!> \param e_ndrhoa_tau_a derivative of the energy density with respect to ndrhoa_tau_a
2055!> \param e_ndrhoa_tau_b derivative of the energy density with respect to ndrhoa_tau_b
2056!> \param e_ndrhob_tau_a derivative of the energy density with respect to ndrhob_tau_a
2057!> \param e_ndrhob_tau_b derivative of the energy density with respect to ndrhob_tau_b
2058!> \param e_laplace_rhoa_laplace_rhoa derivative of the energy density with respect to laplace_rhoa_laplace_rhoa
2059!> \param e_laplace_rhoa_laplace_rhob derivative of the energy density with respect to laplace_rhoa_laplace_rhob
2060!> \param e_laplace_rhob_laplace_rhob derivative of the energy density with respect to laplace_rhob_laplace_rhob
2061!> \param e_laplace_rhoa_tau_a derivative of the energy density with respect to laplace_rhoa_tau_a
2062!> \param e_laplace_rhoa_tau_b derivative of the energy density with respect to laplace_rhoa_tau_b
2063!> \param e_laplace_rhob_tau_a derivative of the energy density with respect to laplace_rhob_tau_a
2064!> \param e_laplace_rhob_tau_b derivative of the energy density with respect to laplace_rhob_tau_b
2065!> \param e_tau_a_tau_a derivative of the energy density with respect to tau_a_tau_a
2066!> \param e_tau_a_tau_b derivative of the energy density with respect to tau_a_tau_b
2067!> \param e_tau_b_tau_b derivative of the energy density with respect to tau_b_tau_b
2068!> \param e_rhoa_rhoa_rhoa derivative of the energy density with respect to rhoa_rhoa_rhoa
2069!> \param e_rhoa_rhoa_rhob derivative of the energy density with respect to rhoa_rhoa_rhob
2070!> \param e_rhoa_rhob_rhob derivative of the energy density with respect to rhoa_rhob_rhob
2071!> \param e_rhob_rhob_rhob derivative of the energy density with respect to rhob_rhob_rhob
2072!> \param grad_deriv degree of the derivative that should be evaluated;
2073!> all derivatives up to the given degree are evaluated, in a single
2074!> LibXC call per block of grid points
2075!> \param npoints number of points on the grid
2076!> \param func_name name of the functional
2077!> \param sc scaling factor of the functional
2078!> \param workers cached LibXC functional objects and staging buffers, one per thread
2079!> \author F. Tran
2080! **************************************************************************************************
2081#if defined (__LIBXC)
2082 SUBROUTINE libxc_spin_polarized_calc(rhoa, rhob, norm_drho, norm_drhoa, &
2083 norm_drhob, laplace_rhoa, laplace_rhob, tau_a, tau_b, &
2084 e_0, e_rhoa, e_rhob, e_ndrho, e_ndrhoa, e_ndrhob, &
2085 e_laplace_rhoa, e_laplace_rhob, e_tau_a, e_tau_b, &
2086 e_rhoa_rhoa, e_rhoa_rhob, e_rhob_rhob, &
2087 e_ndrho_rhoa, e_ndrho_rhob, e_ndrhoa_rhoa, &
2088 e_ndrhoa_rhob, e_ndrhob_rhoa, e_ndrhob_rhob, &
2089 e_ndrho_ndrho, e_ndrho_ndrhoa, e_ndrho_ndrhob, &
2090 e_ndrhoa_ndrhoa, e_ndrhoa_ndrhob, e_ndrhob_ndrhob, &
2091 e_rhoa_laplace_rhoa, e_rhoa_laplace_rhob, &
2092 e_rhob_laplace_rhoa, e_rhob_laplace_rhob, &
2093 e_rhoa_tau_a, e_rhoa_tau_b, e_rhob_tau_a, e_rhob_tau_b, &
2094 e_ndrho_laplace_rhoa, e_ndrho_laplace_rhob, &
2095 e_ndrhoa_laplace_rhoa, e_ndrhoa_laplace_rhob, &
2096 e_ndrhob_laplace_rhoa, e_ndrhob_laplace_rhob, &
2097 e_ndrho_tau_a, e_ndrho_tau_b, &
2098 e_ndrhoa_tau_a, e_ndrhoa_tau_b, &
2099 e_ndrhob_tau_a, e_ndrhob_tau_b, &
2100 e_laplace_rhoa_laplace_rhoa, &
2101 e_laplace_rhoa_laplace_rhob, &
2102 e_laplace_rhob_laplace_rhob, &
2103 e_laplace_rhoa_tau_a, e_laplace_rhoa_tau_b, &
2104 e_laplace_rhob_tau_a, e_laplace_rhob_tau_b, &
2105 e_tau_a_tau_a, e_tau_a_tau_b, e_tau_b_tau_b, &
2106 e_rhoa_rhoa_rhoa, e_rhoa_rhoa_rhob, &
2107 e_rhoa_rhob_rhob, e_rhob_rhob_rhob, &
2108 grad_deriv, npoints, func_name, sc, workers)
2109
2110 REAL(kind=dp), DIMENSION(*), INTENT(IN) :: rhoa, rhob, norm_drho, norm_drhoa, &
2111 norm_drhob, laplace_rhoa, &
2112 laplace_rhob, tau_a, tau_b
2113 REAL(kind=dp), DIMENSION(*), INTENT(INOUT) :: e_0, e_rhoa, e_rhob, e_ndrho, e_ndrhoa, &
2114 e_ndrhob, e_laplace_rhoa, e_laplace_rhob, e_tau_a, e_tau_b, e_rhoa_rhoa, e_rhoa_rhob, &
2115 e_rhob_rhob, e_ndrho_rhoa, e_ndrho_rhob, e_ndrhoa_rhoa, e_ndrhoa_rhob, e_ndrhob_rhoa, &
2116 e_ndrhob_rhob, e_ndrho_ndrho, e_ndrho_ndrhoa, e_ndrho_ndrhob, e_ndrhoa_ndrhoa, &
2117 e_ndrhoa_ndrhob, e_ndrhob_ndrhob, e_rhoa_laplace_rhoa, e_rhoa_laplace_rhob, &
2118 e_rhob_laplace_rhoa, e_rhob_laplace_rhob, e_rhoa_tau_a, e_rhoa_tau_b, e_rhob_tau_a, &
2119 e_rhob_tau_b, e_ndrho_laplace_rhoa, e_ndrho_laplace_rhob, e_ndrhoa_laplace_rhoa
2120 REAL(kind=dp), DIMENSION(*), INTENT(INOUT) :: e_ndrhoa_laplace_rhob, e_ndrhob_laplace_rhoa, &
2121 e_ndrhob_laplace_rhob, e_ndrho_tau_a, e_ndrho_tau_b, e_ndrhoa_tau_a, e_ndrhoa_tau_b, &
2122 e_ndrhob_tau_a, e_ndrhob_tau_b, e_laplace_rhoa_laplace_rhoa, e_laplace_rhoa_laplace_rhob, &
2123 e_laplace_rhob_laplace_rhob, e_laplace_rhoa_tau_a, e_laplace_rhoa_tau_b, &
2124 e_laplace_rhob_tau_a, e_laplace_rhob_tau_b, e_tau_a_tau_a, e_tau_a_tau_b, e_tau_b_tau_b, &
2125 e_rhoa_rhoa_rhoa, e_rhoa_rhoa_rhob, e_rhoa_rhob_rhob, e_rhob_rhob_rhob
2126 INTEGER, INTENT(in) :: grad_deriv, npoints
2127 CHARACTER(LEN=default_string_length), INTENT(IN) :: func_name
2128 REAL(kind=dp), INTENT(in) :: sc
2129 TYPE(libxc_worker_set_type), INTENT(INOUT) :: workers
2130
2131 INTEGER :: bsize, family, i, i0, ib, ii, ithread, &
2132 nb, nblocks, nthreads
2133 INTEGER(C_SIZE_T) :: np
2134 LOGICAL :: is_gga, is_mgga
2135
2136 ithread = 0
2137 nthreads = 1
2138!$ ithread = omp_get_thread_num()
2139!$ nthreads = omp_get_num_threads()
2140 cpassert(ithread < SIZE(workers%worker))
2141
2142 bsize = max(1, min(libxc_block_size, (npoints + nthreads - 1)/nthreads))
2143 nblocks = (npoints + bsize - 1)/bsize
2144
2145 family = workers%family
2146 SELECT CASE (family)
2147 CASE (xc_family_lda, xc_family_hyb_lda)
2148 is_gga = .false.
2149 is_mgga = .false.
2150 CASE (xc_family_gga, xc_family_hyb_gga)
2151 is_gga = .true.
2152 is_mgga = .false.
2153 CASE (xc_family_mgga, xc_family_hyb_mgga)
2154 is_gga = .true.
2155 is_mgga = .true.
2156 CASE default
2157 is_gga = .false.
2158 is_mgga = .false.
2159 cpabort(trim(func_name)//": this XC_FAMILY is currently not supported.")
2160 END SELECT
2161
2162 ! As in the spin-unpolarized case the density and kinetic energy density
2163 ! cutoffs are applied by LibXC itself.
2164 associate(w => workers%worker(ithread + 1), has_laplace => workers%has_laplace, &
2165 no_exc => workers%no_exc, eps_rho => workers%epsilon_rho, &
2166 eps_tau => workers%epsilon_tau)
2167!$OMP DO
2168 DO ib = 1, nblocks
2169 i0 = (ib - 1)*bsize
2170 nb = min(bsize, npoints - i0)
2171 np = int(nb, kind=c_size_t)
2172
2173 ! stage this block's inputs in LibXC's layout
2174 DO i = 1, nb
2175 ii = i0 + i
2176 w%rho(1, i) = max(rhoa(ii), 0.0_dp)
2177 w%rho(2, i) = max(rhob(ii), 0.0_dp)
2178 END DO
2179 IF (is_gga) THEN
2180 ! CP2K works with the norms of the gradients, LibXC with their contractions
2181 DO i = 1, nb
2182 ii = i0 + i
2183 w%nda(i) = max(norm_drhoa(ii), epsilon(0.0_dp)*1.e4_dp)
2184 w%ndb(i) = max(norm_drhob(ii), epsilon(0.0_dp)*1.e4_dp)
2185 w%nd(i) = max(norm_drho(ii), epsilon(0.0_dp)*1.e4_dp)
2186 w%sigma(1, i) = w%nda(i)**2
2187 w%sigma(3, i) = w%ndb(i)**2
2188 w%sigma(2, i) = 0.5_dp*(w%nd(i)**2 - w%sigma(1, i) - w%sigma(3, i))
2189 END DO
2190 END IF
2191 IF (is_mgga) THEN
2192 DO i = 1, nb
2193 ii = i0 + i
2194 w%lapl(1, i) = laplace_rhoa(ii)
2195 w%lapl(2, i) = laplace_rhob(ii)
2196 w%tau(1, i) = max(tau_a(ii), 0.0_dp)
2197 w%tau(2, i) = max(tau_b(ii), 0.0_dp)
2198 END DO
2199 ! screening on tau and the Fermi hole curvature bound, per spin channel;
2200 ! see the spin-unpolarized routine. The tau test is on the sum of the two
2201 ! channels, as the density test is.
2202 DO i = 1, nb
2203 IF (w%tau(1, i) + w%tau(2, i) <= eps_tau) THEN
2204 w%rho(1, i) = 0.0_dp
2205 w%rho(2, i) = 0.0_dp
2206 END IF
2207 w%tau(1, i) = max(w%tau(1, i), &
2208 w%sigma(1, i)/(8.0_dp*max(w%rho(1, i), eps_rho)))
2209 w%tau(2, i) = max(w%tau(2, i), &
2210 w%sigma(3, i)/(8.0_dp*max(w%rho(2, i), eps_rho)))
2211 END DO
2212 END IF
2213
2214 ! one LibXC call for the whole block
2215 IF (is_mgga) THEN
2216 SELECT CASE (grad_deriv)
2217 CASE (0)
2218 CALL xc_f03_mgga_exc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%lapl(1, 1), w%tau(1, 1), w%exc(1))
2219 CASE (1)
2220 IF (no_exc) THEN
2221 CALL xc_f03_mgga_vxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%lapl(1, 1), w%tau(1, 1), &
2222 w%vrho(1, 1), w%vsigma(1, 1), w%vlapl(1, 1), w%vtau(1, 1))
2223 w%exc(1:nb) = 0.0_dp
2224 ELSE
2225 CALL xc_f03_mgga_exc_vxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%lapl(1, 1), w%tau(1, 1), &
2226 w%exc(1), w%vrho(1, 1), w%vsigma(1, 1), w%vlapl(1, 1), w%vtau(1, 1))
2227 END IF
2228 CASE (2)
2229 IF (no_exc) THEN
2230 CALL xc_f03_mgga_vxc_fxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%lapl(1, 1), w%tau(1, 1), &
2231 w%vrho(1, 1), w%vsigma(1, 1), w%vlapl(1, 1), w%vtau(1, 1), &
2232 w%v2rho2(1, 1), w%v2rhosigma(1, 1), w%v2rholapl(1, 1), &
2233 w%v2rhotau(1, 1), w%v2sigma2(1, 1), w%v2sigmalapl(1, 1), &
2234 w%v2sigmatau(1, 1), w%v2lapl2(1, 1), w%v2lapltau(1, 1), w%v2tau2(1, 1))
2235 w%exc(1:nb) = 0.0_dp
2236 ELSE
2237 CALL xc_f03_mgga(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%lapl(1, 1), w%tau(1, 1), &
2238 w%exc(1), w%vrho(1, 1), w%vsigma(1, 1), w%vlapl(1, 1), w%vtau(1, 1), &
2239 w%v2rho2(1, 1), w%v2rhosigma(1, 1), w%v2rholapl(1, 1), &
2240 w%v2rhotau(1, 1), w%v2sigma2(1, 1), w%v2sigmalapl(1, 1), &
2241 w%v2sigmatau(1, 1), w%v2lapl2(1, 1), w%v2lapltau(1, 1), w%v2tau2(1, 1))
2242 END IF
2243 END SELECT
2244 ELSE IF (is_gga) THEN
2245 SELECT CASE (grad_deriv)
2246 CASE (0)
2247 CALL xc_f03_gga_exc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%exc(1))
2248 CASE (1)
2249 IF (no_exc) THEN
2250 CALL xc_f03_gga_vxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), w%vrho(1, 1), w%vsigma(1, 1))
2251 w%exc(1:nb) = 0.0_dp
2252 ELSE
2253 CALL xc_f03_gga_exc_vxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), &
2254 w%exc(1), w%vrho(1, 1), w%vsigma(1, 1))
2255 END IF
2256 CASE (2)
2257 IF (no_exc) THEN
2258 CALL xc_f03_gga_vxc_fxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), &
2259 w%vrho(1, 1), w%vsigma(1, 1), &
2260 w%v2rho2(1, 1), w%v2rhosigma(1, 1), w%v2sigma2(1, 1))
2261 w%exc(1:nb) = 0.0_dp
2262 ELSE
2263 CALL xc_f03_gga_exc_vxc_fxc(w%func, np, w%rho(1, 1), w%sigma(1, 1), &
2264 w%exc(1), w%vrho(1, 1), w%vsigma(1, 1), &
2265 w%v2rho2(1, 1), w%v2rhosigma(1, 1), w%v2sigma2(1, 1))
2266 END IF
2267 END SELECT
2268 ELSE
2269 SELECT CASE (grad_deriv)
2270 CASE (0)
2271 CALL xc_f03_lda_exc(w%func, np, w%rho(1, 1), w%exc(1))
2272 CASE (1)
2273 CALL xc_f03_lda_exc_vxc(w%func, np, w%rho(1, 1), w%exc(1), w%vrho(1, 1))
2274 CASE (2)
2275 CALL xc_f03_lda_exc_vxc_fxc(w%func, np, w%rho(1, 1), &
2276 w%exc(1), w%vrho(1, 1), w%v2rho2(1, 1))
2277 CASE (3)
2278 CALL xc_f03_lda(w%func, np, w%rho(1, 1), &
2279 w%exc(1), w%vrho(1, 1), w%v2rho2(1, 1), w%v3rho3(1, 1))
2280 END SELECT
2281 END IF
2282
2283 ! accumulate; one loop per group of derivatives, selected by the order
2284 ! requested and the family
2285 IF (grad_deriv >= 0) THEN
2286 DO i = 1, nb
2287 ii = i0 + i
2288 e_0(ii) = e_0(ii) + sc*w%exc(i)*(w%rho(1, i) + w%rho(2, i))
2289 END DO
2290 END IF
2291 IF (grad_deriv >= 1) THEN
2292 DO i = 1, nb
2293 ii = i0 + i
2294 e_rhoa(ii) = e_rhoa(ii) + sc*w%vrho(1, i)
2295 e_rhob(ii) = e_rhob(ii) + sc*w%vrho(2, i)
2296 END DO
2297 IF (is_gga) THEN
2298 DO i = 1, nb
2299 ii = i0 + i
2300 e_ndrho(ii) = e_ndrho(ii) + sc*w%vsigma(2, i)*w%nd(i)
2301 e_ndrhoa(ii) = e_ndrhoa(ii) + &
2302 sc*(2.0_dp*w%vsigma(1, i) - w%vsigma(2, i))*w%nda(i)
2303 e_ndrhob(ii) = e_ndrhob(ii) + &
2304 sc*(2.0_dp*w%vsigma(3, i) - w%vsigma(2, i))*w%ndb(i)
2305 END DO
2306 END IF
2307 IF (is_mgga) THEN
2308 DO i = 1, nb
2309 ii = i0 + i
2310 e_tau_a(ii) = e_tau_a(ii) + sc*w%vtau(1, i)
2311 e_tau_b(ii) = e_tau_b(ii) + sc*w%vtau(2, i)
2312 END DO
2313 END IF
2314 IF (is_mgga .AND. has_laplace) THEN
2315 DO i = 1, nb
2316 ii = i0 + i
2317 e_laplace_rhoa(ii) = e_laplace_rhoa(ii) + sc*w%vlapl(1, i)
2318 e_laplace_rhob(ii) = e_laplace_rhob(ii) + sc*w%vlapl(2, i)
2319 END DO
2320 END IF
2321 END IF
2322 IF (grad_deriv >= 2) THEN
2323 DO i = 1, nb
2324 ii = i0 + i
2325 e_rhoa_rhoa(ii) = e_rhoa_rhoa(ii) + sc*w%v2rho2(1, i)
2326 e_rhoa_rhob(ii) = e_rhoa_rhob(ii) + sc*w%v2rho2(2, i)
2327 e_rhob_rhob(ii) = e_rhob_rhob(ii) + sc*w%v2rho2(3, i)
2328 END DO
2329 IF (is_gga) THEN
2330 DO i = 1, nb
2331 ii = i0 + i
2332 e_ndrho_rhoa(ii) = e_ndrho_rhoa(ii) + sc*w%v2rhosigma(2, i)*w%nd(i)
2333 e_ndrho_rhob(ii) = e_ndrho_rhob(ii) + sc*w%v2rhosigma(5, i)*w%nd(i)
2334 e_ndrhoa_rhoa(ii) = e_ndrhoa_rhoa(ii) + &
2335 sc*(2.0_dp*w%v2rhosigma(1, i) - w%v2rhosigma(2, i))*w%nda(i)
2336 e_ndrhoa_rhob(ii) = e_ndrhoa_rhob(ii) + &
2337 sc*(2.0_dp*w%v2rhosigma(4, i) - w%v2rhosigma(5, i))*w%nda(i)
2338 e_ndrhob_rhoa(ii) = e_ndrhob_rhoa(ii) + &
2339 sc*(2.0_dp*w%v2rhosigma(3, i) - w%v2rhosigma(2, i))*w%ndb(i)
2340 e_ndrhob_rhob(ii) = e_ndrhob_rhob(ii) + &
2341 sc*(2.0_dp*w%v2rhosigma(6, i) - w%v2rhosigma(5, i))*w%ndb(i)
2342 e_ndrho_ndrho(ii) = e_ndrho_ndrho(ii) + &
2343 sc*(w%vsigma(2, i) + w%nd(i)**2*w%v2sigma2(4, i))
2344 e_ndrho_ndrhoa(ii) = e_ndrho_ndrhoa(ii) + &
2345 sc*(2.0_dp*w%v2sigma2(2, i) - w%v2sigma2(4, i))*w%nd(i)*w%nda(i)
2346 e_ndrho_ndrhob(ii) = e_ndrho_ndrhob(ii) + &
2347 sc*(2.0_dp*w%v2sigma2(5, i) - w%v2sigma2(4, i))*w%nd(i)*w%ndb(i)
2348 e_ndrhoa_ndrhoa(ii) = e_ndrhoa_ndrhoa(ii) + &
2349 sc*(2.0_dp*w%vsigma(1, i) - w%vsigma(2, i) + w%nda(i)**2*( &
2350 4.0_dp*w%v2sigma2(1, i) - 4.0_dp*w%v2sigma2(2, i) + w%v2sigma2(4, i)))
2351 e_ndrhoa_ndrhob(ii) = e_ndrhoa_ndrhob(ii) + &
2352 sc*(4.0_dp*w%v2sigma2(3, i) - 2.0_dp*w%v2sigma2(2, i) - &
2353 2.0_dp*w%v2sigma2(5, i) + w%v2sigma2(4, i))*w%nda(i)*w%ndb(i)
2354 e_ndrhob_ndrhob(ii) = e_ndrhob_ndrhob(ii) + &
2355 sc*(2.0_dp*w%vsigma(3, i) - w%vsigma(2, i) + w%ndb(i)**2*( &
2356 4.0_dp*w%v2sigma2(6, i) - 4.0_dp*w%v2sigma2(5, i) + w%v2sigma2(4, i)))
2357 END DO
2358 END IF
2359 IF (is_mgga) THEN
2360 DO i = 1, nb
2361 ii = i0 + i
2362 e_rhoa_tau_a(ii) = e_rhoa_tau_a(ii) + sc*w%v2rhotau(1, i)
2363 e_rhoa_tau_b(ii) = e_rhoa_tau_b(ii) + sc*w%v2rhotau(2, i)
2364 e_rhob_tau_a(ii) = e_rhob_tau_a(ii) + sc*w%v2rhotau(3, i)
2365 e_rhob_tau_b(ii) = e_rhob_tau_b(ii) + sc*w%v2rhotau(4, i)
2366 e_ndrho_tau_a(ii) = e_ndrho_tau_a(ii) + sc*w%v2sigmatau(3, i)*w%nd(i)
2367 e_ndrho_tau_b(ii) = e_ndrho_tau_b(ii) + sc*w%v2sigmatau(4, i)*w%nd(i)
2368 e_ndrhoa_tau_a(ii) = e_ndrhoa_tau_a(ii) + &
2369 sc*(2.0_dp*w%v2sigmatau(1, i) - w%v2sigmatau(3, i))*w%nda(i)
2370 e_ndrhoa_tau_b(ii) = e_ndrhoa_tau_b(ii) + &
2371 sc*(2.0_dp*w%v2sigmatau(2, i) - w%v2sigmatau(4, i))*w%nda(i)
2372 e_ndrhob_tau_a(ii) = e_ndrhob_tau_a(ii) + &
2373 sc*(2.0_dp*w%v2sigmatau(5, i) - w%v2sigmatau(3, i))*w%ndb(i)
2374 e_ndrhob_tau_b(ii) = e_ndrhob_tau_b(ii) + &
2375 sc*(2.0_dp*w%v2sigmatau(6, i) - w%v2sigmatau(4, i))*w%ndb(i)
2376 e_tau_a_tau_a(ii) = e_tau_a_tau_a(ii) + sc*w%v2tau2(1, i)
2377 e_tau_a_tau_b(ii) = e_tau_a_tau_b(ii) + sc*w%v2tau2(2, i)
2378 e_tau_b_tau_b(ii) = e_tau_b_tau_b(ii) + sc*w%v2tau2(3, i)
2379 END DO
2380 END IF
2381 IF (is_mgga .AND. has_laplace) THEN
2382 DO i = 1, nb
2383 ii = i0 + i
2384 e_rhoa_laplace_rhoa(ii) = e_rhoa_laplace_rhoa(ii) + sc*w%v2rholapl(1, i)
2385 e_rhoa_laplace_rhob(ii) = e_rhoa_laplace_rhob(ii) + sc*w%v2rholapl(2, i)
2386 e_rhob_laplace_rhoa(ii) = e_rhob_laplace_rhoa(ii) + sc*w%v2rholapl(3, i)
2387 e_rhob_laplace_rhob(ii) = e_rhob_laplace_rhob(ii) + sc*w%v2rholapl(4, i)
2388 e_ndrho_laplace_rhoa(ii) = e_ndrho_laplace_rhoa(ii) + sc*w%v2sigmalapl(3, i)*w%nd(i)
2389 e_ndrho_laplace_rhob(ii) = e_ndrho_laplace_rhob(ii) + sc*w%v2sigmalapl(4, i)*w%nd(i)
2390 e_ndrhoa_laplace_rhoa(ii) = e_ndrhoa_laplace_rhoa(ii) + &
2391 sc*(2.0_dp*w%v2sigmalapl(1, i) - w%v2sigmalapl(3, i))*w%nda(i)
2392 e_ndrhoa_laplace_rhob(ii) = e_ndrhoa_laplace_rhob(ii) + &
2393 sc*(2.0_dp*w%v2sigmalapl(2, i) - w%v2sigmalapl(4, i))*w%nda(i)
2394 e_ndrhob_laplace_rhoa(ii) = e_ndrhob_laplace_rhoa(ii) + &
2395 sc*(2.0_dp*w%v2sigmalapl(5, i) - w%v2sigmalapl(3, i))*w%ndb(i)
2396 e_ndrhob_laplace_rhob(ii) = e_ndrhob_laplace_rhob(ii) + &
2397 sc*(2.0_dp*w%v2sigmalapl(6, i) - w%v2sigmalapl(4, i))*w%ndb(i)
2398 e_laplace_rhoa_laplace_rhoa(ii) = e_laplace_rhoa_laplace_rhoa(ii) + sc*w%v2lapl2(1, i)
2399 e_laplace_rhoa_laplace_rhob(ii) = e_laplace_rhoa_laplace_rhob(ii) + sc*w%v2lapl2(2, i)
2400 e_laplace_rhob_laplace_rhob(ii) = e_laplace_rhob_laplace_rhob(ii) + sc*w%v2lapl2(3, i)
2401 e_laplace_rhoa_tau_a(ii) = e_laplace_rhoa_tau_a(ii) + sc*w%v2lapltau(1, i)
2402 e_laplace_rhoa_tau_b(ii) = e_laplace_rhoa_tau_b(ii) + sc*w%v2lapltau(2, i)
2403 e_laplace_rhob_tau_a(ii) = e_laplace_rhob_tau_a(ii) + sc*w%v2lapltau(3, i)
2404 e_laplace_rhob_tau_b(ii) = e_laplace_rhob_tau_b(ii) + sc*w%v2lapltau(4, i)
2405 END DO
2406 END IF
2407 END IF
2408 IF (grad_deriv >= 3) THEN
2409 DO i = 1, nb
2410 ii = i0 + i
2411 e_rhoa_rhoa_rhoa(ii) = e_rhoa_rhoa_rhoa(ii) + sc*w%v3rho3(1, i)
2412 e_rhoa_rhoa_rhob(ii) = e_rhoa_rhoa_rhob(ii) + sc*w%v3rho3(2, i)
2413 e_rhoa_rhob_rhob(ii) = e_rhoa_rhob_rhob(ii) + sc*w%v3rho3(3, i)
2414 e_rhob_rhob_rhob(ii) = e_rhob_rhob_rhob(ii) + sc*w%v3rho3(4, i)
2415 END DO
2416 END IF
2417 END DO
2418!$OMP END DO
2419 END associate
2420
2421 END SUBROUTINE libxc_spin_polarized_calc
2422#endif
2423
2424END MODULE xc_libxc
static GRID_HOST_DEVICE int idx(const orbital a)
Return coset index of given orbital angular momentum.
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public marques2012
integer, save, public lehtola2018
represents keywords in an input
subroutine, public keyword_release(keyword)
releases the given keyword (see doc/ReferenceCounting.html)
subroutine, public keyword_create(keyword, location, name, description, usage, type_of_var, n_var, repeats, variants, default_val, default_l_val, default_r_val, default_lc_val, default_c_val, default_i_val, default_l_vals, default_r_vals, default_c_vals, default_i_vals, lone_keyword_val, lone_keyword_l_val, lone_keyword_r_val, lone_keyword_c_val, lone_keyword_i_val, lone_keyword_l_vals, lone_keyword_r_vals, lone_keyword_c_vals, lone_keyword_i_vals, enum_c_vals, enum_i_vals, enum, enum_strict, enum_desc, unit_str, citations, deprecation_notice, removed)
creates a keyword object
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_create(section, location, name, description, n_keywords, n_subsections, repeats, citations, deprecation_notice)
creates a list of keywords
subroutine, public section_add_keyword(section, keyword)
adds a keyword to the given section
subroutine, public section_add_subsection(section, subsection)
adds a subsection to the given section
recursive subroutine, public section_release(section)
releases the given keyword list (see doc/ReferenceCounting.html)
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
Module with functions to handle derivative descriptors. derivative description are strings have the f...
integer, parameter, public deriv_norm_drho
integer, parameter, public deriv_laplace_rhob
integer, parameter, public deriv_norm_drhoa
integer, parameter, public deriv_rhob
integer, parameter, public deriv_rhoa
integer, parameter, public deriv_tau
integer, parameter, public deriv_tau_b
integer, parameter, public deriv_tau_a
integer, parameter, public deriv_laplace_rhoa
integer, parameter, public deriv_rho
integer, parameter, public deriv_norm_drhob
integer, parameter, public deriv_laplace_rho
represent a group ofunctional derivatives
type(xc_derivative_type) function, pointer, public xc_dset_get_derivative(derivative_set, description, allocate_deriv)
returns the requested xc_derivative
Provides types for the management of the xc-functionals and their derivatives.
subroutine, public xc_derivative_get(deriv, split_desc, order, deriv_data, accept_null_data)
returns various information on the given derivative
Includes all necessary routines, functions and parameters from libxc. Provides CP2K routines/function...
calculates a functional from libxc and its derivatives
Definition xc_libxc.F:28
subroutine, public libxc_spin_unpolarized_info(libxc_params, reference, shortform, needs, max_deriv, print_warn, func_name_override)
info about the functional from libxc
Definition xc_libxc.F:375
subroutine, public libxc_spin_unpolarized_eval(rho_set, deriv_set, grad_deriv, libxc_params, func_name_override)
evaluates the functional from libxc
Definition xc_libxc.F:933
subroutine, public libxc_spin_polarized_info(libxc_params, reference, shortform, needs, max_deriv, print_warn, func_name_override)
info about the functional from libxc
Definition xc_libxc.F:489
subroutine, public libxc_release_workers()
Reads the external parameters of a LibXC functional from its input section.
Definition xc_libxc.F:899
subroutine, public libxc_spin_polarized_eval(rho_set, deriv_set, grad_deriv, libxc_params, func_name_override)
evaluates the functional from libxc
Definition xc_libxc.F:1191
subroutine, public libxc_version_info(version, compiled_version)
info about the LibXC version
Definition xc_libxc.F:598
subroutine, public libxc_add_sections(section)
...
Definition xc_libxc.F:269
logical function, public libxc_check_existence_in_libxc(libxc_params)
This function checks whether a functional name belongs to LibXC.
Definition xc_libxc.F:204
integer function, public libxc_get_reference_length(libxc_params, lsd)
This function returns the maximum length of the reference string for a given LibXC functional.
Definition xc_libxc.F:225
subroutine, public libxc_library_reference(reference, doi)
Returns the citation LibXC asks for the library itself.
Definition xc_libxc.F:618
contains the structure
contains the structure
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
represent a keyword in the input
represent a section of the input file
A derivative set contains the different derivatives of a xc-functional in form of a linked list.
represent a derivative of a functional
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