Skip to content

Commit 92d6beb

Browse files
committed
Added extra tests for boundary conditions
1 parent 3d1d7e9 commit 92d6beb

2 files changed

Lines changed: 169 additions & 82 deletions

File tree

particles/particles.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def __init__(self, sim_data, bc, n_particles, particle_generator="grid",
7474
String with generator name of custom particle generator function
7575
pos_array : float array
7676
Array of particle positions to use with particle initialization
77+
init_array : float array
78+
Array of initial particle positions required for plotting from file.
7779
"""
7880

7981
self.sim_data = sim_data
@@ -172,16 +174,16 @@ def update_particles(self, dt, u=None, v=None):
172174
method to advance particles using the cell-centered velocity.
173175
174176
We will explicitly pass in u and v if they cannot be accessed from the
175-
sim_data in the usual way.
177+
sim_data using get_var("velocity").
176178
177179
Parameters
178180
----------
181+
dt : float
182+
timestep
179183
u : ArrayIndexer object
180184
x-velocity
181185
v : ArrayIndexer object
182186
y-velocity
183-
dt : float
184-
timestep
185187
"""
186188
myg = self.sim_data.grid
187189

@@ -200,8 +202,8 @@ def update_particles(self, dt, u=None, v=None):
200202
x_frac = x_idx % 1
201203
y_frac = y_idx % 1
202204

203-
# get the index of the bottom left cell
204-
# we'll add one as going to use buf'd quantities -
205+
# get the index of the particle's closest bottom left cell
206+
# we'll add one as going to use buf'd grids -
205207
# this will catch the cases where the particle is on the edges
206208
# of the grid.
207209
x_idx = int(x_idx) + 1
@@ -227,10 +229,11 @@ def enforce_particle_boundaries(self):
227229
Enforce the particle boundaries
228230
229231
TODO: copying the dict and adding everything back again is messy
230-
- think of a better way to do this?
232+
- think of a better way to do this? Did it this way so don't have
233+
to remove items from a dictionary while iterating it for outflow
234+
boundaries.
231235
"""
232236
old_particles = self.particles.copy()
233-
self.particles = dict()
234237

235238
myg = self.sim_data.grid
236239

@@ -245,51 +248,51 @@ def enforce_particle_boundaries(self):
245248
# -x boundary
246249
if p.x < myg.xmin:
247250
if xlb in ["outflow", "neumann"]:
251+
del self.particles[k]
248252
continue
249253
elif xlb == "periodic":
250254
p.x = myg.xmax + p.x - myg.xmin
251-
elif xlb in ["reflect-even", "reflect-odd"]:
255+
elif xlb in ["reflect-even", "reflect-odd", "dirichlet"]:
252256
p.x = 2 * myg.xmin - p.x
253257
else:
254258
msg.fail("ERROR: xlb = %s invalid BC for particles" % (xlb))
255259

256260
# +x boundary
257261
if p.x > myg.xmax:
258262
if xrb in ["outflow", "neumann"]:
263+
del self.particles[k]
259264
continue
260265
elif xrb == "periodic":
261266
p.x = myg.xmin + p.x - myg.xmax
262-
elif xrb in ["reflect-even", "reflect-odd"]:
267+
elif xrb in ["reflect-even", "reflect-odd", "dirichlet"]:
263268
p.x = 2 * myg.xmax - p.x
264269
else:
265270
msg.fail("ERROR: xrb = %s invalid BC for particles" % (xrb))
266271

267272
# -y boundary
268273
if p.y < myg.ymin:
269274
if ylb in ["outflow", "neumann"]:
275+
del self.particles[k]
270276
continue
271277
elif ylb == "periodic":
272278
p.y = myg.ymax + p.y - myg.ymin
273-
elif ylb in ["reflect-even", "reflect-odd"]:
279+
elif ylb in ["reflect-even", "reflect-odd", "dirichlet"]:
274280
p.y = 2 * myg.ymin - p.y
275281
else:
276282
msg.fail("ERROR: ylb = %s invalid BC for particles" % (ylb))
277283

278284
# +y boundary
279285
if p.y > myg.ymax:
280286
if yrb in ["outflow", "neumann"]:
287+
del self.particles[k]
281288
continue
282289
elif yrb == "periodic":
283290
p.y = myg.ymin + p.y - myg.ymax
284-
elif yrb in ["reflect-even", "reflect-odd"]:
291+
elif yrb in ["reflect-even", "reflect-odd", "dirichlet"]:
285292
p.y = 2 * myg.ymax - p.y
286293
else:
287294
msg.fail("ERROR: yrb = %s invalid BC for particles" % (yrb))
288295

289-
self.particles[k] = p
290-
291-
self.n_particles = len(self.particles)
292-
293296
def get_positions(self):
294297
"""
295298
Return an array of current particle positions.
@@ -307,7 +310,7 @@ def get_init_positions(self):
307310

308311
def write_particles(self, f):
309312
"""
310-
Output the particles' positions to an HDF5 file.
313+
Output the particles' positions (and initial positions) to an HDF5 file.
311314
312315
Parameters
313316
----------

0 commit comments

Comments
 (0)