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#
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
MeshandDomainMeshobjects 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 namedmesh_{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:
.pmshforMeshobjects.pdmshforDomainMeshobjects
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).
When the source exposes
run_id(index)and/ormesh_name(index, seq)methods, the following placeholders are also available:{run_id}— an integer identifier for the simulation run, resolved viasource.run_id(index).{mesh_name}— a per-mesh name resolved viasource.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}). 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 placeholder resolution.
Called automatically by the
Pipelinewhen the sink is attached viaPipeline.write().- Parameters:
source (Source[Mesh]) – The pipeline source. If it exposes
relative_path(index),run_id(index), ormesh_name(index, seq)methods, the sink will use them to resolve naming placeholders.
- physicsnemo_curator.domains.mesh.sinks.mesh_writer.logger#