17 USE ieee_arithmetic,
ONLY: ieee_quiet_nan,&
32 REAL(
dp),
PARAMETER :: step = 1.e-5_dp
33 REAL(
dp) :: max_error = 0.0_dp
35 CALL check_atomic_residual()
36 CALL check_gaussian_fields()
38 WRITE (*,
'(A)')
'upf_inverse_unittest PASS'
44 COMPLEX(dp) :: dg(3, 3), dr(3, 3), response(3), rho(3), &
47 REAL(dp) :: delta_g(3, 3), delta_r(3), g(3, 3), &
51 ALLOCATE (pot%r(5), pot%rab(5), pot%rho_nlcc(5))
52 pot%r(:) = [0.0_dp, 0.5_dp, 1.0_dp, 1.5_dp, 2.0_dp]
54 pot%rho_nlcc(:) = [1.0_dp, 0.8_dp, 0.5_dp, 0.2_dp, 0.1_dp]
55 pot%core_correction = .true.
57 g(:, 2) = [0.3_dp, -0.2_dp, 0.4_dp]
59 position = [0.2_dp, -0.3_dp, 0.1_dp]
60 delta_r = [0.02_dp, 0.01_dp, -0.03_dp]
63 CALL check(abs(3.0_dp*rho(1) - 4.0_dp*
pi/6.0_dp* &
64 sum([1.0_dp, 4.0_dp, 2.0_dp, 4.0_dp, 1.0_dp]*pot%r**2*pot%rho_nlcc)),
"Original core zero mode", 1.e-12_dp)
65 CALL check(abs(rho(3) - conjg(rho(2))),
"Original core Fourier reality", 1.e-12_dp)
66 response = sum(dr*spread(delta_r, 2, 3), dim=1) + sum(dg*delta_g, dim=1) - 0.01_dp*rho
68 shift = real(2*side - 3, dp)*step
70 3.0_dp*(1.0_dp + 0.01_dp*shift), samples(:, side))
72 CALL check(maxval(abs((samples(:, 2) - samples(:, 1))/(2.0_dp*step) - response)),
"Original core joint response", 2.e-9_dp)
73 pot%core_correction = .false.
75 CALL check(maxval(abs(rho)) + maxval(abs(dr)) + maxval(abs(dg)),
"Absent partial core", 0.0_dp)
81 SUBROUTINE check_inverse()
82 INTEGER,
PARAMETER :: nb = 2, nf = 5, np = 3
84 COMPLEX(KIND=dp) :: actual(nb, nb), b(np, nb), bd(np, np), chi(nf, nb), dchi(nf, nb), &
85 dd(np, np), ddd(np, np), ddelta(nf, np), ddg(np, nb), delta(nf, np), dg(np, nb), &
86 dgd(nb, np), dgg(nb, nb), donsite(np, np), dop(nf, nf), dprojector(np, nf), ds(nf, nb), &
87 dw(np, nb), empty_b(0, nb), empty_delta(nf, 0), empty_q(0, 0), empty_w(0, nb), &
88 gd(nb, np), gg(nb, nb), images(nf, nb, 2), onsite(np, np), op(nf, nf), projected(np, nb), &
89 projector(np, nf), reference(nb, nb), response(nb, nb), sampled(nb, nb, 2), &
90 shifted_chi(nf, nb), shifted_delta(nf, np), shifted_op(nf, nf), shifted_p(np, nf)
91 COMPLEX(KIND=dp) :: shifted_q(np, np), soft(nf, nb), w(np, nb)
92 INTEGER :: i, info, j, phase, side
93 REAL(KIND=
dp) :: shift
99 chi(i, j) = cmplx(sin(real(i + 2*j,
dp)), (phase - 1)*cos(real(i*j,
dp)),
dp)
100 dchi(i, j) = 0.07_dp*cmplx(cos(real(i + j,
dp)), (phase - 1)*sin(real(2*i + j,
dp)),
dp)
105 delta(i, j) = 0.12_dp*cmplx(cos(real(i*j,
dp)), (phase - 1)*sin(real(i + j,
dp)),
dp)
106 ddelta(i, j) = 0.03_dp*cmplx(sin(real(i + 2*j,
dp)), (phase - 1)*cos(real(i*j,
dp)),
dp)
107 projector(j, i) = 0.15_dp*cmplx(sin(real(i + j,
dp)), (phase - 1)*cos(real(2*i + j,
dp)),
dp)
108 dprojector(j, i) = 0.02_dp*cmplx(cos(real(i + j,
dp)), (phase - 1)*sin(real(i*j,
dp)),
dp)
114 op(i, j) = cmplx(0.1_dp*i - 0.05_dp*j, (phase - 1)*0.03_dp*(i + j),
dp)
115 dop(i, j) = cmplx(0.02_dp*(i + j), (phase - 1)*0.01_dp*(i - j),
dp)
118 onsite = op(1:np, 1:np)*0.3_dp
119 donsite = dop(1:np, 1:np)*0.4_dp
120 bd = matmul(projector, delta)
121 b = matmul(projector, chi)
123 IF (info /= 0 .OR. .NOT. inverse%ready) error stop
'Inverse factorization failed'
126 projected = matmul(projector, soft)
127 CALL check(maxval(abs(projected - w)),
'inverse projector identity')
128 CALL check(maxval(abs(soft + matmul(delta, projected) - chi)),
'full reconstruction round trip')
130 matmul(dprojector, delta) + matmul(projector, ddelta), dw)
132 gg = matmul(conjg(transpose(chi)), matmul(op, chi))
133 gd = matmul(conjg(transpose(chi)), matmul(op, delta))
134 dg = matmul(conjg(transpose(delta)), matmul(op, chi))
135 dd = matmul(conjg(transpose(delta)), matmul(op, delta))
137 reference = matmul(conjg(transpose(soft)), matmul(op, soft)) + &
138 matmul(conjg(transpose(projected)), matmul(onsite, projected))
139 CALL check(maxval(abs(actual - reference)),
'inverse operator versus direct fields')
140 dgg = matmul(conjg(transpose(dchi)), matmul(op, chi)) + &
141 matmul(conjg(transpose(chi)), matmul(dop, chi) + matmul(op, dchi))
142 dgd = matmul(conjg(transpose(dchi)), matmul(op, delta)) + &
143 matmul(conjg(transpose(chi)), matmul(dop, delta) + matmul(op, ddelta))
144 ddg = matmul(conjg(transpose(ddelta)), matmul(op, chi)) + &
145 matmul(conjg(transpose(delta)), matmul(dop, chi) + matmul(op, dchi))
146 ddd = matmul(conjg(transpose(ddelta)), matmul(op, delta)) + &
147 matmul(conjg(transpose(delta)), matmul(dop, delta) + matmul(op, ddelta))
148 CALL upf_inverse_operator_response(dgg, gd, dg, dd, onsite, w, dgd, ddg, ddd, donsite, dw, response)
150 shift = (2*side - 3)*step
151 shifted_chi = chi + shift*dchi
152 shifted_delta = delta + shift*ddelta
153 shifted_p = projector + shift*dprojector
154 shifted_op = op + shift*dop
155 shifted_q = onsite + shift*donsite
157 IF (info /= 0) error stop
'Displaced inverse factorization failed'
160 projected = matmul(shifted_p, images(:, :, side))
161 sampled(:, :, side) = matmul(conjg(transpose(images(:, :, side))), &
162 matmul(shifted_op, images(:, :, side))) + &
163 matmul(conjg(transpose(projected)), matmul(shifted_q, projected))
165 CALL check(maxval(abs(ds - (images(:, :, 2) - images(:, :, 1))/(2*step))),
'inverse basis response', 1.e-9_dp)
166 CALL check(maxval(abs(response - (sampled(:, :, 2) - sampled(:, :, 1))/(2*step))), &
167 'inverse operator response', 1.e-9_dp)
171 IF (info /= 0 .OR. .NOT. inverse%ready) error stop
'Empty inverse failed'
174 CALL check(maxval(abs(soft - chi)),
'identity without reconstruction projectors')
175 bd = cmplx(0.0_dp, 0.0_dp,
dp)
178 IF (info /= 2 .OR. inverse%ready) error stop
'Singular inverse accepted'
179 bd(2, 2) = -1.0_dp + 1.e-12_dp
181 IF (info /= np + 1 .OR. inverse%ready) error stop
'Ill-conditioned inverse accepted'
182 bd(1, 1) = cmplx(ieee_value(0.0_dp, ieee_quiet_nan), 0.0_dp,
dp)
184 IF (info /= np + 2 .OR. inverse%ready) error stop
'Nonfinite inverse accepted'
185 END SUBROUTINE check_inverse
191 SUBROUTINE check_atomic_residual()
192 COMPLEX(dp) :: b(2, 2), chi(3, 2), coupling(2, 2), &
193 metric(2, 2), soft(3, 2), w(2, 2)
194 COMPLEX(dp),
ALLOCATABLE :: rs(:, :), rt(:, :)
196 REAL(dp) :: delta(3, 2), hard(3, 2), ps(3, 2), &
200 ps = reshape([0.2_dp, 0.5_dp, -0.3_dp, 0.1_dp, -0.4_dp, 0.7_dp], [3, 2])
201 delta = reshape([0.3_dp, -0.1_dp, 0.2_dp, -0.2_dp, 0.4_dp, 0.1_dp], [3, 2])
203 t = reshape([1.0_dp, 0.2_dp, 0.1_dp, 0.2_dp, 2.0_dp, -0.3_dp, 0.1_dp, -0.3_dp, 1.5_dp], [3, 3])
204 q = reshape([0.4_dp, 0.1_dp, 0.1_dp, 0.6_dp], [2, 2])
205 chi = cmplx(ps, delta, dp)
206 coupling = cmplx(matmul(transpose(ps), delta), 0.0_dp, dp)
208 IF (info /= 0) error stop
'Atomic inverse failed'
209 b = matmul(transpose(ps), chi)
212 atomic%hard%nproj = 2
213 ALLOCATE (atomic%kinetic, source=matmul(transpose(hard), matmul(t, hard)) - matmul(transpose(ps), matmul(t, ps)))
214 ALLOCATE (atomic%difference_kinetic, source=matmul(transpose(delta), matmul(t, delta)))
215 ALLOCATE (atomic%wave_overlap, source=matmul(transpose(hard), hard) - matmul(transpose(ps), ps))
216 ALLOCATE (atomic%difference_overlap, source=matmul(transpose(delta), delta))
218 CALL check(maxval(abs(matmul(conjg(transpose(chi)), matmul(t, chi)) + rt - &
219 matmul(conjg(transpose(w)), matmul(atomic%kinetic, w)) - &
220 matmul(conjg(transpose(soft)), matmul(t, soft)))),
'atomic kinetic closure residual')
221 metric = matmul(conjg(transpose(chi)), chi) + rs + &
222 matmul(conjg(transpose(w)), matmul(q - atomic%wave_overlap, w))
223 CALL check(maxval(abs(metric - matmul(conjg(transpose(soft)), soft) - &
224 matmul(conjg(transpose(w)), matmul(q, w)))),
'atomic metric closure residual')
225 IF (maxval(abs(rt)) < 1.e-3_dp .OR. maxval(abs(rs)) < 1.e-3_dp) error stop
'Trivial closure test'
226 END SUBROUTINE check_atomic_residual
231 SUBROUTINE check_gaussian_fields()
232 INTEGER,
PARAMETER :: nb = 11, nf = 5
234 COMPLEX(dp) :: dg(nf, nb, 3), dv(nf, nb), g(nf, nb, 3), &
235 gss(nf, nb, 3, 2), other(nf, nb), &
236 v(nf, nb), vs(nf, nb, 2)
237 INTEGER :: axis, ico, image, images(3, 3), row, &
238 side, translated_images(3, 3)
239 REAL(dp) :: bloch(3), cell(3, 3), center(3), dc(3, 3), dcenter(3), dk(3), dpnt(3, nf), &
240 gradient(nf, nb, 3), gs(nf, nb, 3, 2), hh(nf, nb, 3, 3), samples(nf, nb, 2), shift, &
241 value(nf, nb), x(3, nf), xp(3, nf)
249 ALLOCATE (basis%lmax(2), basis%npgf(2), basis%nshell(2), basis%l(2, 2), &
250 basis%first_sgf(2, 2), basis%last_sgf(2, 2), basis%zet(2, 2), basis%sphi(40, nb))
253 basis%nshell = [2, 1]
255 basis%l(:, 1) = [0, 3]
259 basis%first_sgf(:, 1) = [1, 2]
260 basis%last_sgf(:, 1) = [1, 8]
261 basis%first_sgf(1, 2) = 9
262 basis%last_sgf(1, 2) = 11
264 basis%zet(:, 1) = [.4_dp, .9_dp]
265 basis%zet(1, 2) = .7_dp
267 basis%sphi(1, 1) = .6_dp
268 basis%sphi(21, 1) = -.2_dp
271 basis%sphi(ico, row) = .03_dp*sin(real(ico*row, dp))
272 basis%sphi(ico + 20, row) = -.02_dp*cos(real(ico + row, dp))
277 basis%sphi(ico, row) = .1_dp*sin(real(ico*row, dp))
281 x(:, 2) = [.3_dp, 0.0_dp, 0.0_dp]
282 x(:, 3) = [0.0_dp, -.7_dp, 0.0_dp]
283 x(:, 4) = [.23_dp, .51_dp, -.4_dp]
284 x(:, 5) = [-.6_dp, .2_dp, .8_dp]
286 CALL check(maxval(abs(value(:, 1) - (.6_dp*exp(-.4_dp*sum(x*x, dim=1)) &
287 - .2_dp*exp(-.9_dp*sum(x*x, dim=1))))),
'native signed s contraction')
291 xp(axis, :) = xp(axis, :) + (2*side - 3)*step
294 CALL check(maxval(abs(gradient(:, :, axis) - (samples(:, :, 2) - samples(:, :, 1))/(2*step))), &
295 'contracted Gaussian point gradient', 2.e-8_dp)
296 CALL check(maxval(abs(hh(:, :, :, axis) - (gs(:, :, :, 2) - gs(:, :, :, 1))/(2*step))), &
297 'contracted Gaussian origin/axis Hessian', 2.e-7_dp)
299 cell = reshape([2.3_dp, .1_dp, .2_dp, .2_dp, 2.7_dp, -.1_dp, .1_dp, .3_dp, 2.1_dp], [3, 3])
300 center = [.1_dp, -.2_dp, .3_dp]
301 images = reshape([0, 0, 0, 1, -1, 0, -1, 0, 1], [3, 3])
302 bloch = [.23_dp, -.17_dp, .11_dp]
304 dcenter = [.07_dp, -.02_dp, .01_dp]
306 dk = [.03_dp, .02_dp, -.01_dp]
307 CALL gaussian_basis_fields_periodic(basis, x, center, cell, images, bloch, v, g, dv, dg, dpnt, dcenter, dc, dk)
309 shift = (2*side - 3)*step
311 images, bloch + shift*dk, vs(:, :, side), gss(:, :, :, side))
313 CALL check(maxval(abs(dv - (vs(:, :, 2) - vs(:, :, 1))/(2*step))),
'native Gaussian Bloch joint response', 2.e-8_dp)
314 CALL check(maxval(abs(dg - (gss(:, :, :, 2) - gss(:, :, :, 1))/(2*step))),
'native Gaussian Bloch gradient response', 2.e-7_dp)
316 CALL check(maxval(abs(other - conjg(v))),
'native Gaussian Bloch time reversal')
318 translated_images(:, image) = images(:, image) - [1, 0, 0]
321 CALL check(maxval(abs(other - exp(cmplx(0.0_dp, -2*
pi*bloch(1), dp))*v)),
'native Gaussian lattice representative')
323 END SUBROUTINE check_gaussian_fields
331 SUBROUTINE check(value, label, tolerance)
332 REAL(KIND=
dp),
INTENT(IN) ::
value
333 CHARACTER(LEN=*),
INTENT(IN) :: label
334 REAL(KIND=
dp),
INTENT(IN),
OPTIONAL :: tolerance
339 IF (
PRESENT(tolerance)) tol = tolerance
340 max_error = max(max_error,
value)
341 IF (
value > tol)
THEN
342 WRITE (*, *) trim(label),
value, tol
343 error stop
'Inverse primitive mismatch'
subroutine, public deallocate_gto_basis_set(gto_basis_set)
...
subroutine, public allocate_gto_basis_set(gto_basis_set)
...
Native contracted Gaussian fields and their consistent Cartesian/Bloch responses. Uses the stored sph...
subroutine, public gaussian_basis_fields_evaluate(basis, displacements, value, gradient, hessian, cutoff_squared)
Evaluate a native contracted basis at explicit point-minus-center displacements. No minimum-image ope...
subroutine, public gaussian_basis_fields_periodic(basis, points, center, cell, images, reduced_k, value, gradient, response, gradient_response, point_response, center_response, cell_response, reduced_k_response, cutoff_squared)
Sum explicit Gaussian images with physical Bloch gradients and joint geometry response....
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
Provides Cartesian and spherical orbital pointers and indices.
subroutine, public init_orbital_pointers(maxl)
Initialize or update the orbital pointers.
integer, dimension(:), allocatable, public ncoset
Fourier coefficients and geometry derivatives of the original UPF partial core density.
subroutine, public upf_core_fourier(pot, gvecs, position, volume, density, dposition, dg)
Integrate the supplied true spherical density with the original radial quadrature....
Inverse of a specified finite-rank UPF reconstruction, including intercenter coupling....
subroutine, public upf_inverse_project(inverse, beta_gaussian, coefficients)
Solve for W=P*U*chi; do not replace original q by an orthogonalized metric.
subroutine, public upf_inverse_init(beta_delta, inverse, info, minimum_rcond)
Factor K with original projector normalization and all supplied intercenter blocks.
subroutine, public upf_inverse_basis_response(gaussian_response, delta, delta_response, coefficients, coefficients_response, response)
Joint field response d(U*chi)=dchi-dDelta*W-Delta*dW.
subroutine, public upf_inverse_basis(gaussian, delta, coefficients, soft)
Evaluate inverse images on a field batch: U*chi=chi-Delta*W. Spatial derivatives use the correspondin...
subroutine, public upf_inverse_atomic_residual(atomic, coefficients, delta_overlap, delta_kinetic, kinetic_residual, metric_residual)
Finite partial-wave closure residuals added to Gaussian T plus hard D-T and Gaussian S....
subroutine, public upf_inverse_project_response(inverse, coefficients, beta_gaussian_response, beta_delta_response, response)
Differentiate the same reconstruction: K*dW=dB-dK*W. Displacement/strain responses must include the o...
subroutine, public upf_inverse_operator(gaussian_operator, gaussian_delta, delta_gaussian, delta_operator, augmentation, coefficients, transformed)
Pull back A+P^dagger*augmentation*P into reconstructed Gaussian variables.
subroutine, public upf_inverse_operator_response(gaussian_response, gaussian_delta, delta_gaussian, delta_operator, augmentation, coefficients, gaussian_delta_response, delta_gaussian_response, delta_operator_response, augmentation_response, coefficients_response, response)
Differentiate the full operator pullback, including both inverse-basis legs. Matrix responses already...
Owned UPF dataset and radial conventions shared by ATOM and Quickstep. Dataset availability does not ...
program upf_inverse_unittest
Inverse reconstruction identities, conditioning and analytic field/operator responses.
subroutine check_core_fourier()
Original core normalization, finite endpoint and joint phase/lattice/volume derivative.