Coverage for tests/test_radial_distrubution.py: 96%
55 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1""" Test code for computing radial distribution function """
3from itertools import product
5import numpy as np
7import gamdpy as gp
9def test_radial_distribution():
10 spatial_dimensions = 1, 2, 3, 4
11 densities = 1.0, 0.32
12 for D, rho in product(spatial_dimensions, densities):
13 # print(D, rho)
14 number_of_particles = 10_000
15 conf = gp.Configuration(D=D)
16 conf.make_positions(N=number_of_particles, rho=rho)
17 conf['m'] = 1.0
19 bins=16
20 calc_rdf = gp.CalculatorRadialDistribution(conf, bins=bins)
21 number_of_updates = 4
22 for _ in range(number_of_updates):
23 conf['r'] = (np.random.rand(number_of_particles, D)-0.5) * conf.simbox.get_lengths() # Ideal gas configuration
24 # print(conf['r'][0])
25 conf.copy_to_device()
26 calc_rdf.update()
28 rdf_data = calc_rdf.read()
29 r = rdf_data['distances']
30 assert len(r) == bins, "Problem with (D, rho) = " + str((D, rho))
31 rdfs = rdf_data['rdf']
32 # print(rdfs)
33 assert rdfs.shape == (number_of_updates, bins), "Problem with (D, rho) = " + str((D, rho))
34 mean_rdf = np.mean(rdfs)
35 assert abs(mean_rdf - 1.0) < 0.01, "Problem with (D, rho) = " + str((D, rho))
36 assert abs(np.max(rdfs) - 1.0) < 0.8, "Problem with (D, rho) = " + str((D, rho))
37 assert abs(np.min(rdfs) - 1.0) < 0.8, "Problem with (D, rho) = " + str((D, rho))
40def test_radial_distribution_lees_edwards():
41 spatial_dimensions = 2, 3, 4
42 densities = 1.0, 0.32
43 for D, rho in product(spatial_dimensions, densities):
44 number_of_particles = 10_000
45 conf = gp.Configuration(D=D)
46 conf.make_positions(N=number_of_particles, rho=rho)
47 conf['m'] = 1.0
49 conf.simbox = gp.LeesEdwards(conf.D, conf.simbox.get_lengths(), box_shift=0.1)
51 bins=16
52 calc_rdf = gp.CalculatorRadialDistribution(conf, bins=bins)
54 number_of_updates = 4
55 for _ in range(number_of_updates):
56 conf['r'] = (np.random.rand(number_of_particles, D)-0.5) * conf.simbox.get_lengths() # Ideal gas configuration
57 # print(conf['r'][0])
58 conf.copy_to_device()
59 calc_rdf.update()
61 rdf_data = calc_rdf.read()
62 r = rdf_data['distances']
63 assert len(r) == bins, "Problem with (D, rho) = " + str((D, rho))
64 rdfs = rdf_data['rdf']
65 # print(rdfs)
66 assert rdfs.shape == (number_of_updates, bins), "Problem with (D, rho) = " + str((D, rho))
67 mean_rdf = np.mean(rdfs)
68 assert abs(mean_rdf - 1.0) < 0.01, "Problem with (D, rho) = " + str((D, rho))
69 assert abs(np.max(rdfs) - 1.0) < 0.8, "Problem with (D, rho) = " + str((D, rho))
70 assert abs(np.min(rdfs) - 1.0) < 0.8, "Problem with (D, rho) = " + str((D, rho))
72if __name__ == "__main__":
73 test_radial_distribution()
74 test_radial_distribution_lees_edwards()