Laws inputs
This tutorial showcases the different inputs that can be used inside the laws.
using ODINNIf we represent the A simple rheological law that we already presented in the Laws tutorial, we can see that it depends on an input T, which is the long term air temperature:
params = Parameters() # Dummy parameters
nn_model = NeuralNetwork(params)
A_law = LawA(nn_model, params)(:T,) -> Array{Float64, 0} (↧@start custom VJP ✅ precomputed)
The inputs of the laws are represented as objects that derive from AbstractInput. We have defined a subset of inputs that can be used to parameterize laws.
Implementation
It is also possible to define new inputs by creating a new struct type and defining the method for this specific type. On top of type of the input, we also need to override three methods using multiple dispatch:
default_name: It returns a symbolic representation of the input, which is convenient to have the complete name of it.get_input: It computes the value of the input at a given timetfor a specific glacier inside the simulation.Base.zero: It returns the zero value of the input for a specific glacier, used to generate an empty cache.
For example the scalar long term air temperature is defined with the following code:
struct iAvgScalarTemp <: AbstractInput end
default_name(::iAvgScalarTemp) = :averaged_scalar_long_term_temperature
function get_input(temp::iAvgScalarTemp, simulation, glacier_idx, t)
glacier = simulation.glaciers[glacier_idx]
return mean(glacier.climate.longterm_temps_scalar)
end
function Base.zero(temp::iAvgScalarTemp, simulation, glacier_idx)
glacier = simulation.glaciers[glacier_idx]
return zero(glacier.climate.longterm_temps_scalar)
endAn input can compute a physical quantity which is not already defined in the iceflow model like the long term air temperature above, but it can also re-use existing variables. This is the case of the surface slope ∇S. It is retrieved simply by returning the cached variable that lives in the iceflow model:
struct i∇S <: AbstractInput end
default_name(::i∇S) = :∇S
function get_input(::i∇S, simulation, glacier_idx, t)
return simulation.cache.iceflow.∇S
end
function Base.zero(::i∇S, simulation, glacier_idx)
(; nx, ny) = simulation.glaciers[glacier_idx]
return zeros(nx - 1, ny - 1)
endKeep in mind that if you define new inputs, this will work only for forward simulations. As soon as you do inversions with custom gradient computation (that is not with SciMLSensitivity), this requires a careful rooting of the gradient and you need to implement more than simply defining new inputs that depend on the glacier state. This is considered as a very advanced feature and we recommend that you seek assistance in this case.
List of available inputs
For the moment we support the following list of inputs:
- Scalar averaged long term air temperature
Huginn.iAvgScalarTemp — Type
iAvgScalarTemp <: AbstractInputInput that represents the long term air temperature over the whole glacier. It is computed using the OGGM climate data over a period predefined in Gungnir (i.e. around 30 years).
iAvgScalarTemp()averaged_long_term_temperature: iAvgScalarTemp()- Gridded averaged long term air temperature
Huginn.iAvgGriddedTemp — Type
iAvgGriddedTemp <: AbstractInputInput that represents the long term air temperature over the glacier grid. It is computed using the OGGM climate data over a period predefined in Gungnir (i.e. around 30 years).
iAvgGriddedTemp()gridded_long_term_temperature: iAvgGriddedTemp()- Cumulative positive degree days (PDD)
Huginn.iCPDD — Type
iCPDD <: AbstractInputInput that represents the cumulative positive degree days (PDD) over the last time window window. It is computed by summing the daily PDD values from t - window to t using the glacier's climate data.
iCPDD()CPDD: iCPDD{Dates.Week}(Dates.Week(1))- Ice thickness on the dual grid in the SIA
Huginn.iH̄ — Type
iH̄ <: AbstractInputInput that represents the ice thickness in the SIA. It is the averaged ice thickness computed on the dual grid, that is H̄ = avg(H) which is different from the ice thickness solution H.
iH̄()H_dual_grid: iH̄()- Surface slope
Huginn.i∇S — Type
i∇S <: AbstractInputInput that represents the surface slope in the SIA. It is computed using the bedrock elevation and the ice thickness solution H. The spatial differences are averaged over the opposite axis:
S = B + H
∇S = (avg_y(diff_x(S) / Δx) .^ 2 .+ avg_x(diff_y(S) / Δy) .^ 2) .^ (1/2)i∇S()∇S: i∇S()- Topographic roughness
Huginn.iTopoRough — Type
iTopoRough{F<:AbstractFloat} <: AbstractInputInput that represents the topographic roughness of the glacier. It is computed as the curvature of the glacier bed (or surface) over a specified window size. The curvature can be calculated in different directions (flow, cross-flow, or both) and using different curvature types (scalar or variability).
iTopoRough()topographic_roughness: iTopoRough{Float64}(200.0, :scalar, :flow, :bed)This page was generated using Literate.jl.