Restart Simulation

This simulation is split into two pieces, run one after the other. The purpose of this example is to show how to use the restart functionality.

using Subzero, CairoMakie, GeoInterfaceMakie
using JLD2, Random, Statistics

const FT = Float64
const Δt = 20
const nΔt = 2500
const nfloes = 20
const L = 1e5
const Δgrid = 1e4
const hmean = 2
const concentration = 0.7
const uomax = 2

dirs = [joinpath("restart_sim", "run" * string(i)) for i in 1:2]
2-element Vector{String}:
 "restart_sim/run1"
 "restart_sim/run2"

Create Grid

grid = RegRectilinearGrid(; x0 = 0.0, xf = L, y0 = 0.0, yf = L, Δx = Δgrid, Δy = Δgrid)
RegRectilinearGrid{Float64}
  ⊢x extent (0.0 to 100000.0) with 10 grid cells of size 10000.0 m
  ∟y extent (0.0 to 100000.0) with 10 grid cells of size 10000.0 m

Create Domain

nboundary = PeriodicBoundary(North; grid)
sboundary = PeriodicBoundary(South; grid)
eboundary = PeriodicBoundary(East; grid)
wboundary = PeriodicBoundary(West; grid)
domain = Domain(; north = nboundary, south = sboundary, east = eboundary,west =  wboundary)
Domain
  ⊢Northern boundary of type PeriodicBoundary{North, Float64}
  ⊢Southern boundary of type PeriodicBoundary{South, Float64}
  ⊢Eastern boundary of type PeriodicBoundary{East, Float64}
  ⊢Western boundary of type PeriodicBoundary{West, Float64}
  ∟0-element TopograpahyElement{Float64} list

Create Ocean

ngrid = Int(L/Δgrid) + 1
ygrid = range(0,L,ngrid)
uoprofile = @. uomax * (1 - abs(1 - 2 * ygrid/L))
uvels_ocean = repeat(
    uoprofile,
    outer = (1, ngrid),
)
ocean = Ocean(;
    u = uvels_ocean',
    grid,
    v = 0,
    temp = 0,
)
Ocean{Float64}
  ⊢Vector fields of dimension (11, 11)
  ⊢Tracer fields of dimension (11, 11)
  ⊢Average u-velocity of: 0.90909 m/s
  ⊢Average v-velocity of: 0.0 m/s
  ∟Average temperature of: 0.0 C

Create Atmos

atmos = Atmos(FT; grid, u = 0.0, v = 0.0, temp = 0.0)
Atmos{Float64}
  ⊢Vector fields of dimension (11, 11)
  ⊢Tracer fields of dimension (11, 11)
  ⊢Average u-velocity of: 0.0 m/s
  ⊢Average v-velocity of: 0.0 m/s
  ∟Average temperature of: 0.0 C

Create Floes

floe_generator = VoronoiTesselationFieldGenerator(; nfloes, concentrations = [concentration], hmean, Δh = 0)
floe_settings = FloeSettings(; subfloe_point_generator = SubGridPointsGenerator(; grid, npoint_per_cell = 2))
floe_arr = initialize_floe_field(FT; generator = floe_generator,  domain, rng = Xoshiro(1), floe_settings)
21-element StructArray(::Vector{GeoInterface.Wrappers.Polygon{false, false, Vector{GeoInterface.Wrappers.LinearRing{false, false, Vector{Tuple{Float64, Float64}}, Nothing, Nothing}}, Nothing, Nothing}}, ::Vector{Vector{Float64}}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Vector{Float64}}, ::Vector{Vector{Float64}}, ::Vector{Vector{Float64}}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Subzero.Status}, ::Vector{Int64}, ::Vector{Int64}, ::Vector{Vector{Int64}}, ::Vector{Vector{Int64}}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Matrix{Float64}}, ::Vector{Float64}, ::Vector{Matrix{Float64}}, ::Vector{Int64}, ::Vector{Matrix{Float64}}, ::Vector{Matrix{Float64}}, ::Vector{Matrix{Float64}}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}) with eltype Floe{Float64}:
 Floe{Float64}
  ⊢Centroid of (85711.61922, 27312.21323) m
  ⊢Height of 2.0 m
  ⊢Area of 4.6939800559853e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (1992.88234, 72479.44018) m
  ⊢Height of 2.0 m
  ⊢Area of 4.472412766761e7 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (33613.80576, 83906.94778) m
  ⊢Height of 2.0 m
  ⊢Area of 9.1770485471185e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (93357.10571, 59553.21689) m
  ⊢Height of 2.0 m
  ⊢Area of 1.9638967050933e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (81812.79465, 93051.11248) m
  ⊢Height of 2.0 m
  ⊢Area of 2.2352717453713e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (24336.02328, 57598.84303) m
  ⊢Height of 2.0 m
  ⊢Area of 3.2239597582052e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (7157.5241, 25954.12483) m
  ⊢Height of 2.0 m
  ⊢Area of 8.128930093923e7 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (58484.33123, 96073.3103) m
  ⊢Height of 2.0 m
  ⊢Area of 2.1325459898699e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (18305.63868, 40649.64815) m
  ⊢Height of 2.0 m
  ⊢Area of 2.7691754012614e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (71288.17994, 45938.89147) m
  ⊢Height of 2.0 m
  ⊢Area of 6.6925017843697e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 ⋮
 Floe{Float64}
  ⊢Centroid of (42958.00112, 13654.89571) m
  ⊢Height of 2.0 m
  ⊢Area of 3.6688421815656e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (15308.74744, 68626.39083) m
  ⊢Height of 2.0 m
  ⊢Area of 2.6089116090995e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (94831.18867, 73451.81728) m
  ⊢Height of 2.0 m
  ⊢Area of 8.53964690716e7 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (58425.22293, 20191.46541) m
  ⊢Height of 2.0 m
  ⊢Area of 6.8390424362643e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (80594.00653, 67170.83978) m
  ⊢Height of 2.0 m
  ⊢Area of 3.5492907961813e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (8962.3331, 87293.65732) m
  ⊢Height of 2.0 m
  ⊢Area of 4.5438229527206e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (5155.53544, 54160.47284) m
  ⊢Height of 2.0 m
  ⊢Area of 2.4705330754859e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (97870.36737, 80465.95766) m
  ⊢Height of 2.0 m
  ⊢Area of 4.515583491587e7 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

 Floe{Float64}
  ⊢Centroid of (39324.7364, 42187.87374) m
  ⊢Height of 2.0 m
  ⊢Area of 7.1940065813534e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

Create Model

model = Model(;grid, ocean, atmos, domain, floes = floe_arr)
Model{Float64, ...}
 ⊢RegRectilinearGrid{Float64}
  ⊢x extent (0.0 to 100000.0) with 10 grid cells of size 10000.0 m
  ∟y extent (0.0 to 100000.0) with 10 grid cells of size 10000.0 m
 ⊢Domain
  ⊢Northern boundary of type PeriodicBoundary{North, Float64}
  ⊢Southern boundary of type PeriodicBoundary{South, Float64}
  ⊢Eastern boundary of type PeriodicBoundary{East, Float64}
  ⊢Western boundary of type PeriodicBoundary{West, Float64}
  ∟0-element TopograpahyElement{Float64} list
 ⊢Ocean{Float64}
  ⊢Vector fields of dimension (11, 11)
  ⊢Tracer fields of dimension (11, 11)
  ⊢Average u-velocity of: 0.90909 m/s
  ⊢Average v-velocity of: 0.0 m/s
  ∟Average temperature of: 0.0 C
 ⊢Atmos{Float64}
  ⊢Vector fields of dimension (11, 11)
  ⊢Tracer fields of dimension (11, 11)
  ⊢Average u-velocity of: 0.0 m/s
  ⊢Average v-velocity of: 0.0 m/s
  ∟Average temperature of: 0.0 C
 ∟Floe List:
  ⊢Number of floes: 21
  ⊢Total floe area: 7.20994167671866e9
  ∟Average floe height: 2.0

Create Outout Writers

initwriter = InitialStateOutputWriter(dir = dirs[1], overwrite = true)
checkpointer = CheckpointOutputWriter(
    250,
    dir = dirs[1],
    filename = "checkpoint.jld2",
    overwrite = true,
    jld2_kw = Dict{Symbol, Any}(),
)
floewriter = FloeOutputWriter(50, dir = dirs[1], overwrite = true)
writers = OutputWriters(initwriter, floewriter, checkpointer)
OutputWriters
  ⊢1 InitialStateOuputWriter(s)
  ⊢1 CheckpointOutputWriter(s)
  ⊢1 FloeOutputWriter(s)
  ∟0 GridOutputWriter(s)

Create Simulation and Constants

modulus = 1.5e3*(mean(sqrt.(floe_arr.area)) + minimum(sqrt.(floe_arr.area)))
consts = Constants(; E = modulus, f = 0, turnθ = 0)
simulation = Simulation(;
    model = model,
    consts = consts,
    Δt = Δt,
    nΔt = nΔt,
    verbose = true,
    writers = writers,
    rng = Xoshiro(1),
    floe_settings,
)
Simulation
  ⊢Timestep: 20 seconds
  ⊢Runtime: 2500 timesteps
  ⊢RNG: Xoshiro(0xfff0241072ddab67, 0xc53bc12f4c3f0b4e, 0x56d451780b2dd4ba, 0x50a4aa153d208dd8, 0x3649a58b3b63d5db)
  ⊢verbose: true
  ⊢model
  ⊢consts
  ⊢floe_settings
  ⊢collision_settings
  ∟ ...

Run the first part of the simulation

run!(simulation)
sim is running!
0 timesteps
50 timesteps
100 timesteps
150 timesteps
200 timesteps
250 timesteps
300 timesteps
350 timesteps
400 timesteps
450 timesteps
500 timesteps
550 timesteps
600 timesteps
650 timesteps
700 timesteps
750 timesteps
800 timesteps
850 timesteps
900 timesteps
950 timesteps
1000 timesteps
1050 timesteps
1100 timesteps
1150 timesteps
1200 timesteps
1250 timesteps
1300 timesteps
1350 timesteps
1400 timesteps
1450 timesteps
1500 timesteps
1550 timesteps
1600 timesteps
1650 timesteps
1700 timesteps
1750 timesteps
1800 timesteps
1850 timesteps
1900 timesteps
1950 timesteps
2000 timesteps
2050 timesteps
2100 timesteps
2150 timesteps
2200 timesteps
2250 timesteps
2300 timesteps
2350 timesteps
2400 timesteps
2450 timesteps
2500 timesteps
sim done running!

Run second part of the simulation

new_initwriter = InitialStateOutputWriter(initwriter; dir = dirs[2])
new_floewriter = FloeOutputWriter(floewriter; dir = dirs[2])
writers = OutputWriters(new_initwriter, new_floewriter)  # didn't save checkpoint since not restarting
Subzero.restart!(
    dirs[1] * "/initial_state.jld2",
    dirs[1] * "/checkpoint.jld2",
    nΔt, writers; start_tstep = nΔt)
sim is running!
2500 timesteps
2550 timesteps
2600 timesteps
2650 timesteps
2700 timesteps
2750 timesteps
2800 timesteps
2850 timesteps
2900 timesteps
2950 timesteps
3000 timesteps
3050 timesteps
3100 timesteps
3150 timesteps
3200 timesteps
3250 timesteps
3300 timesteps
3350 timesteps
3400 timesteps
3450 timesteps
3500 timesteps
3550 timesteps
3600 timesteps
3650 timesteps
3700 timesteps
3750 timesteps
3800 timesteps
3850 timesteps
3900 timesteps
3950 timesteps
4000 timesteps
4050 timesteps
4100 timesteps
4150 timesteps
4200 timesteps
4250 timesteps
4300 timesteps
4350 timesteps
4400 timesteps
4450 timesteps
4500 timesteps
4550 timesteps
4600 timesteps
4650 timesteps
4700 timesteps
4750 timesteps
4800 timesteps
4850 timesteps
4900 timesteps
4950 timesteps
5000 timesteps
sim done running!

Plot all simulation parts

for i in 1:2
    plot_sim(
        joinpath(dirs[i], "floes.jld2"),
        joinpath(dirs[i], "initial_state.jld2"),
        Δt,
        joinpath(dirs[i], "restart_floes.mp4"),
    )
end

First Part of Simulation

Second Part of Simulation


This page was generated using Literate.jl.