Skip to content
LIBRARY
Analog.Basic.Tests.MTransformer.md

Analog.Basic.Tests.MTransformer

Test circuit for MTransformer with N=2.

Replicates the primary-side circuit from the MSL CompareTransformers example: SineVoltage → R1 → Transformer primary → Ground (primary side) Transformer secondary → R2 → Load → Ground (secondary side)

With these parameters the MTransformer(N=2) should behave identically to the MSL Basic.Transformer(L1, L2, M).

Parameters (from MSL CompareTransformers): f = 10 Hz, Vpeak = 0.1 V, Vdc = 0.1 V, phase = pi/2 n = 2 (turns ratio) R1 = 0.01 Ω, R2 = 0.0025 Ω, RL = 0.25 Ω L1 ≈ 0.16 H, L2 ≈ 0.04 H, M ≈ 0.07958 H

Usage

ElectricalComponents.Analog.Basic.Tests.MTransformer()

Behavior

[connect(sine+y,source+V)connect(source+p,r1+p)connect(r1+n,transformer+p1)connect(transformer+n1,gnd1+g,source+n)connect(transformer+p2,r2+p)connect(r2+n,load+p)connect(load+n,gnd2+g,transformer+n2)sine.y(t)=sine.offset+sine.amplitudeifelse(tsine.starttime,sin(sine.phase+6.283185307179586sine.frequency(sine.starttime+t)),sin(sine.phase))source.v(t)=source.p.v(t)source.n.v(t)source.i(t)=source.p.i(t)source.n.i(t)+source.p.i(t)=0source.v(t)=source.uVsource.V(t)r1.v(t)=r1.p.v(t)r1.n.v(t)r1.i(t)=r1.p.i(t)r1.p.i(t)+r1.n.i(t)=0r1.v(t)=r1.Rr1.i(t)transformer.v(t)=transformer.Lmdtransformer.i(t)dttransformer.v1(t)=transformer.p1.v(t)transformer.n1.v(t)0=transformer.n1.i(t)+transformer.p1.i(t)transformer.i1(t)=transformer.p1.i(t)transformer.v2(t)=transformer.n2.v(t)+transformer.p2.v(t)0=transformer.p2.i(t)+transformer.n2.i(t)transformer.i2(t)=transformer.p2.i(t)r2.v(t)=r2.p.v(t)r2.n.v(t)r2.i(t)=r2.p.i(t)r2.n.i(t)+r2.p.i(t)=0r2.v(t)=r2.Rr2.i(t)load.v(t)=load.n.v(t)+load.p.v(t)load.i(t)=load.p.i(t)load.n.i(t)+load.p.i(t)=0load.v(t)=load.Rload.i(t)gnd1.g.v(t)=0gnd2.g.v(t)=0]

Source

dyad
"""
Test circuit for MTransformer with N=2.

Replicates the primary-side circuit from the MSL CompareTransformers example:
  SineVoltage → R1 → Transformer primary → Ground (primary side)
  Transformer secondary → R2 → Load → Ground (secondary side)

With these parameters the MTransformer(N=2) should behave identically
to the MSL Basic.Transformer(L1, L2, M).

Parameters (from MSL CompareTransformers):
  f = 10 Hz, Vpeak = 0.1 V, Vdc = 0.1 V, phase = pi/2
  n = 2 (turns ratio)
  R1 = 0.01 Ω, R2 = 0.0025 Ω, RL = 0.25 Ω
  L1 ≈ 0.16 H, L2 ≈ 0.04 H, M ≈ 0.07958 H
"""
test component MTransformer
  # Sine voltage source (primary side)
  sine = BlockComponents.Sources.Sine(offset = 0.1, amplitude = 0.1, frequency = 10.0, phase = 1.5707963267948966) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  source = ElectricalComponents.Analog.Sources.VoltageSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 155, "y1": 125, "x2": 255, "y2": 225, "rot": 0}
      },
      "tags": []
    }
  }
  # Primary winding resistance
  r1 = ElectricalComponents.Analog.Basic.Resistor(R = 0.01) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 285, "y1": 236, "x2": 385, "y2": 336, "rot": 0}
      },
      "tags": []
    }
  }
  # The MTransformer with N=2
  transformer = ElectricalComponents.Analog.Basic.MTransformer(N = 2, L = [0.15996, 0.07958, 0.03999]) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 414, "y1": 236, "x2": 514, "y2": 336, "rot": 0}
      },
      "tags": []
    }
  }
  # Secondary winding resistance
  r2 = ElectricalComponents.Analog.Basic.Resistor(R = 0.0025) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 630, "y1": 500, "x2": 730, "y2": 600, "rot": 0}
      },
      "tags": []
    }
  }
  # Load resistor
  load = ElectricalComponents.Analog.Basic.Resistor(R = 0.25) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 155, "y1": 356, "x2": 255, "y2": 456, "rot": 0}
      },
      "tags": []
    }
  }
  # Separate grounds for primary and secondary (galvanic isolation)
  gnd1 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 620, "y1": 350, "x2": 720, "y2": 450, "rot": 0}
      },
      "tags": []
    }
  }
  gnd2 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 500, "x2": 390, "y2": 600, "rot": 0}
      },
      "tags": []
    }
  }
relations
  # Drive voltage source with sine
  connect(sine.y, source.V) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 205, "y": 70}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  # Primary side: source → R1 → transformer winding 1 → ground
  connect(source.p, r1.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 175}, {"x": 140, "y": 286}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(r1.n, transformer.p[1]) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(transformer.n[1], gnd1.g, source.n) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [{"x": 670, "y": 286}], "E": 2},
        {
          "S": -1,
          "M": [{"x": 540, "y": 246}, {"x": 600, "y": 246}, {"x": 600, "y": 175}],
          "E": 3
        }
      ],
      "junctions": [{"x": 540, "y": 286}],
      "renderStyle": "standard"
    }
  }
  # Secondary side: transformer winding 2 → R2 → load → ground
  connect(transformer.p[2], r2.p) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {
          "S": -1,
          "M": [{"x": 400, "y": 500}, {"x": 500, "y": 500}, {"x": 500, "y": 550}],
          "E": 2
        }
      ],
      "junctions": [{"x": 400, "y": 286}],
      "renderStyle": "standard"
    }
  }
  connect(r2.n, load.p) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [
            {"x": 750, "y": 550},
            {"x": 750, "y": 690},
            {"x": 140, "y": 690},
            {"x": 140, "y": 406}
          ],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(load.n, gnd2.g, transformer.n[2]) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [{"x": 335, "y": 433.5}, {"x": 340, "y": 433.5}], "E": 2},
        {"S": -1, "M": [{"x": 600, "y": 406}, {"x": 600, "y": 286}], "E": 3}
      ],
      "junctions": [{"x": 335, "y": 406}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 5,
        "expect": {
          "signals": ["transformer.i[1]", "transformer.i[2]", "transformer.v[1]", "transformer.v[2]"]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
Test circuit for MTransformer with N=2.

Replicates the primary-side circuit from the MSL CompareTransformers example:
  SineVoltage → R1 → Transformer primary → Ground (primary side)
  Transformer secondary → R2 → Load → Ground (secondary side)

With these parameters the MTransformer(N=2) should behave identically
to the MSL Basic.Transformer(L1, L2, M).

Parameters (from MSL CompareTransformers):
  f = 10 Hz, Vpeak = 0.1 V, Vdc = 0.1 V, phase = pi/2
  n = 2 (turns ratio)
  R1 = 0.01 Ω, R2 = 0.0025 Ω, RL = 0.25 Ω
  L1 ≈ 0.16 H, L2 ≈ 0.04 H, M ≈ 0.07958 H
"""
test component MTransformer
  # Sine voltage source (primary side)
  sine = BlockComponents.Sources.Sine(offset = 0.1, amplitude = 0.1, frequency = 10.0, phase = 1.5707963267948966) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  source = ElectricalComponents.Analog.Sources.VoltageSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 155, "y1": 125, "x2": 255, "y2": 225, "rot": 0}
      },
      "tags": []
    }
  }
  # Primary winding resistance
  r1 = ElectricalComponents.Analog.Basic.Resistor(R = 0.01) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 285, "y1": 236, "x2": 385, "y2": 336, "rot": 0}
      },
      "tags": []
    }
  }
  # The MTransformer with N=2
  transformer = ElectricalComponents.Analog.Basic.MTransformer(N = 2, L = [0.15996, 0.07958, 0.03999]) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 414, "y1": 236, "x2": 514, "y2": 336, "rot": 0}
      },
      "tags": []
    }
  }
  # Secondary winding resistance
  r2 = ElectricalComponents.Analog.Basic.Resistor(R = 0.0025) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 630, "y1": 500, "x2": 730, "y2": 600, "rot": 0}
      },
      "tags": []
    }
  }
  # Load resistor
  load = ElectricalComponents.Analog.Basic.Resistor(R = 0.25) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 155, "y1": 356, "x2": 255, "y2": 456, "rot": 0}
      },
      "tags": []
    }
  }
  # Separate grounds for primary and secondary (galvanic isolation)
  gnd1 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 620, "y1": 350, "x2": 720, "y2": 450, "rot": 0}
      },
      "tags": []
    }
  }
  gnd2 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 500, "x2": 390, "y2": 600, "rot": 0}
      },
      "tags": []
    }
  }
relations
  # Drive voltage source with sine
  connect(sine.y, source.V) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 205, "y": 70}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  # Primary side: source → R1 → transformer winding 1 → ground
  connect(source.p, r1.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 175}, {"x": 140, "y": 286}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(r1.n, transformer.p[1]) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(transformer.n[1], gnd1.g, source.n) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [{"x": 670, "y": 286}], "E": 2},
        {
          "S": -1,
          "M": [{"x": 540, "y": 246}, {"x": 600, "y": 246}, {"x": 600, "y": 175}],
          "E": 3
        }
      ],
      "junctions": [{"x": 540, "y": 286}],
      "renderStyle": "standard"
    }
  }
  # Secondary side: transformer winding 2 → R2 → load → ground
  connect(transformer.p[2], r2.p) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {
          "S": -1,
          "M": [{"x": 400, "y": 500}, {"x": 500, "y": 500}, {"x": 500, "y": 550}],
          "E": 2
        }
      ],
      "junctions": [{"x": 400, "y": 286}],
      "renderStyle": "standard"
    }
  }
  connect(r2.n, load.p) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [
            {"x": 750, "y": 550},
            {"x": 750, "y": 690},
            {"x": 140, "y": 690},
            {"x": 140, "y": 406}
          ],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(load.n, gnd2.g, transformer.n[2]) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [{"x": 335, "y": 433.5}, {"x": 340, "y": 433.5}], "E": 2},
        {"S": -1, "M": [{"x": 600, "y": 406}, {"x": 600, "y": 286}], "E": 3}
      ],
      "junctions": [{"x": 335, "y": 406}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 5,
        "expect": {
          "signals": ["transformer.i[1]", "transformer.i[2]", "transformer.v[1]", "transformer.v[2]"]
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt