Skip to content

Commit

Permalink
Merge pull request #1291 from nschloe/flac-fix2
Browse files Browse the repository at this point in the history
various flac fixes
  • Loading branch information
nschloe authored Feb 24, 2022
2 parents 7f41c04 + 60f0e54 commit 3510aea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = meshio
version = 5.3.1
version = 5.3.2
author = Nico Schlömer et al.
author_email = nico.schloemer@gmail.com
description = I/O for many mesh formats
Expand Down
50 changes: 28 additions & 22 deletions src/meshio/flac3d/_flac3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,34 @@ def split_f_z(mesh):
if not all(item is None for item in value)
}

# 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

for label, values in zsets.items():
zsets[label] = np.concatenate(values)
for label, values in fsets.items():
fsets[label] = np.concatenate(values)

# flac3d indices start at 1
for label, values in zsets.items():
zsets[label] += 1
for label, values in fsets.items():
fsets[label] += 1

return zcells, fcells, zsets, fsets


Expand All @@ -397,28 +425,6 @@ def write(filename, mesh: Mesh, float_fmt: str = ".16e", binary: bool = False):
# split into face/zone data
zcells, fcells, zsets, fsets = split_f_z(mesh)

# 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.
if zsets is not None:
for label, values in zsets.items():
zsets[label] = np.concatenate(values)
if fsets is not None:
for label, values in fsets.items():
fsets[label] = np.concatenate(values)

mode = "wb" if binary else "w"
with open_file(filename, mode) as f:
if binary:
Expand Down

0 comments on commit 3510aea

Please sign in to comment.