Skip to content

VTXWriter: support file modes#4177

Open
schnellerhase wants to merge 8 commits intomainfrom
schnellerhase/vtx-timeseries
Open

VTXWriter: support file modes#4177
schnellerhase wants to merge 8 commits intomainfrom
schnellerhase/vtx-timeseries

Conversation

@schnellerhase
Copy link
Copy Markdown
Contributor

@schnellerhase schnellerhase commented Apr 24, 2026

Adds support to ADIOS2Writer and VTXWriter to open files in append mode (following interface of VTKFile). Enabling usage such as

import dolfinx
from mpi4py import MPI

mesh = dolfinx.mesh.create_unit_square(comm := MPI.COMM_WORLD, n := 10, n)
V = dolfinx.fem.functionspace(mesh, ("CG", 1))
f = dolfinx.fem.Function(V)

# this usage previously only held the 9th iterate in the output, i.e. was not supported
for i in range(10):
    f.x.array[:] = i
    with dolfinx.io.VTXWriter(
        comm,
        "out_a.bp",
        "a",
        [f],
    ) as writer:
        writer.write(i)

# now holds equivalent output to:
with dolfinx.io.VTXWriter(
    comm,
    "out_w.bp",
    "w",
    [f],
) as writer:
    for i in range(10):
        f.x.array[:] = i
        writer.write(i)

Demonstrates the new feature, with simplified I/o logic in the naiver stokes demo.

@schnellerhase schnellerhase added enhancement New feature or request io labels Apr 24, 2026
@schnellerhase schnellerhase force-pushed the schnellerhase/vtx-timeseries branch 2 times, most recently from c274af4 to 1f68407 Compare April 24, 2026 13:05
@schnellerhase schnellerhase self-assigned this Apr 24, 2026
@schnellerhase schnellerhase marked this pull request as ready for review April 24, 2026 13:21
@schnellerhase schnellerhase requested a review from jorgensd April 24, 2026 13:21
@schnellerhase schnellerhase changed the title VTXWriter: enable append file writing VTXWriter: support file modes Apr 24, 2026
@schnellerhase schnellerhase force-pushed the schnellerhase/vtx-timeseries branch 2 times, most recently from e75536c to e350ed9 Compare April 24, 2026 13:36
@schnellerhase schnellerhase force-pushed the schnellerhase/vtx-timeseries branch from e350ed9 to 1911667 Compare April 24, 2026 13:55
Args:
comm: The MPI communicator
filename: The output filename
mode: The filemode to open the file in, one of 'a' (append)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove "one of", automatic when using "or".

if (mode == "a")
return adios2::Mode::Append;

if (mode == "w")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if and else?

_engine->Close();
}
//-----------------------------------------------------------------------------
adios2::Mode impl_adios2::mode(const std::string& mode)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider just wrapping adios2::Mode directly as an enum?

_engine->Close();
}
//-----------------------------------------------------------------------------
adios2::Mode impl_adios2::mode(const std::string& mode)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use non-owning std::string_view

}

/// Convert string to corresponding adios2 mode.
/// @param[in] mode Mode in string representation, either "w" or "a".
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving aside Enum vs no Enum, it's generally most transparent to map modes directly e.g. "Read" -> "adios2::Mode::Read". Then I have a clear idea what "Read" means in the context of the underlying library.

@jorgensd
Copy link
Copy Markdown
Member

I'm a bit sceptical about adding an "append" mode, as the VTXScheme shouldn't (or at least couldn't previously) be modified at runtime with ADIOS2, which is why the initializer takes in the functions/meshes to store at each time-step, instead of following the XDMF file version where we write when we can.

adding an append-mode needs us to revise the internal logic to ensure for consistent input at multiple steps.
We would also have to thoroughly check which variables ADIOS2 now allows to be time-dependent (last section of https://adios2.readthedocs.io/en/latest/ecosystem/visualization.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request io

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants