diff --git a/src/concrete_blocks.jl b/src/concrete_blocks.jl index 9570a0fbc64394fcd3d5c0d3b5935fb314a1e4d2..b3ea308671c5244645ac0a2e2741efcd6a2186b9 100644 --- a/src/concrete_blocks.jl +++ b/src/concrete_blocks.jl @@ -1,7 +1,7 @@ module ConcreteBlocks -import JuMP: has_values, optimize! +import JuMP: has_values, optimize!, value import ..BuildingBlocks: BuildingBlock, BuildingBlockPlaceholder, properties, duration -import ..SequenceBuilders: SequenceBuilder, to_block, AbstractSequence +import ..SequenceBuilders: SequenceBuilder, to_block, AbstractSequence, TR, get_blocks abstract type AbstractConcreteBlock <: BuildingBlock end @@ -40,7 +40,17 @@ function ConcreteGradient(arr::Vector) ) end +function ConcreteGradient(times, gradients) + ConcreteGradient( + times, + [g[1] for g in gradients], + [g[2] for g in gradients], + [g[3] for g in gradients], + ) +end + ConcreteGradient(::Nothing) = nothing +ConcreteGradient(values::Tuple{<:Vector, <:Vector}) = ConcreteGradient(values...) ConcreteGradient(values::Tuple{<:Vector, <:Vector, <:Vector, <:Vector}) = ConcreteGradient(values...) @@ -55,12 +65,13 @@ struct ConcreteBlock <: AbstractConcreteBlock pulse :: Union{ConcreteRFPulse, Nothing} gradient :: Union{ConcreteGradient, Nothing} readout_times :: Vector{Float64} + rotate_gradients :: Bool end ConcreteBlock(args...; kwargs...) = BuildingBlockPlaceholder{ConcreteBlock}(args...; kwargs...) -function ConcreteBlock(builder::AbstractSequence, duration::Number; pulse=nothing, gradient=nothing, readout_times=Number[]) - ConcreteBlock(builder, duration, ConcreteRFPulse(pulse), ConcreteGradient(gradient), Float64.(readout_times)) +function ConcreteBlock(builder::AbstractSequence, duration::Number; pulse=nothing, gradient=nothing, readout_times=Number[], rotate_gradients=false) + ConcreteBlock(builder, duration, ConcreteRFPulse(pulse), ConcreteGradient(gradient), Float64.(readout_times), rotate_gradients) end @@ -112,11 +123,14 @@ struct Sequence <: AbstractSequence TR :: Number end +TR(seq::Sequence) = seq.TR +get_blocks(seq::Sequence) = seq.blocks + function Sequence(builder::SequenceBuilder) if !has_values(builder) optimize!(builder.model) end - seq = Sequence(AbstractConcreteBlock[], value(TR)) + seq = Sequence(AbstractConcreteBlock[], value(TR(builder))) for block in builder.blocks push!(seq.blocks, ConcreteBlock(seq, block)) end diff --git a/src/gradients/pulsed_gradients.jl b/src/gradients/pulsed_gradients.jl index e0a955be95f65ebe17145708284bbbf0e742c577..0c4bc4303d1d98883d88c731e7138ac9afaa22a6 100644 --- a/src/gradients/pulsed_gradients.jl +++ b/src/gradients/pulsed_gradients.jl @@ -132,7 +132,7 @@ function to_concrete_block(s::AbstractSequence, block::PulsedGradient) t_start = value(start_time(block)) t_rise = value(rise_time(block)) t_d = value(δ(block)) - return ConcreteBlock(s, t_start + t_d + t_rise, gradients=[ + return ConcreteBlock(s, t_start + t_d + t_rise, gradient=[ (t_start, zeros(3)), (t_start + t_rise, qvec), (t_start + t_d, qvec),