pycbg.preprocessing.Particles¶
-
class
pycbg.preprocessing.
Particles
(mesh, npart_perdim_percell=1, directory='', check_duplicates=True)¶ Create and write to a file particles from a
Mesh
object.- Parameters
mesh (
Mesh
object) – Mesh in which the particles will be generated.npart_perdim_percell (int, optional) – Number of particles for each dimensions in one cell. All cells will contain
npart_perdim_percell**3
equally spaced particles. Note that particles are equally spaced within a cell, not between cells. Default is 1 .directory (str, optional) – Directory in which the particles file will be saved. If the directory doesn’t already exist, it will be created. It is set by default to the current working directory.
check_duplicates (bool, optional) – See CB-Geo documentation for informations on this parameter. Default is True.
-
particles
¶ Positions of all particles written into the particles file. The id of a particle is the index of its line in this array. Noting npart the number of particles, the shape of particles is
(npart,3)
.- Type
numpy array
-
filename
¶ Path to the particles file from the current working directory.
- Type
str
-
npart_perdim_percell
¶ Number of particles for each dimensions in one cell.
- Type
int
-
directory
¶ Directory in which the particles file will be saved.
- Type
str
-
check_duplicates
¶ See CB-Geo documentation.
- Type
bool
Notes
The particles file is written upon creating the object.
One can manually generate the particles by directly setting the particles attribute. It is then necessary to rewrite the particles file using the write_file method.
Examples
Generating 8 particles in a one cell mesh :
>>> mesh = Mesh((1.,1.,1.), (1,1,1)) >>> particles = Particles(mesh, 2) >>> particles.particles array([[0.33333333, 0.33333333, 0.33333333], [0.33333333, 0.33333333, 0.66666667], [0.33333333, 0.66666667, 0.33333333], [0.33333333, 0.66666667, 0.66666667], [0.66666667, 0.33333333, 0.33333333], [0.66666667, 0.33333333, 0.66666667], [0.66666667, 0.66666667, 0.33333333], [0.66666667, 0.66666667, 0.66666667]])
Manually generating four particles :
>>> mesh = Mesh((1.,1.,1.), (1,1,1)) >>> particles = Particles(mesh) >>> particles.particles = np.array([[.02, .02, .02], ... [.05, .02, .02], ... [.02, .05, .02], ... [.02, .02, .05]]) >>> particles.write_file()
Note that a mesh has to be specified even if it isn’t used.
-
__init__
(mesh, npart_perdim_percell=1, directory='', check_duplicates=True)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
Initialize self.
Create the particles using the given mesh.
Write the particles file formatted for CB-Geo.
-
create_particles
(mesh, npart_perdim_percell=1)¶ Create the particles using the given mesh.
- Parameters
mesh (
Mesh
object) – Mesh in which the particles will be generated.npart_perdim_percell (int, optional) – Number of particles for each dimensions in one cell. All cells will contain
npart_perdim_percell**3
equally spaced particles. Note that particles are equally spaced within a cell, not between cells. Default is 1 .
-
write_file
()¶ Write the particles file formatted for CB-Geo.