foamgen.packing¶
Packing module¶
- synopsis
Prepares packed spheres for tessellation.
Functions
Delete unnecessary files. |
|
|
Create input file for packing-generation program. |
|
Runs the packing algorithm. |
|
Create cell size distribution and save it to file. |
|
Packs spheres into periodic domain. |
Reads results of packing algorithm. |
|
|
Save picture of packed domain. |
|
Save cell size distribution plot. |
|
Simple and fast algorithm for packing. |
-
foamgen.packing.
create_input
(npart, domain=1.0)[source]¶ Create input file for packing-generation program.
Function creates
generation.conf
file with some default inputs.- Parameters
npart (int) – number of spheres
domain (float, optional) – size of domain
-
foamgen.packing.
generate_structure
(flag)[source]¶ Runs the packing algorithm.
PackingGeneration.exe
must exist.generation.conf
must exist.- Parameters
flag (str) – argument to be passed to packing-generation program
-
foamgen.packing.
make_csd
(shape, scale, npart)[source]¶ Create cell size distribution and save it to file.
Log-normal distribution from scipy is used. Creates
diameters.txt
file with sphere diameters.- Parameters
shape (float) – shape size parameter of log-normal distribution
scale (float) – scale size parameter of log-normal distribution
npart (int) – number of spheres
- Returns
array of sphere diameters
- Return type
ndarray
-
foamgen.packing.
pack_spheres
(fname, shape, scale, number_of_cells, algorithm, maxit, render, clean)[source]¶ Packs spheres into periodic domain.
Creates file ending
Packing.csv
with sphere centers and radii. Simple model is implemented directly, other algorithms use Vasili Baranov’s code.- Parameters
fname (str) – base filename
shape (float) – shape size parameter of log-normal distribution
scale (float) – scale size parameter of log-normal distribution
number_of_cells (int) – number of spheres
algorithm (str) – name of packing algorithm
maxit (int) – number of tries for packing algorithm
render (bool) – save picture of packing if True
clean (bool) – delete redundant files if True
- Raises
Exception – when maximum number of iterations was reached
-
foamgen.packing.
read_results
()[source]¶ Reads results of packing algorithm.
Packing results are read from
packing.nfo
andpacking.xyzd
files.- Returns
center positions and diameters of spheres
- Return type
DataFrame
-
foamgen.packing.
render_packing
(fname, data, domain=1.0, pixels=1000)[source]¶ Save picture of packed domain.
Uses spack. Creates
*Packing.png
file.- Parameters
fname (str) – base filename
data (DataFrame) – center positions and diameters of spheres
domain (float, optional) – size of domain
pixels (int, optional) – picture resolution
-
foamgen.packing.
save_csd
(fname, diam, shape, scale, show_plot=False)[source]¶ Save cell size distribution plot.
Creates files
*.Packing_histogram.png
and*.Packing_histogram.pdf
with cell size distribution histogram and continual probability density function.- Parameters
fname (str) – base filename
diam (ndarray) – array of sphere diameters
shape (float) – shape size parameter of log-normal distribution
scale (float) – scale size parameter of log-normal distribution
show_plot (bool, optional) – create window with plot
-
foamgen.packing.
simple_packing
(diam)[source]¶ Simple and fast algorithm for packing.
Often leads to overlapping spheres. Can lead to infinite loop, thus it raises Exception after 10 s. Use of this algorithm at this stage is discouraged.
- Parameters
diam (ndarray) – array of sphere diameters
- Returns
center positions and diameters of spheres
- Return type
DataFrame
- Raises
Exception – when running for more than 10 s