Analog.Examples.ParallelResonance
ParallelResonance models two parallel RLC resonance circuits, each driven by a current source with variable frequency and amplitude.
This component simulates two independent parallel RLC circuits. The first circuit is driven by a sinusoidal current source, and the second by a cosinusoidal current source. The frequency of both current sources is controlled by a common ramp signal, causing a frequency sweep. The amplitude of both current sources is determined by a common constant signal. Each RLC circuit consists of a resistor, an inductor, and a capacitor connected in parallel with the current source and a voltage sensor. The ground components provide a common reference potential.
Usage
ElectricalComponents.Analog.Examples.ParallelResonance()
Behavior
using ElectricalComponents #hide
using ModelingToolkit #hide
@named sys = ElectricalComponents.Analog.Examples.ParallelResonance() #hide
full_equations(sys) #hide<< @example-block not executed in draft mode >>Source
"""
`ParallelResonance` models two parallel RLC resonance circuits, each driven by a current source with variable frequency and amplitude.
This component simulates two independent parallel RLC circuits. The first circuit is driven by a sinusoidal current source,
and the second by a cosinusoidal current source. The frequency of both current sources is controlled by a common ramp signal,
causing a frequency sweep. The amplitude of both current sources is determined by a common constant signal.
Each RLC circuit consists of a resistor, an inductor, and a capacitor connected in parallel with the current source
and a voltage sensor. The ground components provide a common reference potential.
"""
example component ParallelResonance
"First RLC circuit's ideal current source for the first RLC circuit."
current_source1 = ElectricalComponents.Analog.Sources.CurrentSource() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 50, "y1": 50, "x2": 150, "y2": 150, "rot": 270},
"diagram": {"iconName": "default", "x1": 250, "y1": 210, "x2": 350, "y2": 310, "rot": 270}
},
"tags": []
}
}
"First RLC circuit's ground reference for the first RLC circuit."
ground1 = ElectricalComponents.Analog.Basic.Ground() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 50, "y1": 200, "x2": 150, "y2": 300, "rot": 0},
"diagram": {"iconName": "default", "x1": 160, "y1": 360, "x2": 260, "y2": 460, "rot": 0}
},
"tags": []
}
}
"First RLC circuit's resistor in the first parallel RLC circuit."
resistor1 = ElectricalComponents.Analog.Basic.Resistor(R = 0.5) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 200, "y1": 50, "x2": 300, "y2": 150, "rot": 90},
"diagram": {"iconName": "default", "x1": 400, "y1": 210, "x2": 500, "y2": 310, "rot": 90}
},
"tags": []
}
}
"First RLC circuit's inductor in the first parallel RLC circuit."
inductor1 = ElectricalComponents.Analog.Basic.Inductor(L = 0.1 / (2 * pi)) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 350, "y1": 50, "x2": 450, "y2": 150, "rot": 90},
"diagram": {"iconName": "default", "x1": 550, "y1": 210, "x2": 650, "y2": 310, "rot": 90}
},
"tags": []
}
}
"First RLC circuit's capacitor in the first parallel RLC circuit."
capacitor1 = ElectricalComponents.Analog.Basic.Capacitor(C = 0.001 / (2 * pi)) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 500, "y1": 50, "x2": 600, "y2": 150, "rot": 90},
"diagram": {"iconName": "default", "x1": 700, "y1": 210, "x2": 800, "y2": 310, "rot": 90}
},
"tags": []
}
}
"First RLC circuit's voltage sensor across the first RLC circuit."
voltage_sensor1 = ElectricalComponents.Analog.Sensors.VoltageSensor() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 650, "y1": 50, "x2": 750, "y2": 150, "rot": 90},
"diagram": {"iconName": "default", "x1": 850, "y1": 210, "x2": 950, "y2": 310, "rot": 90}
},
"tags": []
}
}
"Generates a sine wave with variable frequency and amplitude for the first current source."
input_signal1 = BlockComponents.Sources.SineVariableFrequencyAndAmplitude() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": -100, "y1": 50, "x2": 0, "y2": 150, "rot": 0},
"diagram": {"iconName": "default", "x1": 100, "y1": 310, "x2": 200, "y2": 210, "rot": 0}
},
"tags": []
}
}
"Generates a cosine wave with variable frequency and amplitude for the second current source."
input_signal2 = BlockComponents.Sources.CosineVariableFrequencyAndAmplitude() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": -100, "y1": 350, "x2": 0, "y2": 450, "rot": 0},
"diagram": {"iconName": "default", "x1": 100, "y1": 510, "x2": 200, "y2": 610, "rot": 0}
},
"tags": []
}
}
"Generates a ramp signal to control the frequency of the input signals."
ramp = BlockComponents.Sources.Ramp(start_time = 0, duration = 1, offset = 0, height = 200) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": -300, "y1": 125, "x2": -200, "y2": 225, "rot": 0},
"diagram": {"iconName": "default", "x1": -100, "y1": 290, "x2": 0, "y2": 390, "rot": 0}
},
"tags": []
}
}
"Generates a constant signal to control the amplitude of the input signals."
const_signal = BlockComponents.Sources.Constant(k = 1) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": -300, "y1": 275, "x2": -200, "y2": 375, "rot": 0},
"diagram": {"iconName": "default", "x1": -100, "y1": 440, "x2": 0, "y2": 540, "rot": 0}
},
"tags": []
}
}
"Second RLC circuit's ideal current source for the second RLC circuit (cosine wave)."
current_source2 = ElectricalComponents.Analog.Sources.CurrentSource() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 50, "y1": 350, "x2": 150, "y2": 450, "rot": 270},
"diagram": {"iconName": "default", "x1": 250, "y1": 510, "x2": 350, "y2": 610, "rot": 270}
},
"tags": []
}
}
"Second RLC circuit's ground reference for the second RLC circuit."
ground2 = ElectricalComponents.Analog.Basic.Ground() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 50, "y1": 500, "x2": 150, "y2": 600, "rot": 0},
"diagram": {"iconName": "default", "x1": 250, "y1": 680, "x2": 350, "y2": 780, "rot": 0}
},
"tags": []
}
}
"Second RLC circuit's resistor in the second parallel RLC circuit."
resistor2 = ElectricalComponents.Analog.Basic.Resistor(R = 0.5) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 200, "y1": 350, "x2": 300, "y2": 450, "rot": 90},
"diagram": {"iconName": "default", "x1": 400, "y1": 510, "x2": 500, "y2": 610, "rot": 90}
},
"tags": []
}
}
"Second RLC circuit's inductor in the second parallel RLC circuit."
inductor2 = ElectricalComponents.Analog.Basic.Inductor(L = 0.1 / (2 * pi)) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 350, "y1": 350, "x2": 450, "y2": 450, "rot": 90},
"diagram": {"iconName": "default", "x1": 550, "y1": 510, "x2": 650, "y2": 610, "rot": 90}
},
"tags": []
}
}
"Second RLC circuit's capacitor in the second parallel RLC circuit."
capacitor2 = ElectricalComponents.Analog.Basic.Capacitor(C = 0.001 / (2 * pi)) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 500, "y1": 350, "x2": 600, "y2": 450, "rot": 90},
"diagram": {"iconName": "default", "x1": 700, "y1": 510, "x2": 800, "y2": 610, "rot": 90}
},
"tags": []
}
}
"Second RLC circuit's voltage sensor across the second RLC circuit."
voltage_sensor2 = ElectricalComponents.Analog.Sensors.VoltageSensor() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 650, "y1": 350, "x2": 750, "y2": 450, "rot": 90},
"diagram": {"iconName": "default", "x1": 850, "y1": 510, "x2": 950, "y2": 610, "rot": 90}
},
"tags": []
}
}
relations
initial inductor1.i = 0
initial inductor2.i = 0
initial capacitor1.v = 0
initial capacitor2.v = 0
connect(ramp.y, input_signal1.frequency, input_signal2.frequency) {
"Dyad": {
"edges": [
{"S": -1, "M": [], "E": 1},
{"S": -1, "M": [{"x": 60, "y": 237}], "E": 2},
{"S": -1, "M": [{"x": 60, "y": 583}], "E": 3}
],
"junctions": [{"x": 60, "y": 340}],
"renderStyle": "standard"
}
}
connect(const_signal.y, input_signal1.amplitude, input_signal2.amplitude) {
"Dyad": {
"edges": [
{"S": -1, "M": [], "E": 1},
{"S": -1, "M": [{"x": 80, "y": 288}], "E": 2},
{"S": -1, "M": [{"x": 80, "y": 534}], "E": 3}
],
"junctions": [{"x": 80, "y": 490}],
"renderStyle": "standard"
}
}
connect(input_signal1.y, current_source1.I) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(input_signal2.y, current_source2.I) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(current_source1.n, resistor1.p, inductor1.p, capacitor1.p, voltage_sensor1.p) {
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 300, "y": 90}], "E": -1},
{"S": -1, "M": [], "E": 2},
{"S": -1, "M": [{"x": 600, "y": 90}], "E": 3},
{"S": -1, "M": [{"x": 750, "y": 90}], "E": 4},
{"S": -1, "M": [{"x": 900, "y": 90}], "E": 5}
],
"junctions": [{"x": 450, "y": 90}],
"renderStyle": "standard"
}
}
connect(ground1.g, current_source1.p, resistor1.n, inductor1.n, capacitor1.n, voltage_sensor1.n) {
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 210, "y": 340}, {"x": 300, "y": 340}], "E": -1},
{"S": 2, "M": [], "E": -1},
{"S": -1, "M": [{"x": 300, "y": 340}, {"x": 450, "y": 340}], "E": 3},
{"S": -1, "M": [{"x": 300, "y": 340}, {"x": 600, "y": 340}], "E": 4},
{"S": -1, "M": [{"x": 300, "y": 340}, {"x": 750, "y": 340}], "E": 5},
{"S": -1, "M": [{"x": 300, "y": 340}, {"x": 900, "y": 340}], "E": 6}
],
"junctions": [{"x": 300, "y": 320}],
"renderStyle": "standard"
}
}
connect(current_source2.n, resistor2.p, inductor2.p, capacitor2.p, voltage_sensor2.p) {
"Dyad": {
"edges": [
{"S": -1, "M": [{"x": 300, "y": 350}], "E": 1},
{"S": -1, "M": [], "E": 2},
{"S": -1, "M": [{"x": 600, "y": 350}], "E": 3},
{"S": -1, "M": [{"x": 750, "y": 350}], "E": 4},
{"S": -1, "M": [{"x": 900, "y": 350}], "E": 5}
],
"junctions": [{"x": 450, "y": 350}],
"renderStyle": "standard"
}
}
connect(ground2.g, current_source2.p, resistor2.n, inductor2.n, capacitor2.n, voltage_sensor2.n) {
"Dyad": {
"edges": [
{"S": -1, "M": [{"x": 300, "y": 650}], "E": 1},
{"S": -1, "M": [{"x": 300, "y": 650}], "E": 2},
{"S": -1, "M": [], "E": 3},
{"S": -1, "M": [{"x": 600, "y": 650}], "E": 4},
{"S": -1, "M": [{"x": 750, "y": 650}], "E": 5},
{"S": -1, "M": [{"x": 900, "y": 650}], "E": 6}
],
"junctions": [{"x": 450, "y": 650}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://ElectricalComponents/Example.svg"},
"tests": {
"case1": {"stop": 1, "expect": {"signals": ["voltage_sensor1.v", "voltage_sensor2.v"]}}
}
}
}
endFlattened Source
"""
`ParallelResonance` models two parallel RLC resonance circuits, each driven by a current source with variable frequency and amplitude.
This component simulates two independent parallel RLC circuits. The first circuit is driven by a sinusoidal current source,
and the second by a cosinusoidal current source. The frequency of both current sources is controlled by a common ramp signal,
causing a frequency sweep. The amplitude of both current sources is determined by a common constant signal.
Each RLC circuit consists of a resistor, an inductor, and a capacitor connected in parallel with the current source
and a voltage sensor. The ground components provide a common reference potential.
"""
example component ParallelResonance
"First RLC circuit's ideal current source for the first RLC circuit."
current_source1 = ElectricalComponents.Analog.Sources.CurrentSource() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 50, "y1": 50, "x2": 150, "y2": 150, "rot": 270},
"diagram": {"iconName": "default", "x1": 250, "y1": 210, "x2": 350, "y2": 310, "rot": 270}
},
"tags": []
}
}
"First RLC circuit's ground reference for the first RLC circuit."
ground1 = ElectricalComponents.Analog.Basic.Ground() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 50, "y1": 200, "x2": 150, "y2": 300, "rot": 0},
"diagram": {"iconName": "default", "x1": 160, "y1": 360, "x2": 260, "y2": 460, "rot": 0}
},
"tags": []
}
}
"First RLC circuit's resistor in the first parallel RLC circuit."
resistor1 = ElectricalComponents.Analog.Basic.Resistor(R = 0.5) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 200, "y1": 50, "x2": 300, "y2": 150, "rot": 90},
"diagram": {"iconName": "default", "x1": 400, "y1": 210, "x2": 500, "y2": 310, "rot": 90}
},
"tags": []
}
}
"First RLC circuit's inductor in the first parallel RLC circuit."
inductor1 = ElectricalComponents.Analog.Basic.Inductor(L = 0.1 / (2 * pi)) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 350, "y1": 50, "x2": 450, "y2": 150, "rot": 90},
"diagram": {"iconName": "default", "x1": 550, "y1": 210, "x2": 650, "y2": 310, "rot": 90}
},
"tags": []
}
}
"First RLC circuit's capacitor in the first parallel RLC circuit."
capacitor1 = ElectricalComponents.Analog.Basic.Capacitor(C = 0.001 / (2 * pi)) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 500, "y1": 50, "x2": 600, "y2": 150, "rot": 90},
"diagram": {"iconName": "default", "x1": 700, "y1": 210, "x2": 800, "y2": 310, "rot": 90}
},
"tags": []
}
}
"First RLC circuit's voltage sensor across the first RLC circuit."
voltage_sensor1 = ElectricalComponents.Analog.Sensors.VoltageSensor() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 650, "y1": 50, "x2": 750, "y2": 150, "rot": 90},
"diagram": {"iconName": "default", "x1": 850, "y1": 210, "x2": 950, "y2": 310, "rot": 90}
},
"tags": []
}
}
"Generates a sine wave with variable frequency and amplitude for the first current source."
input_signal1 = BlockComponents.Sources.SineVariableFrequencyAndAmplitude() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": -100, "y1": 50, "x2": 0, "y2": 150, "rot": 0},
"diagram": {"iconName": "default", "x1": 100, "y1": 310, "x2": 200, "y2": 210, "rot": 0}
},
"tags": []
}
}
"Generates a cosine wave with variable frequency and amplitude for the second current source."
input_signal2 = BlockComponents.Sources.CosineVariableFrequencyAndAmplitude() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": -100, "y1": 350, "x2": 0, "y2": 450, "rot": 0},
"diagram": {"iconName": "default", "x1": 100, "y1": 510, "x2": 200, "y2": 610, "rot": 0}
},
"tags": []
}
}
"Generates a ramp signal to control the frequency of the input signals."
ramp = BlockComponents.Sources.Ramp(start_time = 0, duration = 1, offset = 0, height = 200) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": -300, "y1": 125, "x2": -200, "y2": 225, "rot": 0},
"diagram": {"iconName": "default", "x1": -100, "y1": 290, "x2": 0, "y2": 390, "rot": 0}
},
"tags": []
}
}
"Generates a constant signal to control the amplitude of the input signals."
const_signal = BlockComponents.Sources.Constant(k = 1) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": -300, "y1": 275, "x2": -200, "y2": 375, "rot": 0},
"diagram": {"iconName": "default", "x1": -100, "y1": 440, "x2": 0, "y2": 540, "rot": 0}
},
"tags": []
}
}
"Second RLC circuit's ideal current source for the second RLC circuit (cosine wave)."
current_source2 = ElectricalComponents.Analog.Sources.CurrentSource() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 50, "y1": 350, "x2": 150, "y2": 450, "rot": 270},
"diagram": {"iconName": "default", "x1": 250, "y1": 510, "x2": 350, "y2": 610, "rot": 270}
},
"tags": []
}
}
"Second RLC circuit's ground reference for the second RLC circuit."
ground2 = ElectricalComponents.Analog.Basic.Ground() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 50, "y1": 500, "x2": 150, "y2": 600, "rot": 0},
"diagram": {"iconName": "default", "x1": 250, "y1": 680, "x2": 350, "y2": 780, "rot": 0}
},
"tags": []
}
}
"Second RLC circuit's resistor in the second parallel RLC circuit."
resistor2 = ElectricalComponents.Analog.Basic.Resistor(R = 0.5) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 200, "y1": 350, "x2": 300, "y2": 450, "rot": 90},
"diagram": {"iconName": "default", "x1": 400, "y1": 510, "x2": 500, "y2": 610, "rot": 90}
},
"tags": []
}
}
"Second RLC circuit's inductor in the second parallel RLC circuit."
inductor2 = ElectricalComponents.Analog.Basic.Inductor(L = 0.1 / (2 * pi)) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 350, "y1": 350, "x2": 450, "y2": 450, "rot": 90},
"diagram": {"iconName": "default", "x1": 550, "y1": 510, "x2": 650, "y2": 610, "rot": 90}
},
"tags": []
}
}
"Second RLC circuit's capacitor in the second parallel RLC circuit."
capacitor2 = ElectricalComponents.Analog.Basic.Capacitor(C = 0.001 / (2 * pi)) {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 500, "y1": 350, "x2": 600, "y2": 450, "rot": 90},
"diagram": {"iconName": "default", "x1": 700, "y1": 510, "x2": 800, "y2": 610, "rot": 90}
},
"tags": []
}
}
"Second RLC circuit's voltage sensor across the second RLC circuit."
voltage_sensor2 = ElectricalComponents.Analog.Sensors.VoltageSensor() {
"Dyad": {
"placement": {
"icon": {"iconName": "default", "x1": 650, "y1": 350, "x2": 750, "y2": 450, "rot": 90},
"diagram": {"iconName": "default", "x1": 850, "y1": 510, "x2": 950, "y2": 610, "rot": 90}
},
"tags": []
}
}
relations
initial inductor1.i = 0
initial inductor2.i = 0
initial capacitor1.v = 0
initial capacitor2.v = 0
connect(ramp.y, input_signal1.frequency, input_signal2.frequency) {
"Dyad": {
"edges": [
{"S": -1, "M": [], "E": 1},
{"S": -1, "M": [{"x": 60, "y": 237}], "E": 2},
{"S": -1, "M": [{"x": 60, "y": 583}], "E": 3}
],
"junctions": [{"x": 60, "y": 340}],
"renderStyle": "standard"
}
}
connect(const_signal.y, input_signal1.amplitude, input_signal2.amplitude) {
"Dyad": {
"edges": [
{"S": -1, "M": [], "E": 1},
{"S": -1, "M": [{"x": 80, "y": 288}], "E": 2},
{"S": -1, "M": [{"x": 80, "y": 534}], "E": 3}
],
"junctions": [{"x": 80, "y": 490}],
"renderStyle": "standard"
}
}
connect(input_signal1.y, current_source1.I) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(input_signal2.y, current_source2.I) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(current_source1.n, resistor1.p, inductor1.p, capacitor1.p, voltage_sensor1.p) {
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 300, "y": 90}], "E": -1},
{"S": -1, "M": [], "E": 2},
{"S": -1, "M": [{"x": 600, "y": 90}], "E": 3},
{"S": -1, "M": [{"x": 750, "y": 90}], "E": 4},
{"S": -1, "M": [{"x": 900, "y": 90}], "E": 5}
],
"junctions": [{"x": 450, "y": 90}],
"renderStyle": "standard"
}
}
connect(ground1.g, current_source1.p, resistor1.n, inductor1.n, capacitor1.n, voltage_sensor1.n) {
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 210, "y": 340}, {"x": 300, "y": 340}], "E": -1},
{"S": 2, "M": [], "E": -1},
{"S": -1, "M": [{"x": 300, "y": 340}, {"x": 450, "y": 340}], "E": 3},
{"S": -1, "M": [{"x": 300, "y": 340}, {"x": 600, "y": 340}], "E": 4},
{"S": -1, "M": [{"x": 300, "y": 340}, {"x": 750, "y": 340}], "E": 5},
{"S": -1, "M": [{"x": 300, "y": 340}, {"x": 900, "y": 340}], "E": 6}
],
"junctions": [{"x": 300, "y": 320}],
"renderStyle": "standard"
}
}
connect(current_source2.n, resistor2.p, inductor2.p, capacitor2.p, voltage_sensor2.p) {
"Dyad": {
"edges": [
{"S": -1, "M": [{"x": 300, "y": 350}], "E": 1},
{"S": -1, "M": [], "E": 2},
{"S": -1, "M": [{"x": 600, "y": 350}], "E": 3},
{"S": -1, "M": [{"x": 750, "y": 350}], "E": 4},
{"S": -1, "M": [{"x": 900, "y": 350}], "E": 5}
],
"junctions": [{"x": 450, "y": 350}],
"renderStyle": "standard"
}
}
connect(ground2.g, current_source2.p, resistor2.n, inductor2.n, capacitor2.n, voltage_sensor2.n) {
"Dyad": {
"edges": [
{"S": -1, "M": [{"x": 300, "y": 650}], "E": 1},
{"S": -1, "M": [{"x": 300, "y": 650}], "E": 2},
{"S": -1, "M": [], "E": 3},
{"S": -1, "M": [{"x": 600, "y": 650}], "E": 4},
{"S": -1, "M": [{"x": 750, "y": 650}], "E": 5},
{"S": -1, "M": [{"x": 900, "y": 650}], "E": 6}
],
"junctions": [{"x": 450, "y": 650}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://ElectricalComponents/Example.svg"},
"tests": {
"case1": {"stop": 1, "expect": {"signals": ["voltage_sensor1.v", "voltage_sensor2.v"]}}
}
}
}
endTest Cases
using ElectricalComponents
using DyadInterface: TransientAnalysis, rebuild_sol, ODEAlg
using ModelingToolkit: toggle_namespacing, get_initial_conditions, @named
using CSV, DataFrames, Plots
snapshotsdir = joinpath(dirname(dirname(pathof(ElectricalComponents))), "test", "snapshots")<< @setup-block not executed in draft mode >>Test Case case1
@named model_case1 = ElectricalComponents.Analog.Examples.ParallelResonance()
model_case1 = toggle_namespacing(model_case1, false)
model_case1 = toggle_namespacing(model_case1, true)
result_case1 = TransientAnalysis(; model = model_case1, alg = ODEAlg.Auto(), start = 0e+0, stop = 1e+0, abstol=1e-6, reltol=1e-6)
sol_case1 = rebuild_sol(result_case1)<< @setup-block not executed in draft mode >>df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.voltage_sensor1.v])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "ElectricalComponents.Analog.Examples.ParallelResonance_case1_sig0.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.voltage_sensor1.v], width=2, label="Actual value of voltage_sensor1.v")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of voltage_sensor1.v")
end<< @setup-block not executed in draft mode >>plt<< @example-block not executed in draft mode >>df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.voltage_sensor2.v])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "ElectricalComponents.Analog.Examples.ParallelResonance_case1_sig1.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.voltage_sensor2.v], width=2, label="Actual value of voltage_sensor2.v")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of voltage_sensor2.v")
end<< @setup-block not executed in draft mode >>plt<< @example-block not executed in draft mode >>Related
Examples
Experiments
Analyses