Skip to content

Commit 3d1d7e9

Browse files
committed
Test for array_generate_particles
1 parent 56239b9 commit 3d1d7e9

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

particles/tests/test_particles.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88

99
def test_particle():
10+
"""
11+
Test Particle class
12+
"""
13+
1014
n_particles = 5
1115

1216
for n in range(n_particles):
@@ -18,6 +22,10 @@ def test_particle():
1822

1923

2024
def test_particles_random_gen():
25+
"""
26+
Test random particle generator.
27+
"""
28+
2129
rp = runparams.RuntimeParameters()
2230

2331
rp.params["mesh.nx"] = 8
@@ -53,6 +61,10 @@ def test_particles_random_gen():
5361

5462

5563
def test_particles_grid_gen():
64+
"""
65+
Test Particles grid generator.
66+
"""
67+
5668
rp = runparams.RuntimeParameters()
5769

5870
rp.params["mesh.nx"] = 8
@@ -84,6 +96,41 @@ def test_particles_grid_gen():
8496
assert positions == correct_positions, "sets are not the same"
8597

8698

99+
def test_particles_array_gen():
100+
"""
101+
Test Particles particle generator from input array.
102+
"""
103+
104+
rp = runparams.RuntimeParameters()
105+
106+
rp.params["mesh.nx"] = 8
107+
rp.params["mesh.ny"] = 8
108+
rp.params["particles.do_particles"] = 1
109+
n_particles = 50
110+
111+
# set up sim
112+
sim = NullSimulation("", "", rp)
113+
114+
# set up grid
115+
my_grid = grid_setup(rp)
116+
my_data = patch.CellCenterData2d(my_grid)
117+
bc = bc_setup(rp)[0]
118+
my_data.create()
119+
sim.cc_data = my_data
120+
121+
# generate random array of particles
122+
init_positions = np.random.rand(n_particles, 2)
123+
124+
ps = particles.Particles(sim.cc_data, bc, n_particles,
125+
"array", pos_array=init_positions)
126+
127+
positions = set([(p.x, p.y) for p in ps.particles.values()])
128+
129+
correct_positions = set([(x, y) for (x, y) in init_positions])
130+
131+
assert positions == correct_positions, "sets are not the same"
132+
133+
87134
def test_particles_advect():
88135
rp = runparams.RuntimeParameters()
89136

0 commit comments

Comments
 (0)