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#
Write |
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
Meshobjects to disk.Each mesh is saved to a subdirectory of output_dir using the physicsnemo native format (
Mesh.save()). By default the subdirectory is namedmesh_{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 byMeshReaderin 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/subdirfor 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.meshformesh.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}). WhenNone(the default) the built-in patternmesh_{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:
- Raises:
ValueError – If naming_template contains invalid placeholders.
- classmethod params() list[physicsnemo_curator.core.base.Param]#
Return parameter descriptors for the mesh sink.
- set_source(
- source: physicsnemo_curator.core.base.Source[physicsnemo.mesh.Mesh],
Inject the pipeline source for
{relpath}/{stem}resolution.Called automatically by the
Pipelinewhen the sink is attached viaPipeline.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.
- physicsnemo_curator.domains.mesh.sinks.mesh_writer.logger#