Coverage for gpaw/test/fd_ops/test_nabla.py: 100%

38 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-14 00:18 +0000

1import numpy as np 

2from gpaw.lfc import LocalizedFunctionsCollection as LFC 

3from gpaw.grid_descriptor import GridDescriptor 

4from gpaw.atom.radialgd import EquidistantRadialGridDescriptor 

5from gpaw.spline import Spline 

6from gpaw.setup import Setup 

7 

8 

9def test_fd_ops_nabla(): 

10 rc = 2.0 

11 a = 2.5 * rc 

12 n = 64 

13 lmax = 2 

14 b = 8.0 

15 m = (lmax + 1)**2 

16 gd = GridDescriptor([n, n, n], [a, a, a]) 

17 r = np.linspace(0, rc, 200) 

18 g = np.exp(-(r / rc * b)**2) 

19 splines = [Spline.from_data(l=l, rmax=rc, f_g=g) for l in range(lmax + 1)] 

20 c = LFC(gd, [splines]) 

21 c.set_positions([(0, 0, 0)]) 

22 psi = gd.zeros(m) 

23 d0 = c.dict(m) 

24 if 0 in d0: 

25 d0[0] = np.identity(m) 

26 c.add(psi, d0) 

27 d1 = c.dict(m, derivative=True) 

28 c.derivative(psi, d1) 

29 

30 class TestSetup(Setup): 

31 l_j = range(lmax + 1) 

32 nj = lmax + 1 

33 ni = m 

34 

35 def __init__(self): 

36 pass 

37 rgd = EquidistantRadialGridDescriptor(r[1], len(r)) 

38 g = [np.exp(-(r / rc * b)**2) * r**l for l in range(lmax + 1)] 

39 d2 = TestSetup().get_derivative_integrals(rgd, g, np.zeros_like(g)) 

40 if 0 in d1: 

41 print(abs(d1[0] - d2).max()) 

42 assert abs(d1[0] - d2).max() < 2e-9