mesh_writer#

PhysicsNeMo Mesh writer sink.

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

Attributes#

Classes#

MeshSink

Write Mesh and DomainMesh 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 and DomainMesh objects to disk.

Each mesh is saved to a subdirectory of output_dir using the physicsnemo native format (Mesh.save() / DomainMesh.save()). By default the subdirectory is named mesh_{index:04d}_{seq}, but a custom naming_template can be provided to control output names.

The appropriate file extension is appended automatically based on the object type:

  • .pmsh for Mesh objects

  • .pdmsh for DomainMesh objects

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).

When the source exposes run_id(index) and/or mesh_name(index, seq) methods, the following placeholders are also available:

  • {run_id} — an integer identifier for the simulation run, resolved via source.run_id(index).

  • {mesh_name} — a per-mesh name resolved via source.mesh_name(index, seq). Useful for multi-mesh sources where each sequence position has a distinct logical name.

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}, {stem}, {run_id}, and {mesh_name} 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 placeholder resolution.

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

Parameters:

source (Source[Mesh]) – The pipeline source. If it exposes relative_path(index), run_id(index), or mesh_name(index, seq) methods, the sink will use them 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#