Assembler
Assembler
Assembler manages assembly sections for a Model.
Runtime API:
- create_section(...), get(...), get_all(), remove(...), clear()
- assemble(...) to build mesh_maker.assembled_mesh
Attributes
Methods:
_print_assembly_start_banner
Print a compact start banner before assembly progress begins.
_print_assembly_complete_banner
Print a compact completion banner after assembly summary.
create_section
create_section(meshparts: List[str], num_partitions: int = 1, partition_algorithm: str = 'kd-tree', partitioner: Optional[str] = None, merge_points: bool = True, merge_in_final: bool = True, mass_merging: str = 'sum', tolerance: float = 1e-05, **kwargs: Any) -> AssemblySection
Create an AssemblySection directly through the Assembler.
This method creates a new AssemblySection from the specified mesh parts and automatically registers it with the Assembler. It handles initialization of the section, assigns a unique tag, and returns the created section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meshparts
|
List[str]
|
List of mesh part names to be assembled. These must be names of previously created MeshPart instances. |
required |
num_partitions
|
int
|
Number of partitions for parallel processing. For kd-tree, will be rounded to next power of 2. Defaults to 1 (no partitioning). |
1
|
partition_algorithm
|
str
|
Backward-compatible name for the mesh partitioner.
Prefer using |
'kd-tree'
|
partitioner
|
str
|
Mesh partitioner name (Femora terminology), e.g. "kd-tree",
"morton", "geometric".
If provided, it overrides |
None
|
merge_points
|
bool
|
Whether to merge points that are within a tolerance distance when assembling mesh parts. Defaults to True. |
True
|
merge_in_final
|
bool
|
If True, this section's points may be merged during the final assembler.assemble(...) merge pass (when merge_points=True). If False, this section is excluded from final point merging. Defaults to True. |
True
|
mass_merging
|
str
|
Method for merging mass properties of mesh parts. Defaults to "sum". Options are "sum" or "average". if "sum", the mass is summed across all merged points. if "average", the mass is averaged across merged points. |
'sum'
|
tolerance
|
float
|
Spatial tolerance used when merging points within this assembly section. Defaults to 1e-5. |
1e-05
|
**kwargs
|
Any
|
Additional keyword arguments to pass to AssemblySection constructor |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
AssemblySection |
AssemblySection
|
The newly created and registered assembly section |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any of the specified mesh parts don't exist or if the partition algorithm is invalid |
get_all
Return a copy of all assembly sections keyed by tag.
_add_assembly_section
Register an AssemblySection on this assembler and assign its tag.
Called by create_section(...) after the section mesh is built.
The assembler owns section registry lifecycle; sections do not register
themselves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assembly_section
|
AssemblySection
|
The AssemblySection to add |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Unique tag assigned to the added assembly section |
_retag_sections
Retag all assembly sections to ensure continuous numbering from 1.
This internal method is called after removing a section to ensure that the remaining sections have sequential tags starting from 1. It creates a new dictionary with updated tags and updates each section's internal tag.
_snap_points
staticmethod
Snap points within tolerance to the first representative point using KDTree.
get_num_cells
return the total number of cells in the assembled mesh
Returns: positive int: total number of cells negative int: if assembled mesh is None
get_num_points
return the total number of points in the assembled mesh
Returns: positive int: total number of points negative int: if assembled mesh is None
assemble
assemble(merge_points: bool = True, mass_merging: str = 'sum', tolerance: float = 1e-05, *, progress_callback=None) -> None
Assemble all registered AssemblySections into a single unified mesh.
This method combines all assembly sections into a single PyVista UnstructuredGrid. It preserves important mesh data like element tags, material tags, and region information. It also handles partitioning by correctly updating the Core cell data to maintain distinct partition ids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
merge_points
|
bool
|
Whether to merge points during assembly. If True, points within a small tolerance will be combined, creating a continuous mesh. If False, all points are preserved. Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no assembly sections have been created |
Exception
|
If any error occurs during the assembly process |
delete_assembled_mesh
Delete the assembled mesh.
Releases memory by deleting the assembled mesh, if it exists. This is useful when you want to clear resources or prepare for a new assembly operation without affecting the assembly sections.
plot
plot(color=None, style=None, scalars=None, clim=None, show_edges=None, edge_color=None, point_size=None, line_width=None, opacity=None, flip_scalars=False, lighting=None, n_colors=256, interpolate_before_map=None, cmap=None, label=None, reset_camera=None, scalar_bar_args=None, show_scalar_bar=None, multi_colors=False, name=None, texture=None, render_points_as_spheres=None, render_lines_as_tubes=None, smooth_shading=None, split_sharp_edges=None, ambient=None, diffuse=None, specular=None, specular_power=None, nan_color=None, nan_opacity=1.0, culling=None, rgb=None, categories=False, silhouette=None, use_transparency=False, below_color=None, above_color=None, annotations=None, pickable=True, preference='point', log_scale=False, pbr=None, metallic=None, roughness=None, render=True, user_matrix=None, component=None, emissive=None, copy_mesh=False, backface_params=None, show_vertices=None, edge_opacity=None, add_axes=True, add_bounding_box=False, show_grid=False, explode=False, explode_factor=0.1, sperate_beams_solid=False, opacity_beams=1.0, opacity_solids=0.5, tube_radius=0.05, show_cells_by_type=False, cells_to_show: Optional[List[int]] = None, off_screen: bool = False, screenshot: Optional[str] = None, **kwargs) -> None
Plot the assembled mesh using PyVista.
This method visualizes the assembled mesh for the Assembler instance.
It uses the PyVista plotting capabilities to render the mesh with
all keyword arguments supported by pyvista.Plotter.add_mesh for customization.
Parameters
color : str, sequence, or ColorLike, optional Solid color for the mesh. Accepts string, RGB list, or hex color string. style : str, optional Visualization style: 'surface', 'wireframe', 'points', or 'points_gaussian'. scalars : str or numpy.ndarray, optional Scalars used to color the mesh. String name or array. clim : sequence of float, optional Two-item color bar range for scalars. Example: [-1, 2]. show_edges : bool, optional Show mesh edges. Not for wireframe style. edge_color : str, sequence, or ColorLike, optional Color for edges when show_edges=True. point_size : float, optional Size of points. Default is 5.0. line_width : float, optional Thickness of lines for wireframe/surface. opacity : float, str, or array_like, optional Opacity of the mesh. Float (0-1), string transfer function, or array. flip_scalars : bool, optional Flip direction of colormap. lighting : bool, optional Enable/disable view direction lighting. n_colors : int, optional Number of colors for scalars. Default is 256. interpolate_before_map : bool, optional Smoother scalars display. Default True. cmap : str, list, or LookupTable, optional Colormap for scalars. String name, list of colors, or LookupTable. label : str, optional Label for legend. reset_camera : bool, optional Reset camera after adding mesh. scalar_bar_args : dict, optional Arguments for scalar bar. show_scalar_bar : bool, optional Show/hide scalar bar. multi_colors : bool, str, cycler, or sequence, optional Color each block by a solid color for MultiBlock datasets. name : str, optional Name for the mesh/actor for updating. texture : pyvista.Texture or np.ndarray, optional Texture to apply if mesh has texture coordinates. render_points_as_spheres : bool, optional Render points as spheres. render_lines_as_tubes : bool, optional Show lines as tubes. smooth_shading : bool, optional Enable smooth shading (Phong algorithm). split_sharp_edges : bool, optional Split sharp edges >30 degrees for smooth shading. ambient : float, optional Ambient lighting coefficient (0-1). diffuse : float, optional Diffuse lighting coefficient. Default 1.0. specular : float, optional Specular lighting coefficient. Default 0.0. specular_power : float, optional Specular power (0.0-128.0). nan_color : str, sequence, or ColorLike, optional Color for NaN values in scalars. nan_opacity : float, optional Opacity for NaN values (0-1). Default 1.0. culling : str, optional Face culling: 'front' or 'back'. rgb : bool, optional Interpret scalars as RGB(A) colors. categories : bool, optional Use unique values in scalars as n_colors. silhouette : dict or bool, optional Plot silhouette highlight for mesh. Dict for properties. use_transparency : bool, optional Invert opacity mapping to transparency. below_color : str, sequence, or ColorLike, optional Color for values below scalars range. above_color : str, sequence, or ColorLike, optional Color for values above scalars range. annotations : dict, optional Annotations for scalar bar. pickable : bool, optional Set actor pickable. preference : str, optional Scalar mapping preference: 'point' or 'cell'. log_scale : bool, optional Use log scale for color mapping. pbr : bool, optional Enable physics-based rendering (PBR). metallic : float, optional Metallic value for PBR (0-1). roughness : float, optional Roughness for PBR (0-1). render : bool, optional Force render. Default True. user_matrix : np.ndarray or vtkMatrix4x4, optional Transformation matrix for actor. component : int, optional Component of vector-valued scalars to plot. emissive : bool, optional Treat points as emissive light sources (for 'points_gaussian'). copy_mesh : bool, optional Copy mesh before adding. Default False. backface_params : dict or pyvista.Property, optional Backface rendering parameters. show_vertices : bool, optional Render external surface vertices. See vertex_ kwargs. edge_opacity : float, optional Edge opacity (0-1). explode : bool, optional Whether to explode blocks apart when style="explode". explode_factor : float, optional Factor to explode blocks apart when style="explode". sperate_beams_solid : bool, optional Whether to render beams and solids seperately. opacity_beams : float, optional Opacity of beams when sperate_beams_solid=True. opacity_solids : float, optional Opacity of solids when sperate_beams_solid=True. off_screen : bool, optional Render off-screen. Useful for servers without displays. screenshot : str, optional File path to save the screenshot. *kwargs : dict, optional Additional keyword arguments for PyVista add_mesh.
Raises
ValueError If no assembled mesh exists to plot.
get_mesh
Get the assembled mesh.
Returns the currently assembled mesh as a PyVista UnstructuredGrid. If no mesh has been assembled yet, returns None.
Returns:
| Type | Description |
|---|---|
Optional[UnstructuredGrid]
|
Optional[pv.UnstructuredGrid]: The assembled mesh, or None if not yet created |