mesher module
Warning
The following description is partially AI generated, it might be incomplete or incorrect.
- mesher.add_meshes_to_plotter(plotter, meshes)[source]
Add multiple meshes to a PyVista plotter.
This function adds the provided meshes to a given PyVista plotter object for visualization.
Parameters: plotter (pyvista.Plotter): The PyVista plotter object to which the meshes will be added. meshes (dict): A dictionary containing the meshes to add, keyed by mesh type.
Returns: pyvista.Plotter: The updated PyVista plotter object.
- mesher.check_points_inside_mesh(mesh, grid)[source]
Check if each point in the grid is inside or outside the mesh.
Parameters: mesh (pyvista.PolyData): The mesh to test against. grid (pyvista.StructuredGrid): The grid of points to test.
Returns: inside_points (np.ndarray): An array where 1 indicates the point is inside the mesh, and 0 indicates outside.
- mesher.create_matlab_script(script_filename, common_path, model_path, stl_path, block_height_multiplier, hmax, hmin)[source]
Create a MATLAB script to generate the mesh.
This function generates a MATLAB script that automates the creation of a mesh using COMSOL Multiphysics, including setting the necessary parameters for the mesh generation.
Parameters: script_filename (str): The path where the MATLAB script will be saved. common_path (str): The path to the common directory containing necessary scripts. model_path (str): The path to the model directory. stl_path (str): The path to the STL file of the mesh. block_height_multiplier (float): The multiplier for the block height. hmax (str): The maximum element size for meshing. hmin (str): The minimum element size for meshing.
- mesher.create_spatial_grid(bounds, spacing=1.0)[source]
Create a spatial grid of points that covers the size of the given bounds.
This function generates a 3D grid of points that spans the specified bounding box, with points spaced according to the given spacing parameter.
Parameters: bounds (tuple): The bounds of the region to cover (xmin, xmax, ymin, ymax, zmin, zmax). spacing (float): The spacing between points in the grid. Default is 1.0.
Returns: pyvista.StructuredGrid: The spatial grid of points.
- mesher.extract_plot(grid, inside_points)[source]
Visualize the inside points as a volume using PolyData.
This function takes a grid and a corresponding array of inside points, and creates a PolyData object that represents the volume of points inside the mesh.
Parameters: grid (pyvista.StructuredGrid): The spatial grid of points. inside_points (np.ndarray): An array where 1 indicates the point is inside the mesh, and 0 indicates outside.
Returns: pyvista.PolyData: The PolyData object representing the inside points.
- mesher.find_common_dir(start_dir, target_dir_name)[source]
Find the target directory by searching upwards from the start directory.
This function searches recursively upwards from a specified starting directory to find a directory with the specified name.
Parameters: start_dir (str): The directory path from which to start the search. target_dir_name (str): The name of the directory to find.
Returns: str: The absolute path to the target directory if found.
Raises: FileNotFoundError: If the target directory is not found.
- mesher.join_relative_paths(file_dir, relative_paths)[source]
Join the script directory with the relative paths.
This function joins the provided script directory with the relative paths of input files and ensures that all paths are correctly formed.
Parameters: file_dir (str): The directory where the script is located. relative_paths (dict): A dictionary of relative paths.
Returns: dict: A dictionary containing the absolute paths of the input files.
- class mesher.myMesh(paths, **kwargs)[source]
Bases:
object- assign_material_map(spacing=1.0)[source]
Assign material IDs to each point in the spatial grid based on the mesh it is inside.
This function creates a structured grid of points within the bounds of the wall mesh and checks which points are inside each of the provided meshes. The result is stored in the material_points attribute.
Parameters: spacing (float): The spacing between points in the grid. Default is 1.0.
- create_mph_mesh(block_height_multiplier, hmax, hmin)[source]
Create the volumetric wall mesh using COMSOL and MATLAB.
This function orchestrates the process of creating a volumetric wall mesh by first saving the wall mesh, then preparing and executing the required MATLAB script, and finally processing the output mesh file using COMSOL and custom tools.
- create_volumetric_wall_mesh(block_height_multiplier, hmax, hmin)[source]
Create the volumetric wall mesh using COMSOL and MATLAB.
This function orchestrates the process of creating a volumetric wall mesh by first saving the wall mesh, then preparing and executing the required MATLAB script, and finally processing the output mesh file using COMSOL and custom tools.
- prepare_matlab_script(block_height_multiplier, hmax, hmin)[source]
Create a MATLAB script to generate the mesh.
This function generates a MATLAB script that automates the process of creating a mesh using COMSOL Multiphysics. The script is saved in the specified output directory.
Parameters: block_height_multiplier (float): Multiplier for the block height used in the mesh. hmax (float): Maximum mesh element size. hmin (float): Minimum mesh element size.
- run_bash_script()[source]
Call the bash script.
This function executes a predefined Wolfram Language script using the wolframscript command-line tool. The script processes the mesh data in the specified output directory.
- save_to_hdf(material, name, outPath=None)[source]
Save material points data to HDF5 format.
This function saves the material point data for a specific material to an HDF5 file.
Parameters: material (str): The material for which to save the data (e.g., ‘wall’, ‘calc’, ‘fibr’, ‘lrnc’). name (str): The name of the output HDF5 file (without extension). outPath (str, optional): The directory where the HDF5 file will be saved.
If None, the default output path is used.
- save_wall_mesh()[source]
Save the wall mesh to an STL file.
This function saves the wall mesh to an STL file named ‘vessel_wall.stl’ in the specified output directory.
Raises: ValueError: If no wall mesh is found to save.
- scale_meshes(scale_factor)[source]
Scale all loaded meshes by the specified scale factor and store them in self.scaled.
This function applies a uniform scaling transformation to all loaded meshes based on the provided scale factor. The scaled meshes are stored in the scaled attribute.
Parameters: scale_factor (float): The factor by which to scale the meshes.
- set_out_path(paths)[source]
Set the output path for saving the material map files.
This function checks if the output directory exists and creates it if necessary. It then sets the outPath attribute to the specified output path.
Parameters: paths (dict): A dictionary containing the ‘out’ key with the output directory path.
- translate_meshes_to_origin()[source]
Translate a list of meshes so that the smallest coordinate for each axis starts from zero.
This function translates the loaded meshes so that the smallest coordinates along the x, y, and z axes are shifted to the origin (0, 0, 0). The translated meshes are stored in the translated attribute.
Returns: list: A list of translated meshes.
- visualize_material_map(plotter=None)[source]
Visualize the material map for the specified material.
This function creates a 3D plot that visualizes the distribution of material IDs across the spatial grid. Each material type (e.g., wall, calcification, fibrous, lipid) is displayed in a separate subplot.
Parameters: plotter (pyvista.Plotter, optional): A PyVista plotter object for customized plotting.
If None, a new plotter is created.
- visualize_mesh(type='scaled')[source]
Visualize the meshes in the self.scaled dictionary.
This function creates a 3D plot of the meshes. The meshes can be visualized in their original, translated, or scaled state based on the type parameter.
Parameters: type (str): The type of meshes to visualize (‘scaled’, ‘translated’, or ‘loaded’).
- write_material_map(outPath=None)[source]
Save all material points to HDF5 files and then run the bash script.
This function saves the material point data for all materials (‘wall’, ‘lrnc’, ‘calc’, ‘fibr’) to individual HDF5 files and then runs a predefined Wolfram Language script for further processing.
Parameters: outPath (str, optional): The directory where the HDF5 files will be saved.
If None, the default output path is used.