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), allocatable, public :: functional(:,:)
138
139 type(xc_functional_t), allocatable, public :: kernel(:,:)
140 type(xc_cam_t), public :: cam
141 type(xc_lrc_t), public :: lrc
142
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
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
167contains
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
175 integer :: ifunc
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
186 if (abs(xcs%cam%alpha) + abs(xcs%cam%beta) > m_epsilon) call xcs%cam%print(namespace, iunit=iunit)
189 end subroutine xc_write_info
191 ! ---------------------------------------------------------
192 subroutine xc_write_fxc_info(xcs, iunit, namespace)
193 type(xc_t), intent(in) :: xcs
194 integer, optional, intent(in) :: iunit
195 type(namespace_t), optional, intent(in) :: namespace
197 integer :: ifunc
198
200
201 write(message(1), '(a)') "Exchange-correlation kernel:"
202 call messages_info(1, iunit=iunit, namespace=namespace)
204 do ifunc = func_x, func_c
205 call xc_functional_write_info(xcs%kernel(ifunc, 1), iunit, namespace)
206 end do
209 end subroutine xc_write_fxc_info
210
212 ! ---------------------------------------------------------
213 subroutine xc_init_device_support(xcs, namespace)
214 type(xc_t), intent(inout) :: xcs
215 type(namespace_t), intent(in) :: namespace
219 xcs%xc_on_host = .not. xc_is_using_device(namespace)
224 ! ---------------------------------------------------------
226 logical function xc_is_using_device(namespace)
227 type(namespace_t), intent(in) :: namespace
229 logical :: xc_force_cpu
230
231 push_sub(xc_is_using_device)
232
233 !%Variable XCForceFunctionalsOnCPU
234 !%Type logical
235 !%Default no
236 !%Section Hamiltonian::XC
237 !%Description
238 !% By setting this variable to <tt>yes</tt>, you force Octopus to evaluate XC functionals
239 !% on the CPU, even if CUDA/HIP support is available.
240 !%End
241 call parse_variable(namespace, 'XCForceFunctionalsOnCPU', .false., xc_force_cpu)
243#if defined(HAVE_LIBXC_DEVICE) && defined(HAVE_ACCEL)
244 xc_is_using_device = .false.
245 if (accel_is_enabled()) then
246 xc_is_using_device = .not. xc_force_cpu
247 end if
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)
251 end if
252 xc_is_using_device = .false.
253#else
254 xc_is_using_device = .false.
255#endif
256
257 pop_sub(xc_is_using_device)
258 end function xc_is_using_device
259
260 ! ---------------------------------------------------------
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
263 type(namespace_t), intent(in) :: namespace
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
273
274 integer :: isp, xc_major, xc_minor, xc_micro
275 logical :: ll, using_hartree_fock
276 type(block_t) :: blk
277 type(xc_cam_t) :: cam_ext
278 logical :: cam_ext_set
279
280 push_sub(xc_init)
281
282 call xc_f03_version(xc_major, xc_minor, xc_micro)
283
284 xcs%family = 0
285 xcs%flags = 0
286 xcs%kernel_family = 0
287
288 call parse()
289
290 call xc_lrc_init(xcs%lrc, namespace, ndim, periodic_dim)
291
292 call xc_init_device_support(xcs, namespace)
293
294 ! 1D/2D functionals (e.g. lda_x_1d_soft) call xc_integrate() which uses malloc() inside
295 ! GPU kernels. With large meshes this exhausts the CUDA device heap (cudaErrorIllegalAddress).
296 if (ndim /= 3) xcs%xc_on_host = .true.
297
298 !we also need XC functionals that do not depend on the current
299 !get both spin-polarized and unpolarized
300
301 ! TODO: check that nel should not be spin polarized here
302 safe_allocate(xcs%functional(2,2))
303 safe_allocate(xcs%kernel(2,2))
304 do isp = 1, 2
305
306 call xc_functional_init(xcs%functional(func_x, isp), namespace, x_id, ndim, nel, isp, xcs%xc_on_host)
307 call xc_functional_init(xcs%functional(func_c, isp), namespace, c_id, ndim, nel, isp, xcs%xc_on_host)
308
309 call xc_functional_init(xcs%kernel(func_x, isp), namespace, xk_id, ndim, nel, isp, xcs%xc_on_host)
310 call xc_functional_init(xcs%kernel(func_c, isp), namespace, ck_id, ndim, nel, isp, xcs%xc_on_host)
311
312 end do
313
314 xcs%family = ior(xcs%family, xcs%functional(func_x,1)%family)
315 xcs%family = ior(xcs%family, xcs%functional(func_c,1)%family)
316
317 xcs%flags = ior(xcs%flags, xcs%functional(func_x,1)%flags)
318 xcs%flags = ior(xcs%flags, xcs%functional(func_c,1)%flags)
319
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.
324
325
326 if (xc_is_not_size_consistent(xcs, namespace) .and. periodic_dim > 0) then
327 message(1) = "Cannot perform a periodic calculation with a functional"
328 message(2) = "that depends on the number of electrons."
329 call messages_fatal(2, namespace=namespace)
330 end if
331
332 ! Take care of hybrid functionals (they appear in the correlation functional)
333 xcs%cam = cam_null
334
335 using_hartree_fock = (theory_level == hartree_fock) &
336 .or. (theory_level == generalized_kohn_sham_dft .and. family_is_hybrid(xcs))
337
338 ll = using_hartree_fock &
339 .or.(xcs%functional(func_x,1)%id == xc_oep_x) &
340 .or. family_is_hybrid(xcs)
341 if (ll) then
342 if ((xcs%functional(func_x,1)%id /= 0).and.(xcs%functional(func_x,1)%id /= xc_oep_x)) then
343 message(1) = "You cannot use an exchange functional when performing"
344 message(2) = "a Hartree-Fock calculation or using a hybrid functional."
345 call messages_fatal(2, namespace=namespace)
346 end if
347
348 if (periodic_dim == ndim) then
349 call messages_experimental("Fock operator (Hartree-Fock, OEP, hybrids) in fully periodic systems", namespace=namespace)
350 end if
351
352 ! get the mixing coefficient for hybrids
353 if (family_is_hybrid(xcs)) then
354 if (cam_ext_set) call set_hybrid_params(xcs, namespace, cam_ext)
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)
359 else
360 ! we are doing Hartree-Fock plus possibly a correlation functional
361 xcs%cam = cam_exact_exchange
362 end if
363
364 ! reset certain variables
365 xcs%functional(func_x,1)%family = xc_family_oep
366 xcs%functional(func_x,1)%id = xc_oep_x
367 xcs%functional(func_x,2)%family = xc_family_oep
368 xcs%functional(func_x,2)%id = xc_oep_x
369 if (.not. using_hartree_fock) then
370 xcs%family = ior(xcs%family, xc_family_oep)
371 end if
372 end if
373
374 if (in_family(xcs%family, [xc_family_lca])) then
375 call messages_not_implemented("LCA current functionals", namespace) ! not even in libxc!
376 end if
377
378 call messages_obsolete_variable(namespace, 'MGGAimplementation')
379 call messages_obsolete_variable(namespace, 'CurrentInTau', 'XCUseGaugeIndependentKED')
380
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"
383 call messages_fatal(1, namespace=namespace)
384 end if
385
386 if (family_is_mgga(xcs%family) .or. family_is_nc_mgga(xcs%family)) then
387 !%Variable XCUseGaugeIndependentKED
388 !%Type logical
389 !%Default yes
390 !%Section Hamiltonian::XC
391 !%Description
392 !% If true, when evaluating the XC functional, a term including the (paramagnetic or total) current
393 !% is added to the kinetic-energy density such as to make it gauge-independent.
394 !% Applies only to meta-GGA (and hybrid meta-GGA) functionals.
395 !%End
396 call parse_variable(namespace, 'XCUseGaugeIndependentKED', .true., xcs%use_gi_ked)
397 end if
398
399 pop_sub(xc_init)
400
401 contains
402
403 subroutine parse()
404
405 push_sub(xc_init.parse)
406
407 ! the values of x_id, c_id, xk_id, and c_id are read outside the routine
408
409 !%Variable XCDensityCorrection
410 !%Type integer
411 !%Default none
412 !%Section Hamiltonian::XC::DensityCorrection
413 !%Description
414 !% This variable controls the long-range correction of the XC
415 !% potential using the <a href=http://arxiv.org/abs/1107.4339>XC density representation</a>.
416 !%Option none 0
417 !% No correction is applied.
418 !%Option long_range_x 1
419 !% The correction is applied to the exchange potential.
420 !%End
421 call parse_variable(namespace, 'XCDensityCorrection', lr_none, xcs%xc_density_correction)
422
423 if (xcs%xc_density_correction /= lr_none) then
424 call messages_experimental('XC density correction', namespace=namespace)
425
426 if(ispin /= unpolarized) then
427 call messages_not_implemented('XCDensityCorrection with SpinComponents /= unpolarized', namespace)
428 end if
429
430 !%Variable XCDensityCorrectionOptimize
431 !%Type logical
432 !%Default true
433 !%Section Hamiltonian::XC::DensityCorrection
434 !%Description
435 !% When enabled, the density cutoff will be
436 !% optimized to replicate the boundary conditions of the exact
437 !% XC potential. If the variable is set to no, the value of
438 !% the cutoff must be given by <tt>XCDensityCorrectionCutoff</tt>
439 !% variable.
440 !%End
441 call parse_variable(namespace, 'XCDensityCorrectionOptimize', .true., xcs%xcd_optimize_cutoff)
442
443 !%Variable XCDensityCorrectionCutoff
444 !%Type float
445 !%Default 0.0
446 !%Section Hamiltonian::XC::DensityCorrection
447 !%Description
448 !% The value of the cutoff applied to the XC density.
449 !%End
450 call parse_variable(namespace, 'XCDensityCorrectionCutoff', m_zero, xcs%xcd_ncutoff)
451
452 !%Variable XCDensityCorrectionMinimum
453 !%Type logical
454 !%Default true
455 !%Section Hamiltonian::XC::DensityCorrection
456 !%Description
457 !% When enabled, the cutoff optimization will
458 !% return the first minimum of the <math>q_{xc}</math> function if it does
459 !% not find a value of -1 (<a href=http://arxiv.org/abs/1107.4339>details</a>).
460 !% This is required for atoms or small
461 !% molecules, but may cause numerical problems.
462 !%End
463 call parse_variable(namespace, 'XCDensityCorrectionMinimum', .true., xcs%xcd_minimum)
465 !%Variable XCDensityCorrectionNormalize
466 !%Type logical
467 !%Default true
468 !%Section Hamiltonian::XC::DensityCorrection
469 !%Description
470 !% When enabled, the correction will be
471 !% normalized to reproduce the exact boundary conditions of
472 !% the XC potential.
473 !%End
474 call parse_variable(namespace, 'XCDensityCorrectionNormalize', .true., xcs%xcd_normalize)
475
476 end if
477
478 !%Variable ParallelXC
479 !%Type logical
480 !%Default true
481 !%Section Execution::Parallelization
482 !%Description
483 !% When enabled, additional parallelization
484 !% will be used for the calculation of the XC functional.
485 !%End
486 call messages_obsolete_variable(namespace, 'XCParallel', 'ParallelXC')
487 call parse_variable(namespace, 'ParallelXC', .true., xcs%parallel)
488
489
490 !%Variable HybridCAMParameters
491 !%Type block
492 !%Section Hamiltonian::XC
493 !%Description
494 !% This variable specifies the <math>\alpha, \beta, \omega</math> parameters
495 !% for CAM-type hybrid functionals. Octopus applies exact exchange with the
496 !% attenuated interaction
497 !% <math>\alpha/r + \beta\,{\rm erfc}(\omega r)/r</math>, or equivalently
498 !% <math>4\pi/G^2 [\alpha + \beta(1-\exp(-G^2/(4\omega^2)))]</math> in
499 !% reciprocal space. Thus <math>\alpha</math> is the full-range exact-exchange
500 !% fraction, and <math>\beta</math> is the additional short-range screened
501 !% exact-exchange fraction. Defaults are zero.
502 !%
503 !% HSE06 corresponds to:
504 !% <tt>%HybridCAMParameters
505 !% 0.0 | 0.25 | 0.11
506 !% %</tt>
507 !% The parameters <tt>0.25 | 0.0 | 0.11</tt> instead define a 25% full-range
508 !% hybrid and are not equivalent to HSE06.
509 !%End
510 cam_ext = cam_null
511
512 cam_ext_set = parse_block(namespace, 'HybridCamParameters', blk) == 0
513 if (cam_ext_set) then
514 call parse_block_float(blk, 0, 0, cam_ext%alpha)
515 call parse_block_float(blk, 0, 1, cam_ext%beta)
516 call parse_block_float(blk, 0, 2, cam_ext%omega)
517 call parse_block_end(blk)
518 end if
519
520 if (cam_ext_set) then
521 call cam_ext%print(namespace, msg="Setting external CAM parameters")
522 endif
523
524 pop_sub(xc_init.parse)
525 end subroutine parse
526
527 end subroutine xc_init
528
529
530 ! ---------------------------------------------------------
531 subroutine xc_end(xcs)
532 type(xc_t), intent(inout) :: xcs
533
534 integer :: isp
535
536 push_sub(xc_end)
537
538 do isp = 1, 2
539 call xc_functional_end(xcs%functional(func_x, isp))
540 call xc_functional_end(xcs%functional(func_c, isp))
541 call xc_functional_end(xcs%kernel(func_x, isp))
542 call xc_functional_end(xcs%kernel(func_c, isp))
543 end do
544 safe_deallocate_a(xcs%functional)
545 safe_deallocate_a(xcs%kernel)
546 xcs%family = 0
547 xcs%flags = 0
548
549 ! Free the persistent host staging buffers (see internal_quantities_t), allocated
550 ! with the hardware-aware allocator in xc_compute_vxc.
551 if (associated(xcs%quantities%hbuf_dens)) then
552 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dens(1,1)), size(xcs%quantities%hbuf_dens, kind=int64)*8_int64)
553 nullify(xcs%quantities%hbuf_dens)
554 end if
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)
558 end if
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)
562 end if
563 if (associated(xcs%quantities%hbuf_tau)) then
564 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_tau(1,1)), size(xcs%quantities%hbuf_tau, kind=int64)*8_int64)
565 nullify(xcs%quantities%hbuf_tau)
566 end if
567 if (associated(xcs%quantities%hbuf_zk)) then
568 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_zk(1)), size(xcs%quantities%hbuf_zk, kind=int64)*8_int64)
569 nullify(xcs%quantities%hbuf_zk)
570 end if
571 if (associated(xcs%quantities%hbuf_dedd)) then
572 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dedd(1,1)), size(xcs%quantities%hbuf_dedd, kind=int64)*8_int64)
573 nullify(xcs%quantities%hbuf_dedd)
574 end if
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)
578 end if
579 if (associated(xcs%quantities%hbuf_dedldens)) then
580 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dedldens(1,1)), &
581 size(xcs%quantities%hbuf_dedldens, kind=int64)*8_int64)
582 nullify(xcs%quantities%hbuf_dedldens)
583 end if
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)
587 end if
588
589 pop_sub(xc_end)
590 end subroutine xc_end
591
592 ! ---------------------------------------------------------
597 logical pure function xc_is_orbital_dependent(xcs)
598 type(xc_t), intent(in) :: xcs
599
601 in_family(xcs%functional(func_x,1)%family, [xc_family_oep]) .or. &
602 in_family(xcs%family, [xc_family_mgga, xc_family_nc_mgga])
603
604 end function xc_is_orbital_dependent
605
606 ! ---------------------------------------------------------
608 pure logical function family_is_gga(family, only_collinear)
609 integer, intent(in) :: family
610 logical, optional, intent(in) :: only_collinear
611
612 if(optional_default(only_collinear, .false.)) then
613 family_is_gga = in_family(family, [xc_family_gga, xc_family_hyb_gga, &
614 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc])
615 else
616 family_is_gga = in_family(family, [xc_family_gga, xc_family_hyb_gga, &
617 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc, xc_family_nc_mgga])
618 end if
619 end function family_is_gga
620
621 !----------------------------------------------------------------------
626 pure logical function family_is_supported(family)
627 integer, intent(in) :: family
628
629 family_is_supported = in_family(family, [xc_family_lda, xc_family_hyb_lda, xc_family_gga, xc_family_hyb_gga, &
630 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc])
631 end function family_is_supported
632
633 ! ---------------------------------------------------------
635 pure logical function family_is_mgga(family, only_collinear)
636 integer, intent(in) :: family
637 logical, optional, intent(in) :: only_collinear
638
639 if(optional_default(only_collinear, .false.)) then
640 family_is_mgga = in_family(family, [xc_family_mgga, xc_family_hyb_mgga])
641 else
642 family_is_mgga = in_family(family, [xc_family_mgga, xc_family_hyb_mgga, xc_family_nc_mgga])
643 end if
644 end function family_is_mgga
645
646 pure logical function family_is_nc_mgga(family)
647 integer, intent(in) :: family
648
649 family_is_nc_mgga = bitand(family, xc_family_nc_mgga) /= 0
650 end function family_is_nc_mgga
651
652 ! ---------------------------------------------------------
654 logical pure function family_is_mgga_with_exc(xcs)
655 type(xc_t), intent(in) :: xcs
656
657 integer :: ixc
660 do ixc = 1, 2
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
664 end if
665 end do
666 end function family_is_mgga_with_exc
667
669 logical pure function family_is_hybrid(xcs)
670 type(xc_t), intent(in) :: xcs
671
672 integer :: ixc
673
674 family_is_hybrid = .false.
675 do ixc = 1, 2
676 if (in_family(xcs%functional(ixc, 1)%family, [xc_family_hyb_lda, xc_family_hyb_gga, xc_family_hyb_mgga])) then
678 end if
679 end do
680 end function family_is_hybrid
681
682 pure logical function in_family(family, xc_families)
683 integer, intent(in) :: family
684 integer, intent(in) :: xc_families(:)
685
686 in_family = bitand(family, sum(xc_families)) /= 0
687 end function in_family
688
690 logical function xc_compute_exchange(xc, theory_level)
691 class(xc_t), intent(in) :: xc
692 integer, intent(in) :: theory_level
693
694 integer, parameter :: exchange_theory_level(3) = [hartree, hartree_fock, rdmft]
695
697
698 xc_compute_exchange = any(exchange_theory_level == theory_level) .or. &
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)
702
703 pop_sub(xc_compute_exchange)
704
705 end function xc_compute_exchange
706
707 ! ---------------------------------------------------------
709 subroutine set_hybrid_params(xcs, namespace, cam_ext)
710 type(xc_t), intent(inout) :: xcs
711 type(namespace_t), intent(in) :: namespace
712 type(xc_cam_t), intent(in) :: cam_ext
713
714 real(real64), parameter :: default_alpha_pbe0 = 0.25_real64
715 real(real64) :: parameters(3)
716
717 push_sub(set_hybrid_params)
718
719 ! LibXC expects an array of reals, ordered [alpha, beta, omega]
720 parameters = cam_ext%as_array()
721 xcs%cam%alpha = parameters(1)
722
723 select case(xcs%functional(func_c, 1)%id)
724
725 case(xc_hyb_gga_xc_pbeh, xc_hyb_lda_xc_lda0) ! original PBE0/LDA0 in libxc
726 if(parameters(1) < m_zero) parameters(1) = default_alpha_pbe0
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)
731
732 case(xc_hyb_gga_xc_cam_pbeh, xc_hyb_lda_xc_cam_lda0)
733 xcs%cam%beta = parameters(2)
734 xcs%cam%omega = parameters(3)
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)
737 ! check 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:")
744 case default
745 assert(.false.)
746
747 end select
748
749 pop_sub(set_hybrid_params)
750 end subroutine set_hybrid_params
752 ! ---------------------------------------------------------
754 logical function xc_is_not_size_consistent(xcs, namespace)
755 type(xc_t), intent(in) :: xcs
756 type(namespace_t), intent(in) :: namespace
757
758 xc_is_not_size_consistent = xc_functional_is_not_size_consistent(xcs%functional(func_x,1), namespace) &
759 .or. xc_functional_is_not_size_consistent(xcs%functional(func_c,1), namespace)
760 end function xc_is_not_size_consistent
761
762 ! ---------------------------------------------------------
764 logical pure function xc_is_energy_functional(xcs)
765 type(xc_t), intent(in) :: xcs
766 xc_is_energy_functional = xc_functional_is_energy_functional(xcs%functional(func_x,1)) &
767 .or. xc_functional_is_energy_functional(xcs%functional(func_c,1))
768 end function xc_is_energy_functional
769
770end module xc_oct_m
771
772
773!! Local Variables:
774!! mode: f90
775!! coding: utf-8
776!! End:
pure logical function, public accel_is_enabled()
Definition: accel.F90:391
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:173
integer, parameter, public hartree_fock
Definition: global.F90:223
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:223
real(real64), parameter, public m_epsilon
Definition: global.F90:189
real(real64), parameter, public m_one
Definition: global.F90:174
This module implements the underlying real-space grid.
Definition: grid.F90:96
Definition: io.F90:93
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1048
character(len=512), private msg
Definition: messages.F90:143
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:501
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:980
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1020
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:600
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
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:128
type(xc_cam_t), parameter, public cam_exact_exchange
Use only Hartree Fock exact exchange.
Definition: xc_cam.F90:131
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:123
Definition: xc.F90:97
subroutine, public xc_write_info(xcs, iunit, namespace)
Definition: xc.F90:243
integer, parameter, public lr_none
Definition: xc.F90:235
pure logical function, public family_is_mgga(family, only_collinear)
Is the xc function part of the mGGA family.
Definition: xc.F90:697
subroutine set_hybrid_params(xcs, namespace, cam_ext)
Sets external parameters for some hybrid functionals.
Definition: xc.F90:771
pure logical function, public family_is_gga(family, only_collinear)
Is the xc function part of the GGA family.
Definition: xc.F90:670
subroutine, public xc_init(xcs, namespace, ndim, periodic_dim, nel, x_id, c_id, xk_id, ck_id, theory_level, ispin)
Definition: xc.F90:323
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:716
logical function, public xc_is_using_device(namespace)
Check if XC will run on device (parses config and checks availability)
Definition: xc.F90:299
subroutine, public xc_end(xcs)
Definition: xc.F90:593
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:826
logical pure function, public family_is_hybrid(xcs)
Returns true if the functional is an hybrid functional.
Definition: xc.F90:731
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:816
subroutine, public xc_init_device_support(xcs, namespace)
Definition: xc.F90:286
integer, parameter, public lr_x
Definition: xc.F90:235
pure logical function, public family_is_nc_mgga(family)
Definition: xc.F90:708
logical function xc_compute_exchange(xc, theory_level)
Theory levels and functionals for which exacy exchange is required.
Definition: xc.F90:752
pure logical function, public family_is_supported(family)
Is the xc family internally supported by Octopus.
Definition: xc.F90:688
pure logical function, public in_family(family, xc_families)
Definition: xc.F90:744
subroutine, public xc_write_fxc_info(xcs, iunit, namespace)
Definition: xc.F90:265
logical pure function, public xc_is_orbital_dependent(xcs)
Is the xc family orbital dependent.
Definition: xc.F90:659
Coulomb-attenuating method parameters, used in the partitioning of the Coulomb potential into a short...
Definition: xc_cam.F90:118
int true(void)
subroutine parse()
Definition: xc.F90:465