Coverage for gpaw/test/fdtd/test_ed_wrapper.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 numpy as np
2import pytest
3from ase import Atoms
4from gpaw.fdtd.poisson_fdtd import QSFDTD
5from gpaw.fdtd.polarizable_material import (PermittivityPlus,
6 PolarizableMaterial,
7 PolarizableSphere)
8from gpaw.mpi import world
11@pytest.mark.old_gpaw_only
12def test_fdtd_ed_wrapper(in_tmp_dir):
13 # This test does the same calculation as ed.py, but using
14 # QSFDTD wrapper instead
16 # Accuracy
17 energy_eps = 0.0005
19 # Whole simulation cell (Angstroms)
20 cell = [20, 20, 30]
22 # Quantum subsystem
23 atom_center = np.array([10.0, 10.0, 20.0])
24 atoms = Atoms('Na2', [atom_center + [0.0, 0.0, -1.50],
25 atom_center + [0.0, 0.0, +1.50]])
27 # Classical subsystem
28 sphere_center = np.array([10.0, 10.0, 10.0])
29 classical_material = PolarizableMaterial()
30 classical_material.add_component(
31 PolarizableSphere(
32 permittivity=PermittivityPlus(data=[[1.20, 0.20, 25.0]]),
33 center=sphere_center,
34 radius=5.0))
36 # Wrap calculators
37 qsfdtd = QSFDTD(classical_material=classical_material,
38 atoms=atoms,
39 cells=(cell, 2.50),
40 spacings=[1.60, 0.40],
41 remove_moments=(1, 4),
42 communicator=world)
44 # Run
45 qsfdtd.ground_state('gs.gpw',
46 mode='fd',
47 eigensolver='cg',
48 nbands=-1,
49 convergence={'energy': energy_eps},
50 symmetry={'point_group': False})
51 assert qsfdtd.energy == pytest.approx(
52 -0.631881, abs=energy_eps * qsfdtd.gs_calc.get_number_of_electrons())
53 qsfdtd.time_propagation('gs.gpw', kick_strength=[0.000, 0.000, 0.001],
54 time_step=10, iterations=5,
55 dipole_moment_file='dm.dat', restart_file='td.gpw')
56 qsfdtd.time_propagation('td.gpw', kick_strength=None, time_step=10,
57 iterations=5, dipole_moment_file='dm.dat')
59 # Test
60 ref_cl_dipole_moment = [5.25374117e-14, 5.75811267e-14, 3.08349334e-02]
61 ref_qm_dipole_moment = [1.78620337e-11, -1.57782578e-11, 5.21368300e-01]
63 tol = 1e-4
64 cl_dm = qsfdtd.td_calc.hamiltonian.poisson.get_classical_dipole_moment()
65 qm_dm = qsfdtd.td_calc.hamiltonian.poisson.get_quantum_dipole_moment()
66 assert cl_dm == pytest.approx(ref_cl_dipole_moment, abs=tol)
67 assert qm_dm == pytest.approx(ref_qm_dipole_moment, abs=tol)