Coverage for gpaw/test/pw/test_reallfc.py: 100%
48 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-12 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-12 00:18 +0000
1import numpy as np
2import pytest
4from gpaw.grid_descriptor import GridDescriptor
5from gpaw.spline import Spline
6import gpaw.mpi as mpi
7from gpaw.pw.descriptor import PWDescriptor
8from gpaw.pw.lfc import PWLFC
11@pytest.mark.ci
12def test_pw_reallfc():
13 x = 2.0
14 rc = 3.5
15 r = np.linspace(0, rc, 100)
17 n = 40
18 a = 8.0
19 gd = GridDescriptor((n, n, n), (a, a, a), comm=mpi.serial_comm)
21 spos_ac = np.array([(0.15, 0.45, 0.95)])
23 pd = PWDescriptor(45, gd, complex)
24 pdr = PWDescriptor(45, gd)
26 for l in range(4):
27 print(l)
28 s = Spline.from_data(l, rc, 2 * x**1.5 / np.pi * np.exp(-x * r**2))
30 lfc = PWLFC([[s]], pd)
31 lfcr = PWLFC([[s]], pdr)
33 c_axi = {0: np.zeros((1, 2 * l + 1), complex)}
34 c_axi[0][0, 0] = 1.9
35 cr_axi = {0: np.zeros((1, 2 * l + 1))}
36 cr_axi[0][0, 0] = 1.9
38 b = pd.zeros(1, dtype=complex)
39 br = pdr.zeros(1)
41 lfc.set_positions(spos_ac)
42 lfc.add(b, c_axi)
43 lfcr.set_positions(spos_ac)
44 lfcr.add(br, cr_axi)
46 a = pd.ifft(b[0])
47 ar = pdr.ifft(br[0])
48 assert abs(a - ar).max() == pytest.approx(0, abs=1e-14)
50 if l == 0:
51 a = a[:, ::-1].copy()
52 b0 = pd.fft(a)
53 br0 = pdr.fft(a.real)
55 lfc.integrate(b0, c_axi)
56 lfcr.integrate(br0, cr_axi)
58 assert abs(c_axi[0][0] - cr_axi[0][0]).max() < 1e-14
60 c_axiv = {0: np.zeros((1, 2 * l + 1, 3), complex)}
61 cr_axiv = {0: np.zeros((1, 2 * l + 1, 3))}
62 lfc.derivative(b0, c_axiv)
63 lfcr.derivative(br0, cr_axiv)
64 assert abs(c_axiv[0][0] - cr_axiv[0][0]).max() < 1e-14