14 USE ieee_arithmetic,
ONLY: ieee_is_finite
17#include "../base/base_uses.f90"
37 COMPLEX(dp),
INTENT(IN) :: left(:, :), right(:, :)
38 REAL(
dp),
INTENT(IN) :: weights(:)
39 COMPLEX(dp),
INTENT(OUT) :: integral(:, :)
42 CALL check_pair(left, right, weights, shape(integral))
43 integral = cmplx(0.0_dp, 0.0_dp,
dp)
44 CALL add_pair(left, right, weights, integral)
45 IF (
PRESENT(comm))
CALL comm%sum(integral)
60 weights_response, response, comm)
61 COMPLEX(dp),
INTENT(IN) :: left(:, :), right(:, :)
62 REAL(
dp),
INTENT(IN) :: weights(:)
63 COMPLEX(dp),
INTENT(IN) :: left_response(:, :), right_response(:, :)
64 REAL(
dp),
INTENT(IN) :: weights_response(:)
65 COMPLEX(dp),
INTENT(OUT) :: response(:, :)
68 CALL check_pair(left, right, weights, shape(response))
69 cpassert(all(shape(left_response) == shape(left)))
70 cpassert(all(shape(right_response) == shape(right)))
71 cpassert(
SIZE(weights_response) ==
SIZE(weights))
72 response = cmplx(0.0_dp, 0.0_dp,
dp)
73 CALL add_pair(left_response, right, weights, response)
74 CALL add_pair(left, right_response, weights, response)
75 CALL add_pair(left, right, weights_response, response)
76 IF (
PRESENT(comm))
CALL comm%sum(response)
97 vdensity, vgradient, vtau, integral, comm)
98 COMPLEX(dp),
INTENT(IN) :: left(:, :), right(:, :), &
99 left_gradient(:, :, :), &
100 right_gradient(:, :, :)
101 REAL(
dp),
INTENT(IN) :: weights(:), vdensity(:), &
102 vgradient(:, :), vtau(:)
103 COMPLEX(dp),
INTENT(OUT) :: integral(:, :)
106 COMPLEX(dp),
ALLOCATABLE :: work(:, :)
107 INTEGER :: axis, nright
108 LOGICAL :: gradient_active(3), tau_active
110 CALL check_semilocal(left, right, left_gradient, right_gradient, weights, &
111 vdensity, vgradient, vtau, shape(integral))
112 integral = cmplx(0.0_dp, 0.0_dp,
dp)
113 IF (.NOT. any(weights /= 0.0_dp) .OR. &
114 .NOT. (any(vdensity /= 0.0_dp) .OR. any(vgradient /= 0.0_dp) .OR. any(vtau /= 0.0_dp)))
THEN
115 IF (
PRESENT(comm))
CALL comm%sum(integral)
119 gradient_active(axis) = any(vgradient(:, axis) /= 0.0_dp)
121 tau_active = any(vtau /= 0.0_dp)
122 nright =
SIZE(right, 2)
123 ALLOCATE (work(
SIZE(right, 1), nright))
124 work(:, :) = spread(vdensity, 2, nright)*right
126 IF (.NOT. gradient_active(axis)) cycle
127 work(:, :) = work + spread(vgradient(:, axis), 2, nright)*right_gradient(:, :, axis)
129 CALL add_pair(left, work, weights, integral)
131 IF (.NOT. gradient_active(axis) .AND. .NOT. tau_active) cycle
132 work(:, :) = spread(vgradient(:, axis), 2, nright)*right
133 IF (tau_active) work(:, :) = work + 0.5_dp*spread(vtau, 2, nright)*right_gradient(:, :, axis)
134 CALL add_pair(left_gradient(:, :, axis), work, weights, integral)
136 IF (
PRESENT(comm))
CALL comm%sum(integral)
162 vdensity, vgradient, vtau, left_response, right_response, &
163 left_gradient_response, right_gradient_response, &
164 weights_response, vdensity_response, vgradient_response, &
165 vtau_response, response, comm)
166 COMPLEX(dp),
INTENT(IN) :: left(:, :), right(:, :), &
167 left_gradient(:, :, :), &
168 right_gradient(:, :, :)
169 REAL(
dp),
INTENT(IN) :: weights(:), vdensity(:), &
170 vgradient(:, :), vtau(:)
171 COMPLEX(dp),
INTENT(IN) :: left_response(:, :), right_response(:, :), &
172 left_gradient_response(:, :, :), right_gradient_response(:, :, :)
173 REAL(
dp),
INTENT(IN) :: weights_response(:), &
174 vdensity_response(:), &
175 vgradient_response(:, :), &
177 COMPLEX(dp),
INTENT(OUT) :: response(:, :)
180 COMPLEX(dp),
ALLOCATABLE :: work(:, :)
182 CALL check_semilocal(left, right, left_gradient, right_gradient, weights, &
183 vdensity, vgradient, vtau, shape(response))
184 CALL check_semilocal(left_response, right_response, left_gradient_response, right_gradient_response, &
185 weights_response, vdensity_response, vgradient_response, vtau_response, shape(response))
186 cpassert(all(shape(left_response) == shape(left)))
187 cpassert(all(shape(right_response) == shape(right)))
188 ALLOCATE (work(
SIZE(response, 1),
SIZE(response, 2)))
191 weights, vdensity, vgradient, vtau, response)
193 weights, vdensity, vgradient, vtau, work)
194 response = response + work
196 weights_response, vdensity, vgradient, vtau, work)
197 response = response + work
199 weights, vdensity_response, vgradient_response, vtau_response, work)
200 response = response + work
201 IF (
PRESENT(comm))
CALL comm%sum(response)
217 COMPLEX(dp),
INTENT(IN) :: soft(:, :), soft_gradient(:, :, :), &
219 REAL(
dp),
INTENT(OUT) :: density(:), gradient(:, :), tau(:)
221 COMPLEX(dp),
ALLOCATABLE :: derivative(:, :), work(:, :)
222 INTEGER :: axis, n, npoint
223 REAL(
dp) :: tolerance
226 npoint =
SIZE(soft, 1)
227 cpassert(all(shape(ao_density) == [n, n]))
228 cpassert(all(shape(soft_gradient) == [npoint, n, 3]))
229 cpassert(
SIZE(density) == npoint .AND.
SIZE(tau) == npoint)
230 cpassert(all(shape(gradient) == [npoint, 3]))
232 tolerance = 128.0_dp*epsilon(1.0_dp)*max(1.0_dp, maxval(abs(ao_density)))
233 IF (.NOT. (maxval(abs(ao_density - conjg(transpose(ao_density)))) <= tolerance))
THEN
234 cpabort(
"Inconsistent inverse quadrature dimensions")
237 ALLOCATE (work(npoint, n), derivative(npoint, n))
238 work(:, :) = matmul(soft, ao_density)
239 density = real(sum(conjg(soft)*work, dim=2),
dp)
242 gradient(:, axis) = 2.0_dp*real(sum(conjg(soft_gradient(:, :, axis))*work, dim=2),
dp)
243 derivative(:, :) = matmul(soft_gradient(:, :, axis), ao_density)
244 tau = tau + 0.5_dp*real(sum(conjg(soft_gradient(:, :, axis))*derivative, dim=2),
dp)
255 SUBROUTINE add_pair(left, right, weights, integral)
256 COMPLEX(dp),
INTENT(IN) :: left(:, :), right(:, :)
257 REAL(
dp),
INTENT(IN) :: weights(:)
258 COMPLEX(dp),
INTENT(INOUT) :: integral(:, :)
260 COMPLEX(dp),
ALLOCATABLE :: work(:, :)
262 IF (
SIZE(weights) == 0 .OR.
SIZE(left, 2) == 0 .OR.
SIZE(right, 2) == 0)
RETURN
263 IF (.NOT. any(weights /= 0.0_dp))
RETURN
264 ALLOCATE (work(
SIZE(right, 1),
SIZE(right, 2)))
265 work(:, :) = spread(weights, 2,
SIZE(right, 2))*right
266 integral = integral + matmul(conjg(transpose(left)), work)
267 END SUBROUTINE add_pair
276 SUBROUTINE check_pair(left, right, weights, output_shape)
277 COMPLEX(dp),
INTENT(IN) :: left(:, :), right(:, :)
278 REAL(
dp),
INTENT(IN) :: weights(:)
279 INTEGER,
INTENT(IN) :: output_shape(2)
281 IF (.NOT. (
SIZE(left, 1) ==
SIZE(weights) .AND.
SIZE(right, 1) ==
SIZE(weights)))
THEN
282 cpabort(
"Inconsistent inverse quadrature dimensions")
284 cpassert(all(output_shape == [
SIZE(left, 2),
SIZE(right, 2)]))
285 cpassert(all(ieee_is_finite(weights)))
286 END SUBROUTINE check_pair
300 SUBROUTINE check_semilocal(left, right, left_gradient, right_gradient, weights, vdensity, vgradient, vtau, output_shape)
301 COMPLEX(dp),
INTENT(IN) :: left(:, :), right(:, :), &
302 left_gradient(:, :, :), &
303 right_gradient(:, :, :)
304 REAL(
dp),
INTENT(IN) :: weights(:), vdensity(:), &
305 vgradient(:, :), vtau(:)
306 INTEGER,
INTENT(IN) :: output_shape(2)
308 CALL check_pair(left, right, weights, output_shape)
309 IF (.NOT. (all(shape(left_gradient) == [
SIZE(left, 1),
SIZE(left, 2), 3])))
THEN
310 cpabort(
"Inconsistent inverse quadrature dimensions")
312 IF (.NOT. (all(shape(right_gradient) == [
SIZE(right, 1),
SIZE(right, 2), 3])))
THEN
313 cpabort(
"Inconsistent inverse quadrature dimensions")
315 IF (.NOT. (
SIZE(vdensity) ==
SIZE(weights) .AND.
SIZE(vtau) ==
SIZE(weights)))
THEN
316 cpabort(
"Inconsistent inverse quadrature dimensions")
318 cpassert(all(shape(vgradient) == [
SIZE(weights), 3]))
319 END SUBROUTINE check_semilocal
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
Common point quadratures and semilocal adjoints for inverse UPF basis blocks. Point rows may be MPI-d...
subroutine, public upf_inverse_semilocal_response(left, right, left_gradient, right_gradient, weights, vdensity, vgradient, vtau, left_response, right_response, left_gradient_response, right_gradient_response, weights_response, vdensity_response, vgradient_response, vtau_response, response, comm)
Response of the same semilocal block, including moving gradients, potentials and measure....
subroutine, public upf_inverse_pair(left, right, weights, integral, comm)
Integrate left^dagger * weights * right, without discarding intercenter terms. Use the same rule for ...
subroutine, public upf_inverse_smooth_density(soft, soft_gradient, ao_density, density, gradient, tau)
Smooth density descriptors whose adjoint is the semilocal pair operator. Per-spin AO density includes...
subroutine, public upf_inverse_pair_response(left, right, weights, left_response, right_response, weights_response, response, comm)
Differentiate both field legs and the original quadrature measure.
subroutine, public upf_inverse_semilocal_pair(left, right, left_gradient, right_gradient, weights, vdensity, vgradient, vtau, integral, comm)
Semilocal rectangular block for density, Cartesian density gradient and tau potentials....