Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes demo and add it to tests #100

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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