ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

Cannot use structural parameter as array size

Open baggepinnen opened this issue 9 months ago • 3 comments

@mtkmodel Foo begin
    @structural_parameters begin
        nx = 2
    end
    @variables begin
        (x(t)[1:nx]), [description = "State"]
    end
    @equations begin
    end
end
ERROR: promotion of types Int64 and Symbol failed to change any arguments

With explicit array size, it works

julia> @mtkmodel Foo begin
           @structural_parameters begin
               nx = 2
           end
           @variables begin
               (x(t)[1:2]), [description = "State"]
           end
           @equations begin
           end
       end
ModelingToolkit.Model{typeof(__Foo__), Dict{Symbol, Any}}(__Foo__, Dict{Symbol, Any}(:variables => Dict{Symbol, Dict{Symbol, Any}}(:x => Dict(:type => Real, :description => "State", :size => (2,))), :kwargs => Dict{Symbol, Dict}(:nx => Dict(:value => 2), :x => Dict{Symbol, Union{Nothing, UnionAll}}(:value => nothing, :type => AbstractArray{Real})), :structural_parameters => Dict{Symbol, Dict}(:nx => Dict(:value => 2)), :independent_variable => t, :equations => Any[]), false)

baggepinnen avatar May 06 '24 09:05 baggepinnen

Duplicate of https://github.com/SciML/ModelingToolkit.jl/issues/2453?

jaakkor2 avatar May 07 '24 11:05 jaakkor2

Is there a workaround to allow variable sized arrays?

dfabianus avatar Jun 15 '24 13:06 dfabianus

For what? That seems very orthogonal to this issue.

ChrisRackauckas avatar Jun 15 '24 16:06 ChrisRackauckas

With https://github.com/SciML/ModelingToolkit.jl/pull/3107, this is now possible

ven-k avatar Oct 15 '24 17:10 ven-k