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

Analog.Basic.Tests.VariableInductor

Test circuit for VariableInductor.

A sine voltage source (1 V, 1 Hz) drives an RL circuit where the inductance ramps from 0.1 H to 0.6 H over 2 s. A 10 Ω series resistor provides damping.

The flux-based formulation should produce smooth voltage despite the time-varying inductance.

Usage

ElectricalComponents.Analog.Basic.Tests.VariableInductor()

Behavior

[connect(sine+y,vs+V)connect(vs+p,R1+p)connect(R1+n,vl+p)connect(vl+n,ground+g)connect(vs+n,ground+g)connect(ramp+y,vl+L)sine.y(t)=sine.offset+sine.amplitudeifelse(tsine.starttime,sin(sine.phase+6.283185307179586sine.frequency(sine.starttime+t)),sin(sine.phase))vs.v(t)=vs.n.v(t)+vs.p.v(t)vs.i(t)=vs.p.i(t)vs.n.i(t)+vs.p.i(t)=0vs.v(t)=vs.uVvs.V(t)R1.v(t)=R1.p.v(t)R1.n.v(t)R1.i(t)=R1.p.i(t)R1.n.i(t)+R1.p.i(t)=0R1.v(t)=R1.RR1.i(t)vl.v(t)=vl.p.v(t)vl.n.v(t)vl.i(t)=vl.p.i(t)vl.p.i(t)+vl.n.i(t)=0vl.Psi(t)=max(vl.L(t),vl.Lmin)vl.i(t)vl.v(t)=dvl.Psi(t)dtramp.y(t)=ifelse(ramp.starttime<t,ifelse(t<ramp.duration+ramp.starttime,ramp.offset+ramp.height(ramp.starttime+t)ramp.duration,ramp.height+ramp.offset),ramp.offset)ground.g.v(t)=0]

Source

dyad
"""
Test circuit for VariableInductor.

A sine voltage source (1 V, 1 Hz) drives an RL circuit where the
inductance ramps from 0.1 H to 0.6 H over 2 s. A 10 Ω series
resistor provides damping.

The flux-based formulation should produce smooth voltage despite
the time-varying inductance.
"""
test component VariableInductor
  "Sine signal source: 1 V amplitude, 1 Hz"
  sine = BlockComponents.Sources.Sine(amplitude = 1, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 40, "y1": 400, "x2": 140, "y2": 500, "rot": 0}
      },
      "tags": []
    }
  }
  "Voltage source driven by the sine signal"
  vs = ElectricalComponents.Analog.Sources.VoltageSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 250, "y1": 500, "x2": 350, "y2": 400, "rot": 90}
      },
      "tags": []
    }
  }
  "Series resistor (10 Ω)"
  R1 = ElectricalComponents.Analog.Basic.Resistor(R = 10) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 280, "x2": 550, "y2": 380, "rot": 0}
      },
      "tags": []
    }
  }
  "Variable inductor under test"
  vl = ElectricalComponents.Analog.Basic.VariableInductor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 740, "y1": 500, "x2": 640, "y2": 400, "rot": 270}
      },
      "tags": []
    }
  }
  "Ramp for inductance: 0.1 H to 0.6 H over 2 s"
  ramp = BlockComponents.Sources.Ramp(height = 0.5, offset = 0.1, duration = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 950, "y1": 400, "x2": 850, "y2": 500, "rot": 0}
      },
      "tags": []
    }
  }
  "Ground reference"
  ground = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 600, "x2": 550, "y2": 700, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial vl.i = 0
  connect(sine.y, vs.V) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(vs.p, R1.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 300, "y": 330}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(R1.n, vl.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 690, "y": 330}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(vl.n, ground.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 690, "y": 540}, {"x": 500, "y": 540}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(vs.n, ground.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 300, "y": 540}, {"x": 500, "y": 540}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(ramp.y, vl.L) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 1,
        "atol": {"vl.v": 0.0001},
        "expect": {"signals": ["vl.v", "vl.i", "vl.Psi"]}
      }
    }
  }
}
end
Flattened Source
dyad
"""
Test circuit for VariableInductor.

A sine voltage source (1 V, 1 Hz) drives an RL circuit where the
inductance ramps from 0.1 H to 0.6 H over 2 s. A 10 Ω series
resistor provides damping.

The flux-based formulation should produce smooth voltage despite
the time-varying inductance.
"""
test component VariableInductor
  "Sine signal source: 1 V amplitude, 1 Hz"
  sine = BlockComponents.Sources.Sine(amplitude = 1, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 40, "y1": 400, "x2": 140, "y2": 500, "rot": 0}
      },
      "tags": []
    }
  }
  "Voltage source driven by the sine signal"
  vs = ElectricalComponents.Analog.Sources.VoltageSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 250, "y1": 500, "x2": 350, "y2": 400, "rot": 90}
      },
      "tags": []
    }
  }
  "Series resistor (10 Ω)"
  R1 = ElectricalComponents.Analog.Basic.Resistor(R = 10) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 280, "x2": 550, "y2": 380, "rot": 0}
      },
      "tags": []
    }
  }
  "Variable inductor under test"
  vl = ElectricalComponents.Analog.Basic.VariableInductor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 740, "y1": 500, "x2": 640, "y2": 400, "rot": 270}
      },
      "tags": []
    }
  }
  "Ramp for inductance: 0.1 H to 0.6 H over 2 s"
  ramp = BlockComponents.Sources.Ramp(height = 0.5, offset = 0.1, duration = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 950, "y1": 400, "x2": 850, "y2": 500, "rot": 0}
      },
      "tags": []
    }
  }
  "Ground reference"
  ground = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 600, "x2": 550, "y2": 700, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial vl.i = 0
  connect(sine.y, vs.V) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(vs.p, R1.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 300, "y": 330}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(R1.n, vl.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 690, "y": 330}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(vl.n, ground.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 690, "y": 540}, {"x": 500, "y": 540}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(vs.n, ground.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 300, "y": 540}, {"x": 500, "y": 540}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(ramp.y, vl.L) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 1,
        "atol": {"vl.v": 0.0001},
        "expect": {"signals": ["vl.v", "vl.i", "vl.Psi"]}
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt