Skip to content

Assembler

Assembler

Assembler(mesh_maker: 'Model | None' = None)

Combine and partition model mesh parts through model.assembler.

First create sections from registered mesh-part names. Section creation builds a section mesh immediately. Then assemble combines those section meshes, applies model lifecycle operations, and stores the final mesh on model.assembled_mesh. It does not export Tcl or run OpenSees.

Assembly sections are mesh/partition groups, not structural cross sections from model.section. Partitions describe the solver decomposition, not a scheduler allocation or an automatic MPI launch.

Example
from femora import Model

model = Model()
soil = model.material.nd.elastic_isotropic(user_name="soil", E=1e5, nu=0.3, rho=1.8)
brick = model.element.brick.std(ndof=3, material=soil)
model.meshpart.volume.uniform_rectangular_grid(
    user_name="soil_block", element=brick,
    x_min=0, x_max=4, y_min=0, y_max=4, z_min=-4, z_max=0,
    nx=2, ny=2, nz=2,
)
section = model.assembler.create_section(meshparts=["soil_block"], num_partitions=1)
model.assembler.assemble(progress_callback=lambda *_: None)
assert model.assembled_mesh is not None
assert model.assembler.get(section.tag) is section
Warning

Point merging changes connectivity. Keep nodes distinct when interfaces are intended to connect independent components. Reassembly replaces the final mesh and is not transactional: a failure can leave no valid final mesh.

Methods:

Name Description
create_section

Create an AssemblySection directly through the Assembler.

get

Return the registered assembly section for an exact tag.

get_all

Return a copy of all assembly sections keyed by tag.

remove

Remove an assembly section and retag the remaining sections.

clear

Empty the section registry, retaining the current final mesh.

assemble

Assemble all registered AssemblySections into a single unified mesh.

get_mesh

Return a copy of the final assembled mesh, not the live model mesh.

get_num_cells

return the total number of cells in the assembled mesh

get_num_points

return the total number of points in the assembled mesh

delete_assembled_mesh

Delete the assembled mesh.

reset

Clear the final mesh and all section registrations.

plot

Plot the assembled mesh using PyVista.

Methods:

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, *, progress_callback: Callable[..., None] | None = None) -> '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 partitioner. Defaults to "kd-tree".

'kd-tree'
partitioner str

Mesh partitioner name (Femora terminology), e.g. "kd-tree", "morton", "geometric". If provided, it overrides partition_algorithm.

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
progress_callback Callable[..., None] | None

Optional section-construction progress callback.

None

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

get(tag: int) -> 'AssemblySection'

Return the registered assembly section for an exact tag.

Parameters:

Name Type Description Default
tag int

Current section registry key.

required

Raises:

Type Description
KeyError

No section has that tag. Unlike some component managers, this lookup does not return None for missing entries.

get_all

get_all() -> Dict[int, 'AssemblySection']

Return a copy of all assembly sections keyed by tag.

remove

remove(tag: int) -> None

Remove an assembly section and retag the remaining sections.

Parameters:

Name Type Description Default
tag int

Current section key; an absent key raises KeyError.

required

Source mesh parts are not removed. The current final mesh is not automatically rebuilt, so assemble again before export.

clear

clear() -> None

Empty the section registry, retaining the current final mesh.

Source mesh parts remain registered. Use reset() to clear both sections and the final mesh; this method alone does not prevent use of a previously assembled mesh.

assemble

assemble(merge_points: bool = True, mass_merging: str = 'sum', tolerance: float = 1e-05, *, progress_callback: Callable[..., None] | None = 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
mass_merging str

Mass combination policy for merged nodes, sum or average. Choose consistently with how source nodal masses represent shared physical contributions.

'sum'
tolerance float

Point-merging tolerance in model length units.

1e-05
progress_callback Callable | None

Receives progress value and message. None uses Femora's default progress display.

None

Returns:

Name Type Description
result None

The result is stored on model.assembled_mesh; this method does not return the grid.

Raises:

Type Description
ValueError

If no assembly sections have been created

Exception

If any error occurs during the assembly process

get_mesh

get_mesh() -> Optional[pv.UnstructuredGrid]

Return a copy of the final assembled mesh, not the live model mesh.

To intentionally access live mesh arrays, use model.assembled_mesh. A returned copy can be inspected or saved independently.

Returns:

Name Type Description
mesh UnstructuredGrid | None

Mesh copy, or None if absent.

get_num_cells

get_num_cells() -> int

return the total number of cells in the assembled mesh

Returns:

Name Type Description
count int

Assembled cell count, or -1 if no final mesh exists.

get_num_points

get_num_points() -> int

return the total number of points in the assembled mesh

Returns:

Name Type Description
count int

Assembled point count, or -1 if no final mesh exists.

delete_assembled_mesh

delete_assembled_mesh() -> None

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.

reset

reset() -> None

Clear the final mesh and all section registrations.

Source mesh parts and their element/material definitions are retained. Recreate sections before assembling again. This does not delete files or clear all model managers; use model.clear_model() for the latter.

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.