utils Module

This includes utility functions that is used in MPM module.

utils.dxf2points(dxf_file)[source]
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 mesh

  • z_fill_method (str) – method to fill between lower and upper z-coordinates

  • lower_mesh (trimesh.Trimesh)

  • upper_mesh (trimesh.Trimesh)

  • cell_size (list)

  • initial_alpha (float) – = 0.1

  • alpha_decay (float)

  • n_particles_per_dim (int)

Returns:

Parameters:
  • lower_mesh (Trimesh)

  • upper_mesh (Trimesh)

  • cell_size (list)

  • n_particles_per_dim (int)

  • z_find_method (str)

  • base_find_method (str)

  • z_fill_method (str)

  • initial_alpha (float)

  • alpha_decay (float)

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 bound

  • cell_size (list) – [x_len, y_len, z_len]

  • particle_distance (float) – default distance between particles

  • method (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:

Parameters:
  • xy_coords (array)

  • z_ranges (array)

  • particle_distance (float)

  • method (str)

utils.generate_points(ranges, distance)[source]
Parameters:
  • ranges (list) – [[x_min, x_max], [y_min, y_max] [z_min, z_max]]

  • distance (float)

  • round_unit (float)

Returns:

coordinate of points with shape=(n_points, n_dims)

Parameters:
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_h5(uuid_dir, timestep, n_mpis)[source]
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)

utils.obj2mesh(file_path)[source]
utils.save_script(current_script_path, save_path)[source]