Skip to content

boundary_absorber

boundary_absorber

Rectangular absorbing-boundary augmentation for assembled meshes.

Attributes

FEMORA_MAX_NDF module-attribute

FEMORA_MAX_NDF = 9

Classes

PartitionerError

Bases: RuntimeError

Raised when a partitioning method fails or returns invalid output.

This exception is raised when validation of partitioner output formats, min/max indices, or array shapes fails, or if METIS is requested but pymetis is not available.

PartitionerRegistry

Registry and manager for Femora mesh partitioners.

This registry maintains a collection of partitioner algorithms (both built-in and optional dependency-based, like METIS) that map a PyVista UnstructuredGrid's mesh cells to integer partition IDs in [0, num_partitions - 1].

Attributes:

Name Type Description
_partitioners Dict[str, _RegisteredPartitioner]

Internal registry map storing registered partitioner functions and their availability checks.

Example
import pyvista as pv
from femora.components.partitioner.partitioner import PartitionerRegistry

# Construct a simple VTK grid and partition its cells
grid = pv.UnstructuredGrid(...)
labels = PartitionerRegistry.partition(
    grid,
    num_partitions=4,
    partitioner="hilbert",
)
Methods:
register staticmethod
register(name: str, func: Callable[..., ndarray], *, is_available: Optional[Callable[[], bool]] = None) -> None

Register a custom partitioner algorithm in Femora.

Parameters:

Name Type Description Default
name str

Unique string identifier for the partitioner (case-insensitive).

required
func Callable[..., ndarray]

A callable of type PartitionerFunc mapping a PyVista UnstructuredGrid and partition count to a 1D NumPy array of cell partition IDs.

required
is_available Optional[Callable[[], bool]]

Optional callback returning True if the partitioner's system dependencies are met. Defaults to None (always available).

None

Raises:

Type Description
ValueError

If name is empty or whitespace-only.

get_available_types staticmethod
get_available_types(*, include_unavailable: bool = False) -> List[str]

Get the names of all registered partitioner algorithms.

Parameters:

Name Type Description Default
include_unavailable bool

If True, returns all registered algorithms even if their external library dependencies (like pymetis) are missing. Defaults to False.

False

Returns:

Type Description
List[str]

List[str]: A sorted list of registered partitioner name keys.

validate staticmethod
validate(name: str) -> None

Validate if a partitioner name is registered and available.

Parameters:

Name Type Description Default
name str

The case-insensitive name of the partitioner to validate.

required

Raises:

Type Description
ValueError

If the partitioner name is not registered.

ImportError

If the partitioner requires missing external dependencies.

partition staticmethod
partition(mesh: UnstructuredGrid, num_partitions: int, *, partitioner: str = 'kd-tree', **kwargs: Any) -> np.ndarray

Partition a mesh's cells into a specified number of balanced domains.

Parameters:

Name Type Description Default
mesh UnstructuredGrid

The PyVista UnstructuredGrid representing the global assembled mesh.

required
num_partitions int

Target number of partitions/cores (must be >= 1).

required
partitioner str

Registered case-insensitive name of the partitioning algorithm to use. Defaults to "kd-tree".

'kd-tree'
**kwargs Any

Extra parameters passed to the underlying partitioner function.

{}

Returns:

Type Description
ndarray

np.ndarray: A 1D integer NumPy array of shape (mesh.n_cells,) mapping each cell index to a partition ID in [0, num_partitions - 1].

Raises:

Type Description
ValueError

If num_partitions is less than 1.

PartitionerError

If the partitioning function fails, returns an incorrect array shape, or produces out-of-bound partition IDs.

Model

Model(*, model_name: str | None = None, model_path: str | None = None)

Own a model's definitions, mesh parts, assembly, and exported solver process.

Each Model creates its own managers. Create definitions through those managers, assign them to mesh parts, assemble the parts, and export a solver script. Model construction and export do not launch OpenSees.

Parameters:

Name Type Description Default
model_name str | None

Default export basename, or None to require explicit filenames.

None
model_path str | None

Default export directory. Unknown configuration keywords are rejected instead of silently ignored.

None

Attributes:

Name Type Description
assembled_mesh UnstructuredGrid | None

Combined mesh after assembly, or None before assembly and after clear_model(). Export and downstream operations use it.

material

Material registry with nd and uniaxial factories.

section

Beam, shell, fiber, and other section factories.

transformation

Coordinate-transformation definitions for elements.

element

Beam, brick, quad, and special element definitions.

meshpart

Factories and registry for discretized component meshes.

assembler

Section creation, mesh combination, and partitioning.

interface

Connections between separate model components.

constraint

Single-point and multipoint constraints through sp and mp.

mass

Nodal mass assignment helpers.

damping

Damping definitions.

region

Region definitions and damping association.

group

Node and element selection groups.

mask

Model selection masks.

time_series

Loading time-function definitions.

ground_motion

Ground-motion definitions referencing time series.

load

Load definitions used by patterns.

pattern

Load-pattern definitions.

recorder

Solver response-output definitions.

actions

Deferred solver commands.

analysis

Static/transient analyses and solution-stack factories.

process

Ordered solver operations included in the exported Tcl.

events

Model-owned lifecycle notification bus.

spatial_transform

Spatial mesh transformation service.

Example
from femora import Model

model = Model(model_name="site", model_path="example_outputs/site")
soil = model.material.nd.elastic_isotropic(
    user_name="soil", E=108000.0, nu=1.0 / 3.0, rho=1.8,
)
model.set_results_folder("results")
assert model.material.get_by_name("soil") is soil
assert model.assembled_mesh is None
Note

Femora does not convert units. Choose a consistent system for geometry, material stiffness, density, loads, and time. A Model is not a Jobs Workflow and its process is not a remote execution scheduler.

Initialize a Femora Model instance.

Parameters:

Name Type Description Default
model_name str | None

Name used for default exported filenames.

None
model_path str | None

Directory used for default exports.

None
Methods:
set_nodetag_start
set_nodetag_start(start_tag: int) -> None

Set the starting tag number for nodes in exported TCL.

Parameters:

Name Type Description Default
start_tag int

First node tag to use (must be >= 1)

required
set_eletag_start
set_eletag_start(start_tag: int) -> None

Set the starting tag number for elements in exported TCL.

Parameters:

Name Type Description Default
start_tag int

First element tag to use (must be >= 1)

required
set_start_core_tag
set_start_core_tag(start_tag: int) -> None

Set the starting tag number for cores in exported TCL.

Parameters:

Name Type Description Default
start_tag int

First core tag to use (must be >= 0)

required
export_to_tcl
export_to_tcl(filename: str | None = None, progress_callback: Callable[..., None] | None = None, decimals: int = 5) -> bool

Export the model to a TCL file

Parameters:

Name Type Description Default
filename str

The filename to export to. If None, uses model_name in model_path

None
progress_callback callable

Callback function to report progress. If None, uses tqdm progress bar.

None
decimals int

Coordinate precision passed to the Tcl exporter.

5

Returns:

Name Type Description
success bool

True on success. Export/filesystem failures raise exceptions rather than returning False.

Raises:

Type Description
ValueError

If no filename is provided and model_name/model_path are not set

export_to_vtk
export_to_vtk(filename: str | None = None, write_info_json: bool = False, indent: int = 2) -> bool

Export the model to a vtk file

Parameters:

Name Type Description Default
filename str

The filename to export to. If None, uses model_name in model_path

None
write_info_json bool

When True, also write a lightweight sidecar JSON file.

False
indent int

JSON indentation level for sidecar info.

2

Returns:

Name Type Description
success bool

True on success. Missing assembly and write errors raise exceptions rather than returning False.

export_to_json
export_to_json(filename: str | None = None, indent: int = 2) -> bool

Export a lightweight structural snapshot of the model to JSON.

Parameters:

Name Type Description Default
filename str

The filename to export to. If None, uses model_name in model_path

None
indent int

JSON indentation level. Defaults to 2.

2

Returns:

Name Type Description
success bool

True if export was successful

set_model_info
set_model_info(model_name: str | None = None, model_path: str | None = None) -> None

Update model information

Parameters:

Name Type Description Default
model_name str

New model name

None
model_path str

New model path

None
set_results_folder
set_results_folder(folder_name: str) -> None

Store the output-folder setting used during recorder/export generation.

This setter stores the supplied value as-is. It does not create the directory, inspect permissions, or change Python's working directory. Relative paths are interpreted by the generated solver commands in their execution environment, not resolved by this setter.

Parameters:

Name Type Description Default
folder_name str

path to the results folder

required
get_results_folder
get_results_folder() -> str

Get the current results folder path

Returns:

Name Type Description
folder str

The path to the results folder

get_femora_parts
get_femora_parts() -> list[dict]

Return a detached metadata snapshot of registered source parts.

Returns:

Type Description
list[dict]

list[dict]: Source-part records used by VTK export. This is not a

list[dict]

mesh-part registry or a replacement for model.meshpart.get_all().

print_info
print_info() -> None

Print final-mesh point/cell counts, or 'No mesh found'.

This writes to stdout and returns None. It does not inspect convergence or validate the physical model.

get_max_ele_tag
get_max_ele_tag() -> int

Compute the last sequential export element tag from the cell count.

Returns:

Name Type Description
tag int

Start tag plus cell count minus one, or -1 without assembly. This does not inspect arbitrary imported cell tags.

get_max_node_tag
get_max_node_tag() -> int

Compute the last sequential export node tag from the point count.

Returns:

Name Type Description
tag int

Start tag plus point count minus one, or -1 without assembly. This is not the number of free solver equations.

get_start_ele_tag
get_start_ele_tag() -> int

Return the first exported solver element tag.

Returns:

Name Type Description
tag int

Export origin, independent of element-definition registry tags.

get_start_node_tag
get_start_node_tag() -> int

Return the first exported solver node tag.

Returns:

Name Type Description
tag int

Origin used when mapping zero-based assembled point indices.

clear_model
clear_model() -> None

Clear model definitions, assembled meshes, and ordered process steps.

Managers are retained but emptied, export tag starts reset to their defaults, and built-in lifecycle subscriptions are re-established. Custom event subscriptions are removed. Model name, model path, and the results-folder setting are retained.

This is destructive to the in-memory model. It does not delete exported files or results, stop a running solver, or emit a solver wipe. Previously held component references may be detached or stale; rebuild definitions through the model's managers before assembling again.

Functions:

_suppress_vtk_clip_warning

_suppress_vtk_clip_warning()

Suppress noisy VTK clip warnings for the rectangular absorber path.

_normalize_absorber_kwargs

_normalize_absorber_kwargs(*, num_layers: Optional[int] = None, num_partitions: Optional[int] = None, partition_algo: Optional[str] = None, geometry: Optional[str] = None, boundary_type: Optional[str] = None, rayleigh_damping: Optional[float] = None, match_damping: Optional[bool] = None, progress_callback: Optional[Callable] = None, **legacy_kwargs) -> dict

Normalize and validate keyword arguments for boundary absorber creation.

Parameters:

Name Type Description Default
num_layers Optional[int]

Number of absorbing cell layers.

None
num_partitions Optional[int]

Number of domain partitions/cores for parallel processing.

None
partition_algo Optional[str]

"kd-tree" uses VTK's spatial partitioner, which may round the requested count upward. "metis" uses the shared mesh partitioner, requires pymetis, and checks for the exact requested number of nonempty absorber partitions.

None
geometry Optional[str]

Boundary layer geometry. Must be "Rectangular" or "Cylindrical".

None
boundary_type Optional[str]

Boundary absorber formulation type. One of "PML", "Rayleigh", or "ASDA".

None
rayleigh_damping Optional[float]

Rayleigh damping factor. Defaults to 0.95.

None
match_damping Optional[bool]

If True, matches existing model damping rather than applying new.

None
progress_callback Optional[Callable]

Optional callback receiving float values to track progress.

None
**legacy_kwargs

Legacy snakeCase/camelCase arguments for backward compatibility.

{}

Returns:

Type Description
dict

A dictionary of normalized and validated parameter values.

Raises:

Type Description
TypeError

If required parameters are missing.

ValueError

If argument values are mathematically invalid or unsupported.

NotImplementedError

If unsupported experimental formulations are requested.

apply_rectangular_absorbing_layer

apply_rectangular_absorbing_layer(mesh_maker: 'Model', config: dict) -> bool

Apply a registered rectangular absorbing layer to the assembled mesh.

This function augments the assembled PyVista grid with PML or Rayleigh absorbing layers at the model boundaries (left, right, front, back, bottom) and registers the corresponding OpenSees elements and node constraints.

Parameters:

Name Type Description Default
mesh_maker 'Model'

The Model instance whose assembled mesh is to be augmented.

required
config dict

Dictionary containing normalized absorber parameters.

required

Returns:

Type Description
bool

True if the absorbing boundary was applied successfully.

Raises:

Type Description
ValueError

If no assembled mesh is found, if partitioning parameters are inconsistent, or if boundary element types or materials are incompatible.