XDMF - writing DG space. (ver 0.10)

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 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:

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

Can you help?

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.

1 Like