1- Particles overview
2- ==================
1+ Particles
2+ =========
33
44A solver for modelling particles.
55
66``particles.particles `` implementation and use
77----------------------------------------------
88
9- We import the basic particles functionality as:
9+ We import the basic particles module functionality as:
1010
1111.. code-block :: python
1212
@@ -20,28 +20,48 @@ The particles solver is made up of two classes:
2020 about a collection of particles.
2121
2222The 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).
23+ based on the velocity on the grid. The keys are tuples of the particles'
24+ initial positions (however the values of the keys themselves are never used
25+ in the module, so this could be altered using e.g. a custom ``particle_generator ``
26+ function without otherwise affecting the behaviour of the module).
2627
27- The particles can be initialised in a number of ways:
28+ The particles can be initialized in a number of ways:
2829
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> `,
30+ * :func: `randomly_generate_particles <particles.particles.Particles .randomly_generate_particles> `,
31+ which randomly generates ``n_particles `` within the domain.
32+ * :func: `grid_generate_particles <particles.particles.Particles .grid_generate_particles> `,
3233 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+ x-direction and y-direction (note that it uses the same number of particles in
3435 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- * :func: `array_generate_particles <particles.particles.Particle.array_generate_particles> `,
38- generates particles based on array of particle positions passed to the constructor;
39- * the user can define their own ``particle_generator `` and pass this into the
40- Particles constructor. This function takes the number of particles to be
36+ domain is not square). The number of particles will be increased/decreased
37+ in order to fill the whole domain.
38+ * :func: `array_generate_particles <particles.particles.Particles.array_generate_particles> `,
39+ which generates particles based on array of particle positions passed to the
40+ constructor.
41+ * The user can define their own ``particle_generator `` function and pass this into the
42+ ``Particles `` constructor. This function takes the number of particles to be
4143 generated and returns a dictionary of ``Particle `` objects.
4244
43- We can initialize particles in a problem using the following code in the
44- solver's ``Simulation.initialize `` function:
45+ We can turn on/off the particles solver using the following runtime paramters:
46+
47+ +--------------------------------------------------------------------------------+
48+ | ``[particles]`` |
49+ +=======================+========================================================+
50+ | ``do_particles`` | do we want to model particles? (0=no, 1=yes) |
51+ +-----------------------+--------------------------------------------------------+
52+ | ``n_particles`` | number of particles to be modelled |
53+ +-----------------------+--------------------------------------------------------+
54+ | ``particle_generator`` | how do we initialize the particles? "random" |
55+ | | randomly generates particles throughout the domain, |
56+ | | "grid" generates equally spaced particles, "array" |
57+ | | generates particles at positions given in an array |
58+ | | passed to the constructor. This option can be |
59+ | | overridden by passing a custom generator function to |
60+ | | the ``Particles `` constructor. |
61+ +-----------------------+--------------------------------------------------------+
62+
63+ Using these runtime parameters, we can initialize particles in a problem using
64+ the following code in the solver's ``Simulation.initialize `` function:
4565
4666.. code-block :: python
4767
@@ -58,38 +78,34 @@ update of the other variables in the solver's ``Simulation.evolve`` function:
5878 if self .particles is not None :
5979 self .particles.update_particles(self .dt)
6080
81+ This will both update the positions of the particles and enforce the boundary
82+ conditions.
83+
6184For some problems (e.g. advection), the x- and y- velocities must also be passed
6285in as arguments to this function as they cannot be accessed using the standard
63- ``get_var("velocity") `` command.
86+ ``get_var("velocity") `` command. In this case, we would instead use
87+
88+ .. code-block :: python
89+
90+ if self .particles is not None :
91+ self .particles.update_particles(self .dt, u, v)
6492
65- We can turn on/off the particles solver using the following runtime paramters:
6693
67- +--------------------------------------------------------------------------------+
68- | ``[particles]`` |
69- +=======================+========================================================+
70- | ``do_particles`` | do we want to model particles? (0=no, 1=yes) |
71- +-----------------------+--------------------------------------------------------+
72- | ``n_particles`` | number of particles to be modelled |
73- +-----------------------+--------------------------------------------------------+
74- | ``particle_generator`` | how do we initialize the particles? "random" |
75- | | randomly generates particles throughout the domain, |
76- | | "grid" generates equally spaced particles. This |
77- | | option can be overridden by passing a custom generator |
78- | | function to the ``Particles `` constructor. |
79- +-----------------------+--------------------------------------------------------+
8094
8195 Plotting particles
8296------------------
8397
84- Particles can be plotted by getting their positions using
98+ Given the ``Particles `` object ``particles ``, we can plot the particles by getting
99+ their positions using
85100
86101.. code-block :: python
87102
88103 particle_positions = particles.get_positions()
89104
90105 In order to track the movement of particles over time, it's useful
91- to 'dye' the particles based on their initial positions. This can
92- be done by calling
106+ to 'dye' the particles based on their initial positions. Assuming that the
107+ keys of the particles dictionary were set as the particles' initial positions,
108+ this can be done by calling
93109
94110.. code-block :: python
95111
0 commit comments