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