From 20e277da5621c5659de3aaf338c58541590562d2 Mon Sep 17 00:00:00 2001 From: chrisbrahms Date: Wed, 2 Aug 2023 08:36:29 +0100 Subject: [PATCH] add :x and :y polarisation --- src/Interface.jl | 21 ++++++++++++--------- test/test_interface.jl | 9 +++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Interface.jl b/src/Interface.jl index 1dc825a4..f79cc1bc 100644 --- a/src/Interface.jl +++ b/src/Interface.jl @@ -36,7 +36,7 @@ peak power specified. - `mode::Symbol`: Mode in which this input should be coupled. Can be `:lowest` for the lowest-order mode in the simulation, or a mode designation (e.g. `:HE11`, `:HE12`, `:TM01`, etc.). Defaults to `:lowest`. -- `polarisation`: Can be `:linear`, `:circular`, or an ellipticity number -1 ≤ ε ≤ 1, +- `polarisation`: Can be `:linear`, `:x`, `:y`, `:circular`, or an ellipticity number -1 ≤ ε ≤ 1, where ε=-1 corresponds to left-hand circular, ε=1 to right-hand circular, and ε=0 to linear polarisation. - `propagator`: A function `propagator!(Eω, grid)` which **mutates** its first argument to @@ -71,7 +71,7 @@ specified. - `mode::Symbol`: Mode in which this input should be coupled. Can be `:lowest` for the lowest-order mode in the simulation, or a mode designation (e.g. `:HE11`, `:HE12`, `:TM01`, etc.). Defaults to `:lowest`. -- `polarisation`: Can be `:linear`, `:circular`, or an ellipticity number -1 ≤ ε ≤ 1, +- `polarisation`: Can be `:linear`, `:x`, `:y`, `:circular`, or an ellipticity number -1 ≤ ε ≤ 1, where ε=-1 corresponds to left-hand circular, ε=1 to right-hand circular, and ε=0 to linear polarisation. - `propagator`: A function `propagator!(Eω, grid)` which **mutates** its first argument to @@ -105,7 +105,7 @@ specified, and duration given either as `τfwhm` or `τw`. - `mode::Symbol`: Mode in which this input should be coupled. Can be `:lowest` for the lowest-order mode in the simulation, or a mode designation (e.g. `:HE11`, `:HE12`, `:TM01`, etc.). Defaults to `:lowest`. -- `polarisation`: Can be `:linear`, `:circular`, or an ellipticity number -1 ≤ ε ≤ 1, +- `polarisation`: Can be `:linear`, `:x`, `:y`, `:circular`, or an ellipticity number -1 ≤ ε ≤ 1, where ε=-1 corresponds to left-hand circular, ε=1 to right-hand circular, and ε=0 to linear polarisation. - `propagator`: A function `propagator!(Eω, grid)` which **mutates** its first argument to @@ -149,7 +149,7 @@ A custom pulse defined by tabulated data to be used with `prop_capillary`. - `mode::Symbol`: Mode in which this input should be coupled. Can be `:lowest` for the lowest-order mode in the simulation, or a mode designation (e.g. `:HE11`, `:HE12`, `:TM01`, etc.). Defaults to `:lowest`. -- `polarisation`: Can be `:linear`, `:circular`, or an ellipticity number -1 ≤ ε ≤ 1, +- `polarisation`: Can be `:linear`, `:x`, `:y`, `:circular`, or an ellipticity number -1 ≤ ε ≤ 1, where ε=-1 corresponds to left-hand circular, ε=1 to right-hand circular, and ε=0 to linear polarisation. - `propagator`: A function `propagator!(Eω, grid)` which **mutates** its first argument to @@ -280,8 +280,8 @@ In this case, all keyword arguments except for `λ0` are ignored. - `power`: Peak power **after any spectral phases are added**. - `pulseshape`: Shape of the transform-limited pulse. Can be `:gauss` for a Gaussian pulse or `:sech` for a sech² pulse. -- `polarisation`: Polarisation of the input pulse. Can be `:linear` (default), `:circular`, - or an ellipticity number -1 ≤ ε ≤ 1, where ε=-1 corresponds to left-hand circular, +- `polarisation`: Polarisation of the input pulse. Can be `:linear` (default), `:x`, `:y`, + `:circular`, or an ellipticity number -1 ≤ ε ≤ 1, where ε=-1 corresponds to left-hand circular, ε=1 to right-hand circular, and ε=0 to linear polarisation. The major axis for elliptical polarisation is always the y-axis. - `propagator`: A function `propagator!(Eω, grid)` which **mutates** its first argument to @@ -407,12 +407,13 @@ end function needpol(pol) if pol == :linear return false - elseif pol == :circular + elseif pol in (:circular, :x, :y) return true else - error("Polarisation must be :linear, :circular, or an ellipticity, not $pol") + error("Polarisation must be :linear, :circular, :x/:y, or an ellipticity, not $pol") end end + needpol(pol::Number) = true needpol(pulse::Pulses.AbstractPulse) = needpol(pulse.polarisation) needpol(pulses::Vector{<:Pulses.AbstractPulse}) = any(needpol, pulses) @@ -661,8 +662,10 @@ _findmode(mode_s, md) = _findmode([mode_s], md) function makeinputs(mode_s, λ0, pulse::Pulses.AbstractPulse) idcs = findmode(mode_s, pulse) (length(idcs) > 0) || error("Mode $(pulse.mode) not found in mode list: $mode_s") - if pulse.polarisation == :linear + if pulse.polarisation == :linear || pulse.polarisation == :x ((mode=idcs[1], fields=(pulse.field,)),) + elseif pulse.polarisation == :y + ((mode=idcs[2], fields=(pulse.field,)),) else (length(idcs) == 2) || error("Modes not set up for circular/elliptical polarisation") f1, f2 = ellfields(pulse) diff --git a/test/test_interface.jl b/test/test_interface.jl index 48dd0301..25bc81ef 100644 --- a/test/test_interface.jl +++ b/test/test_interface.jl @@ -21,6 +21,15 @@ old_logger = Logging.global_logger(logger) o2 = prop_capillary(args...; polarisation=:linear, modes=4, kwargs...) @test o1["Eω"][:, 1:2:end, :] ≈ o2["Eω"][:, :, :] end + @testset "x/y" begin + o1 = prop_capillary(args...; polarisation=:x, modes=4, kwargs...) + o2 = prop_capillary(args...; polarisation=:y, modes=4, kwargs...) + @test o1["Eω"][:, 1:2:end, :] ≈ o2["Eω"][:, 2:2:end, :] + @test all(iszero, o1["Eω"][:, 2:2:end, 1]) + @test isapprox(o1["stats"]["energy"][1, 1], kwargs.energy; rtol=1e-4) + @test isapprox(o2["stats"]["energy"][2, 1], kwargs.energy; rtol=1e-4) + @test all(iszero, o2["Eω"][:, 1:2:end, 1]) + end @testset "circular, $modes" for modes in (:HE11, :HE12, 1, 2) o1 = prop_capillary(args...; modes, polarisation=:circular, kwargs...) o2 = prop_capillary(args...; modes, polarisation=1.0, kwargs...)