.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/transport_models/compare_p3.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_p3.py: Compare full P3 with SP3 and P1 ================================ Solve the same seven-fiber contact geometry on two skin layers with three angular approximations. Full P3 retains the three-dimensional spherical-harmonic moments through order three. The supplied values are illustrative, and agreement between the models does not establish accuracy against radiative transfer. .. GENERATED FROM PYTHON SOURCE LINES 11-21 .. 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 23-29 Define the common physical configuration ---------------------------------------- The Henyey–Greenstein anisotropy belongs to the material. The three models share matched-index faces, six diffuse sources, mesh, and aperture. The finite mesh samples the layer interface at tetrahedron centroids, so the interface geometry and disk footprints also require mesh refinement. .. GENERATED FROM PYTHON SOURCE LINES 29-94 .. code-block:: Python dermis = MomentRT.Material( absorption=0.03 / ureg.millimeter, reduced_scattering=1.0 / ureg.millimeter, refractive_index=1.4, anisotropy=0.8, phase_function=MomentRT.phase_function.HenyeyGreenstein(), ) epidermis = MomentRT.Material( absorption=0.06 / ureg.millimeter, reduced_scattering=1.6 / ureg.millimeter, refractive_index=1.4, anisotropy=0.7, phase_function=MomentRT.phase_function.HenyeyGreenstein(), ) sample = MomentRT.StructuredMedium( origin=(-4, -4, 0) * ureg.millimeter, size=(8, 8, 4) * ureg.millimeter, ) sample.add_background(material=dermis) sample.add_layer( name="Epidermis", thickness=0.8 * ureg.millimeter, material=epidermis, ) sources = [] for fiber_number in range(6): angle = fiber_number * np.pi / 3 coordinates = np.array([np.cos(angle), np.sin(angle)]) * 1.8 * ureg.millimeter source = MomentRT.SurfaceSource.on_face( sample=sample, face="z_min", coordinates=coordinates, radius=0.8 * ureg.millimeter, wavelength=850 * ureg.nanometer, optical_power=(1 / 6) * ureg.milliwatt, name=f"Illumination fiber {fiber_number + 1}", ) sources.append(source) detector = MomentRT.SurfaceDetector.on_face( sample=sample, face="z_min", coordinates=np.array([0, 0]) * ureg.millimeter, radius=0.8 * ureg.millimeter, acceptance_angle=90 * ureg.degree, orientation="outward_normal", name="Collection fiber", ) mesh = MomentRT.CartesianMesh.from_sample(sample=sample, shape=(9, 9, 7)) boundary = MomentRT.RobinBoundary(effective_reflectance=0) boundaries = MomentRT.Boundaries.uniform(condition=boundary) .. GENERATED FROM PYTHON SOURCE LINES 95-103 Solve and compare the detector signal ------------------------------------- P3 solves six even angular moments and reconstructs ten odd moments from their gradients. SP3 instead solves two composite fields. The contact detector currently uses a Lambertian angular-acceptance approximation for all three models, including P3. Each linear diffuse solve uses one source; the six fluences and detector powers are added incoherently. This does not model optical interference, fiber modes, or Fresnel entry losses. .. GENERATED FROM PYTHON SOURCE LINES 103-167 .. code-block:: Python solvers = { "P1": MomentRT.P1(boundaries=boundaries), "SP3": MomentRT.SP3(boundaries=boundaries), "P3": MomentRT.P3(boundaries=boundaries), } combined_fields = {} for name, solver in solvers.items(): results = [] for fiber_number, source in enumerate(sources, start=1): simulation = MomentRT.Simulation( medium=sample, source=source, mesh=mesh, solver=solver, detectors={"contact": detector}, ) report = simulation.validate() if not report.valid: raise ValueError(report.summary()) result = simulation.run() results.append(result) if name == "P1": print( f"Fiber {fiber_number} source area: sampled " f"{result.source_sampled_area.to('mm^2'):~P}, " f"geometric {result.source_geometric_area.to('mm^2'):~P}" ) combined_values = sum(result.fluence.values for result in results) combined_fields[name] = MomentRT.ScalarField( mesh=results[0].fluence.mesh, values=combined_values, name=f"Combined {name} fluence rate", metadata={**results[0].fluence.metadata, "source_count": len(sources)}, ) collected_power = sum(result.detector_power["contact"] for result in results) residual_power = sum(result.energy_balance["residual_power"] for result in results) print(f"{name} collected power: {collected_power.to('mW'):~P}") print(f"{name} minimum fluence: {combined_values.min():~P}") print(f"{name} energy residual: {residual_power:~P}") print( f"{name} sampled detector area: {results[0].detectors['contact'].sampled_area.to('mm^2'):~P}" ) print( f"{name} geometric detector area: {results[0].detectors['contact'].geometric_area.to('mm^2'):~P}" ) .. rst-class:: sphx-glr-script-out .. code-block:: none Fiber 1 source area: sampled 1.8333333333333333 mm², geometric 2.0106192982974678 mm² Fiber 2 source area: sampled 2.1666666666666665 mm², geometric 2.0106192982974678 mm² Fiber 3 source area: sampled 2.0 mm², geometric 2.0106192982974678 mm² Fiber 4 source area: sampled 1.8333333333333333 mm², geometric 2.0106192982974678 mm² Fiber 5 source area: sampled 2.1666666666666665 mm², geometric 2.0106192982974678 mm² Fiber 6 source area: sampled 2.0 mm², geometric 2.0106192982974678 mm² P1 collected power: 0.06642209718791982 mW P1 minimum fluence: -1.3068580830308083 W/m² P1 energy residual: -1.3552527156068805e-18 W P1 sampled detector area: 1.6666666666666665 mm² P1 geometric detector area: 2.0106192982974678 mm² SP3 collected power: 0.06471650491678295 mW SP3 minimum fluence: -1.0599514053421157 W/m² SP3 energy residual: -8.944667923005412e-19 W SP3 sampled detector area: 1.6666666666666665 mm² SP3 geometric detector area: 2.0106192982974678 mm² P3 collected power: 0.05794231277494402 mW P3 minimum fluence: -1.6575186027265618 W/m² P3 energy residual: 1.2739375526704677×10⁻¹⁸ W P3 sampled detector area: 1.6666666666666665 mm² P3 geometric detector area: 2.0106192982974678 mm² .. GENERATED FROM PYTHON SOURCE LINES 168-174 Explore the full P3 fluence ---------------------------- Linear scale retains any negative values from the angular or spatial approximation. Refine the mesh and compare against an independent transport reference before interpreting the result for a particular sensor. The gallery preview is captured from this same combined P3 volume. .. GENERATED FROM PYTHON SOURCE LINES 174-185 .. code-block:: Python overlays = [*sources, detector] fluence_figure = combined_fields["P3"].plot( view="volume", scale="linear", overlays=overlays, show=show_figures, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 186-189 Inspect the modeled geometry ---------------------------- This view shows the configured geometry and instrument footprints. .. GENERATED FROM PYTHON SOURCE LINES 189-191 .. code-block:: Python gallery_system_figure = sample.plot(overlays=overlays, show=False) .. raw:: html .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.205 seconds) .. _sphx_glr_download_gallery_transport_models_compare_p3.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: compare_p3.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: compare_p3.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: compare_p3.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_