Mesh API¶
The reference uses implementation paths where necessary for static
documentation, but the documented primitives and operations are exported from
the top-level nmesh package. For example, use nmesh.Box, not an internal
module import.
Loading and construction¶
Mesh region IDs may be arbitrary positive integers. When loading a simulation, materials are assigned to the distinct IDs in ascending order.
load ¶
Load legacy Nmesh or a Meshio-supported mesh file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
Source mesh path. |
required |
reorder
|
bool
|
Request unsupported legacy node reordering. |
False
|
distribute
|
bool
|
Keep true; manual distribution is unsupported. |
True
|
Returns:
| Type | Description |
|---|---|
MeshFromFile
|
Mesh wrapper containing points, simplices, regions, and topology. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If the mesh layout or supported cells are invalid. |
NotImplementedError
|
If reordering or manual distribution is requested. |
mesh_from_points_and_simplices ¶
mesh_from_points_and_simplices(points: Sequence[Sequence[float]] | None = None, simplices_indices: Sequence[Sequence[int]] | None = None, simplices_regions: Sequence[int] | None = None, periodic_point_indices: Sequence[Sequence[int]] | None = None, initial: int = 0, do_reorder: bool = False, do_distribute: bool = True)
Construct a mesh from explicit points, simplex indices, and regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
Sequence[Sequence[float]] | None
|
Coordinate vectors with a consistent dimension. |
None
|
simplices_indices
|
Sequence[Sequence[int]] | None
|
Point-index vectors defining simplex cells. |
None
|
simplices_regions
|
Sequence[int] | None
|
Positive region ID for every simplex. |
None
|
periodic_point_indices
|
Sequence[Sequence[int]] | None
|
Optional groups of equivalent periodic points. The micromagnetic simulation does not currently support periodic boundary physics. |
None
|
initial
|
int
|
Use |
0
|
do_reorder
|
bool
|
Request unsupported legacy node reordering. |
False
|
do_distribute
|
bool
|
Keep true; manual distribution is unsupported. |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If points, simplices, regions, or indices are inconsistent. |
NotImplementedError
|
If reordering or manual distribution is requested. |
save ¶
save(mesh: MeshBase, filename: str | Path) -> None
Save a mesh using the format selected by the destination suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
MeshBase
|
Mesh to serialize. |
required |
filename
|
str | Path
|
Destination. |
required |
Mesh objects¶
MeshBase ¶
Expose mesh geometry and topology through cached Python values.
Attributes:
| Name | Type | Description |
|---|---|---|
points |
list[Point]
|
Node coordinates. |
simplices |
list[Simplex]
|
Point indices for every simplex cell. |
regions |
list[int]
|
Region ID for every simplex. |
dim |
int
|
Coordinate dimension. |
surfaces |
list[list[int]]
|
Boundary simplex indices. |
point_regions |
list[list[int]]
|
Incident region IDs for every point. |
links |
list[tuple[int, int]]
|
Unique mesh edges as point-index pairs. |
region_volumes |
list[float]
|
Computed volume for each region. |
Mesh ¶
Mesh(bounding_box: Sequence[Sequence[float]] | None, objects: Sequence[MeshObject] | None = None, a0: float = 1.0, density: str = '', periodic: Sequence[bool] | Sequence[float] | None = None, fixed_points: Sequence[Sequence[float]] | None = None, mobile_points: Sequence[Sequence[float]] | None = None, simply_points: Sequence[Sequence[float]] | None = None, callback: tuple[MeshCallback, int] | None = None, mesh_bounding_box: bool = False, meshing_parameters: MeshingParameters | None = None, cache_name: str = '', hints: Sequence[tuple[MeshBase, MeshObject]] | None = None, **kwargs: Any)
Generate a simplex mesh from implicit geometric objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounding_box
|
Sequence[Sequence[float]] | None
|
Lower and upper coordinate corners enclosing the model. |
required |
objects
|
Sequence[MeshObject] | None
|
Geometry primitives or boolean combinations to mesh. |
None
|
a0
|
float
|
Target initial point spacing in mesh-coordinate units. |
1.0
|
density
|
str
|
Optional legacy density expression. |
''
|
periodic
|
Sequence[bool] | Sequence[float] | None
|
Periodic coordinate selectors for bounding-box meshing. |
None
|
fixed_points
|
Sequence[Sequence[float]] | None
|
Additional points held fixed during relaxation. |
None
|
mobile_points
|
Sequence[Sequence[float]] | None
|
Additional mobile seed points. |
None
|
simply_points
|
Sequence[Sequence[float]] | None
|
Additional simple seed points. |
None
|
callback
|
tuple[MeshCallback, int] | None
|
Mesher progress callback and interval. |
None
|
mesh_bounding_box
|
bool
|
Mesh the complete bounding box when true. |
False
|
meshing_parameters
|
MeshingParameters | None
|
Explicit mesher controls. |
None
|
cache_name
|
str
|
Optional compatibility cache label. |
''
|
hints
|
Sequence[tuple[MeshBase, MeshObject]] | None
|
Mesh/object hint pairs. |
None
|
**kwargs
|
Any
|
Named meshing-parameter overrides. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the bounding box or object configuration is invalid. |
Geometry primitives¶
Box ¶
Box(p1: ArrayLike, p2: ArrayLike, transform: Iterable[TransformationStep] | None = None, fixed: Sequence[Sequence[float]] | None = None, mobile: Sequence[Sequence[float]] | None = None, system_coords: bool = True, use_fixed_corners: bool = False)
Create a box from two opposite corners.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p1
|
ArrayLike
|
First corner coordinates. |
required |
p2
|
ArrayLike
|
Opposite corner coordinates. |
required |
transform
|
Iterable[TransformationStep] | None
|
Optional transformation steps applied in order. |
None
|
fixed
|
Sequence[Sequence[float]] | None
|
Extra fixed mesher points. |
None
|
mobile
|
Sequence[Sequence[float]] | None
|
Extra mobile mesher points. |
None
|
system_coords
|
bool
|
Apply transformations in system coordinates when true. |
True
|
use_fixed_corners
|
bool
|
Add every box corner as a fixed mesher point. |
False
|
signed_distance ¶
Evaluate the object's scalar field at one point or many points.
contains ¶
Return whether the supplied point or points lie inside the object.
shift ¶
Translate the object by the given vector.
scale ¶
Scale the object in body coordinates by the supplied per-axis factors.
rotate ¶
Rotate the object in the plane spanned by the two axis indices.
rotate_3d ¶
Rotate a three-dimensional object about the supplied axis vector.
transform ¶
Apply a sequence of named transform tuples in the given order.
Ellipsoid ¶
Ellipsoid(lengths: ArrayLike, transform: Iterable[TransformationStep] | None = None, fixed: Sequence[Sequence[float]] | None = None, mobile: Sequence[Sequence[float]] | None = None, system_coords: bool = True)
Create an axis-aligned ellipsoid from its principal radii.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lengths
|
ArrayLike
|
Positive radius along each coordinate axis. |
required |
transform
|
Iterable[TransformationStep] | None
|
Optional transformation steps applied in order. |
None
|
fixed
|
Sequence[Sequence[float]] | None
|
Extra fixed mesher points. |
None
|
mobile
|
Sequence[Sequence[float]] | None
|
Extra mobile mesher points. |
None
|
system_coords
|
bool
|
Apply transformations in system coordinates when true. |
True
|
signed_distance ¶
Evaluate the object's scalar field at one point or many points.
contains ¶
Return whether the supplied point or points lie inside the object.
shift ¶
Translate the object by the given vector.
scale ¶
Scale the object in body coordinates by the supplied per-axis factors.
rotate ¶
Rotate the object in the plane spanned by the two axis indices.
rotate_3d ¶
Rotate a three-dimensional object about the supplied axis vector.
transform ¶
Apply a sequence of named transform tuples in the given order.
Conic ¶
Conic(c1: ArrayLike, r1: float, c2: ArrayLike, r2: float, transform: Iterable[TransformationStep] | None = None, fixed: Sequence[Sequence[float]] | None = None, mobile: Sequence[Sequence[float]] | None = None, system_coords: bool = True)
Create a conical frustum from two centers and radii.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c1
|
ArrayLike
|
First end center. |
required |
r1
|
float
|
Non-negative first-end radius. |
required |
c2
|
ArrayLike
|
Second end center. |
required |
r2
|
float
|
Non-negative second-end radius. |
required |
transform
|
Iterable[TransformationStep] | None
|
Optional transformation steps applied in order. |
None
|
fixed
|
Sequence[Sequence[float]] | None
|
Extra fixed mesher points. |
None
|
mobile
|
Sequence[Sequence[float]] | None
|
Extra mobile mesher points. |
None
|
system_coords
|
bool
|
Apply transformations in system coordinates when true. |
True
|
signed_distance ¶
Evaluate the object's scalar field at one point or many points.
contains ¶
Return whether the supplied point or points lie inside the object.
shift ¶
Translate the object by the given vector.
scale ¶
Scale the object in body coordinates by the supplied per-axis factors.
rotate ¶
Rotate the object in the plane spanned by the two axis indices.
rotate_3d ¶
Rotate a three-dimensional object about the supplied axis vector.
transform ¶
Apply a sequence of named transform tuples in the given order.
union ¶
Return a geometry that is inside any supplied object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objects
|
Sequence[MeshObject]
|
At least two objects with the same dimension. |
required |
Returns:
| Type | Description |
|---|---|
MeshObject
|
Combined mesh object. |
difference ¶
Carve each subtractor out of a mother object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mother
|
MeshObject
|
Object to retain. |
required |
subtract
|
Sequence[MeshObject]
|
Same-dimensional objects to remove. |
required |
Returns:
| Type | Description |
|---|---|
MeshObject
|
Resulting mesh object. |
intersect ¶
Return a geometry that is inside every supplied object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objects
|
Sequence[MeshObject]
|
At least two objects with the same dimension. |
required |
Returns:
| Type | Description |
|---|---|
MeshObject
|
Intersected mesh object. |