flac index fix
@@ -385,33 +385,23 @@ def split_f_z(mesh):
if not all(item is None for item in value)
}
- return zcells, fcells, zsets, fsets
-
-
-def write(filename, mesh: Mesh, float_fmt: str = ".16e", binary: bool = False):
- """Write FLAC3D f3grid grid file."""
- skip = [c.type for c in mesh.cells if c.type not in meshio_only["zone"]]
- if skip:
- warn(f'FLAC3D format only supports 3D cells. Skipping {", ".join(skip)}.')
-
- # split into face/zone data
- zcells, fcells, zsets, fsets = split_f_z(mesh)
+ # Right now, the zsets contain indices into the corresponding cell block.
+ # FLAC3D expects _global_ indices. Update.
+ cell_block_sizes = [len(cb) for cb in zcells]
+ for key, data in zsets.items():
+ gid = 0
+ for n, block in zip(cell_block_sizes, data):
+ block += gid
+ gid += n
+
+ # TODO not sure if fcells and zcells share a common global index
+ cell_block_sizes = [len(cb) for cb in fcells]
+ for key, data in fsets.items():
+ gid = 0
+ for n, block in zip(cell_block_sizes, data):
+ block += gid
+ gid += n
- # elif mesh.cell_data:
- # print(mesh)
- # # TODO convert cell_data to cell_sets
- # exit(1)
- # key, other = _pick_first_int_data(mesh.cell_data)
- # if key:
- # materials = np.concatenate(mesh.cell_data[key])
- # if other:
- # warn(
- # "FLAC3D can only write one cell data array. "
- # f'Picking {key}, skipping {", ".join(other)}.'
- # )
-
- # Translate the material array from meshio.cell_set data to a
- # dictionary with labels as keys.
for label, values in zsets.items():
zsets[label] = np.concatenate(values)
for label, values in fsets.items():
@@ -423,6 +413,18 @@ def write(filename, mesh: Mesh, float_fmt: str = ".16e", binary: bool = False):
for label, values in fsets.items():
fsets[label] += 1
+ return zcells, fcells, zsets, fsets
+
+
+def write(filename, mesh: Mesh, float_fmt: str = ".16e", binary: bool = False):
+ """Write FLAC3D f3grid grid file."""
+ skip = [c.type for c in mesh.cells if c.type not in meshio_only["zone"]]
+ if skip:
+ warn(f'FLAC3D format only supports 3D cells. Skipping {", ".join(skip)}.')
+
+ # split into face/zone data
+ zcells, fcells, zsets, fsets = split_f_z(mesh)
+
mode = "wb" if binary else "w"
with open_file(filename, mode) as f:
if binary:
