Skip to content

Commit

Permalink
Update Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
oashour committed Feb 10, 2021
1 parent 23f65f4 commit 18b164a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ include("HirotaSolvers.jl")
include("SSSolvers.jl")

"""
solve!(sim::Simulation)
solve!(sim::Sim)
Solves the `Simulation` object `sim` using the techniques its attributes specify.
Solves the `Sim` object `sim`.
See also: [`init_sim`](@ref), [`NLSS.Plotter.plot_ψ`](@ref)
See also: [`Sim`](@ref)
"""
function solve!(sim::Sim)
# Set initial condition
Expand Down
39 changes: 37 additions & 2 deletions src/Types.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

struct Box{TT<:Real}
t::Array{TT, 1}
ω::Array{TT, 1}
Expand All @@ -9,8 +10,13 @@ struct Box{TT<:Real}
n_periods::Int64
end

"""
function Box(xᵣ::Pair, T; dx, Nₓ, Nₜ, n_periods)
Create a `::Box` object with `Nₜ` transverse nodes, `Nₓ` longitudinal nodes (or `dx` grid spacing in the lontidunal direction, only one option can be specified), of size `[(xᵣ.first), (xᵣ.second)]` in the longitudinal direction and `[(-T*n_periods/2), (T*n_periods/2))`
"""
function Box(xᵣ::Pair, T; dx = 0.0, Nₓ = 0, Nₜ = 256, n_periods = 1)
@info "Initializing simulation box with $n_periods period(s) and dx = $dx, Nₜ = $Nₜ."
@info "Initializing Box with $n_periods period(s) and dx = $dx, Nₜ = $Nₜ."
T = n_periods * T
@info "Longitudinal range is [$(xᵣ.first), $(xᵣ.second)], transverse range is [$(-T/2), $(T/2))"
dt = T / Nₜ
Expand Down Expand Up @@ -56,7 +62,14 @@ struct Sim{TT<:Real, F}
P::Array{TT, 1}
end # Simulation

function Sim(λ, box::Box, ψ₀::Array{Complex{TT}, 1}, T̂; α = 0.0, ϵ=0.0, β = 0.0) where TT <: Real
"""
function Sim(λ, box::Box, ψ₀::Array{Complex{TT}, 1}, T̂; α = 0.0, ϵ=0.0, β=0.0) where TT <: Rea
Create a `::Sim` object corresponding to eigenvalue `λ` (only used for breathers, ignored for arbitrary initial conditions), initial condition `ψ₀` and algorithm `T̂`. `α` is the Hirota equation parameter and `ϵ` is the Sasa-Satsuma equation parameter. `β` controls pruning.
See also: [`Box`](@ref)
"""
function Sim(λ, box::Box, ψ₀::Array{Complex{TT}, 1}, T̂; α = 0.0, ϵ=0.0, β=0.0) where TT <: Real
ψ = Array{Complex{TT}}(undef, box.Nₜ, box.Nₓ)
ψ̃ = similar(ψ)
E = zeros(box.Nₓ)
Expand Down Expand Up @@ -95,6 +108,21 @@ struct Calc{TT<:Real}
P::Vector{TT}
end # Simulation

"""
function Calc(λ::Array{Complex{TT}}, tₛ, xₛ, seed, box; m=0.0) where TT <: Real
Create a `::Calc` object with eigenvalues `λ`, shifts `xₛ` and `tₛ` and seeding solution `seed`. `box::Box` is the Box object used for the calculation and `m` is the elliptic parameter for cnoidal solutions. `seed` can have the following values:
`seed = "0"` ``\\implies \\psi_0 = 0``
`seed = "exp"` ``\\implies \\psi_0 = e^{ix}``
`seed = "dn"` ``\\implies \\psi_0 = dn(t, m)e^{ix(1-m/2)}``
`seed = "cn"` ``\\implies \\psi_0 = \\sqrt{m}cn(t, m)e^{ix(m - 1/2)}``
See also: [`Box`](@ref)
"""
function Calc::Array{Complex{TT}}, tₛ, xₛ, seed, box; m=0.0) where TT <: Real
if ~(length(λ) == length(tₛ) == length(xₛ))
throw(ArgumentError("Length of shifts and eigenvalue array should be the same."))
Expand Down Expand Up @@ -169,6 +197,13 @@ function (K̂::Ks)(dx)
end
end

"""
function Operators(sim)
Construct appropriate operators for `sim::Sim`. These include the Fourier operator `F̂`, inverse Fourier operator `F̃̂`, dispersion operaotr `K̂`, and Hirota/Sasa-Satsuma operators `B̂` and `B̂B`. This object also includes some arrays for temporary operations in Nystrom integrators.
See also: [`Sim`](@ref)
"""
function Operators(sim)
# Generate FFT Plans to optimize performance
@info "Generating FFT plans"
Expand Down
33 changes: 25 additions & 8 deletions src/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
function compute_IoM!(obj)
Computes the integrals of motion of `obj.ψ` and saves them in respective fields of `obj`.
`obj` can be a `Sim` or `Calc` object
Result can be plotted using plot(obj, :IoM)
`obj` can be a `::Sim` or `::Calc` object. The fields are:
````
obj.KE # Array containing the kinetic energy K(x)
obj.PE # Array containing the potential energy V(x)
obj.E # Array containing the energy H(x)
obj.N # Array containing the norm N(x)
obj.P # Array containing the momentum P(x)
obj.dE # Array containing the energy error δE(x)
obj.dN # Array containing the norm error δN(x)
obj.dP # Array containing the momentum error δP(x)
````
Result can be plotted using `plot(obj, :IoM)`
"""
function compute_IoM!(obj)
@info "Computing integrals of motions"
Expand Down Expand Up @@ -89,14 +100,20 @@ end #compute_parameters
# ψ₀
###########################################################################
"""
function ψ₀_periodic(coeff, box::SimBox, params::SimParamseters; phase=0)
function ψ₀_periodic(coeff::Array, box::Box, Ω; phase=0)
Computes an initial wavefunction for the `box::Box`, with fundamental frequency `Ω`
and coefficients ``A_{1\\ldots n}`` = `coeff` and an overall phase ``e^{i \\phi t}`` where ``\\phi`` = `phase`. i.e. ``\\psi_0`` is of the form:
Computes an initial wavefunction for the `SimBox` `box`, with fundamental frequency `sim.Ω`
and coefficients ``A_1...n`` = `coeff` and an overall phase `exp(i phase t)`, i.e. of the form:
``
\\psi(x=0, t) = e^{i \\phi t} (A_0 + 2 \\sum_{1}^{n} A_m \\cos(m \\Omega t))
``
**TODO**: insert latex form here
where:
See also: [`init_sim`](@ref)
``
A_0 = \\sqrt{1 - 2 \\sum_{m=1}^n |A_m|^2}
``
"""
function ψ₀_periodic(coeff::Array, box::Box, Ω; phase=0)
@info "Initializing periodic ψ₀"
Expand Down

0 comments on commit 18b164a

Please sign in to comment.