def to_meshio(mesh, point_data=None, cell_data=None, encode_cell_data=True, encode_point_data=False):
    t = mesh.dofs.element_dofs.copy()
    if isinstance(mesh, skfem.MeshHex2):
        t = t[HEX_MAPPING]
    elif isinstance(mesh, skfem.MeshHex):
        t = t[HEX_MAPPING[:8]]
    mtype = TYPE_MESH_MAPPING[type(mesh)]
    cells = {mtype: t.T}
    if encode_cell_data:
        if (cell_data is None):
            cell_data = {}
        cell_data.update(mesh._encode_cell_data())
    if encode_point_data:
        if (point_data is None):
            point_data = {}
        point_data.update(mesh._encode_point_data())
    mio = meshio.Mesh(mesh.p.T, cells, point_data=point_data, cell_data=cell_data)
    return mio
def to_meshio(mesh, point_data=None, cell_data=None, encode_cell_data=True, encode_point_data=False):
    t = mesh.dofs.element_dofs.copy()
    if isinstance(mesh, skfem.MeshHex2):
        t = t[HEX_MAPPING]
    elif isinstance(mesh, skfem.MeshHex):
        t = t[HEX_MAPPING[:8]]
    mtype = TYPE_MESH_MAPPING[type(mesh)]
    cells = {mtype: t.T}
    if encode_cell_data:
        if (cell_data is None):
            cell_data = {}
        cell_data.update(mesh._encode_cell_data())
    if encode_point_data:
        if (point_data is None):
            point_data = {}
        point_data.update(mesh._encode_point_data())
    mio = meshio.Mesh(mesh.p.T, cells, point_data=point_data, cell_data=cell_data)
    return mio