Grid Generation
pysammos.grid_generation package
Regular Cuboid module
This module provides the Grid_Generation class for generating regular cuboid grids
for coarse graining in DEM simulations. It supports automatic and custom grid range
determination, and can generate 1D, 2D, or 3D grids with user-specified axes and resolution.
Key Methods
Automatic_Range()Determines grid ranges automatically based on particle bounds and smoothing length.
Create_grid_points()Static method to generate grid points and nodes for 1D, 2D, or 3D grids.
Generate()Main method to generate the grid using either automatic or custom ranges.
- class pysammos.grid_generation.regular_cuboid.Grid_Generation(smoothing_length, particle_bounds, grid_dimensions, grid_axes, max_particle_diameter, automatic_range, custom_grid_range, custom_grid_transects)[source]
Bases:
objectInputs
- smoothing_lengthfloat
Smoothing length (kernel size) for grid spacing calculations.
- particle_boundsndarray of shape (3, 2)
Minimum and maximum coordinates for the particle domain along x, y, z.
- grid_dimensionsint
Dimensionality of the grid: 1, 2, or 3.
- grid_axesstr
Axes along which the grid will be generated. For 1D: 'x', 'y', or 'z'. For 2D: 'xy', 'xz', or 'yz'. For 3D: 'xyz' (implicitly used).
- max_particle_diameterfloat
Maximum particle diameter used for domain buffer calculations.
- automatic_rangebool
If True, automatically determine the grid range with domain padding.
- custom_grid_rangetuple of float or None
Custom range (x0, x1, y0, y1, z0, z1) if automatic_range is False.
- custom_grid_transectstuple of float or None
Custom transect positions (x_transect, y_transect, z_transect) if automatic_range is False.
Example
>>> grid_gen = Grid_Generation(smoothing_length=0.1, ... particle_bounds=np.array([[0, 1], [0, 1], [0, 1]]), ... grid_dimensions=2, ... grid_axes='xy', ... max_particle_diameter=0.05, ... automatic_range=True, ... custom_grid_range=(None, None, None, None, None, None), ... custom_grid_transects=(None, None, None)) >>> GridPoints, Nodes, Spacing, Ranges_Length = grid_gen.Generate() >>> print("Grid Points:\n", GridPoints) >>> print("Nodes:", Nodes) >>> print("Spacing:", Spacing) >>> print("Ranges Length:", Ranges_Length)
- Automatic_Range()[source]
Automatically determine the grid coordinate ranges based on domain bounds and kernel size.
- Return type:
Tuple[list,list,list]
Inputs
- x_rangelist of float
Minimum and maximum x-coordinates for the grid.
- y_rangelist of float
Minimum and maximum y-coordinates for the grid.
- z_rangelist of float
Minimum and maximum z-coordinates for the grid.
Outputs
- x_rangelist of float
Minimum and maximum x-coordinates for the grid.
- y_rangelist of float
Minimum and maximum y-coordinates for the grid.
- z_rangelist of float
Minimum and maximum z-coordinates for the grid.
Notes
The method offsets the bounds by \(2.5\,c + 0.5\,d_\mathrm{max}\), where \(c\) is the smoothing length and \(d_\mathrm{max}\) is the maximum particle diameter, to avoid boundary effects.
- static Create_grid_points(X_range, Y_range, Z_range, X_transect, Y_transect, Z_transect, c, high_res_scaling=1.5, dimensions=3, axes='xyz')[source]
Create structured grid points in 1D, 2D, or 3D.
- Return type:
Tuple[ndarray,ndarray,ndarray]
Inputs
- X_range, Y_range, Z_rangelist of float or None
Coordinate ranges for each axis, in the form [min, max]. If None, that axis will be fixed at its transect value.
- X_transect, Y_transect, Z_transectfloat or None
Transect positions for fixed coordinates when not generating points along that axis.
- cfloat
Smoothing length used for grid spacing calculation.
- high_res_scalingfloat, optional
Scaling factor for grid density (default is 1.5).
- dimensionsint, {1, 2, 3}
Dimensionality of the generated grid.
- axesstr
Axes along which to generate the grid. Options are:
3D: 'xyz'
2D: 'xy', 'xz', 'yz'
1D: 'x', 'y', 'z'
Outputs
- grid_pointsndarray of shape (N, 3)
Array of generated grid points in 3D coordinates.
- nodesndarray of shape (3,)
Number of nodes along each axis (0 if fixed).
- spacingndarray
Grid spacing along each active axis.
- raises ValueError:
If the number of grid points in a direction is <= 1, or if dimensions/axes combination is invalid.
Notes
Spacing along active axes is computed as
c / high_res_scaling.The output is always a set of points in 3D space, even for 1D and 2D grids, to maintain compatibility with 3D data structures.
This method uses np.meshgrid to create structured grids.
- Generate()[source]
Generate the computational grid points.
- Return type:
Tuple[ndarray,ndarray,ndarray,ndarray]
Outputs
- GridPointsndarray of shape (N, 3)
Generated grid points in 3D coordinates.
- Nodesndarray of shape (3,)
Number of nodes along each axis.
- Spacingndarray
Grid spacing along each active axis.
- Ranges_Lengthndarray of shape (3,)
Length of each coordinate range. Zero if the axis is fixed.
Notes
If automatic_range is True, grid ranges are computed using
Automatic_Range()with domain padding.If automatic_range is False, ranges and transects are taken from custom_grid_range and custom_grid_transects.
The method calls
Create_grid_points()to build the grid.