Skip to content
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

sol[inlet.conc] does not work in flow connector #3416

Open
cstjean opened this issue Feb 25, 2025 · 3 comments
Open

sol[inlet.conc] does not work in flow connector #3416

cstjean opened this issue Feb 25, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@cstjean
Copy link
Contributor

cstjean commented Feb 25, 2025

Describe the bug 🐞

If I have a stream connector for a concentration, sol[inlet.concentration] should work. It doesn't, but it works for sol.outlet.concentration.

Minimal Reproducible Example 👇

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

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

@mtkmodel Source begin
    @components begin
        outlet = SolutionPin()
    end
    @equations begin
        outlet.flow ~ -10
        outlet.conc ~ 0.3
    end
end

@mtkmodel Tank begin
    @components begin
        inlet = SolutionPin()
    end
    @variables begin
        product_mass(t) = 0
        conc(t)
    end
    @equations begin
        D(product_mass) ~ inlet.flow * instream(inlet.conc)
        conc ~ instream(inlet.conc)  # obviously not physically correct
    end
end

@mtkmodel Room begin
    @components begin
        src = Source()
        tank = Tank()
    end
    @equations begin
        connect(src.outlet, tank.inlet)
    end
end

@mtkbuild room = Room()
prob = ODEProblem(room, [], (0, 10.0), [])
sol = solve(prob)

sol[room.src.outlet.conc]  # works
sol[room.src.inlet.flow]  # works
sol[room.tank.inlet.conc] # ERROR: ArgumentError: tank₊inlet₊conc(t) is neither an observed nor an unknown 
sol[room.tank.conc] # works

Adding instream() does not work either (it shouldn't be required anyway).

@cstjean cstjean added the bug Something isn't working label Feb 25, 2025
@cstjean cstjean changed the title sol[inlet.conc] does not work (instream) sol[inlet.conc] does not work in flow connector Feb 25, 2025
@AayushSabharwal
Copy link
Member

The problem is that tank.inlet.conc is not present in the simplified system, so MTK doesn't know how to compute it.

julia> room
Model room:
Equations (1):
  1 standard: see equations(room)
Unknowns (1): see unknowns(room)
  tank₊product_mass(t) [defaults to 0]
Observed (6): see observed(room)

julia> observed(room)
6-element Vector{Equation}:
 src₊outlet₊flow(t) ~ -10.0
 src₊outlet₊conc(t) ~ 0.3
 tank₊inlet₊dummy(t) ~ -0.0
 tank₊inlet₊flow(t) ~ -src₊outlet₊flow(t)
 tank₊conc(t) ~ src₊outlet₊conc(t)
 src₊outlet₊dummy(t) ~ tank₊inlet₊dummy(t)

julia> equations(room)
1-element Vector{Equation}:
 Differential(t)(tank₊product_mass(t)) ~ tank₊inlet₊flow(t)*src₊outlet₊conc(t)

@ChrisRackauckas
Copy link
Member

Seems like a stream connector bug?

@AayushSabharwal
Copy link
Member

Yeah likely. I'm looking into it.

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

3 participants