{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Field visualisation using `pyvista`\n", "\n", "**Note:** If you experience any problems in plotting with `pyvista`, please make sure you run the Jupyter notebook in Google Chrome.\n", "\n", "There are several ways how a field can be visualised, using:\n", "\n", "- `matplotlib`\n", "-`pyvista`\n", "- `holoviews`\n", "- vtk-based libraries, e.g. `pyvista`\n", "\n", "\n", "`pyvista` provides three-dimensional interactive plots of fields inside Jupyter notebook.\n", "\n", "Let us say we have a sample, which is an ellipsoid\n", "\n", "$$\\frac{x^2}{a^2} + \\frac{y^2}{b^2} + \\frac{z^2}{c^2} <= 1$$\n", "\n", "with $a=5\\,\\text{nm}$, $b=3\\,\\text{nm}$, and $c=2\\,\\text{nm}$. The space is discretised into cells with dimensions $(0.5\\,\\text{nm}, 0.5\\,\\text{nm}, 0.5\\,\\text{nm})$. The value of the field at $(x, y, z)$ point is $(-cy, cx, cz)$, with $c=10^{9}$. The norm of the field inside the cylinder is $10^{6}$.\n", "\n", "Let us first build that field." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import discretisedfield as df\n", "\n", "a, b, c = 5e-9, 3e-9, 2e-9\n", "cell = (0.5e-9, 0.5e-9, 0.5e-9)\n", "\n", "mesh = df.Mesh(p1=(-a, -b, -c), p2=(a, b, c), cell=cell)\n", "\n", "\n", "def norm_fun(pos):\n", " x, y, z = pos\n", " if (x / a) ** 2 + (y / b) ** 2 + (z / c) ** 2 <= 1:\n", " return 1e6\n", " else:\n", " return 0\n", "\n", "\n", "def value_fun(pos):\n", " x, y, z = pos\n", " c = 1e9\n", " return (-c * y, c * x, c * z)\n", "\n", "\n", "field = df.Field(mesh, nvdim=3, value=value_fun, norm=norm_fun, valid=\"norm\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The most basic plot we can show is the plot of all the cells where the value is valid." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [ "nbval-ignore-output" ] }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "cb6b15fa32e74765a42c479f93bc010c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Widget(value=\"