Models
There are 3 main types of models in ODINN.jl
, iceflow models, mass balance models and machine learning models. These three families are determined by abstract types, with specific types being declared as subtypes of these abstract types to ensure compatibility through the ODINN ecosystem.
The three main types of models are gathered in a parent type Model
in the following way:
ODINN.Model
— FunctionModel(;
iceflow::Union{IFM, Nothing},
mass_balance::Union{MBM, Nothing},
regressors::NamedTuple = (;),
target::Union{TAR, Nothing} = nothing,
) where {IFM <: IceflowModel, MBM <: MBmodel, TAR <: AbstractTarget}
Creates a new model instance using the provided iceflow, mass balance, and machine learning components.
Arguments
iceflow::Union{IFM, Nothing}
: The iceflow model to be used. Can be a single model ornothing
.mass_balance::Union{MBM, Nothing}
: The mass balance model to be used. Can be a single model ornothing
.machine_learning::Union{MLM, Nothing}
: The machine learning model to be used. Can be a single model ornothing
.
Returns
model
: A new instance ofSleipnir.Model
initialized with the provided components.
ODINN.Model
— MethodModel(;
iceflow::Union{IFM, Nothing},
mass_balance::Union{MBM, Nothing},
regressors::NamedTuple = (;),
target::Union{TAR, Nothing} = nothing,
) where {IFM <: IceflowModel, MBM <: MBmodel, TAR <: AbstractTarget}
Creates a new model instance using the provided iceflow, mass balance, and machine learning components.
Arguments
iceflow::Union{IFM, Nothing}
: The iceflow model to be used. Can be a single model ornothing
.mass_balance::Union{MBM, Nothing}
: The mass balance model to be used. Can be a single model ornothing
.machine_learning::Union{MLM, Nothing}
: The machine learning model to be used. Can be a single model ornothing
.
Returns
model
: A new instance ofSleipnir.Model
initialized with the provided components.
Ice flow models
Ice flow models are used to solve the PDEs describing the gravitational flow of glaciers. All ice flow models must be a subtype of abstract type IceflowModel
. Ice flow models are managed by the Huginn.jl
package.
The main type of ice flow model used in ODINN.jl
right now is a 2D Shallow Ice Approximation (SIA) model (Hutter, 1983). This is declared in the following way:
Huginn.SIA2Dmodel
— TypeSIA2Dmodel(A, C, n, Y, U, n_H, n_∇S)
SIA2Dmodel(params; A, C, n, Y, U, n_H, n_∇S)
Create a SIA2Dmodel
, representing a two-dimensional Shallow Ice Approximation (SIA) model.
The SIA model describes glacier flow under the assumption that deformation and basal sliding dominate the ice dynamics. It relies on:
- Glen's flow law for internal deformation, with flow rate factor
A
and exponentn
, - A sliding law governed by coefficient
C
, - Optionally the user can provide either:
- A specific diffusive velocity
U
such thatD = U * H
- A modified creep coefficient
Y
that takes into account the ice thickness such thatD = (C + Y * 2/(n+2)) * (ρ*g)^n * H^(n_H+1) * |∇S|^(n_∇S-1)
wheren_H
andn_∇S
are optional parameters that control if the SIA should use then
law or not. This formulation is denoted as the hybrid diffusivity in the code.
- A specific diffusive velocity
This struct stores the laws used to compute these three parameters during a simulation. If not provided, default constant laws are used based on glacier-specific values.
Arguments
A
: Law for the flow rate factor. Defaults to a constant value from the glacier.C
: Law for the sliding coefficient. Defaults similarly.n
: Law for the flow law exponent. Defaults similarly.Y
: Law for the hybrid diffusivity. Providing a law forY
discards the laws ofA
,C
andn
.U
: Law for the diffusive velocity. Defaults behavior is to disable it and in such a case it is computed fromA
,C
andn
. Providing a law forU
discards the laws ofA
,C
,n
andY
.n_H::F
: The exponent to use forH
in the SIA equation when using the Y law (hybrid diffusivity). It should benothing
when this law is not used.n_∇S::F
: The exponent to use for∇S
in the SIA equation when using the Y law (hybrid diffusivity). It should benothing
when this law is not used.Y_is_provided::Bool
: Whether the diffusivity is provided by the user through the hybrid diffusivityY
or it has to be computed from the SIA formula fromA
,C
andn
.U_is_provided::Bool
: Whether the diffusivity is provided by the user through the diffusive velocityU
or it has to be computed from the SIA formula fromA
,C
andn
.n_H_is_provided::Bool
: Whether theH
exponent is prescribed by the user, or the one of then
law has to be used. This flag is used only when a law forY
is used.n_∇S_is_provided::Bool
: Whether the∇S
exponent is prescribed by the user, or the one of then
law has to be used. This flag is used only when a law forY
is used.apply_A_in_SIA::Bool
: Whether the value of theA
law should be computed each time the SIA is evaluated.apply_C_in_SIA::Bool
: Whether the value of theC
law should be computed each time the SIA is evaluated.apply_n_in_SIA::Bool
: Whether the value of then
law should be computed each time the SIA is evaluated.apply_Y_in_SIA::Bool
: Whether the value of theY
law should be computed each time the SIA is evaluated.apply_U_in_SIA::Bool
: Whether the value of theU
law should be computed each time the SIA is evaluated.
When a simulation will be run in ODINN.jl
using an ice flow model, its related equation will be solved using OrdinaryDiffEq.jl
. The related equation to a SIA2Dmodel
is declared in its related util functions. These equations need to be defined in-place (to reduce memory allocations and ensure maximum performance, see example below). This is both compatible with the forward runs and with the reverse pass differentiated using Enzyme.jl
.
Huginn.SIA2D!
— FunctionSIA2D!(
dH::Matrix{R},
H::Matrix{R},
simulation::SIM,
t::R,
θ,
) where {R <:Real, SIM <: Simulation}
Simulates the evolution of ice thickness in a 2D shallow ice approximation (SIA) model. Works in-place.
Arguments
dH::Matrix{R}
: Matrix to store the rate of change of ice thickness.H::Matrix{R}
: Matrix representing the ice thickness.simulation::SIM
: Simulation object containing model parameters and state.t::R
: Current simulation time.θ
: Parameters of the laws to be used in the SIA. Can benothing
when no learnable laws are used.
Details
This function updates the ice thickness H
and computes the rate of change dH
using the shallow ice approximation in 2D. It retrieves necessary parameters from the simulation
object, enforces positive ice thickness values, updates glacier surface altimetry and computes surface gradients. It then applies the necessary laws that are not updated via callbacks (A
, C
, n
or U
depending on the use-case) and computes the flux components, and flux divergence.
Notes
- The function operates on a staggered grid for computing gradients and fluxes.
- Surface elevation differences are capped using upstream ice thickness to impose boundary conditions.
- The function modifies the input matrices
dH
andH
in-place.
See also SIA2D
Mass balance models
(Surface) Mass balance models are used to simulate the simplified thermodynamics of the forcing of the atmosphere on glaciers. As per ice flow models, all specific mass balance models needs to be a subtype of the abstract type MBmodel
. Mass balance models are managed by Muninn.jl
. For now, we have simple temperature-index models, with either one or two degree-day factors (DDFs) (Hock, 2003):
Muninn.TImodel1
— TypeTImodel1{F <: AbstractFloat}
A structure representing a temperature index model with degree-day factor and accumulation factor.
Keyword arguments
DDF::F
: Degree-day factor, which is a coefficient used to convert temperature into melt.acc_factor::F
: Accumulation factor, which is a coefficient used to adjust the accumulation of mass.
Type Parameters
F
: A subtype ofAbstractFloat
representing the type of the factors.
Muninn.TImodel1
— MethodTImodel1(params::Sleipnir.Parameters; DDF::F = 7.0/1000.0, acc_factor::F = 1.0/1000.0) where {F <: AbstractFloat}
Create a temperature index model with one degree-day factor (DDF) with the given parameters.
Arguments
params::Sleipnir.Parameters
: The simulation parameters.DDF::F
: Degree-day factor (default is 7.0/1000.0).acc_factor::F
: Accumulation factor (default is 1.0/1000.0).
Returns
TI1_model
: An instance of TImodel1 with the specified parameters.
Surface mass balance models are run in DiscreteCallback
s from OrdinaryDiffEq.jl
, which enable the safe execution during the solving of a PDE in specificly prescribed time steps determined in the steps
field in Sleipnir.SimulationParameters
.
We soon plan to add compatibility with neural networks coming from the MassBalanceMachine, which should become the de facto surface mass balance model in the ODINN.jl
ecosystem.
Regressors
Regressors (e.g. machine learning models) are used in the context of Universal Differential Equations (UDEs, Rackauckas et al., 2020) to parametrize or learn specific parts of differential equations. Machine Learning models are managed by ODINN.jl
. Virtually all available regressors in Julia can be used inside ODINN, but they need to be correctly interfaced. Here is an example of a simple neural network (multilayer perceptron) using Lux.jl
:
ODINN.NeuralNetwork
— TypeNeuralNetwork{
ChainType <: Lux.Chain,
ComponentVectorType <: ComponentVector,
NamedTupleType <: NamedTuple,
} <: MLmodel
Feed-forward neural network.
Fields
architecture::ChainType
:Flux.Chain
neural network architectureθ::ComponentVectorType
: Neural network parametersst::NamedTupleType
: Neural network status
In order to parametrize a given variable inside an (ice flow) model, one can do it via the regressors
keyword in Model
:
nn_model = NeuralNetwork(params)
A_law = LawA(nn_model, params)
model = Model(
iceflow = SIA2Dmodel(params; A=A_law),
mass_balance = TImodel1(params; DDF=6.0/1000.0, acc_factor=1.2/1000.0),
regressors = (; A=nn_model)
)