This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Storing current time in VTK file

+1 vote

To output a function's value to a VTK file, I do the following

ofile = File("u.pvd")
ofile << u

With XDMF files, I have the option to output the time value of that specific timestep

ofile = XDMFFile("u.xdmf")
ofile.write(u, t)

When I try the same with VTK output, I observe that the time value is not there

ofile = File("u.pvd")
ofile << u, t

Hence I see the timestep count, not the time value when postprocessing the files in ParaView. The << operator accepts another float as a second parameter, but strangely does not wrap it in a field in the .vtu files.

The file u.pvd:

<?xml version="1.0"?>
<VTKFile type="Collection" version="0.1">
  <Collection>
    <DataSet timestep="0" part="0" file="u000000.vtu" />
    <DataSet timestep="1" part="0" file="u000001.vtu" />
    <DataSet timestep="2" part="0" file="u000002.vtu" />
    ...
  </Collection>
</VTKFile>

The file u000000.vtu

<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid"  version="0.1"  >
<UnstructuredGrid>
<Piece  NumberOfPoints="1089" NumberOfCells="2048">
<Points>
<DataArray  type="Float64"  NumberOfComponents="3"  format="ascii"> ...  </DataArray>
</Points>
<Cells>
<DataArray  type="UInt32"  Name="connectivity"  format="ascii"> ...  </DataArray>
<DataArray  type="UInt32"  Name="offsets"  format="ascii"> ... </DataArray>
<DataArray  type="UInt8"  Name="types"  format="ascii"> ... </DataArray>
</Cells>
<PointData  Scalars="u"> 
<DataArray  type="Float64"  Name="u"  format="ascii"> ... </DataArray>
</PointData> 
</Piece>
</UnstructuredGrid>
</VTKFile>

The time field is nowhere to be seen, contrary to what is expected. How can I make it so that the time value is output to the VTK files?

asked Apr 11, 2017 by hosolmaz FEniCS User (1,510 points)

2 Answers

+3 votes
 
Best answer

This should do it

ofile << (u, t)
answered Apr 12, 2017 by KristianE FEniCS Expert (12,900 points)
selected Apr 12, 2017 by hosolmaz
0 votes

Consider the following

ofile << (u, t)

(the function and time wrapped with round brackets). This works for me.

answered Apr 11, 2017 by mhabera FEniCS User (1,890 points)
...