Skip to content
LIBRARY
Analog.Examples.CompareTransformers.md

Analog.Examples.CompareTransformers

MSL validation test: CompareTransformers (basic transformer part).

Recreates the basic-transformer subcircuit from Modelica.Electrical.Analog.Examples.CompareTransformers. A sine voltage source (Vpeak=0.1 V, f=10 Hz, phase=π/2, offset=0.1 V) drives a transformer through a primary resistor R1. The secondary side has a series resistor R2 and a load resistor RL. Both sides are grounded.

The full MSL example also compares against an IdealTransformer, which is not yet available in this library. Only the basic-transformer signals are validated here. The IdealTransformer comparison can be added once that component exists.

Transformer parameters are derived from a turns ratio n and magnetizing inductance Lm1, following the MSL parameterisation:

  • M = Lm1 / n

  • L1 = L1sigma + M·n (primary leakage + mutual)

  • L2 = L2sigma + M/n (secondary leakage + mutual)

With the default values (n=2, f=10 Hz) the coupling coefficient is ≈ 0.995, so the inductance matrix is non-singular.

MSL reference: tolerance=1e-6, StopTime=50.

Usage

ElectricalComponents.Analog.Examples.CompareTransformers(Vdc=0.1, Vpeak=0.1, f=10, phi0=pi / 2, n=2, R1=0.01, L1sigma=0.05 / (2 * pi * f), Lm1=10.0 / (2 * pi * f), L2sigma=0.05 / (2 * pi * f * n ^ 2), R2=R1 / n ^ 2, RL=1.0 / n ^ 2, M_val=Lm1 / n, L1_val=L1sigma + M_val * n, L2_val=L2sigma + M_val / n)

Parameters:

NameDescriptionUnitsDefault value
VdcDC offset of voltage sourceV0.1
VpeakPeak voltage of voltage sourceV0.1
fFrequency of voltage sourceHz10
phi0Phase of voltage sourceradpi / 2
nTurns ratio primary:secondary voltage2
R1Primary resistance w.r.t. primary sideΩ0.01
L1sigmaPrimary leakage inductance w.r.t. primary sideH0.05 / (2 * pi * f)
Lm1Magnetizing inductance w.r.t. primary sideH10 / (2 * pi * f)
L2sigmaSecondary leakage inductance w.r.t. secondary sideH0.05 / (2 * pi * f * n ^ 2)
R2Secondary resistance w.r.t. secondary sideΩR1 / n ^ 2
RLLoad resistanceΩ1 / n ^ 2

Behavior

[connect(sine1+y,voltagesource1+V)connect(voltagesource1+n,ground11+g)connect(resistor11+n,basictransformer+p1)connect(basictransformer+n1,ground11+g)connect(basictransformer+p2,resistor12+p)connect(resistor12+n,load1+p)connect(load1+n,ground12+g)connect(basictransformer+n2,ground12+g)connect(resistor11+p,voltagesource1+p)sine1.y(t)=sine1.offset+sine1.amplitudeifelse(tsine1.starttime,sin(sine1.phase+6.283185307179586sine1.frequency(sine1.starttime+t)),sin(sine1.phase))voltagesource1.v(t)=voltagesource1.p.v(t)voltagesource1.n.v(t)voltagesource1.i(t)=voltagesource1.p.i(t)voltagesource1.p.i(t)+voltagesource1.n.i(t)=0voltagesource1.v(t)=voltagesource1.uVvoltagesource1.V(t)ground11.g.v(t)=0ground12.g.v(t)=0resistor11.v(t)=resistor11.n.v(t)+resistor11.p.v(t)resistor11.i(t)=resistor11.p.i(t)resistor11.p.i(t)+resistor11.n.i(t)=0resistor11.v(t)=resistor11.Rresistor11.i(t)resistor12.v(t)=resistor12.n.v(t)+resistor12.p.v(t)resistor12.i(t)=resistor12.p.i(t)resistor12.n.i(t)+resistor12.p.i(t)=0resistor12.v(t)=resistor12.Rresistor12.i(t)load1.v(t)=load1.n.v(t)+load1.p.v(t)load1.i(t)=load1.p.i(t)load1.n.i(t)+load1.p.i(t)=0load1.v(t)=load1.Rload1.i(t)basictransformer.v1(t)=basictransformer.n1.v(t)+basictransformer.p1.v(t)basictransformer.v2(t)=basictransformer.n2.v(t)+basictransformer.p2.v(t)basictransformer.i1(t)=basictransformer.p1.i(t)basictransformer.i2(t)=basictransformer.p2.i(t)0=basictransformer.p1.i(t)+basictransformer.n1.i(t)0=basictransformer.n2.i(t)+basictransformer.p2.i(t)basictransformer.v1(t)=basictransformer.L1dbasictransformer.i1(t)dt+basictransformer.Mdbasictransformer.i2(t)dtbasictransformer.v2(t)=basictransformer.L2dbasictransformer.i2(t)dt+basictransformer.Mdbasictransformer.i1(t)dt]

Source

dyad
"""
MSL validation test: CompareTransformers (basic transformer part).

Recreates the basic-transformer subcircuit from
`Modelica.Electrical.Analog.Examples.CompareTransformers`.
A sine voltage source (Vpeak=0.1 V, f=10 Hz, phase=π/2, offset=0.1 V) drives
a transformer through a primary resistor R1. The secondary side has a series
resistor R2 and a load resistor RL. Both sides are grounded.

The full MSL example also compares against an IdealTransformer, which is not
yet available in this library. Only the basic-transformer signals are validated
here. The IdealTransformer comparison can be added once that component exists.

Transformer parameters are derived from a turns ratio `n` and magnetizing
inductance `Lm1`, following the MSL parameterisation:
- M    = Lm1 / n
- L1   = L1sigma + M·n  (primary leakage + mutual)
- L2   = L2sigma + M/n  (secondary leakage + mutual)

With the default values (n=2, f=10 Hz) the coupling coefficient is ≈ 0.995,
so the inductance matrix is non-singular.

MSL reference: tolerance=1e-6, StopTime=50.
"""
example component CompareTransformers
  "Sine signal: Vpeak amplitude, f Hz, phase phi0, offset Vdc"
  sine1 = BlockComponents.Sources.Sine(amplitude = Vpeak, frequency = f, phase = phi0, offset = Vdc) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 0, "y1": 0, "x2": 100, "y2": 100, "rot": 0}
      },
      "tags": []
    }
  }
  "Voltage source driven by sine"
  voltage_source1 = ElectricalComponents.Analog.Sources.VoltageSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 130, "x2": 70, "y2": 230, "rot": 0}
      },
      "tags": []
    }
  }
  "Primary ground"
  ground11 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 60, "y1": 400, "x2": 160, "y2": 500, "rot": 0}
      },
      "tags": []
    }
  }
  "Secondary ground"
  ground12 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 890, "y1": 400, "x2": 990, "y2": 500, "rot": 0}
      },
      "tags": []
    }
  }
  "Primary series resistor"
  resistor11 = ElectricalComponents.Analog.Basic.Resistor(R = R1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 130, "x2": 390, "y2": 230, "rot": 0}
      },
      "tags": []
    }
  }
  "Secondary series resistor"
  resistor12 = ElectricalComponents.Analog.Basic.Resistor(R = R2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 720, "y1": 130, "x2": 820, "y2": 230, "rot": 0}
      },
      "tags": []
    }
  }
  "Secondary load"
  load1 = ElectricalComponents.Analog.Basic.Resistor(R = RL) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 890, "y1": 200, "x2": 990, "y2": 300, "rot": 90}
      },
      "tags": []
    }
  }
  "Transformer with mutual inductance coupling"
  basic_transformer = ElectricalComponents.Analog.Basic.Transformer(L1 = L1_val, L2 = L2_val, M = M_val) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 180, "x2": 550, "y2": 280, "rot": 0}
      },
      "tags": []
    }
  }
  "DC offset of voltage source"
  parameter Vdc::Voltage = 0.1
  "Peak voltage of voltage source"
  parameter Vpeak::Voltage = 0.1
  "Frequency of voltage source"
  parameter f::Frequency = 10
  "Phase of voltage source"
  parameter phi0::Angle = pi / 2
  "Turns ratio primary:secondary voltage"
  parameter n::Real = 2
  "Primary resistance w.r.t. primary side"
  parameter R1::Resistance = 0.01
  "Primary leakage inductance w.r.t. primary side"
  parameter L1sigma::Inductance = 0.05 / (2 * pi * f)
  "Magnetizing inductance w.r.t. primary side"
  parameter Lm1::Inductance = 10.0 / (2 * pi * f)
  "Secondary leakage inductance w.r.t. secondary side"
  parameter L2sigma::Inductance = 0.05 / (2 * pi * f * n ^ 2)
  "Secondary resistance w.r.t. secondary side"
  parameter R2::Resistance = R1 / n ^ 2
  "Load resistance"
  parameter RL::Resistance = 1.0 / n ^ 2
  "Mutual inductance"
  final parameter M_val::Inductance = Lm1 / n
  "Primary no-load inductance"
  final parameter L1_val::Inductance = L1sigma + M_val * n
  "Secondary no-load inductance"
  final parameter L2_val::Inductance = L2sigma + M_val / n
relations
  initial basic_transformer.i1 = 0
  initial basic_transformer.i2 = 0
  "Sine drives voltage source"
  connect(sine1.y, voltage_source1.V) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 120, "y": 50}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Source negative to primary ground"
  connect(voltage_source1.n, ground11.g) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 30, "y": 180}, {"x": 30, "y": 330}, {"x": 110, "y": 330}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  "Primary resistor to transformer port 1 positive"
  connect(resistor11.n, basic_transformer.p1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 400, "y": 180}, {"x": 400, "y": 181}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Transformer port 1 negative to primary ground"
  connect(basic_transformer.n1, ground11.g) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 330, "y": 279}, {"x": 330, "y": 330}, {"x": 110, "y": 330}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  "Transformer port 2 positive to secondary resistor"
  connect(basic_transformer.p2, resistor12.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 720, "y": 181}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Secondary resistor to load"
  connect(resistor12.n, load1.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 940, "y": 180}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Load to secondary ground"
  connect(load1.n, ground12.g) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  "Transformer port 2 negative to secondary ground"
  connect(basic_transformer.n2, ground12.g) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 581, "y": 280}, {"x": 581, "y": 330}, {"x": 940, "y": 330}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(resistor11.p, voltage_source1.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
end
Flattened Source
dyad
"""
MSL validation test: CompareTransformers (basic transformer part).

Recreates the basic-transformer subcircuit from
`Modelica.Electrical.Analog.Examples.CompareTransformers`.
A sine voltage source (Vpeak=0.1 V, f=10 Hz, phase=π/2, offset=0.1 V) drives
a transformer through a primary resistor R1. The secondary side has a series
resistor R2 and a load resistor RL. Both sides are grounded.

The full MSL example also compares against an IdealTransformer, which is not
yet available in this library. Only the basic-transformer signals are validated
here. The IdealTransformer comparison can be added once that component exists.

Transformer parameters are derived from a turns ratio `n` and magnetizing
inductance `Lm1`, following the MSL parameterisation:
- M    = Lm1 / n
- L1   = L1sigma + M·n  (primary leakage + mutual)
- L2   = L2sigma + M/n  (secondary leakage + mutual)

With the default values (n=2, f=10 Hz) the coupling coefficient is ≈ 0.995,
so the inductance matrix is non-singular.

MSL reference: tolerance=1e-6, StopTime=50.
"""
example component CompareTransformers
  "Sine signal: Vpeak amplitude, f Hz, phase phi0, offset Vdc"
  sine1 = BlockComponents.Sources.Sine(amplitude = Vpeak, frequency = f, phase = phi0, offset = Vdc) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 0, "y1": 0, "x2": 100, "y2": 100, "rot": 0}
      },
      "tags": []
    }
  }
  "Voltage source driven by sine"
  voltage_source1 = ElectricalComponents.Analog.Sources.VoltageSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 130, "x2": 70, "y2": 230, "rot": 0}
      },
      "tags": []
    }
  }
  "Primary ground"
  ground11 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 60, "y1": 400, "x2": 160, "y2": 500, "rot": 0}
      },
      "tags": []
    }
  }
  "Secondary ground"
  ground12 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 890, "y1": 400, "x2": 990, "y2": 500, "rot": 0}
      },
      "tags": []
    }
  }
  "Primary series resistor"
  resistor11 = ElectricalComponents.Analog.Basic.Resistor(R = R1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 130, "x2": 390, "y2": 230, "rot": 0}
      },
      "tags": []
    }
  }
  "Secondary series resistor"
  resistor12 = ElectricalComponents.Analog.Basic.Resistor(R = R2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 720, "y1": 130, "x2": 820, "y2": 230, "rot": 0}
      },
      "tags": []
    }
  }
  "Secondary load"
  load1 = ElectricalComponents.Analog.Basic.Resistor(R = RL) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 890, "y1": 200, "x2": 990, "y2": 300, "rot": 90}
      },
      "tags": []
    }
  }
  "Transformer with mutual inductance coupling"
  basic_transformer = ElectricalComponents.Analog.Basic.Transformer(L1 = L1_val, L2 = L2_val, M = M_val) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 180, "x2": 550, "y2": 280, "rot": 0}
      },
      "tags": []
    }
  }
  "DC offset of voltage source"
  parameter Vdc::Voltage = 0.1
  "Peak voltage of voltage source"
  parameter Vpeak::Voltage = 0.1
  "Frequency of voltage source"
  parameter f::Frequency = 10
  "Phase of voltage source"
  parameter phi0::Angle = pi / 2
  "Turns ratio primary:secondary voltage"
  parameter n::Real = 2
  "Primary resistance w.r.t. primary side"
  parameter R1::Resistance = 0.01
  "Primary leakage inductance w.r.t. primary side"
  parameter L1sigma::Inductance = 0.05 / (2 * pi * f)
  "Magnetizing inductance w.r.t. primary side"
  parameter Lm1::Inductance = 10.0 / (2 * pi * f)
  "Secondary leakage inductance w.r.t. secondary side"
  parameter L2sigma::Inductance = 0.05 / (2 * pi * f * n ^ 2)
  "Secondary resistance w.r.t. secondary side"
  parameter R2::Resistance = R1 / n ^ 2
  "Load resistance"
  parameter RL::Resistance = 1.0 / n ^ 2
  "Mutual inductance"
  final parameter M_val::Inductance = Lm1 / n
  "Primary no-load inductance"
  final parameter L1_val::Inductance = L1sigma + M_val * n
  "Secondary no-load inductance"
  final parameter L2_val::Inductance = L2sigma + M_val / n
relations
  initial basic_transformer.i1 = 0
  initial basic_transformer.i2 = 0
  "Sine drives voltage source"
  connect(sine1.y, voltage_source1.V) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 120, "y": 50}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Source negative to primary ground"
  connect(voltage_source1.n, ground11.g) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 30, "y": 180}, {"x": 30, "y": 330}, {"x": 110, "y": 330}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  "Primary resistor to transformer port 1 positive"
  connect(resistor11.n, basic_transformer.p1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 400, "y": 180}, {"x": 400, "y": 181}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Transformer port 1 negative to primary ground"
  connect(basic_transformer.n1, ground11.g) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 330, "y": 279}, {"x": 330, "y": 330}, {"x": 110, "y": 330}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  "Transformer port 2 positive to secondary resistor"
  connect(basic_transformer.p2, resistor12.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 720, "y": 181}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Secondary resistor to load"
  connect(resistor12.n, load1.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 940, "y": 180}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Load to secondary ground"
  connect(load1.n, ground12.g) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  "Transformer port 2 negative to secondary ground"
  connect(basic_transformer.n2, ground12.g) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 581, "y": 280}, {"x": 581, "y": 330}, {"x": 940, "y": 330}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(resistor11.p, voltage_source1.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {}
end


Test Cases

No test cases defined.

  • Examples

  • Experiments

  • Analyses