Quick question on using VTKFile

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

# 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

   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.

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?

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

     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).

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