.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/results/cross_section_and_volume.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_results_cross_section_and_volume.py: Cross sections and box-normalized coefficients ============================================== Pad one fixed physical sphere with background voxels at fixed spacing. The box-normalized scattering coefficient changes with sample volume, while its product with that volume is the scattering cross section. Padding tests representation and normalization, not an infinite-medium transport limit. .. GENERATED FROM PYTHON SOURCE LINES 10-39 .. code-block:: Python import matplotlib.pyplot as plt from bornsim import Grid, Solver, Source, Sphere, StructuredMedium from bornsim.units import ureg grid = Grid( shape=(12, 12, 12), spacing=20 * ureg.nanometer, ) sphere = Sphere( radius=70 * ureg.nanometer, refractive_index=1.35, ) medium = StructuredMedium() medium.add_background(refractive_index=1.33) medium.add_structures(sphere) volume = medium.to_volume(grid=grid) volume_figure = volume.plot_3d( field="refractive_index", ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 41-78 .. code-block:: Python source = Source(wavelength=633 * ureg.nanometer) solver = Solver( source=source, order=4, ) figure, axes = plt.subplots(1, 2, figsize=(10, 4), layout="constrained") for count in (10, 12, 16): grid = Grid( shape=(count, count, count), spacing=20 * ureg.nanometer, ) volume = medium.to_volume(grid=grid) result = solver.solve(target=volume) scattering_area = (result.mu_s * result.sample_volume).to("nanometer**2") axes[0].plot(range(1, 5), result.mu_s.to("1 / meter").magnitude, "o-", label=f"{count}³ box") axes[1].plot(range(1, 5), scattering_area.magnitude, "o-", label=f"{count}³ box") print(f"Box {count}³, fourth-order scattering cross section: {scattering_area[-1]}") axes[0].set(ylabel="Box-normalized coefficient (m⁻¹)") axes[1].set(ylabel="Scattering cross section (nm²)") for axis in axes: axis.set(xlabel="Cumulative Born order", xticks=range(1, 5)) axis.legend() plt.show() .. image-sg:: /auto_examples/results/images/sphx_glr_cross_section_and_volume_001.png :alt: cross section and volume :srcset: /auto_examples/results/images/sphx_glr_cross_section_and_volume_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Box 10³, fourth-order scattering cross section: 1.7439052154060923 nanometer ** 2 Box 12³, fourth-order scattering cross section: 1.7439052154060923 nanometer ** 2 Box 16³, fourth-order scattering cross section: 1.7439052154060921 nanometer ** 2 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.385 seconds) .. _sphx_glr_download_auto_examples_results_cross_section_and_volume.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cross_section_and_volume.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cross_section_and_volume.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: cross_section_and_volume.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_