diff --git a/src/building_blocks.jl b/src/building_blocks.jl index 7ec07be710a1d02c4b63126be0986ca023053e2a..e5888f1ade7ca988efcf7f202c8e88a33e1d16a1 100644 --- a/src/building_blocks.jl +++ b/src/building_blocks.jl @@ -45,7 +45,17 @@ abstract type ContainerBlock <: BuildingBlock end Return all the [`BuildingBlock`](@ref) objects includes in this container with their indices. """ -function get_children_blocks end +get_children_blocks(bb::BuildingBlock) = [(i, bb[i]) for i in get_children_indices] + +""" + get_children_indices(container) + +Return the indices of all the children in a [`ContainerBlock`](@ref). + +This needs to be defined for every [`ContainerBlock`](@ref). +It is not part of the external API, but is used by [`get_children_blocks`](@ref) +""" +function get_children_indices end """ diff --git a/src/containers/fixed_blocks.jl b/src/containers/fixed_blocks.jl index 3e79370dc2db69a08a555da37198bf2cd35926ad..86e13fdbba18fc33e25123debe2763e037f14016 100644 --- a/src/containers/fixed_blocks.jl +++ b/src/containers/fixed_blocks.jl @@ -1,7 +1,7 @@ module FixedBlocks -import ...BuildingBlocks: BuildingBlock, ContainerBlock +import ...BuildingBlocks: BuildingBlock, ContainerBlock, get_children_indices import ...Gradients: FixedGradient import ...Pulses: FixedPulse import ...Variables: duration, variables @@ -58,13 +58,13 @@ start_time(fb::FixedBlock, index::Symbol) = start_time(fb, Val(index)) start_time(fb::FixedBlock, ::Val{:pulse}) = fb.pulse_delay start_time(fb::FixedBlock, ::Val{:gradient}) = fb.gradient_delay -function get_children_blocks(fb::FixedBlock) - res = Tuple{Symbol, BuildingBlock}[] +function get_children_indices(fb::FixedBlock) + res = Symbol[] if !isnothing(fb.pulse) - push!((:pulse, fb.pulse)) + push!(:pulse) end if !isnothing(fb. gradient) - push!((:gradient, fb.gradient)) + push!(:gradient) end return res end diff --git a/src/containers/sequences.jl b/src/containers/sequences.jl index d5d080f5231fe001eca966da038b78734e8dcb85..875d42fca350994b18d3c6773644621c89c4f861 100644 --- a/src/containers/sequences.jl +++ b/src/containers/sequences.jl @@ -5,7 +5,7 @@ module Sequences import JuMP: Model, @constraint import ...BuildSequences: @global_model_constructor import ...Variables: variables, start_time, duration, VariableType, get_free_variable, TR, end_time -import ...BuildingBlocks: BuildingBlock, ContainerBlock, to_block, get_children_blocks, scanner_constraints!, fixed, BuildingBlockPrinter +import ...BuildingBlocks: BuildingBlock, ContainerBlock, to_block, get_children_indices, scanner_constraints!, fixed, BuildingBlockPrinter import ..FixedBlocks: FixedBlock abstract type AbstractSequence <: ContainerBlock end @@ -48,7 +48,7 @@ Sequence(model::Model, blocks...; TR=nothing, scanner=nothing) = Sequence(model, Base.length(seq::AbstractSequence) = length(seq._blocks) Base.getindex(seq::AbstractSequence, index) = seq._blocks[index] -get_children_blocks(seq::AbstractSequence) = enumerate(seq._blocks) +get_children_indices(seq::AbstractSequence) = eachindex(seq._blocks) """ start_time(sequence::Sequence, index::Integer, args...) diff --git a/src/gradients/pulsed_gradients.jl b/src/gradients/pulsed_gradients.jl index 0ac4681e4c4b60458cb3ebeeb2077634686ab3d8..6b4de105cfde059c764e972d646f599235f56583 100644 --- a/src/gradients/pulsed_gradients.jl +++ b/src/gradients/pulsed_gradients.jl @@ -6,7 +6,7 @@ module PulsedGradients import JuMP: @constraint, @variable, Model, VariableRef, owner_model, value import StaticArrays: SVector import ...Variables: qval, bval, rise_time, flat_time, slew_rate, gradient_strength, variables, duration, δ, get_free_variable, VariableType -import ...BuildingBlocks: ContainerBlock, duration, set_simple_constraints!, fixed, start_time, get_children_blocks +import ...BuildingBlocks: ContainerBlock, duration, set_simple_constraints!, fixed, start_time, get_children_indices import ...BuildSequences: @global_model_constructor import ..FixedGradients: FixedGradient import ..ChangingGradientBlocks: ChangingGradientBlock diff --git a/src/gradients/slice_selects.jl b/src/gradients/slice_selects.jl index e6f8165b3df2c39393d570ccea020ffc685e3ed3..0a30e73c63bb5d27f6797bba24985925763c2a39 100644 --- a/src/gradients/slice_selects.jl +++ b/src/gradients/slice_selects.jl @@ -1,6 +1,6 @@ module SliceSelects import JuMP: Model -import ...BuildingBlocks: RFPulseBlock, ContainerBlock, get_children_blocks +import ...BuildingBlocks: RFPulseBlock, ContainerBlock, get_children_indices import ...Variables: VariableType, slice_thickness, get_free_variable, effective_time, start_time, qvec, bmat, qval, bval import ...Variables: flip_angle, amplitude, phase, frequency, bandwidth, inverse_bandwidth, N_left, N_right import ..ConstantGradientBlocks: ConstantGradientBlock @@ -47,7 +47,7 @@ function AbstractSliceSelect{VariableType}(model::Model, gradient_strength::SVec end -get_children_blocks(select::SliceSelect) = [(symb, getproperty(select, symb)) for symb in (:flat_before, :pulse, :flat_after)] +get_children_indices(::SliceSelect) = (:flat_before, :pulse, :flat_after) Base.get_index(select::SliceSelect, index::Symbol) = getproperty(select, index) start_time(select::SliceSelect, symbol::Symbol) = start_time(select, Val(symbol))