Skip to content

Commit 1de31d0

Browse files
test: test multi-input connect with single-input AP
1 parent 26668fd commit 1de31d0

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

test/downstream/analysis_points.jl

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,101 @@ end
340340
G = CS.ss(matrices...) |> sminreal
341341
@test tf(G) tf(CS.feedback(Ps, Cs))
342342
end
343+
344+
function normal_test_system()
345+
@named F1 = FirstOrder(k = 1, T = 1)
346+
@named F2 = FirstOrder(k = 1, T = 1)
347+
@named add = Blocks.Add(k1 = 1, k2 = 2)
348+
@named back = Feedback()
349+
350+
eqs_normal = [connect(back.output, :ap, F1.input)
351+
connect(back.output, F2.input)
352+
connect(F1.output, add.input1)
353+
connect(F2.output, add.input2)
354+
connect(add.output, back.input2)]
355+
@named normal_inner = ODESystem(eqs_normal, t; systems = [F1, F2, add, back])
356+
357+
@named step = Step()
358+
eqs2_normal = [
359+
connect(step.output, normal_inner.back.input1)
360+
]
361+
@named sys_normal = ODESystem(eqs2_normal, t; systems = [normal_inner, step])
362+
end
363+
364+
sys_normal = normal_test_system()
365+
366+
prob = ODEProblem(structural_simplify(sys_normal), [], (0.0, 10.0))
367+
@test SciMLBase.successful_retcode(solve(prob, Rodas5P()))
368+
matrices_normal, _ = get_sensitivity(sys_normal, sys_normal.normal_inner.ap)
369+
370+
@testset "Analysis point overriding part of connection - normal connect" begin
371+
@named F1 = FirstOrder(k = 1, T = 1)
372+
@named F2 = FirstOrder(k = 1, T = 1)
373+
@named add = Blocks.Add(k1 = 1, k2 = 2)
374+
@named back = Feedback()
375+
376+
eqs = [connect(back.output, F1.input, F2.input)
377+
connect(F1.output, add.input1)
378+
connect(F2.output, add.input2)
379+
connect(add.output, back.input2)]
380+
@named inner = ODESystem(eqs, t; systems = [F1, F2, add, back])
381+
382+
@named step = Step()
383+
eqs2 = [connect(step.output, inner.back.input1)
384+
connect(inner.back.output, :ap, inner.F1.input)]
385+
@named sys = ODESystem(eqs2, t; systems = [inner, step])
386+
387+
prob = ODEProblem(structural_simplify(sys), [], (0.0, 10.0))
388+
@test SciMLBase.successful_retcode(solve(prob, Rodas5P()))
389+
390+
matrices, _ = get_sensitivity(sys, sys.ap)
391+
@test matrices == matrices_normal
392+
end
393+
394+
@testset "Analysis point overriding part of connection - variable connect" begin
395+
@named F1 = FirstOrder(k = 1, T = 1)
396+
@named F2 = FirstOrder(k = 1, T = 1)
397+
@named add = Blocks.Add(k1 = 1, k2 = 2)
398+
@named back = Feedback()
399+
400+
eqs = [connect(back.output.u, F1.input.u, F2.input.u)
401+
connect(F1.output, add.input1)
402+
connect(F2.output, add.input2)
403+
connect(add.output, back.input2)]
404+
@named inner = ODESystem(eqs, t; systems = [F1, F2, add, back])
405+
406+
@named step = Step()
407+
eqs2 = [connect(step.output, inner.back.input1)
408+
connect(inner.back.output.u, :ap, inner.F1.input.u)]
409+
@named sys = ODESystem(eqs2, t; systems = [inner, step])
410+
411+
prob = ODEProblem(structural_simplify(sys), [], (0.0, 10.0))
412+
@test SciMLBase.successful_retcode(solve(prob, Rodas5P()))
413+
414+
matrices, _ = get_sensitivity(sys, sys.ap)
415+
@test matrices == matrices_normal
416+
end
417+
418+
@testset "Analysis point overriding part of connection - mixed connect" begin
419+
@named F1 = FirstOrder(k = 1, T = 1)
420+
@named F2 = FirstOrder(k = 1, T = 1)
421+
@named add = Blocks.Add(k1 = 1, k2 = 2)
422+
@named back = Feedback()
423+
424+
eqs = [connect(back.output, F1.input, F2.input)
425+
connect(F1.output, add.input1)
426+
connect(F2.output, add.input2)
427+
connect(add.output, back.input2)]
428+
@named inner = ODESystem(eqs, t; systems = [F1, F2, add, back])
429+
430+
@named step = Step()
431+
eqs2 = [connect(step.output, inner.back.input1)
432+
connect(inner.back.output.u, :ap, inner.F1.input.u)]
433+
@named sys = ODESystem(eqs2, t; systems = [inner, step])
434+
435+
prob = ODEProblem(structural_simplify(sys), [], (0.0, 10.0))
436+
@test SciMLBase.successful_retcode(solve(prob, Rodas5P()))
437+
438+
matrices, _ = get_sensitivity(sys, sys.ap)
439+
@test matrices == matrices_normal
440+
end

0 commit comments

Comments
 (0)