VTXWriter: support file modes#4177
Conversation
c274af4 to
1f68407
Compare
e75536c to
e350ed9
Compare
e350ed9 to
1911667
Compare
| if (mode == "a") | ||
| return adios2::Mode::Append; | ||
|
|
||
| if (mode == "w") |
| _engine->Close(); | ||
| } | ||
| //----------------------------------------------------------------------------- | ||
| adios2::Mode impl_adios2::mode(const std::string& mode) |
There was a problem hiding this comment.
Did you consider just wrapping adios2::Mode directly as an enum?
There was a problem hiding this comment.
The ADIOS2Writer operates directly on adios::Mode only the VTXWriter on the string. I understood the second as being the no longer adios2 interface specific implementation of dolfinx's interface, therefore not using the enum there.
| } | ||
|
|
||
| /// Convert string to corresponding adios2 mode. | ||
| /// @param[in] mode Mode in string representation, either "w" or "a". |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
r, w are the unix names for the operation and also what we use for the VTKFile interface.
|
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. |
I checked with the following script, which seems to correctly append to the xml contents (while currently duplicating everything though) of the VTXScheme. That should allow us to enable append mode writing in principle, right? 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))
V2 = dolfinx.fem.functionspace(mesh, ("CG", 2))
f = dolfinx.fem.Function(V)
f.x.array[:] = 1
f2 = dolfinx.fem.Function(V2)
f2.x.array[:] = 2
with dolfinx.io.VTXWriter(
comm,
"out.bp",
"w",
[f],
) as writer:
writer.write(0)
with dolfinx.io.VTXWriter(
comm,
"out.bp",
"a",
[f2],
) as writer:
writer.write(1)
from adios2 import Stream
with Stream("out.bp", "r") as s:
# steps comes from the stream
for _ in s.steps():
# track current step
print(f"Current step is {s.current_step()}")
# inspect variables in current step
# for name, info in s.available_variables().items():
# print("variable_name: " + name, end=" ")
# for key, value in info.items():
# print("\t" + key + ": " + value, end=" ")
# print()
xml = s.read_attribute("vtk.xml")
print(xml)Output: Current step is 0
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1">
<UnstructuredGrid>
<Piece NumberOfPoints="NumberOfNodes" NumberOfCells="NumberOfCells">
<Points>
<DataArray Name="geometry" />
</Points>
<Cells>
<DataArray Name="connectivity" />
<DataArray Name="types" />
</Cells>
<PointData>
<DataArray Name="TIME">step</DataArray>
<DataArray Name="vtkOriginalPointIds" />
<DataArray Name="vtkGhostType" />
<DataArray Name="f" />
</PointData>
</Piece>
</UnstructuredGrid>
</VTKFile>
Current step is 1
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1">
<UnstructuredGrid>
<Piece NumberOfPoints="NumberOfNodes" NumberOfCells="NumberOfCells">
<Points>
<DataArray Name="geometry" />
</Points>
<Cells>
<DataArray Name="connectivity" />
<DataArray Name="types" />
</Cells>
<PointData>
<DataArray Name="TIME">step</DataArray>
<DataArray Name="vtkOriginalPointIds" />
<DataArray Name="vtkGhostType" />
<DataArray Name="f" />
</PointData>
</Piece>
</UnstructuredGrid>
</VTKFile> |
|
@schnellerhase They did change how attributes work in adios2 a while ago (ornladios/ADIOS2#4471) which blurred the lines between variables and attributes, which I guess it makes it work. |
Adds support to
ADIOS2WriterandVTXWriterto open files in append mode (following interface ofVTKFile). Enabling usage such asDemonstrates the new feature, with simplified I/o logic in the naiver stokes demo.