Coverage for gpaw/test/fdtd/test_ed_shapes.py: 100%

21 statements  

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

1# flake8: noqa 

2from gpaw.fdtd.poisson_fdtd import QSFDTD 

3from gpaw.fdtd.polarizable_material import PermittivityPlus, PolarizableMaterial, \ 

4 PolarizableSphere, PolarizableBox, \ 

5 PolarizableEllipsoid, PolarizableRod, \ 

6 PolarizableTetrahedron 

7import pytest 

8 

9 

10@pytest.mark.old_gpaw_only 

11def test_fdtd_ed_shapes(in_tmp_dir): 

12 # Whole simulation cell (Angstroms) 

13 cell = [40, 40, 20] 

14 

15 # Classical subsystem 

16 classical_material = PolarizableMaterial() 

17 classical_material.add_component(PolarizableSphere(permittivity = PermittivityPlus(data = [[1.20, 0.20, 25.0]]), 

18 center = [10, 10, 10], 

19 radius = 4.5)) 

20 classical_material.add_component(PolarizableBox(permittivity = PermittivityPlus(data = [[1.40, 0.20, 25.0]]), 

21 corner1 = [18.1, 5.1, 5.1], 

22 corner2 = [22.9, 14.9, 14.9])) 

23 classical_material.add_component(PolarizableEllipsoid(permittivity = PermittivityPlus(data = [[1.60, 0.20, 25.0]]), 

24 center = [30.0, 10.0, 10.0], 

25 radii = [ 3.9, 5.9, 4.9])) 

26 classical_material.add_component(PolarizableRod(permittivity = PermittivityPlus(data = [[1.80, 0.20, 25.0]]), 

27 corners = [[10.0, 21.5, 10.0], [10.0, 33.5, 10.0]], 

28 round_corners = True, 

29 radius = 3.9)) 

30 classical_material.add_component(PolarizableRod(permittivity = PermittivityPlus(data = [[1.00, 0.20, 25.0]]), 

31 corners = [[20.0, 21.5, 10.0], [25.0, 33.5, 10.0]], 

32 round_corners = True, 

33 radius = 2.9)) 

34 classical_material.add_component(PolarizableTetrahedron(permittivity = PermittivityPlus(data = [[0.80, 0.20, 25.0]]), 

35 corners = [[24.1, 16.1, 5.1], 

36 [30.1, 36.1, 6.1], 

37 [36.4, 27.6, 7.1], 

38 [30.0, 25.0, 14.9]])) 

39 

40 

41 # Wrap calculators 

42 qsfdtd = QSFDTD(classical_material = classical_material, 

43 atoms = None, 

44 cells = (cell, 2.00), 

45 spacings = [1.60, 0.40], 

46 remove_moments = (1, 1)) 

47 

48 # Run 

49 energy = qsfdtd.ground_state('gs.gpw', 

50 mode='fd', 

51 eigensolver='cg', 

52 nbands=-1, 

53 symmetry={'point_group': False}) 

54 qsfdtd.time_propagation('gs.gpw', kick_strength=[0.000, 0.000, 0.001], time_step=10, iterations=5, dipole_moment_file='dmCl.dat') 

55 

56 # Restart and run 

57 qsfdtd.write('td.gpw', mode='all') 

58 qsfdtd.time_propagation('td.gpw', kick_strength=None, time_step=10, iterations=5, dipole_moment_file='dmCl.dat') 

59 

60 # Test 

61 ref_cl_dipole_moment = [ -1.01218549e-04, -3.03603883e-05, 1.86063875e-01] 

62 tol = 1e-6 

63 assert qsfdtd.td_calc.hamiltonian.poisson.get_classical_dipole_moment() == pytest.approx(ref_cl_dipole_moment, abs=tol)