### A Pluto.jl notebook ###
# v1.0.0

using Markdown
using InteractiveUtils

# ╔═╡ c4fb43ea-6ce9-4576-85d8-7cb3e8554f03
begin
    import Pkg
    Pkg.activate(joinpath(@__DIR__, ".."))
    using CoupledDipole
    using CairoMakie
end

# ╔═╡ f4634f74-bfef-48a1-beca-e3294be8ac7e
md"""
# Core-shell orientation-averaged spectra

This notebook evaluates `simulate_core_shell` with three interaction settings:

- sphere-mediated coupling + self-reaction (`full`),
- sphere-mediated coupling without mediated self-reaction (`no self-reaction`),
- no sphere-mediated dipole-dipole coupling (`uncoupled`).

The output matrix columns are:
`[cext, cabs, csca, dext, dabs, dsca, cd_ext, cd_abs, cd_sca]`,
all normalized per shell dipole.
"""

# ╔═╡ 77f6675f-5267-4d70-968e-f83f35394db4
begin
    wavelengths = collect(380.0:2.0:580.0)
    rho_dye = 0.5
    tensor_type = 1      # isotropic radial
    position_type = 1    # fibonacci
    medium = 1.33
    R0 = 3.0
    d = 0.5
    N_inc = 8
    N_sca = 10
    N_mie = 16
    N_esa = 120
    N_theta = 241
end

# ╔═╡ 9484f461-3c4f-4e59-a258-3f4b6eae1d2e
begin
    x_full = simulate_core_shell(
        rho_dye,
        tensor_type,
        position_type,
        wavelengths,
        medium,
        R0,
        d,
        N_inc;
        N_sca=N_sca,
        N_mie=N_mie,
        N_esa=N_esa,
        N_theta=N_theta,
        coupling=true,
        self_reaction=true,
    )

    x_no_self = simulate_core_shell(
        rho_dye,
        tensor_type,
        position_type,
        wavelengths,
        medium,
        R0,
        d,
        N_inc;
        N_sca=N_sca,
        N_mie=N_mie,
        N_esa=N_esa,
        N_theta=N_theta,
        coupling=true,
        self_reaction=false,
    )

    x_uncoupled = simulate_core_shell(
        rho_dye,
        tensor_type,
        position_type,
        wavelengths,
        medium,
        R0,
        d,
        N_inc;
        N_sca=N_sca,
        N_mie=N_mie,
        N_esa=N_esa,
        N_theta=N_theta,
        coupling=false,
        self_reaction=true,
    )

    @assert all(isfinite, x_full)
    @assert all(isfinite, x_no_self)
    @assert all(isfinite, x_uncoupled)
end

# ╔═╡ 68f1535b-faad-411f-a94c-12341ce8f67f
let
    fig = Figure(size=(900, 390))
    ax1 = Axis(fig[1, 1], xlabel="Wavelength / nm", ylabel="Extinction / nm² per dye")
    ax2 = Axis(fig[1, 2], xlabel="Wavelength / nm", ylabel="Differential absorption / nm² per dye")

    lines!(ax1, wavelengths, x_full[:, 1], label="full")
    lines!(ax1, wavelengths, x_no_self[:, 1], label="no self-reaction")
    lines!(ax1, wavelengths, x_uncoupled[:, 1], label="uncoupled")
    axislegend(ax1, position=:rt)

    lines!(ax2, wavelengths, x_full[:, 5], label="full")
    lines!(ax2, wavelengths, x_no_self[:, 5], label="no self-reaction")
    lines!(ax2, wavelengths, x_uncoupled[:, 5], label="uncoupled")
    axislegend(ax2, position=:rt)

    fig
end

# ╔═╡ 83079c61-bd81-45c0-a255-9b4311510c9e


# ╔═╡ Cell order:
# ╠═c4fb43ea-6ce9-4576-85d8-7cb3e8554f03
# ╟─f4634f74-bfef-48a1-beca-e3294be8ac7e
# ╠═77f6675f-5267-4d70-968e-f83f35394db4
# ╠═9484f461-3c4f-4e59-a258-3f4b6eae1d2e
# ╠═68f1535b-faad-411f-a94c-12341ce8f67f
# ╠═83079c61-bd81-45c0-a255-9b4311510c9e
