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

Add ChuaDiode as a @mtkmodel #208

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions src/Electrical/Analog/ideal_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,43 @@ Electromotoric force (electric/mechanic transformer)
flange.tau ~ -k * i
end
end

"""
ChuaDiode(; name, Ga, Gb, Ve)

Chua's Diode

# States

See [OnePort](@ref)

# Connectors:

- `p` Positive pin
- `n` Negative pin

# Parameters:

- `Ga` : [`Ohm`] Negative of the slope of the V-I curve when v < -Ve and v > V
- `Gb` : [`Ohm`] Negative of the slope of the V-I curve when -Ve < v < Ve
- `Ve` : [`V`] Absolute value of voltage where the behaviour of the diode changes
"""
@mtkmodel ChuaDiode begin
@extend v, i = oneport = OnePort()
@parameters begin
Ga = 1.0,
[description = "Negative of the slope of the V-I curve when v < -Ve and v > Ve"]
Gb = 1.0, [description = "Negative of the slope of the V-I curve when -Ve < v < Ve"]
Ve = 1.0,
[
description = "Absolute value of voltage where the behaviour of the diode changes",
]
end
@equations begin
i ~ ifelse(v < -Ve,
Gb * (v + Ve) - Ga * Ve,
ifelse(v > Ve,
Gb * (v - Ve) + Ga * Ve,
Ga * v))
end
end
2 changes: 1 addition & 1 deletion src/Electrical/Electrical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ include("utils.jl")

export Capacitor,
Ground, Inductor, Resistor, Conductor, Short, IdealOpAmp, EMF,
HeatingResistor
HeatingResistor, ChuaDiode
include("Analog/ideal_components.jl")

export CurrentSensor, PotentialSensor, VoltageSensor, PowerSensor, MultiSensor
Expand Down
27 changes: 27 additions & 0 deletions test/Electrical/analog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,30 @@ end
# savefig(plt, "test_current_$(source.name)")
end
end

@testset "ChuaCircuit" begin
@parameters t
@named ChuaD = ChuaDiode(Ga = -0.757576, Gb = -0.409091, Ve = 1)
@named L = Inductor(L = 18, i = 0.0)
@named Ro = Resistor(R = 12.5e-3)
@named G = Conductor(G = 0.565)
@named C1 = Capacitor(C = 10, v = 4)
@named C2 = Capacitor(C = 100, v = 0.0)
@named Gnd = Ground()

connections = [connect(L.p, G.p)
connect(G.n, ChuaD.p)
connect(ChuaD.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, ChuaD, Gnd])
sys = structural_simplify(model)
prob = ODEProblem(sys, Pair[], (0, 5e4), saveat = 0.01)
sol = solve(prob, Rodas4())
@test sol.retcode == Success
end