diff --git a/KomaMRICore/src/KomaMRICore.jl b/KomaMRICore/src/KomaMRICore.jl index ca83e6fc5..3486329ed 100644 --- a/KomaMRICore/src/KomaMRICore.jl +++ b/KomaMRICore/src/KomaMRICore.jl @@ -1,4 +1,4 @@ -module KomaMRICore +module KomaMRICore # General import Base.*, Base.abs diff --git a/KomaMRICore/src/simulation/Flow.jl b/KomaMRICore/src/simulation/Flow.jl index 8ad57a410..a7ca08178 100644 --- a/KomaMRICore/src/simulation/Flow.jl +++ b/KomaMRICore/src/simulation/Flow.jl @@ -31,12 +31,10 @@ function outflow_spin_reset!( idx = KomaMRIBase.get_indexing_range(spin_span) spin_state_matrix = @view(spin_state_matrix[idx, :]) # Obtain mask - itp = KomaMRIBase.interpolate(action.spin_reset, KomaMRIBase.Gridded(KomaMRIBase.Constant{KomaMRIBase.Previous}()), Val(size(action.spin_reset, 1)), t) - mask = KomaMRIBase.resample(itp, ts) - mask .= (cumsum(mask; dims=2) .== 0) + mask = get_mask(action.spin_reset, ts) # Modify spin state: reset and replace by initial value - spin_state_matrix .*= mask - spin_state_matrix .+= replace_by .* (1 .- mask) + spin_state_matrix .*= (1 .- mask) + spin_state_matrix .+= replace_by .* mask return nothing end @@ -56,20 +54,31 @@ function outflow_spin_reset!( idx = KomaMRIBase.get_indexing_range(spin_span) M = @view(M[idx]) # Obtain mask - itp = KomaMRIBase.interpolate(action.spin_reset, KomaMRIBase.Gridded(KomaMRIBase.Constant{KomaMRIBase.Previous}()), Val(size(action.spin_reset, 1)), t) - mask = KomaMRIBase.resample(itp, ts) - mask .= (cumsum(mask; dims=2) .== 0) + mask = get_mask(action.spin_reset, ts) mask = @view(mask[:, end]) # Modify spin state: reset and replace by initial value - M.xy .*= mask - M.z .*= mask - M.xy .+= 0 .* (1 .- mask) - M.z .+= replace_by .* (1 .- mask) + M.xy .*= (1 .- mask) + M.z .*= (1 .- mask) + M.xy .+= 0 .* mask + M.z .+= replace_by .* mask return nothing end -init_time(t, seq_t, add_t0) = t -init_time(t, seq_t::AbstractArray, add_t0) = begin +function init_time(t, seq_t::AbstractArray, add_t0) t1 = @view(seq_t[1]) return add_t0 ? [t1 (t1 .+ t)] : t1 .+ t end +function init_time(t, seq_t, add_t0) + return t +end + +function get_mask(spin_reset, t::Real) + itp = KomaMRIBase.interpolate(spin_reset, KomaMRIBase.Gridded(KomaMRIBase.Constant{KomaMRIBase.Previous}()), Val(size(spin_reset, 1)), t) + return KomaMRIBase.resample(itp, t) +end +function get_mask(spin_reset, t::AbstractArray) + itp = KomaMRIBase.interpolate(spin_reset, KomaMRIBase.Gridded(KomaMRIBase.Constant{KomaMRIBase.Previous}()), Val(size(spin_reset, 1)), t) + mask = KomaMRIBase.resample(itp, t) + mask .= (cumsum(mask; dims=2) .== 1) + return mask +end \ No newline at end of file diff --git a/KomaMRICore/src/simulation/SimMethods/Bloch/BlochCPU.jl b/KomaMRICore/src/simulation/SimMethods/Bloch/BlochCPU.jl index 0f3d4739a..ddd74ae7a 100644 --- a/KomaMRICore/src/simulation/SimMethods/Bloch/BlochCPU.jl +++ b/KomaMRICore/src/simulation/SimMethods/Bloch/BlochCPU.jl @@ -56,7 +56,7 @@ function run_spin_precession!( ) where {T<:Real} #Simulation #Motion - x, y, z = get_spin_coords(p.motion, p.x, p.y, p.z, seq.t[1,:]') + x, y, z = get_spin_coords(p.motion, p.x, p.y, p.z, seq.t[1]) #Initialize arrays Bz_old = prealloc.Bz_old @@ -76,7 +76,7 @@ function run_spin_precession!( t_seq = zero(T) # Time for seq_idx=2:length(seq.t) - x, y, z = get_spin_coords(p.motion, p.x, p.y, p.z, seq.t[seq_idx,:]') + x, y, z = get_spin_coords(p.motion, p.x, p.y, p.z, seq.t[seq_idx]) t_seq += seq.Δt[seq_idx-1] #Effective Field @@ -90,7 +90,7 @@ function run_spin_precession!( @. Mxy = exp(-t_seq / p.T2) * M.xy * cis(ϕ) #Reset Spin-State (Magnetization). Only for FlowPath - outflow_spin_reset!(Mxy, seq.t[seq_idx,:]', p.motion) + outflow_spin_reset!(Mxy, seq.t[seq_idx], p.motion) sig[ADC_idx] = sum(Mxy) ADC_idx += 1