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

add scanner_constraints!

parent 6d0bd6f1
No related branches found
No related tags found
No related merge requests found
module BuildingBlocks module BuildingBlocks
import LinearAlgebra: norm import LinearAlgebra: norm
import ..BaseBuildingBlocks: BaseBuildingBlock, events, waveform_sequence import ..BaseBuildingBlocks: BaseBuildingBlock, events, waveform_sequence
import ...Variables: VariableType, duration, make_generic, get_pulse, get_readout import ...Variables: VariableType, duration, make_generic, get_pulse, get_readout, scanner_constraints!
import ...Components: BaseComponent, DelayedEvent, RFPulseComponent, ReadoutComponent import ...Components: BaseComponent, DelayedEvent, RFPulseComponent, ReadoutComponent
""" """
......
...@@ -13,8 +13,8 @@ In addition this defines: ...@@ -13,8 +13,8 @@ In addition this defines:
""" """
module Variables module Variables
import JuMP: @constraint, @variable, Model, @objective, objective_function, value, AbstractJuMPScalar import JuMP: @constraint, @variable, Model, @objective, objective_function, value, AbstractJuMPScalar
import ..Scanners: gradient_strength, slew_rate import ..Scanners: gradient_strength, slew_rate, Scanner
import ..BuildSequences: global_model import ..BuildSequences: global_model, global_scanner
""" """
Parent type of all components, building block, and sequences that form an MRI sequence. Parent type of all components, building block, and sequences that form an MRI sequence.
...@@ -323,4 +323,36 @@ Returns a generic version of the `BaseSequence`, `BaseBuildingBlock`, or `BaseCo ...@@ -323,4 +323,36 @@ Returns a generic version of the `BaseSequence`, `BaseBuildingBlock`, or `BaseCo
""" """
function make_generic end function make_generic end
"""
scanner_constraints!(block)
Constraints [`gradient_strength`](@ref) and [`slew_rate`](@ref) to be less than the [`global_scanner`](@ref) maximum.
"""
function scanner_constraints!(bb::AbstractBlock)
try
global_scanner()
catch e
return
end
for f in (gradient_strength, slew_rate)
try
value = gradient_strength(bb)
catch e
if e isa VariableNotAvailable
continue
else
rethrow()
end
end
if value isa AbstractVector
for v in value
@constraint global_model() v <= f(global_scanner())
end
else
@constraint global_model() value <= f(global_scanner())
end
end
end
end end
\ No newline at end of file
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