nutils
nutils copied to clipboard
Improve VTK output file naming
The way how treelog.userfile
resolves conflicting filenames leads to problems with Paraview. I will provide more information below and I hope it's enough to understand the problems I'm facing.
How do I write output?
Usually a nutils script has the following layout:
# initialization
nutils.export.vtk(`out/solution`, ...)
for step in range(5):
# computation
nutils.export.vtk(`out/solution`, ...)
This results in the following output files:
$ ls out/
solution-1.vtk solution-2.vtk solution-3.vtk solution-4.vtk solution-5.vtk solution.vtk
I like about the current approach that I only have to provide the prefix solution
and nutils takes care of the rest. However, the way how treelog.userfile
deals with conflicting filenames is problematic (see below).
What's the problem?
- If I run the same script again the output is not overwritten, but the old output files are kept while the new output is "appended". I get
$ ls out/
solution-10.vtk solution-11.vtk solution-1.vtk solution-2.vtk solution-3.vtk solution-4.vtk solution-5.vtk solution-6.vtk solution-7.vtk solution-8.vtk solution-9.vtk solution.vtk
- The output is not working correctly with paraview, because the files
solution-*
are considered as one dataset andsolution.vtk
is ignored here:
What do I expect?
I'm working a lot with FEniCS. Here the following rules are applied, when writing output:
- when the filename
solution
is given, start withsolution-0.vtk
. I currently can get what I want, by manually renamingsolution.vtk
tosolution-0.vtk
: - override existing files. Here, I currently have to manually delete old files before running a new simulation.
Further resources:
-
Full example of nutils code that we are using + workaround for the problems described above: https://github.com/precice/tutorials/blob/5783ae56fbb10bb3ca4a5e8e9808ca248cc645b8/partitioned-heat-conduction/nutils/heat.py#L97-L166
- The workaround forces us to manually compose the filename
- Another workaround is to provide a dummy file
solution.vtk
such that the first file nutils write is notsolution.vtk
, butsolution-1.vtk
(see https://github.com/precice/tutorials/pull/153/commits/e7b445976d81b391bc3c7a8e43d2827b3ce0da6e). - Still leads to problems in paraview, if running the same case multiple times:
-
How FEniCS uses output files in a similar context:
- definition: https://github.com/precice/tutorials/blob/5783ae56fbb10bb3ca4a5e8e9808ca248cc645b8/partitioned-heat-conduction/fenics/heat.py#L157-L161
- initial data: https://github.com/precice/tutorials/blob/5783ae56fbb10bb3ca4a5e8e9808ca248cc645b8/partitioned-heat-conduction/fenics/heat.py#L166-L168
- further timesteps: https://github.com/precice/tutorials/blob/5783ae56fbb10bb3ca4a5e8e9808ca248cc645b8/partitioned-heat-conduction/fenics/heat.py#L229-L231
-
Minimal example using
treelog.userfile
: nutils-export.txt