# Single Stack Utils

## Functions

ClimateMachine.SingleStackUtils.get_vars_from_nodal_stackFunction
get_vars_from_nodal_stack(
grid::DiscontinuousSpectralElementGrid{T, dim, N},
Q::MPIStateArray,
vars;
vrange::UnitRange = 1:size(Q, 3),
i::Int = 1,
j::Int = 1,
exclude::Vector{String} = String[],
interp = false,
) where {T, dim, N}

Return a dictionary whose keys are the flattenednames() of the variables specified in vars (as returned by e.g. vars_state), and whose values are arrays of the values for that variable along the vertical dimension in Q. Only a single element is expected in the horizontal as this is intended for the single stack configuration and i and j identify the horizontal nodal coordinates.

Variables listed in exclude are skipped.

source
ClimateMachine.SingleStackUtils.get_vars_from_element_stackFunction
get_vars_from_element_stack(
grid::DiscontinuousSpectralElementGrid{T, dim, N},
Q::MPIStateArray,
vars;
vrange::UnitRange = 1:size(Q, 3),
exclude::Vector{String} = String[],
interp = false,
) where {T, dim, N}

Return an array of get_vars_from_nodal_stack()s whose dimensions are the number of nodal points per element in the horizontal plane.

Variables listed in exclude are skipped.

source
ClimateMachine.SingleStackUtils.get_horizontal_meanFunction
get_horizontal_mean(
grid::DiscontinuousSpectralElementGrid{T, dim, N},
Q::MPIStateArray,
vars;
vrange::UnitRange = 1:size(Q, 3),
exclude::Vector{String} = String[],
interp = false,
) where {T, dim, N}

Return a dictionary whose keys are the flattenednames() of the variables specified in vars (as returned by e.g. vars_state), and whose values are arrays of the horizontal averages for that variable along the vertical dimension in Q. Only a single element is expected in the horizontal as this is intended for the single stack configuration.

Variables listed in exclude are skipped.

source
ClimateMachine.SingleStackUtils.get_horizontal_varianceFunction
get_horizontal_variance(
grid::DiscontinuousSpectralElementGrid{T, dim, N},
Q::MPIStateArray,
vars;
vrange::UnitRange = 1:size(Q, 3),
exclude::Vector{String} = String[],
interp = false,
) where {T, dim, N}

Return a dictionary whose keys are the flattenednames() of the variables specified in vars (as returned by e.g. vars_state), and whose values are arrays of the horizontal variance for that variable along the vertical dimension in Q. Only a single element is expected in the horizontal as this is intended for the single stack configuration.

Variables listed in exclude are skipped.

source
ClimateMachine.SingleStackUtils.reduce_nodal_stackFunction
reduce_nodal_stack(
op::Function,
grid::DiscontinuousSpectralElementGrid{T, dim, N},
Q::MPIStateArray,
vars::NamedTuple,
var::String;
vrange::UnitRange = 1:size(Q, 3),
) where {T, dim, N}

Reduce var from vars within Q over all nodal points in the specified vrange of elements with op. Return a tuple (result, z) where result is the final value returned by op and z is the index within vrange where the result was determined.

source
ClimateMachine.SingleStackUtils.reduce_element_stackFunction
reduce_element_stack(
op::Function,
grid::DiscontinuousSpectralElementGrid{T, dim, N},
Q::MPIStateArray,
vars::NamedTuple,
var::String;
vrange::UnitRange = 1:size(Q, 3),
) where {T, dim, N}

Reduce var from vars within Q over all nodal points in the specified vrange of elements with op. Return a tuple (result, z) where result is the final value returned by op and z is the index within vrange where the result was determined.

source
ClimateMachine.SingleStackUtils.horizontally_average!Function
horizontally_average!(
grid::DiscontinuousSpectralElementGrid{T, dim, N},
Q::MPIStateArray,
i_vars,
) where {T, dim, N}

Horizontally average variables, from variable indexes i_vars, in MPIStateArray Q.

Note

These are not proper horizontal averages– the main purpose of this method is to ensure that there are no horizontal fluxes for a single stack configuration.

source
ClimateMachine.SingleStackUtils.dict_of_nodal_statesFunction
dict_of_nodal_states(
solver_config,
state_types = (Prognostic(), Auxiliary());
aux_excludes = [],
interp = false,
)

A dictionary of single stack prognostic and auxiliary variables at the i=1,j=1 node given

• solver_config a SolverConfiguration
• aux_excludes a vector of strings containing the variables to exclude from the auxiliary state.
source
ClimateMachine.SingleStackUtils.NodalStackType
NodalStack(
bl::BalanceLaw,
grid::DiscontinuousSpectralElementGrid,
prognostic,
auxiliary,
diffusive,
hyperdiffusive;
i = 1,
j = 1,
interp = true,
)

A struct whose iterate(::NodalStack) traverses the nodal stack and returns a NamedTuple of point-wise fields (Vars).

Example

for state_local in NodalStack(
bl,
grid,
prognostic, # global field along nodal stack
auxiliary,
diffusive,
hyperdiffusive
)
prog = state_local.prog # point-wise field along nodal stack
end

TODO: Make prognostic, auxiliary, diffusive, hyperdiffusive optional

Arguments

• bl the balance law
• grid the discontinuous spectral element grid
• prognostic the global prognostic state
• auxiliary the global auxiliary state
• diffusive the global diffusive state (gradient-flux)
• hyperdiffusive the global hyperdiffusive state
• i,j the i,j'th nodal stack (in the horizontal directions)
• interp a bool indicating whether to interpolate the duplicate Gauss-Lebotto points at the element faces.
Warn

Before iterating, the data is transferred from the device (GPU) to the host (CPU), as this is intended for debugging / diagnostics usage.

source
ClimateMachine.SingleStackUtils.single_stack_diagnosticsFunction
single_stack_diagnostics(
grid::DiscontinuousSpectralElementGrid,
bl::BalanceLaw,
t::Real,
direction;
kwargs...,
)

Arguments

• grid the grid
• bl the balance law
• t time
• direction direction
• kwargs keyword arguments, passed to NodalStack.

An array of nested NamedTuples, containing results of

• z - altitude
• prog - the prognostic state
• aux - the auxiliary state
• ∇flux - the gradient-flux (diffusive) state
• hyperdiff - the hyperdiffusive state

and all the nested NamedTuples, merged together, from the precompute methods.

source