From bb001cb81d0e1905a47b1848a2b76c67d4630c7f Mon Sep 17 00:00:00 2001 From: Sathvik Bhagavan Date: Mon, 14 Aug 2023 08:08:12 +0000 Subject: [PATCH 1/2] test(Electrical): add test for `ChuaDiode` --- test/Electrical/analog.jl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/Electrical/analog.jl b/test/Electrical/analog.jl index 35fce60d5..bd7190d3a 100644 --- a/test/Electrical/analog.jl +++ b/test/Electrical/analog.jl @@ -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 From 7a3e09d25a564cebb32cf3d6dfd086e31ec0718e Mon Sep 17 00:00:00 2001 From: Sathvik Bhagavan Date: Mon, 14 Aug 2023 08:09:34 +0000 Subject: [PATCH 2/2] feat(Electrical): add `ChuaDiode` as a `@mtkmodel` --- src/Electrical/Analog/ideal_components.jl | 40 +++++++++++++++++++++++ src/Electrical/Electrical.jl | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Electrical/Analog/ideal_components.jl b/src/Electrical/Analog/ideal_components.jl index 82a787e90..b1ad4a9e7 100644 --- a/src/Electrical/Analog/ideal_components.jl +++ b/src/Electrical/Analog/ideal_components.jl @@ -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 diff --git a/src/Electrical/Electrical.jl b/src/Electrical/Electrical.jl index 687f92b20..e32248d64 100644 --- a/src/Electrical/Electrical.jl +++ b/src/Electrical/Electrical.jl @@ -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