particles package

Particles routines

Submodules

particles.particles module

Stores and manages particles and updates their positions based on the velocity on the grid.

class particles.particles.Particle(x, y, u=0, v=0)[source]

Bases: object

Class to hold properties of a single (massless) particle.

This class could be extended (i.e. inherited from) to model e.g. massive/charged particles.

interpolate_velocity(myg, u, v)[source]

Interpolate the x- and y-velocities defined on grid myg to the particle’s position.

Parameters
mygGrid2d

grid which the velocities are defined on

uArrayIndexer

x-velocity

vArrayIndexer

y_velocity

pos()[source]

Return position vector.

update(u, v, dt)[source]

Advect the particle and update its velocity.

velocity()[source]

Return velocity vector.

class particles.particles.Particles(sim_data, bc, n_particles, particle_generator='grid', pos_array=None, init_array=None)[source]

Bases: object

Class to hold multiple particles.

array_generate_particles(pos_array, init_array=None)[source]

Generate particles based on array of their positions. This is used when reading particle data from file.

Parameters
pos_arrayfloat array

Array of particle positions.

init_arrayfloat array

Array of initial particle positions.

enforce_particle_boundaries()[source]

Enforce the particle boundaries

TODO: copying the dict and adding everything back again is messy - think of a better way to do this? Did it this way so don’t have to remove items from a dictionary while iterating it for outflow boundaries.

get_init_positions()[source]

Return initial positions of the particles as an array.

We defined the particles as a dictionary with their initial positions as the keys, so this just becomes a restructuring operation.

get_positions()[source]

Return an array of current particle positions.

grid_generate_particles(n_particles)[source]

Generate particles equally spaced across the grid. Currently has the same number of particles in the x and y directions (so dx != dy unless the domain is square) - may be better to scale this.

If necessary, shall increase/decrease n_particles in order to fill grid.

randomly_generate_particles(n_particles)[source]

Randomly generate n_particles.

update_particles(dt, u=None, v=None)[source]

Update the particles on the grid. This is based off the AdvectWithUcc function in AMReX, which used the midpoint method to advance particles using the cell-centered velocity.

We will explicitly pass in u and v if they cannot be accessed from the sim_data using get_var("velocity").

Parameters
dtfloat

timestep

uArrayIndexer object

x-velocity

vArrayIndexer object

y-velocity

write_particles(f)[source]

Output the particles’ positions (and initial positions) to an HDF5 file.

Parameters
fh5py object

HDF5 file to write to