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

Analog.Basic.Tests.VariableConductor

Test circuit for VariableConductor.

Same topology as ShowVariableResistor: a sine voltage source drives two parallel branches — a fixed 3-resistor chain (R1-R2-R3, each 1 Ohm) and a chain with two 1 Ohm resistors flanking a VariableConductor. The conductance ramps from 0.5 S (≡ 2 Ω) down to ~0.143 S (≡ 7 Ω) over 2 s, mirroring the resistance ramp in ShowVariableResistor.

Usage

ElectricalComponents.Analog.Basic.Tests.VariableConductor()

Behavior

[connect(sine+y,voltagesource+V)connect(voltagesource+p,ground1+g)connect(voltagesource+n,R1+p)connect(voltagesource+n,R4+p)connect(R1+n,R2+p)connect(R2+n,R3+p)connect(R3+n,ground2+g)connect(R4+n,variableconductor+p)connect(R5+n,ground2+g)connect(variableconductor+n,R5+p)connect(ramp+y,variableconductor+G)connect(fixedtemp+port,variableconductor+heat_port)sine.y(t)=sine.offset+sine.amplitudeifelse(tsine.starttime,sin(sine.phase+6.283185307179586sine.frequency(sine.starttime+t)),sin(sine.phase))voltagesource.v(t)=voltagesource.n.v(t)+voltagesource.p.v(t)voltagesource.i(t)=voltagesource.p.i(t)voltagesource.n.i(t)+voltagesource.p.i(t)=0voltagesource.v(t)=voltagesource.uVvoltagesource.V(t)ground1.g.v(t)=0ground2.g.v(t)=0R1.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)R2.v(t)=R2.p.v(t)R2.n.v(t)R2.i(t)=R2.p.i(t)R2.p.i(t)+R2.n.i(t)=0R2.v(t)=R2.RR2.i(t)R3.v(t)=R3.n.v(t)+R3.p.v(t)R3.i(t)=R3.p.i(t)R3.p.i(t)+R3.n.i(t)=0R3.v(t)=R3.RR3.i(t)R4.v(t)=R4.n.v(t)+R4.p.v(t)R4.i(t)=R4.p.i(t)R4.p.i(t)+R4.n.i(t)=0R4.v(t)=R4.RR4.i(t)variableconductor.v(t)=variableconductor.p.v(t)variableconductor.n.v(t)variableconductor.i(t)=variableconductor.p.i(t)variableconductor.n.i(t)+variableconductor.p.i(t)=0variableconductor.G_actual(t)=variableconductor.G(t)1+(variableconductor.T_ref+variableconductor.heat_port.T(t))variableconductor.alphavariableconductor.i(t)=variableconductor.G_actual(t)variableconductor.v(t)variableconductor.LossPower(t)=variableconductor.v(t)variableconductor.i(t)variableconductor.heat_port.Q_flow(t)=variableconductor.LossPower(t)R5.v(t)=R5.p.v(t)R5.n.v(t)R5.i(t)=R5.p.i(t)R5.p.i(t)+R5.n.i(t)=0R5.v(t)=R5.RR5.i(t)ramp.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)fixedtemp.port.T(t)=fixedtemp.T]

Source

dyad
"""
Test circuit for VariableConductor.

Same topology as ShowVariableResistor: a sine voltage source drives
two parallel branches — a fixed 3-resistor chain (R1-R2-R3, each
1 Ohm) and a chain with two 1 Ohm resistors flanking a
VariableConductor. The conductance ramps from 0.5 S (≡ 2 Ω) down
to ~0.143 S (≡ 7 Ω) over 2 s, mirroring the resistance ramp in
ShowVariableResistor.
"""
test component VariableConductor
  "Sine voltage source: V=1 V, f=1 Hz"
  sine = BlockComponents.Sources.Sine(amplitude = 1, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Voltage source driven by the sine signal"
  voltage_source = ElectricalComponents.Analog.Sources.VoltageSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 100, "y1": 230, "x2": 200, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  "Ground at source positive terminal"
  ground1 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 10, "y1": 660, "x2": 110, "y2": 760, "rot": 0}
      },
      "tags": []
    }
  }
  "Ground at return path (right side)"
  ground2 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 900, "y1": 690, "x2": 1000, "y2": 790, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed resistor chain (top branch)"
  R1 = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 230, "x2": 400, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  R2 = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 500, "y1": 230, "x2": 600, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  R3 = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 700, "y1": 230, "x2": 800, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  "Variable conductor chain (bottom branch)"
  R4 = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 530, "x2": 390, "y2": 630, "rot": 0}
      },
      "tags": []
    }
  }
  variable_conductor = ElectricalComponents.Analog.Basic.VariableConductor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 500, "y1": 530, "x2": 600, "y2": 630, "rot": 0}
      },
      "tags": []
    }
  }
  R5 = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 700, "y1": 530, "x2": 800, "y2": 630, "rot": 0}
      },
      "tags": []
    }
  }
  "Ramp signal for variable conductance: 0.5 S down to ~0.143 S over 2 s"
  ramp = BlockComponents.Sources.Ramp(height = -0.357, offset = 0.5, duration = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 380, "y1": 370, "x2": 480, "y2": 470, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed temperature to ground the thermal port (alpha=0, so T is irrelevant)"
  fixed_temp = ThermalComponents.Sources.FixedTemperature(T = 300.15) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 740, "x2": 420, "y2": 840, "rot": 0}
      },
      "tags": []
    }
  }
relations
  guess variable_conductor.i = 0
  "Signal to voltage source"
  connect(sine.y, voltage_source.V) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 150, "y": 70}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Source positive to ground1"
  connect(voltage_source.p, ground1.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 60, "y": 280}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Source negative to both branches"
  connect(voltage_source.n, R1.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(voltage_source.n, R4.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 270, "y": 280}, {"x": 270, "y": 580}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Top branch: R1 -> R2 -> R3 -> ground2"
  connect(R1.n, R2.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(R2.n, R3.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(R3.n, ground2.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 950, "y": 280}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Bottom branch: R4 -> VC -> R5 -> ground2"
  connect(R4.n, variable_conductor.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(R5.n, ground2.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 950, "y": 580}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(variable_conductor.n, R5.p) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(ramp.y, variable_conductor.G) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 550, "y": 420}], "E": 2}]
    }
  }
  connect(fixed_temp.port, variable_conductor.heat_port) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 551, "y": 790}], "E": 2}]
    }
  }
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["variable_conductor.i", "R2.i", "variable_conductor.LossPower"]}
      }
    }
  }
}
end
Flattened Source
dyad
"""
Test circuit for VariableConductor.

Same topology as ShowVariableResistor: a sine voltage source drives
two parallel branches — a fixed 3-resistor chain (R1-R2-R3, each
1 Ohm) and a chain with two 1 Ohm resistors flanking a
VariableConductor. The conductance ramps from 0.5 S (≡ 2 Ω) down
to ~0.143 S (≡ 7 Ω) over 2 s, mirroring the resistance ramp in
ShowVariableResistor.
"""
test component VariableConductor
  "Sine voltage source: V=1 V, f=1 Hz"
  sine = BlockComponents.Sources.Sine(amplitude = 1, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Voltage source driven by the sine signal"
  voltage_source = ElectricalComponents.Analog.Sources.VoltageSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 100, "y1": 230, "x2": 200, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  "Ground at source positive terminal"
  ground1 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 10, "y1": 660, "x2": 110, "y2": 760, "rot": 0}
      },
      "tags": []
    }
  }
  "Ground at return path (right side)"
  ground2 = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 900, "y1": 690, "x2": 1000, "y2": 790, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed resistor chain (top branch)"
  R1 = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 230, "x2": 400, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  R2 = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 500, "y1": 230, "x2": 600, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  R3 = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 700, "y1": 230, "x2": 800, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  "Variable conductor chain (bottom branch)"
  R4 = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 530, "x2": 390, "y2": 630, "rot": 0}
      },
      "tags": []
    }
  }
  variable_conductor = ElectricalComponents.Analog.Basic.VariableConductor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 500, "y1": 530, "x2": 600, "y2": 630, "rot": 0}
      },
      "tags": []
    }
  }
  R5 = ElectricalComponents.Analog.Basic.Resistor(R = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 700, "y1": 530, "x2": 800, "y2": 630, "rot": 0}
      },
      "tags": []
    }
  }
  "Ramp signal for variable conductance: 0.5 S down to ~0.143 S over 2 s"
  ramp = BlockComponents.Sources.Ramp(height = -0.357, offset = 0.5, duration = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 380, "y1": 370, "x2": 480, "y2": 470, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed temperature to ground the thermal port (alpha=0, so T is irrelevant)"
  fixed_temp = ThermalComponents.Sources.FixedTemperature(T = 300.15) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 740, "x2": 420, "y2": 840, "rot": 0}
      },
      "tags": []
    }
  }
relations
  guess variable_conductor.i = 0
  "Signal to voltage source"
  connect(sine.y, voltage_source.V) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 150, "y": 70}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Source positive to ground1"
  connect(voltage_source.p, ground1.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 60, "y": 280}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Source negative to both branches"
  connect(voltage_source.n, R1.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(voltage_source.n, R4.p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 270, "y": 280}, {"x": 270, "y": 580}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Top branch: R1 -> R2 -> R3 -> ground2"
  connect(R1.n, R2.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(R2.n, R3.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(R3.n, ground2.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 950, "y": 280}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  "Bottom branch: R4 -> VC -> R5 -> ground2"
  connect(R4.n, variable_conductor.p) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(R5.n, ground2.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 950, "y": 580}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(variable_conductor.n, R5.p) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(ramp.y, variable_conductor.G) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 550, "y": 420}], "E": 2}]
    }
  }
  connect(fixed_temp.port, variable_conductor.heat_port) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 551, "y": 790}], "E": 2}]
    }
  }
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["variable_conductor.i", "R2.i", "variable_conductor.LossPower"]}
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt