Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run box model simulation with LOBSTER and scale_negatives = true #238

Open
ali-ramadhan opened this issue Jan 7, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ali-ramadhan
Copy link
Collaborator

ali-ramadhan commented Jan 7, 2025

MWE:

using CairoMakie
using Oceananigans
using Oceananigans.Units
using Oceananigans.Fields: FunctionField

using OceanBioME

const year = years = 365day

grid = BoxModelGrid()
clock = Clock(time = zero(grid))

PAR⁰(t) = 100 * (1 - cos((t + 150days) * 2π / year)) * (1 / (1 + 0.2 * exp(-((mod(t, year) - 200days) / 50days)^2))) + 2

const z = -10
PAR_func(t) = PAR⁰(t) * exp(0.2z)

PAR = FunctionField{Center, Center, Center}(PAR_func, grid; clock)

biogeochemistry = LOBSTER(;
    grid,
    light_attenuation_model = PrescribedPhotosyntheticallyActiveRadiation(PAR),
    carbonates = true,
    oxygen = true,
    variable_redfield = true,
    scale_negatives = false
)

model = BoxModel(; biogeochemistry, clock)

simulation = Simulation(model; Δt = 0.1, stop_time = 10)

run!(simulation)

errors with

ERROR: LoadError: type BoxModel has no field tracers
Stacktrace:
  [1] getproperty
    @ ./Base.jl:37 [inlined]
  [2] (::OceanBioME.var"#21#22"{BoxModel{RectilinearGrid{…}, OceanBioME.ContinuousBiogeochemistry{…}, @NamedTuple{…}, Vector{…}, @NamedTuple{…}, Oceananigans.TimeSteppers.RungeKutta3TimeStepper{…}, Clock{…}, @NamedTuple{}}})(tracer_name::Symbol)
    @ OceanBioME ./none:0
  [3] iterate
    @ ./generator.jl:47 [inlined]
  [4] collect(itr::Base.Generator{NTuple{7, Symbol}, OceanBioME.var"#21#22"{BoxModel{RectilinearGrid{…}, OceanBioME.ContinuousBiogeochemistry{…}, @NamedTuple{…}, Vector{…}, @NamedTuple{…}, Oceananigans.TimeSteppers.RungeKutta3TimeStepper{…}, Clock{…}, @NamedTuple{}}}})
    @ Base ./array.jl:834
  [5] _totuple(::Type{Tuple}, ::Base.Generator{NTuple{7, Symbol}, OceanBioME.var"#21#22"{BoxModel{RectilinearGrid{…}, OceanBioME.ContinuousBiogeochemistry{…}, @NamedTuple{…}, Vector{…}, @NamedTuple{…}, Oceananigans.TimeSteppers.RungeKutta3TimeStepper{…}, Clock{…}, @NamedTuple{}}}})
    @ Base ./tuple.jl:425
  [6] Tuple(itr::Base.Generator{NTuple{7, Symbol}, OceanBioME.var"#21#22"{BoxModel{RectilinearGrid{…}, OceanBioME.ContinuousBiogeochemistry{…}, @NamedTuple{…}, Vector{…}, @NamedTuple{…}, Oceananigans.TimeSteppers.RungeKutta3TimeStepper{…}, Clock{…}, @NamedTuple{}}}})
    @ Base ./tuple.jl:391
  [7] update_biogeochemical_state!(model::BoxModel{RectilinearGrid{…}, OceanBioME.ContinuousBiogeochemistry{…}, @NamedTuple{…}, Vector{…}, @NamedTuple{…}, Oceananigans.TimeSteppers.RungeKutta3TimeStepper{…}, Clock{…}, @NamedTuple{}}, scale::ScaleNegativeTracers{NTuple{…}, Vector{…}, Float64, Bool})
    @ OceanBioME ~/atdepth/OceanBioME.jl/src/Utils/negative_tracers.jl:136
  [8] update_biogeochemical_state!(bgc::OceanBioME.ContinuousBiogeochemistry{…}, model::BoxModel{…})
    @ OceanBioME ~/atdepth/OceanBioME.jl/src/OceanBioME.jl:153
  [9] update_state!(model::BoxModel{RectilinearGrid{…}, OceanBioME.ContinuousBiogeochemistry{…}, @NamedTuple{…}, Vector{…}, @NamedTuple{…}, Oceananigans.TimeSteppers.RungeKutta3TimeStepper{…}, Clock{…}, @NamedTuple{}}, callbacks::Vector{Any}; compute_tendencies::Bool)
    @ OceanBioME.BoxModels ~/atdepth/OceanBioME.jl/src/BoxModel/boxmodel.jl:99
 [10] update_state!(model::BoxModel{RectilinearGrid{…}, OceanBioME.ContinuousBiogeochemistry{…}, @NamedTuple{…}, Vector{…}, @NamedTuple{…}, Oceananigans.TimeSteppers.RungeKutta3TimeStepper{…}, Clock{…}, @NamedTuple{}}, callbacks::Vector{Any})
    @ OceanBioME.BoxModels ~/atdepth/OceanBioME.jl/src/BoxModel/boxmodel.jl:86
 [11] initialize!(sim::Simulation{BoxModel{…}, Float64, Float64, OrderedCollections.OrderedDict{…}, OrderedCollections.OrderedDict{…}, OrderedCollections.OrderedDict{…}})
    @ Oceananigans.Simulations ~/.julia/packages/Oceananigans/GXAdX/src/Simulations/run.jl:202
 [12] time_step!(sim::Simulation{BoxModel{…}, Float64, Float64, OrderedCollections.OrderedDict{…}, OrderedCollections.OrderedDict{…}, OrderedCollections.OrderedDict{…}})
    @ Oceananigans.Simulations ~/.julia/packages/Oceananigans/GXAdX/src/Simulations/run.jl:118
 [13] run!(sim::Simulation{BoxModel{…}, Float64, Float64, OrderedCollections.OrderedDict{…}, OrderedCollections.OrderedDict{…}, OrderedCollections.OrderedDict{…}}; pickup::Bool)
    @ Oceananigans.Simulations ~/.julia/packages/Oceananigans/GXAdX/src/Simulations/run.jl:102
 [14] run!(sim::Simulation{BoxModel{…}, Float64, Float64, OrderedCollections.OrderedDict{…}, OrderedCollections.OrderedDict{…}, OrderedCollections.OrderedDict{…}})
    @ Oceananigans.Simulations ~/.julia/packages/Oceananigans/GXAdX/src/Simulations/run.jl:91
 [15] top-level scope
    @ ~/atdepth/OceanBioME.jl/scale_negatives_error.jl:33
 [16] include(fname::String)
    @ Base.MainInclude ./client.jl:494
 [17] top-level scope
    @ REPL[4]:1
in expression starting at /home/alir/atdepth/OceanBioME.jl/scale_negatives_error.jl:33
Some type information was truncated. Use `show(err)` to see complete types.

but is fine with scale_negatives = false.

Sounds like the issue is that it should model.fields for the box model and model.tracers for Oceananigans.jl models.

cc @almacarolina @suki-atdepthmrv

@ali-ramadhan ali-ramadhan added the bug Something isn't working label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant