Skip to content

Commit

Permalink
fix: fixed an issue with quick_plot using unstructured meshes (#127)
Browse files Browse the repository at this point in the history
* check if unstructured mesh has only triangular faces

* update changelog [skip ci]
  • Loading branch information
mcflugen authored Oct 20, 2020
1 parent 47f7e85 commit d3e5723
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog for pymt
1.2.2 (unreleased)
------------------

- Nothing changed yet.
- Fixed an issue in quick_plot when trying to plot unstructured meshes (#127)


1.2.1 (2020-09-22)
Expand Down
17 changes: 11 additions & 6 deletions pymt/framework/bmi_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@ def quick_plot(bmi, name, **kwds):
gtype = bmi.grid_type(gid)
grid = bmi.grid[gid]

x, y = grid.node_x.values, grid.node_y.values
z = bmi.get_value(name)

x_label = "{name} ({units})".format(
name=grid.node_x.standard_name, units=grid.node_x.units
)
y_label = "{name} ({units})".format(
name=grid.node_y.standard_name, units=grid.node_y.units
)

if gtype in ("unstructured_triangular",):
tris = bmi.grid_face_node_connectivity(gid).reshape((-1, 3))
plt.tripcolor(x, y, tris, z, **kwds)
z = bmi.get_value(name)

if gtype.startswith("unstructured"):
x, y = grid.node_x.values, grid.node_y.values
nodes_per_face = bmi.grid_nodes_per_face(gid)
if np.all(nodes_per_face == 3):
tris = bmi.grid_face_nodes(gid).reshape((-1, 3))
# tris = bmi.grid_face_node_connectivity(gid).reshape((-1, 3))
plt.tripcolor(x, y, tris, z, **kwds)
else:
raise ValueError("quickplot is only able to plot unstructured meshes of triangles")
elif gtype in ("uniform_rectilinear", "structured_quad"):
shape = bmi.grid_shape(gid)
spacing = bmi.grid_spacing(gid)
Expand Down

0 comments on commit d3e5723

Please sign in to comment.