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

using Markdown
using InteractiveUtils

# ╔═╡ a7beac6a-2699-4515-a36b-a6577064e131
begin
    import Pkg
    Pkg.activate(joinpath(@__DIR__, ".."))
    using CoupledDipole
    using CairoMakie
    using StaticArrays
    using Rotations
end

# ╔═╡ 05239faa-c453-4fc9-ac08-39718c8e0ed7
md"""
# Near field of a gold-sphere chain

Five 10 nm-radius gold spheres, spaced by 80 nm in water, are illuminated at
633 nm along z. The first linear polarisation is along x. We plot total
electric intensity relative to the unit incident intensity in the xy plane.
The point-dipole approximation is not a resolved internal-field model:
probes inside particles are excluded from the plot.
"""

# ╔═╡ 38ca2d45-77c2-48d1-a2be-2d38cb677b22
begin
    material = Material([633.0], Dict("Au" => epsilon_Au, "medium" => λ -> 1.33))
    cluster = cluster_chain(5, 80, 10, 10, 10)
    x = collect(-220.0:5.0:220.0)
    y = collect(-80.0:5.0:80.0)
    probes = [SVector(xi, yi, 0.0) for xi in x, yi in y][:]
end

# ╔═╡ c3a39758-5894-4466-812f-e38c016ed05b
begin
    intensity, _, _, positions = map_nf(probes, cluster, material, [RotZ(0.0)];
        evaluate_inside=false)
    @assert size(intensity) == (length(probes), 2)
    @assert all(isfinite, intensity[.!positions.inside, :])
    outside_intensity = copy(intensity[:, 1])
    outside_intensity[positions.inside] .= NaN
end

# ╔═╡ 5639aefc-53e4-4081-9590-2acc042b194c
let
    fig = Figure(size=(750, 350))
    ax = Axis(fig[1, 1], xlabel="x / nm", ylabel="y / nm", aspect=DataAspect())
    hm = heatmap!(ax, x, y, reshape(outside_intensity, length(x), length(y));
        colormap=:viridis)
    Colorbar(fig[1, 2], hm; label="Total |E|^2 / incident |E|^2")
    fig
end

# ╔═╡ Cell order:
# ╠═a7beac6a-2699-4515-a36b-a6577064e131
# ╟─05239faa-c453-4fc9-ac08-39718c8e0ed7
# ╠═38ca2d45-77c2-48d1-a2be-2d38cb677b22
# ╠═c3a39758-5894-4466-812f-e38c016ed05b
# ╠═5639aefc-53e4-4081-9590-2acc042b194c
