festim-dev / festim-dev/FESTIM

Basic functionality for plotting fields with pyvista

Open
#1,175 0 comments 1 reaction 2 assignees Claimed by @RemDelaporteMathurin View on GitHub
Dominant language
Python
Stars
135
Forks
45
Avg merge
3d 23h
Merged PRs (30d)
14

Description

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

Proposed usage:

```python
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)

```python
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.