Here is a MWE with the change of name that make a change in the unknows
using ModelingToolkit
using DifferentialEquations
using SciCompDSL
using ModelingToolkit: t_nounits as t, D_nounits as D
using SciMLStructures: Tunable, canonicalize, replace
using PreallocationTools
using Plots
@connector Pin begin
p(t)
q(t), [connect = Flow]
end
@mtkmodel OnePort begin
@components begin
in = Pin()
out = Pin()
end
@variables begin
Δp(t)
q(t)
end
@equations begin
Δp ~ in.p - out.p
0 ~ in.q + out.q
q ~ in.q
end
end
@mtkmodel ConstantPressure begin
@components begin
node = Pin()
end
@parameters begin
P
end
@equations begin
node.p ~ P
end
end
@mtkmodel ForcedFlow begin
@components begin
in = Pin()
out = Pin()
end
@parameters begin
Q
end
@equations begin
out.q ~ - Q
in.q ~ Q
end
end
@mtkmodel Resistor begin
@extend Δp, q = oneport = OnePort()
@parameters begin
R
end
@equations begin
Δp ~ q * R
end
end
@mtkmodel ResistorValve begin
@extend Δp, q = oneport = OnePort()
@parameters begin
R
end
@equations begin
q ~ Δp / R * (Δp > 0)
end
end
@mtkmodel Capacitor_1 begin
@components begin
in = Pin()
out = Pin()
end
@parameters begin
C
end
@variables begin
V(t)
end
@equations begin
out.q ~ - in.q
D(V) ~ in.q
in.q ~ (D(in.p)-D(out.p)) * C
end
end
@mtkmodel Capacitor_2 begin
@components begin
in = Pin()
out = Pin()
end
@parameters begin
k
p0
end
@variables begin
V(t)
C(t)
end
@equations begin
out.q ~ - in.q
D(V) ~ in.q
in.q * (in.p - out.p - p0) * k ~ (D(in.p)-D(out.p))
C ~ 1/(k*(in.p - out.p -p0))
end
end
# -------------------------
# Numerical values
vals = Dict{Symbol, Float64}()
vals[:Pa_v] = 100.0
vals[:Psinus_v] = 6.34
vals[:Pic_v] = 9.5
vals[:P0_v] = 3.2
vals[:Prod_v] = 0.006
vals[:Ra_v] = 6.0
vals[:Rc_v] = 0.08
vals[:Rv_v] = 0.77
vals[:Ro_v] = 525.0
vals[:Ca_v] = 0.02
vals[:E_v] = 0.35*1.3
# Define elements
@named Pa = ConstantPressure(P = vals[:Pa_v]);
@named Psinus = ConstantPressure(P = vals[:Psinus_v]);
@named Pic = ConstantPressure(P = vals[:Pic_v]);
@named Prod = ForcedFlow(Q = vals[:Prod_v]);
@named Ra = Resistor(R = vals[:Ra_v]);
@named Rc = Resistor(R = vals[:Rc_v]);
@named Rv = Resistor(R = vals[:Rv_v]);
@named Ro = ResistorValve(R = vals[:Ro_v]);
@named Ca = Capacitor_1(C = vals[:Ca_v]);
@named Cv = Capacitor_2(k = vals[:E_v], p0 = vals[:P0_v]);
# Define the elements used in the steady-state model
elements_steady_state = [Pa, Psinus, Pic, Prod, Ra, Rc, Rv, Ro, Ca, Cv];
# Describe how components are connected
assembly_steady_state = [
connect(Pa.node, Ra.in, Ca.in);
connect(Ra.out, Rc.in, Prod.in);
connect(Rc.out, Cv.in, Rv.in);
connect(Ca.out, Prod.out, Cv.out, Ro.in, Pic.node);
connect(Rv.out, Ro.out, Psinus.node);
];
# Declare the system as an ODESystem
@mtkcompile sys_steady_state = System(assembly_steady_state,t; systems = elements_steady_state)
We have
Model sys_steady_state:
Equations (4):
4 standard: see equations(sys_steady_state)
Unknowns (4): see unknowns(sys_steady_state)
Cv₊in₊q(t)
Cv₊V(t)
Cv₊in₊p(t)
Ca₊V(t)
Parameters (11): see parameters(sys_steady_state)
Pa₊P
Psinus₊P
Pic₊P
Prod₊Q
⋮
Observed (46): see observed(sys_steady_state)
Then when doing this
# Define elements
@named Pa_steady_state = ConstantPressure(P = vals[:Pa_v]);
@named Psinus = ConstantPressure(P = vals[:Psinus_v]);
@named Pic = ConstantPressure(P = vals[:Pic_v]);
@named Prod = ForcedFlow(Q = vals[:Prod_v]);
@named Ra = Resistor(R = vals[:Ra_v]);
@named Rc = Resistor(R = vals[:Rc_v]);
@named Rv = Resistor(R = vals[:Rv_v]);
@named Ro = ResistorValve(R = vals[:Ro_v]);
@named Ca = Capacitor_1(C = vals[:Ca_v]);
@named Cv = Capacitor_2(k = vals[:E_v], p0 = vals[:P0_v]);
# Define the elements used in the steady-state model
elements_steady_state = [Pa_steady_state, Psinus, Pic, Prod, Ra, Rc, Rv, Ro, Ca, Cv];
# Describe how components are connected
assembly_steady_state = [
connect(Pa_steady_state.node, Ra.in, Ca.in);
connect(Ra.out, Rc.in, Prod.in);
connect(Rc.out, Cv.in, Rv.in);
connect(Ca.out, Prod.out, Cv.out, Ro.in, Pic.node);
connect(Rv.out, Ro.out, Psinus.node);
];
# Declare the system as an ODESystem
@mtkcompile sys_steady_state = System(assembly_steady_state,t; systems = elements_steady_state)
I have this :
Model sys_steady_state:
Equations (4):
4 standard: see equations(sys_steady_state)
Unknowns (4): see unknowns(sys_steady_state)
Rc₊q(t)
Cv₊V(t)
Cv₊in₊p(t)
Ca₊V(t)
Parameters (11): see parameters(sys_steady_state)
Pa_steady_state₊P
Psinus₊P
Pic₊P
Prod₊Q
⋮
Observed (46): see observed(sys_steady_state)
So I have a change from Cv.in.q(t) to Rc.q(t) in the unknows.