Skip to content

Instantly share code, notes, and snippets.

@shkiefer
Last active January 2, 2022 01:01
Show Gist options
  • Save shkiefer/56a77c61b46030b53dafed90fc5102ff to your computer and use it in GitHub Desktop.
Save shkiefer/56a77c61b46030b53dafed90fc5102ff to your computer and use it in GitHub Desktop.
def get_grid_with_field(meshed_region, field):
name = '_'.join(field.name.split("_")[:-1])
location = field.location
if location == dpf.locations.nodal:
mesh_location = meshed_region.nodes
elif location == dpf.locations.elemental:
mesh_location = meshed_region.elements
else:
raise ValueError(
"Only elemental or nodal location are supported for plotting."
)
overall_data = np.full(len(mesh_location), np.nan)
ind, mask = mesh_location.map_scoping(field.scoping)
overall_data[ind] = field.data[mask]
grid = meshed_region.grid
if location == dpf.locations.nodal:
grid.point_data[name] = overall_data
elif location == dpf.locations.elemental:
grid.cell_data[name] = overall_data
return grid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment