Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

pymrm.segmentation

Back to modules overview

SDF-based domain segmentation for immersed boundaries in pymrm.

Immersed boundary conditions are specified per wall crossing rather than on a grid-aligned face, so the spatial broadcasting that domain-wall boundary conditions enjoy (a single value copied along a wall) is not directly available. In practice the most useful spatial pattern is piecewise constant per body: give every dispersed element (a disjoint region of the signed distance field) its own interface condition. This module restores that workflow.

segment_domain labels the disjoint regions of the SDF with scipy.ndimage.label. crossing_segments maps each IBM crossing to the label of the body it bounds, and segment_values / combine_interface_conditions expand per-segment data to the per-crossing arrays consumed by pymrm.apply_ibm and pymrm.apply_ibm_interface. Where a body touches the domain boundary, wall_patch / wall_values produce broadcast-ready coefficients for the ordinary {a, b, d} wall boundary conditions, so a wall-touching body can carry the same condition on its wall patch as on its immersed part. wall_contact reports which bodies reach a domain wall — useful on the fluid side (region="positive") to detect isolated no-flux pockets that would otherwise make the operator singular.

The region argument selects which side of the interface is segmented: "negative" (the default, sdf < 0 solid bodies) or "positive" (sdf >= 0 fluid regions), matching the solid/fluid convention of pymrm.construct_ibm.

View module source on GitHub

Public API

SymbolTypeSummary
SegmentationclassPer-cell integer labelling of one region of the spatial grid.
combine_interface_conditionsfunctionMerge per-segment interface conditions into one per-crossing ic.
crossing_segmentsfunctionSegment label of the body bounded by each IBM crossing.
segment_domainfunctionLabel the disjoint regions of a signed distance field.
segment_fieldfunctionExpand per-segment values to a per-cell spatial field.
segment_valuesfunctionExpand per-segment values to a per-crossing array for pymrm.apply_ibm.
wall_contactfunctionWhether each segment reaches each domain wall.
wall_patchfunctionSegment labels on one domain wall, shaped as a full-field coefficient.
wall_valuesfunctionPer-segment values on one domain wall as a full-field BC coefficient.

Segmentation()

Open dedicated reference page

Per-cell integer labelling of one region of the spatial grid.

Produced by segment_domain (connected components of a signed distance field) or by pymrm.construct_ibm_particles (one label per particle, which keeps touching particles distinct). The per-segment helpers (crossing_segments, segment_values, combine_interface_conditions, wall_patch, wall_values, segment_field) work with either source.

Attributes

View source on GitHub

Members

connectivity

View source on GitHub

labels

View source on GitHub

n_segments

View source on GitHub

region

View source on GitHub

sizes

View source on GitHub

combine_interface_conditions(ic_by_segment, seg, ibm, *, default = None)

Open dedicated reference page

Merge per-segment interface conditions into one per-crossing ic.

Each entry of ic_by_segment is a two-dict interface condition in the format of pymrm.apply_ibm_interface. The returned ic has, for every coefficient slot, a per-crossing array assembled from the owning segment of each crossing — so all crossings of one body share that body’s condition.

Parameters

Returns

View source on GitHub

crossing_segments(seg, ibm)

Open dedicated reference page

Segment label of the body bounded by each IBM crossing.

For region="negative" the label of the inside (solid) cut cell is returned; for region="positive" the outside (fluid) cut cell. In either case the cut cell lies in the segmented region, so every returned label is in 1 .. n_segments.

Parameters

Returns

View source on GitHub

segment_domain(sdf, *, region = 'negative', connectivity = 1)

Open dedicated reference page

Label the disjoint regions of a signed distance field.

Parameters

Returns

View source on GitHub

segment_field(values, seg, *, default = 0.0)

Open dedicated reference page

Expand per-segment values to a per-cell spatial field.

lookup[seg.labels] — background cells (label 0) receive default. For example a per-particle diffusivity for the cell-centred-D conjugate diffusion pattern.

Parameters

Returns

View source on GitHub

segment_values(values, seg, ibm, *, default = None)

Open dedicated reference page

Expand per-segment values to a per-crossing array for pymrm.apply_ibm.

Parameters

Returns

View source on GitHub

wall_contact(seg)

Open dedicated reference page

Whether each segment reaches each domain wall.

Returns

Notes

A fluid-side segmentation (region="positive") whose segment touches no wall is an isolated pocket; with all-Neumann surroundings it makes the operator singular. Detect them with np.flatnonzero(~wall_contact(seg).any(axis=(1, 2))) + 1.

View source on GitHub

wall_patch(seg, ibm, axis, side)

Open dedicated reference page

Segment labels on one domain wall, shaped as a full-field coefficient.

Parameters

Returns

View source on GitHub

wall_values(values, seg, ibm, axis, side, *, default = 0.0)

Open dedicated reference page

Per-segment values on one domain wall as a full-field BC coefficient.

Combines wall_patch with a per-segment lookup so that a wall-touching body can be given the same condition on its wall patch as on its immersed boundary. The per-segment values may carry non-spatial structure (broadcastable to ibm.ns_shape).

Parameters

Returns

View source on GitHub