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

using Markdown
using InteractiveUtils

# ╔═╡ a3f67a9f-9742-45b4-a0df-bc769f2d5932
begin
    import Pkg
    Pkg.activate(joinpath(@__DIR__, ".."))
    using CoupledDipole
    using CairoMakie
end

# ╔═╡ ed0f7ad4-7069-4de0-862f-2c159cc4bce0
md"""
# Core-shell CDA vs effective multilayer-Mie

This notebook compares:

- explicit shell dipoles around a core (`simulate_core_shell`), and
- an effective homogeneous shell in multilayer Mie (`simulate_mie`).

Both return per-dye cross-sections `[cext, cabs, csca]` in nm².
The Mie curve is also shown with local-field normalization (`mloc=true`).
"""

# ╔═╡ e8f11690-a31f-48b2-8b99-5a8cb1489303
begin
    wavelengths = collect(380.0:2.0:680.0)
    rho_dye = 0.15
    medium = 1.33
    R0 = 3.0
    d = 0.2
    spacer = 1.0

    tensor_type = 1      # isotropic radial
    position_type = 1    # fibonacci
    N_inc = 8
end

# ╔═╡ 7f6fc6f5-ef82-4346-8382-b3e78a73f3d1
begin
    x_cda = simulate_core_shell(
        rho_dye,
        tensor_type,
        position_type,
        wavelengths,
        medium,
        R0,
        d,
        N_inc;
        N_sca=10,
        N_mie=16,
        N_esa=120,
        N_theta=241,
        coupling=true,
        self_reaction=true,
    )

    x_mie = simulate_mie(rho_dye, R0, d, spacer, wavelengths, medium, 20, false, false)
    x_mie_mloc = simulate_mie(rho_dye, R0, d, spacer, wavelengths, medium, 20, false, true)

    @assert size(x_cda, 1) == length(wavelengths)
    @assert size(x_mie, 1) == length(wavelengths)
    @assert all(isfinite, x_cda)
    @assert all(isfinite, x_mie)
    @assert all(isfinite, x_mie_mloc)
end

# ╔═╡ 66a3505f-2f5d-4f7b-93ba-c26b2e1df90f
let
    fig = Figure(size=(900, 700))
    ax1 = Axis(fig[1, 1], xlabel="Wavelength / nm", ylabel="Extinction / nm² per dye")
    ax2 = Axis(fig[1, 2], xlabel="Wavelength / nm", ylabel="Absorption / nm² per dye")
    ax3 = Axis(fig[2, 1], xlabel="Wavelength / nm", ylabel="Scattering / nm² per dye")
    ax4 = Axis(fig[2, 2], xlabel="Wavelength / nm", ylabel="Extinction ratio (Mie/CDA)")

    lines!(ax1, wavelengths, x_cda[:, 1], label="CDA shell")
    lines!(ax1, wavelengths, x_mie[:, 1], label="Mie effective shell")
    lines!(ax1, wavelengths, x_mie_mloc[:, 1], label="Mie effective shell (mloc)")
    axislegend(ax1, position=:rb)

    lines!(ax2, wavelengths, x_cda[:, 2], label="CDA shell")
    lines!(ax2, wavelengths, x_mie[:, 2], label="Mie effective shell")
    lines!(ax2, wavelengths, x_mie_mloc[:, 2], label="Mie effective shell (mloc)")

    lines!(ax3, wavelengths, x_cda[:, 3], label="CDA shell")
    lines!(ax3, wavelengths, x_mie[:, 3], label="Mie effective shell")
    lines!(ax3, wavelengths, x_mie_mloc[:, 3], label="Mie effective shell (mloc)")

    lines!(ax4, wavelengths, x_mie[:, 1] ./ x_cda[:, 1], label="raw")
    lines!(ax4, wavelengths, x_mie_mloc[:, 1] ./ x_cda[:, 1], label="mloc")
    hlines!(ax4, [1.0], color=:black, linestyle=:dash)
    axislegend(ax4, position=:rb)

    fig
end

# ╔═╡ Cell order:
# ╠═a3f67a9f-9742-45b4-a0df-bc769f2d5932
# ╟─ed0f7ad4-7069-4de0-862f-2c159cc4bce0
# ╠═e8f11690-a31f-48b2-8b99-5a8cb1489303
# ╠═7f6fc6f5-ef82-4346-8382-b3e78a73f3d1
# ╠═66a3505f-2f5d-4f7b-93ba-c26b2e1df90f
