From 1dbbcc1689662015e1a1f8cae5d85b1c7354a495 Mon Sep 17 00:00:00 2001 From: Jordi Bolibar Date: Wed, 15 May 2024 14:50:37 +0000 Subject: [PATCH] Changes for functional inversions --- Project.toml | 4 ++-- src/models/mass_balance/mass_balance_utils.jl | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 3444f4d..3073ce1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Muninn" uuid = "4b816528-16ba-4e32-9a2e-3c1bc2049d3a" authors = ["Jordi Bolibar "] -version = "0.2.7" +version = "0.3.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -21,7 +21,7 @@ JLD2 = "0.4" PyCall = "1" Reexport = "1" Revise = "3" -Sleipnir = "0.5" +Sleipnir = "0.6" julia = "1.9" [extras] diff --git a/src/models/mass_balance/mass_balance_utils.jl b/src/models/mass_balance/mass_balance_utils.jl index 2756e3b..20437f6 100644 --- a/src/models/mass_balance/mass_balance_utils.jl +++ b/src/models/mass_balance/mass_balance_utils.jl @@ -16,7 +16,7 @@ function MB_timestep(model::Model, glacier::G, step::F, t::F) where {F <: Abstra end -function MB_timestep!(model::Model, glacier::G, step::F, t::F) where {F <: AbstractFloat, G <: AbstractGlacier} +function MB_timestep!(model::Model, glacier::G, step::F, t; batch_id::Union{Nothing, I} = nothing) where {I <: Integer, F <: AbstractFloat, G <: AbstractGlacier} # First we get the dates of the current time and the previous step period = partial_year(Day, t - step):Day(1):partial_year(Day, t) @@ -24,7 +24,11 @@ function MB_timestep!(model::Model, glacier::G, step::F, t::F) where {F <: Abstr # Convert climate dataset to 2D based on the glacier's DEM downscale_2D_climate!(glacier) - - model.iceflow.MB .= compute_MB(model.mass_balance, glacier.climate.climate_2D_step) + # Simulations using Reverse Diff require an iceflow and mass balance model per glacier + if isnothing(batch_id) + model.iceflow.MB .= compute_MB(model.mass_balance, glacier.climate.climate_2D_step) + else + model.iceflow[batch_id].MB .= compute_MB(model.mass_balance[batch_id], glacier.climate.climate_2D_step) + end end