Analog electrical models

This library of components is modeled after the Modelica.Electrical.Analog library.

Voltage nodes with type Voltage are the main Unknown type used in electrical circuits. voltage nodes can be single floating point unknowns representing a single voltage node. A Voltage can also be an array representing multiphase circuits or multiple node positions. Lastly, Voltage unknowns can also be complex for use with quasiphasor-type solutions.

The type ElectricalNode is a Union type that can be an Array, a number, an expression, or an Unknown. This is used in model functions to allow passing a Voltage node or a real value (like 0.0 for ground).

Example

function ex_ChuaCircuit()
    @variables n1(t) n2(t) n3(t) = 4.0
    g = 0.0
    function NonlinearResistor(n1::ElectricalNode, n2::ElectricalNode; Ga, Gb, Ve)
        i = Current(compatible_values(n1, n2))
        v = Voltage(compatible_values(n1, n2))
        [
            Branch(n1, n2, v, i)
            i = ie(v < -Ve, Gb .* (v + Ve) - Ga .* Ve,
                   ie(v > Ve, Gb .* (v - Ve) + Ga*Ve, Ga*v))
        ]
    end
    [
        :r1 => Resistor(n1, g,  R = 12.5e-3) 
        :l1 => Inductor(n1, n2, L = 18.0)
        :r2 => Resistor(n2, n3, R = 1 / 0.565) 
        :c1 => Capacitor(n2, g, C = 100.0)
        :c2 => Capacitor(n3, g, C = 10.0)
        :r3 => NonlinearResistor(n3, g, Ga = -0.757576, Gb = -0.409091, Ve = 1.0)
    ]
end

Basics

Resistor

FunctionalModels.Lib.ResistorFunction

The linear resistor connects the branch voltage v with the branch current i by i*R = v. The Resistance R is allowed to be positive, zero, or negative.

Resistor(n1::ElectricalNode, n2::ElectricalNode; 
         R = 1.0, T = 293.15, T_ref = 300.15, alpha = 0.0)
Resistor(n1::ElectricalNode, n2::ElectricalNode, hp::HeatPort; 
         R = 1.0, T = 293.15, T_ref = 300.15, alpha = 0.0)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]

Keyword/Optional Arguments

  • R::Signal : Resistance at temperature T_ref [ohms], default = 1.0 ohms
  • hp::HeatPort : Heat port [K], optional
  • T::HeatPort : Fixed device temperature or HeatPort [K], default = T_ref
  • T_ref::Signal : Reference temperature [K], default = 300.15K
  • alpha::Signal : Temperature coefficient of resistance (R_actual = R*(1 + alpha*(T_heatPort - T_ref))) [1/K], default = 0.0

Details

The resistance R is optionally temperature dependent according to the following equation:

R = R_ref*(1 + alpha*(hp.T - T_ref))

With the optional hp HeatPort argument, the power will be dissipated into this HeatPort.

The resistance R can be a constant numeric value or an Unknown, meaning it can vary with time. Note: it is recommended that the R signal should not cross the zero value. Otherwise, depending on the surrounding circuit, the probability of singularities is high.

This device is vectorizable using array inputs for one or both of n1 and n2.

Example

function model()
    @variables n1
    g = 0.0
    [
        :vsrc => SineVoltage(n1, g, V = 100.0)
        :r1   => Resistor(n1, g, R = 3.0, T = 330.0, alpha = 1.0)
    ]
end
source

Capacitor

FunctionalModels.Lib.CapacitorFunction

The linear capacitor connects the branch voltage v with the branch current i by i = C * dv/dt.

Capacitor(n1::ElectricalNode, n2::ElectricalNode; C::Signal) 

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]

Keyword/Optional Arguments

  • C::Signal : Capacitance [F]

Details

C can be a constant numeric value or an Unknown, meaning it can vary with time. If C is a constant, it may be positive, zero, or negative. If C is a signal, it should be greater than zero.

This device is vectorizable using array inputs for one or both of n1 and n2.

Example

function model()
    @variables n1(t)
    g = 0.0
    [
        :vsrc => SineVoltage(n1, g, V = 100.0)
        :r    => Resistor(n1, g, R = 3.0)
        :c    => Capacitor(n1, g, C = 1.0)
    ]
end
source

Inductor

FunctionalModels.Lib.InductorFunction

The linear inductor connects the branch voltage v with the branch current i by v = L * di/dt.

Inductor(n1::ElectricalNode, n2::ElectricalNode; L::Signal)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]

Keyword/Optional Arguments

  • L::Signal : Inductance [H]

Details

L can be a constant numeric value or an Unknown, meaning it can vary with time. If L is a constant, it may be positive, zero, or negative. If L is a signal, it should be greater than zero.

This device is vectorizable using array inputs for one or both of n1 and n2

Example

function model()
    @variables n1(t)
    g = 0.0
    [
        :vsrc => SineVoltage(n1, g, V = 100.0)
        :r    => Resistor(n1, g, R = 3.0)
        :c    => Inductor(n1, g, L = 6.0)
    ]
end
source

SaturatingInductor

FunctionalModels.Lib.SaturatingInductorFunction

To be done...

SaturatingInductor as implemented in the Modelica Standard Library depends on a Discrete value that is not fixed. This is not currently supported. Only Unknowns can currently be solved during initial conditions.

source

Transformer

FunctionalModels.Lib.TransformerFunction

The transformer is a two port. The left port voltage v1, left port current i1, right port voltage v2 and right port current i2 are connected by the following relation:

| v1 |         | L1   M  |  | i1' |
|    |    =    |         |  |     |
| v2 |         | M    L2 |  | i2' |

L1, L2, and M are the primary, secondary, and coupling inductances respectively.

Transformer(p1::ElectricalNode, n1::ElectricalNode, p2::ElectricalNode, n2::ElectricalNode; 
            L1 = 1.0, L2 = 1.0, M = 1.0)

Arguments

  • p1::ElectricalNode : Positive electrical node of the left port (potential p1 > n1 for positive voltage drop v1) [V]
  • n1::ElectricalNode : Negative electrical node of the left port [V]
  • p2::ElectricalNode : Positive electrical node of the right port (potential p2 > n2 for positive voltage drop v2) [V]
  • n2::ElectricalNode : Negative electrical node of the right port [V]

Keyword/Optional Arguments

  • L1::Signal : Primary inductance [H]
  • L2::Signal : Secondary inductance [H]
  • M::Signal : Coupling inductance [H]
source

EMF

FunctionalModels.Lib.EMFFunction

EMF transforms electrical energy into rotational mechanical energy. It is used as basic building block of an electrical motor. The mechanical connector flange can be connected to elements of the rotational library.

EMF(n1::ElectricalNode, n2::ElectricalNode, flange::Flange,
    support_flange = 0.0, k = 1.0)
EMF(n1::ElectricalNode, n2::ElectricalNode, flange::Flange;
    support_flange = 0.0, k = 1.0)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]
  • flange::Flange : Rotational shaft

Keyword/Optional Arguments

  • support_flange : Support/housing of the EMF shaft
  • k : Transformation coefficient [N.m/A]
source

Ideal

IdealDiode

FunctionalModels.Lib.IdealDiodeFunction

This is an ideal switch which is open (off), if it is reversed biased (voltage drop less than 0) closed (on), if it is conducting (current > 0). This is the behaviour if all parameters are exactly zero. Note, there are circuits, where this ideal description with zero resistance and zero cinductance is not possible. In order to prevent singularities during switching, the opened diode has a small conductance Gon and the closed diode has a low resistance Roff which is default.

The parameter Vknee which is the forward threshold voltage, allows to displace the knee point along the Gon-characteristic until v = Vknee.

IdealDiode(n1::ElectricalNode, n2::ElectricalNode; 
           Vknee = 0.0, Ron = 1e-5, Goff = 1e-5)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]

Keyword/Optional Arguments

  • Vknee : Forward threshold voltage [V], default = 0.0
  • Ron : Closed diode resistance [Ohm], default = 1.E-5
  • Goff : Opened diode conductance [S], default = 1.E-5
source

IdealThyristor

FunctionalModels.Lib.IdealThyristorFunction

This is an ideal thyristor model which is open (off), if the voltage drop is less than 0 or fire is false closed (on), if the voltage drop is greater or equal 0 and fire is true.

This is the behaviour if all parameters are exactly zero. Note, there are circuits, where this ideal description with zero resistance and zero cinductance is not possible. In order to prevent singularities during switching, the opened thyristor has a small conductance Goff and the closed thyristor has a low resistance Ron which is default.

The parameter Vknee which is the forward threshold voltage, allows to displace the knee point along the Goff-characteristic until v = Vknee.

IdealThyristor(n1::ElectricalNode, n2::ElectricalNode, fire; 
               Vknee = 0.0, Ron = 1e-5, Goff = 1e-5)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]
  • fire : Discrete bool variable indicating firing of the thyristor

Keyword/Optional Arguments

  • Vknee : Forward threshold voltage [V], default = 0.0
  • Ron : Closed thyristor resistance [Ohm], default = 1.E-5
  • Goff : Opened thyristor conductance [S], default = 1.E-5
source

IdealOpAmp

FunctionalModels.Lib.IdealOpAmpFunction

The ideal OpAmp is a two-port device. The left port is fixed to v1=0 and i1=0 (nullator). At the right port, both any voltage v2 and any current i2 are possible (norator).

The ideal OpAmp with three pins is of exactly the same behaviour as the ideal OpAmp with four pins. Only the negative output pin is left out. Both the input voltage and current are fixed to zero (nullator). At the output pin both any voltage v2 and any current i2 are possible.

IdealOpAmp(p1::ElectricalNode, n1::ElectricalNode, p2::ElectricalNode, n2::ElectricalNode)
IdealOpAmp(p1::ElectricalNode, n1::ElectricalNode, p2::ElectricalNode)

Arguments

  • p1::ElectricalNode : Positive electrical node of the left port (potential p1 > n1 for positive voltage drop v1) [V]
  • n1::ElectricalNode : Negative electrical node of the left port [V]
  • p2::ElectricalNode : Positive electrical node of the right port (potential p2 > n2 for positive voltage drop v2) [V]
  • n2::ElectricalNode : Negative electrical node of the right port [V], defaults to 0.0 V
source

IdealOpeningSwitch

FunctionalModels.Lib.IdealOpeningSwitchFunction

The ideal opening switch has a positive pin p and a negative pin n. The switching behaviour is controlled by the input signal control. If control is true, pin p is not connected with negative pin n. Otherwise, pin p is connected with negative pin n.

In order to prevent singularities during switching, the opened switch has a (very low) conductance Goff and the closed switch has a (very low) resistance Ron. The limiting case is also allowed, i.e., the resistance Ron of the closed switch could be exactly zero and the conductance Goff of the open switch could be also exactly zero. Note, there are circuits, where a description with zero Ron or zero Goff is not possible.

IdealOpeningSwitch(n1::ElectricalNode, n2::ElectricalNode, control;
                   Ron = 1e-5, Goff = 1e-5)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]
  • control : true => switch open, false => n1-n2 connected

Keyword/Optional Arguments

  • Ron : Closed switch resistance [Ohm], default = 1.E-5
  • Goff : Opened switch conductance [S], default = 1.E-5
source

IdealClosingSwitch

FunctionalModels.Lib.IdealClosingSwitchFunction

The ideal closing switch has a positive node n1 and a negative node n2. The switching behaviour is controlled by input signal control. If control is true, n1 and n2 are connected.

In order to prevent singularities during switching, the opened switch has a (very low) conductance Goff and the closed switch has a (very low) resistance Ron. The limiting case is also allowed, i.e., the resistance Ron of the closed switch could be exactly zero and the conductance Goff of the open switch could be also exactly zero. Note, there are circuits, where a description with zero Ron or zero Goff is not possible.

IdealClosingSwitch(n1::ElectricalNode, n2::ElectricalNode, control;
                   Ron = 1e-5, Goff = 1e-5)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]
  • control : true => n1 & n2 connected, false => switch open

Keyword/Optional Arguments

  • Ron : Closed switch resistance [Ohm], default = 1.E-5
  • Goff : Opened switch conductance [S], default = 1.E-5
source

ControlledIdealOpeningSwitch

FunctionalModels.Lib.ControlledIdealOpeningSwitchFunction

This ideal opening switch has a positive node n1 and a negative node n2. The switching behaviour is controlled by the voltage control. If control is greater than level, n1 and n2 are not connected (open switch). If control is less than level, the switch is closed.

In order to prevent singularities during switching, the opened switch has a (very low) conductance Goff and the closed switch has a (very low) resistance Ron. The limiting case is also allowed, i.e., the resistance Ron of the closed switch could be exactly zero and the conductance Goff of the open switch could be also exactly zero. Note, there are circuits, where a description with zero Ron or zero Goff is not possible.

ControlledIdealOpeningSwitch(n1::ElectricalNode, n2::ElectricalNode, control;
                   level, Ron = 1e-5, Goff = 1e-5)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]
  • control : Control voltage [V]

Keyword/Optional Arguments

  • level : Switching voltage [V]
  • Ron : Closed switch resistance [Ohm], default = 1.E-5
  • Goff : Opened switch conductance [S], default = 1.E-5
source

ControlledIdealClosingSwitch

FunctionalModels.Lib.ControlledIdealClosingSwitchFunction

This ideal opening switch has a positive node n1 and a negative node n2. The switching behaviour is controlled by the voltage control. If control is greater than level, n1 and n2 are connected (closed switch). If control is less than level, the switch is open.

In order to prevent singularities during switching, the opened switch has a (very low) conductance Goff and the closed switch has a (very low) resistance Ron. The limiting case is also allowed, i.e., the resistance Ron of the closed switch could be exactly zero and the conductance Goff of the open switch could be also exactly zero. Note, there are circuits, where a description with zero Ron or zero Goff is not possible.

ControlledIdealClosingSwitch(n1::ElectricalNode, n2::ElectricalNode, control;
                   level, Ron = 1e-5, Goff = 1e-5)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]
  • control : Control voltage [V]

Keyword/Optional Arguments

  • level : Switching voltage [V]
  • Ron : Closed switch resistance [Ohm], default = 1.E-5
  • Goff : Opened switch conductance [S], default = 1.E-5
source

Semiconductors

Diode

FunctionalModels.Lib.DiodeFunction

The simple diode is a one port. It consists of the diode itself and an parallel ohmic resistance R. The diode formula is:

i  =  ids * ( e^(v/vt) - 1 )

If the exponent v/vt reaches the limit maxex, the diode characterisic is linearly continued to avoid overflow.

Diode(n1::ElectricalNode, n2::ElectricalNode; 
      Ids = 1e-6,  Vt = 0.04,  Maxexp = 15,  R = 1e8)
Diode(n1::ElectricalNode, n2::ElectricalNode; hp::HeatPort;
      Ids = 1e-6,  Vt = 0.04,  Maxexp = 15,  R = 1e8)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]
  • hp::HeatPort : Heat port [K]

Keyword/Optional Arguments

  • Ids : Saturation current [A], default = 1.e-6
  • Vt : Voltage equivalent of temperature (kT/qn) [V], default = 0.04
  • Maxexp : Max. exponent for linear continuation, default = 15.0
  • R : Parallel ohmic resistance [Ohm], default = 1.e8
source

ZDiode

Sources

SignalVoltage

FunctionalModels.Lib.SignalVoltageFunction

The signal voltage source is a parameterless converter of real valued signals into a source voltage.

This voltage source may be vectorized.

SignalVoltage(n1::ElectricalNode, n2::ElectricalNode; V::Signal)  

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]
  • V::Signal : Voltage between n1 and n2 (= n1 - n2) as an input signal
source

SineVoltage

FunctionalModels.Lib.SineVoltageFunction

A sinusoidal voltage source. An offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

This voltage source may be vectorized.

SineVoltage(n1::ElectricalNode, n2::ElectricalNode; 
            V = 1.0,  f = 1.0,  ang = 0.0,  offset = 0.0)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]

Keyword/Optional Arguments

  • V : Amplitude of sine wave [V], default = 1.0
  • phase : Phase of sine wave [rad], default = 0.0
  • freqHz : Frequency of sine wave [Hz], default = 1.0
  • offset : Voltage offset [V], default = 0.0
  • startTime : Time offset [s], default = 0.0
source

StepVoltage

FunctionalModels.Lib.StepVoltageFunction

A step voltage source. An event is introduced at the transition. Probably cannot be vectorized.

StepVoltage(n1::ElectricalNode, n2::ElectricalNode; 
            V = 1.0,  start = 0.0,  offset = 0.0)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]

Keyword/Optional Arguments

  • V : Height of step [V], default = 1.0
  • offset : Voltage offset [V], default = 0.0
  • startTime : Time offset [s], default = 0.0
source

SignalCurrent

FunctionalModels.Lib.SignalCurrentFunction

The signal current source is a parameterless converter of real valued signals into a current voltage.

This current source may be vectorized.

SignalCurrent(n1::ElectricalNode, n2::ElectricalNode; I::Signal)  

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]
  • I::Signal : Current flowing from n1 to n2 as an input signal
source

Utilities

SeriesProbe

FunctionalModels.Lib.SeriesProbeFunction

Connect a series current probe between two nodes. This is vectorizable.

SeriesProbe(n1, n2; name::AbstractString)

Arguments

  • n1 : Positive node
  • n2 : Negative node
  • name::AbstractString : The name of the probe

Example

function model()
    @named n1 = Voltage()
    @named n2 = Voltage()
    g = 0.0
    [
        :vsrc => SineVoltage(n1, g, V = 100.0)
        :i => SeriesProbe(n1, n2, "current")
        :r => Resistor(n2, g, R = 2.0)
    ]
end
source

BranchHeatPort

FunctionalModels.Lib.BranchHeatPortFunction

Wrap argument model with a heat port that captures the power generated by the electrical device. This is vectorizable.

BranchHeatPort(n1::ElectricalNode, n2::ElectricalNode, hp::HeatPort,
               model::Function, args...)

Arguments

  • n1::ElectricalNode : Positive electrical node [V]
  • n2::ElectricalNode : Negative electrical node [V]
  • hp::HeatPort : Heat port [K]
  • model::Function : Model to wrap
  • args... : Arguments passed to model

Examples

Here's an example of a definition defining a Resistor that uses a heat port (a Temperature) in terms of another model:

function ResistorWithHeating(n1::ElectricalNode, n2::ElectricalNode, R::Signal, hp::Temperature; T_ref::Signal, alpha::Signal) 
    BranchHeatPort(n1, n2, hp, Resistor, R .* (1 + alpha .* (hp - T_ref)))
end
source