How to open a result?

For dolfinx, the best way I’ve found is to use meshio to read the DOF arrays. e.g.

import meshio

mesh_meshio = meshio.read(xdmf_filename)
u = mesh_meshio.point_data["name"]

or

u = mesh_meshio.cell_data["name"]

for DG0 functions.

If you need to construct a dolfinx function from this, you will need to reorder the cell indices to match the dolfinx ordering.

def permute_array(array, perm_indices):
    output = array.copy()
    for i in range(len(array)):
        output[i] = array[perm_indices[i]]
    return output

CG1 = dolfinx.fem.VectorFunctionSpace(mesh, ("CG", 1))
u_dolfinx = dolfinx.fem.Function(CG1)
u_dolfinx.x.array[:] = permute_array(u, mesh.geometry.input_global_indices).flatten()

or for DG0 functions

DG0 = dolfinx.fem.VectorFunctionSpace(mesh, ("DG", 0))
u_dolfinx = dolfinx.fem.Function(DG0)
u_dolfinx.x.array[:] = permute_array(u, mesh.topology.original_cell_index).flatten()

Please note that this will only work on a single process.

1 Like