Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion KomaMRICore/src/datatypes/Spinor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ Spinor rotation matrix. Counter-clockwise rotation of `φ` with respect to the a
(NMR imaging). IEEE Transactions on Medical Imaging, 10(1), 53-65.
doi:10.1109/42.75611
"""
Q(φ, nxy, nz) = Spinor(cos.(φ/2).-1im*nz.*sin.(φ/2), -1im*nxy.*sin.(φ/2))
function Q(φ, nxy, nz)
neg_im = complex(zero(eltype(φ)), -one(eltype(φ)))
return Spinor(
(@. cos(φ / 2) + neg_im * nz * sin(φ / 2)),
(@. neg_im * nxy * sin(φ / 2)),
)
end

"""
y = abs(s::Spinor)
Expand Down
12 changes: 7 additions & 5 deletions KomaMRICore/src/simulation/SimMethods/BlochSimple/BlochSimple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ function run_spin_precession!(
outflow_spin_reset!(Mxy, seq.t[2:end]', p.motion)
outflow_spin_reset!(M, seq.t[2:end]', p.motion; replace_by=p.ρ)
#Acquired signal
adc = findall(cpu(seq.ADC[2:end]))
Mxy_adc = Mxy[:, adc]
acquire_block_signal!(
sig, Mxy_adc, sys.receiver, p.motion, (x, y, z), adc,
)
if !isempty(sig)
adc = findall(cpu(seq.ADC[2:end]))
Mxy_adc = Mxy[:, adc]
acquire_block_signal!(
sig, Mxy_adc, sys.receiver, p.motion, (x, y, z), adc,
)
end
return nothing
end

Expand Down
35 changes: 26 additions & 9 deletions KomaMRICore/src/simulation/SimulatorCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,21 @@ function run_spin_precession_parallel!(
prealloc::PreallocResult;
Nthreads=Threads.nthreads(),
)
parts = kfoldperm(length(obj), Nthreads)

ThreadsX.foreach(enumerate(parts)) do (i, p)
if Nthreads == 1
p = 1:length(obj)
run_spin_precession!(
@view(obj[p]), seq, split_sig_per_thread(sig, i, p, sim_method), @view(Xt[p]), sys, sim_method, groupsize, backend, @view(prealloc[p])
obj, seq, split_sig_per_thread(sig, 1, p, sim_method), Xt, sys,
sim_method, groupsize, backend, prealloc
)
else
parts = kfoldperm(length(obj), Nthreads)

ThreadsX.foreach(enumerate(parts)) do (i, p)
run_spin_precession!(
@view(obj[p]), seq, split_sig_per_thread(sig, i, p, sim_method),
@view(Xt[p]), sys, sim_method, groupsize, backend, @view(prealloc[p])
)
end
end

return nothing
Expand All @@ -131,13 +140,21 @@ function run_spin_excitation_parallel!(
prealloc::PreallocResult;
Nthreads=Threads.nthreads(),
)
parts = kfoldperm(length(obj), Nthreads)

ThreadsX.foreach(enumerate(parts)) do (i, p)
if Nthreads == 1
p = 1:length(obj)
run_spin_excitation!(
@view(obj[p]), seq, split_sig_per_thread(sig, i, p, sim_method), @view(Xt[p]),
sys, sim_method, groupsize, backend, @view(prealloc[p])
obj, seq, split_sig_per_thread(sig, 1, p, sim_method), Xt,
sys, sim_method, groupsize, backend, prealloc
)
else
parts = kfoldperm(length(obj), Nthreads)

ThreadsX.foreach(enumerate(parts)) do (i, p)
run_spin_excitation!(
@view(obj[p]), seq, split_sig_per_thread(sig, i, p, sim_method), @view(Xt[p]),
sys, sim_method, groupsize, backend, @view(prealloc[p])
)
end
end

return nothing
Expand Down
Loading