Variable Templates

Types

ClimateMachine.VariableTemplates.GradType
Grad{S,A,offset}(array::A)

Defines property overloading along slices of the second dimension of array using the type S as a template. offset is used to shift the starting element of the array.

source

Index methods

ClimateMachine.VariableTemplates.@varsMacro
@vars(var1::Type1, var2::Type2)

A convenient syntax for describing a NamedTuple type.

Example

julia> @vars(a::Float64, b::Float64)
NamedTuple{(:a, :b),Tuple{Float64,Float64}}
source
ClimateMachine.VariableTemplates.flattened_named_tupleFunction
flattened_named_tuple

A flattened NamedTuple, given a Vars or nested NamedTuple instance.

Example:

using Test
using ClimateMachine.VariableTemplates
nt = (x = 1, a = (y = 2, z = 3, b = ((a = 1,), (a = 2,), (a = 3,))));
fnt = flattened_named_tuple(nt);
@test keys(fnt) == (:x, :a_y, :a_z, :a_b_1_a, :a_b_2_a, :a_b_3_a)
@test length(fnt) == 6
@test fnt.x == 1
@test fnt.a_y == 2
@test fnt.a_z == 3
@test fnt.a_b_1_a == 1
@test fnt.a_b_2_a == 2
@test fnt.a_b_3_a == 3
source
ClimateMachine.VariableTemplates.varsindicesFunction
varsindices(S, ps::Tuple)
varsindices(S, ps...)

Return a tuple of indices corresponding to the properties specified by ps based on the template type S. Properties can be specified using either symbols or strings.

Examples

julia> S = @vars(x::Float64, y::Float64, z::Float64)
julia> varsindices(S, (:x, :z))
(1, 3)

julia> S = @vars(x::Float64, y::@vars(α::Float64, β::SVector{3, Float64}))
julia> varsindices(S, "x", "y.β")
(1, 3, 4, 5)
source
ClimateMachine.VariableTemplates.varsindexFunction
varsindex(S, p::Symbol, [sp::Symbol...])

Return a range of indices corresponding to the property p and (optionally) its subproperties sp based on the template type S.

Examples

julia> S = @vars(x::Float64, y::Float64)
julia> varsindex(S, :y)
2:2

julia> S = @vars(x::Float64, y::@vars(α::Float64, β::SVector{3, Float64}))
julia> varsindex(S, :y, :β)
3:5
source