Skip to content

Commit

Permalink
Merge pull request #147 from jtravs/fields
Browse files Browse the repository at this point in the history
RFC: possible Fields module
  • Loading branch information
jtravs authored Apr 23, 2020
2 parents d3b6e72 + 0abedec commit 0a87315
Show file tree
Hide file tree
Showing 50 changed files with 1,447 additions and 1,039 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ deps/deps.jl
Manifest.toml
_git2_*
docs/build
*.info
16 changes: 2 additions & 14 deletions docs/src/scans.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ The first step is to write a standard Luna script to run a *single* simulation i
```julia
# Lots of setup work...
gausspulse = let τ=30e-15, λ=λ0
function gausspulse(t)
It = Maths.gauss(t, fwhm=τ)
ω0 = 2π*PhysData.c/λ0
Et = @. sqrt(It)*cos(ω0*t)
end

end
in1 = (func=gausspulse, energy=1e-6)
inputs = (in1, )
Expand Down Expand Up @@ -38,15 +34,7 @@ Then, make the following changes:

@scan begin
# Lots of setup work...
gausspulse = let τ=$τ, λ=λ0
function gausspulse(t)
It = Maths.gauss(t, fwhm=τ)
ω0 = 2π*PhysData.c/λ0
Et = @. sqrt(It)*cos(ω0*t)
end
end
in1 = (func=gausspulse, energy=$energy)
inputs = (in1, )
inputs = Fields.GaussField(λ0=λ0, τfwhm=$τ, energy=$energy)
# More setup work...
Luna.run(...) # run the simulation
end
Expand Down
43 changes: 19 additions & 24 deletions examples/MI_modeAvg_env.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
import Luna
import Luna: Grid, Maths, Capillary, PhysData, Nonlinear, Ionisation, NonlinearRHS, Output, Stats, LinearOps, Modes
import Logging
import FFTW
import NumericalIntegration: integrate, SimpsonEven
Logging.disable_logging(Logging.BelowMinLevel)

import PyPlot:pygui, plt
using Luna

a = 15e-6
gas = :Ar
pres = 25

τ = 600e-15
τfwhm = 600e-15
λ0 = 800e-9
flength = 80e-2
energy = 10e-6

grid = Grid.EnvGrid(80e-2, 800e-9, (220e-9, 3000e-9), 4e-12)
grid = Grid.EnvGrid(flength, λ0, (220e-9, 3000e-9), 4e-12)

m = Capillary.MarcatilliMode(a, gas, pres, loss=false)
aeff(z) = Modes.Aeff(m, z=z)

energyfun = NonlinearRHS.energy_modal()

function gausspulse(t)
It = Maths.gauss(t, fwhm=τ)
ω0 = 2π*PhysData.c/λ0
Et = @. sqrt(It)
end
energyfun, energyfunω = Fields.energyfuncs(grid)

dens0 = PhysData.density(gas, pres)
densityfun(z) = dens0
Expand All @@ -40,16 +29,22 @@ ionrate = Ionisation.ionrate_fun!_ADK(ionpot)
responses = (Nonlinear.Kerr_env(PhysData.γ3_gas(gas)),)
# Nonlinear.PlasmaCumtrapz(grid.to, grid.to, ionrate, ionpot))

in1 = (func=gausspulse, energy=10e-6)
inputs = (in1, )
inputs = (Fields.GaussField(λ0=λ0, τfwhm=τfwhm, energy=energy), Fields.ShotNoise())

Eω, transform, FT = Luna.setup(grid, energyfun, densityfun, normfun, responses, inputs, aeff)
Luna.shotnoise!(Eω, grid)
Eω, transform, FT = Luna.setup(grid, densityfun, normfun, responses, inputs, aeff)

statsfun = Stats.collect_stats((Stats.ω0(grid), ))
output = Output.MemoryOutput(0, grid.zmax, 201, (length(grid.ω),), statsfun)
statsfun = Stats.collect_stats(grid, Eω,
Stats.ω0(grid),
Stats.energy(grid, energyfunω),
Stats.peakpower(grid),
Stats.fwhm_t(grid),
Stats.density(densityfun))
output = Output.MemoryOutput(0, grid.zmax, 201, statsfun)
Luna.run(Eω, grid, linop, transform, FT, output)

import FFTW
import PyPlot:pygui, plt

ω = grid.ω
t = grid.t
f = FFTW.fftshift(ω, 1)./2π.*1e-15
Expand All @@ -68,7 +63,7 @@ zpeak = argmax(dropdims(maximum(It, dims=1), dims=1))

energy = zeros(length(zout))
for ii = 1:size(Etout, 2)
energy[ii] = energyfun(t, Etout[:, ii])
energy[ii] = energyfun(Etout[:, ii])
end

pygui(true)
Expand Down
27 changes: 10 additions & 17 deletions examples/Raman/Raman_modeAvg.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
using Luna
import Logging
import FFTW
Logging.disable_logging(Logging.BelowMinLevel)

a = 13e-6
gas = :H2
pres = 5
flength = 200e-2

τ = 20e-15
τfwhm = 20e-15
λ0 = 800e-9
energy = 1e-6

grid = Grid.RealGrid(200e-2, 800e-9, (180e-9, 3000e-9), 4e-12)
grid = Grid.RealGrid(flength, λ0, (180e-9, 3000e-9), 4e-12)

m = Capillary.MarcatilliMode(a, gas, pres, loss=false)
aeff(z) = Modes.Aeff(m, z=z)

energyfun, energyfunω = NonlinearRHS.energy_modal(grid)

function gausspulse(t)
It = Maths.gauss(t, fwhm=τ)
ω0 = 2π*PhysData.c/λ0
Et = @. sqrt(It)*cos(ω0*t)
end
energyfun, energyfunω = Fields.energyfuncs(grid)

dens0 = PhysData.density(gas, pres)
densityfun(z) = dens0
Expand All @@ -34,10 +26,9 @@ linop, βfun, frame_vel, αfun = LinearOps.make_const_linop(grid, m, λ0)

normfun = NonlinearRHS.norm_mode_average(grid.ω, βfun, aeff)

in1 = (func=gausspulse, energy=energy)
inputs = (in1, )
inputs = Fields.GaussField(λ0=λ0, τfwhm=τfwhm, energy=energy)

Eω, transform, FT = Luna.setup(grid, energyfun, densityfun, normfun, responses, inputs, aeff)
Eω, transform, FT = Luna.setup(grid, densityfun, normfun, responses, inputs, aeff)

statsfun = Stats.collect_stats(grid, Eω,
Stats.ω0(grid),
Expand All @@ -46,10 +37,12 @@ statsfun = Stats.collect_stats(grid, Eω,
Stats.peakintensity(grid, aeff),
Stats.fwhm_t(grid),
Stats.density(densityfun))
output = Output.MemoryOutput(0, grid.zmax, 201, (length(grid.ω),), statsfun)
output = Output.MemoryOutput(0, grid.zmax, 201, statsfun)

Luna.run(Eω, grid, linop, transform, FT, output)

import FFTW

ω = grid.ω
t = grid.t

Expand All @@ -69,7 +62,7 @@ zpeak = argmax(dropdims(maximum(It, dims=1), dims=1))
Et = Maths.hilbert(Etout)
energy = zeros(length(zout))
for ii = 1:size(Etout, 2)
energy[ii] = energyfun(t, Etout[:, ii])
energy[ii] = energyfun(Etout[:, ii])
end

import PyPlot:pygui, plt
Expand Down
27 changes: 10 additions & 17 deletions examples/Raman/Raman_modeAvg_env.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
using Luna
import Logging
import FFTW
Logging.disable_logging(Logging.BelowMinLevel)

a = 13e-6
gas = :H2
pres = 5
flength = 200e-2

τ = 20e-15
τfwhm = 20e-15
λ0 = 800e-9
energy = 1e-6

grid = Grid.EnvGrid(200e-2, 800e-9, (180e-9, 3000e-9), 4e-12)
grid = Grid.EnvGrid(flength, λ0, (180e-9, 3000e-9), 4e-12)

m = Capillary.MarcatilliMode(a, gas, pres, loss=false)
aeff(z) = Modes.Aeff(m, z=z)

energyfun, energyfunω = NonlinearRHS.energy_modal(grid)

function gausspulse(t)
It = Maths.gauss(t, fwhm=τ)
Et = @. sqrt(It)
end
energyfun, energyfunω = Fields.energyfuncs(grid)

dens0 = PhysData.density(gas, pres)
densityfun(z) = dens0
Expand All @@ -33,22 +26,22 @@ linop, βfun, frame_vel, αfun = LinearOps.make_const_linop(grid, m, λ0)

normfun = NonlinearRHS.norm_mode_average(grid.ω, βfun, aeff)

in1 = (func=gausspulse, energy=energy)
inputs = (in1, )
inputs = Fields.GaussField(λ0=λ0, τfwhm=τfwhm, energy=energy)

Eω, transform, FT = Luna.setup(grid, energyfun, densityfun, normfun, responses, inputs, aeff)
Eω, transform, FT = Luna.setup(grid, densityfun, normfun, responses, inputs, aeff)

statsfun = Stats.collect_stats(grid, Eω,
Stats.ω0(grid),
Stats.energy(grid, energyfunω),
Stats.energy_λ(grid, energyfunω, (150e-9, 300e-9), label="RDW"),
Stats.peakpower(grid),
Stats.fwhm_t(grid),
Stats.density(densityfun))
output = Output.MemoryOutput(0, grid.zmax, 201, (length(grid.ω),), statsfun)
output = Output.MemoryOutput(0, grid.zmax, 201, statsfun)

Luna.run(Eω, grid, linop, transform, FT, output)

import FFTW

ω = grid.ω
t = grid.t
f = FFTW.fftshift(ω, 1)./2π.*1e-15
Expand All @@ -68,7 +61,7 @@ zpeak = argmax(dropdims(maximum(It, dims=1), dims=1))

energy = zeros(length(zout))
for ii = 1:size(Etout, 2)
energy[ii] = energyfun(t, Etout[:, ii])
energy[ii] = energyfun(Etout[:, ii])
end

import PyPlot:pygui, plt
Expand Down
32 changes: 12 additions & 20 deletions examples/Raman/Raman_modeAvg_noTHG.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import Luna
import Luna: Grid, Maths, Capillary, PhysData, Nonlinear, Ionisation, NonlinearRHS, Output, Stats, LinearOps, Modes, Raman
import Logging
import FFTW
Logging.disable_logging(Logging.BelowMinLevel)
using Luna

a = 13e-6
gas = :H2
pres = 5
flength = 200e-2

τ = 20e-15
τfwhm = 20e-15
λ0 = 800e-9
energy = 1e-6

grid = Grid.RealGrid(200e-2, 800e-9, (180e-9, 3000e-9), 4e-12)
grid = Grid.RealGrid(flength, λ0, (180e-9, 3000e-9), 4e-12)

m = Capillary.MarcatilliMode(a, gas, pres, loss=false)
aeff(z) = Modes.Aeff(m, z=z)

energyfun = NonlinearRHS.energy_modal()

function gausspulse(t)
It = Maths.gauss(t, fwhm=τ)
ω0 = 2π*PhysData.c/λ0
Et = @. sqrt(It)*cos(ω0*t)
end
energyfun, energyfunω = Fields.energyfuncs(grid)

dens0 = PhysData.density(gas, pres)
densityfun(z) = dens0
Expand All @@ -35,16 +26,17 @@ linop, βfun, frame_vel, αfun = LinearOps.make_const_linop(grid, m, λ0)

normfun = NonlinearRHS.norm_mode_average(grid.ω, βfun, aeff)

in1 = (func=gausspulse, energy=energy)
inputs = (in1, )
inputs = Fields.GaussField(λ0=λ0, τfwhm=τfwhm, energy=energy)

Eω, transform, FT = Luna.setup(grid, energyfun, densityfun, normfun, responses, inputs, aeff)
Eω, transform, FT = Luna.setup(grid, densityfun, normfun, responses, inputs, aeff)

statsfun = Stats.collect_stats((Stats.ω0(grid), ))
output = Output.MemoryOutput(0, grid.zmax, 201, (length(grid.ω),), statsfun)
statsfun = Stats.collect_stats(grid, Eω, Stats.ω0(grid))
output = Output.MemoryOutput(0, grid.zmax, 201, statsfun)

Luna.run(Eω, grid, linop, transform, FT, output)

import FFTW

ω = grid.ω
t = grid.t

Expand All @@ -64,7 +56,7 @@ zpeak = argmax(dropdims(maximum(It, dims=1), dims=1))
Et = Maths.hilbert(Etout)
energy = zeros(length(zout))
for ii = 1:size(Etout, 2)
energy[ii] = energyfun(t, Etout[:, ii])
energy[ii] = energyfun(Etout[:, ii])
end

import PyPlot:pygui, plt
Expand Down
37 changes: 14 additions & 23 deletions examples/arpcf_modeAvg.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
using Luna
import Logging
import FFTW
import NumericalIntegration: integrate, SimpsonEven
Logging.disable_logging(Logging.BelowMinLevel)

# import DSP.Unwrap: unwrap

import PyPlot:pygui, plt

a = 13e-6
gas = :Ar
pres = 5
flength = 15e-2

τ = 30e-15
τfwhm = 30e-15
λ0 = 800e-9
energy = 1e-6

grid = Grid.RealGrid(15e-2, 800e-9, (160e-9, 3000e-9), 1e-12)
grid = Grid.RealGrid(flength, λ0, (160e-9, 3000e-9), 1e-12)

m = Antiresonant.ZeisbergerMode(a, gas, pres, wallthickness=200e-9, loss=false)
aeff = let m=m
z -> Modes.Aeff(m, z=z)
end

energyfun, energyfunω = NonlinearRHS.energy_modal(grid)

function gausspulse(t)
It = Maths.gauss(t, fwhm=τ)
ω0 = 2π*PhysData.c/λ0
Et = @. sqrt(It)*cos(ω0*t)
end
energyfun, energyfunω = Fields.energyfuncs(grid)

dens0 = PhysData.density(gas, pres)
densityfun(z) = dens0
Expand All @@ -44,11 +32,10 @@ linop, βfun, β1, αfun = LinearOps.make_const_linop(grid, m, λ0)

normfun = NonlinearRHS.norm_mode_average(grid.ω, βfun, aeff)

in1 = (func=gausspulse, energy=1e-6)
inputs = (in1, )
inputs = Fields.GaussField(λ0=λ0, τfwhm=τfwhm, energy=energy)

Eω, transform, FT = Luna.setup(
grid, energyfun, densityfun, normfun, responses, inputs, aeff)
grid, densityfun, normfun, responses, inputs, aeff)

statsfun = Stats.collect_stats(grid, Eω,
Stats.ω0(grid),
Expand All @@ -59,9 +46,13 @@ statsfun = Stats.collect_stats(grid, Eω,
Stats.fwhm_t(grid),
Stats.electrondensity(grid, ionrate, densityfun, aeff),
Stats.density(densityfun))
output = Output.MemoryOutput(0, grid.zmax, 201, (length(grid.ω),), statsfun)
output = Output.MemoryOutput(0, grid.zmax, 201, statsfun)

Luna.run(Eω, grid, linop, transform, FT, output)

import FFTW
import PyPlot:pygui, plt

##
ω = grid.ω
t = grid.t
Expand All @@ -80,8 +71,8 @@ Itlog = log10.(Maths.normbymax(It))
zpeak = argmax(dropdims(maximum(It, dims=1), dims=1))

Et = Maths.hilbert(Etout)
energy = [energyfun(t, Etout[:, ii]) for ii=1:size(Etout, 2)]
energyω = [energyfunω(ω, Eout[:, ii]) for ii=1:size(Eout, 2)]
energy = [energyfun(Etout[:, ii]) for ii=1:size(Etout, 2)]
energyω = [energyfunω(Eout[:, ii]) for ii=1:size(Eout, 2)]

pygui(true)
##
Expand Down
Loading

0 comments on commit 0a87315

Please sign in to comment.