mesh_writer#

PhysicsNeMo Mesh writer sink.

Persists physicsnemo.mesh.Mesh objects to disk using the native tensordict memory-mapped format via Mesh.save().

Attributes#

Classes#

MeshSink

Write Mesh objects to disk.

Module Contents#

class physicsnemo_curator.domains.mesh.sinks.mesh_writer.MeshSink(output_dir: str, naming_template: str | None = None)#

Bases: physicsnemo_curator.core.base.Sink[physicsnemo.mesh.Mesh]

Write Mesh objects to disk.

Each mesh is saved to a subdirectory of output_dir using the physicsnemo native format (Mesh.save()). By default the subdirectory is named mesh_{index:04d}_{seq}, but a custom naming_template can be provided to control output names — for example, to produce filenames that match the patterns expected by MeshReader in PhysicsNeMo.

When the pipeline’s source exposes a relative_path(index) method (e.g. VTKSource), two additional template placeholders become available:

  • {relpath} — the parent directory of the source file relative to the source root (e.g. sim_a/subdir for a file at <root>/sim_a/subdir/mesh.vtu). Empty string when the file lives directly in the root.

  • {stem} — the filename stem of the source file (without extension, e.g. mesh for mesh.vtu).

These are wired automatically by the pipeline — no need to pass the source manually. This enables directory-mirroring workflows where the output dataset reproduces the nested folder layout of the input.

Parameters:
  • output_dir (str) – Directory where mesh outputs will be written.

  • naming_template (str or None) – Python format string used to generate subdirectory names. The placeholders {index} (source index) and {seq} (sequence number within the source, starting at 0) are always available. When the source supports it, {relpath} and {stem} are also available. Standard format-spec syntax is supported (e.g. {index:04d}). When None (the default) the built-in pattern mesh_{index:04d}_{seq} is used.

Examples

Default naming:

>>> sink = MeshSink(output_dir="./output/")
>>> paths = sink(mesh_generator, index=0)
>>> paths
['./output/mesh_0000_0']

Custom naming for compatibility with MeshReader:

>>> sink = MeshSink(
...     output_dir="./output/",
...     naming_template="boundary_{index}.vtp.pmsh",
... )
>>> paths = sink(mesh_generator, index=0)
>>> paths
['./output/boundary_0.vtp.pmsh']

Directory mirroring (preserves input folder structure, wired by pipeline):

>>> pipeline = (
...     VTKSource("./input/")
...     .write(MeshSink(output_dir="./output/", naming_template="{relpath}/{stem}"))
... )

Initialise the mesh sink.

Parameters:
  • output_dir (str) – Directory where mesh outputs will be written.

  • naming_template (str or None) – Python format string for subdirectory names. See the class docstring for details.

Raises:

ValueError – If naming_template contains invalid placeholders.

classmethod params() list[physicsnemo_curator.core.base.Param]#

Return parameter descriptors for the mesh sink.

Returns:

The output_dir and optional naming_template parameters.

Return type:

list[Param]

set_source(
source: physicsnemo_curator.core.base.Source[physicsnemo.mesh.Mesh],
) None#

Inject the pipeline source for {relpath}/{stem} resolution.

Called automatically by the Pipeline when the sink is attached via Pipeline.write().

Parameters:

source (Source[Mesh]) – The pipeline source. If it exposes a relative_path(index) method, the sink will use it to resolve naming placeholders.

description: ClassVar[str] = 'Save meshes in physicsnemo native format (tensordict memmap)'#

Short description shown in the interactive CLI.

name: ClassVar[str] = 'PhysicsNeMo Mesh Writer'#

Human-readable display name for the interactive CLI.

physicsnemo_curator.domains.mesh.sinks.mesh_writer.logger#