Options Classes¶
This page documents the options classes for configuring remeshing operations.
Overview¶
Each mesh kind has a corresponding options class:
| Mesh Kind | Options Class |
|---|---|
TETRAHEDRAL |
Mmg3DOptions |
TRIANGULAR_2D |
Mmg2DOptions |
TRIANGULAR_SURFACE |
MmgSOptions |
Options classes are immutable dataclasses with:
- Type-checked parameters
- IDE autocomplete support
- Factory methods for common configurations
- Conversion to dictionary for
remesh()
3D Options¶
mmgpy.Mmg3DOptions
dataclass
¶
Mmg3DOptions(
*,
hmin: float | None = None,
hmax: float | None = None,
hsiz: float | None = None,
hausd: float | None = None,
hgrad: float | None = None,
hgradreq: float | None = None,
ar: float | None = None,
verbose: int | None = None,
mem: int | None = None,
optim: bool = False,
noinsert: bool = False,
noswap: bool = False,
nomove: bool = False,
nosurf: bool = False,
)
Bases: _MmgOptionsBase
Options for 3D tetrahedral mesh remeshing (MMG3D).
All parameters are optional. When None, MMG uses its internal defaults. Options are immutable after creation.
Additional Attributes¶
nosurf : bool Disable surface modifications (3D only).
Example:¶
opts = Mmg3DOptions(hmax=0.1, hausd=0.01) mesh.remesh(opts) # Pass options directly
options: show_root_heading: true members: - init - fine - coarse - optimize_only - to_dict
2D Options¶
mmgpy.Mmg2DOptions
dataclass
¶
Mmg2DOptions(
*,
hmin: float | None = None,
hmax: float | None = None,
hsiz: float | None = None,
hausd: float | None = None,
hgrad: float | None = None,
hgradreq: float | None = None,
ar: float | None = None,
verbose: int | None = None,
mem: int | None = None,
optim: bool = False,
noinsert: bool = False,
noswap: bool = False,
nomove: bool = False,
nosurf: bool = False,
)
Bases: _MmgOptionsBase
Options for 2D triangular mesh remeshing (MMG2D).
All parameters are optional. When None, MMG uses its internal defaults. Options are immutable after creation.
Additional Attributes¶
nosurf : bool Disable boundary modifications.
options: show_root_heading: true members: - init - fine - coarse - optimize_only - to_dict
Surface Options¶
mmgpy.MmgSOptions
dataclass
¶
MmgSOptions(
*,
hmin: float | None = None,
hmax: float | None = None,
hsiz: float | None = None,
hausd: float | None = None,
hgrad: float | None = None,
hgradreq: float | None = None,
ar: float | None = None,
verbose: int | None = None,
mem: int | None = None,
optim: bool = False,
noinsert: bool = False,
noswap: bool = False,
nomove: bool = False,
)
Bases: _MmgOptionsBase
Options for surface mesh remeshing (MMGS).
All parameters are optional. When None, MMG uses its internal defaults. Options are immutable after creation.
Note: Surface remeshing (MMGS) does not have a nosurf option.
options: show_root_heading: true members: - init - fine - coarse - optimize_only - to_dict
Parameter Reference¶
Size Parameters¶
| Parameter | Type | Description |
|---|---|---|
hmin |
float |
Minimum edge length |
hmax |
float |
Maximum edge length |
hsiz |
float |
Uniform target edge length |
hgrad |
float |
Gradation: max ratio between adjacent edges (default: 1.3) |
Geometric Parameters¶
| Parameter | Type | Description |
|---|---|---|
hausd |
float |
Hausdorff distance: max distance to input geometry |
angle |
float |
Ridge detection angle in degrees (default: 45.0) |
Control Parameters¶
| Parameter | Type | Description |
|---|---|---|
optim |
int |
Optimization mode: 1 = optimize only |
noinsert |
int |
Disable vertex insertion: 1 = no new vertices |
nosurf |
int |
Preserve surface: 1 = don't move surface vertices |
nomove |
int |
Disable vertex motion: 1 = no vertex smoothing |
noswap |
int |
Disable edge swapping: 1 = no topology changes |
Output Parameters¶
| Parameter | Type | Description |
|---|---|---|
verbose |
int |
Verbosity: -1=silent, 0=errors, 1=info, 2+=debug |
Usage Examples¶
Basic Usage¶
from mmgpy import Mesh, Mmg3DOptions
mesh = Mesh("input.mesh")
# Create options
opts = Mmg3DOptions(
hmin=0.01,
hmax=0.1,
hausd=0.001,
verbose=1,
)
# Use with remesh
result = mesh.remesh(opts)
Factory Methods¶
from mmgpy import Mmg3DOptions
# Fine mesh (small elements)
fine_opts = Mmg3DOptions.fine()
# Coarse mesh (large elements)
coarse_opts = Mmg3DOptions.coarse()
# Optimization only (no topology changes)
opt_opts = Mmg3DOptions.optimize_only()
Converting to Dictionary¶
opts = Mmg3DOptions(hmax=0.1, hausd=0.001)
# Get as dictionary
params = opts.to_dict()
print(params) # {'hmax': 0.1, 'hausd': 0.001}
# Unpack into remesh
result = mesh.remesh(**opts.to_dict())
Customizing Presets¶
from dataclasses import replace
# Start with a preset
base = Mmg3DOptions.fine()
# Customize using replace
custom = replace(base, hmax=0.05, verbose=1)
Combining with Keyword Arguments¶
Options objects and keyword arguments cannot be mixed:
# Correct: use options object
result = mesh.remesh(opts)
# Correct: use keyword arguments
result = mesh.remesh(hmax=0.1, hausd=0.001)
# Error: mixing both
result = mesh.remesh(opts, verbose=1) # TypeError!
Recommended Values¶
For Quality Optimization¶
opts = Mmg3DOptions(
optim=1, # Enable optimization mode
noinsert=1, # Don't add vertices
hgrad=1.1, # Gentle gradation
)
For Surface Preservation¶
opts = Mmg3DOptions(
hmax=0.1,
hausd=0.0001, # Tight approximation
nosurf=1, # Preserve surface vertices
)
For CFD Meshes¶
opts = Mmg3DOptions(
hmin=0.001,
hmax=0.1,
hgrad=1.2, # Smooth size transition
hausd=0.001,
angle=20.0, # Detect more ridges
)