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

Set qval/qvec directly if possible

parent 016647d5
No related branches found
No related tags found
1 merge request!2Define variables through new @defvar macro
module InstantGradients module InstantGradients
import StaticArrays: SVector, SMatrix import StaticArrays: SVector, SMatrix
import JuMP: @constraint import JuMP: @constraint
import ...Variables: @defvar, VariableType, variables, get_free_variable, set_simple_constraints!, make_generic, adjust_internal, adjustable, gradient_orientation import ...Variables: @defvar, VariableType, variables, get_free_variable, set_simple_constraints!, make_generic, adjust_internal, adjustable, gradient_orientation, apply_simple_constraint!
import ...BuildSequences: global_model import ...BuildSequences: global_model
import ..AbstractTypes: EventComponent, GradientWaveform import ..AbstractTypes: EventComponent, GradientWaveform
...@@ -20,16 +20,18 @@ If the `orientation` is set an [`InstantGradient1D`](@ref) is returned, otherwis ...@@ -20,16 +20,18 @@ If the `orientation` is set an [`InstantGradient1D`](@ref) is returned, otherwis
""" """
abstract type InstantGradient{N} <: EventComponent end abstract type InstantGradient{N} <: EventComponent end
function (::Type{InstantGradient})(; orientation=nothing, group=nothing, variables...) function (::Type{InstantGradient})(; orientation=nothing, group=nothing, qval=nothing, qvec=[nothing, nothing, nothing], vars...)
if isnothing(orientation) if isnothing(orientation)
res = InstantGradient3D(nothing, group) res = InstantGradient3D(get_free_variable.(qvec), group)
apply_simple_constraint!(variables.qval(res), qval)
else else
res = InstantGradient1D(nothing, orientation, group) res = InstantGradient1D(get_free_variable(qval), orientation, group)
if !(res.qvec isa Number) if !(res.qval isa Number)
@constraint global_model() res.qvec >= 0 @constraint global_model() res.qval >= 0
end end
apply_simple_constraint!(variables.qvec(res), qvec)
end end
set_simple_constraints!(res, variables) set_simple_constraints!(res, vars)
return res return res
end end
...@@ -52,15 +54,6 @@ struct InstantGradient3D <: InstantGradient{3} ...@@ -52,15 +54,6 @@ struct InstantGradient3D <: InstantGradient{3}
group :: Union{Nothing, Symbol} group :: Union{Nothing, Symbol}
end end
function InstantGradient3D(; qvec=nothing, group=nothing, variables...)
if isnothing(qvec)
qvec = [nothing, nothing, nothing]
end
res = InstantGradient3D(get_free_variable.(qvec), group)
set_simple_constraints!(res, variables)
return res
end
@defvar gradient qvec(ig::InstantGradient3D) = ig.qvec @defvar gradient qvec(ig::InstantGradient3D) = ig.qvec
......
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