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

Fix qval/qval_square variables

parent 325dbb0e
No related branches found
No related tags found
No related merge requests found
module BuildingBlocks module BuildingBlocks
import JuMP: value, Model, @constraint, @objective, objective_function, AbstractJuMPScalar import JuMP: value, Model, @constraint, @objective, objective_function, AbstractJuMPScalar
import Printf: @sprintf import Printf: @sprintf
import ..Variables: Variables, variables, start_time, duration, end_time, gradient_strength, slew_rate, effective_time, VariableType, alternative_variables import ..Variables: Variables, variables, start_time, duration, end_time, gradient_strength, slew_rate, effective_time, VariableType, alternative_variables, qval_square
import ..BuildSequences: global_model, global_scanner, fixed import ..BuildSequences: global_model, global_scanner, fixed
import ..Scanners: Scanner import ..Scanners: Scanner
...@@ -122,6 +122,9 @@ end ...@@ -122,6 +122,9 @@ end
for variable_func in keys(variables) for variable_func in keys(variables)
if variable_func in [:qval_square, :qval]
continue
end
@eval function Variables.$variable_func(bb::BuildingBlock) @eval function Variables.$variable_func(bb::BuildingBlock)
if Variables.$variable_func in keys(alternative_variables) if Variables.$variable_func in keys(alternative_variables)
alt_var, forward, backward, _ = alternative_variables[Variables.$variable_func] alt_var, forward, backward, _ = alternative_variables[Variables.$variable_func]
...@@ -144,6 +147,13 @@ for variable_func in keys(variables) ...@@ -144,6 +147,13 @@ for variable_func in keys(variables)
end end
end end
function Variables.qval_square(bb::BuildingBlock, args...; kwargs...)
vec = Variables.qvec(bb, args...; kwargs...)
return vec[1]^2 + vec[2]^2 + vec[3]^2
end
Variables.qval(bb::BuildingBlock, args...; kwargs...) = sqrt(Variables.qval_square(bb, args...; kwargs...))
struct BuildingBlockPrinter{T<:BuildingBlock} struct BuildingBlockPrinter{T<:BuildingBlock}
bb::T bb::T
......
...@@ -65,12 +65,6 @@ for (block_symbol, all_functions) in all_variables_symbols ...@@ -65,12 +65,6 @@ for (block_symbol, all_functions) in all_variables_symbols
end end
# helper functions
function qval_square(bb, args...; kwargs...)
vec = qvec(bb, args...; kwargs...)
return vec[1]^2 + vec[2]^2 + vec[3]^2
end
alternative_variables = Dict( alternative_variables = Dict(
qval => (qval_square, n->n^2, sqrt, false), qval => (qval_square, n->n^2, sqrt, false),
slice_thickness => (inverse_slice_thickness, inv, inv, true), slice_thickness => (inverse_slice_thickness, inv, inv, true),
......
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