Skip to content

Commit

Permalink
Merge branch 'main' into jsw/bump-oceananigans-0.90
Browse files Browse the repository at this point in the history
  • Loading branch information
jagoosw authored Nov 8, 2023
2 parents 476ad87 + f677df5 commit f610b33
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"

[compat]
Adapt = "3"
Documenter = "0.27"
Documenter = "1"
JLD2 = "0.4"
KernelAbstractions = "0.9"
Oceananigans = "0.90"
Expand Down
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ model_parameters = (LOBSTER(; grid = BoxModelGrid()),
GasExchange(; gas = :CO₂).condition.func,
GasExchange(; gas = :O₂).condition.func)

gas_exchange_gas(::Val{G}) where G = G
exchanged_gas(::Val{G}) where G = G

model_name(model) = if Base.typename(typeof(model)).wrapper == GasExchange
"$(gas_exchange_gas(model.gas)) air-sea exchange"
"$(exchanged_gas(model.gas)) air-sea exchange"
else
Base.typename(typeof(model)).wrapper
end
Expand Down
10 changes: 2 additions & 8 deletions docs/src/model_components/biogeochemical/LOBSTER.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ julia> using OceanBioME, Oceananigans
julia> grid = RectilinearGrid(size=(3, 3, 30), extent=(10, 10, 200));
julia> bgc_model = LOBSTER(; grid, carbonates = true)
Lodyc-DAMTP Ocean Biogeochemical Simulation Tools for Ecosystem and Resources (LOBSTER) model (Float64)
Optional components:
├── Carbonates ✅
├── Oxygen ❌
└── Variable Redfield Ratio ❌
Sinking Velocities:
├── sPOM: 0.0 to -3.47e-5 m/s
└── bPOM: 0.0 to -0.0023148148148148147 m/s
LOBSTER{Float64} with carbonates ✅, oxygen ❌, variable Redfield ratio ❌and (:sPOM, :bPOM) sinking
Light attenuation: Two-band light attenuation model (Float64)
Sediment: Nothing
Particles: Nothing
Modifiers: Nothing
```

## Model equations
Expand Down
3 changes: 1 addition & 2 deletions src/Light/2band.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ function TwoBandPhotosyntheticallyActiveRadiation(; grid,

field = CenterField(grid; boundary_conditions =
regularize_field_boundary_conditions(
FieldBoundaryConditions(top = ValueBoundaryCondition(surface_PAR)),
grid, :PAR))
FieldBoundaryConditions(top = ValueBoundaryCondition(surface_PAR)), grid, :PAR))

return TwoBandPhotosyntheticallyActiveRadiation(water_red_attenuation,
water_blue_attenuation,
Expand Down
32 changes: 16 additions & 16 deletions src/Models/AdvectedPopulations/LOBSTER/LOBSTER.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,11 @@ julia> using Oceananigans
julia> grid = RectilinearGrid(size=(3, 3, 30), extent=(10, 10, 200));
julia> model = LOBSTER(; grid)
Lodyc-DAMTP Ocean Biogeochemical Simulation Tools for Ecosystem and Resources (LOBSTER) model (Float64)
Optional components:
├── Carbonates ❌
├── Oxygen ❌
└── Variable Redfield Ratio ❌
Sinking Velocities:
├── sPOM: 0.0 to -3.47e-5 m/s
└── bPOM: 0.0 to -0.0023148148148148147 m/s
LOBSTER{Float64} with carbonates ❌, oxygen ❌, variable Redfield ratio ❌and (:sPOM, :bPOM) sinking
Light attenuation: Two-band light attenuation model (Float64)
Sediment: Nothing
Particles: Nothing
Modifiers: Nothing
```
"""
function LOBSTER(; grid,
Expand Down Expand Up @@ -353,7 +347,13 @@ function LOBSTER(; grid,

if scale_negatives
scaler = ScaleNegativeTracers(underlying_biogeochemistry, grid)
modifiers = isnothing(modifiers) ? scaler : (modifiers..., scaler)
if isnothing(modifiers)
modifiers = scaler
elseif modifiers isa Tuple
modifiers = (modifiers..., scaler)
else
modifiers = (modifiers, scaler)
end
end

return Biogeochemistry(underlying_biogeochemistry;
Expand Down Expand Up @@ -432,14 +432,14 @@ adapt_structure(to, lobster::LOBSTER) =
adapt(to, lobster.optionals),
adapt(to, lobster.sinking_velocities))

summary(::LOBSTER{FT, B, W}) where {FT, B, W} = string("Lodyc-DAMTP Ocean Biogeochemical Simulation Tools for Ecosystem and Resources (LOBSTER) model ($FT)")
summary(::LOBSTER{FT, Val{B}, NamedTuple{K, V}}) where {FT, B, K, V} = string("LOBSTER{$FT} with carbonates $(B[1] ? :✅ : :❌), oxygen $(B[2] ? :✅ : :❌), variable Redfield ratio $(B[3] ? :✅ : :❌)and $K sinking")

show(io::IO, model::LOBSTER{FT, Val{B}, W}) where {FT, B, W} = string(summary(model), " \n",
" Optional components:", "\n",
" ├── Carbonates $(B[1] ? :✅ : :❌) \n",
" ├── Oxygen $(B[2] ? :✅ : :❌) \n",
" └── Variable Redfield Ratio $(B[3] ? :✅ : :❌)", "\n",
" Sinking Velocities:", "\n", show_sinking_velocities(model.sinking_velocities))
show(io::IO, model::LOBSTER{FT, Val{B}, W}) where {FT, B, W} = print(io, string("Lodyc-DAMTP Ocean Biogeochemical Simulation Tools for Ecosystem and Resources (LOBSTER) model \n",
"├── Optional components:", "\n",
" ├── Carbonates $(B[1] ? :✅ : :❌) \n",
" ├── Oxygen $(B[2] ? :✅ : :❌) \n",
" └── Variable Redfield Ratio $(B[3] ? :✅ : :❌)", "\n",
"└── Sinking Velocities:", "\n", show_sinking_velocities(model.sinking_velocities)))

@inline maximum_sinking_velocity(bgc::LOBSTER) = maximum(abs, bgc.sinking_velocities.bPOM.w)

Expand Down
13 changes: 5 additions & 8 deletions src/Models/AdvectedPopulations/NPZD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,11 @@ julia> using Oceananigans
julia> grid = RectilinearGrid(size=(20, 30), extent=(200, 200), topology=(Bounded, Flat, Bounded));
julia> model = NutrientPhytoplanktonZooplanktonDetritus(; grid)
Nutrient Phytoplankton Zooplankton Detritus model (Float64)
Sinking Velocities:
├── P: 0.0 to -2.9525462962962963e-6 m/s
└── D: 0.0 to -3.181597222222222e-5 m/s
NutrientPhytoplanktonZooplanktonDetritus{Float64} model, with (:P, :D) sinking
Light attenuation: Two-band light attenuation model (Float64)
Sediment: Nothing
Particles: Nothing
Modifiers: Nothing
```
"""
function NutrientPhytoplanktonZooplanktonDetritus(; grid,
Expand Down Expand Up @@ -297,9 +294,9 @@ function update_boxmodel_state!(model::BoxModel{<:Biogeochemistry{<:NPZD}, <:Any
getproperty(model.values, :T) .= model.forcing.T(model.clock.time)
end

summary(::NPZD{FT, W}) where {FT, W} = string("Nutrient Phytoplankton Zooplankton Detritus model ($FT)")
show(io::IO, model::NPZD) = string(summary(model), " \n",
" Sinking Velocities:", "\n", show_sinking_velocities(model.sinking_velocities))
summary(::NPZD{FT, NamedTuple{K, V}}) where {FT, K, V} = string("NutrientPhytoplanktonZooplanktonDetritus{$FT} model, with $K sinking")
show(io::IO, model::NPZD{FT}) where {FT} = print(io, string("NutrientPhytoplanktonZooplanktonDetritus{$FT} model \n",
"└── Sinking Velocities:", "\n", show_sinking_velocities(model.sinking_velocities)))

@inline maximum_sinking_velocity(bgc::NPZD) = maximum(abs, bgc.sinking_velocities.D.w)

Expand Down
7 changes: 5 additions & 2 deletions src/OceanBioME.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,13 @@ conserved_tracers(model::Biogeochemistry) = conserved_tracers(model.underlying_b

summary(bgc::Biogeochemistry) = string("Biogeochemical model based on $(summary(bgc.underlying_biogeochemistry))")
show(io::IO, model::Biogeochemistry) =
print(io, show(model.underlying_biogeochemistry), " \n",
print(io, summary(model.underlying_biogeochemistry), " \n",
" Light attenuation: ", summary(model.light_attenuation), "\n",
" Sediment: ", summary(model.sediment), "\n",
" Particles: ", summary(model.particles))
" Particles: ", summary(model.particles), "\n",
" Modifiers: ", summary(model.modifiers))

summary(modifiers::Tuple) = tuple([summary(modifier) for modifier in modifiers])

include("Utils/Utils.jl")
include("Boundaries/Boundaries.jl")
Expand Down
5 changes: 5 additions & 0 deletions src/Utils/negative_tracers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using Oceananigans.Architectures: device, architecture, arch_array
using Oceananigans.Biogeochemistry: AbstractBiogeochemistry

import Adapt: adapt_structure, adapt
import Base: summary, show
import Oceananigans.Biogeochemistry: update_tendencies!, update_biogeochemical_state!

"""
Expand Down Expand Up @@ -84,6 +85,10 @@ function ScaleNegativeTracers(bgc::AbstractBiogeochemistry, grid; warn = false)
return ScaleNegativeTracers(tracers, scalefactors, warn)
end

summary(scaler::ScaleNegativeTracers) = string("Mass conserving negative scaling of $(scaler.tracers)")
show(io::IO, scaler::ScaleNegativeTracers) = print(io, string(summary(scaler), "\n",
"└── Scalefactors: $(scaler.scalefactors)"))

function update_biogeochemical_state!(model, scale::ScaleNegativeTracers)
workgroup, worksize = work_layout(model.grid, :xyz)

Expand Down

0 comments on commit f610b33

Please sign in to comment.