-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
87 additions
and
314 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# # Example: 2D Simulation | ||
# | ||
# ## Set up Julia environment | ||
|
||
import Pkg | ||
Pkg.activate(mktempdir()) | ||
|
||
Pkg.add("CairoMakie") | ||
Pkg.add("CSV") | ||
Pkg.add("NPZ") | ||
Pkg.add("PencilFFTs") | ||
Pkg.develop(path = joinpath(@__DIR__, "..")) # Load version of UltraDark in this repo | ||
|
||
using UltraDark | ||
using Test | ||
using NPZ | ||
using CairoMakie | ||
using CSV | ||
|
||
Threads.nthreads() | ||
|
||
# ## Define initial conditions | ||
# | ||
# Define a 2D grid. | ||
|
||
resol = 128 | ||
len = 10.0 | ||
|
||
grids = Grids((len, len, len / resol), (resol, resol, 1)); | ||
|
||
# Add some solitons to the grid. Strictly speaking, these aren't solitons in 2D, but they'll do for demonstration purposes. | ||
|
||
mass = 10 | ||
position_1 = [-len / 5, -len / 5, 0] | ||
position_2 = [-len / 5, +len / 5, 0] | ||
velocity = [1, 0, 0] | ||
phase_1 = 0 | ||
phase_2 = π | ||
t0 = 0 | ||
|
||
UltraDark.Initialise.add_fdm_soliton!(grids, mass, position_1, velocity, phase_1, t0) | ||
UltraDark.Initialise.add_fdm_soliton!(grids, mass, position_2, velocity, phase_2, t0) | ||
|
||
# ## Set options | ||
|
||
output_dir = joinpath(mktempdir(), "output", "2D") | ||
|
||
output_times = 0:0.1:5 | ||
output_config = OutputConfig(output_dir, output_times); | ||
|
||
options = Config.SimulationConfig(); | ||
|
||
# ## Run simulation | ||
|
||
@time simulate!(grids, options, output_config) | ||
|
||
# ## Plot output | ||
|
||
summary = CSV.File(joinpath(output_config.directory, "summary.csv")); | ||
|
||
# rho_init = npzread("$(output_config.directory)/rho_1.npy"); | ||
rho_last = npzread("$(output_config.directory)/rho_$(length(output_times)).npy"); | ||
δ_lims = extrema(rho_last .- 1) | ||
|
||
fig_anim = Figure() | ||
ax_anim = Axis(fig_anim[1, 1], aspect = DataAspect()) | ||
|
||
hidedecorations!(ax_anim) | ||
|
||
cb_density = Colorbar(fig_anim[1, 2], limits = δ_lims, label = L"$\rho/\rho_{\text{crit}}$") | ||
|
||
frame = Observable(1) | ||
|
||
rho = lift(i -> npzread(joinpath(output_config.directory, "rho_$(i).npy"))[:, :, 1], frame) | ||
δ = @lift($rho .- 1) | ||
|
||
contourf!( | ||
ax_anim, | ||
grids.x[:, 1, 1], | ||
grids.y[1, :, 1], | ||
δ, | ||
levels = range(δ_lims[1], δ_lims[2], 10), | ||
) | ||
|
||
Record(fig_anim, 1:length(output_times); framerate = 5) do f | ||
frame[] = f | ||
end |