MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / plot_streamlines

Function plot_streamlines

python/demo/demo_pyvista.py:312–348  ·  view source on GitHub ↗

Plot streamlines of a vector field in 3D.

()

Source from the content-addressed store, hash-verified

310
311
312def plot_streamlines():
313 """Plot streamlines of a vector field in 3D."""
314 msh = create_unit_cube(MPI.COMM_WORLD, 4, 4, 4, CellType.hexahedron, dtype=np.float64)
315 gdim = msh.geometry.dim
316 V = functionspace(msh, ("Discontinuous Lagrange", 2, (gdim,)))
317 u = Function(V, dtype=np.float64)
318 u.interpolate(lambda x: np.vstack((-(x[1] - 0.5), x[0] - 0.5, np.zeros(x.shape[1]))))
319
320 cells, types, x = plot.vtk_mesh(V)
321 num_dofs = x.shape[0]
322 values = np.zeros((num_dofs, 3), dtype=np.float64)
323 values[:, :gdim] = u.x.array.reshape(num_dofs, V.dofmap.index_map_bs)
324
325 # Create a point cloud of glyphs
326 grid = pyvista.UnstructuredGrid(cells, types, x)
327 grid["vectors"] = values
328 grid.set_active_vectors("vectors")
329 glyphs = grid.glyph(orient="vectors", factor=0.1)
330 streamlines = grid.streamlines(
331 vectors="vectors", return_source=False, source_radius=1, n_points=150
332 )
333
334 # Create Create plotter
335 plotter = pyvista.Plotter()
336 plotter.add_text("Streamlines.", position="upper_edge", font_size=20, color="black")
337 plotter.add_mesh(grid, style="wireframe")
338 plotter.add_mesh(glyphs)
339 plotter.add_mesh(streamlines.tube(radius=0.001))
340 plotter.view_xy()
341 if pyvista.OFF_SCREEN:
342 plotter.screenshot(
343 out_folder / f"streamlines_{MPI.COMM_WORLD.rank}.png",
344 transparent_background=transparent,
345 window_size=[figsize, figsize],
346 )
347 else:
348 plotter.show()
349
350
351plot_scalar()

Callers 1

demo_pyvista.pyFile · 0.85

Calls 5

interpolateMethod · 0.95
create_unit_cubeFunction · 0.90
functionspaceFunction · 0.90
FunctionClass · 0.90
add_meshMethod · 0.80

Tested by

no test coverage detected