Skip to content

Commit 9f1cbb3

Browse files
committed
Add test
1 parent f8b596c commit 9f1cbb3

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

test/odaeproblem.jl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using ModelingToolkit, ModelingToolkitStandardLibrary, Test
2+
using OrdinaryDiffEq
3+
using ModelingToolkitStandardLibrary.Electrical
4+
using ModelingToolkitStandardLibrary.Blocks
5+
6+
function Segment(; name)
7+
@named R = Resistor(; R = 1)
8+
@named r = Resistor(; R = 1)
9+
@named C = Capacitor(; C = 1)
10+
11+
@named p1 = Pin() # top-left
12+
@named p2 = Pin() # top-right
13+
@named n = Pin() # bottom
14+
15+
eqs = [connect(p1, R.p)
16+
connect(R.n, p2, r.p)
17+
connect(r.n, C.p)
18+
connect(C.n, n)]
19+
20+
return ODESystem(eqs, t, [], [];
21+
name = name,
22+
systems = [r, R, C, n, p1, p2])
23+
end
24+
25+
function Strip(; name)
26+
num_segments = 10
27+
# construct `num_segments` segments
28+
segments = [Segment(; name = Symbol(:St_, seg))
29+
for seg in 1:num_segments]
30+
31+
@named p1 = Pin() # top-left
32+
@named p2 = Pin() # top-right
33+
@named n = Pin() # bottom
34+
35+
eqs = [connect(p1, segments[1].p1)
36+
connect(p2, segments[end].p2)
37+
[connect(n, seg.n) for seg in segments]...
38+
[connect(segments[i].p2, segments[i + 1].p1) for i in 1:(num_segments - 1)]...]
39+
40+
return ODESystem(eqs, t, [], []; name,
41+
systems = [p1, p2, n, segments...])
42+
end
43+
44+
@variables t
45+
@named source = Voltage()
46+
@named c = Constant(k = 0.01)
47+
48+
@named ground = Ground()
49+
@named strip = Strip()
50+
51+
rc_eqs = [connect(c.output, source.V)
52+
connect(source.p, strip.p1, strip.p2)
53+
connect(strip.n, source.n, ground.g)]
54+
55+
@named rc_model = ODESystem(rc_eqs, t, systems = [strip, c, source, ground])
56+
sys = structural_simplify(rc_model)
57+
58+
prob = ODAEProblem(sys, [], (0, 10))
59+
@test_nowarn solve(prob, Tsit5())

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ using SafeTestsets, Test
2323
@safetestset "JumpSystem Test" begin include("jumpsystem.jl") end
2424
@safetestset "Constraints Test" begin include("constraints.jl") end
2525
@safetestset "Reduction Test" begin include("reduction.jl") end
26+
@safetestset "ODAEProblem Test" begin include("odaeproblem.jl") end
2627
@safetestset "Components Test" begin include("components.jl") end
2728
@safetestset "print_tree" begin include("print_tree.jl") end
2829
@safetestset "Error Handling" begin include("error_handling.jl") end

0 commit comments

Comments
 (0)