114
114
@test sol[inductor. i][end ] ≈ 10 atol= 1e-3
115
115
end
116
116
117
+ @testset " RC with voltage sources" begin
118
+ R, C = 1 , 1
119
+ @named voltage = Voltage ()
120
+ @named source_const = Constant (k= 10 )
121
+ @named source_sin = Sine (offset= 1 , amplitude= 10 , frequency= 2 , start_time= 0.5 , phase= 0 )
122
+ @named source_step = Step (offset= 1 , height= 10 , start_time= 0.5 )
123
+ @named source_tri = Triangular (offset= 1 , start_time= 0.5 , amplitude= 10 , frequency= 2 )
124
+ @named source_dsin = ExpSine (offset= 1 , amplitude= 10 , frequency= 2 , start_time= 0.5 , phase= 0 , damping= 0.5 )
125
+ @named source_ramp = Ramp (offset= 1 , height= 10 , start_time= 0.5 , duration= 1 )
126
+ sources = [source_const, source_sin, source_step, source_tri, source_dsin, source_ramp]
127
+
128
+ @named resistor = Resistor (; R)
129
+ @named capacitor = Capacitor (; C)
130
+ @named ground = Ground ()
131
+
132
+ for source in sources
133
+ connections = [
134
+ connect (source. output, voltage. V)
135
+ connect (voltage. p, resistor. p)
136
+ connect (resistor. n, capacitor. p)
137
+ connect (capacitor. n, voltage. n, ground. g)
138
+ ]
139
+
140
+ @named model = ODESystem (connections, t; systems= [resistor, capacitor, source, ground, voltage])
141
+ sys = structural_simplify (model)
142
+ prob = ODAEProblem (sys, [capacitor. v => 10.0 ], (0.0 , 10.0 ))
143
+ @test_nowarn sol = solve (prob, Rodas5 ())
144
+ @test_nowarn sol = solve (prob, Tsit5 ())
145
+
146
+ # Plots.plot(sol; vars=[voltage.v, capacitor.v])
147
+ end
148
+ end
149
+
150
+
117
151
# RC with current sources
118
152
@testset " RC with current sources" begin
119
153
start_time = 2
139
173
140
174
end
141
175
142
- # TODO : Once the Square() is back fix & re-enable this test
143
176
@testset " Integrator" begin
144
177
R= 1e3
145
178
f= 1
@@ -230,8 +263,8 @@ _damped_sine_wave(x, f, A, st, ϕ, d) = exp((st-x)*d)*A*sin(2*π*f*(x-st) + ϕ)
230
263
@test sol[voltage. V. u] ≈ waveforms (i, sol. t) atol= 1e-1
231
264
@test sol[voltage. p. v] ≈ sol[voltage. V. u]
232
265
# For visual inspection
233
- # plt = plot(sol; vars=[vsource .v])
234
- # savefig(plt, "test_voltage_$(Symbolics.getname(vsource) )")
266
+ # plt = plot(sol; vars=[voltage .v])
267
+ # savefig(plt, "test_voltage_$(source.name )")
235
268
end
236
269
end
237
270
284
317
@test sol[current. I. u] ≈ sol[current. p. i] atol= 1e-1
285
318
# For visual inspection
286
319
# plt = plot(sol)
287
- # savefig(plt, "test_current_$(Symbolics.getname(isource) )")
320
+ # savefig(plt, "test_current_$(source.name )")
288
321
end
289
322
end
0 commit comments