One dimensional column forced by external data with carbonate chemistry

In this example we setup a simple 1D column with the LOBSTER biogeochemical model and observe its evolution. This example demonstrates:

  • How to setup OceanBioME's biogeochemical models
  • How to load external forcing data
  • How to run with optional tracer sets such as carbonate chemistry
  • How to setup a non-uniform grid for better near surface resolution
  • How to visualise results

For this example we use force by mixing layer depth and surface photosynthetically available radiation (PAR) data from the Mercator Ocean model and NASA VIIRS observations.

Install dependencies

First we check we have the dependencies installed

using Pkg
pkg"add OceanBioME, Oceananigans, NetCDF, Interpolations, DataDeps, CairoMakie"

Model setup

First load the required packages

using OceanBioME
using Oceananigans, Random, Printf, NetCDF, Interpolations, DataDeps
using Oceananigans.Units
using Oceananigans.Fields: FunctionField

import Oceananigans.TurbulenceClosures: maximum_numeric_diffusivity

maximum_numeric_diffusivity(κ::NamedTuple) = maximum(maximum.(values(κ)))
maximum_numeric_diffusivity(κ::FunctionField) = maximum(κ)

const year = years = 365days # just for these idealised cases

Load external forcing data

Loading the forcing data from our online copy

dd = DataDep(
    "example_data",
    "example data from subpolar re-analysis and observational products",
    "https://github.com/OceanBioME/OceanBioME_example_data/raw/main/subpolar.nc"
)
register(dd)
filename = datadep"example_data/subpolar.nc"
times = ncread(filename, "time")
temp = ncread(filename, "temp")
salinity = ncread(filename, "so")
mld = ncread(filename, "mld")
par = ncread(filename, "par")

temperature_itp = LinearInterpolation(times, temp)
salinity_itp = LinearInterpolation(times, salinity)
mld_itp = LinearInterpolation(times, mld)
PAR_itp = LinearInterpolation(times, par)

t_function(x, y, z, t) = temperature_itp(mod(t, 364days))
s_function(x, y, z, t) = salinity_itp(mod(t, 364days))
surface_PAR(x, y, t) = PAR_itp(mod(t, 364days))
κₜ(x, y, z, t) = 2e-2 * max(1 - (z + mld_itp(mod(t, 364days)) / 2)^2 / (mld_itp(mod(t, 364days)) / 2)^2, 0) + 1e-4

Grid and diffusivity field

Define the grid (in this case a non uniform grid for better resolution near the surface) and an extra Oceananigans field for the PAR to be stored in

Nz = 33
Lz = 600meters
refinement = 10
stretching = 5.754
h(k) = (k - 1) / Nz
ζ₀(k) = 1 + (h(k) - 1) / refinement
Σ(k) = (1 - exp(-stretching * h(k))) / (1 - exp(-stretching))
z_faces(k) = Lz * (ζ₀(k) * Σ(k) - 1)

grid = RectilinearGrid(size = (1, 1, Nz), x = (0, 20meters), y = (0, 20meters), z = z_faces)

clock = Clock(; time = 0.0)

κ = FunctionField{Center, Center, Center}(κₜ, grid; clock)
FunctionField located at (Center, Center, Center)
├── func: κₜ (generic function with 1 method)
├── grid: 1×1×33 RectilinearGrid{Float64, Oceananigans.Grids.Periodic, Oceananigans.Grids.Periodic, Oceananigans.Grids.Bounded} on Oceananigans.Architectures.CPU with 1×1×3 halo
├── clock: Clock{Float64, Float64}(time=0 seconds, iteration=0, last_Δt=Inf days)
└── parameters: nothing

Biogeochemical and Oceananigans model

Here we instantiate the LOBSTER model with carbonate chemistry and a surface flux of DIC (CO₂)

biogeochemistry = LOBSTER(; grid,
                            surface_photosynthetically_active_radiation = surface_PAR,
                            carbonates = true,
                            scale_negatives = true)

CO₂_flux = GasExchange(; gas = :CO₂)

T = FunctionField{Center, Center, Center}(t_function, grid; clock)
S = FunctionField{Center, Center, Center}(s_function, grid; clock)

model = NonhydrostaticModel(; grid, clock,
                              closure = ScalarDiffusivity(ν = κ, κ = κ),
                              biogeochemistry,
                              boundary_conditions = (DIC = FieldBoundaryConditions(top = CO₂_flux),),
                              auxiliary_fields = (; T, S))

set!(model, P = 0.03, Z = 0.03, NO₃ = 11.0, NH₄ = 0.05, DIC = 2200.0, Alk = 2400.0)

Simulation

Next we setup the simulation along with some callbacks that:

  • Show the progress of the simulation
  • Store the output
  • Prevent the tracers from going negative from numerical error (see discussion of this in the positivity preservation implementation page)
  • Adapt the timestep length to reduce the run time
simulation = Simulation(model, Δt = 1minutes, stop_time = 100days)

progress_message(sim) = @printf("Iteration: %04d, time: %s, Δt: %s, wall time: %s\n",
                                iteration(sim),
                                prettytime(sim),
                                prettytime(sim.Δt),
                                prettytime(sim.run_wall_time))

simulation.callbacks[:progress] = Callback(progress_message, IterationInterval(500))

filename = "data_forced"
simulation.output_writers[:profiles] = JLD2OutputWriter(model,
                                                        model.tracers,
                                                        filename = "$filename.jld2",
                                                        schedule = TimeInterval(1day),
                                                        overwrite_existing = true)

wizard = TimeStepWizard(cfl = 0.2, diffusive_cfl = 0.2,
                        max_change = 1.5, min_change = 0.75,
                        cell_advection_timescale = column_advection_timescale)

simulation.callbacks[:wizard] = Callback(wizard, IterationInterval(10))

Run!

We are ready to run the simulation

run!(simulation)
[ Info: Initializing simulation...
Iteration: 0000, time: 0 seconds, Δt: 1 minute, wall time: 0 seconds
[ Info:     ... simulation initialization complete (2.415 seconds)
[ Info: Executing initial time step...
[ Info:     ... initial time step complete (4.914 seconds).
Iteration: 0500, time: 6.595 hours, Δt: 47.460 seconds, wall time: 8.712 seconds
Iteration: 1000, time: 13.184 hours, Δt: 47.420 seconds, wall time: 10.072 seconds
Iteration: 1500, time: 19.767 hours, Δt: 47.386 seconds, wall time: 11.434 seconds
Iteration: 2000, time: 1.098 days, Δt: 47.380 seconds, wall time: 12.803 seconds
Iteration: 2500, time: 1.372 days, Δt: 47.427 seconds, wall time: 14.158 seconds
Iteration: 3000, time: 1.647 days, Δt: 47.487 seconds, wall time: 15.524 seconds
Iteration: 3500, time: 1.921 days, Δt: 47.481 seconds, wall time: 16.896 seconds
Iteration: 4000, time: 2.196 days, Δt: 47.312 seconds, wall time: 18.271 seconds
Iteration: 4500, time: 2.470 days, Δt: 47.360 seconds, wall time: 19.639 seconds
Iteration: 5000, time: 2.744 days, Δt: 47.449 seconds, wall time: 21.001 seconds
Iteration: 5500, time: 3.018 days, Δt: 47.405 seconds, wall time: 22.375 seconds
Iteration: 6000, time: 3.292 days, Δt: 47.445 seconds, wall time: 23.743 seconds
Iteration: 6500, time: 3.566 days, Δt: 47.337 seconds, wall time: 25.104 seconds
Iteration: 7000, time: 3.841 days, Δt: 47.312 seconds, wall time: 26.473 seconds
Iteration: 7500, time: 4.115 days, Δt: 47.427 seconds, wall time: 27.855 seconds
Iteration: 8000, time: 4.389 days, Δt: 47.347 seconds, wall time: 29.208 seconds
Iteration: 8500, time: 4.663 days, Δt: 47.314 seconds, wall time: 30.574 seconds
Iteration: 9000, time: 4.937 days, Δt: 47.320 seconds, wall time: 31.937 seconds
Iteration: 9500, time: 5.210 days, Δt: 47.335 seconds, wall time: 33.313 seconds
Iteration: 10000, time: 5.484 days, Δt: 47.349 seconds, wall time: 34.683 seconds
Iteration: 10500, time: 5.758 days, Δt: 47.366 seconds, wall time: 36.042 seconds
Iteration: 11000, time: 6.032 days, Δt: 47.388 seconds, wall time: 37.419 seconds
Iteration: 11500, time: 6.307 days, Δt: 47.442 seconds, wall time: 38.779 seconds
Iteration: 12000, time: 6.581 days, Δt: 47.510 seconds, wall time: 40.147 seconds
Iteration: 12500, time: 6.856 days, Δt: 47.494 seconds, wall time: 41.503 seconds
Iteration: 13000, time: 7.131 days, Δt: 47.500 seconds, wall time: 42.899 seconds
Iteration: 13500, time: 7.406 days, Δt: 47.481 seconds, wall time: 44.270 seconds
Iteration: 14000, time: 7.680 days, Δt: 47.401 seconds, wall time: 45.639 seconds
Iteration: 14500, time: 7.954 days, Δt: 47.345 seconds, wall time: 47.023 seconds
Iteration: 15000, time: 8.228 days, Δt: 47.337 seconds, wall time: 48.460 seconds
Iteration: 15500, time: 8.502 days, Δt: 47.337 seconds, wall time: 49.832 seconds
Iteration: 16000, time: 8.776 days, Δt: 47.337 seconds, wall time: 51.204 seconds
Iteration: 16500, time: 9.049 days, Δt: 47.337 seconds, wall time: 52.655 seconds
Iteration: 17000, time: 9.323 days, Δt: 47.337 seconds, wall time: 54.025 seconds
Iteration: 17500, time: 9.597 days, Δt: 47.337 seconds, wall time: 55.412 seconds
Iteration: 18000, time: 9.871 days, Δt: 47.337 seconds, wall time: 56.786 seconds
Iteration: 18500, time: 10.145 days, Δt: 47.337 seconds, wall time: 58.176 seconds
Iteration: 19000, time: 10.419 days, Δt: 47.337 seconds, wall time: 59.544 seconds
Iteration: 19500, time: 10.693 days, Δt: 47.337 seconds, wall time: 1.015 minutes
Iteration: 20000, time: 10.966 days, Δt: 47.337 seconds, wall time: 1.038 minutes
Iteration: 20500, time: 11.240 days, Δt: 47.338 seconds, wall time: 1.061 minutes
Iteration: 21000, time: 11.514 days, Δt: 47.340 seconds, wall time: 1.084 minutes
Iteration: 21500, time: 11.788 days, Δt: 47.341 seconds, wall time: 1.107 minutes
Iteration: 22000, time: 12.061 days, Δt: 47.330 seconds, wall time: 1.130 minutes
Iteration: 22500, time: 12.335 days, Δt: 47.314 seconds, wall time: 1.153 minutes
Iteration: 23000, time: 12.609 days, Δt: 47.376 seconds, wall time: 1.176 minutes
Iteration: 23500, time: 12.884 days, Δt: 47.531 seconds, wall time: 1.199 minutes
Iteration: 24000, time: 13.158 days, Δt: 47.431 seconds, wall time: 1.223 minutes
Iteration: 24500, time: 13.432 days, Δt: 47.385 seconds, wall time: 1.246 minutes
Iteration: 25000, time: 13.707 days, Δt: 47.349 seconds, wall time: 1.269 minutes
Iteration: 25500, time: 13.981 days, Δt: 47.325 seconds, wall time: 1.292 minutes
Iteration: 26000, time: 14.254 days, Δt: 47.332 seconds, wall time: 1.315 minutes
Iteration: 26500, time: 14.528 days, Δt: 47.345 seconds, wall time: 1.339 minutes
Iteration: 27000, time: 14.802 days, Δt: 47.360 seconds, wall time: 1.362 minutes
Iteration: 27500, time: 15.076 days, Δt: 47.408 seconds, wall time: 1.386 minutes
Iteration: 28000, time: 15.351 days, Δt: 47.467 seconds, wall time: 1.409 minutes
Iteration: 28500, time: 15.625 days, Δt: 47.334 seconds, wall time: 1.432 minutes
Iteration: 29000, time: 15.899 days, Δt: 47.317 seconds, wall time: 1.456 minutes
Iteration: 29500, time: 16.173 days, Δt: 47.337 seconds, wall time: 1.479 minutes
Iteration: 30000, time: 16.447 days, Δt: 47.337 seconds, wall time: 1.502 minutes
Iteration: 30500, time: 16.720 days, Δt: 47.337 seconds, wall time: 1.526 minutes
Iteration: 31000, time: 16.994 days, Δt: 47.337 seconds, wall time: 1.548 minutes
Iteration: 31500, time: 17.268 days, Δt: 47.333 seconds, wall time: 1.572 minutes
Iteration: 32000, time: 17.542 days, Δt: 47.329 seconds, wall time: 1.595 minutes
Iteration: 32500, time: 17.816 days, Δt: 47.326 seconds, wall time: 1.618 minutes
Iteration: 33000, time: 18.089 days, Δt: 47.323 seconds, wall time: 1.642 minutes
Iteration: 33500, time: 18.363 days, Δt: 47.321 seconds, wall time: 1.665 minutes
Iteration: 34000, time: 18.637 days, Δt: 47.319 seconds, wall time: 1.689 minutes
Iteration: 34500, time: 18.911 days, Δt: 47.318 seconds, wall time: 1.713 minutes
Iteration: 35000, time: 19.185 days, Δt: 47.320 seconds, wall time: 1.736 minutes
Iteration: 35500, time: 19.458 days, Δt: 47.325 seconds, wall time: 1.760 minutes
Iteration: 36000, time: 19.732 days, Δt: 47.330 seconds, wall time: 1.785 minutes
Iteration: 36500, time: 20.006 days, Δt: 47.337 seconds, wall time: 1.808 minutes
Iteration: 37000, time: 20.280 days, Δt: 47.337 seconds, wall time: 1.831 minutes
Iteration: 37500, time: 20.554 days, Δt: 47.337 seconds, wall time: 1.856 minutes
Iteration: 38000, time: 20.828 days, Δt: 47.337 seconds, wall time: 1.879 minutes
Iteration: 38500, time: 21.101 days, Δt: 47.337 seconds, wall time: 1.902 minutes
Iteration: 39000, time: 21.375 days, Δt: 47.337 seconds, wall time: 1.925 minutes
Iteration: 39500, time: 21.649 days, Δt: 47.337 seconds, wall time: 1.948 minutes
Iteration: 40000, time: 21.923 days, Δt: 47.337 seconds, wall time: 1.971 minutes
Iteration: 40500, time: 22.197 days, Δt: 47.335 seconds, wall time: 1.994 minutes
Iteration: 41000, time: 22.471 days, Δt: 47.332 seconds, wall time: 2.017 minutes
Iteration: 41500, time: 22.745 days, Δt: 47.329 seconds, wall time: 2.039 minutes
Iteration: 42000, time: 23.018 days, Δt: 47.328 seconds, wall time: 2.063 minutes
Iteration: 42500, time: 23.292 days, Δt: 47.400 seconds, wall time: 2.086 minutes
Iteration: 43000, time: 23.567 days, Δt: 47.522 seconds, wall time: 2.108 minutes
Iteration: 43500, time: 23.842 days, Δt: 47.420 seconds, wall time: 2.131 minutes
Iteration: 44000, time: 24.116 days, Δt: 47.336 seconds, wall time: 2.155 minutes
Iteration: 44500, time: 24.389 days, Δt: 47.312 seconds, wall time: 2.178 minutes
Iteration: 45000, time: 24.663 days, Δt: 47.345 seconds, wall time: 2.201 minutes
Iteration: 45500, time: 24.938 days, Δt: 47.428 seconds, wall time: 2.223 minutes
Iteration: 46000, time: 25.212 days, Δt: 47.461 seconds, wall time: 2.247 minutes
Iteration: 46500, time: 25.487 days, Δt: 47.468 seconds, wall time: 2.269 minutes
Iteration: 47000, time: 25.761 days, Δt: 47.475 seconds, wall time: 2.292 minutes
Iteration: 47500, time: 26.036 days, Δt: 47.482 seconds, wall time: 2.316 minutes
Iteration: 48000, time: 26.310 days, Δt: 47.481 seconds, wall time: 2.339 minutes
Iteration: 48500, time: 26.585 days, Δt: 47.481 seconds, wall time: 2.362 minutes
Iteration: 49000, time: 26.860 days, Δt: 47.480 seconds, wall time: 2.385 minutes
Iteration: 49500, time: 27.135 days, Δt: 47.481 seconds, wall time: 2.408 minutes
Iteration: 50000, time: 27.409 days, Δt: 47.483 seconds, wall time: 2.431 minutes
Iteration: 50500, time: 27.684 days, Δt: 47.485 seconds, wall time: 2.455 minutes
Iteration: 51000, time: 27.959 days, Δt: 47.487 seconds, wall time: 2.479 minutes
Iteration: 51500, time: 28.234 days, Δt: 47.489 seconds, wall time: 2.503 minutes
Iteration: 52000, time: 28.508 days, Δt: 47.491 seconds, wall time: 2.526 minutes
Iteration: 52500, time: 28.783 days, Δt: 47.492 seconds, wall time: 2.549 minutes
Iteration: 53000, time: 29.058 days, Δt: 47.497 seconds, wall time: 2.572 minutes
Iteration: 53500, time: 29.333 days, Δt: 47.515 seconds, wall time: 2.595 minutes
Iteration: 54000, time: 29.608 days, Δt: 47.533 seconds, wall time: 2.619 minutes
Iteration: 54500, time: 29.883 days, Δt: 47.550 seconds, wall time: 2.642 minutes
Iteration: 55000, time: 30.158 days, Δt: 47.502 seconds, wall time: 2.665 minutes
Iteration: 55500, time: 30.433 days, Δt: 47.443 seconds, wall time: 2.688 minutes
Iteration: 56000, time: 30.707 days, Δt: 47.396 seconds, wall time: 2.711 minutes
Iteration: 56500, time: 30.981 days, Δt: 47.360 seconds, wall time: 2.734 minutes
Iteration: 57000, time: 31.255 days, Δt: 47.358 seconds, wall time: 2.757 minutes
Iteration: 57500, time: 31.529 days, Δt: 47.359 seconds, wall time: 2.781 minutes
Iteration: 58000, time: 31.803 days, Δt: 47.360 seconds, wall time: 2.804 minutes
Iteration: 58500, time: 32.077 days, Δt: 47.372 seconds, wall time: 2.827 minutes
Iteration: 59000, time: 32.351 days, Δt: 47.426 seconds, wall time: 2.851 minutes
Iteration: 59500, time: 32.626 days, Δt: 47.499 seconds, wall time: 2.874 minutes
Iteration: 60000, time: 32.901 days, Δt: 47.518 seconds, wall time: 2.897 minutes
Iteration: 60500, time: 33.175 days, Δt: 47.480 seconds, wall time: 2.920 minutes
Iteration: 61000, time: 33.450 days, Δt: 47.466 seconds, wall time: 2.943 minutes
Iteration: 61500, time: 33.725 days, Δt: 47.451 seconds, wall time: 2.966 minutes
Iteration: 62000, time: 33.999 days, Δt: 47.438 seconds, wall time: 2.989 minutes
Iteration: 62500, time: 34.273 days, Δt: 47.454 seconds, wall time: 3.012 minutes
Iteration: 63000, time: 34.548 days, Δt: 47.471 seconds, wall time: 3.035 minutes
Iteration: 63500, time: 34.823 days, Δt: 47.489 seconds, wall time: 3.058 minutes
Iteration: 64000, time: 35.097 days, Δt: 47.433 seconds, wall time: 3.081 minutes
Iteration: 64500, time: 35.371 days, Δt: 47.317 seconds, wall time: 3.104 minutes
Iteration: 65000, time: 35.645 days, Δt: 47.362 seconds, wall time: 3.127 minutes
Iteration: 65500, time: 35.920 days, Δt: 47.487 seconds, wall time: 3.150 minutes
Iteration: 66000, time: 36.194 days, Δt: 47.399 seconds, wall time: 3.174 minutes
Iteration: 66500, time: 36.468 days, Δt: 47.376 seconds, wall time: 3.197 minutes
Iteration: 67000, time: 36.743 days, Δt: 47.357 seconds, wall time: 3.219 minutes
Iteration: 67500, time: 37.016 days, Δt: 47.345 seconds, wall time: 3.243 minutes
Iteration: 68000, time: 37.291 days, Δt: 47.500 seconds, wall time: 3.266 minutes
Iteration: 68500, time: 37.566 days, Δt: 47.382 seconds, wall time: 3.289 minutes
Iteration: 69000, time: 37.839 days, Δt: 47.312 seconds, wall time: 3.312 minutes
Iteration: 69500, time: 38.113 days, Δt: 47.336 seconds, wall time: 3.335 minutes
Iteration: 70000, time: 38.387 days, Δt: 47.367 seconds, wall time: 3.358 minutes
Iteration: 70500, time: 38.661 days, Δt: 47.411 seconds, wall time: 3.381 minutes
Iteration: 71000, time: 38.936 days, Δt: 47.464 seconds, wall time: 3.404 minutes
Iteration: 71500, time: 39.210 days, Δt: 47.480 seconds, wall time: 3.427 minutes
Iteration: 72000, time: 39.485 days, Δt: 47.480 seconds, wall time: 3.450 minutes
Iteration: 72500, time: 39.759 days, Δt: 47.480 seconds, wall time: 3.473 minutes
Iteration: 73000, time: 40.034 days, Δt: 47.480 seconds, wall time: 3.497 minutes
Iteration: 73500, time: 40.309 days, Δt: 47.480 seconds, wall time: 3.520 minutes
Iteration: 74000, time: 40.584 days, Δt: 47.480 seconds, wall time: 3.543 minutes
Iteration: 74500, time: 40.858 days, Δt: 47.480 seconds, wall time: 3.566 minutes
Iteration: 75000, time: 41.133 days, Δt: 47.480 seconds, wall time: 3.589 minutes
Iteration: 75500, time: 41.408 days, Δt: 47.480 seconds, wall time: 3.612 minutes
Iteration: 76000, time: 41.683 days, Δt: 47.480 seconds, wall time: 3.635 minutes
Iteration: 76500, time: 41.957 days, Δt: 47.480 seconds, wall time: 3.658 minutes
Iteration: 77000, time: 42.232 days, Δt: 47.480 seconds, wall time: 3.682 minutes
Iteration: 77500, time: 42.507 days, Δt: 47.480 seconds, wall time: 3.705 minutes
Iteration: 78000, time: 42.781 days, Δt: 47.480 seconds, wall time: 3.728 minutes
Iteration: 78500, time: 43.056 days, Δt: 47.480 seconds, wall time: 3.751 minutes
Iteration: 79000, time: 43.331 days, Δt: 47.480 seconds, wall time: 3.774 minutes
Iteration: 79500, time: 43.606 days, Δt: 47.480 seconds, wall time: 3.799 minutes
Iteration: 80000, time: 43.880 days, Δt: 47.480 seconds, wall time: 3.823 minutes
Iteration: 80500, time: 44.155 days, Δt: 47.421 seconds, wall time: 3.847 minutes
Iteration: 81000, time: 44.429 days, Δt: 47.343 seconds, wall time: 3.870 minutes
Iteration: 81500, time: 44.703 days, Δt: 47.312 seconds, wall time: 3.894 minutes
Iteration: 82000, time: 44.977 days, Δt: 47.333 seconds, wall time: 3.917 minutes
Iteration: 82500, time: 45.250 days, Δt: 47.312 seconds, wall time: 3.940 minutes
Iteration: 83000, time: 45.524 days, Δt: 47.333 seconds, wall time: 3.963 minutes
Iteration: 83500, time: 45.798 days, Δt: 47.401 seconds, wall time: 3.986 minutes
Iteration: 84000, time: 46.073 days, Δt: 47.480 seconds, wall time: 4.010 minutes
Iteration: 84500, time: 46.347 days, Δt: 47.480 seconds, wall time: 4.033 minutes
Iteration: 85000, time: 46.622 days, Δt: 47.480 seconds, wall time: 4.056 minutes
Iteration: 85500, time: 46.897 days, Δt: 47.480 seconds, wall time: 4.079 minutes
Iteration: 86000, time: 47.171 days, Δt: 47.480 seconds, wall time: 4.103 minutes
Iteration: 86500, time: 47.446 days, Δt: 47.480 seconds, wall time: 4.126 minutes
Iteration: 87000, time: 47.721 days, Δt: 47.480 seconds, wall time: 4.149 minutes
Iteration: 87500, time: 47.996 days, Δt: 47.480 seconds, wall time: 4.173 minutes
Iteration: 88000, time: 48.270 days, Δt: 47.475 seconds, wall time: 4.196 minutes
Iteration: 88500, time: 48.545 days, Δt: 47.470 seconds, wall time: 4.220 minutes
Iteration: 89000, time: 48.820 days, Δt: 47.466 seconds, wall time: 4.244 minutes
Iteration: 89500, time: 49.094 days, Δt: 47.461 seconds, wall time: 4.267 minutes
Iteration: 90000, time: 49.369 days, Δt: 47.456 seconds, wall time: 4.290 minutes
Iteration: 90500, time: 49.643 days, Δt: 47.451 seconds, wall time: 4.314 minutes
Iteration: 91000, time: 49.918 days, Δt: 47.446 seconds, wall time: 4.337 minutes
Iteration: 91500, time: 50.192 days, Δt: 47.448 seconds, wall time: 4.360 minutes
Iteration: 92000, time: 50.467 days, Δt: 47.454 seconds, wall time: 4.383 minutes
Iteration: 92500, time: 50.741 days, Δt: 47.459 seconds, wall time: 4.406 minutes
Iteration: 93000, time: 51.016 days, Δt: 47.464 seconds, wall time: 4.430 minutes
Iteration: 93500, time: 51.291 days, Δt: 47.462 seconds, wall time: 4.453 minutes
Iteration: 94000, time: 51.565 days, Δt: 47.460 seconds, wall time: 4.476 minutes
Iteration: 94500, time: 51.840 days, Δt: 47.458 seconds, wall time: 4.499 minutes
Iteration: 95000, time: 52.114 days, Δt: 47.456 seconds, wall time: 4.523 minutes
Iteration: 95500, time: 52.389 days, Δt: 47.452 seconds, wall time: 4.546 minutes
Iteration: 96000, time: 52.663 days, Δt: 47.449 seconds, wall time: 4.569 minutes
Iteration: 96500, time: 52.938 days, Δt: 47.445 seconds, wall time: 4.592 minutes
Iteration: 97000, time: 53.213 days, Δt: 47.445 seconds, wall time: 4.615 minutes
Iteration: 97500, time: 53.487 days, Δt: 47.445 seconds, wall time: 4.638 minutes
Iteration: 98000, time: 53.762 days, Δt: 47.445 seconds, wall time: 4.661 minutes
Iteration: 98500, time: 54.036 days, Δt: 47.445 seconds, wall time: 4.684 minutes
Iteration: 99000, time: 54.310 days, Δt: 47.451 seconds, wall time: 4.708 minutes
Iteration: 99500, time: 54.585 days, Δt: 47.457 seconds, wall time: 4.731 minutes
Iteration: 100000, time: 54.860 days, Δt: 47.463 seconds, wall time: 4.754 minutes
Iteration: 100500, time: 55.134 days, Δt: 47.468 seconds, wall time: 4.778 minutes
Iteration: 101000, time: 55.409 days, Δt: 47.472 seconds, wall time: 4.801 minutes
Iteration: 101500, time: 55.683 days, Δt: 47.475 seconds, wall time: 4.824 minutes
Iteration: 102000, time: 55.958 days, Δt: 47.479 seconds, wall time: 4.848 minutes
Iteration: 102500, time: 56.233 days, Δt: 47.480 seconds, wall time: 4.871 minutes
Iteration: 103000, time: 56.508 days, Δt: 47.480 seconds, wall time: 4.894 minutes
Iteration: 103500, time: 56.783 days, Δt: 47.480 seconds, wall time: 4.918 minutes
Iteration: 104000, time: 57.057 days, Δt: 47.480 seconds, wall time: 4.941 minutes
Iteration: 104500, time: 57.332 days, Δt: 47.480 seconds, wall time: 4.964 minutes
Iteration: 105000, time: 57.607 days, Δt: 47.480 seconds, wall time: 4.987 minutes
Iteration: 105500, time: 57.881 days, Δt: 47.480 seconds, wall time: 5.011 minutes
Iteration: 106000, time: 58.156 days, Δt: 47.456 seconds, wall time: 5.035 minutes
Iteration: 106500, time: 58.431 days, Δt: 47.418 seconds, wall time: 5.058 minutes
Iteration: 107000, time: 58.705 days, Δt: 47.385 seconds, wall time: 5.081 minutes
Iteration: 107500, time: 58.979 days, Δt: 47.358 seconds, wall time: 5.105 minutes
Iteration: 108000, time: 59.253 days, Δt: 47.379 seconds, wall time: 5.128 minutes
Iteration: 108500, time: 59.527 days, Δt: 47.411 seconds, wall time: 5.152 minutes
Iteration: 109000, time: 59.801 days, Δt: 47.449 seconds, wall time: 5.175 minutes
Iteration: 109500, time: 60.076 days, Δt: 47.480 seconds, wall time: 5.199 minutes
Iteration: 110000, time: 60.351 days, Δt: 47.480 seconds, wall time: 5.222 minutes
Iteration: 110500, time: 60.625 days, Δt: 47.480 seconds, wall time: 5.246 minutes
Iteration: 111000, time: 60.900 days, Δt: 47.480 seconds, wall time: 5.269 minutes
Iteration: 111500, time: 61.175 days, Δt: 47.480 seconds, wall time: 5.293 minutes
Iteration: 112000, time: 61.450 days, Δt: 47.480 seconds, wall time: 5.316 minutes
Iteration: 112500, time: 61.724 days, Δt: 47.480 seconds, wall time: 5.340 minutes
Iteration: 113000, time: 61.999 days, Δt: 47.480 seconds, wall time: 5.364 minutes
Iteration: 113500, time: 62.274 days, Δt: 47.480 seconds, wall time: 5.388 minutes
Iteration: 114000, time: 62.548 days, Δt: 47.480 seconds, wall time: 5.411 minutes
Iteration: 114500, time: 62.823 days, Δt: 47.480 seconds, wall time: 5.434 minutes
Iteration: 115000, time: 63.098 days, Δt: 47.480 seconds, wall time: 5.458 minutes
Iteration: 115500, time: 63.373 days, Δt: 47.480 seconds, wall time: 5.481 minutes
Iteration: 116000, time: 63.647 days, Δt: 47.480 seconds, wall time: 5.505 minutes
Iteration: 116500, time: 63.922 days, Δt: 47.480 seconds, wall time: 5.528 minutes
Iteration: 117000, time: 64.197 days, Δt: 47.480 seconds, wall time: 5.552 minutes
Iteration: 117500, time: 64.472 days, Δt: 47.480 seconds, wall time: 5.575 minutes
Iteration: 118000, time: 64.746 days, Δt: 47.480 seconds, wall time: 5.599 minutes
Iteration: 118500, time: 65.021 days, Δt: 47.471 seconds, wall time: 5.623 minutes
Iteration: 119000, time: 65.295 days, Δt: 47.352 seconds, wall time: 5.646 minutes
Iteration: 119500, time: 65.569 days, Δt: 47.311 seconds, wall time: 5.670 minutes
Iteration: 120000, time: 65.843 days, Δt: 47.364 seconds, wall time: 5.693 minutes
Iteration: 120500, time: 66.117 days, Δt: 47.451 seconds, wall time: 5.717 minutes
Iteration: 121000, time: 66.391 days, Δt: 47.346 seconds, wall time: 5.740 minutes
Iteration: 121500, time: 66.665 days, Δt: 47.331 seconds, wall time: 5.763 minutes
Iteration: 122000, time: 66.940 days, Δt: 47.453 seconds, wall time: 5.786 minutes
Iteration: 122500, time: 67.214 days, Δt: 47.313 seconds, wall time: 5.810 minutes
Iteration: 123000, time: 67.488 days, Δt: 47.312 seconds, wall time: 5.833 minutes
Iteration: 123500, time: 67.763 days, Δt: 47.353 seconds, wall time: 5.857 minutes
Iteration: 124000, time: 68.036 days, Δt: 47.480 seconds, wall time: 5.880 minutes
Iteration: 124500, time: 68.311 days, Δt: 47.480 seconds, wall time: 5.904 minutes
Iteration: 125000, time: 68.586 days, Δt: 47.480 seconds, wall time: 5.927 minutes
Iteration: 125500, time: 68.861 days, Δt: 47.480 seconds, wall time: 5.950 minutes
Iteration: 126000, time: 69.135 days, Δt: 47.480 seconds, wall time: 5.975 minutes
Iteration: 126500, time: 69.410 days, Δt: 47.480 seconds, wall time: 5.999 minutes
Iteration: 127000, time: 69.685 days, Δt: 47.480 seconds, wall time: 6.023 minutes
Iteration: 127500, time: 69.959 days, Δt: 47.480 seconds, wall time: 6.047 minutes
Iteration: 128000, time: 70.234 days, Δt: 47.480 seconds, wall time: 6.072 minutes
Iteration: 128500, time: 70.509 days, Δt: 47.480 seconds, wall time: 6.096 minutes
Iteration: 129000, time: 70.784 days, Δt: 47.480 seconds, wall time: 6.120 minutes
Iteration: 129500, time: 71.058 days, Δt: 47.480 seconds, wall time: 6.143 minutes
Iteration: 130000, time: 71.333 days, Δt: 47.480 seconds, wall time: 6.166 minutes
Iteration: 130500, time: 71.608 days, Δt: 47.480 seconds, wall time: 6.190 minutes
Iteration: 131000, time: 71.883 days, Δt: 47.480 seconds, wall time: 6.213 minutes
Iteration: 131500, time: 72.157 days, Δt: 47.480 seconds, wall time: 6.237 minutes
Iteration: 132000, time: 72.432 days, Δt: 47.480 seconds, wall time: 6.260 minutes
Iteration: 132500, time: 72.707 days, Δt: 47.480 seconds, wall time: 6.284 minutes
Iteration: 133000, time: 72.981 days, Δt: 47.480 seconds, wall time: 6.307 minutes
Iteration: 133500, time: 73.256 days, Δt: 47.480 seconds, wall time: 6.331 minutes
Iteration: 134000, time: 73.531 days, Δt: 47.480 seconds, wall time: 6.354 minutes
Iteration: 134500, time: 73.806 days, Δt: 47.480 seconds, wall time: 6.378 minutes
Iteration: 135000, time: 74.080 days, Δt: 47.480 seconds, wall time: 6.401 minutes
Iteration: 135500, time: 74.355 days, Δt: 47.480 seconds, wall time: 6.425 minutes
Iteration: 136000, time: 74.630 days, Δt: 47.480 seconds, wall time: 6.449 minutes
Iteration: 136500, time: 74.905 days, Δt: 47.480 seconds, wall time: 6.472 minutes
Iteration: 137000, time: 75.179 days, Δt: 47.480 seconds, wall time: 6.496 minutes
Iteration: 137500, time: 75.454 days, Δt: 47.480 seconds, wall time: 6.519 minutes
Iteration: 138000, time: 75.729 days, Δt: 47.480 seconds, wall time: 6.543 minutes
Iteration: 138500, time: 76.003 days, Δt: 47.480 seconds, wall time: 6.566 minutes
Iteration: 139000, time: 76.278 days, Δt: 47.480 seconds, wall time: 6.590 minutes
Iteration: 139500, time: 76.553 days, Δt: 47.480 seconds, wall time: 6.613 minutes
Iteration: 140000, time: 76.828 days, Δt: 47.480 seconds, wall time: 6.636 minutes
Iteration: 140500, time: 77.102 days, Δt: 47.480 seconds, wall time: 6.661 minutes
Iteration: 141000, time: 77.377 days, Δt: 47.480 seconds, wall time: 6.686 minutes
Iteration: 141500, time: 77.652 days, Δt: 47.480 seconds, wall time: 6.709 minutes
Iteration: 142000, time: 77.927 days, Δt: 47.480 seconds, wall time: 6.732 minutes
Iteration: 142500, time: 78.201 days, Δt: 47.480 seconds, wall time: 6.756 minutes
Iteration: 143000, time: 78.476 days, Δt: 47.480 seconds, wall time: 6.780 minutes
Iteration: 143500, time: 78.751 days, Δt: 47.480 seconds, wall time: 6.803 minutes
Iteration: 144000, time: 79.025 days, Δt: 47.480 seconds, wall time: 6.827 minutes
Iteration: 144500, time: 79.300 days, Δt: 47.480 seconds, wall time: 6.851 minutes
Iteration: 145000, time: 79.575 days, Δt: 47.480 seconds, wall time: 6.874 minutes
Iteration: 145500, time: 79.850 days, Δt: 47.480 seconds, wall time: 6.898 minutes
Iteration: 146000, time: 80.124 days, Δt: 47.480 seconds, wall time: 6.922 minutes
Iteration: 146500, time: 80.399 days, Δt: 47.480 seconds, wall time: 6.947 minutes
Iteration: 147000, time: 80.674 days, Δt: 47.480 seconds, wall time: 6.972 minutes
Iteration: 147500, time: 80.948 days, Δt: 47.480 seconds, wall time: 6.996 minutes
Iteration: 148000, time: 81.223 days, Δt: 47.480 seconds, wall time: 7.020 minutes
Iteration: 148500, time: 81.498 days, Δt: 47.480 seconds, wall time: 7.043 minutes
Iteration: 149000, time: 81.773 days, Δt: 47.480 seconds, wall time: 7.067 minutes
Iteration: 149500, time: 82.047 days, Δt: 47.480 seconds, wall time: 7.090 minutes
Iteration: 150000, time: 82.322 days, Δt: 47.480 seconds, wall time: 7.114 minutes
Iteration: 150500, time: 82.597 days, Δt: 47.480 seconds, wall time: 7.137 minutes
Iteration: 151000, time: 82.872 days, Δt: 47.480 seconds, wall time: 7.160 minutes
Iteration: 151500, time: 83.146 days, Δt: 47.480 seconds, wall time: 7.184 minutes
Iteration: 152000, time: 83.421 days, Δt: 47.480 seconds, wall time: 7.208 minutes
Iteration: 152500, time: 83.696 days, Δt: 47.480 seconds, wall time: 7.231 minutes
Iteration: 153000, time: 83.970 days, Δt: 47.480 seconds, wall time: 7.254 minutes
Iteration: 153500, time: 84.245 days, Δt: 47.480 seconds, wall time: 7.278 minutes
Iteration: 154000, time: 84.520 days, Δt: 47.480 seconds, wall time: 7.302 minutes
Iteration: 154500, time: 84.795 days, Δt: 47.480 seconds, wall time: 7.325 minutes
Iteration: 155000, time: 85.069 days, Δt: 47.479 seconds, wall time: 7.349 minutes
Iteration: 155500, time: 85.344 days, Δt: 47.477 seconds, wall time: 7.372 minutes
Iteration: 156000, time: 85.619 days, Δt: 47.475 seconds, wall time: 7.396 minutes
Iteration: 156500, time: 85.893 days, Δt: 47.473 seconds, wall time: 7.419 minutes
Iteration: 157000, time: 86.168 days, Δt: 47.322 seconds, wall time: 7.443 minutes
Iteration: 157500, time: 86.442 days, Δt: 47.322 seconds, wall time: 7.466 minutes
Iteration: 158000, time: 86.716 days, Δt: 47.395 seconds, wall time: 7.490 minutes
Iteration: 158500, time: 86.990 days, Δt: 47.353 seconds, wall time: 7.513 minutes
Iteration: 159000, time: 87.264 days, Δt: 47.463 seconds, wall time: 7.537 minutes
Iteration: 159500, time: 87.539 days, Δt: 47.486 seconds, wall time: 7.561 minutes
Iteration: 160000, time: 87.813 days, Δt: 47.524 seconds, wall time: 7.585 minutes
Iteration: 160500, time: 88.087 days, Δt: 47.325 seconds, wall time: 7.608 minutes
Iteration: 161000, time: 88.360 days, Δt: 47.316 seconds, wall time: 7.632 minutes
Iteration: 161500, time: 88.634 days, Δt: 47.312 seconds, wall time: 7.656 minutes
Iteration: 162000, time: 88.908 days, Δt: 47.313 seconds, wall time: 7.680 minutes
Iteration: 162500, time: 89.181 days, Δt: 47.347 seconds, wall time: 7.704 minutes
Iteration: 163000, time: 89.456 days, Δt: 47.465 seconds, wall time: 7.728 minutes
Iteration: 163500, time: 89.730 days, Δt: 47.448 seconds, wall time: 7.751 minutes
Iteration: 164000, time: 90.004 days, Δt: 47.340 seconds, wall time: 7.775 minutes
Iteration: 164500, time: 90.278 days, Δt: 47.339 seconds, wall time: 7.798 minutes
Iteration: 165000, time: 90.552 days, Δt: 47.338 seconds, wall time: 7.821 minutes
Iteration: 165500, time: 90.826 days, Δt: 47.338 seconds, wall time: 7.844 minutes
Iteration: 166000, time: 91.100 days, Δt: 47.337 seconds, wall time: 7.868 minutes
Iteration: 166500, time: 91.374 days, Δt: 47.337 seconds, wall time: 7.891 minutes
Iteration: 167000, time: 91.648 days, Δt: 47.338 seconds, wall time: 7.915 minutes
Iteration: 167500, time: 91.922 days, Δt: 47.338 seconds, wall time: 7.938 minutes
Iteration: 168000, time: 92.195 days, Δt: 47.312 seconds, wall time: 7.962 minutes
Iteration: 168500, time: 92.469 days, Δt: 47.363 seconds, wall time: 7.985 minutes
Iteration: 169000, time: 92.743 days, Δt: 47.526 seconds, wall time: 8.008 minutes
Iteration: 169500, time: 93.018 days, Δt: 47.350 seconds, wall time: 8.032 minutes
Iteration: 170000, time: 93.292 days, Δt: 47.332 seconds, wall time: 8.055 minutes
Iteration: 170500, time: 93.566 days, Δt: 47.320 seconds, wall time: 8.078 minutes
Iteration: 171000, time: 93.840 days, Δt: 47.395 seconds, wall time: 8.102 minutes
Iteration: 171500, time: 94.114 days, Δt: 47.396 seconds, wall time: 8.125 minutes
Iteration: 172000, time: 94.388 days, Δt: 47.396 seconds, wall time: 8.149 minutes
Iteration: 172500, time: 94.662 days, Δt: 47.396 seconds, wall time: 8.172 minutes
Iteration: 173000, time: 94.937 days, Δt: 47.712 seconds, wall time: 8.196 minutes
Iteration: 173500, time: 95.212 days, Δt: 47.396 seconds, wall time: 8.220 minutes
Iteration: 174000, time: 95.486 days, Δt: 47.423 seconds, wall time: 8.243 minutes
Iteration: 174500, time: 95.760 days, Δt: 47.331 seconds, wall time: 8.267 minutes
Iteration: 175000, time: 96.034 days, Δt: 47.313 seconds, wall time: 8.290 minutes
Iteration: 175500, time: 96.308 days, Δt: 47.350 seconds, wall time: 8.314 minutes
Iteration: 176000, time: 96.582 days, Δt: 47.357 seconds, wall time: 8.337 minutes
Iteration: 176500, time: 96.856 days, Δt: 47.325 seconds, wall time: 8.360 minutes
Iteration: 177000, time: 97.131 days, Δt: 47.429 seconds, wall time: 8.384 minutes
Iteration: 177500, time: 97.405 days, Δt: 47.352 seconds, wall time: 8.407 minutes
Iteration: 178000, time: 97.679 days, Δt: 47.316 seconds, wall time: 8.431 minutes
Iteration: 178500, time: 97.953 days, Δt: 47.316 seconds, wall time: 8.454 minutes
Iteration: 179000, time: 98.226 days, Δt: 47.312 seconds, wall time: 8.478 minutes
Iteration: 179500, time: 98.500 days, Δt: 47.320 seconds, wall time: 8.501 minutes
Iteration: 180000, time: 98.774 days, Δt: 47.352 seconds, wall time: 8.525 minutes
Iteration: 180500, time: 99.048 days, Δt: 47.487 seconds, wall time: 8.549 minutes
Iteration: 181000, time: 99.322 days, Δt: 47.314 seconds, wall time: 8.572 minutes
Iteration: 181500, time: 99.596 days, Δt: 47.312 seconds, wall time: 8.596 minutes
Iteration: 182000, time: 99.870 days, Δt: 47.357 seconds, wall time: 8.619 minutes
[ Info: Simulation is stopping after running for 8.630 minutes.
[ Info: Simulation time 100 days equals or exceeds stop time 100 days.

Load output and plot

Now we can visualise the results with some post processing to diagnose the air-sea CO₂ flux

   P = FieldTimeSeries("$filename.jld2", "P")
 NO₃ = FieldTimeSeries("$filename.jld2", "NO₃")
   Z = FieldTimeSeries("$filename.jld2", "Z")
sPOM = FieldTimeSeries("$filename.jld2", "sPOM")
bPOM = FieldTimeSeries("$filename.jld2", "bPOM")
 DIC = FieldTimeSeries("$filename.jld2", "DIC")
 Alk = FieldTimeSeries("$filename.jld2", "Alk")

x, y, z = nodes(P)
times = P.times

We compute the air-sea CO₂ flux at the surface (corresponding to vertical index k = grid.Nz) and the carbon export by computing how much carbon sinks below some arbitrary depth; here we use depth that corresponds to k = grid.Nz - 20.

air_sea_CO₂_flux = zeros(length(times))
carbon_export = zeros(length(times))

using Oceananigans.Biogeochemistry: biogeochemical_drift_velocity

for (i, t) in enumerate(times)
    air_sea_CO₂_flux[i] = CO₂_flux.condition.func(0.0, 0.0, t, DIC[1, 1, grid.Nz, i], Alk[1, 1, grid.Nz, i], t_function(1, 1, 0, t), s_function(1, 1, 0, t))
    carbon_export[i] = (sPOM[1, 1, grid.Nz-20, i] * biogeochemical_drift_velocity(model.biogeochemistry, Val(:sPOM)).w[1, 1, grid.Nz-20] +
                        bPOM[1, 1, grid.Nz-20, i] * biogeochemical_drift_velocity(model.biogeochemistry, Val(:bPOM)).w[1, 1, grid.Nz-20]) * redfield(Val(:sPOM), model.biogeochemistry)
end

Both air_sea_CO₂_flux and carbon_export are in units mmol CO₂ / (m² s).

using CairoMakie

fig = Figure(size = (1000, 1500), fontsize = 20)

axis_kwargs = (xlabel = "Time (days)", ylabel = "z (m)", limits = ((0, times[end] / days), (-150meters, 0)))

axP = Axis(fig[1, 1]; title = "Phytoplankton concentration (mmol N/m³)", axis_kwargs...)
hmP = heatmap!(times / days, z, interior(P, 1, 1, :, :)', colormap=:batlow)
Colorbar(fig[1, 2], hmP)

axNO₃ = Axis(fig[2, 1]; title = "Nitrate concentration (mmol N/m³)", axis_kwargs...)
hmNO₃ = heatmap!(times / days, z, interior(NO₃, 1, 1, :, :)', colormap=:batlow)
Colorbar(fig[2, 2], hmNO₃)

axZ = Axis(fig[3, 1]; title = "Zooplankton concentration (mmol N/m³)", axis_kwargs...)
hmZ = heatmap!(times / days, z, interior(Z, 1, 1, :, :)', colormap=:batlow)
Colorbar(fig[3, 2], hmZ)

axD = Axis(fig[4, 1]; title = "Detritus concentration (mmol N/m³)", axis_kwargs...)
hmD = heatmap!(times / days, z, interior(sPOM, 1, 1, :, :)' .+ interior(bPOM, 1, 1, :, :)', colormap=:batlow)
Colorbar(fig[4, 2], hmD)

CO₂_molar_mass = (12 + 2 * 16) * 1e-3 # kg / mol

axfDIC = Axis(fig[5, 1], xlabel = "Time (days)", ylabel = "Flux (kgCO₂/m²/year)",
                         title = "Air-sea CO₂ flux and Sinking", limits = ((0, times[end] / days), nothing))
lines!(axfDIC, times / days, cumsum(air_sea_CO₂_flux) /1e3 * CO₂_molar_mass * year, linewidth = 3, label = "Air-sea flux")
lines!(axfDIC, times / days, cumsum(carbon_export) /1e3    * CO₂_molar_mass * year, linewidth = 3, label = "Sinking export")
Legend(fig[5, 2], axfDIC, framevisible = false)

fig


This page was generated using Literate.jl.