Note
Go to the end to download the full example code.
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.
import os
import numpy as np
import MomentRT
ureg = MomentRT.ureg
show_figures = os.environ.get("MOMENTRT_SPHINX_GALLERY") != "1"
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.
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,
)
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.
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},
)
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.
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())
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²
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.
fluence_figure = result.fluence.plot(
view="volume",
scale="linear",
overlays=[source, detector],
show=show_figures,
)
Inspect the modeled geometry#
This view shows the configured geometry and instrument footprints.
gallery_system_figure = simulation.plot_system(show=False)
Total running time of the script: (0 minutes 0.379 seconds)