{ "cells": [ { "cell_type": "markdown", "id": "qs-intro", "metadata": {}, "source": [ "# Quickstart\n", "\n", "`ngsolve_webgpu.jupyter.Draw` is the high-level entry point. It mirrors the NGSolve webgui `Draw` and dispatches on the type of its first argument:\n", "\n", "* a `Mesh` → renders surface elements + wireframe\n", "* a `CoefficientFunction` (with a `Mesh`) → renders coloured field with colormap and colorbar\n", "* an OCC `OCCGeometry` / `TopoDS_Shape` → renders the geometry with face/edge colours\n", "\n", "Every canvas below is **fully interactive** — drag to rotate, shift-drag to pan, scroll to zoom, and use the GUI panel in the top-right corner." ] }, { "cell_type": "markdown", "id": "qs-mesh-md", "metadata": {}, "source": [ "## A 3D mesh" ] }, { "cell_type": "code", "execution_count": null, "id": "qs-mesh", "metadata": {}, "outputs": [], "source": [ "from ngsolve import *\n", "from ngsolve_webgpu.jupyter import Draw\n", "\n", "mesh = Mesh(unit_cube.GenerateMesh(maxh=0.25))\n", "Draw(mesh)" ] }, { "cell_type": "markdown", "id": "qs-cf-md", "metadata": {}, "source": [ "## A coefficient function on a 2D mesh\n", "\n", "The `order` keyword controls the per-element subdivision used to render high-order data." ] }, { "cell_type": "code", "execution_count": null, "id": "qs-cf", "metadata": {}, "outputs": [], "source": [ "mesh = Mesh(unit_square.GenerateMesh(maxh=0.15))\n", "Draw(sin(10 * x) * cos(8 * y), mesh, order=4)" ] }, { "cell_type": "markdown", "id": "qs-deform-md", "metadata": {}, "source": [ "## Deformation\n", "\n", "The `deformation` keyword applies a vector-valued CF as a per-vertex displacement — handy to lift a 2D scalar field into 3D or to visualise an elasticity solution." ] }, { "cell_type": "code", "execution_count": null, "id": "qs-deform", "metadata": {}, "outputs": [], "source": [ "mesh = Mesh(unit_square.GenerateMesh(maxh=0.15))\n", "f = sin(10 * x) * cos(8 * y)\n", "deformation = CF((0, 0, 0.1 * f))\n", "Draw(f, mesh, deformation=deformation, order=4)" ] }, { "cell_type": "markdown", "id": "qs-clip-md", "metadata": {}, "source": [ "## Clipping a 3D field\n", "\n", "For 3D meshes `Draw` automatically wires up a clipping-plane GUI. Pass `clipping=True` to enable it on load, or a dict to set the initial normal/centre." ] }, { "cell_type": "code", "execution_count": null, "id": "qs-clip", "metadata": {}, "outputs": [], "source": [ "mesh = Mesh(unit_cube.GenerateMesh(maxh=0.2))\n", "Draw(sin(8 * x) * sin(8 * y) * sin(8 * z), mesh, order=3,\n", " clipping={\"nx\": 1, \"ny\": 0, \"nz\": 0})" ] }, { "cell_type": "markdown", "id": "qs-args", "metadata": {}, "source": [ "## Common keyword arguments\n", "\n", "| Argument | Effect |\n", "|---|---|\n", "| `order` | Per-element subdivision for the CF renderer (default 2). |\n", "| `deformation` | Vector CF applied as a displacement to mesh vertices. |\n", "| `clipping` | `True`/`False` or a dict `{enabled, nx, ny, nz, x, y, z}`. |\n", "| `vectors` | `True` or option dict — overlays a vector-glyph layer (2D only). |\n", "| `width`, `height` | Canvas size in CSS pixels. |\n", "| `subdivision` | Override the mesh subdivision used during sampling. |\n", "\n", "`Draw` returns a `Scene` object; its `.gui` attribute lets you append custom controls (sliders, checkboxes), and `.redraw()` re-renders after Python-side changes (parameter updates, GridFunction edits). The remaining sections show how to compose your own scenes from the individual renderer classes when `Draw` isn't enough." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.5" } }, "nbformat": 4, "nbformat_minor": 5 }