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) then
186 write(message(1), '(1x)')
187 write(message(2), '(a,f8.5)') "Exact exchange mixing = ", xcs%cam%alpha
188 write(message(3), '(a,f8.5)') "Exact exchange for short-range beta = ", xcs%cam%beta
189 write(message(4), '(a,f8.5)') "Exact exchange range-separate omega = ", xcs%cam%omega
190 call messages_info(4, iunit=iunit, namespace=namespace)
191 end if
193
195 end subroutine xc_write_info
197 ! ---------------------------------------------------------
198 subroutine xc_write_fxc_info(xcs, iunit, namespace)
199 type(xc_t), intent(in) :: xcs
200 integer, optional, intent(in) :: iunit
201 type(namespace_t), optional, intent(in) :: namespace
203 integer :: ifunc
204
207 write(message(1), '(a)') "Exchange-correlation kernel:"
208 call messages_info(1, iunit=iunit, namespace=namespace)
210 do ifunc = func_x, func_c
211 call xc_functional_write_info(xcs%kernel(ifunc, 1), iunit, namespace)
212 end do
214 pop_sub(xc_write_fxc_info)
215 end subroutine xc_write_fxc_info
218 ! ---------------------------------------------------------
219 subroutine xc_init_device_support(xcs, namespace)
220 type(xc_t), intent(inout) :: xcs
221 type(namespace_t), intent(in) :: namespace
223 push_sub(xc_init_device_support)
224
225 xcs%xc_on_host = .not. xc_is_using_device(namespace)
230 ! ---------------------------------------------------------
232 logical function xc_is_using_device(namespace)
233 type(namespace_t), intent(in) :: namespace
235 logical :: xc_force_cpu
237 push_sub(xc_is_using_device)
239 !%Variable XCForceFunctionalsOnCPU
240 !%Type logical
241 !%Default no
242 !%Section Hamiltonian::XC
243 !%Description
244 !% By setting this variable to <tt>yes</tt>, you force Octopus to evaluate XC functionals
245 !% on the CPU, even if CUDA/HIP support is available.
246 !%End
247 call parse_variable(namespace, 'XCForceFunctionalsOnCPU', .false., xc_force_cpu)
248
249#if defined(HAVE_LIBXC_DEVICE) && defined(HAVE_ACCEL)
251 if (accel_is_enabled()) then
252 xc_is_using_device = .not. xc_force_cpu
253 end if
254#elif defined(HAVE_LIBXC_DEVICE) && !defined(HAVE_ACCEL)
255 if(.not. xc_force_cpu) then
256 call messages_warning("Libxc has device support but no accelerator support is enabled in Octopus.", namespace=namespace)
257 end if
258 xc_is_using_device = .false.
259#else
260 xc_is_using_device = .false.
261#endif
262
263 pop_sub(xc_is_using_device)
265
266 ! ---------------------------------------------------------
267 subroutine xc_init(xcs, namespace, ndim, periodic_dim, nel, x_id, c_id, xk_id, ck_id, hartree_fock, ispin)
268 type(xc_t), intent(out) :: xcs
269 type(namespace_t), intent(in) :: namespace
270 integer, intent(in) :: ndim
271 integer, intent(in) :: periodic_dim
272 real(real64), intent(in) :: nel
273 integer, intent(in) :: x_id
274 integer, intent(in) :: c_id
275 integer, intent(in) :: xk_id
276 integer, intent(in) :: ck_id
277 logical, intent(in) :: hartree_fock
278 integer, intent(in) :: ispin
279
280 integer :: isp, xc_major, xc_minor, xc_micro
281 logical :: ll
282 type(block_t) :: blk
283 type(xc_cam_t) :: cam_ext
284
285 push_sub(xc_init)
286
287 call xc_f03_version(xc_major, xc_minor, xc_micro)
288
289 xcs%family = 0
290 xcs%flags = 0
291 xcs%kernel_family = 0
292
293 call parse()
294
295 call xc_lrc_init(xcs%lrc, namespace, ndim, periodic_dim)
296
297 call xc_init_device_support(xcs, namespace)
298
299 ! 1D/2D functionals (e.g. lda_x_1d_soft) call xc_integrate() which uses malloc() inside
300 ! GPU kernels. With large meshes this exhausts the CUDA device heap (cudaErrorIllegalAddress).
301 if (ndim /= 3) xcs%xc_on_host = .true.
302
303 !we also need XC functionals that do not depend on the current
304 !get both spin-polarized and unpolarized
305
306 ! TODO: check that nel should not be spin polarized here
307 do isp = 1, 2
308
309 call xc_functional_init(xcs%functional(func_x, isp), namespace, x_id, ndim, nel, isp, xcs%xc_on_host)
310 call xc_functional_init(xcs%functional(func_c, isp), namespace, c_id, ndim, nel, isp, xcs%xc_on_host)
311
312 call xc_functional_init(xcs%kernel(func_x, isp), namespace, xk_id, ndim, nel, isp, xcs%xc_on_host)
313 call xc_functional_init(xcs%kernel(func_c, isp), namespace, ck_id, ndim, nel, isp, xcs%xc_on_host)
315 end do
316
317 xcs%family = ior(xcs%family, xcs%functional(func_x,1)%family)
318 xcs%family = ior(xcs%family, xcs%functional(func_c,1)%family)
319
320 xcs%flags = ior(xcs%flags, xcs%functional(func_x,1)%flags)
321 xcs%flags = ior(xcs%flags, xcs%functional(func_c,1)%flags)
322
323 xcs%kernel_family = ior(xcs%kernel_family, xcs%kernel(func_x,1)%family)
324 xcs%kernel_family = ior(xcs%kernel_family, xcs%kernel(func_c,1)%family)
325
326
327 if (xc_is_not_size_consistent(xcs, namespace) .and. periodic_dim > 0) then
328 message(1) = "Cannot perform a periodic calculation with a functional"
329 message(2) = "that depends on the number of electrons."
330 call messages_fatal(2, namespace=namespace)
331 end if
332
333 ! Take care of hybrid functionals (they appear in the correlation functional)
334 xcs%cam = cam_null
335
336 ll = (hartree_fock) &
337 .or.(xcs%functional(func_x,1)%id == xc_oep_x) &
338 .or. family_is_hybrid(xcs)
339 if (ll) then
340 if ((xcs%functional(func_x,1)%id /= 0).and.(xcs%functional(func_x,1)%id /= xc_oep_x)) then
341 message(1) = "You cannot use an exchange functional when performing"
342 message(2) = "a Hartree-Fock calculation or using a hybrid functional."
343 call messages_fatal(2, namespace=namespace)
344 end if
345
346 if (periodic_dim == ndim) then
347 call messages_experimental("Fock operator (Hartree-Fock, OEP, hybrids) in fully periodic systems", namespace=namespace)
348 end if
349
350 ! get the mixing coefficient for hybrids
351 if (family_is_hybrid(xcs)) then
352 if( .not. cam_ext%is_null() ) call set_hybrid_params(xcs, namespace, cam_ext)
353 call xc_f03_hyb_cam_coef(xcs%functional(func_c,1)%conf, xcs%cam%omega, &
354 xcs%cam%alpha, xcs%cam%beta)
355 call xc_f03_hyb_cam_coef(xcs%functional(func_c,2)%conf, xcs%cam%omega, &
356 xcs%cam%alpha, xcs%cam%beta)
357 else
358 ! we are doing Hartree-Fock plus possibly a correlation functional
359 xcs%cam = cam_exact_exchange
360 end if
361
362 ! reset certain variables
363 xcs%functional(func_x,1)%family = xc_family_oep
364 xcs%functional(func_x,1)%id = xc_oep_x
365 xcs%functional(func_x,2)%family = xc_family_oep
366 xcs%functional(func_x,2)%id = xc_oep_x
367 if (.not. hartree_fock) then
368 xcs%family = ior(xcs%family, xc_family_oep)
369 end if
370 end if
371
372 if (in_family(xcs%family, [xc_family_lca])) then
373 call messages_not_implemented("LCA current functionals", namespace) ! not even in libxc!
374 end if
375
376 call messages_obsolete_variable(namespace, 'MGGAimplementation')
377 call messages_obsolete_variable(namespace, 'CurrentInTau', 'XCUseGaugeIndependentKED')
378
379 if (xcs%functional(func_x, 1)%id == xc_mgga_x_tb09 .and. periodic_dim /= 3) then
380 message(1) = "mgga_x_tb09 functional can only be used for 3D periodic systems"
381 call messages_fatal(1, namespace=namespace)
382 end if
383
384 if (family_is_mgga(xcs%family) .or. family_is_nc_mgga(xcs%family)) then
385 !%Variable XCUseGaugeIndependentKED
386 !%Type logical
387 !%Default yes
388 !%Section Hamiltonian::XC
389 !%Description
390 !% If true, when evaluating the XC functional, a term including the (paramagnetic or total) current
391 !% is added to the kinetic-energy density such as to make it gauge-independent.
392 !% Applies only to meta-GGA (and hybrid meta-GGA) functionals.
393 !%End
394 call parse_variable(namespace, 'XCUseGaugeIndependentKED', .true., xcs%use_gi_ked)
395 end if
396
397 pop_sub(xc_init)
398
399 contains
400
401 subroutine parse()
402
403 push_sub(xc_init.parse)
404
405 ! the values of x_id, c_id, xk_id, and c_id are read outside the routine
406
407 !%Variable XCDensityCorrection
408 !%Type integer
409 !%Default none
410 !%Section Hamiltonian::XC::DensityCorrection
411 !%Description
412 !% This variable controls the long-range correction of the XC
413 !% potential using the <a href=http://arxiv.org/abs/1107.4339>XC density representation</a>.
414 !%Option none 0
415 !% No correction is applied.
416 !%Option long_range_x 1
417 !% The correction is applied to the exchange potential.
418 !%End
419 call parse_variable(namespace, 'XCDensityCorrection', lr_none, xcs%xc_density_correction)
420
421 if (xcs%xc_density_correction /= lr_none) then
422 call messages_experimental('XC density correction', namespace=namespace)
423
424 if(ispin /= unpolarized) then
425 call messages_not_implemented('XCDensityCorrection with SpinComponents /= unpolarized', namespace)
426 end if
427
428 !%Variable XCDensityCorrectionOptimize
429 !%Type logical
430 !%Default true
431 !%Section Hamiltonian::XC::DensityCorrection
432 !%Description
433 !% When enabled, the density cutoff will be
434 !% optimized to replicate the boundary conditions of the exact
435 !% XC potential. If the variable is set to no, the value of
436 !% the cutoff must be given by <tt>XCDensityCorrectionCutoff</tt>
437 !% variable.
438 !%End
439 call parse_variable(namespace, 'XCDensityCorrectionOptimize', .true., xcs%xcd_optimize_cutoff)
440
441 !%Variable XCDensityCorrectionCutoff
442 !%Type float
443 !%Default 0.0
444 !%Section Hamiltonian::XC::DensityCorrection
445 !%Description
446 !% The value of the cutoff applied to the XC density.
447 !%End
448 call parse_variable(namespace, 'XCDensityCorrectionCutoff', m_zero, xcs%xcd_ncutoff)
449
450 !%Variable XCDensityCorrectionMinimum
451 !%Type logical
452 !%Default true
453 !%Section Hamiltonian::XC::DensityCorrection
454 !%Description
455 !% When enabled, the cutoff optimization will
456 !% return the first minimum of the <math>q_{xc}</math> function if it does
457 !% not find a value of -1 (<a href=http://arxiv.org/abs/1107.4339>details</a>).
458 !% This is required for atoms or small
459 !% molecules, but may cause numerical problems.
460 !%End
461 call parse_variable(namespace, 'XCDensityCorrectionMinimum', .true., xcs%xcd_minimum)
462
463 !%Variable XCDensityCorrectionNormalize
464 !%Type logical
465 !%Default true
466 !%Section Hamiltonian::XC::DensityCorrection
467 !%Description
468 !% When enabled, the correction will be
469 !% normalized to reproduce the exact boundary conditions of
470 !% the XC potential.
471 !%End
472 call parse_variable(namespace, 'XCDensityCorrectionNormalize', .true., xcs%xcd_normalize)
473
474 end if
475
476 !%Variable ParallelXC
477 !%Type logical
478 !%Default true
479 !%Section Execution::Parallelization
480 !%Description
481 !% When enabled, additional parallelization
482 !% will be used for the calculation of the XC functional.
483 !%End
484 call messages_obsolete_variable(namespace, 'XCParallel', 'ParallelXC')
485 call parse_variable(namespace, 'ParallelXC', .true., xcs%parallel)
486
487
488 !%Variable HybridCAMParameters
489 !%Type block
490 !%Section Hamiltonian::XC
491 !%Description
492 !% This variable specifies the <math>\alpha, \beta, \omega</math> for CAM-type
493 !% hybrid functionals. Defaults are zero.
494 !%End
495 cam_ext = cam_null
496
497 if(parse_block(namespace, 'HybridCamParameters', blk) == 0) then
498 call parse_block_float(blk, 0, 0, cam_ext%alpha)
499 call parse_block_float(blk, 0, 1, cam_ext%beta)
500 call parse_block_float(blk, 0, 2, cam_ext%omega)
501 call parse_block_end(blk)
502 end if
503
504 if(.not. cam_ext%is_null()) then
505 call cam_ext%print(namespace, msg="Info: Setting external CAM parameters")
506 endif
507
508 pop_sub(xc_init.parse)
509 end subroutine parse
510
511 end subroutine xc_init
512
513
514 ! ---------------------------------------------------------
515 subroutine xc_end(xcs)
516 type(xc_t), intent(inout) :: xcs
517
518 integer :: isp
519
520 push_sub(xc_end)
521
522 do isp = 1, 2
523 call xc_functional_end(xcs%functional(func_x, isp))
524 call xc_functional_end(xcs%functional(func_c, isp))
525 call xc_functional_end(xcs%kernel(func_x, isp))
526 call xc_functional_end(xcs%kernel(func_c, isp))
527 end do
528 xcs%family = 0
529 xcs%flags = 0
530
531 ! Free the persistent host staging buffers (see internal_quantities_t), allocated
532 ! with the hardware-aware allocator in xc_compute_vxc.
533 if (associated(xcs%quantities%hbuf_dens)) then
534 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dens(1,1)), size(xcs%quantities%hbuf_dens, kind=int64)*8_int64)
535 nullify(xcs%quantities%hbuf_dens)
536 end if
537 if (associated(xcs%quantities%hbuf_sigma)) then
538 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_sigma(1,1)), size(xcs%quantities%hbuf_sigma, kind=int64)*8_int64)
539 nullify(xcs%quantities%hbuf_sigma)
540 end if
541 if (associated(xcs%quantities%hbuf_ldens)) then
542 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_ldens(1,1)), size(xcs%quantities%hbuf_ldens, kind=int64)*8_int64)
543 nullify(xcs%quantities%hbuf_ldens)
544 end if
545 if (associated(xcs%quantities%hbuf_tau)) then
546 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_tau(1,1)), size(xcs%quantities%hbuf_tau, kind=int64)*8_int64)
547 nullify(xcs%quantities%hbuf_tau)
548 end if
549 if (associated(xcs%quantities%hbuf_zk)) then
550 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_zk(1)), size(xcs%quantities%hbuf_zk, kind=int64)*8_int64)
551 nullify(xcs%quantities%hbuf_zk)
552 end if
553 if (associated(xcs%quantities%hbuf_dedd)) then
554 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dedd(1,1)), size(xcs%quantities%hbuf_dedd, kind=int64)*8_int64)
555 nullify(xcs%quantities%hbuf_dedd)
556 end if
557 if (associated(xcs%quantities%hbuf_vsigma)) then
558 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_vsigma(1,1)), size(xcs%quantities%hbuf_vsigma, kind=int64)*8_int64)
559 nullify(xcs%quantities%hbuf_vsigma)
560 end if
561 if (associated(xcs%quantities%hbuf_dedldens)) then
562 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dedldens(1,1)), &
563 size(xcs%quantities%hbuf_dedldens, kind=int64)*8_int64)
564 nullify(xcs%quantities%hbuf_dedldens)
565 end if
566 if (associated(xcs%quantities%hbuf_dedtau)) then
567 call deallocate_hardware_aware(c_loc(xcs%quantities%hbuf_dedtau(1,1)), size(xcs%quantities%hbuf_dedtau, kind=int64)*8_int64)
568 nullify(xcs%quantities%hbuf_dedtau)
569 end if
570
571 pop_sub(xc_end)
572 end subroutine xc_end
573
574 ! ---------------------------------------------------------
579 logical pure function xc_is_orbital_dependent(xcs)
580 type(xc_t), intent(in) :: xcs
581
582 xc_is_orbital_dependent = family_is_hybrid(xcs) .or. &
583 in_family(xcs%functional(func_x,1)%family, [xc_family_oep]) .or. &
584 in_family(xcs%family, [xc_family_mgga, xc_family_nc_mgga])
585
586 end function xc_is_orbital_dependent
587
588 ! ---------------------------------------------------------
590 pure logical function family_is_gga(family, only_collinear)
591 integer, intent(in) :: family
592 logical, optional, intent(in) :: only_collinear
593
594 if(optional_default(only_collinear, .false.)) then
595 family_is_gga = in_family(family, [xc_family_gga, xc_family_hyb_gga, &
596 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc])
597 else
598 family_is_gga = in_family(family, [xc_family_gga, xc_family_hyb_gga, &
599 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc, xc_family_nc_mgga])
600 end if
601 end function family_is_gga
602
603 !----------------------------------------------------------------------
608 pure logical function family_is_supported(family)
609 integer, intent(in) :: family
610
611 family_is_supported = in_family(family, [xc_family_lda, xc_family_hyb_lda, xc_family_gga, xc_family_hyb_gga, &
612 xc_family_mgga, xc_family_hyb_mgga, xc_family_libvdwxc])
613 end function family_is_supported
614
615 ! ---------------------------------------------------------
617 pure logical function family_is_mgga(family, only_collinear)
618 integer, intent(in) :: family
619 logical, optional, intent(in) :: only_collinear
620
621 if(optional_default(only_collinear, .false.)) then
622 family_is_mgga = in_family(family, [xc_family_mgga, xc_family_hyb_mgga])
623 else
624 family_is_mgga = in_family(family, [xc_family_mgga, xc_family_hyb_mgga, xc_family_nc_mgga])
625 end if
626 end function family_is_mgga
627
628 pure logical function family_is_nc_mgga(family)
629 integer, intent(in) :: family
630
631 family_is_nc_mgga = bitand(family, xc_family_nc_mgga) /= 0
632 end function family_is_nc_mgga
633
634 ! ---------------------------------------------------------
636 logical pure function family_is_mgga_with_exc(xcs)
637 type(xc_t), intent(in) :: xcs
638
639 integer :: ixc
640
642 do ixc = 1, 2
643 if (in_family(xcs%functional(ixc, 1)%family, [xc_family_mgga, xc_family_hyb_mgga, xc_family_nc_mgga]) &
644 .and. xc_functional_is_energy_functional(xcs%functional(ixc, 1))) then
646 end if
647 end do
648 end function family_is_mgga_with_exc
649
651 logical pure function family_is_hybrid(xcs)
652 type(xc_t), intent(in) :: xcs
653
654 integer :: ixc
655
656 family_is_hybrid = .false.
657 do ixc = 1, 2
658 if (in_family(xcs%functional(ixc, 1)%family, [xc_family_hyb_lda, xc_family_hyb_gga, xc_family_hyb_mgga])) then
660 end if
661 end do
662 end function family_is_hybrid
664 pure logical function in_family(family, xc_families)
665 integer, intent(in) :: family
666 integer, intent(in) :: xc_families(:)
667
668 in_family = bitand(family, sum(xc_families)) /= 0
669 end function in_family
670
672 logical function xc_compute_exchange(xc, theory_level)
673 class(xc_t), intent(in) :: xc
674 integer, intent(in) :: theory_level
675
676 integer, parameter :: exchange_theory_level(3) = [hartree, hartree_fock, rdmft]
677
678 push_sub(xc_compute_exchange)
679
680 xc_compute_exchange = any(exchange_theory_level == theory_level) .or. &
681 (theory_level == generalized_kohn_sham_dft .and. family_is_hybrid(xc)) .or. &
682 (xc%functional(func_x, 1)%id == xc_oep_x_slater) .or. &
683 (bitand(xc%family, xc_family_oep) /= 0)
684
685 pop_sub(xc_compute_exchange)
686
687 end function xc_compute_exchange
688
689 ! ---------------------------------------------------------
691 subroutine set_hybrid_params(xcs, namespace, cam_ext)
692 type(xc_t), intent(inout) :: xcs
693 type(namespace_t), intent(in) :: namespace
694 type(xc_cam_t), intent(in) :: cam_ext
695
696 real(real64), parameter :: default_alpha_pbe0 = 0.25_real64
697 real(real64) :: parameters(3)
698
699 push_sub(set_hybrid_params)
700
701 ! LibXC expects an array of reals, ordered [alpha, beta, omega]
702 parameters = cam_ext%as_array()
703 xcs%cam%alpha = parameters(1)
704
705 select case(xcs%functional(func_c, 1)%id)
706
707 case(xc_hyb_gga_xc_pbeh, xc_hyb_lda_xc_lda0) ! original PBE0/LDA0 in libxc
708 if(parameters(1) < m_zero) parameters(1) = default_alpha_pbe0
709 call xc_f03_func_set_ext_params(xcs%functional(func_c, 1)%conf, parameters)
710 call xc_f03_func_set_ext_params(xcs%functional(func_c, 2)%conf, parameters)
711 write(message(1), '(a,f6.3,a)') 'Info: Setting mixing parameter (' , parameters(1) ,').'
712 call messages_info(1)
713
714 case(xc_hyb_gga_xc_cam_pbeh, xc_hyb_lda_xc_cam_lda0)
715 xcs%cam%beta = parameters(2)
716 xcs%cam%omega = parameters(3)
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 ! check parameters
720 call xc_f03_hyb_cam_coef(xcs%functional(func_c,1)%conf, xcs%cam%omega, &
721 xcs%cam%alpha, xcs%cam%beta)
722 call xc_f03_hyb_cam_coef(xcs%functional(func_c,2)%conf, xcs%cam%omega, &
723 xcs%cam%alpha, xcs%cam%beta)
724 call xcs%cam%print(namespace, msg="Setting CAM parameters:")
725
726 case default
727 assert(.false.)
728
729 end select
730
731 pop_sub(set_hybrid_params)
732 end subroutine set_hybrid_params
733
734 ! ---------------------------------------------------------
736 logical function xc_is_not_size_consistent(xcs, namespace)
737 type(xc_t), intent(in) :: xcs
738 type(namespace_t), intent(in) :: namespace
739
740 xc_is_not_size_consistent = xc_functional_is_not_size_consistent(xcs%functional(func_x,1), namespace) &
741 .or. xc_functional_is_not_size_consistent(xcs%functional(func_c,1), namespace)
742 end function xc_is_not_size_consistent
743
744 ! ---------------------------------------------------------
746 logical pure function xc_is_energy_functional(xcs)
747 type(xc_t), intent(in) :: xcs
748 xc_is_energy_functional = xc_functional_is_energy_functional(xcs%functional(func_x,1)) &
749 .or. xc_functional_is_energy_functional(xcs%functional(func_c,1))
750 end function xc_is_energy_functional
751
752end module xc_oct_m
753
754
755!! Local Variables:
756!! mode: f90
757!! coding: utf-8
758!! 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: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:352
pure logical function, public family_is_mgga(family, only_collinear)
Is the xc function part of the mGGA family.
Definition: xc.F90:702
subroutine set_hybrid_params(xcs, namespace, cam_ext)
Sets external parameters for some hybrid functionals.
Definition: xc.F90:776
pure logical function, public family_is_gga(family, only_collinear)
Is the xc function part of the GGA family.
Definition: xc.F90:675
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:721
logical function, public xc_is_using_device(namespace)
Check if XC will run on device (parses config and checks availability)
Definition: xc.F90:328
subroutine, public xc_end(xcs)
Definition: xc.F90:600
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:831
logical pure function, public family_is_hybrid(xcs)
Returns true if the functional is an hybrid functional.
Definition: xc.F90:736
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:821
subroutine, public xc_init_device_support(xcs, namespace)
Definition: xc.F90:315
integer, parameter, public lr_x
Definition: xc.F90:257
pure logical function, public family_is_nc_mgga(family)
Definition: xc.F90:713
logical function xc_compute_exchange(xc, theory_level)
Theory levels and functionals for which exacy exchange is required.
Definition: xc.F90:757
pure logical function, public family_is_supported(family)
Is the xc family internally supported by Octopus.
Definition: xc.F90:693
pure logical function, public in_family(family, xc_families)
Definition: xc.F90:749
subroutine, public xc_write_fxc_info(xcs, iunit, namespace)
Definition: xc.F90:294
logical pure function, public xc_is_orbital_dependent(xcs)
Is the xc family orbital dependent.
Definition: xc.F90:664
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:486