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