{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# This file is part of nannos\n# License: GPLv3\n%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Tangent field\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import importlib\nimport time\n\nimport matplotlib.pyplot as plt\n\nimport nannos as nn\nfrom nannos.formulations.tangent import get_tangent_field\n\nbk = nn.backend\nplt.close(\"all\")\n# plt.ion()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will generate a field tangent to the material interface\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "scale = 1.5\nnh = 600\nlattice = nn.Lattice(([1 * scale, 0], [0, scale]), discretization=2**9)\n\nx, y = lattice.grid\ncirc = lattice.ellipse(\n (0.3 * scale, 0.3 * scale), (0.1 * scale, 0.25 * scale), rotate=-30\n)\nrect = lattice.rectangle(\n (0.7 * scale, 0.7 * scale), (0.2 * scale, 0.5 * scale), rotate=20\n)\ngrid = lattice.ones() * (3 + 0.01j)\ngrid[circ] = 1\ngrid[rect] = 1\n\nst = lattice.Layer(\"pat\", thickness=scale, epsilon=grid)\nlays = [lattice.Layer(\"sup\"), st, lattice.Layer(\"sub\")]\npw = nn.PlaneWave(wavelength=1 / 1.2)\nsim = nn.Simulation(lays, pw, nh)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "FFT version\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "rfilt = 2\ndsp = 10\nt0 = -time.time()\nt = get_tangent_field(\n lattice, grid, sim.harmonics, normalize=False, type=\"fft\", rfilt=rfilt\n)\nt0 += time.time()\nprint(f\"Elapsed time {t0:.4f}s\")\n\n\nplt.figure()\nst.plot()\nplt.quiver(\n x[::dsp, ::dsp],\n y[::dsp, ::dsp],\n t[0][::dsp, ::dsp],\n t[1][::dsp, ::dsp],\n scale=11,\n)\nplt.axis(\"scaled\")\n_ = plt.axis(\"off\")\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "FFT version (normalized)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "t0 = -time.time()\ntnorma = get_tangent_field(\n lattice, grid, sim.harmonics, normalize=True, type=\"fft\", rfilt=rfilt\n)\nt0 += time.time()\nprint(f\"Elapsed time {t0:.4f}s\")\n\n\nplt.figure()\nst.plot()\nplt.quiver(\n x[::dsp, ::dsp],\n y[::dsp, ::dsp],\n tnorma[0][::dsp, ::dsp],\n tnorma[1][::dsp, ::dsp],\n scale=50,\n)\nplt.axis(\"scaled\")\n_ = plt.axis(\"off\")\nplt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import nannos.utils.jupyter\n%nannos_version_table" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.3" } }, "nbformat": 4, "nbformat_minor": 0 }