# XDMF - writing DG space. (ver 0.10)

**URL:** <https://fenicsproject.discourse.group/t/xdmf-writing-dg-space-ver-0-10/18404>\
**Category:** I/O\
**Created:** [November 21, 2025, 3:32pm UTC](https://fenicsproject.discourse.group/t/xdmf-writing-dg-space-ver-0-10/18404 "2025-11-21T15:32:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![acino](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@acino](https://fenicsproject.discourse.group/u/acino)\
**Post date:** [November 21, 2025, 3:32pm UTC](https://fenicsproject.discourse.group/t/xdmf-writing-dg-space-ver-0-10/18404/1 "2025-11-21T15:32:37Z")

</div>

All, I’m migrating my code from version 0.8 to version 0.10.  
I noticed I cannot write out a XDMF file for DG function anymore.

Here is the source code I’m testing.

```auto
auto mesh = std::make_shared<mesh::Mesh<double>>(mesh::create_box<double>(
    MPI_COMM_WORLD, {{{0.0, 0.0, 0.0}, {1.0, 1.0, 1.0}}}, {10, 10, 10},
    mesh::CellType::hexahedron,
    mesh::create_cell_partitioner(mesh::GhostMode::none)));

  constexpr basix::cell::type basix_cell = basix::cell::type::hexahedron;
  constexpr std::size_t degree = 1;
  constexpr std::size_t gdim = 3;

auto element_discontinuous = basix::create_element<double>(
    basix::element::family::P, basix_cell, degree,
    basix::element::lagrange_variant::unset,
    basix::element::dpc_variant::unset, true);

auto S = std::make_shared<fem::FunctionSpace<double>>(
    fem::create_functionspace<double>(
        mesh, std::make_shared<fem::FiniteElement<double>>(
              element_discontinuous, std::vector<std::size_t>{6, })));
auto stress = std::make_shared<fem::Function<T>>(S);
std::span<T> _stress = stress->x()->array();
std::fill(_stress.begin(), _stress.end(), 1.2345);

// Write to XDMF file

dolfinx::io::XDMFFile xdmf_file(mesh->comm(), "./test_xdmf_output.xdmf", "w");
xdmf_file.write_mesh(*mesh);
xdmf_file.write_function(*stress, 0.0);

```

This is the exception I get:

```auto
  Function and Mesh dof layouts do not match. Maybe the Function needs to be
  interpolated?

```

Can you help?

---

<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:** [November 21, 2025, 3:58pm UTC](https://fenicsproject.discourse.group/t/xdmf-writing-dg-space-ver-0-10/18404/2 "2025-11-21T15:58:48Z")

</div>

DG function(except DG-0) have not been possible to write to XDMF for a long time (longer than since 0.8).

If you set `degree=0` it should work.  
If you want to use higher order DG output, use either `VTXWriter` or `VTKFile`.
