.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/structured_media/periodic_array.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_structured_media_periodic_array.py: Finite periodic arrays of dielectric spheres ============================================ Repeat an existing geometric motif on a finite lattice. The lattice vectors are rows of a length-bearing matrix; repetition counts select the number of sites along each row. The complete array is centred on the origin, including half-site offsets for even repetition counts. This example models weak dielectric contrast with the first Born order. It is a finite sample with edges and coherent interference, without periodic boundary conditions or an effective metamaterial constitutive model. .. GENERATED FROM PYTHON SOURCE LINES 14-51 .. code-block:: Python import sys import matplotlib.pyplot as plt import numpy as np from bornsim import Grid, PeriodicMedium, Solver, Source, Sphere from bornsim.units import ureg grid = Grid( shape=(24, 16, 16), spacing=25 * ureg.nanometer, ) sphere = Sphere( radius=50 * ureg.nanometer, refractive_index=1.34, ) array = PeriodicMedium( background_refractive_index=1.33, motif=(sphere,), lattice_vectors=np.diag([175, 175, 175]) * ureg.nanometer, repetitions=(3, 1, 1), overlap="error", ) single = PeriodicMedium( background_refractive_index=1.33, motif=(sphere,), lattice_vectors=np.diag([175, 175, 175]) * ureg.nanometer, repetitions=(1, 1, 1), ) array_volume = array.to_volume(grid=grid) single_volume = single.to_volume(grid=grid) .. GENERATED FROM PYTHON SOURCE LINES 53-57 Inspect the three-sphere array ------------------------------ Each site receives the same motif, preserving its orientation. Geometry outside the voxel box is clipped; these spheres fit completely inside it. .. GENERATED FROM PYTHON SOURCE LINES 57-68 .. code-block:: Python array_figure = array_volume.plot_3d( backend="plotly", mode="volume", field="refractive_index", ) array_figure.update_layout(title="Three dielectric spheres, 175 nm centre spacing") if "--no-browser" not in sys.argv: array_figure.show(renderer="browser") .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 69-71 Inspect the single-site reference --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 71-82 .. code-block:: Python single_figure = single_volume.plot_3d( backend="plotly", mode="volume", field="refractive_index", ) single_figure.update_layout(title="Single sphere on the same voxel grid") if "--no-browser" not in sys.argv: single_figure.show(renderer="browser") .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 83-91 Coherent interference along the x-z meridian -------------------------------------------- Compare the array with three times the isolated-sphere intensity. That reference omits interference between particles. Because the incident beam travels along +z, all three sites have equal incident phase in the forward direction: their first-order amplitudes add, giving nine times the single intensity rather than three times. The spacing is an integer voxel count, so translated particles have identical discrete masks here. .. GENERATED FROM PYTHON SOURCE LINES 91-136 .. code-block:: Python source = Source(wavelength=633 * ureg.nanometer) solver = Solver( source=source, order=1, ) angles = np.linspace(0, 180, 121) * ureg.degree array_result = solver.solve_cut( target=array_volume, angles=angles, ) single_result = solver.solve_cut( target=single_volume, angles=angles, ) array_cross_section = array_result.differential_cross_section.to("nanometer**2 / steradian") single_cross_section = single_result.differential_cross_section.to("nanometer**2 / steradian") np.testing.assert_allclose( array_cross_section.magnitude[..., 0], 9 * single_cross_section.magnitude[..., 0], rtol=1e-12, ) figure, axis = plt.subplots(figsize=(7, 4), layout="constrained") axis.plot(angles.to("degree").magnitude, array_cross_section.magnitude[-1], label="Coherent three-sphere array") axis.plot( angles.to("degree").magnitude, 3 * single_cross_section.magnitude[-1], linestyle="--", label="Three × isolated-sphere intensity", ) axis.set(xlabel="Scattering angle (degrees)", ylabel="dσ/dΩ (nm² sr⁻¹)", title="First Born order") axis.legend(frameon=False) plt.show() .. image-sg:: /auto_examples/structured_media/images/sphx_glr_periodic_array_001.png :alt: First Born order :srcset: /auto_examples/structured_media/images/sphx_glr_periodic_array_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.507 seconds) .. _sphx_glr_download_auto_examples_structured_media_periodic_array.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: periodic_array.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: periodic_array.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: periodic_array.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_