Skip to content
Snippets Groups Projects
Verified Commit e4f2c9dd authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Switch from get_children_blocks to get_children_indices

parent 3dcf149c
No related branches found
No related tags found
No related merge requests found
......@@ -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
"""
......
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
......
......@@ -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...)
......
......@@ -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
......
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))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment