MultiSensorTest
A test circuit designed to verify the behavior of a MultiSensor component within a series R-C circuit driven by a sinusoidal voltage source.
This component models an electrical test bench. A VoltageSource
, whose voltage BlockComponents.Sine
signal generator, applies a sinusoidal voltage to a circuit. This circuit comprises a Resistor
(R) in series with a Capacitor
(C). The MultiSensor
component, which is the device under test, is placed to measure the current Ground
component provides a common reference potential (0 V). The circuit dynamics are governed by the differential equation for the capacitor voltage MultiSensor
is expected to report
Usage
MultiSensorTest()
Behavior
Source
# A test circuit designed to verify the behavior of a MultiSensor component within
# a series R-C circuit driven by a sinusoidal voltage source.
#
# This component models an electrical test bench. A `VoltageSource`, whose voltage
# $V_{in}(t)$ is dictated by a `BlockComponents.Sine` signal generator, applies a
# sinusoidal voltage to a circuit.
# This circuit comprises a `Resistor` (R) in series with a `Capacitor` (C).
# The `MultiSensor` component, which is the device under test, is placed to measure
# the current $i(t)$ flowing through the resistor and capacitor, and the voltage
# $v_C(t)$ across the capacitor. The `Ground` component provides a common reference
# potential (0 V).
# The circuit dynamics are governed by the differential equation for the capacitor
# voltage $v_C(t)$: $R C \frac{d v_C(t)}{dt} + v_C(t) = V_{in}(t)$ and
# the current is $i(t) = C \frac{d v_C(t)}{dt}$.
# The `MultiSensor` is expected to report $v_C(t)$ as its voltage measurement and
# $i(t)$ as its current measurement.
test component MultiSensorTest
# Signal generator providing a sinusoidal input waveform with specified offset, amplitude, and frequency.
source = BlockComponents.Sine(offset=1, amplitude=10, frequency=5)
# Ideal voltage source component; its voltage is controlled by an external signal.
voltage = VoltageSource()
# Resistor component with a resistance value R=1 Ohm.
resistor = Resistor(R=1)
# Capacitor component with a capacitance value C=1 Farad.
capacitor = Capacitor(C=1)
# Electrical ground component, providing a zero-volt reference potential.
ground = Ground()
# The multi-functional sensor component under test; it measures voltage, current and calculates power.
multi_sensor = MultiSensor()
relations
connect(source.y, voltage.V)
connect(voltage.p, resistor.p)
connect(resistor.n, multi_sensor.pc)
connect(multi_sensor.nc, capacitor.p)
connect(capacitor.n, voltage.n, ground.g)
connect(capacitor.p, multi_sensor.pv)
connect(capacitor.n, multi_sensor.nv)
metadata {
"Dyad": {
"tests": {
"case1": {
"stop": 20,
"initial": {"capacitor.v": 10},
"expect": {
"final": {
"multi_sensor.i": "0.31784799",
"multi_sensor.v": "0.682152",
"multi_sensor.power": "0.216820646"
}
}
}
}
}
}
end
Flattened Source
# A test circuit designed to verify the behavior of a MultiSensor component within
# a series R-C circuit driven by a sinusoidal voltage source.
#
# This component models an electrical test bench. A `VoltageSource`, whose voltage
# $V_{in}(t)$ is dictated by a `BlockComponents.Sine` signal generator, applies a
# sinusoidal voltage to a circuit.
# This circuit comprises a `Resistor` (R) in series with a `Capacitor` (C).
# The `MultiSensor` component, which is the device under test, is placed to measure
# the current $i(t)$ flowing through the resistor and capacitor, and the voltage
# $v_C(t)$ across the capacitor. The `Ground` component provides a common reference
# potential (0 V).
# The circuit dynamics are governed by the differential equation for the capacitor
# voltage $v_C(t)$: $R C \frac{d v_C(t)}{dt} + v_C(t) = V_{in}(t)$ and
# the current is $i(t) = C \frac{d v_C(t)}{dt}$.
# The `MultiSensor` is expected to report $v_C(t)$ as its voltage measurement and
# $i(t)$ as its current measurement.
test component MultiSensorTest
# Signal generator providing a sinusoidal input waveform with specified offset, amplitude, and frequency.
source = BlockComponents.Sine(offset=1, amplitude=10, frequency=5)
# Ideal voltage source component; its voltage is controlled by an external signal.
voltage = VoltageSource()
# Resistor component with a resistance value R=1 Ohm.
resistor = Resistor(R=1)
# Capacitor component with a capacitance value C=1 Farad.
capacitor = Capacitor(C=1)
# Electrical ground component, providing a zero-volt reference potential.
ground = Ground()
# The multi-functional sensor component under test; it measures voltage, current and calculates power.
multi_sensor = MultiSensor()
relations
connect(source.y, voltage.V)
connect(voltage.p, resistor.p)
connect(resistor.n, multi_sensor.pc)
connect(multi_sensor.nc, capacitor.p)
connect(capacitor.n, voltage.n, ground.g)
connect(capacitor.p, multi_sensor.pv)
connect(capacitor.n, multi_sensor.nv)
metadata {
"Dyad": {
"tests": {
"case1": {
"stop": 20,
"initial": {"capacitor.v": 10},
"expect": {
"final": {
"multi_sensor.i": "0.31784799",
"multi_sensor.v": "0.682152",
"multi_sensor.power": "0.216820646"
}
}
}
}
}
}
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 = MultiSensorTest()
u0_case1 = [model_case1.capacitor.v => 10]
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 20))
sol_case1 = solve(prob_case1)
retcode: Success
Interpolation: 3rd order Hermite
t: 260-element Vector{Float64}:
0.0
0.05010103301073373
0.0946087415384399
0.1547779984639581
0.21599802888572972
0.2961800292855764
0.3648333700644
0.4445976597608447
0.5320248713713668
0.645331117296668
⋮
19.473359833916902
19.542409231002495
19.615280251672313
19.685905296490144
19.75176360818496
19.821772721570877
19.899303953335025
19.964273786046352
20.0
u: 260-element Vector{Vector{Float64}}:
[10.0]
[9.873766252034635]
[9.791971077475885]
[8.924307746030344]
[8.234084949901694]
[8.24603506951831]
[7.317565921913987]
[6.929603455972936]
[6.634921745318827]
[5.850526707067355]
⋮
[1.2208137865018391]
[1.0656565910840579]
[0.7230160263792365]
[1.2918991859072264]
[0.9725847505760823]
[0.7602173433783846]
[1.3182061937910738]
[0.853161575643345]
[0.6821520068556803]
Related
Examples
Experiments
Analyses
Tests