Coverage for gpaw/test/fd_ops/test_gd.py: 100%
27 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
1import pytest
2import numpy as np
3from gpaw.grid_descriptor import GridDescriptor
6def test_fd_ops_gd():
7 gd = GridDescriptor([4, 4, 4])
8 a = gd.empty(dtype=complex)
9 a[:] = 1.0
10 assert gd.integrate(a.real, a.real) == 1.0
12 def mic(r_v, pbc_c):
13 "Mnimal image convention in an [1.0] * 3 unit cell"
14 r_c = r_v % 1.0
15 r_c -= (2 * r_c).astype(int)
16 return np.where(pbc_c, r_c, r_v)
18 pbc_c = [1, 1, 0]
19 gd = GridDescriptor([10] * 3, cell_cv=[1.] * 3, pbc_c=pbc_c)
20 # Point outside box in non-periodic direction should stay
21 r_v = np.array([0.01, 2.49, 0.01])
22 dr_cG = gd.get_grid_point_distance_vectors(r_v)
23 assert dr_cG[:, 0, 0, 0] == pytest.approx(
24 mic(np.dot(gd.h_cv, gd.beg_c) - r_v, pbc_c), abs=1e-15)
25 # Point outside box in periodic direction should be folded inside
26 r_v = np.array([2.49, 0.01, 0.01])
27 dr_cG = gd.get_grid_point_distance_vectors(r_v)
28 assert dr_cG[:, 0, 0, 0] == pytest.approx(
29 mic(np.dot(gd.h_cv, gd.beg_c) - r_v, pbc_c), abs=1e-15)
32@pytest.mark.serial
33def test_nonorthogonal_distances():
34 """test distance vectors in non-orthogonal cells"""
35 cell_cv = np.eye(3)
36 cell_cv[0, 1] = 1
38 gd = GridDescriptor([2, 4, 1], cell_cv)
39 r_vG = gd.get_grid_point_distance_vectors((0, 0, 0))
41 assert r_vG[1, 1].reshape(4) == pytest.approx([-0.5, -0.25, -1., -0.75])