---
url: /dyad/stable/stdlib/ElectricalComponents/tests/Analog.Basic.Tests.VariableInductor.md
description: >-
  Dyad Analog.Basic.Tests.VariableInductor docs.  Test circuit for
  VariableInductor.
---

# `Analog.Basic.Tests.VariableInductor` {#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 {#Usage}

`ElectricalComponents.Analog.Basic.Tests.VariableInductor()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( sine\_{+}y, vs\_{+}V \right) \\
0 &= \mathrm{connect}\left( vs\_{+}p, R1\_{+}p \right) \\
0 &= \mathrm{connect}\left( R1\_{+}n, vl\_{+}p \right) \\
0 &= \mathrm{connect}\left( vl\_{+}n, ground\_{+}g \right) \\
0 &= \mathrm{connect}\left( vs\_{+}n, ground\_{+}g \right) \\
0 &= \mathrm{connect}\left( ramp\_{+}y, vl\_{+}L \right) \\
\mathtt{sine.y}\left( t \right) &= ifelse\left( \mathtt{sine.continuous}, ifelse\left( t \geq \mathtt{sine.start_time}, \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + t \right) \right), \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + \mathtt{sine.start_time} \right) \right) \right) ~ \mathtt{sine.amplitude}, ifelse\left( t \geq \mathtt{sine.start_time}, \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + t \right) \right) ~ \mathtt{sine.amplitude}, 0 \right) \right) + \mathtt{sine.offset} \\
\mathtt{vs.v}\left( t \right) &=  - \mathtt{vs.n.v}\left( t \right) + \mathtt{vs.p.v}\left( t \right) \\
\mathtt{vs.i}\left( t \right) &= \mathtt{vs.p.i}\left( t \right) \\
\mathtt{vs.n.i}\left( t \right) + \mathtt{vs.p.i}\left( t \right) &= 0 \\
\mathtt{vs.v}\left( t \right) &= \mathtt{vs.V}\left( t \right) ~ \mathtt{vs.uV} \\
\mathtt{R1.v}\left( t \right) &=  - \mathtt{R1.n.v}\left( t \right) + \mathtt{R1.p.v}\left( t \right) \\
\mathtt{R1.i}\left( t \right) &= \mathtt{R1.p.i}\left( t \right) \\
\mathtt{R1.n.i}\left( t \right) + \mathtt{R1.p.i}\left( t \right) &= 0 \\
\mathtt{R1.v}\left( t \right) &= \mathtt{R1.R} ~ \mathtt{R1.i}\left( t \right) \\
\mathtt{vl.v}\left( t \right) &=  - \mathtt{vl.n.v}\left( t \right) + \mathtt{vl.p.v}\left( t \right) \\
\mathtt{vl.i}\left( t \right) &= \mathtt{vl.p.i}\left( t \right) \\
\mathtt{vl.n.i}\left( t \right) + \mathtt{vl.p.i}\left( t \right) &= 0 \\
\mathtt{vl.Psi}\left( t \right) &= max\left( \mathtt{vl.L}\left( t \right), \mathtt{vl.Lmin} \right) ~ \mathtt{vl.i}\left( t \right) \\
\mathtt{vl.v}\left( t \right) &= \frac{\mathrm{d}\mathtt{vl.Psi}\left( t \right)}{\mathrm{d}t} \\
\mathtt{ramp.y}\left( t \right) &= ifelse\left( \mathtt{ramp.start_time} < t, ifelse\left( t < \mathtt{ramp.duration} + \mathtt{ramp.start_time}, \mathtt{ramp.offset} + \frac{\mathtt{ramp.height} ~ \left(  - \mathtt{ramp.start_time} + t \right)}{\mathtt{ramp.duration}}, \mathtt{ramp.height} + \mathtt{ramp.offset} \right), \mathtt{ramp.offset} \right) \\
\mathtt{ground.g.v}\left( t \right) &= 0
\end{align}
$$

## Source {#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": 1e-4},
        "expect": {"signals": ["vl.v", "vl.i", "vl.Psi"]}
      }
    }
  }
}
end
```

```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": 1e-4},
        "expect": {"signals": ["vl.v", "vl.i", "vl.Psi"]}
      }
    }
  }
}
end
```

## Test Cases {#Test-Cases}

### Test Case `case1` {#Test-Case-case1}

```julia
plt
```

![](zushawp.svg)

```julia
plt
```

![](ybinvku.svg)

```julia
plt
```

![](fvwoqhx.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Ground`](Analog.Basic.Tests.VariableInductor.md)

  * [`Ramp`](Analog.Basic.Tests.VariableInductor.md)

  * [`Resistor`](Analog.Basic.Tests.VariableInductor.md)

  * [`Sine`](Analog.Basic.Tests.VariableInductor.md)

  * [`VariableInductor`](Analog.Basic.Tests.VariableInductor.md)

  * [`VariableInductor`](Analog.Basic.Tests.VariableInductor.md)

  * [`VoltageSource`](Analog.Basic.Tests.VariableInductor.md)
