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: do_potential_coulomb,&
13 : do_potential_gaussian,&
14 : do_potential_long,&
15 : do_potential_mix_cl,&
16 : do_potential_mix_cl_trunc,&
17 : do_potential_mix_lg,&
18 : do_potential_short,&
19 : do_potential_truncated
20 : USE kinds, ONLY: default_path_length,&
21 : dp
22 :
23 : IMPLICIT NONE
24 :
25 : PRIVATE
26 :
27 : INTEGER, PARAMETER, PUBLIC :: library_native = 0, &
28 : library_libint = 1
29 :
30 : #if defined(__LIBINT)
31 : INTEGER, PARAMETER, PUBLIC :: default_coulomb_library = library_libint
32 : LOGICAL, PARAMETER :: libint_available = .TRUE.
33 : #else
34 : INTEGER, PARAMETER, PUBLIC :: default_coulomb_library = library_native
35 : LOGICAL, PARAMETER :: libint_available = .FALSE.
36 : #endif
37 :
38 : TYPE, PUBLIC :: integral_library_type
39 : INTEGER :: coulomb2_library = default_coulomb_library
40 : INTEGER :: coulomb3_library = default_coulomb_library
41 : END TYPE integral_library_type
42 :
43 : TYPE, PUBLIC :: coulomb_operator_type
44 : INTEGER :: potential_type = do_potential_coulomb
45 : REAL(dp) :: omega = 0.0_dp ! SR: erfc(omega*r)/r
46 : REAL(dp) :: cutoff_radius = 0.0_dp ! TC cutoff/effective SR range
47 : CHARACTER(default_path_length) :: filename = ""
48 : REAL(dp) :: scale_coulomb = 0.0_dp ! Only for WFC methods
49 : REAL(dp) :: scale_longrange = 0.0_dp ! Only for WFC methods
50 : REAL(dp) :: scale_gaussian = 0.0_dp ! Gaussian coefficient in mixed operators
51 : END TYPE coulomb_operator_type
52 :
53 : ! Enlarge the support slightly when screening the discontinuous truncated Coulomb operator.
54 : REAL(dp), PARAMETER, PUBLIC :: cutoff_screen_factor = 1.0001_dp
55 :
56 : TYPE(integral_library_type), SAVE, PUBLIC :: active_integral_library = integral_library_type()
57 :
58 : PUBLIC :: compare_potential_types, integral_library_init
59 :
60 : CONTAINS
61 :
62 : ! **************************************************************************************************
63 : !> \brief Compare the parameters defining two radial operators.
64 : !> \param potential1 first operator
65 : !> \param potential2 second operator
66 : !> \return whether the operator selectors and their relevant parameters agree
67 : !> \note Table filenames and effective short-range screening cutoffs are excluded.
68 : ! **************************************************************************************************
69 14094 : PURE FUNCTION compare_potential_types(potential1, potential2) RESULT(equals)
70 : TYPE(coulomb_operator_type), INTENT(IN) :: potential1, potential2
71 : LOGICAL :: equals
72 :
73 14094 : equals = .FALSE.
74 14094 : IF (potential1%potential_type /= potential2%potential_type) RETURN
75 :
76 13264 : equals = .TRUE.
77 714 : SELECT CASE (potential1%potential_type)
78 : CASE (do_potential_short, do_potential_long, do_potential_gaussian)
79 714 : IF (potential1%omega /= potential2%omega) equals = .FALSE.
80 : CASE (do_potential_truncated)
81 16 : IF (potential1%cutoff_radius /= potential2%cutoff_radius) equals = .FALSE.
82 : CASE (do_potential_mix_cl, do_potential_mix_cl_trunc)
83 2 : IF (potential1%omega /= potential2%omega) equals = .FALSE.
84 2 : IF (potential1%scale_coulomb /= potential2%scale_coulomb) equals = .FALSE.
85 2 : IF (potential1%scale_longrange /= potential2%scale_longrange) equals = .FALSE.
86 2 : IF (potential1%potential_type == do_potential_mix_cl_trunc) THEN
87 2 : IF (potential1%cutoff_radius /= potential2%cutoff_radius) equals = .FALSE.
88 : END IF
89 : CASE (do_potential_mix_lg)
90 0 : IF (potential1%omega /= potential2%omega) equals = .FALSE.
91 0 : IF (potential1%scale_longrange /= potential2%scale_longrange) equals = .FALSE.
92 13264 : IF (potential1%scale_gaussian /= potential2%scale_gaussian) equals = .FALSE.
93 : END SELECT
94 : END FUNCTION compare_potential_types
95 :
96 : ! **************************************************************************************************
97 : !> \brief Resolves requested Coulomb integral libraries against the compiled-in backends.
98 : !> \param coulomb2_library requested two-center Coulomb integral library
99 : !> \param coulomb3_library requested three-center Coulomb integral library
100 : !> \param fallback_applied whether an unavailable Libint request was replaced by the native backend
101 : ! **************************************************************************************************
102 11915 : SUBROUTINE integral_library_init(coulomb2_library, coulomb3_library, fallback_applied)
103 : INTEGER, INTENT(IN) :: coulomb2_library, coulomb3_library
104 : LOGICAL, INTENT(OUT) :: fallback_applied
105 :
106 11915 : active_integral_library%coulomb2_library = coulomb2_library
107 11915 : active_integral_library%coulomb3_library = coulomb3_library
108 11915 : fallback_applied = .FALSE.
109 :
110 : IF (.NOT. libint_available) THEN
111 : IF (active_integral_library%coulomb2_library == library_libint) THEN
112 : active_integral_library%coulomb2_library = library_native
113 : fallback_applied = .TRUE.
114 : END IF
115 : IF (active_integral_library%coulomb3_library == library_libint) THEN
116 : active_integral_library%coulomb3_library = library_native
117 : fallback_applied = .TRUE.
118 : END IF
119 : END IF
120 :
121 11915 : END SUBROUTINE integral_library_init
122 :
123 0 : END MODULE integral_library_types
|