Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spectral fields and apodizing windows #30

Merged
merged 16 commits into from
Mar 9, 2024
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
name = "ElectricFields"
uuid = "2f84ce32-9bb1-11e8-0d9f-3dce90a4beca"
authors = ["Stefanos Carlström <[email protected]>"]
version = "0.2.2"
version = "0.2.3"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
Formatting = "59287772-0a20-5a39-b81b-1366585eb4c0"
Format = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"

[compat]
AbstractFFTs = "1.3"
FFTW = "1.3"
Formatting = "0.4"
Format = "1.3"
ForwardDiff = "0.10"
IntervalSets = "0.7"
Optim = "1.3"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"

[compat]
CondaPkg = "0.2"
Documenter = "0.27"
Documenter = "1"
FFTW = "1.3.0"
PythonPlot = "1"
Unitful = "1.7"
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ makedocs(;
),
pages=[
"Home" => "index.md",
"Interface" => "interface.md",
"Field types" => "field_types.md",
"Envelopes" => "envelopes.md",
"Carriers" => "carriers.md",
Expand Down
74 changes: 74 additions & 0 deletions docs/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,78 @@ function index_spectrum_example()
end
end

function apodized_field()
@field(F) do
ω = 1.0
I₀ = 1.0
ramp = 0.0
flat = 3.0
env = :tophat
end

t = timeaxis(F)
tplot = 24.2e-3t

tmin = 1.0
tmax = 14.0

Fw = ApodizedField(F, tmin, tmax, ElectricFields.Kaiser(3))

Fv = field_amplitude(F, t)
Av = vector_potential(F, t)

Fwv = field_amplitude(Fw, t)
Awv = vector_potential(Fw, t)

w = ElectricFields.window_value.(Fw.window, 1.0, 14.0, t)

savedfigure("apodized_field", figsize=(7,8)) do
csubplot(211, nox=true) do
plot(tplot, Fv)
plot(tplot, Fwv)
ylabel(L"F(t)")
end
csubplot(212) do
plot(tplot, Av, label="Original field")
plot(tplot, Awv, label="Windowed field")
plot(tplot, w, "--", label="Window")
legend(loc=1)
xlabel(L"$t$ [fs]")
ylabel(L"A(t)")
end
end
end

function apodizing_windows()
x = range(-0.55, stop=0.55, length=1001)

savedfigure("windows", figsize=(7,8)) do
ws = (ElectricFields.Hann(), ElectricFields.Hamming(),
ElectricFields.Blackman(),
ElectricFields.BlackmanExact(),
ElectricFields.Nuttall(),
ElectricFields.BlackmanNuttall(),
ElectricFields.BlackmanHarris(),
ElectricFields.Kaiser(3), ElectricFields.Kaiser(2),
ElectricFields.Rect())

csubplot(211, nox=true) do
for w in ws
plot(x, ElectricFields.window_value.(w, x), label=string(w))
end
ylabel(L"w(x)")
end
csubplot(212) do
for w in ws
plot(x, ElectricFields.window_derivative.(w, x), label=string(w))
end
legend(loc=1, ncol=2)
xlabel(L"$t$ [fs]")
ylabel(L"w'(x)")
end
end
end

macro echo(expr)
println(expr)
:(@time $expr)
Expand All @@ -176,3 +248,5 @@ mkpath(fig_dir)
@echo index_example()
@echo index_polarized_example()
@echo index_spectrum_example()
@echo apodized_field()
@echo apodizing_windows()
84 changes: 84 additions & 0 deletions docs/src/field_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
```@docs
ElectricFields.LinearField
ElectricFields.TransverseField
ElectricFields.LinearTransverseField
ElectricFields.ConstantField
ElectricFields.Ramp
```
Expand All @@ -16,4 +17,87 @@ ElectricFields.NegatedField
ElectricFields.DelayedField
ElectricFields.PaddedField
ElectricFields.WindowedField
ElectricFields.phase_shift
```

## Apodizing Windows

This is a generalization of [`ElectricFields.WindowedField`](@ref),
where the field is multiplied by an [_apodizing
window_](https://en.wikipedia.org/wiki/Window_function), that tapers
of towards the boundaries, and typically (but not always) is zero at
the boundaries. The window functions are non-zero on the interval
``[-1/2,1/2]``, so if other intervals are desired, they will need to
be rescaled. This happens automatically.

Since the apodizing window is multiplied with the vector potential,
the field amplitude gains an extra term due to the chain rule:
```math
\vec{A}_w(t) =
W(t)\vec{A}(t)
\implies
\vec{F}_w(t) =
-\partial_t
\vec{A}_w(t) =
W(t)\vec{F}(t) -
W'(t)\vec{A}(t).
```

### Usage

```julia-repl
julia> @field(F) do
ω = 1.0
I₀ = 1.0
ramp = 0.0
flat = 3.0
env = :tophat
end
Linearly polarized field with
- I₀ = 1.0000e+00 au = 3.5094452e16 W cm⁻² =>
- E₀ = 1.0000e+00 au = 514.2207 GV m⁻¹
- A₀ = 1.0000 au
– a Fixed carrier @ λ = 45.5634 nm (T = 151.9830 as, ω = 1.0000 Ha = 27.2114 eV, f = 6.5797 PHz)
– and a /0‾3‾0\ cycles trapezoidal envelope
– and a bandwidth of Inf Ha = Inf eV ⟺ Inf Hz ⟺ Inf Bohr = Inf m
– Uₚ = 0.2500 Ha = 6.8028 eV => α = 1.0000 Bohr = 52.9177 pm

julia> Fw = ApodizedField(F, 1.0, 14.0, ElectricFields.Kaiser(3))
Kaiser(α = 3) window from 1.0000 jiffies = 24.1888 as to 14.0000 jiffies = 338.6438 as of
Linearly polarized field with
- I₀ = 1.0000e+00 au = 3.5094452e16 W cm⁻² =>
- E₀ = 1.0000e+00 au = 514.2207 GV m⁻¹
- A₀ = 1.0000 au
– a Fixed carrier @ λ = 45.5634 nm (T = 151.9830 as, ω = 1.0000 Ha = 27.2114 eV, f = 6.5797 PHz)
– and a /0‾3‾0\ cycles trapezoidal envelope
– and a bandwidth of Inf Ha = Inf eV ⟺ Inf Hz ⟺ Inf Bohr = Inf m
– Uₚ = 0.2500 Ha = 6.8028 eV => α = 1.0000 Bohr = 52.9177 pm
```

![Apodized field](figures/apodized_field.svg)

```@docs
ApodizedField
span(::ApodizedField)
```

### Windows

See the [Wikipedia page on apodizing
windows](https://en.wikipedia.org/wiki/Window_function) for the formal
definitions of the windows and their frequency responses.

![Apodizing windows](figures/windows.svg)

```@docs
ElectricFields.AbstractWindow
ElectricFields.Rect
ElectricFields.Hann
ElectricFields.Hamming
ElectricFields.Blackman
ElectricFields.BlackmanExact
ElectricFields.Nuttall
ElectricFields.BlackmanNuttall
ElectricFields.BlackmanHarris
ElectricFields.Kaiser
```
6 changes: 3 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ Linearly polarized field with
– Uₚ = 0.2196 Ha = 5.9759 eV => α = 16.4562 Bohr = 870.8242 pm

julia> vector_potential(IR, 4.0)
0.21160647961322301
0.21160647961322293

julia> field_amplitude(IR, 4.0), field_envelope(IR, 4.0)
(-0.05194703530281701, 0.05336224984361336)
(-0.05194703530281699, 0.05336224984361333)

julia> instantaneous_intensity(IR, 4.0), intensity(IR, 4.0)
(0.0026984944767521166, 0.002847529708372214)
(0.0026984944767521144, 0.0028475297083722113)

julia> span(IR)
-661.9198939608042 .. 661.9198939608042
Expand Down
33 changes: 33 additions & 0 deletions docs/src/interface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Interface

## Creation

```@docs
ElectricFields.@field
```

## Time-dependent quantities

```@docs
ElectricFields.field_amplitude
ElectricFields.vector_potential
ElectricFields.instantaneous_intensity
ElectricFields.intensity(::LinearPolarization, f, t::Number; kwargs...)
ElectricFields.field_envelope
ElectricFields.span
ElectricFields.timeaxis
ElectricFields.steps
```

## Spectra

```@docs
ElectricFields.spectrum
ElectricFields.field_amplitude_spectrum
ElectricFields.vector_potential_spectrum
ElectricFields.AbstractFFTs.fft
ElectricFields.nfft
ElectricFields.fft_vector_potential
ElectricFields.nfft_vector_potential
ElectricFields.fftω
```
1 change: 1 addition & 0 deletions docs/src/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ max_frequency
wavenumber
photon_energy
duration
time_bandwidth_product
continuity
fluence
intensity
Expand Down
15 changes: 12 additions & 3 deletions docs/src/reference.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# Reference

```@index
## Internals

```@docs
ElectricFields.calc_params!
ElectricFields.@namespace!
ElectricFields.gaussian_common!
ElectricFields.test_field_parameters
ElectricFields.convolution
ElectricFields.DiracComb
```

```@autodocs
Modules = [ElectricFields]
## Index

```@index
```
3 changes: 2 additions & 1 deletion src/ElectricFields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ using FFTW
using ForwardDiff
using Optim
using Roots
using SpecialFunctions

using IntervalSets

using Parameters

import Base: show
using Formatting
using Format

abstract type AbstractField end

Expand Down
Loading
Loading