Skip to content

Commit f65d4cd

Browse files
fixup! test: test parameters as initialization unknowns
1 parent 57c5119 commit f65d4cd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/initializationsystem.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,36 @@ end
506506
prob = ODEProblem(sys, [x => 1.0, y => 1.0], (0.0, 1.0), [p => missing])
507507
test_parameter(prob, p, 2.0)
508508

509+
@mtkbuild sys = ODESystem([D(x) ~ x, p ~ x + y], t; guesses = [p => 1.0])
510+
@test_throws ModelingToolkit.MissingParametersError ODEProblem(
511+
sys, [x => 1.0, y => 1.0], (0.0, 1.0))
512+
@mtkbuild sys = ODESystem([D(x) ~ x, p ~ x + y], t)
513+
@test_throws ["Invalid setup", "parameter p", "guess"] ODEProblem(
514+
sys, [x => 1.0, y => 1.0], (0.0, 1.0), [p => missing])
515+
509516
@testset "Null system" begin
510517
@variables x(t) y(t) s(t)
511518
@parameters x0 y0
512519
@mtkbuild sys = ODESystem([x ~ x0, y ~ y0, s ~ x + y], t)
513520
prob = ODEProblem(sys, [s => 1.0], (0.0, 1.0), [x0 => 0.3, y0 => missing])
514521
test_parameter(prob, y0, 0.7)
515522
end
523+
524+
using ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica: Fixed, Mass,
525+
Spring, Force
526+
using ModelingToolkitStandardLibrary.Blocks: Constant
527+
528+
@named mass = Mass(; m = 1.0, s = 1.0, v = 0.0, a = 0.0)
529+
@named fixed = Fixed(; s0 = 0.0)
530+
@named spring = Spring(; c = 2.0)
531+
@named gravity = Force()
532+
@named constant = Constant(; k = 9.81)
533+
@mtkbuild sys = ODESystem(
534+
[connect(fixed.flange, spring.flange_a), connect(spring.flange_b, mass.flange_a),
535+
connect(mass.flange_a, gravity.flange), connect(constant.output, gravity.f)],
536+
t;
537+
systems = [fixed, spring, mass, gravity, constant],
538+
guesses = [spring.s_rel0 => 1.0])
539+
prob = ODEProblem(sys, [], (0.0, 1.0), [spring.s_rel0 => missing])
540+
test_parameter(prob, spring.s_rel0, -3.905)
516541
end

0 commit comments

Comments
 (0)