{ "cells": [ { "cell_type": "markdown", "id": "f0a1b2c3", "metadata": {}, "source": [ "# Entity Numbers\n", "\n", "The `EntityNumbers` renderer displays numeric labels at mesh entity positions.\n", "Supported entity types: `vertices`, `edges`, `facets`, `surface_elements`, `volume_elements`.\n", "\n", "Positions are derived on the GPU from the mesh data buffer. For edges and facets,\n", "a small connectivity buffer is uploaded on demand." ] }, { "cell_type": "markdown", "id": "d4e5f6a7", "metadata": {}, "source": [ "## Vertex Numbers" ] }, { "cell_type": "code", "execution_count": null, "id": "b8c9d0e1", "metadata": {}, "outputs": [], "source": [ "from ngsolve import *\n", "from ngsolve_webgpu import *\n", "from webgpu.jupyter import Draw\n", "\n", "mesh = Mesh(unit_square.GenerateMesh(maxh=0.3))\n", "meshdata = MeshData(mesh)\n", "wireframe = MeshWireframe2d(meshdata)\n", "numbers = EntityNumbers(meshdata, entity=\"vertices\", font_size=15)\n", "scene = Draw([wireframe, numbers])" ] }, { "cell_type": "markdown", "id": "f2a3b4c5", "metadata": {}, "source": [ "## Edge Numbers\n", "\n", "Edge numbers are displayed at the midpoint of each edge." ] }, { "cell_type": "code", "execution_count": null, "id": "d6e7f8a9", "metadata": {}, "outputs": [], "source": [ "from ngsolve import *\n", "from ngsolve_webgpu import *\n", "from webgpu.jupyter import Draw\n", "\n", "mesh = Mesh(unit_square.GenerateMesh(maxh=0.3))\n", "meshdata = MeshData(mesh)\n", "wireframe = MeshWireframe2d(meshdata)\n", "numbers = EntityNumbers(meshdata, entity=\"edges\", font_size=12)\n", "scene = Draw([wireframe, numbers])" ] }, { "cell_type": "markdown", "id": "a0b1c2d3", "metadata": {}, "source": [ "## Surface Element Numbers\n", "\n", "Numbers are placed at the centroid of each surface element (triangle/quad)." ] }, { "cell_type": "code", "execution_count": null, "id": "e4f5a6b7", "metadata": {}, "outputs": [], "source": [ "from ngsolve import *\n", "from ngsolve_webgpu import *\n", "from webgpu.jupyter import Draw\n", "\n", "mesh = Mesh(unit_square.GenerateMesh(maxh=0.3))\n", "meshdata = MeshData(mesh)\n", "surface = MeshElements2d(meshdata)\n", "wireframe = MeshWireframe2d(meshdata)\n", "numbers = EntityNumbers(meshdata, entity=\"surface_elements\", font_size=12)\n", "scene = Draw([surface, wireframe, numbers])" ] }, { "cell_type": "markdown", "id": "c8d9e0f1", "metadata": {}, "source": [ "## Facet Numbers\n", "\n", "Facets are the topological faces of elements. In 2D, facets coincide with edges.\n", "In 3D, facets are the triangular/quad faces shared between volume elements." ] }, { "cell_type": "code", "execution_count": null, "id": "a2b3c4d5", "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.5))\n", "meshdata = MeshData(mesh)\n", "clipping = Clipping()\n", "clipping.mode = clipping.Mode.PLANE\n", "clipping.center = [0.5, 0.5, 0.5]\n", "surface = MeshElements2d(meshdata, clipping=clipping)\n", "wireframe = MeshWireframe2d(meshdata, clipping=clipping)\n", "numbers = EntityNumbers(meshdata, entity=\"facets\", font_size=10, clipping=clipping)\n", "scene = Draw([surface, wireframe, numbers])" ] }, { "cell_type": "markdown", "id": "e6f7a8b9", "metadata": {}, "source": [ "## Volume Element Numbers\n", "\n", "For 3D meshes, volume element numbers are placed at element centroids.\n", "Use clipping to see interior elements." ] }, { "cell_type": "code", "execution_count": null, "id": "c0d1e2f3", "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.5))\n", "meshdata = MeshData(mesh)\n", "clipping = Clipping()\n", "clipping.mode = clipping.Mode.PLANE\n", "clipping.center = [0.5, 0.5, 0.5]\n", "vol = MeshElements3d(meshdata, clipping=clipping)\n", "vol.shrink = 0.1\n", "numbers = EntityNumbers(meshdata, entity=\"volume_elements\", font_size=12, clipping=clipping)\n", "scene = Draw([vol, numbers])" ] }, { "cell_type": "markdown", "id": "a4b5c6d7", "metadata": {}, "source": [ "## Combining Multiple Entity Types\n", "\n", "Multiple `EntityNumbers` renderers can be combined to show different numberings simultaneously." ] }, { "cell_type": "code", "execution_count": null, "id": "e8f9a0b1", "metadata": {}, "outputs": [], "source": [ "from ngsolve import *\n", "from ngsolve_webgpu import *\n", "from webgpu.jupyter import Draw\n", "\n", "mesh = Mesh(unit_square.GenerateMesh(maxh=0.5))\n", "meshdata = MeshData(mesh)\n", "wireframe = MeshWireframe2d(meshdata)\n", "vertex_nums = EntityNumbers(meshdata, entity=\"vertices\", font_size=18)\n", "edge_nums = EntityNumbers(meshdata, entity=\"edges\", font_size=12)\n", "scene = Draw([wireframe, vertex_nums, edge_nums])" ] }, { "cell_type": "code", "execution_count": null, "id": "a33a2cc2-626b-4213-be92-7633ca69da94", "metadata": {}, "outputs": [], "source": [] } ], "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 }