20 TYPE(
cell_type),
POINTER :: cell, perturbed
22 REAL(
dp) :: atoms(3, 2), trial(3, 2), hmat(3, 3), point(3), shifted(3)
23 REAL(
dp) ::
value, plus, minus, direct, total, datom(3, 2), dstrain(3, 3), mu
24 REAL(
dp) :: unity_error, derivative_error, translation_error
25 REAL(
dp),
PARAMETER :: h = 2.e-6_dp
26 INTEGER :: mask, periodicity(3), a, d, j, k, l,
TARGET, sample
29 ALLOCATE (cell, perturbed)
30 hmat = reshape([4.0_dp, 0.1_dp, 0.2_dp, 0.7_dp, 5.0_dp, 0.3_dp, -0.2_dp, 0.4_dp, 6.0_dp], [3, 3])
31 atoms(:, 1) = [0.2_dp, 0.3_dp, -0.1_dp]
32 atoms(:, 2) = [1.8_dp, 2.2_dp, 1.3_dp]
34 derivative_error = 0.0_dp
35 translation_error = 0.0_dp
37 periodicity = [merge(1, 0, btest(mask, 0)), merge(1, 0, btest(mask, 1)), merge(1, 0, btest(mask, 2))]
40 cell%perd = periodicity
41 perturbed%perd = periodicity
44 point = [1.1_dp, 1.3_dp, 1.7_dp]
45 IF (sample == 2) point = matmul(hmat, [0.5_dp, 0.2_dp, 0.1_dp])
46 IF (sample == 3) point = matmul(hmat, [1.5_dp, 0.2_dp, 0.1_dp]) + atoms(:, 1)
49 IF (abs(direct -
value) > 2.e-14_dp) error stop
'Cached partition changed the value'
51 mu = (norm2(point - atoms(:, 1)) - norm2(point - atoms(:, 2)))/norm2(atoms(:, 1) - atoms(:, 2))
53 mu = 1.5_dp*mu - 0.5_dp*mu**3
55 IF (abs(
value - 0.5_dp*(1.0_dp - mu)) > 2.e-14_dp) error stop
'Nonperiodic Becke weight changed'
56 IF (maxval(abs(dstrain)) > 2.e-14_dp) error stop
'Molecular partition has an image-strain response'
60 DO l = -3*periodicity(3), 3*periodicity(3)
61 DO k = -3*periodicity(2), 3*periodicity(2)
62 DO j = -3*periodicity(1), 3*periodicity(1)
63 shifted = point - matmul(hmat, real([j, k, l],
dp))
65 total = total + direct
70 unity_error = max(unity_error, abs(total - 1.0_dp))
72 trial(:, 2) = atoms(:, 2) + matmul(hmat, real([1, -1, 2]*periodicity,
dp))
74 translation_error = max(translation_error, abs(direct -
value))
78 trial(d, a) = atoms(d, a) + h
80 trial(d, a) = atoms(d, a) - h
82 derivative_error = max(derivative_error, abs((plus - minus)/(2*h) - datom(d, a)))
88 perturbed%hmat(d, :) = hmat(d, :) + h*hmat(j, :)
89 perturbed%h_inv =
inv_3x3(perturbed%hmat)
91 perturbed%hmat(d, :) = hmat(d, :) - h*hmat(j, :)
92 perturbed%h_inv =
inv_3x3(perturbed%hmat)
94 derivative_error = max(derivative_error, abs((plus - minus)/(2*h) - dstrain(d, j)))
99 WRITE (*,
'(A,ES16.7)')
'PERIODIC PARTITION UNITY ERROR ', unity_error
100 WRITE (*,
'(A,ES16.7)')
'PERIODIC PARTITION TRANSLATION ERROR ', translation_error
101 WRITE (*,
'(A,ES16.7)')
'PERIODIC PARTITION ATOM/STRAIN ERROR ', derivative_error
102 IF (unity_error > 2.e-13_dp) error stop
'Periodic atom-image weights do not sum to one'
103 IF (translation_error > 2.e-13_dp) error stop
'Moving an atom by a lattice vector changed its image family'
104 IF (derivative_error > 3.e-8_dp) error stop
'Periodic partition derivatives fail finite differences'
105 DEALLOCATE (cell, perturbed)
Handles all functions related to the CELL.
Defines the basic variable types.
integer, parameter, public dp
subroutine, public cp2k_finalize()
...
subroutine, public cp2k_init()
...
Collection of simple mathematical functions and subroutines.
pure real(kind=dp) function, dimension(3, 3), public inv_3x3(a)
Returns the inverse of the 3 x 3 matrix a.
Smooth atom-image weights normalized over translated, equivalent environments.
subroutine, public build_periodic_atom_image_layout(atom_coords, cell, target_atom, image_periodicity, layout, target_image)
Prepare geometry shared by the points of an atom block.
subroutine, public periodic_atom_image_partition_from_layout(grid_point, layout, target_image, weight, dweight_datom, dweight_dstrain)
Evaluate a reference-atom weight and optional base-atom and explicit image-strain responses.
subroutine, public periodic_atom_image_partition(grid_point, atom_coords, cell, target_atom, weight, dweight_datom, dweight_dstrain, image_periodicity)
Convenience evaluation without retaining a layout between grid points.
program skala_periodic_partition_unittest
Type defining parameters related to the simulation cell.