ngsPETSc.utils.firedrake_webgui
Firedrake mesh/function visualization via webgui jupyter widgets.
- Supports:
2D triangular and 3D tetrahedral meshes.
Scalar and vector function spaces (Lagrange/CG, DG, RT, Nedelec, …).
High polynomial orders (sub-triangulation level controllable via
subdivision; defaults to the source element degree, capped at 10).Live updates via
FiredrakeScene.Redraw()for time-dependent simulations andipywidgets()-driven parameter sliders.
Attributes
Classes
A webgui scene for a Firedrake mesh or function. |
Functions
|
|
|
|
|
|
|
Resample a ParaView-style stop list into |
|
|
|
Return the function's value shape via UFL on the bound domain. |
Uniform lattice on UFC reference triangle. |
|
|
Map 2D reference triangle points to a face of the UFC tet. |
|
Return a sample-able function and its value rank. |
|
FIAT-tabulate basis (order 0) of a Function/Coordinate at ref_pts. |
|
Evaluate |
|
Evaluate |
|
Force CCW winding so normals point +z. |
|
Flatten per-cell, per-vertex function values to (nverts,) or (nverts, vdim). |
|
|
|
Build vertex / triangle / value arrays for a 2D mesh. |
|
Sub-segmented boundary of a 2D mesh, indexing into the per-cell lattice. |
|
Build per-facet sub-triangulated boundary of a 3D tet mesh. |
|
Geometry edges between boundary regions with different markers, |
|
|
|
Pick a sensible sub-triangulation level. |
|
Draw a Firedrake Mesh or Function in Jupyter. |
Module Contents
- ngsPETSc.utils.firedrake_webgui._POINTEVAL_FAMILIES = ('Lagrange', 'Continuous Lagrange', 'CG', 'Discontinuous Lagrange', 'DG', 'DQ', 'Q', 'DPC')
- ngsPETSc.utils.firedrake_webgui._MAX_SUBDIVISION = 10
- ngsPETSc.utils.firedrake_webgui._MANA_STOPS = [(0.0, (0.098039, 0.137255, 0.352941)), (0.03125, (0.207283, 0.138936, 0.373669)), (0.0625,...
- ngsPETSc.utils.firedrake_webgui._NAMED_COLORMAPS
- ngsPETSc.utils.firedrake_webgui._DEFAULT_COLORMAP = 'mana'
- ngsPETSc.utils.firedrake_webgui._COLORMAP_RESOLUTION = 256
- ngsPETSc.utils.firedrake_webgui._make_trig(N, x0=0, y0=0, dx=1, dy=1)
- ngsPETSc.utils.firedrake_webgui._make_quad(N, x0=0, y0=0, dx=1, dy=1)
- ngsPETSc.utils.firedrake_webgui._intrules
- ngsPETSc.utils.firedrake_webgui.get_intrules(dim: int, order: int)
- ngsPETSc.utils.firedrake_webgui._sample_colormap(spec, n=_COLORMAP_RESOLUTION)
Resample a ParaView-style stop list into
nRGB triples.specmay be:None— use webgui’s default colormap (returnsNone);a string naming an entry in
_NAMED_COLORMAPS;a list of
(t, (r, g, b))tuples withtin[0, 1];an
(N, 3)array of RGB rows assumed to span[0, 1]evenly.
- ngsPETSc.utils.firedrake_webgui._get_mesh_and_func(obj, order)
- ngsPETSc.utils.firedrake_webgui._value_shape(func_or_space)
Return the function’s value shape via UFL on the bound domain.
- ngsPETSc.utils.firedrake_webgui._ref_lattice_tri(n)
Uniform lattice on UFC reference triangle.
Returns
(pts, tris)withptsof shape(npts, 2)andtrisof shape(ntris, 3). Sub-triangles are CCW so their normals point in +z.
- ngsPETSc.utils.firedrake_webgui._UFC_TET_VERTS
- ngsPETSc.utils.firedrake_webgui._UFC_TET_FACET_VERTS = ((1, 2, 3), (0, 2, 3), (0, 1, 3), (0, 1, 2))
- ngsPETSc.utils.firedrake_webgui._facet_ref_pts_3d(local_facet, ref_pts_2d)
Map 2D reference triangle points to a face of the UFC tet.
ref_pts_2dare (s, t) coordinates with s, t >= 0, s + t <= 1. Returns 3D ref-tet coordinates of shape(npts, 3).
- ngsPETSc.utils.firedrake_webgui._interp_for_vis(func, mesh, n)
Return a sample-able function and its value rank.
For Lagrange / DG-style spaces the original
funcis returned. Non-pointwise families (RT, Nedelec, BDM, …) are interpolated into a discontinuous DG_n / vector-DG_n space so that any genuine cross-cell discontinuity in the field — only the normal/tangential trace of an H(div)/H(curl) field is continuous — is preserved by the renderer.
- ngsPETSc.utils.firedrake_webgui._tabulate(func_or_coords, ref_pts)
FIAT-tabulate basis (order 0) of a Function/Coordinate at ref_pts.
Returns the basis array. Scalar element shape is
(ndof, npts); vector element shape is(ndof, vdim, npts).
- ngsPETSc.utils.firedrake_webgui._per_cell_eval(func, ref_pts)
Evaluate
funcat reference points within every cell.Returns array of shape
(ncells, npts)for scalar or(ncells, npts, vdim)for vector functions.
- ngsPETSc.utils.firedrake_webgui._per_cell_coords(mesh, ref_pts)
Evaluate
mesh.coordinatesat reference points per cell.
- ngsPETSc.utils.firedrake_webgui._orient_tris_2d(verts, tris)
Force CCW winding so normals point +z.
- ngsPETSc.utils.firedrake_webgui._flatten_funcvals(vals)
Flatten per-cell, per-vertex function values to (nverts,) or (nverts, vdim).
- ngsPETSc.utils.firedrake_webgui._build_2d_wireframe(data, mesh, func, n, encoding)
- ngsPETSc.utils.firedrake_webgui._build_2d(data, mesh, func, n, encoding)
Build vertex / triangle / value arrays for a 2D mesh.
- ngsPETSc.utils.firedrake_webgui._build_2d_boundary_segments(mesh, n, npts, encoding)
Sub-segmented boundary of a 2D mesh, indexing into the per-cell lattice.
- ngsPETSc.utils.firedrake_webgui._build_3d_boundary(mesh, func, n, encoding)
Build per-facet sub-triangulated boundary of a 3D tet mesh.
- ngsPETSc.utils.firedrake_webgui._build_3d_boundary_edges(mesh, ef, parent_verts, local_facets, n, npts, encoding)
Geometry edges between boundary regions with different markers, sub-divided into the per-facet lattice index space.
- ngsPETSc.utils.firedrake_webgui._func_minmax(func)
- ngsPETSc.utils.firedrake_webgui._default_subdivision(func, mesh)
Pick a sensible sub-triangulation level.
- class ngsPETSc.utils.firedrake_webgui.FiredrakeScene(obj, mesh=None, subdivision=None, colormap=_DEFAULT_COLORMAP, order=1, **kwargs)
Bases:
webgui_jupyter_widgets.BaseWebGuiSceneA webgui scene for a Firedrake mesh or function.
Parameters
- objfiredrake.MeshGeometry or firedrake.Function
Object to visualise.
- meshfiredrake.MeshGeometry, optional
Override mesh (when
objis a function but you want to show it on a different mesh).- subdivisionint, optional
Sub-triangles per element edge. Defaults to the source element degree, capped at 10.
- colormapstr, list, ndarray, or None, optional
Colour map used by the on-screen colour bar. Strings select a built-in (
"mana"(default),"cool_to_warm","ngs"); a stop list[(t, (r, g, b)), ...]or an(N, 3)RGB array is also accepted. PassNoneto fall back to webgui’s default rainbow (equivalent to"ngs").
- obj
- _mesh_override = None
- subdivision = None
- colormap = 'mana'
- kwargs
- encoding = 'b64'
- order = 1
- GetData(set_minmax=True)
- Redraw(obj=None)
Push fresh data to an already-displayed widget.
Pass
objto swap to a different Function/Mesh (useful for slider callbacks) or call without args to re-encode the current object after itsdathas been mutated in place (the time-stepping pattern).
- ngsPETSc.utils.firedrake_webgui.Draw(obj, mesh=None, subdivision=None, colormap=_DEFAULT_COLORMAP, order=1, **kwargs)
Draw a Firedrake Mesh or Function in Jupyter.