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

Running a simulation of a toy problem does not terminate #20

Open
freemin7 opened this issue May 11, 2020 · 2 comments
Open

Running a simulation of a toy problem does not terminate #20

freemin7 opened this issue May 11, 2020 · 2 comments

Comments

@freemin7
Copy link

Hello,

i tried to port a toy problem from Simulink to this framework.


Cf = 0.03
Lf = 0.0003
RLF = 2.0

model = Model(clock=Clock(0,0.01,4.))

konstLaststrom = StepGenerator(;amplitude=0, delay=0.001, offset=1)

divide = Multiplier((*, /))
iAdd = Adder((+, -))

Intuc = ODESystem((dx,x,u,t)->(dx[1]=u[1](t)/Cf), (x,u,t) -> x, [99.99], 0., Inport(), Outport())

Uq = StepGenerator(;amplitude=100, delay=0.0001, offset=0)
uAdd = Adder((-, -, +))

IntiLf = ODESystem((dx,x,u,t)->(dx[1]=u[1](t)/Lf), (x,u,t) -> x, [1.0], 0., Inport(), Outport())

uRf = Gain(gain=RLF)

addnode(model, konstLaststrom, label=:konstLaststrom)
addnode(model, divide, label=:divide)
addnode(model, iAdd, label=:iAdd)
addnode(model, Intuc, label=:Intuc)
addnode(model, Uq, label=:Uq)
addnode(model, uAdd, label=:uAdd)
addnode(model, IntiLf, label=:IntiLf)
addnode(model, uRf, label=:uRf)

addnode(model, Writer(Inport(5)), label=:writer)

addbranch(model, :Intuc => :divide, 1 => 2)
addbranch(model, :konstLaststrom => :divide, 1 => 1)
addbranch(model, :divide => :iAdd, 1 => 2)
addbranch(model, :IntiLf => :iAdd, 1 => 1)
addbranch(model, :iAdd => :Intuc, 1 => 1)
addbranch(model, :Intuc => :iAdd, 1 => 1)

addbranch(model, :Uq => :uAdd, 1 => 3)
addbranch(model, :Intuc => :uAdd, 1 => 2)
addbranch(model, :uRf => :uAdd, 1 => 1)
addbranch(model, :uAdd => :IntiLf, 1 => 1)
addbranch(model, :IntiLf => :uRf, 1 => 1)

addbranch(model, :Uq => :writer, 1 => 1)
addbranch(model, :Intuc => :writer, 1 => 2)
addbranch(model, :IntiLf => :writer, 1 => 3)
addbranch(model, :divide => :writer, 1 => 4)
addbranch(model, :iAdd => :writer, 1 => 5)

sim = simulate(model)

However the program is stuck on:

[ Info: 2020-05-11T20:31:55.632 Inspecting model...
┌ Info:     The model has algebraic loops:Array{Int64,1}[[2, 3, 4], [3, 4], [3, 4, 6, 7], [6, 7, 8]]
└       Trying to break these loops...
[ Info:     Loop [2, 3, 4] is broken
[ Info:     Loop [3, 4] is broken
[ Info:     Loop [3, 4, 6, 7] is broken
[ Info:     Loop [6, 7, 8] is broken
[ Info: 2020-05-11T20:31:56.43 Done.
[ Info: 2020-05-11T20:31:56.43 Initializing the model...
[ Info: 2020-05-11T20:32:00.388 Done...
[ Info: 2020-05-11T20:32:00.388 Running the simulation...

I also found no way to check whether i missed to add some branch, other than manually where i spotted nothing wrong. I also see not CPU utilization.

@zekeriyasari
Copy link
Owner

I am very glad that you give a shot to Jusdl @freemin7

I also found no way to check whether i missed to add some branch,

Jusdl is still in its development phase, and currently needs enrichment (and of course logging) of its inspection scope. So, the inspection of unterminated pins/ports will be included in the model inspection stage of the simulation.

What I see from your model construction is that iAdd has an input port consisting of 2 pins.

iAdd = Adder((+, -))

But, you try to connect the outputs of divide, inTilf and Intuc to iAdd.

addbranch(model, :divide => :iAdd, 1 => 2)
addbranch(model, :IntiLf => :iAdd, 1 => 1)
addbranch(model, :Intuc => :iAdd, 1 => 1)

This is erroneous. You should not connect 3 pins to a 2-pin port. Surely this is not your fault as this should also be checked and not be allowed during model construction . (This check will also be include to the package).

One other important thing with your model(by considering just your model construction above) is that the model includes four algebraic loops. Three of those algebraic loops are nested. Although currently Jusdl simulates models having algebraic loops that are not nested, it needs further development to break nested algebraic loops.

It seems to me that the model you are trying to simulate can be constructed more compactly without needing so many components like adders, multipliers, etc. Can you please write share the model equations with me so that I can try to simulate it.

Thank you again for filing this issue.

@freemin7
Copy link
Author

After removing the wrong term the simulation stops at 50%. So there is still something wrong.

using Jusdl

Cf = 0.03
Lf = 0.0003
RLF = 2.0

model = Model(clock=Clock(0,0.01,4.))

konstLaststrom = StepGenerator(;amplitude=0, delay=0.001, offset=1)

divide = Multiplier((*, /))
iAdd = Adder((+, -))

Intuc = ODESystem((dx,x,u,t)->(dx[1]=u[1](t)/Cf), (x,u,t) -> x, [99.99], 0., Inport(), Outport())

Uq = StepGenerator(;amplitude=100, delay=0.0001, offset=0)
uAdd = Adder((-, -, +))

IntiLf = ODESystem((dx,x,u,t)->(dx[1]=u[1](t)/Lf), (x,u,t) -> x, [1.0], 0., Inport(), Outport())

uRf = Gain(gain=RLF)

addnode(model, konstLaststrom, label=:konstLaststrom)
addnode(model, divide, label=:divide)
addnode(model, iAdd, label=:iAdd)
addnode(model, Intuc, label=:Intuc)
addnode(model, Uq, label=:Uq)
addnode(model, uAdd, label=:uAdd)
addnode(model, IntiLf, label=:IntiLf)
addnode(model, uRf, label=:uRf)

addnode(model, Writer(Inport(5)), label=:writer)

addbranch(model, :Intuc => :divide, 1 => 2)
addbranch(model, :konstLaststrom => :divide, 1 => 1)
addbranch(model, :divide => :iAdd, 1 => 2)
addbranch(model, :IntiLf => :iAdd, 1 => 1)
addbranch(model, :iAdd => :Intuc, 1 => 1)

addbranch(model, :Uq => :uAdd, 1 => 3)
addbranch(model, :Intuc => :uAdd, 1 => 2)
addbranch(model, :uRf => :uAdd, 1 => 1)
addbranch(model, :uAdd => :IntiLf, 1 => 1)
addbranch(model, :IntiLf => :uRf, 1 => 1)

addbranch(model, :Uq => :writer, 1 => 1)
addbranch(model, :Intuc => :writer, 1 => 2)
addbranch(model, :IntiLf => :writer, 1 => 3)
addbranch(model, :divide => :writer, 1 => 4)
addbranch(model, :iAdd => :writer, 1 => 5)

sim = simulate(model)

The model is based on a small SimuLink example of somebody i know and for whom i evaluate whether Julia is ready for their work flow.
TST.zip Since i have no matlab i use a free version of DiffPlug to inspect the file.

It is obvious that this system can be rephrased as a single (linear) ODE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants