# Quick question on using VTKFile

**URL:** <https://fenicsproject.discourse.group/t/quick-question-on-using-vtkfile/10244>\
**Category:** General\
**Created:** [January 24, 2023, 1:16pm UTC](https://fenicsproject.discourse.group/t/quick-question-on-using-vtkfile/10244 "2023-01-24T13:16:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BillS](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BillS](https://fenicsproject.discourse.group/u/BillS)\
**Post date:** [January 24, 2023, 1:16pm UTC](https://fenicsproject.discourse.group/t/quick-question-on-using-vtkfile/10244/1 "2023-01-24T13:16:38Z")

</div>

From my experience and from some of the posts on this forum, XDMF does not work well for plotting functions in the H(curl) or DG spaces. I see all kinds of strange artifacts. I found numerous references on writing data files for single plots, but I would like to plot a time-series animation of a vector function. The equivalent XDMF implementation is

```auto
# Print out time steps
   Et.name = "AnimEfield"
   with io.XDMFFile(mesh.comm, "Movie.xdmf", "w") as xx:
       xx.write_mesh(mesh)
       for t1 in range(50):
          Et.interpolate(E)
          Et.vector.array = Et.vector.array * np.exp(1j * np.pi * t1 /25.0)
          xx.write_function(Et, t1)

```

where t1 is the time variable and Et is the vector field solution.

I tried to do something like this

```auto
   with io.VTKFile(mesh.comm, "Movie.pvd", "w") as xx:
       xx.write_mesh(mesh)
       for t1 in range(50):
         Et.interpolate(E)
         Et.vector.array = Et.vector.array * np.exp(1j * np.pi * t1 /25.0)
          xx.write_function([Et._cpp_object, t1])

```

and the program died with an error.

```auto
Invoked with: <dolfinx.io.utils.VTKFile object at 0x7ff1952e33d0>, [<dolfinx.cpp.fem.Function_complex128 object at 0x7ff195cfc570>, 0], 0.0
Traceback (most recent call last):
  File "/home/bill/Cluster/Fenics2020/CavityBackedBowtieAntenna/Antenna1.py", line 255, in <module>
    res = Model(xin)
  File "/home/bill/Cluster/Fenics2020/CavityBackedBowtieAntenna/Antenna1.py", line 245, in Model
    xx.write_function([Et._cpp_object, t1])
  File "/usr/lib/petscdir/petsc3.15/x86_64-linux-gnu-complex/lib/python3/dist-packages/dolfinx/io/utils.py", line 135, in write_function
    super().write(_extract_cpp_functions(u), t)
TypeError: write(): incompatible function arguments. The following argument types are supported:
    1. (self: dolfinx.cpp.io.VTKFile, u: List[dolfinx.cpp.fem.Function_float64], t: float = 0.0) -> None
    2. (self: dolfinx.cpp.io.VTKFile, u: List[dolfinx.cpp.fem.Function_complex128], t: float = 0.0) -> None
    3. (self: dolfinx.cpp.io.VTKFile, mesh: dolfinx.cpp.mesh.Mesh, t: float = 0.0) -> None

```

How should I present the vector-time paired data?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [January 24, 2023, 1:24pm UTC](https://fenicsproject.discourse.group/t/quick-question-on-using-vtkfile/10244/2 "2023-01-24T13:24:02Z")

</div>

If you look at the input types to the function, you should be able to spot that the correct input type is:

```python
     xx.write_function([Et], t1)

```

In general, I would recommend interpolating into a DG space compatible with the H-curl space, and use `VTXWriter` (which generates a `.bp` folder, compatible with Paraview’s VTXReader).

---

<div class="post-metadata">

**Author:** ![BillS](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BillS](https://fenicsproject.discourse.group/u/BillS)\
**Post date:** [February 22, 2023, 10:15am UTC](https://fenicsproject.discourse.group/t/quick-question-on-using-vtkfile/10244/3 "2023-02-22T10:15:19Z")

</div>

Hi Dokken. Sorry for the late reply. Yes, now everything works as it should. Thanks!
