TrajectoryIndexingUtils methods

This module contains helper functions for indexing and taking slices of the full problem variable vector definitions:

  • problem vector: Z = [z₁, z₂, ..., zₜ]

  • knot point: zₜ = [xₜ, uₜ]

  • augmented state vector: xₜ = [ψ̃ₜ, ψ̃²ₜ, ..., ψ̃ⁿₜ, ∫aₜ, aₜ, daₜ, ..., dᶜ⁻¹aₜ]

where c = control_order

also, below, we use dim(zₜ) = dim examples:

Z[index(t, pos, dim)]               = zₜ[pos]
Z[index(t, dim)]                    = zₜ[dim]
Z[slice(t, pos1, pos2, dim)]        = zₜ[pos1:pos2]
Z[slice(t, pos, dim)]               = zₜ[1:pos]
Z[slice(t, dim)]                    = zₜ[1:dim] := zₜ
Z[slice(t, dim; stretch=stretch)]   = zₜ[1:(dim + stretch)]
Z[slice(t, indices, dim)]           = zₜ[indices]
Z[slice(t1:t2, dim)]                = [zₜ₁;...;zₜ₂]

The functions are also used to access the zₜ vectors, e.g.

zₜ[slice(i, isodim)]                             = ψ̃ⁱₜ
zₜ[n_wfn_states .+ slice(1, ncontrols)]          = ∫aₜ
zₜ[n_wfn_states .+ slice(2, ncontrols)]          = aₜ
zₜ[n_wfn_states .+ slice(augdim + 1, ncontrols)] = uₜ = ddaₜ

Examples below are run with:

using TrajectoryIndexingUtils
Z = collect(1.5:12.5)  # Example vector as Float64
dim = 3  # Example dimension

API

TrajectoryIndexingUtils.indexMethod
index(t::Int, dim::Int)

Calculate the index in the full problem vector for a given time step t and dimension dim. Assumes pos is equal to dim.

julia> Z[index(1, dim)]
3.5
source
TrajectoryIndexingUtils.indexMethod
index(t::Int, pos::Int, dim::Int)

Calculate the index in the full problem vector for a given time step t, position pos, and dimension dim.

julia> Z[index(1, 1, 3)]
1.5
source
TrajectoryIndexingUtils.sliceMethod
slice(t::Int, pos1::Int, pos2::Int, dim::Int)

Calculate slice of the full problem vector for a given time step t, starting position pos1, and ending position pos2.

julia> Z[slice(2, 1, 3, 3)]
3-element Vector{Float64}:
 4.5
 5.5
 6.5
source
TrajectoryIndexingUtils.sliceMethod
slice(t::Int, indices::AbstractVector{Int}, dim::Int)

Calculate slice of the problem vector for a given time step t and a vector of indices indices.

julia> Z[slice(2, [1, 3], 3)]
2-element Vector{Float64}:
 4.5
 6.5
source
TrajectoryIndexingUtils.sliceMethod
slice(t::Int, pos::Int, dim::Int)

Calculate slice of the problem vector for a given time step t, up to position pos. Equivalent to slice(t, 1, pos, dim).'

julia> Z[slice(2, 2, 3)]
2-element Vector{Float64}:
 4.5
 5.5
source
TrajectoryIndexingUtils.sliceMethod
slice(t::Int, dim::Int; stretch=0)

Calculate slice of the problem vector for a given time step t, with an optional stretch parameter

julia> Z[slice(2, 3; stretch=1)]
4-element Vector{Float64}:
 4.5
 5.5
 6.5
 7.5
source
TrajectoryIndexingUtils.sliceMethod
slice(ts::UnitRange{Int}, dim::Int)

Calculate slice of the problem vector for a range of time steps ts that covers each of the knot-points in those steps.

julia> Z[slice(1:2, 3)]
6-element Vector{Float64}:
 1.5
 2.5
 3.5
 4.5
 5.5
 6.5
source