Skip to content

Basic functionality for plotting fields with pyvista #1175

Description

@RemDelaporteMathurin

It would be useful to provide a way to plot fields very quickly (one liner) with pyvista

Proposed usage:

H = F.Species("H")

F.plot(H)  # default

F.plot(H, subdomain=top)  # only one subdomain if multi-material

F.plot([H, D])   # automatically makes two subplots for each species?

F.plot(H, filename="out.png")  # optionally save to file

F.plot(H, show_edges=True)  # shortcut for most common options

Mostly it would be a wrapper for this pyvista code (which can be a bit cumbersome)

def make_ugrid(solution):
    topology, cell_types, geometry = plot.vtk_mesh(solution.function_space)
    u_grid = pyvista.UnstructuredGrid(topology, cell_types, geometry)
    u_grid.point_data["c"] = solution.x.array.real
    u_grid.set_active_scalars("c")
    return u_grid


u_plotter = pyvista.Plotter()

# fun = A.post_processing_solution
fun = A.subdomain_to_post_processing_solution[vol1]
u_grid_left = make_ugrid(fun)
u_plotter.add_mesh(u_grid_left, show_edges=True)

fun = A.subdomain_to_post_processing_solution[vol2]
u_grid_right = make_ugrid(fun)
u_plotter.add_mesh(u_grid_right, show_edges=True)
u_plotter.view_xy()
u_plotter.add_text("Hydrogen concentration in multi-material problem", font_size=12)

if not pyvista.OFF_SCREEN:
    u_plotter.show()
else:
    figure = u_plotter.screenshot("concentration.png")

@jhdark what do you think?

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions