Analog.Sensors.Tests.Sensors
A test circuit with a resistor and capacitor in series, driven by a sinusoidal voltage source, instrumented with voltage, current, and power sensors.
This component models an electrical R-C series circuit. A VoltageSource, whose voltage is determined by a Sine signal generator, drives a Resistor (R=1 Ohm) and a Capacitor (C=1 Farad) connected in series. The circuit is completed by a Ground component. Several sensors are included to monitor the circuit's behavior: a CurrentSensor measures the current flowing through the series R-C combination, a VoltageSensor measures the voltage across the Capacitor, and a PowerSensor measures the instantaneous power associated with the Capacitor. The sine wave generator (source) provides an input signal defined by
Usage
ElectricalComponents.Analog.Sensors.Tests.Sensors()
Behavior
Source
"""
A test circuit with a resistor and capacitor in series, driven by a sinusoidal voltage source, instrumented with voltage, current, and power sensors.
This component models an electrical R-C series circuit. A `VoltageSource`, whose
voltage is determined by a `Sine` signal generator, drives a `Resistor` (R=1 Ohm)
and a `Capacitor` (C=1 Farad) connected in series. The circuit is completed by a
`Ground` component. Several sensors are included to monitor the circuit's
behavior: a `CurrentSensor` measures the current flowing through the series R-C
combination, a `VoltageSensor` measures the voltage across the `Capacitor`, and
a `PowerSensor` measures the instantaneous power associated with the `Capacitor`.
The sine wave generator (`source`) provides an input signal defined by
$V(t) = \text{offset} + \text{amplitude} \cdot \sin(2 \pi \cdot \text{frequency} \cdot t)$,
where offset=1, amplitude=10, and frequency=5 Hz. The primary purpose is to
test the dynamic response of these sensor components in a simple circuit.
"""
test component Sensors
"Signal generator providing a sinusoidal voltage waveform."
source = BlockComponents.Sources.Sine(offset = 1, amplitude = 10, frequency = 5) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 30, "y1": 296, "x2": 130, "y2": 396, "rot": 0}
},
"tags": []
}
}
"Ideal voltage source whose output is controlled by the 'source' signal."
voltage = ElectricalComponents.Analog.Sources.VoltageSource() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 165, "y1": 401, "x2": 265, "y2": 501, "rot": 0}
},
"tags": []
}
}
"Electrical resistor with a fixed resistance value."
resistor = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 295, "y1": 626, "x2": 395, "y2": 726, "rot": 0}
},
"tags": []
}
}
"Electrical capacitor with a fixed capacitance value."
capacitor = ElectricalComponents.Analog.Basic.Capacitor(C = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 35, "y1": 176, "x2": 135, "y2": 276, "rot": 0}
},
"tags": []
}
}
"Electrical ground reference (0V)."
ground = ElectricalComponents.Analog.Basic.Ground() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 295, "y1": 506, "x2": 395, "y2": 606, "rot": 0}
},
"tags": []
}
}
"Sensor to measure voltage difference between its 'p' and 'n' terminals."
voltage_sensor = ElectricalComponents.Analog.Sensors.VoltageSensor() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 165, "y1": 71, "x2": 265, "y2": 171, "rot": 0}
},
"tags": []
}
}
"Sensor to measure current flowing through it from 'p' to 'n'."
current_sensor = ElectricalComponents.Analog.Sensors.CurrentSensor() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 425, "y1": 626, "x2": 525, "y2": 726, "rot": 0}
},
"tags": []
}
}
"Sensor to measure electrical power, based on voltage (pv, nv) and current (pc, nc) measurements."
power_sensor = ElectricalComponents.Analog.Sensors.PowerSensor() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 555, "y1": 626, "x2": 655, "y2": 726, "rot": 0}
},
"tags": []
}
}
relations
connect(source.y, voltage.V) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 215, "y": 346}], "E": 2}],
"renderStyle": "standard"
}
}
connect(voltage.p, resistor.p) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 150, "y": 451}, {"x": 150, "y": 676}], "E": 2}],
"renderStyle": "standard"
}
}
connect(resistor.n, current_sensor.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(current_sensor.n, power_sensor.pc) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(power_sensor.nc, capacitor.p) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [
{"x": 670, "y": 676},
{"x": 670, "y": 20},
{"x": 20, "y": 20},
{"x": 20, "y": 226}
],
"E": 2
}
],
"renderStyle": "standard"
}
}
connect(capacitor.n, voltage.n, ground.g) {
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 280, "y": 226}], "E": -1},
{"S": -1, "M": [], "E": 2},
{"S": -1, "M": [{"x": 345, "y": 451}], "E": 3}
],
"junctions": [{"x": 280, "y": 451}],
"renderStyle": "standard"
}
}
connect(capacitor.p, voltage_sensor.p, power_sensor.pv) {
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 20, "y": 226}, {"x": 20, "y": 20}], "E": -1},
{"S": -1, "M": [{"x": 150, "y": 121}], "E": 2},
{"S": -1, "M": [], "E": -2},
{"S": -2, "M": [{"x": 540, "y": 30}, {"x": 605, "y": 30}], "E": 3}
],
"junctions": [{"x": 150, "y": 20}, {"x": 540, "y": 20}],
"renderStyle": "standard"
}
}
connect(capacitor.n, voltage_sensor.n, power_sensor.nv) {
"Dyad": {
"edges": [
{"S": 1, "M": [], "E": -1},
{"S": -1, "M": [{"x": 280, "y": 121}], "E": 2},
{"S": -1, "M": [{"x": 280, "y": 781}, {"x": 605, "y": 781}], "E": 3}
],
"junctions": [{"x": 280, "y": 226}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://ElectricalComponents/Example.svg"},
"tests": {
"case1": {
"stop": 20,
"initial": {"capacitor.v": 10},
"expect": {
"final": {
"current_sensor.i": "0.31798707833424167",
"voltage_sensor.v": "0.6820129216657976",
"power_sensor.power": "0.21687129634670702"
}
}
}
}
}
}
endFlattened Source
"""
A test circuit with a resistor and capacitor in series, driven by a sinusoidal voltage source, instrumented with voltage, current, and power sensors.
This component models an electrical R-C series circuit. A `VoltageSource`, whose
voltage is determined by a `Sine` signal generator, drives a `Resistor` (R=1 Ohm)
and a `Capacitor` (C=1 Farad) connected in series. The circuit is completed by a
`Ground` component. Several sensors are included to monitor the circuit's
behavior: a `CurrentSensor` measures the current flowing through the series R-C
combination, a `VoltageSensor` measures the voltage across the `Capacitor`, and
a `PowerSensor` measures the instantaneous power associated with the `Capacitor`.
The sine wave generator (`source`) provides an input signal defined by
$V(t) = \text{offset} + \text{amplitude} \cdot \sin(2 \pi \cdot \text{frequency} \cdot t)$,
where offset=1, amplitude=10, and frequency=5 Hz. The primary purpose is to
test the dynamic response of these sensor components in a simple circuit.
"""
test component Sensors
"Signal generator providing a sinusoidal voltage waveform."
source = BlockComponents.Sources.Sine(offset = 1, amplitude = 10, frequency = 5) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 30, "y1": 296, "x2": 130, "y2": 396, "rot": 0}
},
"tags": []
}
}
"Ideal voltage source whose output is controlled by the 'source' signal."
voltage = ElectricalComponents.Analog.Sources.VoltageSource() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 165, "y1": 401, "x2": 265, "y2": 501, "rot": 0}
},
"tags": []
}
}
"Electrical resistor with a fixed resistance value."
resistor = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 295, "y1": 626, "x2": 395, "y2": 726, "rot": 0}
},
"tags": []
}
}
"Electrical capacitor with a fixed capacitance value."
capacitor = ElectricalComponents.Analog.Basic.Capacitor(C = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 35, "y1": 176, "x2": 135, "y2": 276, "rot": 0}
},
"tags": []
}
}
"Electrical ground reference (0V)."
ground = ElectricalComponents.Analog.Basic.Ground() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 295, "y1": 506, "x2": 395, "y2": 606, "rot": 0}
},
"tags": []
}
}
"Sensor to measure voltage difference between its 'p' and 'n' terminals."
voltage_sensor = ElectricalComponents.Analog.Sensors.VoltageSensor() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 165, "y1": 71, "x2": 265, "y2": 171, "rot": 0}
},
"tags": []
}
}
"Sensor to measure current flowing through it from 'p' to 'n'."
current_sensor = ElectricalComponents.Analog.Sensors.CurrentSensor() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 425, "y1": 626, "x2": 525, "y2": 726, "rot": 0}
},
"tags": []
}
}
"Sensor to measure electrical power, based on voltage (pv, nv) and current (pc, nc) measurements."
power_sensor = ElectricalComponents.Analog.Sensors.PowerSensor() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 555, "y1": 626, "x2": 655, "y2": 726, "rot": 0}
},
"tags": []
}
}
relations
connect(source.y, voltage.V) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 215, "y": 346}], "E": 2}],
"renderStyle": "standard"
}
}
connect(voltage.p, resistor.p) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 150, "y": 451}, {"x": 150, "y": 676}], "E": 2}],
"renderStyle": "standard"
}
}
connect(resistor.n, current_sensor.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(current_sensor.n, power_sensor.pc) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(power_sensor.nc, capacitor.p) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [
{"x": 670, "y": 676},
{"x": 670, "y": 20},
{"x": 20, "y": 20},
{"x": 20, "y": 226}
],
"E": 2
}
],
"renderStyle": "standard"
}
}
connect(capacitor.n, voltage.n, ground.g) {
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 280, "y": 226}], "E": -1},
{"S": -1, "M": [], "E": 2},
{"S": -1, "M": [{"x": 345, "y": 451}], "E": 3}
],
"junctions": [{"x": 280, "y": 451}],
"renderStyle": "standard"
}
}
connect(capacitor.p, voltage_sensor.p, power_sensor.pv) {
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 20, "y": 226}, {"x": 20, "y": 20}], "E": -1},
{"S": -1, "M": [{"x": 150, "y": 121}], "E": 2},
{"S": -1, "M": [], "E": -2},
{"S": -2, "M": [{"x": 540, "y": 30}, {"x": 605, "y": 30}], "E": 3}
],
"junctions": [{"x": 150, "y": 20}, {"x": 540, "y": 20}],
"renderStyle": "standard"
}
}
connect(capacitor.n, voltage_sensor.n, power_sensor.nv) {
"Dyad": {
"edges": [
{"S": 1, "M": [], "E": -1},
{"S": -1, "M": [{"x": 280, "y": 121}], "E": 2},
{"S": -1, "M": [{"x": 280, "y": 781}, {"x": 605, "y": 781}], "E": 3}
],
"junctions": [{"x": 280, "y": 226}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://ElectricalComponents/Example.svg"},
"tests": {
"case1": {
"stop": 20,
"initial": {"capacitor.v": 10},
"expect": {
"final": {
"current_sensor.i": "0.31798707833424167",
"voltage_sensor.v": "0.6820129216657976",
"power_sensor.power": "0.21687129634670702"
}
}
}
}
}
}
endTest Cases
Test Case case1
Related
Examples
Experiments
Analyses
Tests