Skip to content
LIBRARY
Analog.Examples.ShowVariableResistor.md

Analog.Examples.ShowVariableResistor

MSL validation test: ShowVariableResistor.

Recreates Modelica.Electrical.Analog.Examples.ShowVariableResistor from MSL v4.0.0. A sine voltage source drives two parallel branches: a fixed 3-resistor chain (R1-R2-R3, each 1 Ohm) and a variable-resistor chain (R4-VR-R5). The variable resistor's value is swept by a ramp from 2 to 7 Ohm over 2 s. The VariableResistor branch should be compared with R2 in the fixed branch.

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

Usage

ElectricalComponents.Analog.Examples.ShowVariableResistor()

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,variableresistor+p)connect(R5+n,ground2+g)connect(variableresistor+n,R5+p)connect(ramp+y,variableresistor+R)connect(fixedtemp+port,variableresistor+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)variableresistor.v(t)=variableresistor.p.v(t)variableresistor.n.v(t)variableresistor.i(t)=variableresistor.p.i(t)variableresistor.p.i(t)+variableresistor.n.i(t)=0variableresistor.R_actual(t)=(1+(variableresistor.T_ref+variableresistor.heat_port.T(t))variableresistor.alpha)variableresistor.R(t)variableresistor.v(t)=variableresistor.R_actual(t)variableresistor.i(t)variableresistor.LossPower(t)=variableresistor.i(t)variableresistor.v(t)variableresistor.heat_port.Q_flow(t)=variableresistor.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
"""
MSL validation test: ShowVariableResistor.

Recreates `Modelica.Electrical.Analog.Examples.ShowVariableResistor` from MSL v4.0.0.
A sine voltage source drives two parallel branches: a fixed 3-resistor chain
(R1-R2-R3, each 1 Ohm) and a variable-resistor chain (R4-VR-R5).
The variable resistor's value is swept by a ramp from 2 to 7 Ohm over 2 s.
The VariableResistor branch should be compared with R2 in the fixed branch.

MSL reference: tolerance=1e-6, StopTime=1.
"""
example component ShowVariableResistor
  "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 negative 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 resistor 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_resistor = ElectricalComponents.Analog.Basic.VariableResistor() {
    "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 resistance: offset=2, height=5, duration=2 s"
  ramp = BlockComponents.Sources.Ramp(height = 5, offset = 2, 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_resistor.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 (matches MSL SineVoltage1.p -> 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 (matches MSL SineVoltage1.n -> R1.p, R4.p)"
  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 -> VR -> R5 -> ground2"
  connect(R4.n, variable_resistor.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_resistor.n, R5.p) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(ramp.y, variable_resistor.R) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 550, "y": 420}], "E": 2}]
    }
  }
  connect(fixed_temp.port, variable_resistor.heat_port) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 551, "y": 790}], "E": 2}]
    }
  }
end
Flattened Source
dyad
"""
MSL validation test: ShowVariableResistor.

Recreates `Modelica.Electrical.Analog.Examples.ShowVariableResistor` from MSL v4.0.0.
A sine voltage source drives two parallel branches: a fixed 3-resistor chain
(R1-R2-R3, each 1 Ohm) and a variable-resistor chain (R4-VR-R5).
The variable resistor's value is swept by a ramp from 2 to 7 Ohm over 2 s.
The VariableResistor branch should be compared with R2 in the fixed branch.

MSL reference: tolerance=1e-6, StopTime=1.
"""
example component ShowVariableResistor
  "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 negative 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 resistor 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_resistor = ElectricalComponents.Analog.Basic.VariableResistor() {
    "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 resistance: offset=2, height=5, duration=2 s"
  ramp = BlockComponents.Sources.Ramp(height = 5, offset = 2, 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_resistor.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 (matches MSL SineVoltage1.p -> 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 (matches MSL SineVoltage1.n -> R1.p, R4.p)"
  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 -> VR -> R5 -> ground2"
  connect(R4.n, variable_resistor.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_resistor.n, R5.p) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(ramp.y, variable_resistor.R) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 550, "y": 420}], "E": 2}]
    }
  }
  connect(fixed_temp.port, variable_resistor.heat_port) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 551, "y": 790}], "E": 2}]
    }
  }
metadata {}
end


Test Cases

No test cases defined.

  • Examples

  • Experiments

  • Analyses