ChuaCircuit
Chua's circuit, an electronic circuit known for its chaotic dynamics.
This component represents Chua's circuit, a relatively simple electronic system capable of exhibiting complex nonlinear dynamics, including bifurcations and chaos. The circuit is constructed from two capacitors (capacitor1
, capacitor2
), one inductor (inductor
), a linear resistor (resistor
), a linear conductor (conductor
), and a single nonlinear element known as Chua's diode (represented by nonlinear_resistor
). The behavior of the circuit is typically described by a set of three first-order autonomous ordinary differential equations for the voltage across each capacitor and the current through the inductor.
The current i_NR
through the nonlinear_resistor
as a function of the voltage v_C1
across it is given by:
The governing differential equations for the circuit are (using v_C1
for capacitor1.v
, v_C2
for capacitor2.v
, i_L
for inductor.i
):
Initial conditions for capacitor1.v
, capacitor2.v
, and inductor.i
are specified within the relations
block to define the starting state of the simulation.
Usage
ChuaCircuit()
Behavior
Source
# Chua's circuit, an electronic circuit known for its chaotic dynamics.
#
# This component represents Chua's circuit, a relatively simple electronic system
# capable of exhibiting complex nonlinear dynamics, including bifurcations and
# chaos. The circuit is constructed from two capacitors (`capacitor1`, `capacitor2`),
# one inductor (`inductor`), a linear resistor (`resistor`), a linear conductor
# (`conductor`), and a single nonlinear element known as Chua's diode (represented
# by `nonlinear_resistor`). The behavior of the circuit is typically described by a
# set of three first-order autonomous ordinary differential equations for the
# voltage across each capacitor and the current through the inductor.
#
# The current `i_NR` through the `nonlinear_resistor` as a function of the voltage `v_C1` across it is given by:
# ```math
# i_{NR}(v_{C1}) = Gb \cdot v_{C1} + \frac{1}{2}(Ga - Gb)(|v_{C1} + Ve| - |v_{C1} - Ve|)
# ```
# The governing differential equations for the circuit are (using `v_C1` for `capacitor1.v`, `v_C2` for `capacitor2.v`, `i_L` for `inductor.i`):
# ```math
# capacitor1.C \cdot \frac{d(v_{C1})}{dt} = conductor.G \cdot (v_{C2} - v_{C1}) - i_{NR}(v_{C1})
# ```
# ```math
# capacitor2.C \cdot \frac{d(v_{C2})}{dt} = conductor.G \cdot (v_{C1} - v_{C2}) - i_L
# ```
# ```math
# inductor.L \cdot \frac{d(i_L)}{dt} = v_{C2} - resistor.R \cdot i_L
# ```
# Initial conditions for `capacitor1.v`, `capacitor2.v`, and `inductor.i` are
# specified within the `relations` block to define the starting state of the simulation.
component ChuaCircuit
# Inductor of the Chua's circuit.
inductor = Inductor(L=18) [{
"Dyad": {"placement": {"icon": {"x1": 0, "y1": 200, "x2": 200, "y2": 400, "rot": 90}}}
}]
# Linear resistor, typically in series with the inductor.
resistor = Resistor(R=12.5e-3) [{
"Dyad": {"placement": {"icon": {"x1": 0, "y1": 500, "x2": 200, "y2": 700, "rot": 90}}}
}]
# Linear conductor, connecting the two capacitors.
conductor = Conductor(G=0.565) [{
"Dyad": {"placement": {"icon": {"x1": 450, "y1": 50, "x2": 650, "y2": 250, "rot": 0}}}
}]
# First capacitor in the Chua's circuit.
capacitor1 = Capacitor(C=10) [{
"Dyad": {"placement": {"icon": {"x1": 600, "y1": 350, "x2": 800, "y2": 550, "rot": 90}}}
}]
# Second capacitor in the Chua's circuit.
capacitor2 = Capacitor(C=100) [{
"Dyad": {"placement": {"icon": {"x1": 300, "y1": 350, "x2": 500, "y2": 550, "rot": 90}}}
}]
# Nonlinear resistor representing the Chua's diode, with parameters Ga, Gb, Ve.
nonlinear_resistor = NonlinearResistor(Ga=-0.757576, Gb=-0.409091, Ve=1) [{
"Dyad": {
"placement": {"icon": {"x1": 900, "y1": 350, "x2": 1100, "y2": 550, "rot": 90}}
}
}]
# Ground reference for the circuit.
ground = Ground() [{
"Dyad": {"placement": {"icon": {"x1": 450, "y1": 800, "x2": 650, "y2": 1000, "rot": 0}}}
}]
relations
initial inductor.i = 0
initial capacitor1.v = 4
initial capacitor2.v = 0
connect(inductor.n, resistor.p) [{"Dyad": {"edges": [{"S": 1, "E": 2}]}}]
connect(inductor.p, capacitor2.p, conductor.p) [{
"Dyad": {
"edges": [
{"S": -1, "M": [{"x": 100, "y": 150}], "E": 1},
{"S": -1, "E": 2},
{"S": -1, "E": 3}
],
"junctions": [{"x": 400, "y": 150}]
}
}]
connect(conductor.n, nonlinear_resistor.p, capacitor1.p) [{
"Dyad": {
"edges": [
{"S": -1, "E": 1},
{"S": -1, "M": [{"x": 1000, "y": 150}], "E": 2},
{"S": -1, "E": 3}
],
"junctions": [{"x": 700, "y": 150}]
}
}]
connect(ground.g, resistor.n, capacitor2.n, capacitor1.n, nonlinear_resistor.n) [{
"Dyad": {
"edges": [
{"S": -1, "E": 1},
{"S": -1, "M": [{"x": 100, "y": 750}], "E": 2},
{"S": -1, "M": [{"x": 400, "y": 750}], "E": 3},
{"S": -1, "M": [{"x": 700, "y": 750}], "E": 4},
{"S": -1, "M": [{"x": 1000, "y": 750}], "E": 5}
],
"junctions": [{"x": 550, "y": 750}]
}
}]
metadata {
"Dyad": {"tests": {"case1": {"stop": 50000, "expect": {"signals": ["capacitor1.v"]}}}}
}
end
Flattened Source
# Chua's circuit, an electronic circuit known for its chaotic dynamics.
#
# This component represents Chua's circuit, a relatively simple electronic system
# capable of exhibiting complex nonlinear dynamics, including bifurcations and
# chaos. The circuit is constructed from two capacitors (`capacitor1`, `capacitor2`),
# one inductor (`inductor`), a linear resistor (`resistor`), a linear conductor
# (`conductor`), and a single nonlinear element known as Chua's diode (represented
# by `nonlinear_resistor`). The behavior of the circuit is typically described by a
# set of three first-order autonomous ordinary differential equations for the
# voltage across each capacitor and the current through the inductor.
#
# The current `i_NR` through the `nonlinear_resistor` as a function of the voltage `v_C1` across it is given by:
# ```math
# i_{NR}(v_{C1}) = Gb \cdot v_{C1} + \frac{1}{2}(Ga - Gb)(|v_{C1} + Ve| - |v_{C1} - Ve|)
# ```
# The governing differential equations for the circuit are (using `v_C1` for `capacitor1.v`, `v_C2` for `capacitor2.v`, `i_L` for `inductor.i`):
# ```math
# capacitor1.C \cdot \frac{d(v_{C1})}{dt} = conductor.G \cdot (v_{C2} - v_{C1}) - i_{NR}(v_{C1})
# ```
# ```math
# capacitor2.C \cdot \frac{d(v_{C2})}{dt} = conductor.G \cdot (v_{C1} - v_{C2}) - i_L
# ```
# ```math
# inductor.L \cdot \frac{d(i_L)}{dt} = v_{C2} - resistor.R \cdot i_L
# ```
# Initial conditions for `capacitor1.v`, `capacitor2.v`, and `inductor.i` are
# specified within the `relations` block to define the starting state of the simulation.
component ChuaCircuit
# Inductor of the Chua's circuit.
inductor = Inductor(L=18) [{
"Dyad": {"placement": {"icon": {"x1": 0, "y1": 200, "x2": 200, "y2": 400, "rot": 90}}}
}]
# Linear resistor, typically in series with the inductor.
resistor = Resistor(R=12.5e-3) [{
"Dyad": {"placement": {"icon": {"x1": 0, "y1": 500, "x2": 200, "y2": 700, "rot": 90}}}
}]
# Linear conductor, connecting the two capacitors.
conductor = Conductor(G=0.565) [{
"Dyad": {"placement": {"icon": {"x1": 450, "y1": 50, "x2": 650, "y2": 250, "rot": 0}}}
}]
# First capacitor in the Chua's circuit.
capacitor1 = Capacitor(C=10) [{
"Dyad": {"placement": {"icon": {"x1": 600, "y1": 350, "x2": 800, "y2": 550, "rot": 90}}}
}]
# Second capacitor in the Chua's circuit.
capacitor2 = Capacitor(C=100) [{
"Dyad": {"placement": {"icon": {"x1": 300, "y1": 350, "x2": 500, "y2": 550, "rot": 90}}}
}]
# Nonlinear resistor representing the Chua's diode, with parameters Ga, Gb, Ve.
nonlinear_resistor = NonlinearResistor(Ga=-0.757576, Gb=-0.409091, Ve=1) [{
"Dyad": {
"placement": {"icon": {"x1": 900, "y1": 350, "x2": 1100, "y2": 550, "rot": 90}}
}
}]
# Ground reference for the circuit.
ground = Ground() [{
"Dyad": {"placement": {"icon": {"x1": 450, "y1": 800, "x2": 650, "y2": 1000, "rot": 0}}}
}]
relations
initial inductor.i = 0
initial capacitor1.v = 4
initial capacitor2.v = 0
connect(inductor.n, resistor.p) [{"Dyad": {"edges": [{"S": 1, "E": 2}]}}]
connect(inductor.p, capacitor2.p, conductor.p) [{
"Dyad": {
"edges": [
{"S": -1, "M": [{"x": 100, "y": 150}], "E": 1},
{"S": -1, "E": 2},
{"S": -1, "E": 3}
],
"junctions": [{"x": 400, "y": 150}]
}
}]
connect(conductor.n, nonlinear_resistor.p, capacitor1.p) [{
"Dyad": {
"edges": [
{"S": -1, "E": 1},
{"S": -1, "M": [{"x": 1000, "y": 150}], "E": 2},
{"S": -1, "E": 3}
],
"junctions": [{"x": 700, "y": 150}]
}
}]
connect(ground.g, resistor.n, capacitor2.n, capacitor1.n, nonlinear_resistor.n) [{
"Dyad": {
"edges": [
{"S": -1, "E": 1},
{"S": -1, "M": [{"x": 100, "y": 750}], "E": 2},
{"S": -1, "M": [{"x": 400, "y": 750}], "E": 3},
{"S": -1, "M": [{"x": 700, "y": 750}], "E": 4},
{"S": -1, "M": [{"x": 1000, "y": 750}], "E": 5}
],
"junctions": [{"x": 550, "y": 750}]
}
}]
metadata {
"Dyad": {"tests": {"case1": {"stop": 50000, "expect": {"signals": ["capacitor1.v"]}}}}
}
end
Test Cases
This is setup code, that must be run before each test case.
using ElectricalComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames
snapshotsdir = joinpath(dirname(dirname(pathof(ElectricalComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/ElectricalComponents/bmmPM/test/snapshots"
Test Case case1
@mtkbuild model_case1 = ChuaCircuit()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 50000))
sol_case1 = solve(prob_case1)
retcode: Success
Interpolation: 3rd order Hermite
t: 1128-element Vector{Float64}:
0.0
0.04423672638045937
0.48660399018505307
2.8930230921363944
7.944031239665286
16.187636165693053
27.934748072301918
43.74567946594178
63.5067910558904
87.4672312779384
⋮
49663.59127020652
49711.62670707901
49754.99781818978
49799.07831070707
49847.34613112373
49895.74714713049
49945.04983915636
49992.28093566908
50000.0
u: 1128-element Vector{Vector{Float64}}:
[4.0, 0.0, 0.0]
[3.998784490548603, 0.0009994729504578044, 1.2282512295631295e-6]
[3.986812188656199, 0.010963702068493704, 0.00014832841649248778]
[3.927366761188868, 0.0641918911786249, 0.0051870515253210426]
[3.8317819891082547, 0.17048051959434382, 0.03821922923756848]
[3.7495648086573987, 0.32765720808396803, 0.1525604782220875]
[3.7556040922230345, 0.5149298585406376, 0.42763078453109205]
[3.9107042150101314, 0.6942912597730589, 0.9575417493695891]
[4.1953366900948845, 0.7944212052684384, 1.7689353111511885]
[4.462303293978727, 0.731470420315997, 2.7683020198995214]
⋮
[1.3832254000169768, -0.3609364678609031, 0.6052675931046779]
[1.445279117610356, -0.04664918945821552, 0.0037394441814346093]
[2.109770048354739, 0.30633476131425025, 0.32662709750791225]
[2.944821222090538, 0.4845750508301034, 1.3281980917576215]
[3.3806951721685308, 0.3209388393600531, 2.427318642790989]
[2.948819545644791, -0.10390473790580373, 2.656270185597289]
[1.9311930714390222, -0.45921447624775497, 1.7458004175601396]
[1.1765240412934448, -0.44093828670775403, 0.437911425112031]
[1.12379451618534, -0.3991542066745897, 0.255574024504258]
df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.capacitor1.v])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "ChuaCircuit_case1_sig0.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.capacitor1.v], width=2, label="Actual value of capacitor1.v")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of capacitor1.v")
end
plt
Related
Examples
Experiments
Analyses