Octopus
xc.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21#if defined(HAVE_CUDA)
22#define HAVE_ACCEL 1
23#endif
24
25module xc_oct_m
26 use accel_oct_m
28 use comm_oct_m
29 use debug_oct_m
34 use global_oct_m
35 use grid_oct_m
36 use io_oct_m
38 use iso_c_binding
39 use, intrinsic :: iso_fortran_env
44 use math_oct_m
45 use mesh_oct_m
48 use mpi_oct_m
50 use parser_oct_m
53 use space_oct_m
56 use types_oct_m
58 use xc_cam_oct_m
59 use xc_f03_lib_m
60#ifdef HAVE_LIBXC_FUNCS
61 use xc_f03_funcs_m
62#endif
63 use xc_fbe_oct_m
66 use xc_lrc_oct_m
67
68 implicit none
69
70 private
71 public :: &
72 xc_t, &
74 xc_init, &
77 xc_end, &
90
91 ! A Structure that contains the quantities needed to compute the functionals
93 real(real64), pointer :: rho(:,:) ! A pointer to the full density
94
95 real(real64), allocatable :: dens(:,:) ! Density (in the local frame of the magnetization)
96 real(real64), allocatable :: gdens(:,:,:) ! Gradient of the density
97 real(real64), allocatable :: ldens(:,:) ! Laplacian of the density
98 real(real64), allocatable :: tau(:,:) ! Kinetic energy density
99
100 type(accel_mem_t) :: dens_buff ! GPU buffer: extracted density in libxc layout (spin_channels x np)
101 type(accel_mem_t) :: zk_buff ! GPU buffer: energy per unit volume
102 type(accel_mem_t) :: dedd_buff ! GPU buffer: dE/dn
103 type(accel_mem_t) :: sigma_buff ! GPU buffer: contracted density gradient (1 or 3 x np)
104 type(accel_mem_t) :: vsigma_buff ! GPU buffer: dE/dsigma
105 type(accel_mem_t) :: tau_buff ! GPU buffer: kinetic energy density (spin_channels x np)
106 type(accel_mem_t) :: ldens_buff ! GPU buffer: Laplacian of the density (spin_channels x np)
107 type(accel_mem_t) :: dedtau_buff ! GPU buffer: dE/dtau
108 type(accel_mem_t) :: dedldens_buff ! GPU buffer: dE/dlaplacian
109
110 ! Persistent pinned (page-locked) host staging buffers in libxc layout.
111 real(real64), pointer, contiguous :: hbuf_dens(:,:) => null()
112 real(real64), pointer, contiguous :: hbuf_sigma(:,:) => null()
113 real(real64), pointer, contiguous :: hbuf_ldens(:,:) => null()
114 real(real64), pointer, contiguous :: hbuf_tau(:,:) => null()
115 real(real64), pointer, contiguous :: hbuf_zk(:) => null()
116 real(real64), pointer, contiguous :: hbuf_dedd(:,:) => null()
117 real(real64), pointer, contiguous :: hbuf_vsigma(:,:) => null()
118 real(real64), pointer, contiguous :: hbuf_dedldens(:,:) => null()
119 real(real64), pointer, contiguous :: hbuf_dedtau(:,:) => null()
121 ! Density correction buffers: populated before XC if corrections are needed on GPU.
122 type(accel_mem_t) :: buff_rho_core ! GPU copy of st%rho_core (np)
123 type(accel_mem_t) :: buff_frozen_rho ! GPU copy of st%frozen_rho (np x nspin)
124 integer :: frozen_rho_np = 0 ! leading dimension of frozen_rho on CPU (= gr%np)
125 real(real64) :: amaldi_factor = m_one ! Amaldi scaling factor applied to dens_buff (1.0 if inactive)
126 ! True when dens_buff was pre-populated from st%buff_density by xc_update_internal_quantities.
127 ! False when xc_compute_vxc must upload CPU l_dens to dens_buff each block.
128 logical :: dens_buff_prefilled = .false.
129 end type internal_quantities_t
130
131
132 type xc_t
133 private
134 integer, public :: family
135 integer, public :: flags
136 integer, public :: kernel_family
137 type(xc_functional_t), public :: functional(2,2)
139
140 type(xc_functional_t), public :: kernel(2,2)
141 type(xc_cam_t), public :: cam
142 type(xc_lrc_t), public :: lrc
143
144 logical, public :: use_gi_ked
145 integer, public :: xc_density_correction
146 logical, public :: xcd_optimize_cutoff
147 real(real64), public :: xcd_ncutoff
148 logical, public :: xcd_minimum
149 logical, public :: xcd_normalize
150 logical, public :: parallel
151 logical, public :: xc_on_host
152
153 type(internal_quantities_t), public :: quantities
154
155 contains
156 procedure :: compute_exchange => xc_compute_exchange
157
158 end type xc_t
159
161 real(real64), public, parameter :: xc_tiny = 1.0e-12_real64
162
163 integer, public, parameter :: &
164 LR_NONE = 0, &
165 lr_x = 1
166
167contains
168
169 ! ---------------------------------------------------------
170 subroutine xc_write_info(xcs, iunit, namespace)
171 type(xc_t), intent(in) :: xcs
172 integer, optional, intent(in) :: iunit
173 type(namespace_t), optional, intent(in) :: namespace
174
175 integer :: ifunc
176
177 push_sub(xc_write_info)
178
179 write(message(1), '(a)') "Exchange-correlation:"
180 call messages_info(1, iunit=iunit, namespace=namespace)
181
182 do ifunc = func_x, func_c
183 call xc_functional_write_info(xcs%functional(ifunc, 1), iunit, namespace)
184 end do
185
186 if (abs(xcs%cam%alpha) + abs(xcs%cam%beta) > m_epsilon) then
187 write(message(1), '(1x)')
188 write(message(2), '(a,f8.5)') "Exact exchange mixing = ", xcs%cam%alpha
189 write(message(3), '(a,f8.5)') "Exact exchange for short-range beta = ", xcs%cam%beta
190 write(message(4), '(a,f8.5)') "Exact exchange range-separate omega = ", xcs%cam%omega
191 call messages_info(4, iunit=iunit, namespace=namespace)
192 end if
194
196 end subroutine xc_write_info
198 ! ---------------------------------------------------------
199 subroutine xc_write_fxc_info(xcs, iunit, namespace)
200 type(xc_t), intent(in) :: xcs
201 integer, optional, intent(in) :: iunit
202 type(namespace_t), optional, intent(in) :: namespace
204 integer :: ifunc
205
208 write(message(1), '(a)') "Exchange-correlation kernel:"
209 call messages_info(1, iunit=iunit, namespace=namespace)
211 do ifunc = func_x, func_c
212 call xc_functional_write_info(xcs%kernel(ifunc, 1), iunit, namespace)
213 end do
215 pop_sub(xc_write_fxc_info)
216 end subroutine xc_write_fxc_info
219 ! ---------------------------------------------------------
220 subroutine xc_init_device_support(xcs, namespace)
221 type(xc_t), intent(inout) :: xcs
222 type(namespace_t), intent(in) :: namespace
224 push_sub(xc_init_device_support)
225
226 xcs%xc_on_host = .not. xc_is_using_device(namespace)
231 ! ---------------------------------------------------------
233 logical function xc_is_using_device(namespace)
234 type(namespace_t), intent(in) :: namespace
236 logical :: xc_force_cpu
238 push_sub(xc_is_using_device)
240 !%Variable XCForceFunctionalsOnCPU
241 !%Type logical
242 !%Default no
243 !%Section Hamiltonian::XC
244 !%Description
245 !% By setting this variable to <tt>yes</tt>, you force Octopus to evaluate XC functionals
246 !% on the CPU, even if CUDA/HIP support is available.
247 !%End
248 call parse_variable(namespace, 'XCForceFunctionalsOnCPU', .false., xc_force_cpu)
249
250#if defined(HAVE_LIBXC_DEVICE) && defined(HAVE_ACCEL)
252 if (accel_is_enabled()) then
253 xc_is_using_device = .not. xc_force_cpu
254 end if
255#elif defined(HAVE_LIBXC_DEVICE) && !defined(HAVE_ACCEL)
256 if(.not. xc_force_cpu) then
257 call messages_warning("Libxc has device support but no accelerator support is enabled in Octopus.", namespace=namespace)
258 end if
259 xc_is_using_device = .false.
260#else
261 xc_is_using_device = .false.
262#endif
263
264 pop_sub(xc_is_using_device)
266
267 ! ---------------------------------------------------------
268 subroutine xc_init(xcs, namespace, ndim, periodic_dim, nel, x_id, c_id, xk_id, ck_id, hartree_fock, ispin)
269 type(xc_t), intent(out) :: xcs
270 type(namespace_t), intent(in) :: namespace
271 integer, intent(in) :: ndim
272 integer, intent(in) :: periodic_dim
273 real(real64), intent(in) :: nel
274 integer, intent(in) :: x_id
275 integer, intent(in) :: c_id
276 integer, intent(in) :: xk_id
277 integer, intent(in) :: ck_id
278 logical, intent(in) :: hartree_fock
279 integer, intent(in) :: ispin
280
281 integer :: isp, xc_major, xc_minor, xc_micro
282 logical :: ll
283 type(block_t) :: blk
284 type(xc_cam_t) :: cam_ext
285
286 push_sub(xc_init)
287
288 call xc_f03_version(xc_major, xc_minor, xc_micro)
289
290 xcs%family = 0
291 xcs%flags = 0
292 xcs%kernel_family = 0
293
294 call parse()
295
296 call xc_lrc_init(xcs%lrc, namespace, ndim, periodic_dim)
297
298 call xc_init_device_support(xcs, namespace)
299
300 ! 1D/2D functionals (e.g. lda_x_1d_soft) call xc_integrate() which uses malloc() inside
301 ! GPU kernels. With large meshes this exhausts the CUDA device heap (cudaErrorIllegalAddress).
302 if (ndim /= 3) xcs%xc_on_host = .true.
303
304 !we also need XC functionals that do not depend on the current
305 !get both spin-polarized and unpolarized
306
307 ! TODO: check that nel should not be spin polarized here
308 do isp = 1, 2
309
310 call xc_functional_init(xcs%functional(func_x, isp), namespace, x_id, ndim, nel, isp, xcs%xc_on_host)
311 call xc_functional_init(xcs%functional(func_c, isp), namespace, c_id, ndim, nel, isp, xcs%xc_on_host)
312
313 call xc_functional_init(xcs%kernel(func_x, isp), namespace, xk_id, ndim, nel, isp, xcs%xc_on_host)
314 call xc_functional_init(xcs%kernel(func_c, isp), namespace, ck_id, ndim, nel, isp, xcs%xc_on_host)
316 end do
317
318 xcs%family = ior(xcs%family, xcs%functional(func_x,1)%family)
319 xcs%family = ior(xcs%family, xcs%functional(func_c,1)%family)
320
321 xcs%flags = ior(xcs%flags, xcs%functional(func_x,1)%flags)
322 xcs%flags = ior(xcs%flags, xcs%functional(func_c,1)%flags)
323
324 xcs%kernel_family = ior(xcs%kernel_family, xcs%kernel(func_x,1)%family)
325 xcs%kernel_family = ior(xcs%kernel_family, xcs%kernel(func_c,1)%family)
326
327
328 if (xc_is_not_size_consistent(xcs, namespace) .and. periodic_dim > 0) then
329 message(1) = "Cannot perform a periodic calculation with a functional"
330 message(2) = "that depends on the number of electrons."
331 call messages_fatal(2, namespace=namespace)
332 end if
333
334 ! Take care of hybrid functionals (they appear in the correlation functional)
335 xcs%cam = cam_null
336
337 ll = (hartree_fock) &
338 .or.(xcs%functional(func_x,1)%id == xc_oep_x) &
339 .or. family_is_hybrid(xcs)
340 if (ll) then
341 if ((xcs%functional(func_x,1)%id /= 0).and.(xcs%functional(func_x,1)%id /= xc_oep_x)) then
342 message(1) = "You cannot use an exchange functional when performing"
343 message(2) = "a Hartree-Fock calculation or using a hybrid functional."
344 call messages_fatal(2, namespace=namespace)
345 end if
346
347 if (periodic_dim == ndim) then
348 call messages_experimental("Fock operator (Hartree-Fock, OEP, hybrids) in fully periodic systems", namespace=namespace)
349 end if
350
351 ! get the mixing coefficient for hybrids
352 if (family_is_hybrid(xcs)) then
353 if( .not. cam_ext%is_null() ) call set_hybrid_params(xcs, namespace, cam_ext)
354 call xc_f03_hyb_cam_coef(xcs%functional(func_c,1)%conf, xcs%cam%omega, &
355 xcs%cam%alpha, xcs%cam%beta)
356 call xc_f03_hyb_cam_coef(xcs%functional(func_c,2)%conf, xcs%cam%omega, &
357 xcs%cam%alpha, xcs%cam%beta)
358 else
359 ! we are doing Hartree-Fock plus possibly a correlation functional
360 xcs%cam = cam_exact_exchange
361 end if
362
363 ! reset certain variables
364 xcs%functional(func_x,1)%family = xc_family_oep
365 xcs%functional(func_x,1)%id = xc_oep_x
366 xcs%functional(func_x,2)%family = xc_family_oep
367 xcs%functional(func_x,2)%id = xc_oep_x
368 if (.not. hartree_fock) then
369 xcs%family = ior(xcs%family, xc_family_oep)
370 end if
371 end if
372
373 if (in_family(xcs%family, [xc_family_lca])) then
374 call messages_not_implemented("LCA current functionals", namespace) ! not even in libxc!
375 end if
376
377 call messages_obsolete_variable(namespace, 'MGGAimplementation')
378 call messages_obsolete_variable(namespace, 'CurrentInTau', 'XCUseGaugeIndependentKED')
379
380 if (xcs%functional(func_x, 1)%id == xc_mgga_x_tb09 .and. periodic_dim /= 3) then
381 message(1) = "mgga_x_tb09 functional can only be used for 3D periodic systems"
382 call messages_fatal(1, namespace=namespace)
383 end if
384
385 if (family_is_mgga(xcs%family) .or. family_is_nc_mgga(xcs%family)) then
386 !%Variable XCUseGaugeIndependentKED
387 !%Type logical
388 !%Default yes
389 !%Section Hamiltonian::XC
390 !%Description
391 !% If true, when evaluating the XC functional, a term including the (paramagnetic or total) current
392 !% is added to the kinetic-energy density such as to make it gauge-independent.
393 !% Applies only to meta-GGA (and hybrid meta-GGA) functionals.
394 !%End
395 call parse_variable(namespace, 'XCUseGaugeIndependentKED', .true., xcs%use_gi_ked)
396 end if
397
398 pop_sub(xc_init)
399
400 contains
401
402 subroutine parse()
403
404 push_sub(xc_init.parse)
405
406 ! the values of x_id, c_id, xk_id, and c_id are read outside the routine
407
408 !%Variable XCDensityCorrection
409 !%Type integer
410 !%Default none
411 !%Section Hamiltonian::XC::DensityCorrection
412 !%Description
413 !% This variable controls the long-range correction of the XC
414 !% potential using the <a href=http://arxiv.org/abs/1107.4339>XC density representation</a>.
415 !%Option none 0
416 !% No correction is applied.
417 !%Option long_range_x 1
418 !% The correction is applied to the exchange potential.
419 !%End
420 call parse_variable(namespace, 'XCDensityCorrection', lr_none, xcs%xc_density_correction)
421
422 if (xcs%xc_density_correction /= lr_none) then
423 call messages_experimental('XC density correction', namespace=namespace)
424
425 if(ispin /= unpolarized) then
426 call messages_not_implemented('XCDensityCorrection with SpinComponents /= unpolarized', namespace)
427 end if
428
429 !%Variable XCDensityCorrectionOptimize
430 !%Type logical
431 !%Default true
432 !%Section Hamiltonian::XC::DensityCorrection
433 !%Description
434 !% When enabled, the density cutoff will be
435 !% optimized to replicate the boundary conditions of the exact
436 !% XC potential. If the variable is set to no, the value of
437 !% the cutoff must be given by <tt>XCDensityCorrectionCutoff</tt>
438 !% variable.
439 !%End
440 call parse_variable(namespace, 'XCDensityCorrectionOptimize', .true., xcs%xcd_optimize_cutoff)
441
442 !%Variable XCDensityCorrectionCutoff
443 !%Type float
444 !%Default 0.0
445 !%Section Hamiltonian::XC::DensityCorrection
446 !%Description
447 !% The value of the cutoff applied to the XC density.
448 !%End
449 call parse_variable(namespace, 'XCDensityCorrectionCutoff', m_zero, xcs%xcd_ncutoff)
450
451 !%Variable XCDensityCorrectionMinimum
452 !%Type logical
453 !%Default true
454 !%Section Hamiltonian::XC::DensityCorrection
455 !%Description
456 !% When enabled, the cutoff optimization will
457 !% return the first minimum of the <math>q_{xc}</math> function if it does
458 !% not find a value of -1 (<a href=http://arxiv.org/abs/1107.4339>details</a>).
459 !% This is required for atoms or small
460 !% molecules, but may cause numerical problems.
461 !%End
462 call parse_variable(namespace, 'XCDensityCorrectionMinimum', .true., xcs%xcd_minimum)
463
464 !%Variable XCDensityCorrectionNormalize
465 !%Type logical
466 !%Default true
467 !%Section Hamiltonian::XC::DensityCorrection
468 !%Description
469 !% When enabled, the correction will be
470 !% normalized to reproduce the exact boundary conditions of
471 !% the XC potential.
472 !%End
473 call parse_variable(namespace, 'XCDensityCorrectionNormalize', .true., xcs%xcd_normalize)
474
475 end if
476
477 !%Variable ParallelXC
478 !%Type logical
479 !%Default true
480 !%Section Execution::Parallelization
481 !%Description
482 !% When enabled, additional parallelization
483 !% will be used for the calculation of the XC functional.
484 !%End
485 call messages_obsolete_variable(namespace, 'XCParallel', 'ParallelXC')
486 call parse_variable(namespace, 'ParallelXC', .true., xcs%parallel)
487
488
489 !%Variable HybridCAMParameters
490 !%Type block
491 !%Section Hamiltonian::XC
492 !%Description
493 !% This variable specifies the <math>\alpha, \beta, \omega</math> for CAM-type
494 !% hybrid functionals. Defaults are zero.
495 !%End
496 cam_ext = cam_null
497
498 if(parse_block(namespace, 'HybridCamParameters', blk) == 0) then
499 call parse_block_float(blk, 0, 0, cam_ext%alpha)
500 call parse_block_float(blk, 0, 1, cam_ext%beta)
501 call parse_block_float(blk, 0, 2, cam_ext%omega)
502 call parse_block_end(blk)
503 end if
504
505 if(.not. cam_ext%is_null()) then
506 call cam_ext%print(namespace, msg="Info: Setting external CAM parameters")
507 endif
508
509 pop_sub(xc_init.parse)
510 end subroutine parse
511
512 end subroutine xc_init
513
514
515 ! ---------------------------------------------------------
516 subroutine xc_end(xcs)
517 type(xc_t), intent(inout) :: xcs
518
519 integer :: isp
520
521 push_sub(xc_end)
522
523 do isp = 1, 2
524 call xc_functional_end(xcs%functional(func_x, isp))
525 call xc_functional_end(xcs%functional(func_c, isp))
526 call xc_functional_end(xcs%kernel(func_x, isp))
527 call xc_functional_end(xcs%kernel(func_c, isp))
528 end do
529 xcs%family = 0
530 xcs%flags = 0
531
532 ! Free the persistent host staging buffers (see internal_quantities_t), allocated
533 ! with the hardware-aware allocator in xc_compute_vxc.
534 if (associated(xcs%quantities%hbuf_dens)) then
535 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dens(1,1)), size(xcs%quantities%hbuf_dens, kind=int64)*8_int64)
536 nullify(xcs%quantities%hbuf_dens)
537 end if
538 if (associated(xcs%quantities%hbuf_sigma)) then
539 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_sigma(1,1)), size(xcs%quantities%hbuf_sigma, kind=int64)*8_int64)
540 nullify(xcs%quantities%hbuf_sigma)
541 end if
542 if (associated(xcs%quantities%hbuf_ldens)) then
543 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_ldens(1,1)), size(xcs%quantities%hbuf_ldens, kind=int64)*8_int64)
544 nullify(xcs%quantities%hbuf_ldens)
545 end if
546 if (associated(xcs%quantities%hbuf_tau)) then
547 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_tau(1,1)), size(xcs%quantities%hbuf_tau, kind=int64)*8_int64)
548 nullify(xcs%quantities%hbuf_tau)
549 end if
550 if (associated(xcs%quantities%hbuf_zk)) then
551 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_zk(1)), size(xcs%quantities%hbuf_zk, kind=int64)*8_int64)
552 nullify(xcs%quantities%hbuf_zk)
553 end if
554 if (associated(xcs%quantities%hbuf_dedd)) then
555 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dedd(1,1)), size(xcs%quantities%hbuf_dedd, kind=int64)*8_int64)
556 nullify(xcs%quantities%hbuf_dedd)
557 end if
558 if (associated(xcs%quantities%hbuf_vsigma)) then
559 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_vsigma(1,1)), size(xcs%quantities%hbuf_vsigma, kind=int64)*8_int64)
560 nullify(xcs%quantities%hbuf_vsigma)
561 end if
562 if (associated(xcs%quantities%hbuf_dedldens)) then
563 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dedldens(1,1)), &
564 size(xcs%quantities%hbuf_dedldens, kind=int64)*8_int64)
565 nullify(xcs%quantities%hbuf_dedldens)
566 end if
567 if (associated(xcs%quantities%hbuf_dedtau)) then
568 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dedtau(1,1)), size(xcs%quantities%hbuf_dedtau, kind=int64)*8_int64)
569 nullify(xcs%quantities%hbuf_dedtau)
570 end if
571
572 pop_sub(xc_end)
573 end subroutine xc_end
574
575 ! ---------------------------------------------------------
580 logical pure function xc_is_orbital_dependent(xcs)
581 type(xc_t), intent(in) :: xcs
582
583 xc_is_orbital_dependent = family_is_hybrid(xcs) .or. &
584 in_family(xcs%functional(func_x,1)%family, [xc_family_oep]) .or. &
585 in_family(xcs%family, [xc_family_mgga, xc_family_nc_mgga])
586
587 end function xc_is_orbital_dependent
588
589 ! ---------------------------------------------------------
591 pure logical function family_is_gga(family, only_collinear)
592 integer, intent(in) :: family
593 logical, optional, intent(in) :: only_collinear
594
595 if(optional_default(only_collinear, .false.)) then
596 family_is_gga = in_family(family, [xc_family_gga, xc_family_hyb_gga, &
597 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc])
598 else
599 family_is_gga = in_family(family, [xc_family_gga, xc_family_hyb_gga, &
600 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc, xc_family_nc_mgga])
601 end if
602 end function family_is_gga
603
604 !----------------------------------------------------------------------
609 pure logical function family_is_supported(family)
610 integer, intent(in) :: family
611
612 family_is_supported = in_family(family, [xc_family_lda, xc_family_hyb_lda, xc_family_gga, xc_family_hyb_gga, &
613 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc])
614 end function family_is_supported
615
616 ! ---------------------------------------------------------
618 pure logical function family_is_mgga(family, only_collinear)
619 integer, intent(in) :: family
620 logical, optional, intent(in) :: only_collinear
621
622 if(optional_default(only_collinear, .false.)) then
623 family_is_mgga = in_family(family, [xc_family_mgga, xc_family_hyb_mgga])
624 else
625 family_is_mgga = in_family(family, [xc_family_mgga, xc_family_hyb_mgga, xc_family_nc_mgga])
626 end if
627 end function family_is_mgga
628
629 pure logical function family_is_nc_mgga(family)
630 integer, intent(in) :: family
631
632 family_is_nc_mgga = bitand(family, xc_family_nc_mgga) /= 0
633 end function family_is_nc_mgga
634
635 ! ---------------------------------------------------------
637 logical pure function family_is_mgga_with_exc(xcs)
638 type(xc_t), intent(in) :: xcs
639
640 integer :: ixc
641
643 do ixc = 1, 2
644 if (in_family(xcs%functional(ixc, 1)%family, [xc_family_mgga, xc_family_hyb_mgga, xc_family_nc_mgga]) &
645 .and. xc_functional_is_energy_functional(xcs%functional(ixc, 1))) then
647 end if
648 end do
649 end function family_is_mgga_with_exc
650
652 logical pure function family_is_hybrid(xcs)
653 type(xc_t), intent(in) :: xcs
654
655 integer :: ixc
656
657 family_is_hybrid = .false.
658 do ixc = 1, 2
659 if (in_family(xcs%functional(ixc, 1)%family, [xc_family_hyb_lda, xc_family_hyb_gga, xc_family_hyb_mgga])) then
661 end if
662 end do
663 end function family_is_hybrid
665 pure logical function in_family(family, xc_families)
666 integer, intent(in) :: family
667 integer, intent(in) :: xc_families(:)
668
669 in_family = bitand(family, sum(xc_families)) /= 0
670 end function in_family
671
673 logical function xc_compute_exchange(xc, theory_level)
674 class(xc_t), intent(in) :: xc
675 integer, intent(in) :: theory_level
676
677 integer, parameter :: exchange_theory_level(3) = [hartree, hartree_fock, rdmft]
678
679 push_sub(xc_compute_exchange)
680
681 xc_compute_exchange = any(exchange_theory_level == theory_level) .or. &
682 (theory_level == generalized_kohn_sham_dft .and. family_is_hybrid(xc)) .or. &
683 (xc%functional(func_x, 1)%id == xc_oep_x_slater) .or. &
684 (bitand(xc%family, xc_family_oep) /= 0)
685
686 pop_sub(xc_compute_exchange)
687
688 end function xc_compute_exchange
689
690 ! ---------------------------------------------------------
692 subroutine set_hybrid_params(xcs, namespace, cam_ext)
693 type(xc_t), intent(inout) :: xcs
694 type(namespace_t), intent(in) :: namespace
695 type(xc_cam_t), intent(in) :: cam_ext
696
697 real(real64), parameter :: default_alpha_pbe0 = 0.25_real64
698 real(real64) :: parameters(3)
699
700 push_sub(set_hybrid_params)
701
702 ! LibXC expects an array of reals, ordered [alpha, beta, omega]
703 parameters = cam_ext%as_array()
704 xcs%cam%alpha = parameters(1)
705
706 select case(xcs%functional(func_c, 1)%id)
707
708 case(xc_hyb_gga_xc_pbeh, xc_hyb_lda_xc_lda0) ! original PBE0/LDA0 in libxc
709 if(parameters(1) < m_zero) parameters(1) = default_alpha_pbe0
710 call xc_f03_func_set_ext_params(xcs%functional(func_c, 1)%conf, parameters)
711 call xc_f03_func_set_ext_params(xcs%functional(func_c, 2)%conf, parameters)
712 write(message(1), '(a,f6.3,a)') 'Info: Setting mixing parameter (' , parameters(1) ,').'
713 call messages_info(1)
714
715 case(xc_hyb_gga_xc_cam_pbeh, xc_hyb_lda_xc_cam_lda0)
716 xcs%cam%beta = parameters(2)
717 xcs%cam%omega = parameters(3)
718 call xc_f03_func_set_ext_params(xcs%functional(func_c, 1)%conf, parameters)
719 call xc_f03_func_set_ext_params(xcs%functional(func_c, 2)%conf, parameters)
720 ! check parameters
721 call xc_f03_hyb_cam_coef(xcs%functional(func_c,1)%conf, xcs%cam%omega, &
722 xcs%cam%alpha, xcs%cam%beta)
723 call xc_f03_hyb_cam_coef(xcs%functional(func_c,2)%conf, xcs%cam%omega, &
724 xcs%cam%alpha, xcs%cam%beta)
725 call xcs%cam%print(namespace, msg="Setting CAM parameters:")
726
727 case default
728 assert(.false.)
729
730 end select
731
732 pop_sub(set_hybrid_params)
733 end subroutine set_hybrid_params
734
735 ! ---------------------------------------------------------
737 logical function xc_is_not_size_consistent(xcs, namespace)
738 type(xc_t), intent(in) :: xcs
739 type(namespace_t), intent(in) :: namespace
740
741 xc_is_not_size_consistent = xc_functional_is_not_size_consistent(xcs%functional(func_x,1), namespace) &
742 .or. xc_functional_is_not_size_consistent(xcs%functional(func_c,1), namespace)
743 end function xc_is_not_size_consistent
744
745 ! ---------------------------------------------------------
747 logical pure function xc_is_energy_functional(xcs)
748 type(xc_t), intent(in) :: xcs
749 xc_is_energy_functional = xc_functional_is_energy_functional(xcs%functional(func_x,1)) &
750 .or. xc_functional_is_energy_functional(xcs%functional(func_c,1))
751 end function xc_is_energy_functional
752
753end module xc_oct_m
754
755
756!! Local Variables:
757!! mode: f90
758!! coding: utf-8
759!! End:
pure logical function, public accel_is_enabled()
Definition: accel.F90:403
This module contains interfaces for routines in allocate_hardware_aware.c.
subroutine, public deallocate_hardware_aware(array, size)
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
integer, parameter, public unpolarized
Parameters...
real(real64), parameter, public m_zero
Definition: global.F90:200
integer, parameter, public hartree_fock
Definition: global.F90:250
real(real64), parameter, public m_epsilon
Definition: global.F90:216
real(real64), parameter, public m_one
Definition: global.F90:201
This module implements the underlying real-space grid.
Definition: grid.F90:119
Definition: io.F90:116
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
character(len=512), private msg
Definition: messages.F90:167
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:525
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1000
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1040
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:623
This module handles spin dimensions of the states and the k-point distribution.
This module defines the unit system, used for input and output.
type(xc_cam_t), parameter, public cam_null
All CAM parameters set to zero.
Definition: xc_cam.F90:152
type(xc_cam_t), parameter, public cam_exact_exchange
Use only Hartree Fock exact exchange.
Definition: xc_cam.F90:155
subroutine, public xc_functional_write_info(functl, iunit, namespace)
Write functional information.
subroutine, public xc_functional_init(functl, namespace, id, ndim, nel, spin_channels, functionals_on_cpu)
integer, parameter, public xc_family_nc_mgga
integer, parameter, public xc_oep_x
Exact exchange.
subroutine, public xc_functional_end(functl)
integer, parameter, public func_c
integer, parameter, public func_x
subroutine, public xc_lrc_init(this, namespace, dim, periodic_dim)
Definition: xc_lrc.F90:146
Definition: xc.F90:120
subroutine, public xc_write_info(xcs, iunit, namespace)
Definition: xc.F90:266
subroutine, public xc_init(xcs, namespace, ndim, periodic_dim, nel, x_id, c_id, xk_id, ck_id, hartree_fock, ispin)
Definition: xc.F90:353
pure logical function, public family_is_mgga(family, only_collinear)
Is the xc function part of the mGGA family.
Definition: xc.F90:703
subroutine set_hybrid_params(xcs, namespace, cam_ext)
Sets external parameters for some hybrid functionals.
Definition: xc.F90:777
pure logical function, public family_is_gga(family, only_collinear)
Is the xc function part of the GGA family.
Definition: xc.F90:676
logical pure function, public family_is_mgga_with_exc(xcs)
Is the xc function part of the mGGA family with an energy functional.
Definition: xc.F90:722
logical function, public xc_is_using_device(namespace)
Check if XC will run on device (parses config and checks availability)
Definition: xc.F90:329
subroutine, public xc_end(xcs)
Definition: xc.F90:601
logical pure function, public xc_is_energy_functional(xcs)
Is one of the x or c functional is not an energy functional.
Definition: xc.F90:832
logical pure function, public family_is_hybrid(xcs)
Returns true if the functional is an hybrid functional.
Definition: xc.F90:737
logical function, public xc_is_not_size_consistent(xcs, namespace)
Is one of the x or c functional is not size consistent.
Definition: xc.F90:822
subroutine, public xc_init_device_support(xcs, namespace)
Definition: xc.F90:316
integer, parameter, public lr_x
Definition: xc.F90:258
pure logical function, public family_is_nc_mgga(family)
Definition: xc.F90:714
logical function xc_compute_exchange(xc, theory_level)
Theory levels and functionals for which exacy exchange is required.
Definition: xc.F90:758
pure logical function, public family_is_supported(family)
Is the xc family internally supported by Octopus.
Definition: xc.F90:694
pure logical function, public in_family(family, xc_families)
Definition: xc.F90:750
subroutine, public xc_write_fxc_info(xcs, iunit, namespace)
Definition: xc.F90:295
logical pure function, public xc_is_orbital_dependent(xcs)
Is the xc family orbital dependent.
Definition: xc.F90:665
Coulomb-attenuating method parameters, used in the partitioning of the Coulomb potential into a short...
Definition: xc_cam.F90:141
int true(void)
subroutine parse()
Definition: xc.F90:487