• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eT-program / eT / 22727

07 Apr 2025 10:56PM UTC coverage: 88.592% (-0.007%) from 88.599%
22727

push

gitlab-ci

Merge branch 'fix-cc2-multipliers-summary' into 'development'

Bugfix for CC2 multipliers summary

See merge request eT-program/eT!1554

14 of 14 new or added lines in 1 file covered. (100.0%)

5 existing lines in 1 file now uncovered.

53886 of 60825 relevant lines covered (88.59%)

3057300.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.54
/src/dft_library/functional_manager_class.F90
1
module functional_manager_class
2

3
   !!
4
   !! Functional manager class module
5
   !!  Written by Marco Scavino, October 2022
6
   !!
7
   !!  This class is a wrapper to get the XC functionals from the libxc
8
   !!  external library
9
   !!
10

11
   use parameters
12
   use global_in, only: input
13
   use functional_class, only: functional
14

15
   use memory_manager_class, only: mem
16

17
   use global_out, only: output
18

19
   implicit none
20

21

22
   type :: functional_manager
23

24
      real(dp) :: hf_percentage   = zero
25
      real(dp) :: hf_fraction     = zero
26

27
      real(dp) :: rho_threshold
28
      logical :: is_polarized = .false.
29

30
      integer :: n_functionals
31
      class(functional), dimension(:), allocatable :: functionals
32

33
      character(len=3) :: functional_type = ''
34

35
   contains
36

37
      procedure :: print_settings    => print_settings_functional_manager
38

39
      procedure :: cleanup           => cleanup_functional_manager
40

41
      procedure :: calculate_exc_vxc => calculate_exc_vxc_functional_manager
42

43
      procedure, private :: initialize
44
      procedure, private, nopass :: get_library
45

46
   end type functional_manager
47

48
   interface functional_manager
49
      procedure :: new_functional_manager
50
   end interface functional_manager
51

52
contains
53

54
   function new_functional_manager(is_polarized) result(this)
24✔
55
      !!
56
      !! Written by Marco Scavino, May 2019
57
      !!
58
      !! Call the libxc library to get all the info about the selected functional.
59
      !!
60
      implicit none
61

62
      logical, intent(in) :: is_polarized
63

64
      type(functional_manager) :: this
65

66
      this%rho_threshold = 1.0E-15_dp
24✔
67
      this%is_polarized = .false.
68

UNCOV
69
      if(is_polarized) this%is_polarized = is_polarized
×
70

71
      this%n_functionals = 0
24✔
72

73
      call this%initialize()
24✔
74

75
      ! check if family is hybrid. In case, get the proper HF exchange percentage
76

77
      if(this%hf_fraction.eq.zero) then
24✔
78

79
         call input%get_keyword("hf percentage", "dft functional", this%hf_percentage)
18✔
80

81
         if(this%hf_percentage < zero .or. this%hf_percentage > 100.0_dp) then
18✔
82

UNCOV
83
            call output%printf('n',"HF percentage equal to (f6.2)!", reals=[this%hf_percentage])
×
UNCOV
84
            call output%error_msg("Should be greater than 0 and lower than 100!")
×
85

86
         end if
87

88
         this%hf_fraction = this%hf_percentage/100.0_dp
18✔
89

90
      end if
91

92
   end function new_functional_manager
24✔
93

94

95
   subroutine cleanup_functional_manager(this)
24✔
96
      !!
97
      !! Written by Marco Scavino, May 2019
98
      !!
99
      implicit none
100

101
      class(functional_manager), intent(inout) :: this
102
      integer :: i
103

104
      do i=1, this%n_functionals
54✔
105

106
         call this%functionals(i)%cleanup()
54✔
107

108
      end do
109

110
   end subroutine cleanup_functional_manager
24✔
111

112

113
   subroutine print_settings_functional_manager(this)
24✔
114
      !!
115
      !! Written by Marco Scavino, May 2019
116
      !!
117
      use string_utilities, only: convert_to_lowercase
118
      implicit none
119

120
      class(functional_manager), intent(in) :: this
121

122
      integer :: i
123
      character(len=40) :: kind_
124

125
      call output%printf("n", "", fs='(/)')
24✔
126
      do i=1, this%n_functionals
54✔
127

128
         kind_ = this%functionals(i)%kind_
30✔
129
         call convert_to_lowercase(kind_)
30✔
130

131
         call output%printf('n', trim(kind_) &
132
            // ' functional:    ' // trim(this%functionals(i)%name), fs='(t6,a)')
54✔
133

134
      end do
135

136

137
      call output%printf('n','Density threshold:                (e8.2)', reals=[this%rho_threshold],            &
138
         fs='(/t6,a)')
48✔
139

140
      call output%printf('n','HF percentage (%):                (f6.2)', reals=[this%hf_fraction*100.0E0_dp], &
141
         fs='(/t6,a)')
48✔
142

143
   end subroutine print_settings_functional_manager
24✔
144

145

146
   subroutine calculate_exc_vxc_functional_manager(this, n_points, rho, sigma, e_xc, v_rho, v_sigma)
264✔
147
      !!
148
      !! Written by Marco Scavino, 2022
149
      !!
150
      !! Given a rho (and also sigma for GGA), return the derivatives of the functional
151
      !!
152
      !! e_xc    = ∂ε_xc/∂r
153
      !! v_rho   = ∂ε_xc/∂ρ
154
      !! v_sigma = ∂ε_xc/∂∇ρ
155
      !!
156

157
      use array_initialization, only: zero_array
158
      use omp_lib
159

160
      implicit none
161

162
      class(functional_manager), intent(inout) :: this
163
      integer, intent(in) :: n_points
164

165
      real(dp), intent(in), dimension(n_points) :: rho, sigma
166
      real(dp), intent(out), dimension(n_points) :: v_rho, v_sigma, e_xc
167

168
      integer :: i
169
      real(dp) :: beta
170

171
      real(dp), allocatable, dimension(:) :: v_rho_local, v_sigma_local, e_xc_local
264✔
172

173
      call mem%alloc(e_xc_local, n_points)
264✔
174
      call mem%alloc(v_rho_local, n_points)
264✔
175
      call mem%alloc(v_sigma_local, n_points)
264✔
176

177
      call zero_array(e_xc, n_points)
264✔
178
      call zero_array(v_rho, n_points)
264✔
179
      call zero_array(v_sigma, n_points)
264✔
180

181
      do i=1, this%n_functionals
594✔
182

183
         call this%functionals(i)%calculate_exc_vxc(&
184
            n_points, rho, sigma, e_xc_local, v_rho_local, v_sigma_local)
330✔
185

186
         ! If hybrid exchange, scale by (1 - α)
187

188
         beta = one
330✔
189

190
         if(this%functionals(i)%hf_fraction.gt.zero.and.this%functionals(i)%kind_ .eq. "EXCHANGE") then
330✔
UNCOV
191
            beta = (one - this%functionals(i)%hf_fraction)
×
192
         endif
193

194
         call daxpy(n_points, beta, e_xc_local, 1, e_xc, 1)
330✔
195
         call daxpy(n_points, beta, v_rho_local, 1, v_rho, 1)
330✔
196

197
         if(this%functionals(i)%family == "GGA")then
594✔
198

199
            call daxpy(n_points, beta, v_sigma_local, 1, v_sigma, 1)
198✔
200

201
         endif
202

203
      end do
204

205
      call mem%dealloc(e_xc_local)
264✔
206
      call mem%dealloc(v_rho_local)
264✔
207
      call mem%dealloc(v_sigma_local)
264✔
208

209
   end subroutine calculate_exc_vxc_functional_manager
264✔
210

211

212
   subroutine get_library(selected)
24✔
213
      !!
214
      !! Written by Marco Scavino, 2022
215
      !!
216
      !! Select the available library
217
      !!
218
      use warning_suppressor,   only: do_nothing
219
#ifdef LIBXC_MAJOR
220
      use libxc_class, only: libxc
221
#endif
222
      implicit none
223

224
      class(functional), allocatable :: selected
225

226
#ifdef LIBXC_MAJOR
227
      allocate(libxc::selected)
24✔
228
#else
229
      call do_nothing(selected)
230
      call output%error_msg("eT has not been compiled with a proper functional library!")
231
#endif
232

233
   end subroutine get_library
24✔
234

235

236
   subroutine initialize(this)
24✔
237
      !!
238
      !! Written by Marco Scavino, October 2019
239
      !!
240
      implicit none
241

242
      class(functional_manager), intent(inout) :: this
243

244
      character(len=200), allocatable :: names(:)
24✔
245
      class(functional), allocatable :: selected
48✔
246

247
      integer :: i
248

249
      call this%get_library(selected)
24✔
250
      call selected%read_functionals_names(names)
24✔
251

252
      this%n_functionals = size(names)
24✔
253
      allocate(this%functionals(this%n_functionals), source=selected)
78✔
254

255
      this%hf_percentage = zero
24✔
256

257
      do i=1, this%n_functionals
54✔
258

259
         call this%functionals(i)%initialize(names(i), this%is_polarized, this%rho_threshold)
30✔
260

261
         if(trim(this%functional_type).eq.'lda'.or.this%functionals(i)%family.eq.'LDA') then
30✔
262

263
            this%functional_type = 'lda'
12✔
264

265
         else if(trim(this%functional_type).eq.'gga'.or.this%functionals(i)%family.eq.'GGA') then
18✔
266

267
            this%functional_type = 'gga'
18✔
268

269
         endif
270

271
         if(this%hf_fraction.gt.zero.or.this%functionals(i)%hf_fraction.gt.zero) then
54✔
272

273
            this%hf_fraction = this%hf_fraction + this%functionals(i)%hf_fraction
6✔
274

275
         endif
276

277
      end do
278

279
   end subroutine initialize
24✔
280

281

UNCOV
282
end module
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc