jorgensd / adios4dolfinx

Extending DOLFINx with checkpointing functionality
http://jsdokken.com/adios4dolfinx/
MIT License
20 stars 7 forks source link

Global cells in legacy files #23

Open finsberg opened 1 year ago

finsberg commented 1 year ago

In legacy dolfin, each function where stored with a cells group. I suspect this has something to do with the partition used when saving the file, but currently this information is not used in adios4dolfinx.

Here is a function for reading the global cells.

def read_global_cells(filename: pathlib.Path, group: str):

    adios = adios2.ADIOS(MPI.COMM_WORLD)
    io = adios.DeclareIO("Cells reader")
    io.SetEngine("HDF5")

    # Open ADIOS2 Reader
    infile = io.Open(str(filename), adios2.Mode.Read)
    cells = io.InquireVariable(f"/{group}/cells")
    num_cells_global = cells.Shape()[0]
    cells.SetSelection([[0], [num_cells_global]])

    global_cells = np.empty(num_cells_global, dtype=cells.Type().strip("_t"))
    infile.Get(cells, global_cells, adios2.Mode.Sync)
    infile.Close()
    assert adios.RemoveIO("Cells reader")
    return global_cells.astype(np.int64)