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{Vector{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 (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 (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 (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 (85349.20058, 12759.25721) m
  ⊢Height of 2.0 m
  ⊢Area of 3.8259072868817e8 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 (78082.51385, 3876.11929) m
  ⊢Height of 2.0 m
  ⊢Area of 2.5731412177668e8 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)

 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 (4111.84856, 18450.34293) m
  ⊢Height of 2.0 m
  ⊢Area of 1.0738896057966e8 m^2
  ∟Velocity of (u, v, ξ) of (0.0, 0.0, 0.0) in (m/s, m/s, rad/s)

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

 Floe{Float64}
  ⊢Centroid of (29692.67107, 10025.93572) m
  ⊢Height of 2.0 m
  ⊢Area of 3.4089674709385e8 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 (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 (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 (94387.0422, 42856.57223) m
  ⊢Height of 2.0 m
  ⊢Area of 2.3895189855925e8 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 (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)

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.16084073175878e9
  ∟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)

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)

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.