Skip to content
OnePort.md

OnePort

A base model for two-terminal electrical components, defining voltage and current relationships.

This partial component serves as a foundational building block for creating various two-pin electrical devices. It establishes a common interface with a positive pin (p) and a negative pin (n). By extending TwoPin, it defines voltage across the component (v) as the potential difference between these pins:

v=p.vn.v

The current (i) flowing through the component is taken as the current entering the positive pin (p):

i=p.i

Conservation of charge is maintained by enforcing Kirchhoff's Current Law, ensuring that the current entering one pin exits through the other:

p.i+n.i=0

This model is intended to be extended by specific components like resistors, capacitors, etc., which will add their own constitutive equations relating v and i.

This component extends from TwoPin

Usage

OnePort()

Connectors

Variables

NameDescriptionUnits
vVoltage across the component (between pin p and pin n).V
iCurrent flowing through the component (from pin p to pin n).A

Source

dyad
# A base model for two-terminal electrical components, defining voltage and current relationships.
#
# This partial component serves as a foundational building block for creating various two-pin electrical devices.
# It establishes a common interface with a positive pin (`p`) and a negative pin (`n`).
# By extending `TwoPin`, it defines voltage across the component (`v`) as the potential difference between these pins:
# ```math
# v = p.v - n.v
# ```
# The current (`i`) flowing through the component is taken as the current entering the positive pin (`p`):
# ```math
# i = p.i
# ```
# Conservation of charge is maintained by enforcing Kirchhoff's Current Law,
# ensuring that the current entering one pin exits through the other:
# ```math
# p.i + n.i = 0
# ```
# This model is intended to be extended by specific components like resistors, capacitors, etc.,
# which will add their own constitutive equations relating `v` and `i`.
partial component OnePort
  extends TwoPin
  # Current flowing through the component (from pin p to pin n).
  variable i::Current
relations
  i = p.i
  p.i+n.i = 0
end
Flattened Source
dyad
# A base model for two-terminal electrical components, defining voltage and current relationships.
#
# This partial component serves as a foundational building block for creating various two-pin electrical devices.
# It establishes a common interface with a positive pin (`p`) and a negative pin (`n`).
# By extending `TwoPin`, it defines voltage across the component (`v`) as the potential difference between these pins:
# ```math
# v = p.v - n.v
# ```
# The current (`i`) flowing through the component is taken as the current entering the positive pin (`p`):
# ```math
# i = p.i
# ```
# Conservation of charge is maintained by enforcing Kirchhoff's Current Law,
# ensuring that the current entering one pin exits through the other:
# ```math
# p.i + n.i = 0
# ```
# This model is intended to be extended by specific components like resistors, capacitors, etc.,
# which will add their own constitutive equations relating `v` and `i`.
partial component OnePort
  # Positive electrical pin.
  p = Pin() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "pos", "x1": -50, "y1": 450, "x2": 50, "y2": 550}}
    }
  }]
  # Negative electrical pin.
  n = Pin() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "neg", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
    }
  }]
  # Voltage across the component (between pin p and pin n).
  variable v::Voltage
  # Current flowing through the component (from pin p to pin n).
  variable i::Current
relations
  v = p.v-n.v
  i = p.i
  p.i+n.i = 0
metadata {}
end


Test Cases

This is setup code, that must be run before each test case.

julia
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"
  • Examples

  • Experiments

  • Analyses