.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/parameter_studies/absorption_sweep.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_gallery_parameter_studies_absorption_sweep.py: How absorption changes fluence ============================== Compare analytical P1 fields with the same source and scattering but three absorption coefficients. Higher absorption shortens the distance over which fluence reaches a given value. Inputs are illustrative. .. GENERATED FROM PYTHON SOURCE LINES 9-26 .. code-block:: Python import os import matplotlib.pyplot as plt import numpy as np import MomentRT from MomentRT import ( CartesianMesh, HomogeneousMedium, InfiniteP1, Material, PointSource, Simulation, ureg, ) show_figures = os.environ.get("MOMENTRT_SPHINX_GALLERY") != "1" .. GENERATED FROM PYTHON SOURCE LINES 28-32 Set up the common source and observation window ----------------------------------------------- Use an even node count so that no mesh node lands on the point-source singularity at the origin. .. GENERATED FROM PYTHON SOURCE LINES 32-47 .. code-block:: Python mesh = CartesianMesh( shape=(24, 24, 24), spacing=np.full(3, 0.4) * ureg.millimeter, origin=np.full(3, -4.6) * ureg.millimeter, ) source = PointSource( position=np.zeros(3) * ureg.millimeter, wavelength=970 * ureg.nanometer, optical_power=1 * ureg.milliwatt, ) solver = InfiniteP1() .. GENERATED FROM PYTHON SOURCE LINES 48-52 Solve at several absorption levels ---------------------------------- Keep reduced scattering fixed so that the change between curves is due to absorption. Sample an off-axis line so it does not pass through the source. .. GENERATED FROM PYTHON SOURCE LINES 52-90 .. code-block:: Python line_index = mesh.shape[1] // 2 - 1 coordinates = mesh.points.to("millimeter").magnitude line_positions = coordinates[:, line_index, line_index, :] radial_distance = np.linalg.norm(line_positions, axis=-1) absorption_values = (0.005, 0.02, 0.05) fluence_profiles = [] for absorption_value in absorption_values: material = Material( phase_function=MomentRT.phase_function.HenyeyGreenstein(), absorption=absorption_value / ureg.millimeter, reduced_scattering=0.8 / ureg.millimeter, refractive_index=1.4, ) medium = HomogeneousMedium( material=material, ) simulation = Simulation( medium=medium, source=source, mesh=mesh, solver=solver, ) result = simulation.run() line_fluence = result.fluence.values.to("watt / meter**2").magnitude fluence_profiles.append(line_fluence[:, line_index, line_index]) .. GENERATED FROM PYTHON SOURCE LINES 91-94 Compare the radial profiles --------------------------- The nearest plotted sample remains offset from the ideal point source. .. GENERATED FROM PYTHON SOURCE LINES 94-117 .. code-block:: Python order = np.argsort(radial_distance) figure, axes = plt.subplots(figsize=(8, 5)) for absorption_value, profile in zip(absorption_values, fluence_profiles): axes.plot( radial_distance[order], profile[order], label=f"Absorption = {absorption_value:g} mm$^{{-1}}$", ) axes.set_yscale("log") axes.set_xlabel("Distance from source (mm)") axes.set_ylabel("Fluence rate (W m$^{-2}$)") axes.set_title("Absorption controls attenuation in infinite-medium P1") axes.grid(True, which="both", alpha=0.25) axes.legend() figure.tight_layout() if show_figures: plt.show() .. image-sg:: /gallery/parameter_studies/images/sphx_glr_absorption_sweep_001.png :alt: Absorption controls attenuation in infinite-medium P1 :srcset: /gallery/parameter_studies/images/sphx_glr_absorption_sweep_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 118-122 Explore a three-dimensional fluence volume ------------------------------------------ This is the highest-absorption solution above. The mesh is an observation window within the infinite medium, not the boundary of a physical sample. .. GENERATED FROM PYTHON SOURCE LINES 122-131 .. code-block:: Python volume_figure = result.fluence.plot( view="volume", scale="log", overlays=[source], show=show_figures, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 132-135 Inspect the modeled geometry ---------------------------- This view shows the configured geometry and instrument footprints. .. GENERATED FROM PYTHON SOURCE LINES 135-137 .. code-block:: Python gallery_system_figure = simulation.plot_system(show=False) .. raw:: html .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.215 seconds) .. _sphx_glr_download_gallery_parameter_studies_absorption_sweep.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: absorption_sweep.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: absorption_sweep.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: absorption_sweep.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_