Coverage for gpaw/test/poisson/test_poisson_asym.py: 100%

22 statements  

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

1"""Test poisson solver for asymmetric charges.""" 

2from gpaw.utilities.gauss import Gaussian 

3from gpaw.grid_descriptor import GridDescriptor 

4from gpaw.poisson import PoissonSolver 

5 

6 

7# Initialize classes 

8 

9def test_poisson_poisson_asym(): 

10 a = 20.0 # Size of cell 

11 inv_width = 19 # inverse width of the gaussian 

12 N = 48 # Number of grid points 

13 center_of_charge = (a / 2, a / 2, 3 * a / 4) # off center charge 

14 Nc = (N, N, N) # Number of grid points along each axis 

15 gd = GridDescriptor(Nc, (a, a, a), 0) # Grid-descriptor object 

16 solver = PoissonSolver(nn=3, use_charge_center=True) 

17 solver.set_grid_descriptor(gd) 

18 gauss = Gaussian(gd, a=inv_width, center=center_of_charge) 

19 test_poisson = Gaussian(gd, a=inv_width, center=center_of_charge) 

20 

21 # Check if Gaussian potentials are made correctly 

22 

23 # Array for storing the potential 

24 pot = gd.zeros(dtype=float, global_array=False) 

25 solver.load_gauss() 

26 vg = test_poisson.get_gauss_pot(0) 

27 # Get analytic functions 

28 ng = gauss.get_gauss(0) 

29 # vg = solver.phi_gauss 

30 # Solve potential numerically 

31 solver.solve(pot, ng, charge=1.0, zero_initial_phi=False) 

32 # Determine residual 

33 # residual = norm(pot - vg) 

34 residual = gd.integrate((pot - vg)**2)**0.5 

35 

36 print('residual %s' % ( 

37 residual)) 

38 assert residual < 1e-5 # Better than 5.x 

39 

40 # mpirun -np 2 python gauss_func.py --gpaw-parallel --gpaw-debug