.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/basic/plot_tangent.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_basic_plot_tangent.py: Tangent field ============= .. GENERATED FROM PYTHON SOURCE LINES 15-25 .. code-block:: Python import importlib import time import matplotlib.pyplot as plt import nannos as nn from nannos.formulations.tangent import get_tangent_field .. GENERATED FROM PYTHON SOURCE LINES 26-27 We will generate a field tangent to the material interface .. GENERATED FROM PYTHON SOURCE LINES 27-45 .. code-block:: Python nh = 1500 lattice = nn.Lattice(([1, 0], [0, 1]), discretization=2**9) x, y = lattice.grid circ = lattice.circle((0.3, 0.3), 0.25) rect = lattice.rectangle((0.7, 0.7), (0.2, 0.5)) grid = lattice.ones() * (3 + 0.01j) grid[circ] = 1 grid[rect] = 1 st = lattice.Layer("pat", thickness=1, epsilon=grid) lays = [lattice.Layer("sup"), st, lattice.Layer("sub")] pw = nn.PlaneWave(wavelength=1 / 1.2) sim = nn.Simulation(lays, pw, nh) dsp = 6 .. GENERATED FROM PYTHON SOURCE LINES 46-47 FFT version .. GENERATED FROM PYTHON SOURCE LINES 47-67 .. code-block:: Python t0 = -time.time() t = get_tangent_field(grid, sim.harmonics, normalize=False, type="fft") t0 += time.time() print(f"Elapsed time {t0:.4f}s") plt.figure() st.plot() plt.quiver( x[::dsp, ::dsp], y[::dsp, ::dsp], t[0][::dsp, ::dsp], t[1][::dsp, ::dsp], scale=20, ) plt.axis("scaled") _ = plt.axis("off") plt.show() .. image-sg:: /examples/basic/images/sphx_glr_plot_tangent_001.png :alt: plot tangent :srcset: /examples/basic/images/sphx_glr_plot_tangent_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Elapsed time 1.0557s .. GENERATED FROM PYTHON SOURCE LINES 68-69 Optimized version .. GENERATED FROM PYTHON SOURCE LINES 69-88 .. code-block:: Python t0 = -time.time() topt = get_tangent_field(grid, sim.harmonics, normalize=False, type="opt", maxiter=1) t0 += time.time() print(f"Elapsed time {t0:.4f}s") plt.figure() st.plot() plt.quiver( x[::dsp, ::dsp], y[::dsp, ::dsp], topt[0][::dsp, ::dsp], topt[1][::dsp, ::dsp], scale=20, ) plt.axis("scaled") _ = plt.axis("off") plt.show() .. image-sg:: /examples/basic/images/sphx_glr_plot_tangent_002.png :alt: plot tangent :srcset: /examples/basic/images/sphx_glr_plot_tangent_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Elapsed time 1.3593s .. GENERATED FROM PYTHON SOURCE LINES 89-90 Optimized version (normalized) .. GENERATED FROM PYTHON SOURCE LINES 90-108 .. code-block:: Python t0 = -time.time() topt = get_tangent_field(grid, sim.harmonics, normalize=True, type="opt", maxiter=1) t0 += time.time() print(f"Elapsed time {t0:.4f}s") plt.figure() st.plot() plt.quiver( x[::dsp, ::dsp], y[::dsp, ::dsp], topt[0][::dsp, ::dsp], topt[1][::dsp, ::dsp], scale=20, ) plt.axis("scaled") _ = plt.axis("off") plt.show() .. image-sg:: /examples/basic/images/sphx_glr_plot_tangent_003.png :alt: plot tangent :srcset: /examples/basic/images/sphx_glr_plot_tangent_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Elapsed time 1.3417s .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.469 seconds) **Estimated memory usage:** 1126 MB .. _sphx_glr_download_examples_basic_plot_tangent.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/nannos/nannos.gitlab.io/doc?filepath=notebooks/examples/basic/plot_tangent.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_tangent.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_tangent.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_tangent.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_