using ClimaSeaIce
using ClimaSeaIce.SeaIceDynamics
using ClimaSeaIce.Rheologies
using Oceananigans
using Oceananigans.Units
using Oceananigans.Operators
using Printf
using CairoMakie

A solid block of ice moving against a triangular coastline in a periodic channel

Lx = 512kilometers
Ly = 256kilometers
Nx = 256
Ny = 256

y_max = Ly / 2

arch = CPU()

𝓋ₐ = 10.0   # m / s
Cᴰ = 1.2e-3 # Atmosphere - sea ice drag coefficient
ρₐ = 1.3    # kg/m³
1.3

2 km domain

grid = RectilinearGrid(arch; size = (Nx, Ny),
                                x = (-Lx/2, Lx/2),
                                y = (0, Ly),
                             halo = (4, 4),
                         topology = (Periodic, Bounded, Flat))

bottom(x, y) = ifelse(y > y_max, 0,
               ifelse(abs(x / Lx) * Nx + y / Ly * Ny > 24, 0, 1))

grid = ImmersedBoundaryGrid(grid, GridFittedBoundary(bottom))

#####
##### Setup atmospheric and oceanic forcing
#####
256×256×1 ImmersedBoundaryGrid{Float64, Oceananigans.Grids.Periodic, Oceananigans.Grids.Bounded, Oceananigans.Grids.Flat} on Oceananigans.Architectures.CPU with 4×4×0 halo:
├── immersed_boundary: Oceananigans.ImmersedBoundaries.GridFittedBoundary{Oceananigans.Fields.Field{Oceananigans.Grids.Center, Oceananigans.Grids.Center, Oceananigans.Grids.Center, Nothing, Oceananigans.Grids.RectilinearGrid{Float64, Oceananigans.Grids.Periodic, Oceananigans.Grids.Bounded, Oceananigans.Grids.Flat, Oceananigans.Grids.StaticVerticalDiscretization{Nothing, Nothing, Float64, Float64}, Float64, Float64, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, Oceananigans.Architectures.CPU}, Tuple{Colon, Colon, Colon}, OffsetArrays.OffsetArray{Bool, 3, Array{Bool, 3}}, Bool, Oceananigans.BoundaryConditions.FieldBoundaryConditions{Oceananigans.BoundaryConditions.BoundaryCondition{Oceananigans.BoundaryConditions.Periodic, Nothing}, Oceananigans.BoundaryConditions.BoundaryCondition{Oceananigans.BoundaryConditions.Periodic, Nothing}, Oceananigans.BoundaryConditions.BoundaryCondition{Oceananigans.BoundaryConditions.Flux, Nothing}, Oceananigans.BoundaryConditions.BoundaryCondition{Oceananigans.BoundaryConditions.Flux, Nothing}, Nothing, Nothing, Oceananigans.BoundaryConditions.BoundaryCondition{Oceananigans.BoundaryConditions.Flux, Nothing}}, Nothing, Nothing}}
├── underlying_grid: 256×256×1 RectilinearGrid{Float64, Oceananigans.Grids.Periodic, Oceananigans.Grids.Bounded, Oceananigans.Grids.Flat} on Oceananigans.Architectures.CPU with 4×4×0 halo
├── Periodic x ∈ [-256000.0, 256000.0) regularly spaced with Δx=2000.0
├── Bounded  y ∈ [0.0, 256000.0]       regularly spaced with Δy=1000.0
└── Flat z                             

Atmosphere - sea ice stress

Ua = XFaceField(grid)
τᵤ = Field(- ρₐ * Cᴰ * Ua^2)
set!(Ua, 𝓋ₐ)
compute!(τᵤ)
Oceananigans.BoundaryConditions.fill_halo_regions!(τᵤ)
τᵥ = 0.0

#####
##### Ocean stress (a zero-velocity ocean with a drag)
#####

τₒ = SemiImplicitStress()

#####
##### Numerical details
#####
ClimaSeaIce.SeaIceDynamics.SemiImplicitStress{Oceananigans.Fields.ZeroField{Float64, 3}, Oceananigans.Fields.ZeroField{Float64, 3}, Float64}(ZeroField{Float64}, ZeroField{Float64}, 1026.0, 0.0055)

We use an elasto-visco-plastic rheology and WENO seventh order for advection of h and ℵ

dynamics = SeaIceMomentumEquation(grid;
                                  top_momentum_stress = (u=τᵤ, v=τᵥ),
                                  bottom_momentum_stress = τₒ,
                                  rheology = ElastoViscoPlasticRheology(),
                                  solver = SplitExplicitSolver(substeps=150))

@inline immersed_u_drag(i, j, k, grid, clock, fields, D) = @inbounds - D * fields.u[i, j, k]
@inline immersed_v_drag(i, j, k, grid, clock, fields, D) = @inbounds - D * fields.v[i, j, k]

immersed_u_bc = FluxBoundaryCondition(immersed_u_drag, discrete_form=true, parameters=3e-1)
immersed_v_bc = FluxBoundaryCondition(immersed_v_drag, discrete_form=true, parameters=3e-1)

immersed_u_bc = ImmersedBoundaryCondition(top=nothing, bottom=nothing, west=nothing, east=nothing,
                                          south=immersed_u_bc, north=immersed_u_bc)

immersed_v_bc = ImmersedBoundaryCondition(top=nothing, bottom=nothing, south=nothing, north=nothing,
                                          west=immersed_v_bc, east=immersed_v_bc)

u_bcs = FieldBoundaryConditions(grid, (Face, Center, Nothing);
                                north = ValueBoundaryCondition(0),
                                south = ValueBoundaryCondition(0),
                                immersed = immersed_u_bc)

v_bcs = FieldBoundaryConditions(grid, (Center, Face, Nothing);
                                immersed = immersed_v_bc)

#Define the model!
model = SeaIceModel(grid;
                    advection = WENO(order=7),
                    dynamics = dynamics,
                    boundary_conditions = (; u=u_bcs, v=v_bcs),
                    ice_thermodynamics = nothing)
SeaIceModel{Oceananigans.Architectures.CPU, Oceananigans.ImmersedBoundaries.ImmersedBoundaryGrid}(time = 0 seconds, iteration = 0)
├── grid: 256×256×1 ImmersedBoundaryGrid{Float64, Oceananigans.Grids.Periodic, Oceananigans.Grids.Bounded, Oceananigans.Grids.Flat} on Oceananigans.Architectures.CPU with 4×4×0 halo
├── ice_thermodynamics: Nothing
├── advection: WENO{4, Float64, Float32}(order=7)
└── external_heat_fluxes: 
    ├── top: Nothing
    └── bottom: 0

We start with a concentration of ℵ = 1 everywhere

set!(model, h = 1)
set!(model, ℵ = 1)

#####
##### Setup the simulation
#####

run the model for 10 day

simulation = Simulation(model, Δt = 2minutes, stop_time=2days)
Simulation of SeaIceModel
├── Next time step: 2 minutes
├── Elapsed wall time: 0 seconds
├── Wall time per iteration: NaN days
├── Stop time: 2 days
├── Stop iteration: Inf
├── Wall time limit: Inf
├── Minimum relative step: 0.0
├── Callbacks: OrderedDict with 3 entries:
│   ├── stop_time_exceeded => 3
│   ├── stop_iteration_exceeded => -
│   └── wall_time_limit_exceeded => }
├── Output writers: OrderedDict with no entries
└── Diagnostics: OrderedDict with no entries

Container to hold the data

htimeseries = []
ℵtimeseries = []
utimeseries = []
vtimeseries = []

# Callback function to collect the data from the `sim`ulation
function accumulate_timeseries(sim)
    h = sim.model.ice_thickness
    ℵ = sim.model.ice_concentration
    u = sim.model.velocities.u
    v = sim.model.velocities.v
    push!(htimeseries, deepcopy(Array(interior(h))))
    push!(ℵtimeseries, deepcopy(Array(interior(ℵ))))
    push!(utimeseries, deepcopy(Array(interior(u))))
    push!(vtimeseries, deepcopy(Array(interior(v))))
end

wall_time = Ref(time_ns())

function progress(sim)
    h = sim.model.ice_thickness
    ℵ = sim.model.ice_concentration
    u = sim.model.velocities.u
    v = sim.model.velocities.v

    hmax = maximum(interior(h))
    ℵmin = minimum(interior(ℵ))
    umax = maximum(interior(u)), maximum(interior(v))
    step_time = 1e-9 * (time_ns() - wall_time[])

    @info @sprintf("Time: %s, Iteration %d, Δt %s, max(vel): (%.2e, %.2e), max(trac): %.2f, %.2f, wtime: %s \n",
                   prettytime(sim.model.clock.time),
                   sim.model.clock.iteration,
                   prettytime(sim.Δt),
                   umax..., hmax, ℵmin, prettytime(step_time))

     wall_time[] = time_ns()
end

simulation.callbacks[:progress] = Callback(progress, IterationInterval(10))
simulation.callbacks[:save]     = Callback(accumulate_timeseries, IterationInterval(10))

run!(simulation)
[ Info: Initializing simulation...
[ Info: Time: 0 seconds, Iteration 0, Δt 2 minutes, max(vel): (0.00e+00, 0.00e+00), max(trac): 1.00, 0.00, wtime: 56.525 seconds
[ Info:     ... simulation initialization complete (28.752 seconds)
[ Info: Executing initial time step...
[ Info:     ... initial time step complete (29.442 seconds).
[ Info: Time: 20 minutes, Iteration 10, Δt 2 minutes, max(vel): (1.27e-01, 1.46e-02), max(trac): 1.02, 0.00, wtime: 39.477 seconds
[ Info: Time: 40 minutes, Iteration 20, Δt 2 minutes, max(vel): (1.72e-01, 1.81e-02), max(trac): 1.09, 0.00, wtime: 11.168 seconds
[ Info: Time: 1 hour, Iteration 30, Δt 2 minutes, max(vel): (1.81e-01, 1.89e-02), max(trac): 1.17, 0.00, wtime: 11.246 seconds
[ Info: Time: 1.333 hours, Iteration 40, Δt 2 minutes, max(vel): (1.83e-01, 2.64e-02), max(trac): 1.26, 0.00, wtime: 11.203 seconds
[ Info: Time: 1.667 hours, Iteration 50, Δt 2 minutes, max(vel): (1.86e-01, 1.88e-02), max(trac): 1.33, 0.00, wtime: 11.169 seconds
[ Info: Time: 2 hours, Iteration 60, Δt 2 minutes, max(vel): (1.84e-01, 2.29e-02), max(trac): 1.40, 0.00, wtime: 11.165 seconds
[ Info: Time: 2.333 hours, Iteration 70, Δt 2 minutes, max(vel): (1.83e-01, 2.06e-02), max(trac): 1.47, 0.00, wtime: 11.171 seconds
[ Info: Time: 2.667 hours, Iteration 80, Δt 2 minutes, max(vel): (1.86e-01, 1.95e-02), max(trac): 1.52, 0.00, wtime: 11.175 seconds
[ Info: Time: 3 hours, Iteration 90, Δt 2 minutes, max(vel): (1.87e-01, 1.93e-02), max(trac): 1.57, 0.00, wtime: 11.169 seconds
[ Info: Time: 3.333 hours, Iteration 100, Δt 2 minutes, max(vel): (1.88e-01, 1.91e-02), max(trac): 1.62, 0.00, wtime: 11.153 seconds
[ Info: Time: 3.667 hours, Iteration 110, Δt 2 minutes, max(vel): (1.87e-01, 1.85e-02), max(trac): 1.66, 0.00, wtime: 11.177 seconds
[ Info: Time: 4 hours, Iteration 120, Δt 2 minutes, max(vel): (1.84e-01, 2.25e-02), max(trac): 1.70, 0.00, wtime: 11.190 seconds
[ Info: Time: 4.333 hours, Iteration 130, Δt 2 minutes, max(vel): (1.87e-01, 2.42e-02), max(trac): 1.74, 0.00, wtime: 11.167 seconds
[ Info: Time: 4.667 hours, Iteration 140, Δt 2 minutes, max(vel): (1.82e-01, 2.06e-02), max(trac): 1.77, 0.00, wtime: 11.176 seconds
[ Info: Time: 5 hours, Iteration 150, Δt 2 minutes, max(vel): (1.85e-01, 1.80e-02), max(trac): 1.81, 0.00, wtime: 11.176 seconds
[ Info: Time: 5.333 hours, Iteration 160, Δt 2 minutes, max(vel): (2.02e-01, 2.05e-02), max(trac): 1.84, 0.00, wtime: 11.187 seconds
[ Info: Time: 5.667 hours, Iteration 170, Δt 2 minutes, max(vel): (1.84e-01, 1.82e-02), max(trac): 1.87, 0.00, wtime: 11.165 seconds
[ Info: Time: 6 hours, Iteration 180, Δt 2 minutes, max(vel): (1.85e-01, 1.81e-02), max(trac): 1.89, 0.00, wtime: 11.150 seconds
[ Info: Time: 6.333 hours, Iteration 190, Δt 2 minutes, max(vel): (1.87e-01, 4.19e-02), max(trac): 1.92, 0.00, wtime: 11.169 seconds
[ Info: Time: 6.667 hours, Iteration 200, Δt 2 minutes, max(vel): (1.85e-01, 1.73e-02), max(trac): 1.94, 0.00, wtime: 11.207 seconds
[ Info: Time: 7 hours, Iteration 210, Δt 2 minutes, max(vel): (1.86e-01, 1.97e-02), max(trac): 1.96, 0.00, wtime: 11.170 seconds
[ Info: Time: 7.333 hours, Iteration 220, Δt 2 minutes, max(vel): (1.83e-01, 1.95e-02), max(trac): 1.98, 0.00, wtime: 11.192 seconds
[ Info: Time: 7.667 hours, Iteration 230, Δt 2 minutes, max(vel): (1.88e-01, 1.89e-02), max(trac): 2.00, 0.00, wtime: 11.183 seconds
[ Info: Time: 8 hours, Iteration 240, Δt 2 minutes, max(vel): (1.85e-01, 2.14e-02), max(trac): 2.02, 0.00, wtime: 11.162 seconds
[ Info: Time: 8.333 hours, Iteration 250, Δt 2 minutes, max(vel): (1.84e-01, 2.02e-02), max(trac): 2.03, 0.00, wtime: 11.212 seconds
[ Info: Time: 8.667 hours, Iteration 260, Δt 2 minutes, max(vel): (1.91e-01, 2.12e-02), max(trac): 2.05, 0.00, wtime: 11.180 seconds
[ Info: Time: 9 hours, Iteration 270, Δt 2 minutes, max(vel): (1.85e-01, 1.96e-02), max(trac): 2.06, 0.00, wtime: 11.214 seconds
[ Info: Time: 9.333 hours, Iteration 280, Δt 2 minutes, max(vel): (1.82e-01, 2.27e-02), max(trac): 2.08, 0.00, wtime: 11.185 seconds
[ Info: Time: 9.667 hours, Iteration 290, Δt 2 minutes, max(vel): (1.87e-01, 2.16e-02), max(trac): 2.09, 0.00, wtime: 11.252 seconds
[ Info: Time: 10 hours, Iteration 300, Δt 2 minutes, max(vel): (1.87e-01, 1.91e-02), max(trac): 2.10, 0.00, wtime: 11.334 seconds
[ Info: Time: 10.333 hours, Iteration 310, Δt 2 minutes, max(vel): (1.89e-01, 1.85e-02), max(trac): 2.12, 0.00, wtime: 11.261 seconds
[ Info: Time: 10.667 hours, Iteration 320, Δt 2 minutes, max(vel): (1.86e-01, 1.93e-02), max(trac): 2.13, 0.00, wtime: 11.180 seconds
[ Info: Time: 11 hours, Iteration 330, Δt 2 minutes, max(vel): (1.86e-01, 2.05e-02), max(trac): 2.13, 0.00, wtime: 11.252 seconds
[ Info: Time: 11.333 hours, Iteration 340, Δt 2 minutes, max(vel): (1.89e-01, 2.12e-02), max(trac): 2.14, 0.00, wtime: 11.247 seconds
[ Info: Time: 11.667 hours, Iteration 350, Δt 2 minutes, max(vel): (1.84e-01, 2.11e-02), max(trac): 2.15, 0.00, wtime: 11.211 seconds
[ Info: Time: 12 hours, Iteration 360, Δt 2 minutes, max(vel): (1.89e-01, 1.91e-02), max(trac): 2.16, 0.00, wtime: 11.215 seconds
[ Info: Time: 12.333 hours, Iteration 370, Δt 2 minutes, max(vel): (1.84e-01, 2.19e-02), max(trac): 2.17, 0.00, wtime: 11.181 seconds
[ Info: Time: 12.667 hours, Iteration 380, Δt 2 minutes, max(vel): (1.82e-01, 1.79e-02), max(trac): 2.18, 0.00, wtime: 11.193 seconds
[ Info: Time: 13 hours, Iteration 390, Δt 2 minutes, max(vel): (1.86e-01, 2.06e-02), max(trac): 2.18, 0.00, wtime: 11.162 seconds
[ Info: Time: 13.333 hours, Iteration 400, Δt 2 minutes, max(vel): (1.83e-01, 1.98e-02), max(trac): 2.19, 0.00, wtime: 11.189 seconds
[ Info: Time: 13.667 hours, Iteration 410, Δt 2 minutes, max(vel): (1.83e-01, 1.79e-02), max(trac): 2.19, 0.00, wtime: 11.206 seconds
[ Info: Time: 14 hours, Iteration 420, Δt 2 minutes, max(vel): (1.84e-01, 1.92e-02), max(trac): 2.20, 0.00, wtime: 11.172 seconds
[ Info: Time: 14.333 hours, Iteration 430, Δt 2 minutes, max(vel): (1.85e-01, 2.09e-02), max(trac): 2.21, 0.00, wtime: 11.175 seconds
[ Info: Time: 14.667 hours, Iteration 440, Δt 2 minutes, max(vel): (1.84e-01, 1.93e-02), max(trac): 2.21, 0.00, wtime: 11.203 seconds
[ Info: Time: 15 hours, Iteration 450, Δt 2 minutes, max(vel): (1.84e-01, 2.55e-02), max(trac): 2.22, 0.00, wtime: 11.192 seconds
[ Info: Time: 15.333 hours, Iteration 460, Δt 2 minutes, max(vel): (1.88e-01, 1.82e-02), max(trac): 2.22, 0.00, wtime: 11.233 seconds
[ Info: Time: 15.667 hours, Iteration 470, Δt 2 minutes, max(vel): (1.84e-01, 2.25e-02), max(trac): 2.22, 0.00, wtime: 11.169 seconds
[ Info: Time: 16 hours, Iteration 480, Δt 2 minutes, max(vel): (1.87e-01, 2.22e-02), max(trac): 2.22, 0.00, wtime: 11.190 seconds
[ Info: Time: 16.333 hours, Iteration 490, Δt 2 minutes, max(vel): (1.86e-01, 1.98e-02), max(trac): 2.23, 0.00, wtime: 11.198 seconds
[ Info: Time: 16.667 hours, Iteration 500, Δt 2 minutes, max(vel): (1.86e-01, 2.02e-02), max(trac): 2.23, 0.00, wtime: 11.194 seconds
[ Info: Time: 17 hours, Iteration 510, Δt 2 minutes, max(vel): (1.88e-01, 1.99e-02), max(trac): 2.23, 0.00, wtime: 11.225 seconds
[ Info: Time: 17.333 hours, Iteration 520, Δt 2 minutes, max(vel): (1.86e-01, 2.03e-02), max(trac): 2.23, 0.00, wtime: 11.210 seconds
[ Info: Time: 17.667 hours, Iteration 530, Δt 2 minutes, max(vel): (1.87e-01, 2.08e-02), max(trac): 2.23, 0.00, wtime: 11.585 seconds
[ Info: Time: 18 hours, Iteration 540, Δt 2 minutes, max(vel): (1.87e-01, 2.40e-02), max(trac): 2.24, 0.00, wtime: 11.218 seconds
[ Info: Time: 18.333 hours, Iteration 550, Δt 2 minutes, max(vel): (1.87e-01, 2.06e-02), max(trac): 2.24, 0.00, wtime: 11.186 seconds
[ Info: Time: 18.667 hours, Iteration 560, Δt 2 minutes, max(vel): (1.88e-01, 2.10e-02), max(trac): 2.24, 0.00, wtime: 11.206 seconds
[ Info: Time: 19 hours, Iteration 570, Δt 2 minutes, max(vel): (1.86e-01, 2.04e-02), max(trac): 2.24, 0.00, wtime: 11.221 seconds
[ Info: Time: 19.333 hours, Iteration 580, Δt 2 minutes, max(vel): (1.89e-01, 2.09e-02), max(trac): 2.24, 0.00, wtime: 11.182 seconds
[ Info: Time: 19.667 hours, Iteration 590, Δt 2 minutes, max(vel): (1.86e-01, 2.11e-02), max(trac): 2.24, 0.00, wtime: 11.183 seconds
[ Info: Time: 20 hours, Iteration 600, Δt 2 minutes, max(vel): (1.85e-01, 2.29e-02), max(trac): 2.24, 0.00, wtime: 11.178 seconds
[ Info: Time: 20.333 hours, Iteration 610, Δt 2 minutes, max(vel): (1.86e-01, 2.08e-02), max(trac): 2.24, 0.00, wtime: 11.185 seconds
[ Info: Time: 20.667 hours, Iteration 620, Δt 2 minutes, max(vel): (1.86e-01, 2.24e-02), max(trac): 2.24, 0.00, wtime: 11.185 seconds
[ Info: Time: 21 hours, Iteration 630, Δt 2 minutes, max(vel): (1.85e-01, 2.02e-02), max(trac): 2.24, 0.00, wtime: 11.177 seconds
[ Info: Time: 21.333 hours, Iteration 640, Δt 2 minutes, max(vel): (1.86e-01, 1.93e-02), max(trac): 2.24, 0.00, wtime: 11.260 seconds
[ Info: Time: 21.667 hours, Iteration 650, Δt 2 minutes, max(vel): (1.84e-01, 2.32e-02), max(trac): 2.24, 0.00, wtime: 11.196 seconds
[ Info: Time: 22 hours, Iteration 660, Δt 2 minutes, max(vel): (1.85e-01, 2.02e-02), max(trac): 2.24, 0.00, wtime: 11.165 seconds
[ Info: Time: 22.333 hours, Iteration 670, Δt 2 minutes, max(vel): (1.86e-01, 2.08e-02), max(trac): 2.24, 0.00, wtime: 11.205 seconds
[ Info: Time: 22.667 hours, Iteration 680, Δt 2 minutes, max(vel): (1.84e-01, 1.95e-02), max(trac): 2.24, 0.00, wtime: 11.183 seconds
[ Info: Time: 23 hours, Iteration 690, Δt 2 minutes, max(vel): (1.86e-01, 1.79e-02), max(trac): 2.24, 0.00, wtime: 11.190 seconds
[ Info: Time: 23.333 hours, Iteration 700, Δt 2 minutes, max(vel): (1.85e-01, 2.20e-02), max(trac): 2.24, 0.00, wtime: 11.171 seconds
[ Info: Time: 23.667 hours, Iteration 710, Δt 2 minutes, max(vel): (1.85e-01, 1.97e-02), max(trac): 2.24, 0.00, wtime: 11.175 seconds
[ Info: Time: 1 day, Iteration 720, Δt 2 minutes, max(vel): (1.86e-01, 2.08e-02), max(trac): 2.24, 0.00, wtime: 11.214 seconds
[ Info: Time: 1.014 days, Iteration 730, Δt 2 minutes, max(vel): (1.88e-01, 1.80e-02), max(trac): 2.24, 0.00, wtime: 11.177 seconds
[ Info: Time: 1.028 days, Iteration 740, Δt 2 minutes, max(vel): (1.98e-01, 2.20e-02), max(trac): 2.24, 0.00, wtime: 11.174 seconds
[ Info: Time: 1.042 days, Iteration 750, Δt 2 minutes, max(vel): (1.83e-01, 1.92e-02), max(trac): 2.24, 0.00, wtime: 11.183 seconds
[ Info: Time: 1.056 days, Iteration 760, Δt 2 minutes, max(vel): (1.85e-01, 2.15e-02), max(trac): 2.24, 0.00, wtime: 11.169 seconds
[ Info: Time: 1.069 days, Iteration 770, Δt 2 minutes, max(vel): (1.92e-01, 2.26e-02), max(trac): 2.24, 0.00, wtime: 11.213 seconds
[ Info: Time: 1.083 days, Iteration 780, Δt 2 minutes, max(vel): (1.83e-01, 2.06e-02), max(trac): 2.24, 0.00, wtime: 11.201 seconds
[ Info: Time: 1.097 days, Iteration 790, Δt 2 minutes, max(vel): (1.84e-01, 1.93e-02), max(trac): 2.24, 0.00, wtime: 11.213 seconds
[ Info: Time: 1.111 days, Iteration 800, Δt 2 minutes, max(vel): (1.88e-01, 2.07e-02), max(trac): 2.24, 0.00, wtime: 11.183 seconds
[ Info: Time: 1.125 days, Iteration 810, Δt 2 minutes, max(vel): (1.88e-01, 1.87e-02), max(trac): 2.24, 0.00, wtime: 11.176 seconds
[ Info: Time: 1.139 days, Iteration 820, Δt 2 minutes, max(vel): (1.84e-01, 2.01e-02), max(trac): 2.24, 0.00, wtime: 11.180 seconds
[ Info: Time: 1.153 days, Iteration 830, Δt 2 minutes, max(vel): (1.83e-01, 2.13e-02), max(trac): 2.24, 0.00, wtime: 11.254 seconds
[ Info: Time: 1.167 days, Iteration 840, Δt 2 minutes, max(vel): (1.84e-01, 2.03e-02), max(trac): 2.24, 0.00, wtime: 11.227 seconds
[ Info: Time: 1.181 days, Iteration 850, Δt 2 minutes, max(vel): (1.88e-01, 2.21e-02), max(trac): 2.25, 0.00, wtime: 11.189 seconds
[ Info: Time: 1.194 days, Iteration 860, Δt 2 minutes, max(vel): (1.84e-01, 1.95e-02), max(trac): 2.25, 0.00, wtime: 11.221 seconds
[ Info: Time: 1.208 days, Iteration 870, Δt 2 minutes, max(vel): (1.83e-01, 2.06e-02), max(trac): 2.25, 0.00, wtime: 11.257 seconds
[ Info: Time: 1.222 days, Iteration 880, Δt 2 minutes, max(vel): (1.84e-01, 2.07e-02), max(trac): 2.26, 0.00, wtime: 11.231 seconds
[ Info: Time: 1.236 days, Iteration 890, Δt 2 minutes, max(vel): (1.84e-01, 2.08e-02), max(trac): 2.26, 0.00, wtime: 11.217 seconds
[ Info: Time: 1.250 days, Iteration 900, Δt 2 minutes, max(vel): (1.84e-01, 2.12e-02), max(trac): 2.27, 0.00, wtime: 11.266 seconds
[ Info: Time: 1.264 days, Iteration 910, Δt 2 minutes, max(vel): (1.88e-01, 2.28e-02), max(trac): 2.27, 0.00, wtime: 11.233 seconds
[ Info: Time: 1.278 days, Iteration 920, Δt 2 minutes, max(vel): (1.83e-01, 2.12e-02), max(trac): 2.27, 0.00, wtime: 11.280 seconds
[ Info: Time: 1.292 days, Iteration 930, Δt 2 minutes, max(vel): (1.86e-01, 2.07e-02), max(trac): 2.28, 0.00, wtime: 11.229 seconds
[ Info: Time: 1.306 days, Iteration 940, Δt 2 minutes, max(vel): (1.85e-01, 2.07e-02), max(trac): 2.28, 0.00, wtime: 11.224 seconds
[ Info: Time: 1.319 days, Iteration 950, Δt 2 minutes, max(vel): (1.85e-01, 2.07e-02), max(trac): 2.29, 0.00, wtime: 11.274 seconds
[ Info: Time: 1.333 days, Iteration 960, Δt 2 minutes, max(vel): (1.87e-01, 2.15e-02), max(trac): 2.29, 0.00, wtime: 11.210 seconds
[ Info: Time: 1.347 days, Iteration 970, Δt 2 minutes, max(vel): (1.85e-01, 2.19e-02), max(trac): 2.29, 0.00, wtime: 11.230 seconds
[ Info: Time: 1.361 days, Iteration 980, Δt 2 minutes, max(vel): (1.83e-01, 2.22e-02), max(trac): 2.29, 0.00, wtime: 11.220 seconds
[ Info: Time: 1.375 days, Iteration 990, Δt 2 minutes, max(vel): (1.90e-01, 2.03e-02), max(trac): 2.30, 0.00, wtime: 11.190 seconds
[ Info: Time: 1.389 days, Iteration 1000, Δt 2 minutes, max(vel): (1.83e-01, 2.15e-02), max(trac): 2.30, 0.00, wtime: 11.333 seconds
[ Info: Time: 1.403 days, Iteration 1010, Δt 2 minutes, max(vel): (1.84e-01, 2.05e-02), max(trac): 2.30, 0.00, wtime: 11.240 seconds
[ Info: Time: 1.417 days, Iteration 1020, Δt 2 minutes, max(vel): (1.83e-01, 2.30e-02), max(trac): 2.30, 0.00, wtime: 11.230 seconds
[ Info: Time: 1.431 days, Iteration 1030, Δt 2 minutes, max(vel): (1.84e-01, 2.20e-02), max(trac): 2.31, 0.00, wtime: 11.225 seconds
[ Info: Time: 1.444 days, Iteration 1040, Δt 2 minutes, max(vel): (1.87e-01, 2.58e-02), max(trac): 2.31, 0.00, wtime: 11.217 seconds
[ Info: Time: 1.458 days, Iteration 1050, Δt 2 minutes, max(vel): (1.84e-01, 2.05e-02), max(trac): 2.31, 0.00, wtime: 11.239 seconds
[ Info: Time: 1.472 days, Iteration 1060, Δt 2 minutes, max(vel): (1.87e-01, 1.96e-02), max(trac): 2.31, 0.00, wtime: 11.240 seconds
[ Info: Time: 1.486 days, Iteration 1070, Δt 2 minutes, max(vel): (1.87e-01, 2.08e-02), max(trac): 2.32, 0.00, wtime: 11.212 seconds
[ Info: Time: 1.500 days, Iteration 1080, Δt 2 minutes, max(vel): (1.85e-01, 1.91e-02), max(trac): 2.32, 0.00, wtime: 11.214 seconds
[ Info: Time: 1.514 days, Iteration 1090, Δt 2 minutes, max(vel): (1.87e-01, 2.33e-02), max(trac): 2.32, 0.00, wtime: 11.231 seconds
[ Info: Time: 1.528 days, Iteration 1100, Δt 2 minutes, max(vel): (1.86e-01, 1.98e-02), max(trac): 2.32, 0.00, wtime: 11.254 seconds
[ Info: Time: 1.542 days, Iteration 1110, Δt 2 minutes, max(vel): (1.87e-01, 2.08e-02), max(trac): 2.32, 0.00, wtime: 11.199 seconds
[ Info: Time: 1.556 days, Iteration 1120, Δt 2 minutes, max(vel): (1.87e-01, 2.16e-02), max(trac): 2.33, 0.00, wtime: 11.179 seconds
[ Info: Time: 1.569 days, Iteration 1130, Δt 2 minutes, max(vel): (1.85e-01, 2.56e-02), max(trac): 2.33, 0.00, wtime: 11.176 seconds
[ Info: Time: 1.583 days, Iteration 1140, Δt 2 minutes, max(vel): (1.85e-01, 1.95e-02), max(trac): 2.33, 0.00, wtime: 11.216 seconds
[ Info: Time: 1.597 days, Iteration 1150, Δt 2 minutes, max(vel): (1.83e-01, 2.18e-02), max(trac): 2.33, 0.00, wtime: 11.184 seconds
[ Info: Time: 1.611 days, Iteration 1160, Δt 2 minutes, max(vel): (1.87e-01, 2.12e-02), max(trac): 2.33, 0.00, wtime: 11.209 seconds
[ Info: Time: 1.625 days, Iteration 1170, Δt 2 minutes, max(vel): (2.04e-01, 2.41e-02), max(trac): 2.33, 0.00, wtime: 11.190 seconds
[ Info: Time: 1.639 days, Iteration 1180, Δt 2 minutes, max(vel): (1.90e-01, 2.14e-02), max(trac): 2.34, 0.00, wtime: 11.193 seconds
[ Info: Time: 1.653 days, Iteration 1190, Δt 2 minutes, max(vel): (1.85e-01, 2.41e-02), max(trac): 2.34, 0.00, wtime: 11.239 seconds
[ Info: Time: 1.667 days, Iteration 1200, Δt 2 minutes, max(vel): (1.84e-01, 2.14e-02), max(trac): 2.34, 0.00, wtime: 11.243 seconds
[ Info: Time: 1.681 days, Iteration 1210, Δt 2 minutes, max(vel): (1.85e-01, 2.38e-02), max(trac): 2.34, 0.00, wtime: 11.222 seconds
[ Info: Time: 1.694 days, Iteration 1220, Δt 2 minutes, max(vel): (1.90e-01, 2.00e-02), max(trac): 2.34, 0.00, wtime: 11.229 seconds
[ Info: Time: 1.708 days, Iteration 1230, Δt 2 minutes, max(vel): (1.86e-01, 2.08e-02), max(trac): 2.35, 0.00, wtime: 11.189 seconds
[ Info: Time: 1.722 days, Iteration 1240, Δt 2 minutes, max(vel): (1.85e-01, 2.17e-02), max(trac): 2.35, 0.00, wtime: 11.200 seconds
[ Info: Time: 1.736 days, Iteration 1250, Δt 2 minutes, max(vel): (1.85e-01, 2.55e-02), max(trac): 2.35, 0.00, wtime: 11.189 seconds
[ Info: Time: 1.750 days, Iteration 1260, Δt 2 minutes, max(vel): (1.84e-01, 2.21e-02), max(trac): 2.35, 0.00, wtime: 11.186 seconds
[ Info: Time: 1.764 days, Iteration 1270, Δt 2 minutes, max(vel): (1.88e-01, 2.16e-02), max(trac): 2.35, 0.00, wtime: 11.264 seconds
[ Info: Time: 1.778 days, Iteration 1280, Δt 2 minutes, max(vel): (1.88e-01, 2.09e-02), max(trac): 2.35, 0.00, wtime: 11.223 seconds
[ Info: Time: 1.792 days, Iteration 1290, Δt 2 minutes, max(vel): (1.86e-01, 2.82e-02), max(trac): 2.35, 0.00, wtime: 11.220 seconds
[ Info: Time: 1.806 days, Iteration 1300, Δt 2 minutes, max(vel): (1.90e-01, 1.96e-02), max(trac): 2.36, 0.00, wtime: 11.295 seconds
[ Info: Time: 1.819 days, Iteration 1310, Δt 2 minutes, max(vel): (1.85e-01, 2.14e-02), max(trac): 2.36, 0.00, wtime: 11.254 seconds
[ Info: Time: 1.833 days, Iteration 1320, Δt 2 minutes, max(vel): (1.97e-01, 2.29e-02), max(trac): 2.36, 0.00, wtime: 11.285 seconds
[ Info: Time: 1.847 days, Iteration 1330, Δt 2 minutes, max(vel): (1.87e-01, 2.32e-02), max(trac): 2.36, 0.00, wtime: 11.230 seconds
[ Info: Time: 1.861 days, Iteration 1340, Δt 2 minutes, max(vel): (1.88e-01, 2.27e-02), max(trac): 2.36, 0.00, wtime: 11.252 seconds
[ Info: Time: 1.875 days, Iteration 1350, Δt 2 minutes, max(vel): (1.86e-01, 2.12e-02), max(trac): 2.36, 0.00, wtime: 11.251 seconds
[ Info: Time: 1.889 days, Iteration 1360, Δt 2 minutes, max(vel): (1.85e-01, 2.03e-02), max(trac): 2.36, 0.00, wtime: 11.231 seconds
[ Info: Time: 1.903 days, Iteration 1370, Δt 2 minutes, max(vel): (1.88e-01, 2.20e-02), max(trac): 2.36, 0.00, wtime: 11.274 seconds
[ Info: Time: 1.917 days, Iteration 1380, Δt 2 minutes, max(vel): (1.87e-01, 2.24e-02), max(trac): 2.37, 0.00, wtime: 11.237 seconds
[ Info: Time: 1.931 days, Iteration 1390, Δt 2 minutes, max(vel): (1.86e-01, 2.37e-02), max(trac): 2.37, 0.00, wtime: 11.212 seconds
[ Info: Time: 1.944 days, Iteration 1400, Δt 2 minutes, max(vel): (1.88e-01, 2.27e-02), max(trac): 2.37, 0.00, wtime: 11.243 seconds
[ Info: Time: 1.958 days, Iteration 1410, Δt 2 minutes, max(vel): (1.91e-01, 2.64e-02), max(trac): 2.37, 0.00, wtime: 11.241 seconds
[ Info: Time: 1.972 days, Iteration 1420, Δt 2 minutes, max(vel): (1.88e-01, 2.45e-02), max(trac): 2.37, 0.00, wtime: 11.222 seconds
[ Info: Time: 1.986 days, Iteration 1430, Δt 2 minutes, max(vel): (1.87e-01, 2.15e-02), max(trac): 2.37, 0.00, wtime: 11.226 seconds
[ Info: Simulation is stopping after running for 27.838 minutes.
[ Info: Simulation time 2 days equals or exceeds stop time 2 days.
[ Info: Time: 2 days, Iteration 1440, Δt 2 minutes, max(vel): (1.89e-01, 2.22e-02), max(trac): 2.37, 0.00, wtime: 11.199 seconds

Visualize!

Nt = length(htimeseries)
iter = Observable(1)

hi = @lift(htimeseries[$iter][:, :, 1])
ℵi = @lift(ℵtimeseries[$iter][:, :, 1])
ui = @lift(utimeseries[$iter][:, :, 1])
vi = @lift(vtimeseries[$iter][:, :, 1])

fig = Figure(size = (1000, 500))
ax = Axis(fig[1, 1], title = "sea ice thickness")
heatmap!(ax, hi, colormap = :magma,         colorrange = (0.0, 2.0))

ax = Axis(fig[1, 2], title = "sea ice concentration")
heatmap!(ax, ℵi, colormap = Reverse(:deep), colorrange = (0.0, 1))

ax = Axis(fig[2, 1], title = "zonal velocity")
heatmap!(ax, ui, colorrange = (0, 0.12), colormap = :balance)

ax = Axis(fig[2, 2], title = "meridional velocity")
heatmap!(ax, vi, colorrange = (-0.025, 0.025), colormap = :bwr)

CairoMakie.record(fig, "sea_ice_advected_on_coastline.mp4", 1:Nt, framerate = 8) do i
    iter[] = i
    @info "doing iter $i"
end
[ Info: doing iter 1
[ Info: doing iter 2
[ Info: doing iter 3
[ Info: doing iter 4
[ Info: doing iter 5
[ Info: doing iter 6
[ Info: doing iter 7
[ Info: doing iter 8
[ Info: doing iter 9
[ Info: doing iter 10
[ Info: doing iter 11
[ Info: doing iter 12
[ Info: doing iter 13
[ Info: doing iter 14
[ Info: doing iter 15
[ Info: doing iter 16
[ Info: doing iter 17
[ Info: doing iter 18
[ Info: doing iter 19
[ Info: doing iter 20
[ Info: doing iter 21
[ Info: doing iter 22
[ Info: doing iter 23
[ Info: doing iter 24
[ Info: doing iter 25
[ Info: doing iter 26
[ Info: doing iter 27
[ Info: doing iter 28
[ Info: doing iter 29
[ Info: doing iter 30
[ Info: doing iter 31
[ Info: doing iter 32
[ Info: doing iter 33
[ Info: doing iter 34
[ Info: doing iter 35
[ Info: doing iter 36
[ Info: doing iter 37
[ Info: doing iter 38
[ Info: doing iter 39
[ Info: doing iter 40
[ Info: doing iter 41
[ Info: doing iter 42
[ Info: doing iter 43
[ Info: doing iter 44
[ Info: doing iter 45
[ Info: doing iter 46
[ Info: doing iter 47
[ Info: doing iter 48
[ Info: doing iter 49
[ Info: doing iter 50
[ Info: doing iter 51
[ Info: doing iter 52
[ Info: doing iter 53
[ Info: doing iter 54
[ Info: doing iter 55
[ Info: doing iter 56
[ Info: doing iter 57
[ Info: doing iter 58
[ Info: doing iter 59
[ Info: doing iter 60
[ Info: doing iter 61
[ Info: doing iter 62
[ Info: doing iter 63
[ Info: doing iter 64
[ Info: doing iter 65
[ Info: doing iter 66
[ Info: doing iter 67
[ Info: doing iter 68
[ Info: doing iter 69
[ Info: doing iter 70
[ Info: doing iter 71
[ Info: doing iter 72
[ Info: doing iter 73
[ Info: doing iter 74
[ Info: doing iter 75
[ Info: doing iter 76
[ Info: doing iter 77
[ Info: doing iter 78
[ Info: doing iter 79
[ Info: doing iter 80
[ Info: doing iter 81
[ Info: doing iter 82
[ Info: doing iter 83
[ Info: doing iter 84
[ Info: doing iter 85
[ Info: doing iter 86
[ Info: doing iter 87
[ Info: doing iter 88
[ Info: doing iter 89
[ Info: doing iter 90
[ Info: doing iter 91
[ Info: doing iter 92
[ Info: doing iter 93
[ Info: doing iter 94
[ Info: doing iter 95
[ Info: doing iter 96
[ Info: doing iter 97
[ Info: doing iter 98
[ Info: doing iter 99
[ Info: doing iter 100
[ Info: doing iter 101
[ Info: doing iter 102
[ Info: doing iter 103
[ Info: doing iter 104
[ Info: doing iter 105
[ Info: doing iter 106
[ Info: doing iter 107
[ Info: doing iter 108
[ Info: doing iter 109
[ Info: doing iter 110
[ Info: doing iter 111
[ Info: doing iter 112
[ Info: doing iter 113
[ Info: doing iter 114
[ Info: doing iter 115
[ Info: doing iter 116
[ Info: doing iter 117
[ Info: doing iter 118
[ Info: doing iter 119
[ Info: doing iter 120
[ Info: doing iter 121
[ Info: doing iter 122
[ Info: doing iter 123
[ Info: doing iter 124
[ Info: doing iter 125
[ Info: doing iter 126
[ Info: doing iter 127
[ Info: doing iter 128
[ Info: doing iter 129
[ Info: doing iter 130
[ Info: doing iter 131
[ Info: doing iter 132
[ Info: doing iter 133
[ Info: doing iter 134
[ Info: doing iter 135
[ Info: doing iter 136
[ Info: doing iter 137
[ Info: doing iter 138
[ Info: doing iter 139
[ Info: doing iter 140
[ Info: doing iter 141
[ Info: doing iter 142
[ Info: doing iter 143
[ Info: doing iter 144
[ Info: doing iter 145


This page was generated using Literate.jl.