Skip to content

MeshPart

MeshPart

MeshPart(category: str, mesh_type: str, user_name: str, element: Optional[Element], region: Optional[RegionBase] = None)

Bases: ABC

Extension contract for a discretized component owned by one Model.

Instances do not self-register. A :class:MeshPartManager owns tag assignment and lifecycle.

Concrete subclasses generate mesh and define compatible element types. Ordinary scripts create parts through model.meshpart. Source-part edits must precede section creation, or affected sections must be rebuilt.

Attributes:

Name Type Description
user_name str

Registry name used by assembly section definitions.

element Element | None

Shared reusable element definition.

region RegionBase | None

Region associated with this part.

mesh DataSet | None

Generated geometry and per-point/cell data.

transform MeshPartTransform

Geometry transformation helper.

tag int | None

Part registry tag, not an individual solver cell tag.

Methods:

Name Description
generate_mesh

Generate this part's geometry and metadata in a concrete subclass.

is_elemnt_compatible

Test an element-type name against this mesh family's compatibility list.

remove_cells

Remove whole cells in place, before creating assembly sections.

plot

Display this part's mesh using a new PyVista plotter.

set_damping

Assign damping through this part's existing region.

Methods:

generate_mesh abstractmethod

generate_mesh() -> None

Generate this part's geometry and metadata in a concrete subclass.

Implementations populate mesh in place and may replace previous geometry/data. This abstract contract does not specify a returned mesh. Regeneration does not automatically rebuild existing assembly sections.

is_elemnt_compatible classmethod

is_elemnt_compatible(element: str) -> bool

Test an element-type name against this mesh family's compatibility list.

Parameters:

Name Type Description Default
element str

Element-type name, compared case-insensitively.

required

Returns:

Name Type Description
compatible bool

Whether the name occurs in the class list. This does not validate a material, DOF layout, or cell geometry.

Note

The public method retains the historical spelling elemnt.

remove_cells

remove_cells(selection: ArrayLike) -> None

Remove whole cells in place, before creating assembly sections.

Parameters:

Name Type Description Default
selection ArrayLike

One-dimensional Boolean mask with one entry per current cell, or integer cell indices. True entries are removed.

required

Remaining cell/point data are preserved and unused points are discarded. Coordinates, masses, and connectivity are not interpolated. Other mesh parts are untouched. An empty integer selection is a no-op; removing every cell leaves an empty mesh. Regenerating the mesh resets this edit.

Raises:

Type Description
ValueError

No mesh exists, indices are invalid, or this part has already been copied into an assembly section. Create a new part or remove/rebuild its sections before editing it.

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)
part = 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,
)
centers = part.mesh.cell_centers().points
inside = (abs(centers[:, 0]) < 16) & (centers[:, 2] > -4)
part.remove_cells(inside)

plot

plot(off_screen: bool = False, screenshot: Optional[str] = None, **kwargs: Any) -> None

Display this part's mesh using a new PyVista plotter.

Parameters:

Name Type Description Default
off_screen bool

Request off-screen rendering from PyVista.

False
screenshot str | None

Optional screenshot output passed to show.

None
**kwargs Any

Display options forwarded to Plotter.add_mesh.

{}

Raises:

Type Description
ValueError

No generated mesh exists. Rendering/backend errors propagate.

Note

Creates a zero-filled Mass point-data array when absent. Off-screen rendering still requires a compatible VTK graphics environment.

set_damping

set_damping(damping_instance: Damping) -> None

Assign damping through this part's existing region.

Parameters:

Name Type Description Default
damping_instance Damping

Damping definition accepted by the region.

required

Raises:

Type Description
ValueError

No region is assigned. Region validation errors propagate.

Note

Other parts sharing the region also observe the change. This does not create an isolated region or patch an already exported script.