foamgen.packing

Packing module

synopsis

Prepares packed spheres for tessellation.

Functions

clean_files()

Delete unnecessary files.

create_input(npart[, domain])

Create input file for packing-generation program.

generate_structure(flag)

Runs the packing algorithm.

make_csd(shape, scale, npart)

Create cell size distribution and save it to file.

pack_spheres(fname, shape, scale, …)

Packs spheres into periodic domain.

read_results()

Reads results of packing algorithm.

render_packing(fname, data[, domain, pixels])

Save picture of packed domain.

save_csd(fname, diam, shape, scale[, show_plot])

Save cell size distribution plot.

simple_packing(diam)

Simple and fast algorithm for packing.

foamgen.packing.clean_files()[source]

Delete unnecessary files.

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 and packing.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