.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/transport_models/compare_sp3.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_transport_models_compare_sp3.py: Compare P1 and SP3 transport ============================ Compare the coupled SP3 moment model and P1 diffusion in the same finite sample with matched-index boundary conditions and incoming diffuse light. This comparison illustrates model differences; it does not establish which model matches radiative transfer for a particular sensor. .. GENERATED FROM PYTHON SOURCE LINES 10-20 .. code-block:: Python import os import numpy as np import MomentRT ureg = MomentRT.ureg show_figures = os.environ.get("MOMENTRT_SPHINX_GALLERY") != "1" .. GENERATED FROM PYTHON SOURCE LINES 22-26 Define the sample and instrument -------------------------------- Both models receive the same material, source, detector, mesh, and faces. SP3 additionally uses each material's Henyey–Greenstein anisotropy. .. GENERATED FROM PYTHON SOURCE LINES 26-64 .. code-block:: Python material = MomentRT.Material( phase_function=MomentRT.phase_function.HenyeyGreenstein(), absorption=0.03 / ureg.millimeter, reduced_scattering=1 / ureg.millimeter, refractive_index=1.4, anisotropy=0.8, ) sample = MomentRT.StructuredMedium( origin=(-4, -4, 0) * ureg.millimeter, size=(8, 8, 4) * ureg.millimeter, ) sample.add_background(material=material) mesh = MomentRT.CartesianMesh.from_sample(sample=sample, shape=(13, 13, 9)) source = MomentRT.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, ) detector = MomentRT.SurfaceDetector( face="z_min", position=np.array([2.5, 0, 0]) * ureg.millimeter, radius=0.8 * ureg.millimeter, collection_axis=[0, 0, -1], acceptance_angle=90 * ureg.degree, ) boundary = MomentRT.RobinBoundary(effective_reflectance=0) boundaries = {face: boundary for face in MomentRT.boundary.FACES} .. GENERATED FROM PYTHON SOURCE LINES 65-69 Run both approximations ----------------------- A zero-reflectance Robin face means a matched-index boundary for this SP3 formulation. The illumination is isotropic in the incoming hemisphere. .. GENERATED FROM PYTHON SOURCE LINES 69-98 .. code-block:: Python p1_solver = MomentRT.P1(boundaries=boundaries) sp3_solver = MomentRT.SP3(boundaries=boundaries) p1_simulation = MomentRT.Simulation( medium=sample, source=source, mesh=mesh, solver=p1_solver, detectors={"contact": detector}, ) sp3_simulation = MomentRT.Simulation( medium=sample, source=source, mesh=mesh, solver=sp3_solver, detectors={"contact": detector}, ) p1_result = p1_simulation.run() sp3_result = sp3_simulation.run() print(f"P1 collected power: {p1_result.detector_power['contact'].to('mW'):~P}") print(f"SP3 collected power: {sp3_result.detector_power['contact'].to('mW'):~P}") .. rst-class:: sphx-glr-script-out .. code-block:: none P1 collected power: 0.03201249859038029 mW SP3 collected power: 0.030704009517094424 mW .. GENERATED FROM PYTHON SOURCE LINES 99-104 Inspect the SP3 fluence ----------------------- The displayed fluence combines both SP3 moments. Refine the mesh and compare against an independent transport reference before interpreting a particular source–detector configuration. .. GENERATED FROM PYTHON SOURCE LINES 104-113 .. code-block:: Python figure = sp3_result.fluence.plot( view="volume", scale="linear", overlays=[source, detector], show=show_figures, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 114-117 Inspect the modeled geometry ---------------------------- This view shows the configured geometry and instrument footprints. .. GENERATED FROM PYTHON SOURCE LINES 117-119 .. code-block:: Python gallery_system_figure = sp3_simulation.plot_system(show=False) .. raw:: html .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.226 seconds) .. _sphx_glr_download_gallery_transport_models_compare_sp3.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: compare_sp3.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: compare_sp3.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: compare_sp3.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_