Skip to content
Snippets Groups Projects
Verified Commit 19268c57 authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Rename internal version of qvec to qval3

parent ace8f940
No related branches found
No related tags found
No related merge requests found
module NoGradientBlocks module NoGradientBlocks
import StaticArrays: SVector, SMatrix import StaticArrays: SVector, SMatrix
import ....Variables: VariableType, duration, qval, qvec, bmat_gradient, gradient_strength, slew_rate, get_free_variable import ....Variables: VariableType, duration, qval, bmat_gradient, gradient_strength, slew_rate, get_free_variable
import ...AbstractTypes: GradientWaveform import ...AbstractTypes: GradientWaveform
import ..ChangingGradientBlocks: split_gradient import ..ChangingGradientBlocks: split_gradient
...@@ -31,9 +31,6 @@ end ...@@ -31,9 +31,6 @@ end
NoGradient(duration) = NoGradient{1}(duration) NoGradient(duration) = NoGradient{1}(duration)
qvec(::NoGradient, index1, index2) = zero(SVector{3, Float64})
qvec(::NoGradient) = zero(SVector{3, Float64})
bmat_gradient(::NoGradient{1}) = 0. bmat_gradient(::NoGradient{1}) = 0.
bmat_gradient(::NoGradient{3}) = zero(SMatrix{3, 3, Float64, 9}) 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{1}, qstart::VariableType) = qstart^2 * duration(ngb)
......
...@@ -7,7 +7,7 @@ import JuMP: @constraint ...@@ -7,7 +7,7 @@ import JuMP: @constraint
import ..Abstract: ContainerBlock, start_time import ..Abstract: ContainerBlock, start_time
import ...BuildSequences: global_model import ...BuildSequences: global_model
import ...Components: BaseComponent, GradientWaveform, EventComponent, NoGradient, ChangingGradient, ConstantGradient, split_gradient, DelayedEvent, RFPulseComponent, ReadoutComponent import ...Components: BaseComponent, GradientWaveform, EventComponent, NoGradient, ChangingGradient, ConstantGradient, split_gradient, DelayedEvent, RFPulseComponent, ReadoutComponent
import ...Variables: qval, bmat_gradient, effective_time, get_free_variable import ...Variables: qval, bmat_gradient, effective_time, get_free_variable, qval3
import ...Variables: VariableType, duration, make_generic, get_pulse, get_readout, scanner_constraints! import ...Variables: VariableType, duration, make_generic, get_pulse, get_readout, scanner_constraints!
""" """
...@@ -19,7 +19,7 @@ Main interface: ...@@ -19,7 +19,7 @@ Main interface:
- [`waveform_sequence`](@ref) returns just the gradient waveform as a sequence of [`GradientWaveform`](@ref) objects. - [`waveform_sequence`](@ref) returns just the gradient waveform as a sequence of [`GradientWaveform`](@ref) objects.
- [`waveform`](@ref) returns just the gradient waveform as a sequence of (time, gradient_strength) tuples. - [`waveform`](@ref) returns just the gradient waveform as a sequence of (time, gradient_strength) tuples.
- [`events`](@ref) returns the RF pulses and readouts. - [`events`](@ref) returns the RF pulses and readouts.
- [`qvec`](@ref) returns area under curve for (part of) the gradient waveform. - [`qval3`](@ref) returns area under curve for (part of) the gradient waveform.
Sub-types need to implement: Sub-types need to implement:
- `Base.keys`: returns sequence of keys to all the components. - `Base.keys`: returns sequence of keys to all the components.
...@@ -183,7 +183,7 @@ Similarly, if `last_event` is set to something else than `nothing`, only the gra ...@@ -183,7 +183,7 @@ Similarly, if `last_event` is set to something else than `nothing`, only the gra
""" """
function qval(bb::BaseBuildingBlock, index1, index2) function qval(bb::BaseBuildingBlock, index1, index2)
if (!isnothing(index1)) && (index1 == index2) if (!isnothing(index1)) && (index1 == index2)
return zeros(3) return 0.
end end
sum([qval(wv) for (_, wv) in waveform_sequence(bb, index1, index2)]; init=0.) sum([qval(wv) for (_, wv) in waveform_sequence(bb, index1, index2)]; init=0.)
end end
...@@ -198,7 +198,7 @@ function bmat_gradient(bb::BaseBuildingBlock, qstart, index1, index2) ...@@ -198,7 +198,7 @@ function bmat_gradient(bb::BaseBuildingBlock, qstart, index1, index2)
for (_, part) in waveform_sequence(bb, index1, index2) for (_, part) in waveform_sequence(bb, index1, index2)
result = result .+ bmat_gradient(part, qcurrent) result = result .+ bmat_gradient(part, qcurrent)
qcurrent = qcurrent .+ qvec(part, qcurrent) qcurrent = qcurrent .+ qval3(part, qcurrent)
end end
return result return result
end end
......
...@@ -2,7 +2,7 @@ module EPIReadouts ...@@ -2,7 +2,7 @@ module EPIReadouts
import ...Containers: BaseSequence, get_index_single_TR import ...Containers: BaseSequence, get_index_single_TR
import ..Trapezoids: Trapezoid, opposite_kspace_lines, LineReadout import ..Trapezoids: Trapezoid, opposite_kspace_lines, LineReadout
import ...Components: ADC import ...Components: ADC
import ...Variables: get_free_variable, VariableType, qval, qvec, set_simple_constraints!, resolution, inverse_voxel_size, inverse_fov, resolution, get_readout, apply_simple_constraint!, effective_time import ...Variables: get_free_variable, VariableType, qval, qval3, set_simple_constraints!, resolution, inverse_voxel_size, inverse_fov, resolution, get_readout, apply_simple_constraint!, effective_time
import ...Pathways: PathwayWalker, update_walker_till_time!, walk_pathway! import ...Pathways: PathwayWalker, update_walker_till_time!, walk_pathway!
""" """
...@@ -49,10 +49,10 @@ function EPIReadout(; resolution::AbstractVector{<:Integer}, recenter=false, gro ...@@ -49,10 +49,10 @@ function EPIReadout(; resolution::AbstractVector{<:Integer}, recenter=false, gro
get_free_variable(nothing), get_free_variable(nothing),
ky_lines ky_lines
) )
apply_simple_constraint!(qvec(res.start_gradient), VariableType[-qval(pos)/2, ky_lines[1] * res.ky_step, 0.]) apply_simple_constraint!(qval3(res.start_gradient), VariableType[-qval(pos)/2, ky_lines[1] * res.ky_step, 0.])
if recenter if recenter
sign = isodd(length(ky_lines)) ? -1 : 1 sign = isodd(length(ky_lines)) ? -1 : 1
apply_simple_constraint!(qvec(res.recenter_gradient), VariableType[sign * qval(pos)/2, -ky_lines[end] * res.ky_step, 0.]) apply_simple_constraint!(qval3(res.recenter_gradient), VariableType[sign * qval(pos)/2, -ky_lines[end] * res.ky_step, 0.])
end end
for shift in unique(ky_lines[2:end] - ky_lines[1:end-1]) for shift in unique(ky_lines[2:end] - ky_lines[1:end-1])
res.blips[shift] = Trapezoid(orientation=[0, shift > 0 ? 1 : -1, 0], group=group, qval=abs(shift) * res.ky_step) res.blips[shift] = Trapezoid(orientation=[0, shift > 0 ? 1 : -1, 0], group=group, qval=abs(shift) * res.ky_step)
......
...@@ -3,7 +3,7 @@ import LinearAlgebra: norm, tr ...@@ -3,7 +3,7 @@ import LinearAlgebra: norm, tr
import StaticArrays: SVector, SMatrix import StaticArrays: SVector, SMatrix
import ..Components: NoGradient, RFPulseComponent, ReadoutComponent, InstantGradient, GradientWaveform, DelayedEvent import ..Components: NoGradient, RFPulseComponent, ReadoutComponent, InstantGradient, GradientWaveform, DelayedEvent
import ..Containers: BaseSequence, Sequence, BaseBuildingBlock, waveform, events, waveform_sequence, start_time, AlternativeBlocks import ..Containers: BaseSequence, Sequence, BaseBuildingBlock, waveform, events, waveform_sequence, start_time, AlternativeBlocks
import ..Variables: qvec, qval, bmat_gradient, VariableType, effective_time, duration, TR, bmat, bval, area_under_curve, duration_dephase, duration_transverse import ..Variables: qvec, qval, qval3, bmat_gradient, VariableType, effective_time, duration, TR, bmat, bval, area_under_curve, duration_dephase, duration_transverse
""" """
...@@ -481,7 +481,7 @@ function update_walker_gradient!(gradient::GradientWaveform, walker::PathwayWalk ...@@ -481,7 +481,7 @@ function update_walker_gradient!(gradient::GradientWaveform, walker::PathwayWalk
# update qvec/bmat during gradient # update qvec/bmat during gradient
tracker = walker.gradient_trackers[key] tracker = walker.gradient_trackers[key]
tracker.bmat = tracker.bmat .+ bmat_gradient(gradient, tracker.qvec) tracker.bmat = tracker.bmat .+ bmat_gradient(gradient, tracker.qvec)
tracker.qvec = tracker.qvec .+ qvec(gradient) tracker.qvec = tracker.qvec .+ qval3(gradient)
tracker.last_gradient_time = gradient_start_time + duration(gradient) tracker.last_gradient_time = gradient_start_time + duration(gradient)
end end
......
...@@ -56,7 +56,7 @@ all_variables_symbols = [ ...@@ -56,7 +56,7 @@ all_variables_symbols = [
:inverse_slice_thickness => "Inverse of slice thickness of an RF pulse that is active during a gradient in 1/mm. Also, see [`slice_thickness`](@ref).", :inverse_slice_thickness => "Inverse of slice thickness of an RF pulse that is active during a gradient in 1/mm. Also, see [`slice_thickness`](@ref).",
], ],
:gradient => [ :gradient => [
:qvec => "The spatial range with orientation on which the displacements can be detected due to this gradient in rad/um (also see [`qval`](@ref)).", :qval3 => "The spatial range with orientation on which the displacements can be detected due to this gradient in rad/um (also see [`qval`](@ref)).",
:qval => "The spatial range on which the displacements can be detected due to this gradient in rad/um. This will be a scalar if the orientation is fixed and a scalar otherwise. If you always want a vector, use [`qvec`](@ref).", :qval => "The spatial range on which the displacements can be detected due to this gradient in rad/um. This will be a scalar if the orientation is fixed and a scalar otherwise. If you always want a vector, use [`qvec`](@ref).",
:qval_square => "Square of [`qval`](@ref) in rad^2/um^2.", :qval_square => "Square of [`qval`](@ref) in rad^2/um^2.",
:δ => "Effective duration of a gradient pulse ([`rise_time`](@ref) + [`flat_time`](@ref)) in ms.", :δ => "Effective duration of a gradient pulse ([`rise_time`](@ref) + [`flat_time`](@ref)) in ms.",
...@@ -228,7 +228,7 @@ end ...@@ -228,7 +228,7 @@ end
for (target_name, all_vars) in all_variables_symbols for (target_name, all_vars) in all_variables_symbols
for (variable_func, _) in all_vars for (variable_func, _) in all_vars
if variable_func in [:qvec, ] if variable_func == :qval3
continue continue
end end
get_func = Symbol("get_" * string(target_name)) get_func = Symbol("get_" * string(target_name))
...@@ -276,7 +276,7 @@ for (target_name, all_vars) in all_variables_symbols ...@@ -276,7 +276,7 @@ for (target_name, all_vars) in all_variables_symbols
end end
function qvec(bb::AbstractBlock, args...; kwargs...) function qval3(bb::AbstractBlock, args...; kwargs...)
value = qval(bb, args...; kwargs...) value = qval(bb, args...; kwargs...)
if value isa Number && iszero(value) if value isa Number && iszero(value)
return value return value
...@@ -340,6 +340,7 @@ apply_simple_constraint!(variable, ::Val{:min}) = @objective global_model() Min ...@@ -340,6 +340,7 @@ apply_simple_constraint!(variable, ::Val{:min}) = @objective global_model() Min
apply_simple_constraint!(variable, ::Val{:max}) = @objective global_model() Min objective_function(global_model()) - variable apply_simple_constraint!(variable, ::Val{:max}) = @objective global_model() Min objective_function(global_model()) - variable
apply_simple_constraint!(variable, value::VariableType) = @constraint global_model() variable == value apply_simple_constraint!(variable, value::VariableType) = @constraint global_model() variable == value
apply_simple_constraint!(variable::AbstractVector, value::AbstractVector) = [apply_simple_constraint!(v1, v2) for (v1, v2) in zip(variable, value)] apply_simple_constraint!(variable::AbstractVector, value::AbstractVector) = [apply_simple_constraint!(v1, v2) for (v1, v2) in zip(variable, value)]
apply_simple_constraint!(variable::AbstractVector, value::VariableType) = [apply_simple_constraint!(v1, value) for v1 in variable]
apply_simple_constraint!(variable::Number, value::Number) = @assert variable value "Variable set to multiple incompatible values." apply_simple_constraint!(variable::Number, value::Number) = @assert variable value "Variable set to multiple incompatible values."
function apply_simple_constraint!(variable::NamedTuple, value::NamedTuple) function apply_simple_constraint!(variable::NamedTuple, value::NamedTuple)
for key in keys(value) for key in keys(value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment