54 REAL(
dp),
INTENT(IN) :: r(:), radial(:, :)
55 INTEGER,
INTENT(IN) :: lbeta(:)
57 LOGICAL,
INTENT(IN),
OPTIONAL :: finite_table
59 INTEGER :: first, i, j, l, last, m, n, p
61 REAL(
dp),
ALLOCATABLE :: slope(:),
value(:), y(:)
64 cpassert(n >= 4 .AND.
SIZE(lbeta) > 0)
65 cpassert(all(shape(radial) == [n,
SIZE(lbeta)]))
66 cpassert(all(ieee_is_finite(r)) .AND. all(ieee_is_finite(radial)))
67 cpassert(all(r >= 0.0_dp) .AND. all(r(2:) > r(:n - 1)))
68 cpassert(all(lbeta >= 0) .AND. all(lbeta <= 20))
70 IF (r(1) == 0.0_dp) first = 2
71 n =
SIZE(r) - first + 1
73 fields%lmax = maxval(lbeta)
74 fields%nproj = sum(2*lbeta + 1)
75 IF (
PRESENT(finite_table)) fields%finite_table = finite_table
76 IF (fields%finite_table) fields%radius = r(
SIZE(r))
79 ALLOCATE (fields%lbeta, source=lbeta)
80 ALLOCATE (fields%x(n + 1), fields%coefficients(0:5, n,
SIZE(lbeta)), &
81 fields%radial_end(
SIZE(lbeta)), y(n), value(n + 1), slope(n + 1))
83 fields%x(2:) = r(first:)**2
84 fields%coefficients = 0.0_dp
87 IF (all(radial(:, i) == 0.0_dp)) cycle
89 IF (fields%finite_table)
THEN
90 fields%radial_end(i) =
SIZE(fields%x)
92 DO WHILE (radial(last, i) == 0.0_dp)
95 IF (last ==
SIZE(r))
THEN
96 cpabort(
"Original radial field requires an exact zero suffix")
98 fields%radial_end(i) = last - first + 3
99 fields%radius = max(fields%radius, r(last + 1))
101 cpassert(last >= first)
102 y(:) = radial(first:, i)/r(first:)**lbeta(i)
103 cpassert(all(ieee_is_finite(y)))
104 CALL spline3ders(fields%x(2:), y, fields%x, ynew=
value, dynew=slope)
105 DO j = 1, fields%radial_end(i) - 1
106 h = fields%x(j + 1) - fields%x(j)
107 associate(c => fields%coefficients(:, j, i))
110 c(3) = 3.0_dp*(value(j + 1) - c(1)) - 2.0_dp*c(2) - h*slope(j + 1)
111 c(4) = 2.0_dp*(c(1) - value(j + 1)) + c(2) + h*slope(j + 1)
112 IF (j + 1 == fields%radial_end(i) .AND. .NOT. fields%finite_table)
THEN
113 c(4) = -10.0_dp*c(1) - 6.0_dp*c(2) - 3.0_dp*c(3)
114 c(5) = 15.0_dp*c(1) + 8.0_dp*c(2) + 3.0_dp*c(3)
115 c(6) = -6.0_dp*c(1) - 3.0_dp*c(2) - c(3)
120 ALLOCATE (fields%radial_index(fields%nproj), fields%angular_index(fields%nproj))
122 DO i = 1,
SIZE(lbeta)
126 fields%radial_index(p) = i
127 fields%angular_index(p) = l*l + m
142 REAL(dp),
INTENT(IN) :: displacement(3)
143 REAL(dp),
INTENT(OUT) ::
value(:)
144 REAL(dp),
INTENT(OUT),
OPTIONAL :: gradient(:, :), hessian(:, :, :)
146 INTEGER :: a, axis, axis2, hi, i, l, lo, m, mid, p, &
147 powers(3), reduced(3)
148 REAL(dp) :: angular, da(3), dda(3, 3), factor, h, &
149 radial, rd, rdd, s, t, term
151 cpassert(
ALLOCATED(fields%x) .AND.
SIZE(
value) == fields%nproj)
153 IF (
PRESENT(gradient))
THEN
154 cpassert(all(shape(gradient) == [3, fields%nproj]))
157 IF (
PRESENT(hessian))
THEN
158 cpassert(all(shape(hessian) == [3, 3, fields%nproj]))
161 s = sum(displacement**2)
162 IF (fields%finite_table)
THEN
163 cpassert(s <= fields%radius**2)
164 ELSE IF (s >= fields%radius**2)
THEN
169 DO WHILE (hi - lo > 1)
171 IF (s < fields%x(mid))
THEN
177 h = fields%x(hi) - fields%x(lo)
178 t = (s - fields%x(lo))/h
179 DO p = 1, fields%nproj
180 i = fields%radial_index(p)
181 IF (lo >= fields%radial_end(i)) cycle
183 m = fields%angular_index(p) - l*l
184 associate(c => fields%coefficients(:, lo, i))
185 radial = c(1) + t*(c(2) + t*(c(3) + t*(c(4) + t*(c(5) + t*c(6)))))
186 rd = (c(2) + t*(2.0_dp*c(3) + t*(3.0_dp*c(4) + t*(4.0_dp*c(5) + t*5.0_dp*c(6)))))/h
187 rdd = (2.0_dp*c(3) + t*(6.0_dp*c(4) + t*(12.0_dp*c(5) + t*20.0_dp*c(6))))/h**2
193 powers = indco(:,
ncoset(l - 1) + a)
194 factor = orbtramat(l)%slm(m, a)
195 angular = angular + factor*product(displacement**powers)
197 IF (powers(axis) == 0) cycle
199 reduced(axis) = reduced(axis) - 1
200 term = factor*real(powers(axis), dp)
201 da(axis) = da(axis) + term*product(displacement**reduced)
203 IF (reduced(axis2) == 0) cycle
204 reduced(axis2) = reduced(axis2) - 1
205 dda(axis, axis2) = dda(axis, axis2) + &
206 term*real(reduced(axis2) + 1, dp)*product(displacement**reduced)
207 reduced(axis2) = reduced(axis2) + 1
211 value(p) = radial*angular
212 IF (
PRESENT(gradient)) gradient(:, p) = 2.0_dp*displacement*rd*angular + radial*da
213 IF (
PRESENT(hessian))
THEN
216 hessian(axis, axis2, p) = 4.0_dp*displacement(axis)*displacement(axis2)*rdd*angular + &
217 2.0_dp*rd*(displacement(axis)*da(axis2) + displacement(axis2)*da(axis)) + &
218 radial*dda(axis, axis2)
220 hessian(axis2, axis2, p) = hessian(axis2, axis2, p) + 2.0_dp*rd*angular
246 gradient, response, gradient_response, points_response, &
247 center_response, cell_response, reduced_k_response)
249 REAL(dp),
INTENT(IN) :: points(:, :), center(3), cell(3, 3)
250 INTEGER,
INTENT(IN) :: images(:, :)
251 REAL(dp),
INTENT(IN) :: reduced_k(3)
252 COMPLEX(dp),
INTENT(OUT) ::
value(:, :)
253 COMPLEX(dp),
INTENT(OUT),
OPTIONAL :: gradient(:, :, :), response(:, :), &
254 gradient_response(:, :, :)
255 REAL(dp),
INTENT(IN),
OPTIONAL :: points_response(:, :), &
256 center_response(3), &
257 cell_response(3, 3), &
258 reduced_k_response(3)
260 COMPLEX(dp) :: dphase, phase
261 INTEGER :: axis, image, point
262 REAL(dp) :: displacement(3), dr(3), dshift(3), &
263 shift(3), v(fields%nproj), &
264 hh(3, 3, fields%nproj), &
267 cpassert(
SIZE(points, 1) == 3 .AND.
SIZE(images, 1) == 3)
268 cpassert(all(shape(
value) == [
SIZE(points, 2), fields%nproj]))
269 value = cmplx(0.0_dp, 0.0_dp, dp)
270 IF (
PRESENT(gradient))
THEN
271 cpassert(all(shape(gradient) == [
SIZE(points, 2), fields%nproj, 3]))
272 gradient = cmplx(0.0_dp, 0.0_dp, dp)
274 IF (
PRESENT(response))
THEN
275 cpassert(all(shape(response) == shape(
value)))
276 response = cmplx(0.0_dp, 0.0_dp, dp)
278 IF (
PRESENT(gradient_response))
THEN
279 IF (.NOT. (all(shape(gradient_response) == [
SIZE(points, 2), fields%nproj, 3])))
THEN
280 cpabort(
"Invalid radial field response dimensions")
282 gradient_response = cmplx(0.0_dp, 0.0_dp, dp)
284 IF (
PRESENT(points_response))
THEN
285 cpassert(all(shape(points_response) == shape(points)))
287 DO image = 1,
SIZE(images, 2)
288 shift = center + matmul(cell, real(images(:, image), dp))
290 IF (
PRESENT(center_response)) dshift = center_response
291 IF (
PRESENT(cell_response)) dshift = dshift + matmul(cell_response, real(images(:, image), dp))
292 phase = exp(cmplx(0.0_dp, twopi*dot_product(reduced_k, real(images(:, image), dp)), dp))
293 dphase = cmplx(0.0_dp, 0.0_dp, dp)
294 IF (
PRESENT(reduced_k_response))
THEN
295 dphase = phase*cmplx(0.0_dp, twopi*dot_product(reduced_k_response, real(images(:, image), dp)), dp)
297 DO point = 1,
SIZE(points, 2)
298 displacement = points(:, point) - shift
300 IF (
PRESENT(points_response)) dr = dr + points_response(:, point)
301 IF (sum(displacement**2) >= fields%radius**2) cycle
302 IF (
PRESENT(gradient_response))
THEN
304 ELSE IF (
PRESENT(gradient) .OR.
PRESENT(response))
THEN
309 value(point, :) = value(point, :) + phase*v
310 IF (
PRESENT(response)) response(point, :) = response(point, :) + &
311 phase*matmul(dr, g) + dphase*v
313 IF (
PRESENT(gradient)) gradient(point, :, axis) = gradient(point, :, axis) + phase*g(axis, :)
314 IF (
PRESENT(gradient_response))
THEN
315 gradient_response(point, :, axis) = gradient_response(point, :, axis) + &
316 phase*matmul(dr, hh(axis, :, :)) + dphase*g(axis, :)
subroutine, public upf_radial_fields_periodic(fields, points, center, cell, images, reduced_k, value, gradient, response, gradient_response, points_response, center_response, cell_response, reduced_k_response)
Sum supplied Bloch images on common Cartesian quadrature points, including responses....