Single plant

In this example we setup a single plant in a narrow periodic channel to help understand the drag of the kelp on the water

Install dependencies

First we check we have the dependencies installed

using Pkg
pkg"add Oceananigans OceanBioME GiantKelpDynamics CairoMakie JLD2"

Load the packages and setup the models

using Oceananigans, GiantKelpDynamics, OceanBioME, Oceananigans.Units
using OceanBioME: Biogeochemistry

grid = RectilinearGrid(size = (256, 32, 32), extent = (100, 8, 8))

holdfast_x = [20.]
holdfast_y = [4.]
holdfast_z = [-8.]

max_Δt = 0.5

kelp = GiantKelp(; grid,
                   holdfast_x, holdfast_y, holdfast_z,
                   max_Δt)

@inline sponge(x, y, z) = ifelse(x < 10, 1, 0)

u = Relaxation(; rate = 1/20, target = 0.1, mask = sponge)
v = Relaxation(; rate = 1/20, mask = sponge)
w = Relaxation(; rate = 1/20, mask = sponge)

model = NonhydrostaticModel(; grid,
                              biogeochemistry = Biogeochemistry(NothingBGC(),
                                                                particles = kelp),
                              advection = WENO(),
                              forcing = (; u, v, w),
                              closure = AnisotropicMinimumDissipation())
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
├── grid: 256×32×32 RectilinearGrid{Float64, Oceananigans.Grids.Periodic, Oceananigans.Grids.Periodic, Oceananigans.Grids.Bounded} on Oceananigans.Architectures.CPU with 3×3×3 halo
├── timestepper: QuasiAdamsBashforth2TimeStepper
├── advection scheme: WENO reconstruction order 5
├── tracers: ()
├── closure: Oceananigans.TurbulenceClosures.AnisotropicMinimumDissipation{Oceananigans.TurbulenceClosures.ExplicitTimeDiscretization, @NamedTuple{}, Float64, Nothing}
├── buoyancy: Nothing
└── coriolis: Nothing

Set the initial positions of the plant nodes (relaxed floating to the surface), and the set an initial water velocity

set!(kelp, positions = [0. 0. 3.; 0. 0. 6.; 0. 0. 8.; -3. 0. 8.; -6. 0. 8.; -9. 0. 8.; -12. 0. 8.; -9. 0. 8.;])

set!(model, u = 0.1)

Setup the simulaiton to save the flow and kelp positions

simulation = Simulation(model, Δt = 0.5, stop_time = 10minutes)

prog(sim) = @info "Completed $(prettytime(time(simulation))) in $(simulation.model.clock.iteration) steps with Δt = $(prettytime(simulation.Δt))"

simulation.callbacks[:progress] = Callback(prog, IterationInterval(100))

wizard = TimeStepWizard(cfl = 0.5)
simulation.callbacks[:timestep] = Callback(wizard, IterationInterval(10))

simulation.output_writers[:flow] = JLD2OutputWriter(model, model.velocities, overwrite_existing = true, filename = "single_flow.jld2", schedule = TimeInterval(10))
simulation.output_writers[:kelp] = JLD2OutputWriter(model, (; positions = kelp.positions), overwrite_existing = true, filename = "single_kelp.jld2", schedule = TimeInterval(10))
JLD2OutputWriter scheduled on TimeInterval(10 seconds):
├── filepath: ./single_kelp.jld2
├── 1 outputs: positions
├── array type: Array{Float64}
├── including: [:grid, :coriolis, :buoyancy, :closure]
├── file_splitting: NoFileSplitting
└── file size: 23.0 KiB

Run!

run!(simulation)
[ Info: Initializing simulation...
[ Info: Completed 0 seconds in 0 steps with Δt = 500 ms
[ Info:     ... simulation initialization complete (6.539 seconds)
[ Info: Executing initial time step...
[ Info:     ... initial time step complete (6.157 seconds).
[ Info: Completed 1.398 minutes in 100 steps with Δt = 1.297 seconds
[ Info: Completed 4.029 minutes in 200 steps with Δt = 1.726 seconds
[ Info: Completed 6.781 minutes in 300 steps with Δt = 1.712 seconds
[ Info: Completed 9.325 minutes in 400 steps with Δt = 1.583 seconds
[ Info: Simulation is stopping after running for 6.349 minutes.
[ Info: Simulation time 10 minutes equals or exceeds stop time 10 minutes.

Next we load the data

using CairoMakie, JLD2

u = FieldTimeSeries("single_flow.jld2", "u")

file = jldopen("single_kelp.jld2")

iterations = keys(file["timeseries/t"])

positions = [file["timeseries/positions/$it"] for it in iterations]

close(file)

times = u.times

nothing

Now we can animate the motion of the plant and attenuation of the flow

n = Observable(1)

x_position = @lift positions[$n][1, :, 1] .+ 20
y_position = @lift positions[$n][1, :, 2] .+ 4
z_position = @lift positions[$n][1, :, 3] .- 8

u_vert = @lift interior(u[$n], :, Int(grid.Ny / 2), :)

u_surface = @lift interior(u[$n], :, :, grid.Nz)

xf, yc, zc = nodes(u.grid, Face(), Center(), Center())

fig = Figure(resolution = (1200, 400));

title = @lift "t = $(prettytime(u.times[$n]))"

ax = Axis(fig[1, 1], aspect = DataAspect(); title, ylabel = "z (m)")

hm = heatmap!(ax, xf, zc, u_vert, colormap = :lajolla)

scatter!(ax, x_position, z_position, color = :black)

ax = Axis(fig[2, 1], aspect = DataAspect(), xlabel = "x (m)", ylabel = "y (m)")

hm = heatmap!(ax, xf, yc, u_surface, colormap = :lajolla)

scatter!(ax, x_position, y_position, color = :black)

record(fig, "single.mp4", 1:length(times); framerate = 10) do i;
    n[] = i
end
"single.mp4"

In this video the limitations of the simplified drag stencil can be seen (see previous versions for a more complex stencil). It is better suited to the forest application like in the forest example


This page was generated using Literate.jl.