38 use,
intrinsic :: iso_fortran_env
59#ifdef HAVE_LIBXC_FUNCS
92 real(real64),
pointer :: rho(:,:)
94 real(real64),
allocatable :: dens(:,:)
95 real(real64),
allocatable :: gdens(:,:,:)
96 real(real64),
allocatable :: ldens(:,:)
97 real(real64),
allocatable :: tau(:,:)
99 type(accel_mem_t) :: dens_buff
100 type(accel_mem_t) :: zk_buff
101 type(accel_mem_t) :: dedd_buff
102 type(accel_mem_t) :: sigma_buff
103 type(accel_mem_t) :: vsigma_buff
104 type(accel_mem_t) :: tau_buff
105 type(accel_mem_t) :: ldens_buff
106 type(accel_mem_t) :: dedtau_buff
107 type(accel_mem_t) :: dedldens_buff
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()
121 type(accel_mem_t) :: buff_rho_core
122 type(accel_mem_t) :: buff_frozen_rho
123 integer :: frozen_rho_np = 0
124 real(real64) :: amaldi_factor =
m_one
127 logical :: dens_buff_prefilled = .false.
133 integer,
public :: family
134 integer,
public :: flags
135 integer,
public :: kernel_family
136 type(xc_functional_t),
allocatable,
public :: functional(:,:)
139 type(xc_functional_t),
allocatable,
public :: kernel(:,:)
140 type(xc_cam_t),
public :: cam
141 type(xc_lrc_t),
public :: lrc
143 logical,
public :: use_gi_ked
144 logical,
public :: usexcnhat
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
153 type(internal_quantities_t),
public :: quantities
161 real(real64),
public,
parameter :: xc_tiny = 1.0e-12_real64
163 integer,
public,
parameter :: &
172 integer,
optional,
intent(in) :: iunit
179 write(
message(1),
'(a)')
"Exchange-correlation:"
186 if (abs(xcs%cam%alpha) + abs(xcs%cam%beta) >
m_epsilon)
call xcs%cam%print(namespace, iunit=iunit)
194 integer,
optional,
intent(in) :: iunit
201 write(
message(1),
'(a)')
"Exchange-correlation kernel:"
214 type(
xc_t),
intent(inout) :: xcs
229 logical :: xc_force_cpu
241 call parse_variable(namespace,
'XCForceFunctionalsOnCPU', .false., xc_force_cpu)
243#if defined(HAVE_LIBXC_DEVICE) && defined(HAVE_ACCEL)
248#elif defined(HAVE_LIBXC_DEVICE) && !defined(HAVE_ACCEL)
249 if(.not. xc_force_cpu)
then
250 call messages_warning(
"Libxc has device support but no accelerator support is enabled in Octopus.", namespace=namespace)
261 subroutine xc_init(xcs, namespace, ndim, periodic_dim, nel, x_id, c_id, xk_id, ck_id, theory_level, ispin)
262 type(
xc_t),
intent(out) :: xcs
264 integer,
intent(in) :: ndim
265 integer,
intent(in) :: periodic_dim
266 real(real64),
intent(in) :: nel
267 integer,
intent(in) :: x_id
268 integer,
intent(in) :: c_id
269 integer,
intent(in) :: xk_id
270 integer,
intent(in) :: ck_id
271 integer,
intent(in) :: theory_level
272 integer,
intent(in) :: ispin
274 integer :: isp, xc_major, xc_minor, xc_micro
275 logical :: ll, using_hartree_fock
278 logical :: cam_ext_set
282 call xc_f03_version(xc_major, xc_minor, xc_micro)
286 xcs%kernel_family = 0
290 call xc_lrc_init(xcs%lrc, namespace, ndim, periodic_dim)
296 if (ndim /= 3) xcs%xc_on_host = .
true.
302 safe_allocate(xcs%functional(2,2))
303 safe_allocate(xcs%kernel(2,2))
314 xcs%family = ior(xcs%family, xcs%functional(
func_x,1)%family)
315 xcs%family = ior(xcs%family, xcs%functional(
func_c,1)%family)
317 xcs%flags = ior(xcs%flags, xcs%functional(
func_x,1)%flags)
318 xcs%flags = ior(xcs%flags, xcs%functional(
func_c,1)%flags)
320 xcs%kernel_family = ior(xcs%kernel_family, xcs%kernel(
func_x,1)%family)
321 xcs%kernel_family = ior(xcs%kernel_family, xcs%kernel(
func_c,1)%family)
323 xcs%usexcnhat = .
true.
327 message(1) =
"Cannot perform a periodic calculation with a functional"
328 message(2) =
"that depends on the number of electrons."
338 ll = using_hartree_fock &
343 message(1) =
"You cannot use an exchange functional when performing"
344 message(2) =
"a Hartree-Fock calculation or using a hybrid functional."
348 if (periodic_dim == ndim)
then
349 call messages_experimental(
"Fock operator (Hartree-Fock, OEP, hybrids) in fully periodic systems", namespace=namespace)
355 call xc_f03_hyb_cam_coef(xcs%functional(
func_c,1)%conf, xcs%cam%omega, &
356 xcs%cam%alpha, xcs%cam%beta)
357 call xc_f03_hyb_cam_coef(xcs%functional(
func_c,2)%conf, xcs%cam%omega, &
358 xcs%cam%alpha, xcs%cam%beta)
365 xcs%functional(
func_x,1)%family = xc_family_oep
367 xcs%functional(
func_x,2)%family = xc_family_oep
369 if (.not. using_hartree_fock)
then
370 xcs%family = ior(xcs%family, xc_family_oep)
374 if (
in_family(xcs%family, [xc_family_lca]))
then
381 if (xcs%functional(
func_x, 1)%id == xc_mgga_x_tb09 .and. periodic_dim /= 3)
then
382 message(1) =
"mgga_x_tb09 functional can only be used for 3D periodic systems"
423 if (xcs%xc_density_correction /=
lr_none)
then
441 call parse_variable(namespace,
'XCDensityCorrectionOptimize', .
true., xcs%xcd_optimize_cutoff)
474 call parse_variable(namespace,
'XCDensityCorrectionNormalize', .
true., xcs%xcd_normalize)
512 cam_ext_set =
parse_block(namespace,
'HybridCamParameters', blk) == 0
513 if (cam_ext_set)
then
520 if (cam_ext_set)
then
521 call cam_ext%print(namespace,
msg=
"Setting external CAM parameters")
532 type(
xc_t),
intent(inout) :: xcs
544 safe_deallocate_a(xcs%functional)
545 safe_deallocate_a(xcs%kernel)
551 if (
associated(xcs%quantities%hbuf_dens))
then
553 nullify(xcs%quantities%hbuf_dens)
555 if (
associated(xcs%quantities%hbuf_sigma))
then
556 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_sigma(1,1)),
size(xcs%quantities%hbuf_sigma, kind=int64)*8_int64)
557 nullify(xcs%quantities%hbuf_sigma)
559 if (
associated(xcs%quantities%hbuf_ldens))
then
560 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_ldens(1,1)),
size(xcs%quantities%hbuf_ldens, kind=int64)*8_int64)
561 nullify(xcs%quantities%hbuf_ldens)
563 if (
associated(xcs%quantities%hbuf_tau))
then
565 nullify(xcs%quantities%hbuf_tau)
567 if (
associated(xcs%quantities%hbuf_zk))
then
569 nullify(xcs%quantities%hbuf_zk)
571 if (
associated(xcs%quantities%hbuf_dedd))
then
573 nullify(xcs%quantities%hbuf_dedd)
575 if (
associated(xcs%quantities%hbuf_vsigma))
then
576 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_vsigma(1,1)),
size(xcs%quantities%hbuf_vsigma, kind=int64)*8_int64)
577 nullify(xcs%quantities%hbuf_vsigma)
579 if (
associated(xcs%quantities%hbuf_dedldens))
then
581 size(xcs%quantities%hbuf_dedldens, kind=int64)*8_int64)
582 nullify(xcs%quantities%hbuf_dedldens)
584 if (
associated(xcs%quantities%hbuf_dedtau))
then
585 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dedtau(1,1)),
size(xcs%quantities%hbuf_dedtau, kind=int64)*8_int64)
586 nullify(xcs%quantities%hbuf_dedtau)
598 type(
xc_t),
intent(in) :: xcs
609 integer,
intent(in) :: family
610 logical,
optional,
intent(in) :: only_collinear
612 if(optional_default(only_collinear, .false.))
then
614 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc])
617 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc, xc_family_nc_mgga])
627 integer,
intent(in) :: family
630 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc])
636 integer,
intent(in) :: family
637 logical,
optional,
intent(in) :: only_collinear
639 if(optional_default(only_collinear, .false.))
then
647 integer,
intent(in) :: family
655 type(
xc_t),
intent(in) :: xcs
661 if (
in_family(xcs%functional(ixc, 1)%family, [xc_family_mgga, xc_family_hyb_mgga, xc_family_nc_mgga]) &
662 .and. xc_functional_is_energy_functional(xcs%functional(ixc, 1)))
then
670 type(
xc_t),
intent(in) :: xcs
676 if (
in_family(xcs%functional(ixc, 1)%family, [xc_family_hyb_lda, xc_family_hyb_gga, xc_family_hyb_mgga]))
then
682 pure logical function in_family(family, xc_families)
683 integer,
intent(in) :: family
684 integer,
intent(in) :: xc_families(:)
686 in_family = bitand(family, sum(xc_families)) /= 0
691 class(
xc_t),
intent(in) :: xc
692 integer,
intent(in) :: theory_level
694 integer,
parameter :: exchange_theory_level(3) = [hartree, hartree_fock, rdmft]
699 (theory_level == generalized_kohn_sham_dft .and.
family_is_hybrid(xc)) .or. &
700 (xc%functional(func_x, 1)%id == xc_oep_x_slater) .or. &
701 (bitand(xc%family, xc_family_oep) /= 0)
710 type(
xc_t),
intent(inout) :: xcs
711 type(namespace_t),
intent(in) :: namespace
712 type(xc_cam_t),
intent(in) :: cam_ext
714 real(real64),
parameter :: default_alpha_pbe0 = 0.25_real64
723 select case(xcs%functional(func_c, 1)%id)
725 case(xc_hyb_gga_xc_pbeh, xc_hyb_lda_xc_lda0)
727 call xc_f03_func_set_ext_params(xcs%functional(func_c, 1)%conf,
parameters)
728 call xc_f03_func_set_ext_params(xcs%functional(func_c, 2)%conf,
parameters)
729 write(message(1),
'(a,f6.3,a)')
'Info: Setting mixing parameter (' ,
parameters(1) ,
').'
730 call messages_info(1)
732 case(xc_hyb_gga_xc_cam_pbeh, xc_hyb_lda_xc_cam_lda0)
735 call xc_f03_func_set_ext_params(xcs%functional(func_c, 1)%conf,
parameters)
736 call xc_f03_func_set_ext_params(xcs%functional(func_c, 2)%conf,
parameters)
738 call xc_f03_hyb_cam_coef(xcs%functional(func_c,1)%conf, xcs%cam%omega, &
739 xcs%cam%alpha, xcs%cam%beta)
740 call xc_f03_hyb_cam_coef(xcs%functional(func_c,2)%conf, xcs%cam%omega, &
741 xcs%cam%alpha, xcs%cam%beta)
742 call xcs%cam%print(namespace, msg=
"Setting CAM parameters:")
755 type(
xc_t),
intent(in) :: xcs
756 type(namespace_t),
intent(in) :: namespace
759 .or. xc_functional_is_not_size_consistent(xcs%functional(func_c,1), namespace)
765 type(
xc_t),
intent(in) :: xcs
767 .or. xc_functional_is_energy_functional(xcs%functional(func_c,1))
pure logical function, public accel_is_enabled()
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
integer, parameter, public hartree_fock
integer, parameter, public generalized_kohn_sham_dft
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
This module is intended to contain "only mathematical" functions and procedures.
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_not_implemented(feature, namespace)
character(len=512), private msg
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_obsolete_variable(namespace, name, rep)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_experimental(name, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
integer function, public parse_block(namespace, name, blk, check_varinfo_)
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
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.
type(xc_cam_t), parameter, public cam_exact_exchange
Use only Hartree Fock exact exchange.
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)
subroutine, public xc_write_info(xcs, iunit, namespace)
integer, parameter, public lr_none
pure logical function, public family_is_mgga(family, only_collinear)
Is the xc function part of the mGGA family.
subroutine set_hybrid_params(xcs, namespace, cam_ext)
Sets external parameters for some hybrid functionals.
pure logical function, public family_is_gga(family, only_collinear)
Is the xc function part of the GGA family.
subroutine, public xc_init(xcs, namespace, ndim, periodic_dim, nel, x_id, c_id, xk_id, ck_id, theory_level, ispin)
logical pure function, public family_is_mgga_with_exc(xcs)
Is the xc function part of the mGGA family with an energy functional.
logical function, public xc_is_using_device(namespace)
Check if XC will run on device (parses config and checks availability)
subroutine, public xc_end(xcs)
logical pure function, public xc_is_energy_functional(xcs)
Is one of the x or c functional is not an energy functional.
logical pure function, public family_is_hybrid(xcs)
Returns true if the functional is an hybrid functional.
logical function, public xc_is_not_size_consistent(xcs, namespace)
Is one of the x or c functional is not size consistent.
subroutine, public xc_init_device_support(xcs, namespace)
integer, parameter, public lr_x
pure logical function, public family_is_nc_mgga(family)
logical function xc_compute_exchange(xc, theory_level)
Theory levels and functionals for which exacy exchange is required.
pure logical function, public family_is_supported(family)
Is the xc family internally supported by Octopus.
pure logical function, public in_family(family, xc_families)
subroutine, public xc_write_fxc_info(xcs, iunit, namespace)
logical pure function, public xc_is_orbital_dependent(xcs)
Is the xc family orbital dependent.
Coulomb-attenuating method parameters, used in the partitioning of the Coulomb potential into a short...