Note
Go to the end to download the full example code.
Coherent and diffuse scattering in an absorbing ensemble#
Absorption belongs to the random-medium configuration, so every realization has a reproducible kappa field. Compare total intensity, the intensity of the mean scattered amplitude, and their difference through third Born order.
import matplotlib.pyplot as plt
from bornsim import ConvergenceReport, EnsembleSampling, GaussianMedium, Grid, Solver, Source
from bornsim.units import ureg
medium = GaussianMedium(
background_refractive_index=1.33,
refractive_index_std=0.002,
correlation_length=60 * ureg.nanometer,
extinction_coefficient=0.0005,
)
grid = Grid(
shape=(8, 8, 8),
spacing=30 * ureg.nanometer,
)
source = Source(wavelength=633 * ureg.nanometer)
solver = Solver(source=source, order=3)
ensemble_sampling = EnsembleSampling(realizations=8, seed=42)
result = solver.ensemble(
medium=medium,
grid=grid,
ensemble_sampling=ensemble_sampling,
)
averaged = result.azimuth_average()
figure, axis = plt.subplots(layout="constrained")
for label, data in (
("Total", averaged.differential),
("Coherent", averaged.coherent_differential),
("Diffuse", averaged.diffuse_differential),
):
axis.plot(result.angles.to("degree").magnitude, data.magnitude[-1], label=label)
axis.set(xlabel="Scattering angle (degrees)", ylabel="Differential coefficient (m⁻¹ sr⁻¹)")
axis.legend()
plt.show()
absorption_figure, absorption_axis = plt.subplots(layout="constrained")
absorption_axis.errorbar(
[1, 2, 3],
result.mu_a.to("1 / meter").magnitude,
yerr=result.mu_a_stderr.to("1 / meter").magnitude,
fmt="o-",
)
absorption_axis.set(xlabel="Cumulative scattering order", ylabel="Absorption coefficient (m⁻¹)", xticks=[1, 2, 3])
plt.show()
Statistical interpretation#
Coherent means squared sample-mean scattered amplitude, not the unscattered laser. Diffuse is the population-normalized sample variance of amplitudes. For N realizations its expectation is (N-1)/N times the true variance; with one realization it is zero, not evidence of no diffuse scattering. Increase ensemble size to assess these effects. Error bars here describe sampling uncertainty in absorption, not mesh errors or model validity.
Ensemble-size stability#
Shared initial seeds correlate the estimates. These are stability comparisons, not independent estimates of an error bar on the difference.
size_results = []
for count in (4, 8, 16):
seeds = EnsembleSampling(realizations=count, seed=42)
size_results.append(solver.ensemble(medium=medium, grid=grid, ensemble_sampling=seeds))
report = ConvergenceReport(results=tuple(size_results), labels=("4 seeds", "8 seeds", "16 seeds"))
print(report.summary())
Observable stability (not a physical-validity certificate):
4 seeds: mu_s=17.3245 m^-1, mu_a=9919.034467737558, residual=9.354673840879905e-11, stable=False
8 seeds: mu_s=17.7404 m^-1, mu_a=9918.220264466316, residual=9.375477992306911e-11, stable=False
Changes: {'mu_s': 0.02343873593135006, 'mu_a': 8.208493214641103e-05, 'g': 0.11485254677613699, 'phase_l1': 0.16452609011267225}
16 seeds: mu_s=15.9665 m^-1, mu_a=9918.270279016817, residual=9.375477992306911e-11, stable=False
Changes: {'mu_s': 0.0999915664222087, 'mu_a': 5.042668640212119e-06, 'g': 0.0013280618258851296, 'phase_l1': 0.010823332785659437}
Total running time of the script: (0 minutes 3.544 seconds)

