Skip to content

Commit 9cf1768

Browse files
Fix test cases
1 parent 2ccf8fa commit 9cf1768

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

test/components.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ let
9898
@named rc_model2 = compose(_rc_model2,
9999
[resistor, resistor2, capacitor, source, ground])
100100
sys2 = structural_simplify(rc_model2)
101-
prob2 = ODEProblem(sys2, u0, (0, 10.0))
101+
prob2 = ODEProblem(sys2, [], (0, 10.0), guesses = u0)
102102
sol2 = solve(prob2, Rosenbrock23())
103-
@test sol2[source.p.i] sol2[rc_model2.source.p.i] -sol2[capacitor.i]
103+
@test sol2[source.p.i] sol2[rc_model2.source.p.i] sol2[capacitor.i]
104104
end
105105

106106
# Outer/inner connections
@@ -155,7 +155,7 @@ include("../examples/serial_inductor.jl")
155155
sys = structural_simplify(ll_model)
156156
@test length(equations(sys)) == 2
157157
u0 = unknowns(sys) .=> 0
158-
@test_nowarn ODEProblem(sys, u0, (0, 10.0))
158+
@test_nowarn ODEProblem(sys, [], (0, 10.0), guesses = u0, warn_initialize_determined = false)
159159
prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0, u0, (0, 0.5))
160160
sol = solve(prob, DFBDF())
161161
@test sol.retcode == SciMLBase.ReturnCode.Success

test/state_selection.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ end
4545
# 1516
4646
let
4747
@connector function Fluid_port(; name, p = 101325.0, m = 0.0, T = 293.15)
48-
sts = @variables p(t)=p m(t)=m [connect = Flow] T(t)=T [connect = Stream]
48+
sts = @variables p(t) [guess=p] m(t) [guess = m, connect = Flow] T(t) [guess=T, connect = Stream]
4949
ODESystem(Equation[], t, sts, []; name = name)
5050
end
51-
51+
5252
#this one is for latter
5353
@connector function Heat_port(; name, Q = 0.0, T = 293.15)
54-
sts = @variables T(t)=T Q(t)=Q [connect = Flow]
54+
sts = @variables T(t) [guess=T] Q(t) [guess = Q, connect = Flow]
5555
ODESystem(Equation[], t, sts, []; name = name)
5656
end
57-
57+
5858
# like ground but for fluid systems (fluid_port.m is expected to be zero in closed loop)
5959
function Compensator(; name, p = 101325.0, T_back = 273.15)
6060
@named fluid_port = Fluid_port()
@@ -63,7 +63,7 @@ let
6363
fluid_port.T ~ T_back]
6464
compose(ODESystem(eqs, t, [], ps; name = name), fluid_port)
6565
end
66-
66+
6767
function Source(; name, delta_p = 100, T_feed = 293.15)
6868
@named supply_port = Fluid_port() # expected to feed connected pipe -> m<0
6969
@named return_port = Fluid_port() # expected to receive from connected pipe -> m>0
@@ -74,7 +74,7 @@ let
7474
return_port.T ~ T_feed]
7575
compose(ODESystem(eqs, t, [], ps; name = name), [supply_port, return_port])
7676
end
77-
77+
7878
function Substation(; name, T_return = 343.15)
7979
@named supply_port = Fluid_port() # expected to receive from connected pipe -> m>0
8080
@named return_port = Fluid_port() # expected to feed connected pipe -> m<0
@@ -85,12 +85,12 @@ let
8585
return_port.T ~ T_return]
8686
compose(ODESystem(eqs, t, [], ps; name = name), [supply_port, return_port])
8787
end
88-
88+
8989
function Pipe(; name, L = 1000, d = 0.1, N = 100, rho = 1000, f = 1)
9090
@named fluid_port_a = Fluid_port()
9191
@named fluid_port_b = Fluid_port()
9292
ps = @parameters L=L d=d rho=rho f=f N=N
93-
sts = @variables v(t)=0.0 dp_z(t)=0.0
93+
sts = @variables v(t) [guess=0.0] dp_z(t) [guess=0.0]
9494
eqs = [fluid_port_a.m ~ -fluid_port_b.m
9595
fluid_port_a.T ~ instream(fluid_port_a.T)
9696
fluid_port_b.T ~ fluid_port_a.T
@@ -114,18 +114,18 @@ let
114114
connect(return_pipe.fluid_port_a, source.return_port)]
115115
compose(ODESystem(eqs, t, [], ps; name = name), subs)
116116
end
117-
117+
118118
@named system = System(L = 10)
119119
@unpack supply_pipe, return_pipe = system
120120
sys = structural_simplify(system)
121121
u0 = [
122122
system.supply_pipe.v => 0.1, system.return_pipe.v => 0.1, D(supply_pipe.v) => 0.0,
123123
D(return_pipe.fluid_port_a.m) => 0.0,
124124
D(supply_pipe.fluid_port_a.m) => 0.0]
125-
prob1 = ODEProblem(sys, u0, (0.0, 10.0), [])
126-
prob2 = ODEProblem(sys, u0, (0.0, 10.0), [])
125+
prob1 = ODEProblem(sys, [], (0.0, 10.0), [], guesses = u0)
126+
prob2 = ODEProblem(sys, [], (0.0, 10.0), [], guesses = u0)
127127
prob3 = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, u0, (0.0, 10.0), [])
128-
@test solve(prob1, FBDF()).retcode == ReturnCode.Success
128+
@test solve(prob1, FBDF()).retcode == ReturnCode.Success
129129
#@test solve(prob2, FBDF()).retcode == ReturnCode.Success
130130
@test solve(prob3, DFBDF()).retcode == ReturnCode.Success
131131
end

test/structural_transformation/index_reduction.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,13 @@ let sys = structural_simplify(pendulum2)
144144
D(D(y)) => 0.0,
145145
x => sqrt(2) / 2,
146146
y => sqrt(2) / 2,
147-
T => 0.0
148147
]
149148
p = [
150149
L => 1.0,
151150
g => 9.8
152151
]
153152

154-
prob_auto = ODEProblem(sys, u0, (0.0, 0.5), p)
153+
prob_auto = ODEProblem(sys, u0, (0.0, 0.5), p, guesses = [T => 0.0])
155154
sol = solve(prob_auto, FBDF())
156155
@test sol.retcode == ReturnCode.Success
157156
@test norm(sol[x] .^ 2 + sol[y] .^ 2 .- 1) < 1e-2

0 commit comments

Comments
 (0)