.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/transport_models/sp3_layered_anisotropy.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_sp3_layered_anisotropy.py: Use different anisotropies in a layered sample ================================================ Assign a scattering anisotropy to each material and solve a layered sample with SP3. The values are illustrative, not measured skin properties. SP3 uses the Henyey–Greenstein phase function for each material. .. GENERATED FROM PYTHON SOURCE LINES 9-19 .. 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 21-26 Set optical properties for each layer ------------------------------------- Anisotropy belongs to the material, not the solver. SP3 requires a value for every region, including the background. This model assumes the same refractive index across internal interfaces. .. GENERATED FROM PYTHON SOURCE LINES 26-56 .. 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.65, 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, ) .. GENERATED FROM PYTHON SOURCE LINES 57-61 Configure the source, detector, and solver ------------------------------------------ The incoming source is diffuse and isotropic over the inward hemisphere. A zero-reflectance Robin face selects the matched-index SP3 boundary model. .. GENERATED FROM PYTHON SOURCE LINES 61-99 .. code-block:: Python source = MomentRT.SurfaceSource.on_face( sample=sample, face="z_min", coordinates=np.array([-1.5, 0]) * ureg.millimeter, radius=1.0 * ureg.millimeter, wavelength=850 * ureg.nanometer, optical_power=1 * ureg.milliwatt, ) detector = MomentRT.SurfaceDetector.on_face( sample=sample, face="z_min", coordinates=np.array([1.5, 0]) * ureg.millimeter, radius=0.8 * ureg.millimeter, orientation="outward_normal", acceptance_angle=90 * ureg.degree, ) mesh = MomentRT.CartesianMesh.from_sample( sample=sample, shape=(15, 15, 11), ) boundary = MomentRT.RobinBoundary(effective_reflectance=0) boundaries = MomentRT.Boundaries.uniform(condition=boundary) solver = MomentRT.SP3(boundaries=boundaries) simulation = MomentRT.Simulation( medium=sample, source=source, mesh=mesh, solver=solver, detectors={"contact": detector}, ) .. GENERATED FROM PYTHON SOURCE LINES 100-104 Inspect geometry and solve the sample ------------------------------------- Regions have different absorption, reduced scattering, and anisotropy. The displayed surfaces show the geometry used to construct the sample. .. GENERATED FROM PYTHON SOURCE LINES 104-122 .. code-block:: Python report = simulation.validate() print(report.summary()) if not report.valid: raise ValueError("Fix the reported configuration errors before solving.") system_figure = simulation.plot_system(show=show_figures) result = simulation.run() print(f"Dermis anisotropy: {dermis.anisotropy:.2f}") print(f"Epidermis anisotropy: {epidermis.anisotropy:.2f}") print(result.summary()) .. raw:: html .. rst-class:: sphx-glr-script-out .. code-block:: none Configuration valid Warning: Footprint sampling alone does not establish mesh convergence or transport accuracy. Model note: SP3 is a steady-state simplified P3 angular-moment approximation; it uses each material's normalized phase-function moments through degree 3. Model note: SP3 assumes isotropic incoming diffuse radiance, requires zero-reflectance Robin conditions on illuminated faces, permits reflecting unilluminated faces, and requires equal internal refractive indices. Model note: SP3 agreement with a slab reference verifies this implementation for that case, not accuracy for arbitrary geometries or sensors. Model note: Detector angular acceptance uses a separate Lambertian approximation. Source sampled area: 3.1020408163265303×10⁻⁶ m² Detector contact sampled area: 2.01360544217687×10⁻⁶ m² Dermis anisotropy: 0.80 Epidermis anisotropy: 0.65 Transport result Model: steady-state tetrahedral SP3 FEM Wavelength: 850 nm Mesh shape: (15, 15, 11) Convergence study: not supplied; convergence is not established. Detector contact: 5.439695721012772×10⁻⁶ W (sampled area 2.01360544217687×10⁻⁶ m²; geometric area 2.0106192982974678 mm²) Source sampled area: 3.1020408163265303×10⁻⁶ m²; geometric area: 3.141592653589793×10⁻⁶ m² Incoming power: 1 mW Absorbed power: 0.00019123440812157216 W Escaping power: 0.0008087655918784266 W Residual power: 1.3010426069826053×10⁻¹⁸ W Linear relative residual: 1.68e-15 Warning: minimum fluence is negative: -0.0937768318898355 W/m² .. GENERATED FROM PYTHON SOURCE LINES 123-128 View the physical fluence in three dimensions ---------------------------------------------- The source and detector are overlaid on the solved fluence volume. Refine the mesh to assess both footprint sampling and the detector signal; SP3 is an approximation and this plot does not establish transport accuracy. .. GENERATED FROM PYTHON SOURCE LINES 128-137 .. code-block:: Python fluence_figure = result.fluence.plot( view="volume", scale="linear", overlays=[source, detector], show=show_figures, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 138-141 Inspect the modeled geometry ---------------------------- This view shows the configured geometry and instrument footprints. .. GENERATED FROM PYTHON SOURCE LINES 141-143 .. 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.379 seconds) .. _sphx_glr_download_gallery_transport_models_sp3_layered_anisotropy.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sp3_layered_anisotropy.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sp3_layered_anisotropy.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: sp3_layered_anisotropy.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_