Visualization of Fields

This package provides several means to directly visualize quantities of the scattering setup.

Note

In order to make the plotting functionality available the package PlotlyJS has to be loaded. (It is a weak dependency.)

Plotting Far-Field Patterns

As an example consider a Hertzian dipole that excites a PEC sphere:

using SphericalScattering
using LinearAlgebra, StaticArrays

# --- excite PEC sphere by Hertzian dipole
orient = normalize(SVector(0.0,1.0,1.0))
ex = HertzianDipole(frequency=1e8, orientation=orient, position=2*orient)

sp = PECSphere(radius = 1.0)

# --- evaluate fields at spherical grid points
points_cart, points_sph = sphericalGridPoints()

FF = scatteredfield(sp, ex, FarField(points_cart))

The 3D pattern can then be evaluated as

using PlotlyJS
plotff(FF, points_sph, scale="linear", normalize=true, type="abs")

Alternatively, the field of the dipole itself or the total field can be plotted:

FF = field(sp, ex, FarField(points_cart)) # total field

# --- plot only the φ-component in logarithmic scale
plotff(FF, points_sph, scale="log", normalize=true, type="phi")

Plotting Far-Field Cuts

Sphercial cuts can be conveniently obtained by:

using SphericalScattering
using LinearAlgebra, StaticArrays

# --- excite PEC sphere by magnetic ring current
orient = normalize(SVector(0.0,1.0,1.0))
ex = magneticRingCurrent(frequency=1e8, orientation=orient, center=2*orient, radius=0.2)

sp = PECSphere(radius = 1.0)

# --- evaluate fields at φ = 5° cut
points_cart, points_sph = phiCutPoints(5) # analogously, thetaCutPoints can be used

FF = scatteredfield(sp, ex, FarField(points_cart))

Progress:  62%[=========================>               ]  ETA: 0:00:00
Progress: 100%[=========================================] Time: 0:00:00

The cut can then be plotted as:

using PlotlyJS
plotffcut(norm.(FF), points_sph, normalize=true, scale="log", format="polar")

Plotting Near-Field Cuts

The near-field of an electric ring current can, e.g., be visualized in the xz-plane as:

using SphericalScattering
using LinearAlgebra, StaticArrays

f = 1e8             # frequency
c = 2.99792458e8    # speed of light
λ = c / f           # wavelength

ex = electricRingCurrent(frequency=1e8, center=SVector(0.,0,0), radius=3*λ)

# --- define points in the xz plane
res = λ/15

points_cart = [SVector(x, 0.0, z) for z in -5λ:res:5λ, x in -5λ:res:5λ]
points_sph = SphericalScattering.cart2sph.(points_cart)

# --- evaluate the fields
E = field(ex, ElectricField(points_cart))

To plot the fields a heatmap can be employed:

using PlotlyJS

# --- convert data to spherical coordinates
Esph = SphericalScattering.convertCartesian2Spherical.(E, points_sph)
Eφ = [Esph[i][3] for (i, j) in enumerate(Esph)] # extract φ-component

# --- truncate large values (for plot)
data = abs.(Eφ)
data[data .> 250] .= 250

# --- plot heatmap
layout = Layout(
    yaxis=attr(title_text="y/λ"),
    xaxis=attr(title_text="x/λ")
)

plot(heatmap(x=-5:1/15:5,y=-5:1/15:5,z=data, colorscale="Jet"), layout)

Or instead of the magnitude a snapshot can be plotted

data = real.(Eφ)
data[data .> 250] .= 250

# --- plot heatmap
layout = Layout(
    yaxis=attr(title_text="y/λ"),
    xaxis=attr(title_text="x/λ")
)

plot(heatmap(x=-5:1/15:5,y=-5:1/15:5,z=data, colorscale="Jet"), layout)