diff --git a/Project.toml b/Project.toml index 0ac3003..3380a5d 100644 --- a/Project.toml +++ b/Project.toml @@ -18,7 +18,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Reexport = "1" PyCall = "1" Revise = "3" -Sleipnir = "0.3.2" +Sleipnir = "0.3.3" Infiltrator = "1" JLD2 = "0.4" julia = "1.9" diff --git a/src/models/mass_balance/mass_balance_utils.jl b/src/models/mass_balance/mass_balance_utils.jl index e487774..cc68747 100644 --- a/src/models/mass_balance/mass_balance_utils.jl +++ b/src/models/mass_balance/mass_balance_utils.jl @@ -3,9 +3,9 @@ function compute_MB(mb_model::TImodel1, climate_2D_period::Climate2Dstep) return ((mb_model.acc_factor .* climate_2D_period.snow) .- (mb_model.DDF .* climate_2D_period.PDD)) end -function MB_timestep(model::Model, glacier::Glacier, params_solver::SolverParameters, t::F) where {F <: AbstractFloat} +function MB_timestep(model::Model, glacier::G, step::F, t::F) where {F <: AbstractFloat, G <: AbstractGlacier} # First we get the dates of the current time and the previous step - period = partial_year(Day, t - params_solver.step):Day(1):partial_year(Day, t) + period = partial_year(Day, t - step):Day(1):partial_year(Day, t) climate_step::PyObject = get_cumulative_climate(glacier.climate.sel(time=period)) # Convert climate dataset to 2D based on the glacier's DEM climate_2D_step::PyObject = downscale_2D_climate(climate_step, glacier) @@ -14,32 +14,15 @@ function MB_timestep(model::Model, glacier::Glacier, params_solver::SolverParame end -function MB_timestep!(model::Model, glacier::Glacier, params_solver::SolverParameters, t::F) where {F <: AbstractFloat} +function MB_timestep!(model::Model, glacier::G, step::F, t::F) where {F <: AbstractFloat, G <: AbstractGlacier} # First we get the dates of the current time and the previous step - period = partial_year(Day, t - params_solver.step):Day(1):partial_year(Day, t) - @timeit get_timer("ODINN") "Cumulative climate" begin + period = partial_year(Day, t - step):Day(1):partial_year(Day, t) + get_cumulative_climate!(glacier.climate, period) - end + # Convert climate dataset to 2D based on the glacier's DEM - @timeit get_timer("ODINN") "Downscale 2D climate" begin downscale_2D_climate!(glacier) - end - @timeit get_timer("ODINN") "Compute MB" begin - model.iceflow.MB .= compute_MB(model.mass_balance, glacier.climate.climate_2D_step) - end -end -function apply_MB_mask!(H::Matrix{F}, glacier::Glacier, ifm::IceflowModel) where {F <: AbstractFloat} - # Appy MB only over ice, and avoid applying it to the borders in the accummulation area to avoid overflow - MB::Matrix{F}, MB_mask::BitMatrix, MB_total::Matrix{F} = ifm.MB, ifm.MB_mask, ifm.MB_total - MB_mask .= ((H .> 0.0) .&& (MB .< 0.0)) .|| ((H .> 0.0) .&& (glacier.dist_border .> 1.0) .&& (MB .>= 0.0)) - H[MB_mask] .+= MB[MB_mask] - MB_total[MB_mask] .+= MB[MB_mask] + model.iceflow.MB .= compute_MB(model.mass_balance, glacier.climate.climate_2D_step) end -# function apply_MB_mask!(H, MB, MB_total, dist_border::Matrix{Float64}) -# # Appy MB only over ice, and avoid applying it to the borders in the accummulation area to avoid overflow -# MB_mask = ((H .> 0.0) .&& (MB .< 0.0)) .|| ((H .> 0.0) .&& (dist_border .> 1.0) .&& (MB .>= 0.0)) -# H[MB_mask] .+= MB[MB_mask] -# MB_total[MB_mask] .+= MB[MB_mask] -# end \ No newline at end of file