# Save both CG and DG functions to the same file for Paraview

**URL:** <https://fenicsproject.discourse.group/t/save-both-cg-and-dg-functions-to-the-same-file-for-paraview/14702>\
**Category:** I/O\
**Tags:** io, dolfinx\
**Created:** [May 17, 2024, 8:32am UTC](https://fenicsproject.discourse.group/t/save-both-cg-and-dg-functions-to-the-same-file-for-paraview/14702 "2024-05-17T08:32:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ordinary-slim](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/ordinary-slim/32/4821_2.png) [@ordinary-slim](https://fenicsproject.discourse.group/u/ordinary-slim)\
**Post date:** [May 21, 2024, 8:59am UTC](https://fenicsproject.discourse.group/t/save-both-cg-and-dg-functions-to-the-same-file-for-paraview/14702/2 "2024-05-21T08:59:45Z")

</div>

VTKFile and XDMFFile can save both DG and CG functions. VTXWriter can save CG functions. In the main branch, VTXWriter can also save DG functions but not together with CG functions yet.

You can find some examples here in this post:

> [@How to write binary data with VTK/XDMFFile?](https://fenicsproject.discourse.group/t/how-to-write-binary-data-with-vtk-xdmffile/14095/5):
>
> About this, XDMF is a bit buggy when you write multiple functions. I reported this in [this issue](https://github.com/FEniCS/dolfinx/issues/3026). Not only it duplicates the data so that it occupies more memory, the coloring of a dataset can be “hidden” by the other one somehow. See the MWE below: from dolfinx import mesh, io, fem from mpi4py import MPI nels\_per\_side = 2 mesh = mesh.create\_unit\_square(MPI.COMM\_WORLD, nels\_per\_side, nels\_per\_side, mesh.CellType.quadrilateral) V = fem.functionspace(mesh, ("Lagrange", 1)) D = fem.functionspa…

When visualizing with Paraview, you should use `Xdmf3_Reader_T` for XDMF

---

_[View the full topic](https://fenicsproject.discourse.group/t/save-both-cg-and-dg-functions-to-the-same-file-for-paraview/14702)._
