-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from ValentinKaisermayer/fix-chua-demo
fixes demo and add it to tests
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using ModelingToolkit | ||
using ModelingToolkitStandardLibrary.Electrical | ||
using ModelingToolkitStandardLibrary.Electrical: OnePort | ||
using OrdinaryDiffEq | ||
using IfElse: ifelse | ||
|
||
@testset "Chua Circuit" begin | ||
@parameters t | ||
|
||
function NonlinearResistor(; name, Ga, Gb, Ve) | ||
@named oneport = OnePort() | ||
@unpack v, i = oneport | ||
pars = @parameters Ga=Ga Gb=Gb Ve=Ve | ||
eqs = [ | ||
i ~ ifelse(v < -Ve, | ||
Gb * (v + Ve) - Ga * Ve, | ||
ifelse(v > Ve, | ||
Gb * (v - Ve) + Ga * Ve, | ||
Ga * v)), | ||
] | ||
extend(ODESystem(eqs, t, [], pars; name = name), oneport) | ||
end | ||
|
||
@named L = Inductor(L = 18) | ||
@named Ro = Resistor(R = 12.5e-3) | ||
@named G = Conductor(G = 0.565) | ||
@named C1 = Capacitor(C = 10, v_start = 4) | ||
@named C2 = Capacitor(C = 100) | ||
@named Nr = NonlinearResistor(Ga = -0.757576, | ||
Gb = -0.409091, | ||
Ve = 1) | ||
@named Gnd = Ground() | ||
|
||
connections = [connect(L.p, G.p) | ||
connect(G.n, Nr.p) | ||
connect(Nr.n, Gnd.g) | ||
connect(C1.p, G.n) | ||
connect(L.n, Ro.p) | ||
connect(G.p, C2.p) | ||
connect(C1.n, Gnd.g) | ||
connect(C2.n, Gnd.g) | ||
connect(Ro.n, Gnd.g)] | ||
|
||
@named model = ODESystem(connections, t, systems = [L, Ro, G, C1, C2, Nr, Gnd]) | ||
sys = structural_simplify(model) | ||
prob = ODEProblem(sys, Pair[], (0, 5e4), saveat = 0.01) | ||
sol = solve(prob, Rodas4()) | ||
|
||
@test sol.retcode == :Success | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters