diff --git a/KomaMRIBase/src/datatypes/simulation/DiscreteSequence.jl b/KomaMRIBase/src/datatypes/simulation/DiscreteSequence.jl index 6494980e7..cbf6a2be5 100644 --- a/KomaMRIBase/src/datatypes/simulation/DiscreteSequence.jl +++ b/KomaMRIBase/src/datatypes/simulation/DiscreteSequence.jl @@ -85,9 +85,8 @@ based on simulation parameters. # Returns - `seqd`: (`::DiscreteSequence`) DiscreteSequence struct """ -function discretize(seq::Sequence; sampling_params=default_sampling_params(), add_times=[]) - t, Δt = get_variable_times(seq; Δt=sampling_params["Δt"], Δt_rf=sampling_params["Δt_rf"]) - sort!(append!(t, add_times)) +function discretize(seq::Sequence; sampling_params=default_sampling_params(), motion=NoMotion()) + t, Δt = get_variable_times(seq; Δt=sampling_params["Δt"], Δt_rf=sampling_params["Δt_rf"], motion=motion) B1, Δf = get_rfs(seq, t) Gx, Gy, Gz = get_grads(seq, t) tadc = get_adc_sampling_times(seq) diff --git a/KomaMRIBase/src/motion/Motion.jl b/KomaMRIBase/src/motion/Motion.jl index 3ec19bd29..22cd4e3d5 100644 --- a/KomaMRIBase/src/motion/Motion.jl +++ b/KomaMRIBase/src/motion/Motion.jl @@ -203,5 +203,5 @@ end # Auxiliary functions times(m::Motion) = times(m.time) is_composable(m::Motion) = is_composable(m.action) -get_jump_times(m::Motion) = get_jump_times(m.action, m.time) -get_jump_times(::AbstractAction, ::AbstractTimeSpan) = [] \ No newline at end of file +add_jump_times!(t, m::Motion) = add_jump_times!(t, m.action, m.time) +add_jump_times!(t, ::AbstractAction, ::AbstractTimeSpan) = nothing \ No newline at end of file diff --git a/KomaMRIBase/src/motion/MotionList.jl b/KomaMRIBase/src/motion/MotionList.jl index 91ccfd41f..7879f5408 100644 --- a/KomaMRIBase/src/motion/MotionList.jl +++ b/KomaMRIBase/src/motion/MotionList.jl @@ -203,10 +203,8 @@ function sort_motions!(m::MotionList) return nothing end -function get_jump_times(ml::MotionList{T}) where {T<:Real} - jump_times = T[] +function add_jump_times!(t, ml::MotionList) for m in ml.motions - append!(jump_times, get_jump_times(m)) + add_jump_times!(t, m) end - return jump_times end \ No newline at end of file diff --git a/KomaMRIBase/src/motion/NoMotion.jl b/KomaMRIBase/src/motion/NoMotion.jl index 50a8eedb2..233d00a35 100644 --- a/KomaMRIBase/src/motion/NoMotion.jl +++ b/KomaMRIBase/src/motion/NoMotion.jl @@ -49,4 +49,4 @@ function get_spin_coords( ) where {T<:Real} return x, y, z end -get_jump_times(::NoMotion) = [] \ No newline at end of file +add_jump_times!(t, ::NoMotion) = nothing \ No newline at end of file diff --git a/KomaMRIBase/src/motion/actions/arbitraryactions/FlowPath.jl b/KomaMRIBase/src/motion/actions/arbitraryactions/FlowPath.jl index 2367ea71c..391a56839 100644 --- a/KomaMRIBase/src/motion/actions/arbitraryactions/FlowPath.jl +++ b/KomaMRIBase/src/motion/actions/arbitraryactions/FlowPath.jl @@ -35,4 +35,8 @@ julia> flowpath = FlowPath( dz::AbstractArray{T} spin_reset::AbstractArray{Bool} end -get_jump_times(a::FlowPath, t::AbstractTimeSpan) = (times(t)[end] - times(t)[1])/(size(a.spin_reset)[2]-1) * (getindex.(findall(a.spin_reset .== 1), 2) .- 1) .- 1e-6 \ No newline at end of file + +function add_jump_times!(t, a::FlowPath, time_span::AbstractTimeSpan) + jump_times = (times(time_span)[end] - times(time_span)[1])/(size(a.spin_reset)[2]-1) * (getindex.(findall(a.spin_reset .== 1), 2) .- 1) .- 1e-6 + append!(t, jump_times) +end \ No newline at end of file diff --git a/KomaMRIBase/src/timing/TimeStepCalculation.jl b/KomaMRIBase/src/timing/TimeStepCalculation.jl index e1b76ff27..d77e383bb 100644 --- a/KomaMRIBase/src/timing/TimeStepCalculation.jl +++ b/KomaMRIBase/src/timing/TimeStepCalculation.jl @@ -81,13 +81,15 @@ This function returns non-uniform time points that are relevant in the sequence samples for RF excitation (by nominal we mean that the time separation should be at most `Δt_rf` when the samples are regarded by [`KomaMRI.is_RF_on`](@ref), otherwise the time points are not necessary and the separation will be bigger) +- `motion`: (`::Union{NoMotion, Motion, MotionList}`, `=NoMotion()`) phantom motion, + from which it may be necessary to extract key time points relevant for the simulation # Returns - `t`: (`::Vector{Float64}`, `[s]`) time array with non-uniform time values - `Δt`: (`::Vector{Float64}`, `[s]`) delta time array with the separation between two adjacent time points of the `t` time array """ -function get_variable_times(seq; Δt=1e-3, Δt_rf=1e-5) +function get_variable_times(seq; Δt=1e-3, Δt_rf=1e-5, motion=NoMotion()) t = Float64[] ϵ = MIN_RISE_TIME # Small Float64 T0 = get_block_start_times(seq) @@ -120,6 +122,7 @@ function get_variable_times(seq; Δt=1e-3, Δt_rf=1e-5) end append!(t, t_block) end + add_jump_times!(t, motion) # Removing repeated points sort!(unique!(t)) # Fixes a problem with ADC at the start and end of the seq diff --git a/KomaMRICore/src/simulation/SimulatorCore.jl b/KomaMRICore/src/simulation/SimulatorCore.jl index 3bf1b08ea..aff8a56f7 100644 --- a/KomaMRICore/src/simulation/SimulatorCore.jl +++ b/KomaMRICore/src/simulation/SimulatorCore.jl @@ -336,7 +336,7 @@ function simulate( """ maxlog=1 end # Simulation init - seqd = discretize(seq; sampling_params=sim_params, add_times=KomaMRIBase.get_jump_times(obj.motion)) # Sampling of Sequence waveforms + seqd = discretize(seq; sampling_params=sim_params, motion=obj.motion) # Sampling of Sequence waveforms parts, excitation_bool = get_sim_ranges(seqd; Nblocks=sim_params["Nblocks"]) # Generating simulation blocks t_sim_parts = [seqd.t[p[1]] for p in parts] append!(t_sim_parts, seqd.t[end])