@@ -506,11 +506,36 @@ end
506
506
prob = ODEProblem (sys, [x => 1.0 , y => 1.0 ], (0.0 , 1.0 ), [p => missing ])
507
507
test_parameter (prob, p, 2.0 )
508
508
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
+
509
516
@testset " Null system" begin
510
517
@variables x (t) y (t) s (t)
511
518
@parameters x0 y0
512
519
@mtkbuild sys = ODESystem ([x ~ x0, y ~ y0, s ~ x + y], t)
513
520
prob = ODEProblem (sys, [s => 1.0 ], (0.0 , 1.0 ), [x0 => 0.3 , y0 => missing ])
514
521
test_parameter (prob, y0, 0.7 )
515
522
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 )
516
541
end
0 commit comments