.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/getting_started/structured_sample.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_getting_started_structured_sample.py: A heterogeneous layered sample ============================== Build a synthetic optical phantom with three layers, two spherical inclusions, and a box-shaped heterogeneity. Its materials are illustrative and assumed at one wavelength. Positive z points into the sample. Then illuminate the sample and inspect the finite-sample P1 fluence volume. .. GENERATED FROM PYTHON SOURCE LINES 10-26 .. code-block:: Python import numpy as np import MomentRT from MomentRT import ( P1, Box, Material, RobinBoundary, Simulation, Sphere, StructuredMedium, TetrahedralMesh, UniformSurfaceSource, ureg, ) .. GENERATED FROM PYTHON SOURCE LINES 28-31 Optical materials ----------------- Use explicit unit-bearing optical coefficients. These values are illustrative. .. GENERATED FROM PYTHON SOURCE LINES 31-81 .. code-block:: Python background = Material( phase_function=MomentRT.phase_function.HenyeyGreenstein(), absorption=0.01 / ureg.millimeter, reduced_scattering=0.8 / ureg.millimeter, refractive_index=1.4, ) epidermal_material = Material( phase_function=MomentRT.phase_function.HenyeyGreenstein(), absorption=0.1 / ureg.millimeter, reduced_scattering=1.5 / ureg.millimeter, refractive_index=1.4, ) papillary_material = Material( phase_function=MomentRT.phase_function.HenyeyGreenstein(), absorption=0.04 / ureg.millimeter, reduced_scattering=1.3 / ureg.millimeter, refractive_index=1.4, ) reticular_material = Material( phase_function=MomentRT.phase_function.HenyeyGreenstein(), absorption=0.02 / ureg.millimeter, reduced_scattering=0.9 / ureg.millimeter, refractive_index=1.4, ) inclusion_material = Material( phase_function=MomentRT.phase_function.HenyeyGreenstein(), absorption=0.18 / ureg.millimeter, reduced_scattering=1.6 / ureg.millimeter, refractive_index=1.4, ) second_inclusion_material = Material( phase_function=MomentRT.phase_function.HenyeyGreenstein(), absorption=0.08 / ureg.millimeter, reduced_scattering=2.0 / ureg.millimeter, refractive_index=1.4, ) box_material = Material( phase_function=MomentRT.phase_function.HenyeyGreenstein(), absorption=0.06 / ureg.millimeter, reduced_scattering=0.6 / ureg.millimeter, refractive_index=1.4, ) .. GENERATED FROM PYTHON SOURCE LINES 82-85 Finite sample extent -------------------- Set the lower corner and full dimensions. Positive z points into the sample. .. GENERATED FROM PYTHON SOURCE LINES 85-95 .. code-block:: Python sample = StructuredMedium( origin=(-5, -5, 0) * ureg.millimeter, size=(10, 10, 5) * ureg.millimeter, ) sample.add_background( material=background, ) .. GENERATED FROM PYTHON SOURCE LINES 96-100 Stack background layers ----------------------- Each layer starts below the preceding one. The remaining depth keeps the explicitly configured background material. .. GENERATED FROM PYTHON SOURCE LINES 100-113 .. code-block:: Python sample.add_layer( name="Epidermis", thickness=0.2 * ureg.millimeter, material=epidermal_material, ) sample.add_layer( name="Papillary layer", thickness=0.8 * ureg.millimeter, material=papillary_material, ) .. GENERATED FROM PYTHON SOURCE LINES 114-118 Add a deeper layer and three localized regions ---------------------------------------------- The two spheres overlap layer interfaces. The box intersects the y=0 section. Batch insertion makes the region replacement order explicit. .. GENERATED FROM PYTHON SOURCE LINES 118-152 .. code-block:: Python sample.add_layer( name="Reticular layer", thickness=2.0 * ureg.millimeter, material=reticular_material, ) absorbing_inclusion = Sphere( name="Absorbing inclusion", center=np.array([-1.3, 0, 1.8]) * ureg.millimeter, radius=0.65 * ureg.millimeter, material=inclusion_material, ) scattering_inclusion = Sphere( name="Scattering inclusion", center=np.array([1.5, 0, 2.5]) * ureg.millimeter, radius=0.5 * ureg.millimeter, material=second_inclusion_material, ) rectangular_region = Box( name="Rectangular heterogeneity", origin=(-4, -1.25, 3.3) * ureg.millimeter, size=(1.5, 2.5, 0.9) * ureg.millimeter, material=box_material, ) sample.add_structures( absorbing_inclusion, scattering_inclusion, rectangular_region, ) .. GENERATED FROM PYTHON SOURCE LINES 153-157 Explore the sample in 3D ------------------------ Rotate the geometry and toggle regions in the legend. Transparent surfaces show primitive boundaries; the section below resolves overlaps. .. GENERATED FROM PYTHON SOURCE LINES 157-162 .. code-block:: Python figure = sample.plot( show=False, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 163-167 Configure a finite-sample solve --------------------------------- Use equal refractive indices across all regions because internal refraction at refractive-index jumps is outside the current continuous-fluence FEM model. .. GENERATED FROM PYTHON SOURCE LINES 167-194 .. code-block:: Python mesh = TetrahedralMesh.from_sample( sample=sample, resolution=0.6 * ureg.millimeter, ) source = UniformSurfaceSource( face="z_min", wavelength=970 * ureg.nanometer, optical_power=1 * ureg.milliwatt, ) boundary = RobinBoundary( effective_reflectance=0.5, ) solver = P1( boundaries=MomentRT.Boundaries.uniform(condition=boundary), ) simulation = Simulation( medium=sample, source=source, mesh=mesh, solver=solver, ) .. GENERATED FROM PYTHON SOURCE LINES 195-199 Solve and inspect fluence in 3D ---------------------------------- The volume interpolates the nodal fluence onto a separate display grid. Refine the tetrahedral mesh to assess spatial accuracy. .. GENERATED FROM PYTHON SOURCE LINES 199-210 .. code-block:: Python result = simulation.run() fluence_figure = result.fluence.plot( view="volume", scale="log", display_resolution=0.4 * ureg.millimeter, show=False, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 211-215 Inspect the resolved cross-section ---------------------------------- Unlike transparent construction surfaces, this map resolves material replacement. The y=0 plane intersects both spheres and the box. .. GENERATED FROM PYTHON SOURCE LINES 215-223 .. code-block:: Python section_figure = sample.plot_section( normal="y", position=0 * ureg.millimeter, show=False, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 224-227 Inspect the modeled geometry ---------------------------- This view shows the configured geometry and instrument footprints. .. GENERATED FROM PYTHON SOURCE LINES 227-229 .. 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 1.155 seconds) .. _sphx_glr_download_gallery_getting_started_structured_sample.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: structured_sample.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: structured_sample.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: structured_sample.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_