-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec_nlse.jl
53 lines (40 loc) · 1.1 KB
/
exec_nlse.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Plots
include("./NLSE/ssfm.jl")
include("./NLSE/pseudospectral.jl")
### NLSE simulation by SSFM
Ngrids = 512 # Number of Fourier modes
L = 30.0 # Space period
Δt = 2π / 21
t_end = 2π
Nsteps = round(Int, t_end / Δt)
config = NLSESettings(Nsteps, Δt, t_end, Ngrids, L)
# initial state of the wave function
ψ₀ = 2.0 * sech.(config.gridpoints)
#result = SSFM(ψ₀, config)
result = PseudoSpectral(ψ₀, config)
# output a GIF animation
ymax = maximum(hcat(abs.(result.ψ), result.Vₓ))
anim = @animate for t in 1:result.config.Nsteps
p = plot(result.config.gridpoints,
abs.(result.ψ[:, t]),
ylims = (0, ymax),
label = "|psi|", lw = 2)
plot!(result.config.gridpoints,
result.Vₓ[:, t],
label = "potential", lw = 2)
end
gif(anim, "nlse_ssfm.gif", fps = 60)
gr()
t_ary = 0:Δt:t_end
Z = abs.(result.ψ)
x = config.gridpoints
D = config.Ngrids
N = size(Z)[2]
# Z: D×N matrix to draw
# x: D vector
p = plot()
for n in 1:N
p = plot!(x, fill(n, D), Z[:, n],
color = :black, legend = false)
end
savefig(p, "hogefuga.png")