Skip to content

Commit 2e594aa

Browse files
test: fix initializations for several tests
1 parent 0e07044 commit 2e594aa

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

test/Blocks/continuous.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ end
162162
t,
163163
systems = [pi_controller, plant, ref, fb])
164164
sys = mtkcompile(model)
165+
initial_conditions(sys)[sys.pi_controller.gainPI.k] = 1.0
165166
prob = ODEProblem(sys, Pair[], (0.0, 100.0))
166167
sol = solve(prob, Rodas4())
167168
@test sol.retcode == Success
@@ -238,7 +239,7 @@ end
238239
u_max = 1.5,
239240
u_min = -1.5,
240241
Ta = 0.1)
241-
@named pi_controller = PI(gainPI.k = 3, T = 0.5)
242+
@named pi_controller = PI(T = 0.5)
242243
@named sat = Limiter(y_max = 1.5, y_min = -1.5)
243244
@named plant = Plant()
244245
@named fb = Feedback()
@@ -256,6 +257,7 @@ end
256257
t,
257258
systems = [pi_controller, plant, ref, fb, sat])
258259
sys = mtkcompile(model)
260+
initial_conditions(sys)[sys.pi_controller.gainPI.k] = 1.0
259261
prob = ODEProblem(sys, Pair[], (0.0, 20.0))
260262
sol = solve(prob, Rodas4())
261263
end

test/Blocks/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
(RealOutput(; nout = 3, name = :a), zeros(3))
2424
]
2525
guesses = ModelingToolkit.guesses(block)
26-
@test Symbolics.value(guesses[@nonamespace block.u[1]]) == guess[1]
26+
@test Symbolics.value(guesses[@nonamespace block.u][1]) == guess[1]
2727
end
2828
end
2929

@@ -36,7 +36,7 @@ end
3636

3737
initsys = ModelingToolkit.generate_initializesystem(sys)
3838
initsys = mtkcompile(initsys)
39-
initprob = NonlinearProblem(initsys, [t => 0])
39+
initprob = NonlinearProblem(initsys, merge(initial_conditions(sys), Dict([t => 0])))
4040
initsol = solve(initprob)
4141

4242
@test initsol[sys.so.xd] == 1.0

test/Electrical/analog.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ end
740740

741741
@mtkcompile sys = SimpleNPNCircuit(V_cc = 3.0, V_b = 0.70)
742742

743-
prob = ODEProblem(sys, Pair[], (0.0, 10.0); guesses = [sys.Q1.I_sub => 1.0, sys.Vcc_sine.output.u => 1.0])
743+
prob = ODEProblem(sys, Pair[], (0.0, 10.0); guesses = [sys.Q1.I_sub => 1.0])
744744
sol = solve(prob)
745745

746746
# make sure KCL is true
@@ -780,7 +780,7 @@ end
780780

781781
@mtkcompile sys = SimpleNPNCircuitSubstrate(V_b = 0.70)
782782

783-
prob = ODEProblem(sys, [sys.Q1.c.i => 0.0], (0.0, 10.0))
783+
prob = ODEProblem(sys, [sys.Q1.c.i => 0.0], (0.0, 10.0); guesses = [sys.Q1.I_sub => 1.0, sys.Vcc_sine.output.u => 1.0])
784784
sol = solve(prob)
785785

786786
@test isapprox(

test/Hydraulic/isothermal_compressible.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ end
299299
defs[sys.input.buffer] = Parameter(0.5 * x, dt)
300300

301301
# NOTE: bypassing initialization system: https://github.com/SciML/ModelingToolkit.jl/issues/3312
302-
prob = ODEProblem(sys, initsol[1], (0, 0.1); build_initializeprob = false)
302+
prob = ODEProblem(sys, [unknowns(initsys)[1] => initsol[1]], (0, 0.1); build_initializeprob = false)
303303

304304
#TODO: Implement proper initialization system after issue is resolved
305305
#TODO: How to bring the body back and not have an overdetermined system?

test/Thermal/demo.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using OrdinaryDiffEq: ReturnCode.Success
2121
@named model = System(connections, t,
2222
systems = [mass1, mass2, conduction, Tsensor1, Tsensor2])
2323
sys = mtkcompile(model)
24-
prob = ODEProblem(sys, [], (0, 3.0))
24+
prob = ODEProblem(sys, [conduction.Q_flow => nothing, conduction.dT => nothing], (0, 3.0))
2525
sol = solve(prob, Tsit5())
2626
@test SciMLBase.successful_retcode(sol)
2727
end

test/Thermal/piston.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ using ModelingToolkitStandardLibrary.Blocks
3434

3535
@mtkcompile piston = Piston()
3636

37-
prob = ODEProblem(piston, [], (0, 3.0))
37+
prob = ODEProblem(piston, [piston.gas.dT => nothing, piston.coolant.dT => nothing, piston.wall.Q_flow => nothing, piston.wall.dT => nothing, piston.gas.Q_flow => nothing, piston.coolant.Q_flow => nothing], (0, 3.0))
3838
sol = solve(prob)
3939

4040
# Heat-flow-rate is equal in magnitude

test/Thermal/thermal.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ using OrdinaryDiffEq: ReturnCode.Success
4242
systems = [mass1, mass2, T_sensor1, T_sensor2, th_conductor])
4343
sys = mtkcompile(h2)
4444

45-
u0 = [mass1.T => 1.0
46-
mass2.T => 10.0]
47-
prob = ODEProblem(sys, u0, (0, 3.0))
45+
prob = ODEProblem(sys, [], (0, 3.0))
4846
sol = solve(prob, Tsit5())
4947

5048
@test SciMLBase.successful_retcode(sol)
@@ -76,7 +74,7 @@ end
7674
th_resistor, flow_src, th_ground, th_conductor])
7775
sys = mtkcompile(h2)
7876

79-
u0 = [mass1.T => 10.0]
77+
u0 = [mass1.T => 10.0, th_conductor.dT => nothing, th_conductor.Q_flow => nothing, th_resistor.Q_flow => nothing, th_resistor.dT => nothing]
8078
prob = ODEProblem(sys, u0, (0, 3.0))
8179
sol = solve(prob, Tsit5())
8280

@@ -144,7 +142,7 @@ end
144142
collector, th_resistor, mass])
145143
sys = mtkcompile(coll)
146144

147-
prob = ODEProblem(sys, [], (0, 3.0))
145+
prob = ODEProblem(sys, [mass.T => nothing, th_resistor.Q_flow => nothing, th_resistor.dT => nothing], (0, 3.0))
148146
sol = solve(prob, Rodas4())
149147

150148
@test SciMLBase.successful_retcode(sol)
@@ -169,8 +167,8 @@ end
169167
end
170168

171169
@info "Building a FixedHeatFlow with alpha=0.0"
172-
@mtkcompile test_model = TestModel()
173-
prob = ODEProblem(test_model, Pair[], (0, 10.0))
170+
@mtkcompile test_model = TestModel() allow_parameter = false
171+
prob = ODEProblem(test_model, [test_model.wall.Q_flow => nothing, test_model.wall.dT => nothing], (0, 10.0); guesses = [test_model.heatflow.port.T => 1.0])
174172
sol = solve(prob)
175173

176174
heat_flow = sol[test_model.heatflow.port.Q_flow]

0 commit comments

Comments
 (0)