{ "cells": [ { "cell_type": "markdown", "id": "a1", "metadata": {}, "source": [ "# Vector Fields\n", "\n", "Vector-valued CoefficientFunctions can be visualized as arrow glyphs on surfaces, clipping planes, or as field lines." ] }, { "cell_type": "markdown", "id": "a2", "metadata": {}, "source": [ "## Surface Vectors\n", "\n", "Arrows on the boundary surface of a 3D mesh:" ] }, { "cell_type": "code", "execution_count": null, "id": "a3", "metadata": {}, "outputs": [], "source": [ "from ngsolve import *\n", "from ngsolve_webgpu import *\n", "from webgpu.jupyter import Draw\n", "\n", "mesh = Mesh(unit_cube.GenerateMesh(maxh=0.2))\n", "cf = CF((x, y, 1))\n", "md = MeshData(mesh)\n", "fd = FunctionData(md, cf, order=1)\n", "vecs = SurfaceVectors(fd)\n", "Draw(vecs)" ] }, { "cell_type": "markdown", "id": "a4", "metadata": {}, "source": [ "`SurfaceVectors` samples the vector field on surface elements and renders 3D arrows. `grid_size` controls the density of arrows (default 20)." ] }, { "cell_type": "markdown", "id": "a5", "metadata": {}, "source": [ "## Clipping Vectors\n", "\n", "Arrows on a clipping plane through the volume:" ] }, { "cell_type": "code", "execution_count": null, "id": "a6", "metadata": {}, "outputs": [], "source": [ "from ngsolve import *\n", "from ngsolve_webgpu import *\n", "from webgpu.clipping import Clipping\n", "from webgpu.jupyter import Draw\n", "\n", "mesh = Mesh(unit_cube.GenerateMesh(maxh=0.2))\n", "cf = CF((x, y, 1))\n", "md = MeshData(mesh)\n", "fd = FunctionData(md, cf, order=1)\n", "clipping = Clipping()\n", "clipping.center = [0.5, 0.5, 0.5]\n", "vecs = ClippingVectors(fd, clipping=clipping)\n", "Draw(vecs)" ] }, { "cell_type": "markdown", "id": "a7", "metadata": {}, "source": [ "`ClippingVectors` works like `SurfaceVectors` but on the clipping cross-section. The clipping plane is controlled by the `Clipping` object." ] }, { "cell_type": "markdown", "id": "a8", "metadata": {}, "source": [ "## Field Lines\n", "\n", "Streamlines traced through a 3D vector field:" ] }, { "cell_type": "code", "execution_count": null, "id": "a9", "metadata": {}, "outputs": [], "source": [ "from ngsolve import *\n", "from ngsolve_webgpu.cf import FieldLines\n", "from webgpu.jupyter import Draw\n", "\n", "mesh = Mesh(unit_cube.GenerateMesh(maxh=0.3))\n", "cf = CF((-y, x, 0.1))\n", "fieldlines = FieldLines(cf, mesh, num_lines=100, length=0.5, thickness=0.0015)\n", "Draw(fieldlines)" ] }, { "cell_type": "markdown", "id": "a10", "metadata": {}, "source": [ "`FieldLines` integrates streamlines from random start points. Key parameters:\n", "- `num_lines` — number of streamlines (default 100)\n", "- `length` — integration length (default 0.5)\n", "- `thickness` — line thickness relative to bounding box (default 0.0015)\n", "- `direction` — 0=both, 1=forward, -1=backward" ] } ], "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 }