Skip to main content

A package for calculating packing density of particles in Cartesian and cylindrical coordinate systems.

Project description

Packing3D

A Python package for calculating the local and bulk packing density of particles in 3D Cartesian and cylindrical coordinate systems, with capability to mesh a region and visualise packing density distribution.

Example Image1 Above image: Cross-sectional packing density distribution of 100,000 particles (~500-600 microns) in a cylindrical container of diameter 75 mm, with packing density calculated from z = [0.005 m, 0.020 m].


Table of Contents


Requirements

  • Python 3.8 or later*
  • *WARNING: As of 28th Nov 2024, the VTK dependency of PyVista does not work with Python 3.13

Dependencies

  • NumPy: For efficient numerical operations.
  • SciPy: For numerical integration and advanced mathematical functions.
  • PyVista: For reading and handling .vtk files.

Installation

The package is available on PyPI and can be installed via:

pip install packing3d

Alternatively, clone the repository at https://github.com/fjbarter/packing3d/ and install manually from the local files.


Key Functions

compute_packing_cartesian

Description

Computes the packing density of particles within a defined cuboidal region in Cartesian coordinates.

Args

  • file (str, optional): Path to the .vtk file containing particle data. Required if coordinate data is not provided.
  • boundaries (dict, optional): Dictionary defining the cuboidal region boundaries with keys x_min, x_max, y_min, y_max, z_min, and z_max. Defaults to automatic boundaries based on the dataset.
  • x_data, y_data, z_data (np.ndarray, optional): Preloaded x, y, z coordinates of particles.
  • radii (np.ndarray, optional): Preloaded radii of particles.

Returns

  • float: The packing density as the fraction of volume occupied by particles.

Example

from packing3d import compute_packing_cartesian

packing_density = compute_packing_cartesian(file='particles.vtk')
print(f"Packing Density: {packing_density}")

generate_cartesian_mesh

Description

Generates a Cartesian mesh that can approximate a cuboidal or cylindrical region. If cylindrical_mesh_shape is specified True, the exact volume of the cartesian cells which overlap the cylinder walls is calculated and used for the packing density, so there is no need to worry about incorrectly low packing densities at the wall (although they will still be low!).

Args

  • x_divisions, y_divisions, z_divisions (int): Number of divisions along the x, y, and z axes.
  • boundaries (dict, optional): Dictionary defining the boundaries of the Cartesian region.
  • cylindrical_mesh_shape (bool, optional): Boolean that creates a cylindrical mesh shape with cartesian cells.
  • radius (float, optional): Radius of the cylindrical region to approximate, if applicable.
  • base_level (float, optional): Base level of the cylinder in the z-direction.
  • height (float, optional): Height of the cylindrical region for meshing

Returns

  • list: A list of tuples, each containing (indices, boundaries) for each cell.

Example

from packing3d import generate_cartesian_mesh

mesh = generate_cartesian_mesh(x_divisions=10, y_divisions=10, z_divisions=5,
                               boundaries=boundaries, cylindrical_mesh_shape=False,
                               radius=None, base_level=None, height=None)
print(mesh)

compute_packing_cylindrical

Description

Computes the packing density of particles within a defined cylindrical region in cylindrical coordinates.

Args

  • file (str, optional): Path to the .vtk file containing particle data. Required if coordinate data is not provided.
  • boundaries (dict, optional): Dictionary defining the cylindrical region boundaries with keys r_min, r_max, theta_min, theta_max, z_min, and z_max. Defaults to automatic boundaries based on the dataset.
  • r_data, theta_data, z_data (np.ndarray, optional): Preloaded radial, angular, and z coordinates of particles.
  • radii (np.ndarray, optional): Preloaded radii of particles.

Returns

  • float: The packing density as the fraction of the cylindrical volume occupied by particles.

Example

from packing3d import compute_packing_cylindrical

packing_density = compute_packing_cylindrical(file='particles.vtk')
print(f"Packing Density: {packing_density}")

generate_cylindrical_mesh

Description

Generates a cylindrical mesh with division indices for radial, angular, and z-direction partitions. There is an inner cylindrical cell, created to avoid problems associated with converging radial lines.

The mesh cells created all have a constant volume, with theta_divisions determining the number of cells in the first ring, outside the inner cylindrical cell. If radius_inner is None, it will have a radius equal to the width of each radial division.

Args

  • radius (float): Radius of the cylindrical region.
  • height (float): Height of the cylindrical region.
  • r_divisions, theta_divisions, z_divisions (int): Number of divisions in radial, angular, and z directions.
  • 'radius_inner' (float, optional): Radius of the inner cylindrical cell. Defaults to radius / r_divisions.

Returns

  • list: A list of tuples, each containing (indices, boundaries) for each cell.

Example

from packing3d import generate_cylindrical_mesh

mesh = generate_cylindrical_mesh(radius=10, height=20, r_divisions=5, theta_divisions=8, z_divisions=10)
print(mesh)

convert_to_cylindrical

Description

Converts Cartesian coordinates to cylindrical coordinates with theta in [0, 2π].

Args

  • x_data (np.ndarray): Array of x-coordinates.
  • y_data (np.ndarray): Array of y-coordinates.

Returns

  • r_data (np.ndarray): Radial distances from the origin.
  • theta_data (np.ndarray): Angles in radians from the x-axis, in the range [0, 2π].

read_vtk_file

Description

Reads a .vtk file using PyVista and returns the data object.

Args

  • file (str): Path to the .vtk file.

Returns

  • pyvista.DataSet: The data object from the .vtk file.

retrieve_coordinates

Description

Extracts x, y, z coordinates and radii from the dataset.

Args

  • data: PyVista data object containing particle information.

Returns

  • x_data, y_data, z_data, radii (np.ndarray): Arrays of coordinates and radii.

How It Works

  1. Data Reading:

    • Uses PyVista to read .vtk files containing particle coordinates and radii.
    • read_vtk_file and retrieve_coordinates facilitate this process.
  2. Coordinate Conversion:

    • For cylindrical computations, Cartesian coordinates are converted using convert_to_cylindrical.
  3. Boundary Determination:

    • Boundaries can be user-defined or automatically computed based on the dataset using compute_automatic_boundaries.
  4. Volume Calculations:

    • For particles completely inside the boundaries, their full volume is added.
    • For particles partially overlapping boundaries, geometric functions compute the exact volume of intersection.
  5. Packing Density Computation:

    • Total particle volume within the boundaries is divided by the cell volume to obtain the packing density.

Testing

  • Unit Tests: Planned for future releases to ensure accuracy and reliability.
  • Sample Data: .vtk files are provided for testing in the examples directory.

Examples

  • examples.py in the examples directory provides three examples with corresponding vtk files.

Limitations

  • Optimised for spherical particles only.
  • Requires .vtk files with properly formatted particle data.

License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.


Contact

For questions, support, or contributions, reach out to:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

packing3d-0.1.4.tar.gz (10.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

packing3d-0.1.4-py3-none-any.whl (10.2 MB view details)

Uploaded Python 3

File details

Details for the file packing3d-0.1.4.tar.gz.

File metadata

  • Download URL: packing3d-0.1.4.tar.gz
  • Upload date:
  • Size: 10.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for packing3d-0.1.4.tar.gz
Algorithm Hash digest
SHA256 d70f22f1b9482cdbc82672f3889fa242c1f69fc232e1dca2790824d48f9d2cd5
MD5 a918d9bfa8efa6a892bf3ea977912e85
BLAKE2b-256 dfeb7cfb76d9a98bf97bdcfe79043ece93d89d89f758554fbe4f07a33743dc03

See more details on using hashes here.

File details

Details for the file packing3d-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: packing3d-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 10.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for packing3d-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a326d3cabc79598517f1d55c394414bf3b7ce7811ead9245c3a66a0902b94ea8
MD5 74199330e5a00bed1ac1ca8203a173c9
BLAKE2b-256 eb9da9b57c0671e5f4e84cb6ecff3b975e8860897ba6bea5061d469a306fce5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page