utils Module
This includes utility functions that is used in MPM module.
- utils.fill_particles_between_mesh(lower_mesh, upper_mesh, cell_size, n_particles_per_dim, z_find_method, base_find_method, z_fill_method='simple', initial_alpha=0.1, alpha_decay=1)[source]
- Parameters:
base_find_method (
str) – method to find the base of the area where two surfaces overlap (‘alphashape’ or ‘simple’)z_find_method (
str) – method to find z-coordinate of meshz_fill_method (
str) – method to fill between lower and upper z-coordinateslower_mesh (
trimesh.Trimesh)upper_mesh (
trimesh.Trimesh)cell_size (
list)initial_alpha (
float) – = 0.1alpha_decay (
float)n_particles_per_dim (
int)
Returns:
- utils.fill_particles_inbetween(xy_coords, z_ranges, particle_distance, method='simple')[source]
- Parameters:
xy_coords (
np.array) – shape=(n_coords, 2)z_ranges (
np.array) – shape=(n_xy_coords, 2) where z_ranges[:, 0] is the lower bound & z_ranges[:, 1] is upper boundcell_size (
list) – [x_len, y_len, z_len]particle_distance (
float) – default distance between particlesmethod (
str) – method to fill particles between z_ranges: “simple”, “round” If simple, it uses the exact z-coordinate of mesh. If round, it uses the nearest particle grid points for particle generation.
Returns:
- utils.generate_random_field(x_range, y_range, nx, ny, lx, ly, sigma2, mean_value, seed=None)[source]
Generate a random field with anisotropic exponential correlation.
- Parameters:
x_range – Range of x coordinates (x_min, x_max).
y_range – Range of y coordinates (y_min, y_max).
nx – Number of grid points in x direction.
ny – Number of grid points in y direction.
lx – Correlation length in x direction.
ly – Correlation length in y direction.
sigma2 – Variance of the random field.
mean_value – Mean value of the random field.
seed – Random seed for reproducibility.
- Returns:
2D array containing the random field values. x: Array of x coordinates. y: Array of y coordinates.
- Return type:
field_2D
- utils.get_z_coordinates(mesh, xy_coords, find_method)[source]
Get the z-coordinate values on the mesh that correspond to given (x, y) coordinates.
Parameters: - mesh_path: trimesh object - xy_coords: np.array of shape (n, 2), array of (x, y) coordinates to get z-coords - find_method: ‘kdtree’, ‘linear’
Returns: - np.array of shape (n,), array of z-coordinate values.
- Parameters:
mesh (
Trimesh)xy_coords (
array)find_method (
str)