$(instance)SensorsTest Icon

SensorsTest

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.

Usage

SensorsTest()

Behavior

\[ \begin{equation} \left[ \begin{array}{c} \mathtt{source.y}\left( t \right) = \mathtt{voltage.V}\left( t \right) \\ \mathrm{connect}\left( voltage_{+}p, resistor_{+}p \right) \\ \mathrm{connect}\left( resistor_{+}n, current_{sensor_{+}p} \right) \\ \mathrm{connect}\left( current_{sensor_{+}n}, power_{sensor_{+}pc} \right) \\ \mathrm{connect}\left( power_{sensor_{+}nc}, capacitor_{+}p \right) \\ \mathrm{connect}\left( capacitor_{+}n, voltage_{+}n, ground_{+}g \right) \\ \mathrm{connect}\left( capacitor_{+}p, voltage_{sensor_{+}p}, power_{sensor_{+}pv} \right) \\ \mathrm{connect}\left( capacitor_{+}n, voltage_{sensor_{+}n}, power_{sensor_{+}nv} \right) \\ \mathtt{source.y}\left( t \right) = ifelse\left( \mathtt{source.start\_time} < t, \mathtt{source.offset} + \mathtt{source.amplitude} \sin\left( \mathtt{source.phase} + 6.2832 \mathtt{source.frequency} \left( - \mathtt{source.start\_time} + t \right) \right), \mathtt{source.offset} \right) \\ \mathtt{voltage.v}\left( t \right) = \mathtt{voltage.p.v}\left( t \right) - \mathtt{voltage.n.v}\left( t \right) \\ \mathtt{voltage.i}\left( t \right) = \mathtt{voltage.p.i}\left( t \right) \\ \mathtt{voltage.p.i}\left( t \right) + \mathtt{voltage.n.i}\left( t \right) = 0 \\ \mathtt{voltage.v}\left( t \right) = \mathtt{voltage.uV} \mathtt{voltage.V}\left( t \right) \\ \mathtt{resistor.v}\left( t \right) = - \mathtt{resistor.n.v}\left( t \right) + \mathtt{resistor.p.v}\left( t \right) \\ \mathtt{resistor.i}\left( t \right) = \mathtt{resistor.p.i}\left( t \right) \\ \mathtt{resistor.p.i}\left( t \right) + \mathtt{resistor.n.i}\left( t \right) = 0 \\ \mathtt{resistor.v}\left( t \right) = \mathtt{resistor.R} \mathtt{resistor.i}\left( t \right) \\ \mathtt{capacitor.v}\left( t \right) = \mathtt{capacitor.p.v}\left( t \right) - \mathtt{capacitor.n.v}\left( t \right) \\ \mathtt{capacitor.i}\left( t \right) = \mathtt{capacitor.p.i}\left( t \right) \\ \mathtt{capacitor.p.i}\left( t \right) + \mathtt{capacitor.n.i}\left( t \right) = 0 \\ \mathtt{capacitor.C} \frac{\mathrm{d} \mathtt{capacitor.v}\left( t \right)}{\mathrm{d}t} = \mathtt{capacitor.i}\left( t \right) \\ \mathtt{ground.g.v}\left( t \right) = 0 \\ \mathtt{voltage\_sensor.p.i}\left( t \right) = 0 \\ \mathtt{voltage\_sensor.n.i}\left( t \right) = 0 \\ \mathtt{voltage\_sensor.v}\left( t \right) = \mathtt{voltage\_sensor.p.v}\left( t \right) - \mathtt{voltage\_sensor.n.v}\left( t \right) \\ \mathtt{current\_sensor.p.v}\left( t \right) = \mathtt{current\_sensor.n.v}\left( t \right) \\ \mathtt{current\_sensor.p.i}\left( t \right) = \mathtt{current\_sensor.i}\left( t \right) \\ \mathtt{current\_sensor.n.i}\left( t \right) = - \mathtt{current\_sensor.i}\left( t \right) \\ \mathtt{power\_sensor.power}\left( t \right) = \mathtt{power\_sensor.voltage\_sensor.v}\left( t \right) \mathtt{power\_sensor.current\_sensor.i}\left( t \right) \\ \mathrm{connect}\left( pv, voltage_{sensor_{+}p} \right) \\ \mathrm{connect}\left( voltage_{sensor_{+}n}, nv \right) \\ \mathrm{connect}\left( pc, current_{sensor_{+}p} \right) \\ \mathrm{connect}\left( current_{sensor_{+}n}, nc \right) \\ \mathtt{power\_sensor.voltage\_sensor.p.i}\left( t \right) = 0 \\ \mathtt{power\_sensor.voltage\_sensor.n.i}\left( t \right) = 0 \\ \mathtt{power\_sensor.voltage\_sensor.v}\left( t \right) = - \mathtt{power\_sensor.voltage\_sensor.n.v}\left( t \right) + \mathtt{power\_sensor.voltage\_sensor.p.v}\left( t \right) \\ \mathtt{power\_sensor.current\_sensor.p.v}\left( t \right) = \mathtt{power\_sensor.current\_sensor.n.v}\left( t \right) \\ \mathtt{power\_sensor.current\_sensor.p.i}\left( t \right) = \mathtt{power\_sensor.current\_sensor.i}\left( t \right) \\ \mathtt{power\_sensor.current\_sensor.n.i}\left( t \right) = - \mathtt{power\_sensor.current\_sensor.i}\left( t \right) \\ \end{array} \right] \end{equation} \]

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 SensorsTest
  # Signal generator providing a sinusoidal voltage waveform.
  source = BlockComponents.Sine(offset=1, amplitude=10, frequency=5)
  # Ideal voltage source whose output is controlled by the 'source' signal.
  voltage = VoltageSource()
  # Electrical resistor with a fixed resistance value.
  resistor = Resistor(R=1)
  # Electrical capacitor with a fixed capacitance value.
  capacitor = Capacitor(C=1)
  # Electrical ground reference (0V).
  ground = Ground()
  # Sensor to measure voltage difference between its 'p' and 'n' terminals.
  voltage_sensor = VoltageSensor()
  # Sensor to measure current flowing through it from 'p' to 'n'.
  current_sensor = CurrentSensor()
  # Sensor to measure electrical power, based on voltage (pv, nv) and current (pc, nc) measurements.
  power_sensor = PowerSensor()
relations
  connect(source.y, voltage.V)
  connect(voltage.p, resistor.p)
  connect(resistor.n, current_sensor.p)
  connect(current_sensor.n, power_sensor.pc)
  connect(power_sensor.nc, capacitor.p)
  connect(capacitor.n, voltage.n, ground.g)
  connect(capacitor.p, voltage_sensor.p, power_sensor.pv)
  connect(capacitor.n, voltage_sensor.n, power_sensor.nv)
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 20,
        "initial": {"capacitor.v": 10},
        "expect": {
          "final": {
            "current_sensor.i": "0.31784799",
            "voltage_sensor.v": "0.682152",
            "power_sensor.power": "0.216820646"
          }
        }
      }
    }
  }
}
end
Flattened 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 SensorsTest
  # Signal generator providing a sinusoidal voltage waveform.
  source = BlockComponents.Sine(offset=1, amplitude=10, frequency=5)
  # Ideal voltage source whose output is controlled by the 'source' signal.
  voltage = VoltageSource()
  # Electrical resistor with a fixed resistance value.
  resistor = Resistor(R=1)
  # Electrical capacitor with a fixed capacitance value.
  capacitor = Capacitor(C=1)
  # Electrical ground reference (0V).
  ground = Ground()
  # Sensor to measure voltage difference between its 'p' and 'n' terminals.
  voltage_sensor = VoltageSensor()
  # Sensor to measure current flowing through it from 'p' to 'n'.
  current_sensor = CurrentSensor()
  # Sensor to measure electrical power, based on voltage (pv, nv) and current (pc, nc) measurements.
  power_sensor = PowerSensor()
relations
  connect(source.y, voltage.V)
  connect(voltage.p, resistor.p)
  connect(resistor.n, current_sensor.p)
  connect(current_sensor.n, power_sensor.pc)
  connect(power_sensor.nc, capacitor.p)
  connect(capacitor.n, voltage.n, ground.g)
  connect(capacitor.p, voltage_sensor.p, power_sensor.pv)
  connect(capacitor.n, voltage_sensor.n, power_sensor.nv)
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 20,
        "initial": {"capacitor.v": 10},
        "expect": {
          "final": {
            "current_sensor.i": "0.31784799",
            "voltage_sensor.v": "0.682152",
            "power_sensor.power": "0.216820646"
          }
        }
      }
    }
  }
}
end


Test Cases

Test Case case1