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

@discrete_events or @continuous_events not working with acausal modeling framework #2849

Closed
joseph03choi opened this issue Jul 6, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@joseph03choi
Copy link

@discrete_events or @continuous_events can not "see" connector variables from outside components or its own component variables.
Example component:

@mtkmodel PIcontroller begin
    @components begin
        readingsIn = Stream()
        signalOut = ValveSignal()
    end
    @variables begin
        I_err(t) = 0
    end
    @parameters begin
        c_BSP = 0.32
        K_b = 0.0
        K_c = 9.0
        K_I = 0.18
        s = 0 # No initial signal to open valve
    end
    @equations begin
        D(I_err) ~ c_BSP - readingsIn.c_B
        signalOut.s ~ s
    end
    @discrete_events begin
        ((mod(t-200,30) == 0) & (t >= 30)) => [s ~ K_b + K_c*(c_BSP - readingsIn.c_B) + K_I*I_err]
    end
end

I'm able to connect all my components, use @mtkbuild, and create an ODEProblem(), but when I get to solve(), I get ERROR: UndefVarError: picontroller₊readingsIn₊c_B not defined. I’ve isolated @discrete_events as the issue here because whenever I replace readingsIn.c_B in the @discrete_events block with some number, everything is able to run properly (although I get the wrong solution of course).

Similarly, @discrete_events or @continuous_events can not see its own component variables unless it has a derivative term.
For example:

@mtkmodel PIcontroller begin
    @components begin
        readingsIn = Stream()
        signalOut = ValveSignal()
    end
    @variables begin
        I_err(t) = 0
        B(t) # Trying to use component variable
    end
    @parameters begin
        c_BSP = 0.32
        K_b = 0.0
        K_c = 9.0
        K_I = 0.18
        s = 0 # No initial signal to open valve
    end
    @equations begin
        B ~ readingsIn.c_B
        D(I_err) ~ c_BSP - B
        signalOut.s ~ s
    end
    @discrete_events begin
        ((mod(t-200,30) == 0) & (t >= 30)) => [s ~ K_b + K_c*(c_BSP - B) + K_I*I_err]
    end
end

@discrete_events can't see the variable B, and I get ERROR: UndefVarError: picontroller₊B not defined. @discrete_events can only see B if I do something like D(B) ~ 0, but then I can’t do B ~ readingsIn.c_B because @mtkbuild will tell me I have too many equations.

@joseph03choi joseph03choi added the bug Something isn't working label Jul 6, 2024
@joseph03choi joseph03choi changed the title @discrete_events or @continuous_events not working with acausal modeling framework @discrete_events or @continuous_events not working with acausal modeling framework Jul 6, 2024
@AayushSabharwal
Copy link
Member

Please provide a complete MWE. There isn't enough code here to reproduce the problem (e.g. PIcontroller references Stream and ValveSignal which aren't defined here)

@ChrisRackauckas
Copy link
Member

Closing unless code shows up that allows for reproducing. Indeed I have no idea how to get the error that is being referenced here.

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