Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Library choices for electronic integral APIs.
10 : ! **************************************************************************************************
11 : MODULE integral_library_types
12 : USE input_constants, ONLY: &
13 : do_potential_TShPSC, do_potential_coulomb, do_potential_gaussian, do_potential_long, &
14 : do_potential_mix_cl, do_potential_mix_cl_trunc, do_potential_mix_lg, do_potential_short, &
15 : do_potential_truncated
16 : USE kinds, ONLY: default_path_length,&
17 : dp
18 :
19 : IMPLICIT NONE
20 :
21 : PRIVATE
22 :
23 : INTEGER, PARAMETER, PUBLIC :: library_native = 0, &
24 : library_libint = 1
25 :
26 : #if defined(__LIBINT)
27 : INTEGER, PARAMETER, PUBLIC :: default_coulomb_library = library_libint
28 : LOGICAL, PARAMETER :: libint_available = .TRUE.
29 : #else
30 : INTEGER, PARAMETER, PUBLIC :: default_coulomb_library = library_native
31 : LOGICAL, PARAMETER :: libint_available = .FALSE.
32 : #endif
33 :
34 : TYPE, PUBLIC :: integral_library_type
35 : INTEGER :: coulomb2_library = default_coulomb_library
36 : INTEGER :: coulomb3_library = default_coulomb_library
37 : END TYPE integral_library_type
38 :
39 : TYPE, PUBLIC :: coulomb_operator_type
40 : INTEGER :: potential_type = do_potential_coulomb
41 : REAL(dp) :: omega = 0.0_dp ! SR: erfc(omega*r)/r
42 : REAL(dp) :: cutoff_radius = 0.0_dp ! TC cutoff/effective SR range
43 : CHARACTER(default_path_length) :: filename = ""
44 : REAL(dp) :: scale_coulomb = 0.0_dp ! Only for WFC methods
45 : REAL(dp) :: scale_longrange = 0.0_dp ! Only for WFC methods
46 : REAL(dp) :: scale_gaussian = 0.0_dp ! Gaussian coefficient in mixed operators
47 : END TYPE coulomb_operator_type
48 :
49 : TYPE(integral_library_type), SAVE, PUBLIC :: active_integral_library = integral_library_type()
50 :
51 : PUBLIC :: compare_potential_types, integral_library_init
52 :
53 : CONTAINS
54 :
55 : ! **************************************************************************************************
56 : !> \brief Compare the parameters defining two radial operators.
57 : !> \param potential1 first operator
58 : !> \param potential2 second operator
59 : !> \return whether the operator selectors and their relevant parameters agree
60 : !> \note Table filenames and effective short-range screening cutoffs are excluded.
61 : ! **************************************************************************************************
62 14098 : PURE FUNCTION compare_potential_types(potential1, potential2) RESULT(equals)
63 : TYPE(coulomb_operator_type), INTENT(IN) :: potential1, potential2
64 : LOGICAL :: equals
65 :
66 14098 : equals = .FALSE.
67 14098 : IF (potential1%potential_type /= potential2%potential_type) RETURN
68 :
69 13270 : equals = .TRUE.
70 714 : SELECT CASE (potential1%potential_type)
71 : CASE (do_potential_short, do_potential_long, do_potential_gaussian)
72 714 : IF (potential1%omega /= potential2%omega) equals = .FALSE.
73 : CASE (do_potential_truncated, do_potential_TShPSC)
74 16 : IF (potential1%cutoff_radius /= potential2%cutoff_radius) equals = .FALSE.
75 : CASE (do_potential_mix_cl, do_potential_mix_cl_trunc)
76 2 : IF (potential1%omega /= potential2%omega) equals = .FALSE.
77 2 : IF (potential1%scale_coulomb /= potential2%scale_coulomb) equals = .FALSE.
78 2 : IF (potential1%scale_longrange /= potential2%scale_longrange) equals = .FALSE.
79 2 : IF (potential1%potential_type == do_potential_mix_cl_trunc) THEN
80 2 : IF (potential1%cutoff_radius /= potential2%cutoff_radius) equals = .FALSE.
81 : END IF
82 : CASE (do_potential_mix_lg)
83 0 : IF (potential1%omega /= potential2%omega) equals = .FALSE.
84 0 : IF (potential1%scale_longrange /= potential2%scale_longrange) equals = .FALSE.
85 13270 : IF (potential1%scale_gaussian /= potential2%scale_gaussian) equals = .FALSE.
86 : END SELECT
87 : END FUNCTION compare_potential_types
88 :
89 : ! **************************************************************************************************
90 : !> \brief Resolves requested Coulomb integral libraries against the compiled-in backends.
91 : !> \param coulomb2_library requested two-center Coulomb integral library
92 : !> \param coulomb3_library requested three-center Coulomb integral library
93 : !> \param fallback_applied whether an unavailable Libint request was replaced by the native backend
94 : ! **************************************************************************************************
95 11793 : SUBROUTINE integral_library_init(coulomb2_library, coulomb3_library, fallback_applied)
96 : INTEGER, INTENT(IN) :: coulomb2_library, coulomb3_library
97 : LOGICAL, INTENT(OUT) :: fallback_applied
98 :
99 11793 : active_integral_library%coulomb2_library = coulomb2_library
100 11793 : active_integral_library%coulomb3_library = coulomb3_library
101 11793 : fallback_applied = .FALSE.
102 :
103 : IF (.NOT. libint_available) THEN
104 : IF (active_integral_library%coulomb2_library == library_libint) THEN
105 : active_integral_library%coulomb2_library = library_native
106 : fallback_applied = .TRUE.
107 : END IF
108 : IF (active_integral_library%coulomb3_library == library_libint) THEN
109 : active_integral_library%coulomb3_library = library_native
110 : fallback_applied = .TRUE.
111 : END IF
112 : END IF
113 :
114 11793 : END SUBROUTINE integral_library_init
115 :
116 0 : END MODULE integral_library_types
|