Skip to content

Commit

Permalink
Merge pull request #100 from ValentinKaisermayer/fix-chua-demo
Browse files Browse the repository at this point in the history
fixes demo and add it to tests
  • Loading branch information
ChrisRackauckas authored Aug 19, 2022
2 parents 56eb837 + 94f9c38 commit 8f10ad5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/src/tutorials/custom_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ connections = [
connect(Ro.n, Gnd.g)
]
@named model = ODESystem(connections, t, systems=[L, Ro, G, C1, C2, Nr])
@named model = ODESystem(connections, t, systems=[L, Ro, G, C1, C2, Nr, Gnd])
nothing # hide
```

Expand Down
3 changes: 2 additions & 1 deletion test/Mechanical/rotational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ end
sine,
])
sys = structural_simplify(model)
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, [D(D(inertia2.phi)) => 1.0; D.(states(model)) .=> 0.0], (0, 10.0))
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0,
[D(D(inertia2.phi)) => 1.0; D.(states(model)) .=> 0.0], (0, 10.0))
sol = solve(prob, DFBDF())

# Plots.plot(sol; vars=[inertia1.w, -inertia2.w*2])
Expand Down
50 changes: 50 additions & 0 deletions test/chua_circuit.jl
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
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using SafeTestsets
@safetestset "Analog Circuits" begin include("Electrical/analog.jl") end
#@safetestset "Digital Circuits" begin include("Electrical/digital.jl") end
@safetestset "RC Circuit Demo" begin include("demo.jl") end
@safetestset "Chua Circuit Demo" begin include("chua_circuit.jl") end

# Thermal
@safetestset "Thermal Circuits" begin include("Thermal/thermal.jl") end
Expand Down

0 comments on commit 8f10ad5

Please sign in to comment.