Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cstjean opened this issue May 19, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@cstjean
Copy link
Contributor

cstjean commented May 19, 2025

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
@cstjean cstjean added the bug Something isn't working label May 19, 2025
cstjean added a commit to cstjean/ModelingToolkit.jl that referenced this issue May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants