diff --git a/src/components/gradient_waveforms/gradient_waveforms.jl b/src/components/gradient_waveforms/gradient_waveforms.jl index bacba79a34069cde77d60a590600fc8febd462e4..5e60f1d808ddea2da46b39b1a8f0817deb61a39a 100644 --- a/src/components/gradient_waveforms/gradient_waveforms.jl +++ b/src/components/gradient_waveforms/gradient_waveforms.jl @@ -2,17 +2,17 @@ Module defining sub-types of the [`GradientWaveform`](@ref). There are only three types of [`GradientBlock`] objects: -- [`ChangingGradientBlock`](@ref): any gradient changing linearly in strength. -- [`ConstantGradientBlock`](@ref): any gradient staying constant in strength. These can overlap with a pulse (`SliceSelectPulse`). -- [`NoGradientBlock`](@ref): any part of the gradient waveform when no gradient is active. +- [`ChangingGradient`](@ref): any gradient changing linearly in strength. +- [`ConstantGradient`](@ref): any gradient staying constant in strength. These can overlap with a pulse (`SliceSelectPulse`). +- [`NoGradient`](@ref): any part of the gradient waveform when no gradient is active. These parts are combined into a full gradient waveform in a `BuildingBlock`. Each part of this gradient waveform can compute: -- [`gradient_strength`]: maximum gradient strength in each dimension. -- [`slew_rate`]: maximum slew rate in each dimension. -- [`qvec`]: area under curve in each dimension -- [`bmat_gradient`]: diffusion weighting (scalar in 1D or matrix in 3D). +- `gradient_strength`: maximum gradient strength in each dimension. +- `slew_rate`: maximum slew rate in each dimension. +- `qval`/`qval3`: area under curve +- `bmat_gradient`: diffusion weighting (scalar in 1D or matrix in 3D). """ module GradientWaveforms diff --git a/src/components/gradient_waveforms/no_gradient_blocks.jl b/src/components/gradient_waveforms/no_gradient_blocks.jl index 0a2465de541a760e73d014c7a2417c66ec89982d..742225ceeacd47f9dc8aa982da93b96f89403cb3 100644 --- a/src/components/gradient_waveforms/no_gradient_blocks.jl +++ b/src/components/gradient_waveforms/no_gradient_blocks.jl @@ -5,38 +5,26 @@ import ...AbstractTypes: GradientWaveform import ..ChangingGradientBlocks: split_gradient """ - NoGradient{N}(duration) + NoGradient(duration) Part of a gradient waveform when there is no gradient active. -`N` needs to be set to 1 if `orientation` is fixed in the gradient waveform or 3 otherwise. - Usually, you do not want to create this object directly, use a `BuildingBlock` instead. """ -struct NoGradient{N} <: GradientWaveform{N} +struct NoGradient <: GradientWaveform{0} duration :: VariableType - function NoGradient{N}(duration) where {N} - if !(N in (1, 3)) - error("Dimensionality of the gradient should be 1 or 3, not $N") - end - new(duration) - end end duration(ngb::NoGradient) = ngb.duration for func in (:qval, :gradient_strength, :slew_rate) - @eval $func(::NoGradient{1}) = 0. - @eval $func(::NoGradient{3}) = zero(SVector{3, Float64}) + @eval $func(::NoGradient) = 0. end -gradient_strength(cgb::NoGradient, time::Number) = gradient_strength(cgb) - -NoGradient(duration) = NoGradient{1}(duration) +gradient_strength(nb::NoGradient, time::Number) = 0. -bmat_gradient(::NoGradient{1}) = 0. -bmat_gradient(::NoGradient{3}) = zero(SMatrix{3, 3, Float64, 9}) -bmat_gradient(ngb::NoGradient{1}, qstart::VariableType) = qstart^2 * duration(ngb) -bmat_gradient(ngb::NoGradient{3}, qstart::AbstractVector{<:VariableType}) = @. qstart * permutedims(qstart) * duration(ngb) +bmat_gradient(::NoGradient) = 0. +bmat_gradient(ngb::NoGradient, qstart::VariableType) = qstart^2 * duration(ngb) +bmat_gradient(ngb::NoGradient, qstart::AbstractVector{<:VariableType}) = @. qstart * permutedims(qstart) * duration(ngb) function split_gradient(ngb::NoGradient, times::VariableType...) durations = [times[1], [t[2] - t[1] for t in zip(times[1:end-1], times[2:end])]..., duration(ngb) - times[end]] diff --git a/src/containers/base_sequences.jl b/src/containers/base_sequences.jl index 629c348637d44a74d4361bb8f739aee9dd3387ac..964f470682343cf86901b26b165ee72c27556cb4 100644 --- a/src/containers/base_sequences.jl +++ b/src/containers/base_sequences.jl @@ -173,7 +173,7 @@ Converst object into something that can be included in the sequence: to_block(cb::ContainerBlock) = cb to_block(s::Symbol) = to_block(Val(s)) to_block(s::Union{VariableType, Nothing, Val{:min}, Val{:max}}) = Wait(s) -to_block(ec::EventComponent) = BuildingBlock([NoGradient{3}(duration(ec)), (0., ec)]) +to_block(ec::EventComponent) = BuildingBlock([NoGradient(duration(ec)), (0., ec)]) function make_generic(seq::BaseSequence) diff --git a/src/containers/building_blocks.jl b/src/containers/building_blocks.jl index 5a3b40e1b1fc345cfd2387fbe24abf6fe280e1b6..f50247dbbbe28aec6103c4517136078000586812 100644 --- a/src/containers/building_blocks.jl +++ b/src/containers/building_blocks.jl @@ -274,7 +274,6 @@ end function BuildingBlock(waveform::AbstractVector, events::AbstractVector; orientation=nothing, group=nothing) events = Any[events...] waveform = Any[waveform...] - ndim = isnothing(orientation) ? 1 : 3 zero_grad = isnothing(orientation) ? zeros(3) : 0. if length(waveform) == 0 || waveform[1][1] > 0. pushfirst!(waveform, (0., zero_grad)) @@ -284,7 +283,7 @@ function BuildingBlock(waveform::AbstractVector, events::AbstractVector; orienta for (index_grad, ((prev_time, prev_grad), (time, grad))) in enumerate(zip(waveform[1:end-1], waveform[2:end])) duration = time - prev_time if norm(prev_grad) <= 1e-12 && norm(grad) <= 1e-12 - push!(components, NoGradient{ndim}(duration)) + push!(components, NoGradient(duration)) elseif norm(prev_grad) ≈ norm(grad) push!(components, ConstantGradient(prev_grad, orientation, duration, group)) else @@ -352,6 +351,6 @@ end duration(wb::Wait) = wb.duration Base.keys(::Wait) = (Val(:empty),) -Base.getindex(wb::Wait, ::Val{:empty}) = NoGradient{1}(wb.duration) +Base.getindex(wb::Wait, ::Val{:empty}) = NoGradient(wb.duration) end \ No newline at end of file