|
| 1 | +Particles overview |
| 2 | +================== |
| 3 | + |
| 4 | +A solver for modelling particles. |
| 5 | + |
| 6 | +``particles.particles`` implementation and use |
| 7 | +---------------------------------------------- |
| 8 | + |
| 9 | +We import the basic particles functionality as: |
| 10 | + |
| 11 | +.. code-block:: python |
| 12 | +
|
| 13 | + import particles.particles as particles |
| 14 | +
|
| 15 | +The particles solver is made up of two classes: |
| 16 | + |
| 17 | +* :func:`Particle <particles.particles.Particle>`, which holds |
| 18 | + the data about a single particle (its position and velocity); |
| 19 | +* :func:`Particles <particles.particles.Particles>`, which holds the data |
| 20 | + about a collection of particles. |
| 21 | + |
| 22 | +The particles are stored as a dictionary, and their positions are updated |
| 23 | +based on the velocity on the grid. The keys are assumed to be the initial |
| 24 | +positions of the particles (however this is only used for plotting purposes |
| 25 | +so any tuple would be fine). |
| 26 | + |
| 27 | +The particles can be initialised in a number of ways: |
| 28 | + |
| 29 | +* :func:`randomly_generate_particles <particles.particles.Particle.randomly_generate_particles>`, |
| 30 | + which randomly generates ``n_particles`` within the domain; |
| 31 | +* :func:`grid_generate_particles <particles.particles.Particle.grid_generate_particles>`, |
| 32 | + which will generate approximately ``n_particles`` equally spaced in the |
| 33 | + x-direction and y-direction (though the uses the same number of particles in |
| 34 | + each direction, so the spacing will be different in each direction if the |
| 35 | + domain is not square.) The number of particles will be increased/decreased |
| 36 | + in order to fill the whole domain; |
| 37 | +* the user can define their own ``particle_generator_func`` and pass this into the |
| 38 | + Particles constructor. This function takes the number of particles to be |
| 39 | + generated and returns a dictionary of ``Particle`` objects. |
| 40 | + |
| 41 | +We can initialize particles in a problem using the following code in the |
| 42 | +solver's ``Simulation.initialize`` function: |
| 43 | + |
| 44 | +.. code-block:: python |
| 45 | +
|
| 46 | + if self.rp.get_param("particles.do_particles") == 1: |
| 47 | + self.particles = particles.Particles(self.cc_data, bc, self.rp) |
| 48 | +
|
| 49 | +The particles can then be advanced by inserting the following code after the |
| 50 | +update of the other variables in the solver's ``Simulation.evolve`` function: |
| 51 | + |
| 52 | +.. code-block:: python |
| 53 | +
|
| 54 | + if self.particles is not None: |
| 55 | + self.particles.update_particles(u, v, self.dt) |
| 56 | + self.particles.enforce_particle_boundaries() |
| 57 | +
|
| 58 | +where ``u`` and ``v`` are the ``ArrayIndexer`` objects holding the x-velocity and |
| 59 | +y-velocity on the grid. |
| 60 | + |
| 61 | +We can turn on/off the particles solver using the following runtime paramters: |
| 62 | + |
| 63 | ++--------------------------------------------------------------------------------+ |
| 64 | +|``[particles]`` | |
| 65 | ++=======================+========================================================+ |
| 66 | +|``do_particles`` | do we want to model particles? (0=no, 1=yes) | |
| 67 | ++-----------------------+--------------------------------------------------------+ |
| 68 | +|``n_particles`` | number of particles to be modelled | |
| 69 | ++-----------------------+--------------------------------------------------------+ |
| 70 | +|``particle_generator`` | how do we initialize the particles? "random" | |
| 71 | +| | randomly generates particles throughout the domain, | |
| 72 | +| | "grid" generates equally spaced particles. This | |
| 73 | +| | option can be overridden by passing a custom generator | |
| 74 | +| | function to the ``Particles`` constructor. | |
| 75 | ++-----------------------+--------------------------------------------------------+ |
0 commit comments