.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/parameter_studies/reflectance_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_reflectance_sweep.py: Changing the diffuse boundary reflectance ========================================= Solve the same illuminated slab with three effective diffuse reflectances. The centerline fluence increases as less diffuse current escapes through the sample boundary. The parameter is not a Fresnel reflectance. Inputs are illustrative. .. GENERATED FROM PYTHON SOURCE LINES 10-28 .. code-block:: Python import os import matplotlib.pyplot as plt import numpy as np import MomentRT from MomentRT import ( P1, CartesianMesh, Material, RobinBoundary, Simulation, StructuredMedium, SurfaceSource, ureg, ) show_figures = os.environ.get("MOMENTRT_SPHINX_GALLERY") != "1" .. GENERATED FROM PYTHON SOURCE LINES 30-34 Define a homogeneous finite sample ---------------------------------- The sample is illuminated through its upper z face and uses a common refractive index throughout. .. GENERATED FROM PYTHON SOURCE LINES 34-64 .. code-block:: Python material = Material( phase_function=MomentRT.phase_function.HenyeyGreenstein(), absorption=0.03 / ureg.millimeter, reduced_scattering=1.0 / ureg.millimeter, refractive_index=1.4, ) sample = StructuredMedium( origin=(-4, -4, 0) * ureg.millimeter, size=(8, 8, 4) * ureg.millimeter, ) sample.add_background( material=material, ) mesh = CartesianMesh.from_sample( sample=sample, shape=(13, 13, 9), ) source = SurfaceSource( face="z_min", position=np.array([0, 0, 0]) * ureg.millimeter, radius=1.5 * ureg.millimeter, wavelength=970 * ureg.nanometer, optical_power=1 * ureg.milliwatt, ) .. GENERATED FROM PYTHON SOURCE LINES 65-69 Reuse the same inputs while varying R ------------------------------------- Compare a more open diffuse boundary with progressively stronger internal diffuse reflection. .. GENERATED FROM PYTHON SOURCE LINES 69-110 .. code-block:: Python reflectance_values = (0.0, 0.5, 0.9) center_index_x = mesh.shape[0] // 2 center_index_y = mesh.shape[1] // 2 depth = ( (mesh.origin[2] + np.arange(mesh.shape[2]) * mesh.spacing[2]) .to("millimeter") .magnitude ) centerline_profiles = [] results = [] for reflectance in reflectance_values: boundary = RobinBoundary( effective_reflectance=reflectance, ) solver = P1( boundaries=MomentRT.Boundaries.uniform(condition=boundary), ) simulation = Simulation( medium=sample, source=source, mesh=mesh, solver=solver, ) result = simulation.run() results.append(result) fluence = result.fluence.values.to("watt / meter**2").magnitude centerline_profiles.append(fluence[center_index_x, center_index_y, :]) .. GENERATED FROM PYTHON SOURCE LINES 111-114 Plot fluence through the center of the sample --------------------------------------------- Each curve shares the same material, source power, spot, and mesh. .. GENERATED FROM PYTHON SOURCE LINES 114-133 .. code-block:: Python figure, axes = plt.subplots(figsize=(8, 5)) for reflectance, profile in zip(reflectance_values, centerline_profiles): axes.plot( depth, profile, marker="o", label=f"Effective diffuse reflectance R = {reflectance:g}", ) axes.set_yscale("log") axes.set_xlabel("Depth into sample (mm)") axes.set_ylabel("Centerline fluence rate (W m$^{-2}$)") axes.set_title("Boundary reflection changes the finite-sample field") axes.grid(True, which="both", alpha=0.25) axes.legend() figure.tight_layout() .. image-sg:: /gallery/parameter_studies/images/sphx_glr_reflectance_sweep_001.png :alt: Boundary reflection changes the finite-sample field :srcset: /gallery/parameter_studies/images/sphx_glr_reflectance_sweep_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 134-137 Check energy accounting for each case ------------------------------------- The reported escape is transmitted power integrated over all sample faces. .. GENERATED FROM PYTHON SOURCE LINES 137-152 .. code-block:: Python for reflectance, result in zip(reflectance_values, results): incoming_power = result.energy_balance["incoming_power"].to("milliwatt") escaping_power = result.energy_balance["escaping_power"].to("milliwatt") print( f"R = {reflectance:g}: " f"incoming = {incoming_power:.4g}, " f"escaping = {escaping_power:.4g}" ) if show_figures: plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none R = 0: incoming = 1 milliwatt, escaping = 0.838 milliwatt R = 0.5: incoming = 1 milliwatt, escaping = 0.7425 milliwatt R = 0.9: incoming = 1 milliwatt, escaping = 0.4101 milliwatt .. GENERATED FROM PYTHON SOURCE LINES 153-156 Inspect the intermediate-reflectance volume ------------------------------------------- The middle solution uses R = 0.5 and retains the same source and geometry. .. GENERATED FROM PYTHON SOURCE LINES 156-165 .. code-block:: Python volume_figure = results[1].fluence.plot( view="volume", scale="log", overlays=[source], show=show_figures, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 166-169 Inspect the modeled geometry ---------------------------- This view shows the configured geometry and instrument footprints. .. GENERATED FROM PYTHON SOURCE LINES 169-171 .. 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.406 seconds) .. _sphx_glr_download_gallery_parameter_studies_reflectance_sweep.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: reflectance_sweep.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: reflectance_sweep.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: reflectance_sweep.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_