Skip to content

MTK erroneously claims that my variable "is not a variable inside stream connectors" #3638

Open
@cstjean

Description

@cstjean

Describe the bug 🐞

The error message below says that reactor₊inlet₊conc(t) is not a variable inside stream connectors. inlet.conc is a stream variable, so the connector should be a Stream connector by the definition:

StreamConnector: A connector which has atleast one stream variable, specified by [connect = Stream]. A StreamConnector must have exactly one flow variable.

Expected behavior

  • It should not complain about instream
  • @mtkbuild Reactor() and @mtkbuild Room() should ideally behave the same.

EDIT: on second thought, the core problem is likely that an unconnected connector is considered problematic? This should be the error message?

Minimal Reproducible Example 👇

using ModelingToolkit, DifferentialEquations, Test
using ModelingToolkit: t_nounits as t, D_nounits as D

@connector FlowPin begin
    flow(t), [connect=Flow]
    conc(t), [connect=Stream]
    dummy1(t)
end

@mtkmodel Reactor begin
    @components begin
        inlet = FlowPin()
    end
    @variables begin
        x(t)
    end
    @equations begin
        x ~ instream(inlet.conc)
    end
end

@mtkmodel Room begin
    @components begin
        reactor = Reactor()
    end
end

@mtkbuild reactor = Reactor()  # The system is unbalanced. There are 3 highest order derivative variables and 2 equations.
@mtkbuild room = Room()  #  reactor₊inlet₊conc(t) is not a variable inside stream connectors

Error & Stacktrace ⚠️

julia> include("dbg.jl")
ERROR: LoadError: reactor₊inlet₊conc(t) is not a variable inside stream connectors
Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:35
  [2] expand_instream(csets::Vector{…}, sys::ODESystem, namespace::Nothing, prevnamespace::Nothing; debug::Bool, tol::Float64)
    @ ModelingToolkit C:\Users\a1058035\.julia\packages\ModelingToolkit\15RQb\src\systems\connectors.jl:857
  [3] expand_instream
    @ C:\Users\a1058035\.julia\packages\ModelingToolkit\15RQb\src\systems\connectors.jl:808 [inlined]
  [4] expand_connections(sys::ODESystem, find::Nothing, replace::Nothing; debug::Bool, tol::Float64, scalarize::Bool)
    @ ModelingToolkit C:\Users\a1058035\.julia\packages\ModelingToolkit\15RQb\src\systems\connectors.jl:788
  [5] expand_connections (repeats 2 times)
    @ C:\Users\a1058035\.julia\packages\ModelingToolkit\15RQb\src\systems\connectors.jl:782 [inlined]
  [6] __structural_simplify(sys::ODESystem, io::Nothing; simplify::Bool, kwargs::@Kwargs{})
    @ ModelingToolkit C:\Users\a1058035\.julia\packages\ModelingToolkit\15RQb\src\systems\systems.jl:74
  [7] __structural_simplify
    @ C:\Users\a1058035\.julia\packages\ModelingToolkit\15RQb\src\systems\systems.jl:72 [inlined]
  [8] structural_simplify(sys::ODESystem, io::Nothing; additional_passes::Vector{…}, simplify::Bool, split::Bool, allow_symbolic::Bool, allow_parameter::Bool, conservative::Bool, fully_determined::Bool, kwargs::@Kwargs{})
    @ ModelingToolkit C:\Users\a1058035\.julia\packages\ModelingToolkit\15RQb\src\systems\systems.jl:33
  [9] structural_simplify
    @ C:\Users\a1058035\.julia\packages\ModelingToolkit\15RQb\src\systems\systems.jl:28 [inlined]
 [10] structural_simplify(sys::ODESystem)
    @ ModelingToolkit C:\Users\a1058035\.julia\packages\ModelingToolkit\15RQb\src\systems\systems.jl:28
 [11] top-level scope
    @ C:\Users\a1058035\.julia\packages\ModelingToolkit\15RQb\src\systems\abstractsystem.jl:2475
 [12] include(fname::String)
    @ Main .\sysimg.jl:38
 [13] top-level scope
    @ REPL[2]:1
in expression starting at C:\Users\a1058035\Documents\SimDenkai\play_env\dbg.jl:30
Some type information was truncated. Use `show(err)` to see complete types.

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
ModelingToolkit v9.73.0
SymbolicUtils v3.26.1
Symbolics v6.38.0
  • Output of versioninfo()
v1.11.5

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions